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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
146 | B | Lucky Mask | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a mask of a positive integer *n* the number that is obtained after successive writing ... | The only line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=105). It is guaranteed that number *b* is lucky. | In the only line print a single number — the number *c* that is sought by Petya. | [
"1 7\n",
"100 47\n"
] | [
"7\n",
"147\n"
] | none | 1,000 | [
{
"input": "1 7",
"output": "7"
},
{
"input": "100 47",
"output": "147"
},
{
"input": "458 47",
"output": "467"
},
{
"input": "7 7",
"output": "17"
},
{
"input": "547 47",
"output": "647"
},
{
"input": "77 77",
"output": "177"
},
{
"input":... | 1,657,388,402 | 3,842 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | def mask(n):
n1=str(n)
n2=[int(i) for i in n1]
m=[]
for j in n2:
if j==4 or j==7:
m.append(j)
if m==[]:
m.append(0)
m1="".join(str(ele) for ele in m)
return int(m1)
L=input().split()
a=int(L[0])
b=int(L[1])
i=a
while i>=a and mask(... | Title: Lucky Mask
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Pe... | ```python
def mask(n):
n1=str(n)
n2=[int(i) for i in n1]
m=[]
for j in n2:
if j==4 or j==7:
m.append(j)
if m==[]:
m.append(0)
m1="".join(str(ele) for ele in m)
return int(m1)
L=input().split()
a=int(L[0])
b=int(L[1])
i=a
while i>=a... | 0 | |
591 | B | Rebranding | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slog... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descr... | Print the new name of the corporation. | [
"6 1\npolice\np m\n",
"11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n"
] | [
"molice\n",
"cdcbcdcfcdc\n"
] | In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.co... | 1,000 | [
{
"input": "6 1\npolice\np m",
"output": "molice"
},
{
"input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b",
"output": "cdcbcdcfcdc"
},
{
"input": "1 1\nf\nz h",
"output": "f"
},
{
"input": "1 1\na\na b",
"output": "b"
},
{
"input": "10 10\nlellelleel\ne l\n... | 1,445,766,445 | 2,845 | Python 3 | OK | TESTS | 27 | 592 | 1,536,000 | import string
n,m = map(int, input().split())
s = input()
chars = string.ascii_lowercase
for _ in range(m):
a,b = input().split()
chars = chars.replace(a, "%").replace(b,a).replace("%",b)
replacements = {ord(string.ascii_lowercase[i]):chars[i] for i in range(26)}
print(s.translate(replacements)) | Title: Rebranding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand ... | ```python
import string
n,m = map(int, input().split())
s = input()
chars = string.ascii_lowercase
for _ in range(m):
a,b = input().split()
chars = chars.replace(a, "%").replace(b,a).replace("%",b)
replacements = {ord(string.ascii_lowercase[i]):chars[i] for i in range(26)}
print(s.translate(replacements))
... | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,578,573,206 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | s=str(input())
n=len(s)
a="hello"
b=""
c=-1
for i in range(5):
while c<n-1:
c=c+1
if a[i]==s[c]:
b=b+s[c]
break
if b==a:
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=str(input())
n=len(s)
a="hello"
b=""
c=-1
for i in range(5):
while c<n-1:
c=c+1
if a[i]==s[c]:
b=b+s[c]
break
if b==a:
print("YES")
else:
print("NO")
``` | 3.938 |
53 | D | Physical Education | PROGRAMMING | 1,500 | [
"sortings"
] | D. Physical Education | 2 | 256 | Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is the height of the *i*-th student in the line and *n* is the number of s... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=300) which is the number of students. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) which represent the height of the student occupying the *i*-th place must possess. The third line contains *n* space-separated integers *b**i* (... | In the first line print an integer *k* (0<=≤<=*k*<=≤<=106) which is the number of moves. It is not required to minimize *k* but it must not exceed 106. Then print *k* lines each containing two space-separated integers. Line *p**i*, *p**i*<=+<=1 (1<=≤<=*p**i*<=≤<=*n*<=-<=1) means that Vasya should swap students occupyin... | [
"4\n1 2 3 2\n3 2 1 2\n",
"2\n1 100500\n1 100500\n"
] | [
"4\n2 3\n1 2\n3 4\n2 3\n",
"0\n"
] | none | 2,000 | [
{
"input": "4\n1 2 3 2\n3 2 1 2",
"output": "4\n2 3\n1 2\n3 4\n2 3"
},
{
"input": "2\n1 100500\n1 100500",
"output": "0"
},
{
"input": "3\n652586118 652586118 652586118\n652586118 652586118 652586118",
"output": "3\n2 3\n1 2\n2 3"
},
{
"input": "4\n681106577 681106577 6750771... | 1,686,555,995 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n=int(input())
l=list(map(int,input().split()))
l1=list(map(int,input().split()))
ans=[]
for i in range(n):
if(l[i]==l1[i]):
continue
for j in range(i,n):
if(l[j]==l1[i]):
break
for k in range(j,i,-1):
ans.append([k,k-1])
l[k-1],l[k]=l[k],l[k-1]
print... | Title: Physical Education
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: *a*1,<=*a*2,<=.... | ```python
n=int(input())
l=list(map(int,input().split()))
l1=list(map(int,input().split()))
ans=[]
for i in range(n):
if(l[i]==l1[i]):
continue
for j in range(i,n):
if(l[j]==l1[i]):
break
for k in range(j,i,-1):
ans.append([k,k-1])
l[k-1],l[k]=l[k],l[k... | 0 |
411 | A | Password Check | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che... | The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_". | If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes). | [
"abacaba\n",
"X12345\n",
"CONTEST_is_STARTED!!11\n"
] | [
"Too weak\n",
"Too weak\n",
"Correct\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "Too weak"
},
{
"input": "X12345",
"output": "Too weak"
},
{
"input": "CONTEST_is_STARTED!!11",
"output": "Correct"
},
{
"input": "1zA__",
"output": "Correct"
},
{
"input": "1zA_",
"output": "Too weak"
},
{
"input": "zA_... | 1,627,532,919 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 93 | 7,475,200 | import re
f = input().strip()
if re.compile('[0-9]+').findall(f)and re.compile('[a-z]+').findall(f)and re.compile('[A-Z]+').findall(f)and len(f) > 4:
print('Correct')
else:
print('Too weak') | Title: Password Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password... | ```python
import re
f = input().strip()
if re.compile('[0-9]+').findall(f)and re.compile('[a-z]+').findall(f)and re.compile('[A-Z]+').findall(f)and len(f) > 4:
print('Correct')
else:
print('Too weak')
``` | 3 | |
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate... | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence... | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15... | 1,698,993,595 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | n = int(input())
k = int(input())
count = 0
amount = 0
previous = 0
for i in range(0, n):
a = int(input())
if a == 0:
continue
if count > k and a == previous:
amount += 1
if count <= k:
amount += 1
count += 1
if count == k:
previous = a
print(amo... | Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* p... | ```python
n = int(input())
k = int(input())
count = 0
amount = 0
previous = 0
for i in range(0, n):
a = int(input())
if a == 0:
continue
if count > k and a == previous:
amount += 1
if count <= k:
amount += 1
count += 1
if count == k:
previous = a
... | -1 | |
920 | A | Water The Garden | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the bed *x**i*), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed *... | The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=200).
Then *t* test cases follow. The first line of each test case contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200, 1<=≤<=*k*<=≤<=*n*) — the number of garden beds and water taps, respectively.
Next line contains *k* intege... | For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered. | [
"3\n5 1\n3\n3 3\n1 2 3\n4 1\n1\n"
] | [
"3\n1\n4\n"
] | The first example consists of 3 tests:
1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered. 1. There are 3 garden beds, and there is ... | 0 | [
{
"input": "3\n5 1\n3\n3 3\n1 2 3\n4 1\n1",
"output": "3\n1\n4"
},
{
"input": "26\n1 1\n1\n2 1\n2\n2 1\n1\n2 2\n1 2\n3 1\n3\n3 1\n2\n3 2\n2 3\n3 1\n1\n3 2\n1 3\n3 2\n1 2\n3 3\n1 2 3\n4 1\n4\n4 1\n3\n4 2\n3 4\n4 1\n2\n4 2\n2 4\n4 2\n2 3\n4 3\n2 3 4\n4 1\n1\n4 2\n1 4\n4 2\n1 3\n4 3\n1 3 4\n4 2\n1 2\n4... | 1,517,583,375 | 1,275 | Python 3 | OK | TESTS | 21 | 61 | 5,632,000 | t = int(input())
count = 0
while count < t:
nk = input().split(" ")
n = int(nk[0])
k = int(nk[1])
x = input().split(" ")
i = 0
ans = 1
last = 0
while i < k:
xi = int(x[i])
temp = 0
if last == 0:
temp = xi
else:
dis =... | Title: Water The Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the ... | ```python
t = int(input())
count = 0
while count < t:
nk = input().split(" ")
n = int(nk[0])
k = int(nk[1])
x = input().split(" ")
i = 0
ans = 1
last = 0
while i < k:
xi = int(x[i])
temp = 0
if last == 0:
temp = xi
else:
... | 3 | |
915 | B | Browser | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Luba is surfing the Internet. She currently has *n* opened tabs in her browser, indexed from 1 to *n* from left to right. The mouse cursor is currently located at the *pos*-th tab. Luba needs to use the tabs with indices from *l* to *r* (inclusive) for her studies, and she wants to close all the tabs that don't belong ... | The only line of input contains four integer numbers *n*, *pos*, *l*, *r* (1<=≤<=*n*<=≤<=100, 1<=≤<=*pos*<=≤<=*n*, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened. | Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [*l*,<=*r*]. | [
"6 3 2 4\n",
"6 3 1 3\n",
"5 2 1 5\n"
] | [
"5\n",
"1\n",
"0\n"
] | In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it.
In the second test she only needs to close all the tabs to the right of the current ... | 0 | [
{
"input": "6 3 2 4",
"output": "5"
},
{
"input": "6 3 1 3",
"output": "1"
},
{
"input": "5 2 1 5",
"output": "0"
},
{
"input": "100 1 1 99",
"output": "99"
},
{
"input": "100 50 1 99",
"output": "50"
},
{
"input": "100 99 1 99",
"output": "1"
},... | 1,619,876,957 | 1,757 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 77 | 0 | import sys
import math
input = sys.stdin.readline
for _ in range(1):
n,pos,l,r = map(int,input().split())
ans = 0
if pos < r:
if pos == l:
if l != 1:
ans += 1
if pos != l:
ans += abs(l - pos)
if l != 1:
ans +=... | Title: Browser
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba is surfing the Internet. She currently has *n* opened tabs in her browser, indexed from 1 to *n* from left to right. The mouse cursor is currently located at the *pos*-th tab. Luba needs to use the tabs with indices from *... | ```python
import sys
import math
input = sys.stdin.readline
for _ in range(1):
n,pos,l,r = map(int,input().split())
ans = 0
if pos < r:
if pos == l:
if l != 1:
ans += 1
if pos != l:
ans += abs(l - pos)
if l != 1:
... | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,689,189,344 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | j=int(input())
for i in range(0,j):
a=input()
print(a[0]+str(len(a)-2)+a[-1] if len(a)>10 else a) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
j=int(input())
for i in range(0,j):
a=input()
print(a[0]+str(len(a)-2)+a[-1] if len(a)>10 else a)
``` | 3.977 |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,585,184,072 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 186 | 0 | n = int (input ())
a = list (map (int, input ().split ()))
otv = []
height = 1
for i in range (len (a)):
if a[i] not in otv:
otv.append (a[i])
else:
height += 1
print (height, len (otv)) | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
n = int (input ())
a = list (map (int, input ().split ()))
otv = []
height = 1
for i in range (len (a)):
if a[i] not in otv:
otv.append (a[i])
else:
height += 1
print (height, len (otv))
``` | 0 |
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Ove... | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
... | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example ... | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n10000000... | 1,619,537,914 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 12,697,600 | from collections import defaultdict
def dfs(visited, graph, friends, node):
gold = 0
if node not in visited:
visited.add(node)
gold = graph[node-1]
for i in range(len(friends)):
try:
next_... | Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte... | ```python
from collections import defaultdict
def dfs(visited, graph, friends, node):
gold = 0
if node not in visited:
visited.add(node)
gold = graph[node-1]
for i in range(len(friends)):
try:
... | 0 | |
766 | A | Mahmoud and Longest Uncommon Subsequence | PROGRAMMING | 1,000 | [
"constructive algorithms",
"strings"
] | null | null | While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence ... | The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. | If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*. | [
"abcd\ndefgh\n",
"a\na\n"
] | [
"5\n",
"-1\n"
] | In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*. | 500 | [
{
"input": "abcd\ndefgh",
"output": "5"
},
{
"input": "a\na",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddd... | 1,672,036,154 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 73 | 62 | 307,200 | m = input()
e = input()
print(-1 if m == e else max(len(m),len(e))) | Title: Mahmoud and Longest Uncommon Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two ... | ```python
m = input()
e = input()
print(-1 if m == e else max(len(m),len(e)))
``` | 3 | |
710 | F | String Set Queries | PROGRAMMING | 2,400 | [
"brute force",
"data structures",
"hashing",
"interactive",
"string suffix structures",
"strings"
] | null | null | You should process *m* queries over a set *D* of strings. Each query is one of three kinds:
1. Add a string *s* to the set *D*. It is guaranteed that the string *s* was not added before. 1. Delete a string *s* from the set *D*. It is guaranteed that the string *s* is in the set *D*. 1. For the given string *s* find... | The first line contains integer *m* (1<=≤<=*m*<=≤<=3·105) — the number of queries.
Each of the next *m* lines contains integer *t* (1<=≤<=*t*<=≤<=3) and nonempty string *s* — the kind of the query and the string to process. All strings consist of only lowercase English letters.
The sum of lengths of all strings in th... | For each query of the third kind print the only integer *c* — the desired number of occurrences in the string *s*. | [
"5\n1 abc\n3 abcabc\n2 abc\n1 aba\n3 abababc\n",
"10\n1 abc\n1 bcd\n1 abcd\n3 abcd\n2 abcd\n3 abcd\n2 bcd\n3 abcd\n2 abc\n3 abcd\n"
] | [
"2\n2\n",
"3\n2\n1\n0\n"
] | none | 0 | [
{
"input": "5\n1 abc\n3 abcabc\n2 abc\n1 aba\n3 abababc",
"output": "2\n2"
},
{
"input": "10\n1 abc\n1 bcd\n1 abcd\n3 abcd\n2 abcd\n3 abcd\n2 bcd\n3 abcd\n2 abc\n3 abcd",
"output": "3\n2\n1\n0"
},
{
"input": "2\n1 abbaaabbbababbaaabbbbb\n3 bbbbbbabbbabaabbbbabbb",
"output": "0"
},
... | 1,620,993,355 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 3,000 | 15,155,200 | n=int(input())
arr=[]
for i in range(n):
t,s=map(str,input().split())
t=int(t)
if(t==1):
arr.append(s)
if(t==2):
arr.remove(s)
if(t==3):
count=0
for k in arr:
temp=s
while k in temp:
count+=1
temp=temp[temp.index(k)+1:]
print(count)
| Title: String Set Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You should process *m* queries over a set *D* of strings. Each query is one of three kinds:
1. Add a string *s* to the set *D*. It is guaranteed that the string *s* was not added before. 1. Delete a string *s* fro... | ```python
n=int(input())
arr=[]
for i in range(n):
t,s=map(str,input().split())
t=int(t)
if(t==1):
arr.append(s)
if(t==2):
arr.remove(s)
if(t==3):
count=0
for k in arr:
temp=s
while k in temp:
count+=1
temp=temp[temp.index(k)+1:]
print(count)
``` | 0 | |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of int... | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10"... | 1,692,527,503 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 42 | 218 | 0 | n, m = input().split()
n = int(n)
m = int(m)
count = 0
for a in range(n + 1):
b = n - (a*a)
if a + b**2 == m:
count += 1
print(count)
| Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi... | ```python
n, m = input().split()
n = int(n)
m = int(m)
count = 0
for a in range(n + 1):
b = n - (a*a)
if a + b**2 == m:
count += 1
print(count)
``` | 0 | |
766 | A | Mahmoud and Longest Uncommon Subsequence | PROGRAMMING | 1,000 | [
"constructive algorithms",
"strings"
] | null | null | While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence ... | The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. | If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*. | [
"abcd\ndefgh\n",
"a\na\n"
] | [
"5\n",
"-1\n"
] | In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*. | 500 | [
{
"input": "abcd\ndefgh",
"output": "5"
},
{
"input": "a\na",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddd... | 1,644,941,438 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | s1=input()
s2=input()
if s1==s2:
print(-1)
exit()
if s1[-1]==s2[0]:
if len(s1)>len(s2):
print(len(s1))
else:print(len(s2)) | Title: Mahmoud and Longest Uncommon Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two ... | ```python
s1=input()
s2=input()
if s1==s2:
print(-1)
exit()
if s1[-1]==s2[0]:
if len(s1)>len(s2):
print(len(s1))
else:print(len(s2))
``` | 0 | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,647,530,006 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 109 | 14,336,000 | import sys
input = sys.stdin.readline
(n, b, d) = tuple(map(int, input().split()))
lst = list(map(int, input().split()))
i = 0
s = 0
c = 0
while i < n and lst[i] <= b:
s += lst[i]
if s > d:
s = 0
c += 1
i += 1
print(c) | Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
import sys
input = sys.stdin.readline
(n, b, d) = tuple(map(int, input().split()))
lst = list(map(int, input().split()))
i = 0
s = 0
c = 0
while i < n and lst[i] <= b:
s += lst[i]
if s > d:
s = 0
c += 1
i += 1
print(c)
``` | 0 | |
740 | B | Alyona and flowers | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | null | null | Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choos... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother.
The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100).
The next *m* lines contain the description of the ... | Print single integer — the maximum possible value added to the Alyona's happiness. | [
"5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n",
"4 3\n1 2 3 4\n1 3\n2 4\n1 1\n",
"2 2\n-1 -2\n1 1\n1 2\n"
] | [
"7\n",
"16\n",
"0\n"
] | The first example is the situation described in the statements.
In the second example Alyona should choose all subarrays.
The third example has answer 0 because Alyona can choose none of the subarrays. | 1,000 | [
{
"input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4",
"output": "7"
},
{
"input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1",
"output": "16"
},
{
"input": "2 2\n-1 -2\n1 1\n1 2",
"output": "0"
},
{
"input": "5 6\n1 1 1 -1 0\n2 4\n1 3\n4 5\n1 5\n1 4\n4 5",
"output": "8"
},
{
"inpu... | 1,480,494,695 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 61 | 0 | import math
str = input().split()
n = int(str[0])
m = int(str[1])
arr = [int(i) for i in input().split()]
su = 0
for k in range(m):
str1 = input().split()
n1 = int(str1[0])-1
m1 = int(str1[1])
k = arr[n1:m1]
z = sum(k)
if z>0:
su+= z
print(su)
| Title: Alyona and flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarra... | ```python
import math
str = input().split()
n = int(str[0])
m = int(str[1])
arr = [int(i) for i in input().split()]
su = 0
for k in range(m):
str1 = input().split()
n1 = int(str1[0])-1
m1 = int(str1[1])
k = arr[n1:m1]
z = sum(k)
if z>0:
su+= z
print(su)
``` | 3 | |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,578,983,315 | 1,115 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | s,v1,v2,t1,t2=map(int,input().split())
if v1>=t1:
r1=t1+s*v1+t1
else:
r1=t1+s*v1+t1
if v2>=t2:
r2=t2+s*v2+t2
else:
r2=t2+(s)*v2+t2
#print(r1,r2)
if r1>r2:
print("First")
elif r1<r2:
print("Second")
else:
print("Freindship")
| Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
s,v1,v2,t1,t2=map(int,input().split())
if v1>=t1:
r1=t1+s*v1+t1
else:
r1=t1+s*v1+t1
if v2>=t2:
r2=t2+s*v2+t2
else:
r2=t2+(s)*v2+t2
#print(r1,r2)
if r1>r2:
print("First")
elif r1<r2:
print("Second")
else:
print("Freindship")
``` | 0 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,516,589,291 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 5,632,000 | r, g, b = list(map(int, input().split()))
print(max(r // 3 + g // 3 + b // 3, (r-1) // 3 + (g-1) // 3 + (b-1) // 3, (r-2) // 3 + (g-2) // 3 + (b-2) // 3))
| Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
r, g, b = list(map(int, input().split()))
print(max(r // 3 + g // 3 + b // 3, (r-1) // 3 + (g-1) // 3 + (b-1) // 3, (r-2) // 3 + (g-2) // 3 + (b-2) // 3))
``` | 0 | |
225 | A | Dice Tower | PROGRAMMING | 1,100 | [
"constructive algorithms",
"greedy"
] | null | null | A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
Alice... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower.
The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=... | Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes). | [
"3\n6\n3 2\n5 4\n2 4\n",
"3\n3\n2 6\n4 1\n5 3\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "3\n6\n3 2\n5 4\n2 4",
"output": "YES"
},
{
"input": "3\n3\n2 6\n4 1\n5 3",
"output": "NO"
},
{
"input": "1\n3\n2 1",
"output": "YES"
},
{
"input": "2\n2\n3 1\n1 5",
"output": "NO"
},
{
"input": "3\n2\n1 4\n5 3\n6 4",
"output": "NO"
},
{
"in... | 1,691,774,026 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 52 | 124 | 0 | n=int(input())
x=int(input())
y=7-x
flag=1
for i in range(n):
a,b=map(int,input().split())
if(a==x or (7-a)==x or b==x or (7-b)==x or a==y or (7-a)==y or b==y or (7-b)==y):
flag=0
print("YES")if(flag)else print("NO") | Title: Dice Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other... | ```python
n=int(input())
x=int(input())
y=7-x
flag=1
for i in range(n):
a,b=map(int,input().split())
if(a==x or (7-a)==x or b==x or (7-b)==x or a==y or (7-a)==y or b==y or (7-b)==y):
flag=0
print("YES")if(flag)else print("NO")
``` | 3 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,551,185,106 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 248 | 0 | n=int(input())
l=list(map(int,input().split()))
a,b=[],[]
for x in l:
if x%2==0:
a.append(x)
else:
b.append(x)
if len(a)>len(b):
c=b[0]
else:
c=a[0]
print(l.index(c)+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())
l=list(map(int,input().split()))
a,b=[],[]
for x in l:
if x%2==0:
a.append(x)
else:
b.append(x)
if len(a)>len(b):
c=b[0]
else:
c=a[0]
print(l.index(c)+1)
``` | 3.938 |
768 | B | Code For 1 | PROGRAMMING | 1,600 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer"
] | null | null | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s... | The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=<<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list. | Output the total number of 1s in the range *l* to *r* in the final sequence. | [
"7 2 5\n",
"10 3 10\n"
] | [
"4\n",
"5\n"
] | Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.
For the second example:
<img al... | 1,000 | [
{
"input": "7 2 5",
"output": "4"
},
{
"input": "10 3 10",
"output": "5"
},
{
"input": "56 18 40",
"output": "20"
},
{
"input": "203 40 124",
"output": "67"
},
{
"input": "903316762502 354723010040 354723105411",
"output": "78355"
},
{
"input": "335343... | 1,679,665,318 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | n,r,l=list(map(int,input().split()))
a=[]
b=[]
c=[]
L=0
i=0
j=0
cnt=0
cntt=0
while n>1:
e = n % 2
n=n//2
b.append(e)
cnt+=1
b.reverse()
a.append(n)
c.extend(a)
c.append(b[0])
c.extend(a)
for i in range (1,cnt):
L=len(c)
c.extend(c)
c.insert(L,b[i])
for j in range(r,l+1):
if c[j]==1:
... | Title: Code For 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and ta... | ```python
n,r,l=list(map(int,input().split()))
a=[]
b=[]
c=[]
L=0
i=0
j=0
cnt=0
cntt=0
while n>1:
e = n % 2
n=n//2
b.append(e)
cnt+=1
b.reverse()
a.append(n)
c.extend(a)
c.append(b[0])
c.extend(a)
for i in range (1,cnt):
L=len(c)
c.extend(c)
c.insert(L,b[i])
for j in range(r,l+1):
if c[... | 0 | |
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,590,146,628 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 654 | 10,137,600 | if 1:
from fractions import *
a,b=map(int,input().split())
if a==1 and b==1:
print(1)
else:
print(Fraction((6-(max(a,b))+1)/6))
| 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
if 1:
from fractions import *
a,b=map(int,input().split())
if a==1 and b==1:
print(1)
else:
print(Fraction((6-(max(a,b))+1)/6))
``` | 0 |
195 | A | Let's Watch Football | PROGRAMMING | 1,000 | [
"binary search",
"brute force",
"math"
] | null | null | Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si... | The first line contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=1000,<=*a*<=><=*b*). The first number (*a*) denotes the size of data needed to watch one second of the video. The second number (*b*) denotes the size of data Valeric and Valerko can download from the Net per second. T... | Print a single number — the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses. | [
"4 1 1\n",
"10 3 2\n",
"13 12 1\n"
] | [
"3\n",
"5\n",
"1\n"
] | In the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 · 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watch... | 500 | [
{
"input": "4 1 1",
"output": "3"
},
{
"input": "10 3 2",
"output": "5"
},
{
"input": "13 12 1",
"output": "1"
},
{
"input": "2 1 3",
"output": "3"
},
{
"input": "6 2 4",
"output": "8"
},
{
"input": "5 2 1",
"output": "2"
},
{
"input": "2 1... | 1,686,594,703 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 154 | 2,867,200 | import sys
from typing import List
if not __debug__:
input = open("hack.txt", "r").readline
else:
input = sys.stdin.readline
a, b, c = list(map(int, input().strip().split()))
l, r = 0, c
while l < r:
m = (l + r) // 2
if (m + c) * b >= a * c:
r = m
else:
l = m + 1
print(l)
| Title: Let's Watch Football
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn ... | ```python
import sys
from typing import List
if not __debug__:
input = open("hack.txt", "r").readline
else:
input = sys.stdin.readline
a, b, c = list(map(int, input().strip().split()))
l, r = 0, c
while l < r:
m = (l + r) // 2
if (m + c) * b >= a * c:
r = m
else:
l = m + 1
pri... | 0 | |
879 | B | Table Tennis | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | null | null | *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of t... | The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all ... | Output a single integer — power of the winner. | [
"2 2\n1 2\n",
"4 2\n3 1 2 4\n",
"6 2\n6 5 3 1 2 4\n",
"2 10000000000\n2 1\n"
] | [
"2 ",
"3 ",
"6 ",
"2\n"
] | Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | 1,000 | [
{
"input": "2 2\n1 2",
"output": "2 "
},
{
"input": "4 2\n3 1 2 4",
"output": "3 "
},
{
"input": "6 2\n6 5 3 1 2 4",
"output": "6 "
},
{
"input": "2 10000000000\n2 1",
"output": "2"
},
{
"input": "4 4\n1 3 4 2",
"output": "4 "
},
{
"input": "2 21474836... | 1,657,896,244 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 2,000 | 0 |
str1 = input()
str1 = str1.split(" ")
n = int(str1[0])
v = int(str1[1])
list1 = []
str2 = input()
str2 = str2.split(" ")
for i in range(n):
pow = int(str2[i])
list1.append(pow)
# print(list1)
a = list1[0]
vic =0
while vic < v:
j = 1
b = list1[j]
if a > b:
list1.remove(b)
list1.appen... | Title: Table Tennis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so o... | ```python
str1 = input()
str1 = str1.split(" ")
n = int(str1[0])
v = int(str1[1])
list1 = []
str2 = input()
str2 = str2.split(" ")
for i in range(n):
pow = int(str2[i])
list1.append(pow)
# print(list1)
a = list1[0]
vic =0
while vic < v:
j = 1
b = list1[j]
if a > b:
list1.remove(b)
l... | 0 | |
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,646,428,697 | 2,147,483,647 | Python 3 | OK | TESTS | 104 | 249 | 1,433,600 | a = input()
b = input()
def check_equivalent(entrada):
if len(entrada) % 2:
return entrada
a1 = check_equivalent(entrada[:len(entrada)//2])
a2 = check_equivalent(entrada[len(entrada)//2:])
if a1 < a2:
return a1+a2
else:
return a2+a1
if check_equivalent(a) == check_equival... | Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split str... | ```python
a = input()
b = input()
def check_equivalent(entrada):
if len(entrada) % 2:
return entrada
a1 = check_equivalent(entrada[:len(entrada)//2])
a2 = check_equivalent(entrada[len(entrada)//2:])
if a1 < a2:
return a1+a2
else:
return a2+a1
if check_equivalent(a) == che... | 3 | |
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all... | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3... | 1,692,996,568 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 2,000 | 15,052,800 |
def maxdivpower(n, div):
for i in range(25):
if int(n/div**i)!=n/div**i:
return i-1
n = int(input())
mat = [[int(a) for a in input().split()] for _ in range(n)]
m = len(mat[0])
def calc(div):
dp = {}
for x in range(n):
for y in range(m):
v = mat[x][y]
... | Title: The least round way
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down fro... | ```python
def maxdivpower(n, div):
for i in range(25):
if int(n/div**i)!=n/div**i:
return i-1
n = int(input())
mat = [[int(a) for a in input().split()] for _ in range(n)]
m = len(mat[0])
def calc(div):
dp = {}
for x in range(n):
for y in range(m):
v = mat[x][y]... | 0 |
785 | B | Anton and Classes | PROGRAMMING | 1,100 | [
"greedy",
"sortings"
] | null | null | Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.
Anton has *n* variants when he will attend chess classes, *i*-th variant is given by a period of time (*l*1,<=*i*,<=*r*1,<=*i*). Also he has *m* variants when he will attend programmin... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of time periods when Anton can attend chess classes.
Each of the following *n* lines of the input contains two integers *l*1,<=*i* and *r*1,<=*i* (1<=≤<=*l*1,<=*i*<=≤<=*r*1,<=*i*<=≤<=109) — the *i*-th variant of a period of... | Output one integer — the maximal possible distance between time periods. | [
"3\n1 5\n2 6\n2 3\n2\n2 4\n6 8\n",
"3\n1 5\n2 6\n3 7\n2\n2 4\n1 4\n"
] | [
"3\n",
"0\n"
] | In the first sample Anton can attend chess classes in the period (2, 3) and attend programming classes in the period (6, 8). It's not hard to see that in this case the distance between the periods will be equal to 3.
In the second sample if he chooses any pair of periods, they will intersect. So the answer is 0. | 1,000 | [
{
"input": "3\n1 5\n2 6\n2 3\n2\n2 4\n6 8",
"output": "3"
},
{
"input": "3\n1 5\n2 6\n3 7\n2\n2 4\n1 4",
"output": "0"
},
{
"input": "20\n13 141\n57 144\n82 124\n16 23\n18 44\n64 65\n117 133\n84 117\n77 142\n40 119\n105 120\n71 92\n5 142\n48 132\n106 121\n5 80\n45 92\n66 81\n7 93\n27 71\... | 1,687,869,175 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 73 | 2,308 | 12,185,600 | # full logic before coding
# test_cases = int(input())
# for test_case in range(test_cases):
n = int(input())
max_l1 = 0
min_r1 = 10**9 + 1
for i in range(n):
l1, r1 = map(int, input().split())
if l1 > max_l1:
max_l1 = l1
if r1 < min_r1:
min_r1 = r1
m = int(input())
max_l2... | Title: Anton and Classes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.
Anton has *n* variants when he will attend chess classes, *i*-th variant is given... | ```python
# full logic before coding
# test_cases = int(input())
# for test_case in range(test_cases):
n = int(input())
max_l1 = 0
min_r1 = 10**9 + 1
for i in range(n):
l1, r1 = map(int, input().split())
if l1 > max_l1:
max_l1 = l1
if r1 < min_r1:
min_r1 = r1
m = int(input(... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,665,470,541 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 |
#1
'''
b=int(input())
a=input()
cnt=0
for i in range(len(a)-1):
if a[i]==a[i+1]:
cnt+=1
print(cnt)
'''
#2
'''
teams=input()
cnt=1
flag=0
for i in range(1,len(teams)):
if teams[i]==teams[i-1]:
cnt+=1
else:
cnt=1
if cnt>=7:
flag=1
break
... | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
#1
'''
b=int(input())
a=input()
cnt=0
for i in range(len(a)-1):
if a[i]==a[i+1]:
cnt+=1
print(cnt)
'''
#2
'''
teams=input()
cnt=1
flag=0
for i in range(1,len(teams)):
if teams[i]==teams[i-1]:
cnt+=1
else:
cnt=1
if cnt>=7:
flag=1
... | 0 |
467 | B | Fedor and New Game | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"constructive algorithms",
"implementation"
] | null | null | After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».
The game has (*m*<=+<=1) players and *n* types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (*m*<=+<=1). Types of soldiers are numbered from 0 to *n... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=20; 1<=≤<=*m*<=≤<=1000).
The *i*-th of the next (*m*<=+<=1) lines contains a single integer *x**i* (1<=≤<=*x**i*<=≤<=2*n*<=-<=1), that describes the *i*-th player's army. We remind you that Fedor is the (*m*<=+<=1)-th player. | Print a single integer — the number of Fedor's potential friends. | [
"7 3 1\n8\n5\n111\n17\n",
"3 3 3\n1\n2\n3\n4\n"
] | [
"0\n",
"3\n"
] | none | 1,000 | [
{
"input": "7 3 1\n8\n5\n111\n17",
"output": "0"
},
{
"input": "3 3 3\n1\n2\n3\n4",
"output": "3"
},
{
"input": "4 2 2\n5\n6\n7",
"output": "2"
},
{
"input": "4 7 4\n9\n10\n5\n12\n4\n12\n7\n10",
"output": "7"
},
{
"input": "2 7 2\n1\n1\n1\n1\n1\n1\n1\n1",
"out... | 1,691,472,713 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 93 | 2,457,600 | n,m,k = map(int,input().split())
a = []
for i in range(m+1):
a.append(int(input()))
last = format(a[-1], '#024b')
count = 0
res = 0
for i in range(m):
count = 0
tmp = format(a[i], '#024b')
for j in range(24):
if last[j]!=tmp[j]:
count+=1
if count<=k:
res+... | Title: Fedor and New Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».
The game has (*m*<=+<=1) players and *n* types of soldiers in total. Play... | ```python
n,m,k = map(int,input().split())
a = []
for i in range(m+1):
a.append(int(input()))
last = format(a[-1], '#024b')
count = 0
res = 0
for i in range(m):
count = 0
tmp = format(a[i], '#024b')
for j in range(24):
if last[j]!=tmp[j]:
count+=1
if count<=k:
... | 3 | |
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 53... | 1,684,731,663 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 33 | 92 | 0 | input()
s=[int(i) for i in input().split()]
if len(s)==1:
print('YES')
elif len(s)==3:
print('YES')
else:
k=max(s, key=s.count)
if s.count(k)>len(s)//2:
print('NO')
else:
print('YES') | Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would... | ```python
input()
s=[int(i) for i in input().split()]
if len(s)==1:
print('YES')
elif len(s)==3:
print('YES')
else:
k=max(s, key=s.count)
if s.count(k)>len(s)//2:
print('NO')
else:
print('YES')
``` | 0 | |
215 | B | Olympic Medal | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=<<=*r*2<=<<=*r*1) made of metal with density *p*1 g/cm3. The second part is an inner disk with radius *r*2 cm, it is made of metal with density *p*2 g/... | The first input line contains an integer *n* and a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*. The second input line contains an integer *m* and a sequence of integers *y*1,<=*y*2,<=...,<=*y**m*. The third input line contains an integer *k* and a sequence of integers *z*1,<=*z*2,<=...,<=*z**k*. The last line conta... | Print a single real number — the sought value *r*2 with absolute or relative error of at most 10<=-<=6. It is guaranteed that the solution that meets the problem requirements exists. | [
"3 1 2 3\n1 2\n3 3 2 1\n1 2\n",
"4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1\n"
] | [
"2.683281573000\n",
"2.267786838055\n"
] | In the first sample the jury should choose the following values: *r*<sub class="lower-index">1</sub> = 3, *p*<sub class="lower-index">1</sub> = 2, *p*<sub class="lower-index">2</sub> = 1. | 500 | [
{
"input": "3 1 2 3\n1 2\n3 3 2 1\n1 2",
"output": "2.683281573000"
},
{
"input": "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1",
"output": "2.267786838055"
},
{
"input": "1 5\n1 3\n1 7\n515 892",
"output": "3.263613058533"
},
{
"input": "2 3 2\n3 2 3 1\n2 2 1\n733 883",
"output": "2.... | 1,660,157,193 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 614,400 | x=input().split() ; numr1,r1=int(x[0]),list(map(int,x[1:]))
x=input().split() ; nump1,p1=int(x[0]),list(map(int,x[1:]))
x=input().split() ;nump2,p2=int(x[0]),list(map(int,x[1:]))
A,B=list(map(int,input().split()))
print(max(r1)*(B*max(p1)/(B*max(p1)+min(p2)*A))**.5) | Title: Olympic Medal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=<<=*r*2<=<<=*r*1) made of metal with density *p*1 g/... | ```python
x=input().split() ; numr1,r1=int(x[0]),list(map(int,x[1:]))
x=input().split() ; nump1,p1=int(x[0]),list(map(int,x[1:]))
x=input().split() ;nump2,p2=int(x[0]),list(map(int,x[1:]))
A,B=list(map(int,input().split()))
print(max(r1)*(B*max(p1)/(B*max(p1)+min(p2)*A))**.5)
``` | 3 | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,675,649,074 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 46 | 0 | s = str(input())
o = ""
for c in s:
if c=='h' or c=='e' or c=='i' or c=='d':
o+=c
c1 = 0
c2 = 0
c3 = 0
c4 = 0
c5 = 0
for c in o:
if c=='h':
c1=1
elif c=='e' and c1 ==1: c2=1
elif c=='i' and c4==1: c5 =1
elif c=='i' and c2==1: c3=1
elif c=='d' and c3==1: c4=1
... | Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
s = str(input())
o = ""
for c in s:
if c=='h' or c=='e' or c=='i' or c=='d':
o+=c
c1 = 0
c2 = 0
c3 = 0
c4 = 0
c5 = 0
for c in o:
if c=='h':
c1=1
elif c=='e' and c1 ==1: c2=1
elif c=='i' and c4==1: c5 =1
elif c=='i' and c2==1: c3=1
elif c=='d' and c3==1:... | 3 | |
696 | A | Lorenzo Von Matterhorn | PROGRAMMING | 1,500 | [
"brute force",
"data structures",
"implementation",
"trees"
] | null | null | Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections *i* and 2*i* and another road between *i* and 2*i*<=+<=1 for every positive integer *i*. You can clearly see that there exists a unique shortest path bet... | The first line of input contains a single integer *q* (1<=≤<=*q*<=≤<=1<=000).
The next *q* lines contain the information about the events in chronological order. Each event is described in form 1 *v* *u* *w* if it's an event when government makes a new rule about increasing the passing fee of all roads on the shortest... | For each event of second type print the sum of passing fee of all roads Barney passes in this event, in one line. Print the answers in chronological order of corresponding events. | [
"7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4\n"
] | [
"94\n0\n32\n"
] | In the example testcase:
Here are the intersections used:
1. Intersections on the path are 3, 1, 2 and 4. 1. Intersections on the path are 4, 2 and 1. 1. Intersections on the path are only 3 and 6. 1. Intersections on the path are 4, 2, 1 and 3. Passing fee of roads on the path are 32, 32 and 30 in order. So answ... | 500 | [
{
"input": "7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4",
"output": "94\n0\n32"
},
{
"input": "1\n2 666077344481199252 881371880336470888",
"output": "0"
},
{
"input": "10\n1 1 63669439577744021 396980128\n1 2582240553355225 63669439577744021 997926286\n1 258224055335522... | 1,594,128,821 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 389 | 37,376,000 | def find_path(x,y):
p1,p2 = [],[]
while x!=0:
p1.append(x)
x = x//2
while y!=0:
p2.append(y)
y = y//2
p1 = p1[::-1]
p2 = p2[::-1]
# print (p1,p2)
for i in range(min(len(p1),len(p2))):
if p1[i]==p2[i]:
ind = i
else:
break
path = []
for i in range(ind,len(p1)):
path.append(p1[i])
path = path... | Title: Lorenzo Von Matterhorn
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections *i* and 2*i* and another road between *i* and... | ```python
def find_path(x,y):
p1,p2 = [],[]
while x!=0:
p1.append(x)
x = x//2
while y!=0:
p2.append(y)
y = y//2
p1 = p1[::-1]
p2 = p2[::-1]
# print (p1,p2)
for i in range(min(len(p1),len(p2))):
if p1[i]==p2[i]:
ind = i
else:
break
path = []
for i in range(ind,len(p1)):
path.append(p1[i])
p... | 3 | |
332 | A | Down the Hatch! | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to pl... | The first line contains a single integer *n* (4<=≤<=*n*<=≤<=2000) — the number of participants in the game. The second line describes the actual game: the *i*-th character of this line equals 'a', if the participant who moved *i*-th pointed at the next person with his elbow, and 'b', if the participant pointed with a n... | Print a single integer — the number of glasses of juice Vasya could have drunk if he had played optimally well. | [
"4\nabbba\n",
"4\nabbab\n"
] | [
"1\n",
"0\n"
] | In both samples Vasya has got two turns — 1 and 5. In the first sample, Vasya could have drunk a glass of juice during the fifth turn if he had pointed at the next person with a nod. In this case, the sequence of moves would look like "abbbb". In the second sample Vasya wouldn't drink a single glass of juice as the mov... | 500 | [
{
"input": "4\nabbba",
"output": "1"
},
{
"input": "4\nabbab",
"output": "0"
},
{
"input": "4\naaa",
"output": "0"
},
{
"input": "4\naab",
"output": "0"
},
{
"input": "4\naabaabbba",
"output": "1"
},
{
"input": "6\naaaaaaaaaaaaaaaa",
"output": "2"
... | 1,685,264,244 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;
string s;
cin >> n >> s;
ll count=0;
for(int i=n;i<s.length();i+=n)
{
if(s[i-1] == s[i-2] && s[i-2] == s[i-3])
count++;
}
cout << count << "\n";
return 0;
}
... | Title: Down the Hatch!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and th... | ```python
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;
string s;
cin >> n >> s;
ll count=0;
for(int i=n;i<s.length();i+=n)
{
if(s[i-1] == s[i-2] && s[i-2] == s[i-3])
count++;
}
cout << count << "\n";
return 0;
}
... | -1 | |
845 | B | Luba And The Ticket | PROGRAMMING | 1,600 | [
"brute force",
"greedy",
"implementation"
] | null | null | Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of las... | You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0. | Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky. | [
"000000\n",
"123456\n",
"111000\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one re... | 0 | [
{
"input": "000000",
"output": "0"
},
{
"input": "123456",
"output": "2"
},
{
"input": "111000",
"output": "1"
},
{
"input": "120111",
"output": "0"
},
{
"input": "999999",
"output": "0"
},
{
"input": "199880",
"output": "1"
},
{
"input": "... | 1,686,758,521 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 145 | 311 | 16,691,200 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
from decimal import *
S = [int(x) for x in input()]
ans = float('inf')
for a in ran... | Title: Luba And The Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make th... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
from decimal import *
S = [int(x) for x in input()]
ans = float('inf')
fo... | 3 | |
789 | A | Anastasia and pebbles | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same tim... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | [
"3 2\n2 3 4\n",
"5 4\n3 1 8 9 7\n"
] | [
"3\n",
"5\n"
] | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she... | 500 | [
{
"input": "3 2\n2 3 4",
"output": "3"
},
{
"input": "5 4\n3 1 8 9 7",
"output": "5"
},
{
"input": "1 22\n1",
"output": "1"
},
{
"input": "3 57\n78 165 54",
"output": "3"
},
{
"input": "5 72\n74 10 146 189 184",
"output": "6"
},
{
"input": "9 13\n132 8... | 1,537,788,663 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 170 | 5,939,200 | _, k = map(int, input().split())
print((sum((w + k - 1) // k for w in map(int, input().split())) + 1) // 2 ) | Title: Anastasia and pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could ... | ```python
_, k = map(int, input().split())
print((sum((w + k - 1) // k for w in map(int, input().split())) + 1) // 2 )
``` | 3 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,691,646,743 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 41 | 62 | 0 | s = input()
count = 0
chk = -1
for i in range(len(s)-1):
if s[i+1] == s[i]:
count += 1
if count == 7:
print('YES')
chk = 0
break
else:
count = 1
if chk == -1:
print('NO')
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
s = input()
count = 0
chk = -1
for i in range(len(s)-1):
if s[i+1] == s[i]:
count += 1
if count == 7:
print('YES')
chk = 0
break
else:
count = 1
if chk == -1:
print('NO')
``` | 0 |
82 | B | Sets | PROGRAMMING | 1,700 | [
"constructive algorithms",
"hashing",
"implementation"
] | B. Sets | 2 | 256 | Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose *n* non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possib... | The first input file line contains a number *n* (2<=≤<=*n*<=≤<=200), *n* is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on *n*·(*n*<=-<=1)<=/<=2 lines. Each set starts with the number *k**i* (2<=≤<=*k**i*<=≤<=200), which is the number of numbers written of the *i... | Print on *n* lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order... | [
"4\n3 2 7 4\n3 1 7 3\n3 5 4 2\n3 1 3 5\n4 3 1 2 4\n2 5 7\n",
"4\n5 6 7 8 9 100\n4 7 8 9 1\n4 7 8 9 2\n3 1 6 100\n3 2 6 100\n2 1 2\n",
"3\n2 1 2\n2 1 3\n2 2 3\n"
] | [
"1 7 \n2 2 4 \n2 1 3 \n1 5 \n",
"3 7 8 9 \n2 6 100 \n1 1 \n1 2 \n",
"1 1 \n1 2 \n1 3 \n"
] | none | 1,000 | [
{
"input": "4\n3 2 7 4\n3 1 7 3\n3 5 4 2\n3 1 3 5\n4 3 1 2 4\n2 5 7",
"output": "1 7 \n2 2 4 \n2 1 3 \n1 5 "
},
{
"input": "4\n5 6 7 8 9 100\n4 7 8 9 1\n4 7 8 9 2\n3 1 6 100\n3 2 6 100\n2 1 2",
"output": "3 7 8 9 \n2 6 100 \n1 1 \n1 2 "
},
{
"input": "3\n2 1 2\n2 1 3\n2 2 3",
"output... | 1,637,696,541 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 32 | 1,466 | 2,457,600 | import math
#s = input()
#n = int(input())
#n= (map(int, input().split()))
my_list = list()
list_mn = list()
#n, m, k =(map(int, input().split()))
def recurse(my_set_):
for i in my_list:
set_ = my_set_& i
if(len(set_)):
set_ = i - set_
if(set_ in list_mn):
... | Title: Sets
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose *n* non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his ... | ```python
import math
#s = input()
#n = int(input())
#n= (map(int, input().split()))
my_list = list()
list_mn = list()
#n, m, k =(map(int, input().split()))
def recurse(my_set_):
for i in my_list:
set_ = my_set_& i
if(len(set_)):
set_ = i - set_
if(set_ in l... | 0 |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,697,464,308 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | #CodeForce Round 116a Tram
n = int(input())
passenger = 0
cap = 0
for i in range(n):
o,i = map(int,input().split())
passenger = passenger - o + i
cap = max(cap, passenger)
print(cap) | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
#CodeForce Round 116a Tram
n = int(input())
passenger = 0
cap = 0
for i in range(n):
o,i = map(int,input().split())
passenger = passenger - o + i
cap = max(cap, passenger)
print(cap)
``` | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,689,393,631 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | integer = int(input())
list1 = []
for x in range(0,integer):
nums = input().split()
for num in nums:
num = int(num)
list1.append(num)
if sum(list1) == 0:
print('YES')
else:
print("NO")
print(list1) | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
integer = int(input())
list1 = []
for x in range(0,integer):
nums = input().split()
for num in nums:
num = int(num)
list1.append(num)
if sum(list1) == 0:
print('YES')
else:
print("NO")
print(list1)
``` | 0 |
813 | B | The Golden Age | PROGRAMMING | 1,800 | [
"brute force",
"math"
] | null | null | Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 and 17 are unlucky (4<==<=20<=+<=31, 17<==<=23<=+<=32<==<=24<=+<=30) and year 18 isn't unlucky as the... | The first line contains four integer numbers *x*, *y*, *l* and *r* (2<=≤<=*x*,<=*y*<=≤<=1018, 1<=≤<=*l*<=≤<=*r*<=≤<=1018). | Print the maximum length of The Golden Age within the interval [*l*,<=*r*].
If all years in the interval [*l*,<=*r*] are unlucky then print 0. | [
"2 3 1 10\n",
"3 5 10 22\n",
"2 3 3 5\n"
] | [
"1\n",
"8\n",
"0\n"
] | In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].
In the second example the longest Golden Age is the interval [15, 22]. | 0 | [
{
"input": "2 3 1 10",
"output": "1"
},
{
"input": "3 5 10 22",
"output": "8"
},
{
"input": "2 3 3 5",
"output": "0"
},
{
"input": "2 2 1 10",
"output": "1"
},
{
"input": "2 2 1 1000000",
"output": "213568"
},
{
"input": "2 2 1 1000000000000000000",
... | 1,499,807,654 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 77 | 5,529,600 | x, y, l, r = map(int, list(input().split(' ')))
ar = []
x1 = 1
for i in range(1, 70):
y1 = 1
for j in range(1, 70):
ar.append(x1 + y1)
#if x1 + y1 == 22:
#print("AAAAAAAAAAAA {} {}".format(x1, y1))
y1 *= y
if y1 > r:
break
x1 *= x
if x... | Title: The Golden Age
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 a... | ```python
x, y, l, r = map(int, list(input().split(' ')))
ar = []
x1 = 1
for i in range(1, 70):
y1 = 1
for j in range(1, 70):
ar.append(x1 + y1)
#if x1 + y1 == 22:
#print("AAAAAAAAAAAA {} {}".format(x1, y1))
y1 *= y
if y1 > r:
break
x1 *= x... | 3 | |
476 | B | Dreamoon and WiFi | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"combinatorics",
"dp",
"math",
"probabilities"
] | null | null | Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, de... | The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes ... | Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. | [
"++-+-\n+-+-+\n",
"+-+-\n+-??\n",
"+++\n??-\n"
] | [
"1.000000000000\n",
"0.500000000000\n",
"0.000000000000\n"
] | For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="low... | 1,500 | [
{
"input": "++-+-\n+-+-+",
"output": "1.000000000000"
},
{
"input": "+-+-\n+-??",
"output": "0.500000000000"
},
{
"input": "+++\n??-",
"output": "0.000000000000"
},
{
"input": "++++++++++\n+++??++?++",
"output": "0.125000000000"
},
{
"input": "--+++---+-\n????????... | 1,663,272,427 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 93 | 1,843,200 | import itertools
s1 = input()
s2 = input()
lst1 = list(s1)
lst2 = list(s2)
pos1 = 0
pos2 = 0
n = 0
for i in range(len(lst1)):
if lst1[i] == '+':
pos1 +=1
else:
pos1 -=1
if lst2[i] == '+':
pos2 +=1
elif lst2[i] == '-':
pos2 -=1
else:
n +=1
p... | Title: Dreamoon and WiFi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go... | ```python
import itertools
s1 = input()
s2 = input()
lst1 = list(s1)
lst2 = list(s2)
pos1 = 0
pos2 = 0
n = 0
for i in range(len(lst1)):
if lst1[i] == '+':
pos1 +=1
else:
pos1 -=1
if lst2[i] == '+':
pos2 +=1
elif lst2[i] == '-':
pos2 -=1
else:
... | 3 | |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate... | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": ... | 1,649,214,732 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | x = int(input())
y=[]
z=[]
for i in range(1,x):
y += [int(input())]
for i in range(x):
c = 0
while i>=0:
i=y[i]-1
c+=1
y += [c]
u=0
for i in y:
if int(i)>u:
u=i
print(u)
| Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an... | ```python
x = int(input())
y=[]
z=[]
for i in range(1,x):
y += [int(input())]
for i in range(x):
c = 0
while i>=0:
i=y[i]-1
c+=1
y += [c]
u=0
for i in y:
if int(i)>u:
u=i
print(u)
``` | 0 | |
12 | E | Start of the session | PROGRAMMING | 2,100 | [
"constructive algorithms"
] | E. Start of the season | 2 | 256 | Before the start of the football season in Berland a strange magic ritual is held. The most experienced magicians have to find a magic matrix of the size *n*<=×<=*n* (*n* is even number). Gods will never allow to start the championship without it. Matrix should contain integers from 0 to *n*<=-<=1, main diagonal should... | The first line contains one integer *n* (2<=≤<=*n*<=≤<=1000), *n* is even. | Output *n* lines with *n* numbers each — the required matrix. Separate numbers with spaces. If there are several solutions, output any. | [
"2\n",
"4\n"
] | [
"0 1\n1 0\n",
"0 1 3 2\n1 0 2 3\n3 2 0 1\n2 3 1 0\n"
] | none | 0 | [
{
"input": "2",
"output": "0 1\n1 0"
},
{
"input": "4",
"output": "0 1 3 2\n1 0 2 3\n3 2 0 1\n2 3 1 0"
},
{
"input": "6",
"output": "0 1 4 2 5 3\n1 0 2 5 3 4\n4 2 0 3 1 5\n2 5 3 0 4 1\n5 3 1 4 0 2\n3 4 5 1 2 0"
},
{
"input": "8",
"output": "0 1 5 2 6 3 7 4\n1 0 2 6 3 7 4 ... | 1,675,300,417 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n = int(input())
n2 = n//2
res = [[-1]*n for _ in range(n)]
for i in range(n2):
for j in range(n2-1-i,-1,-1):
res[2*(n2-1-i-j)][2*j] = 2*(n2-1-i)
res[2*(n2-1-i-j)][2*j+1] = 2*(n2-1-i)+1
res[2*(n2-1-i-j)+1][2*j] = 2*(n2-1-i)+1
res[2*(n2-1-i-j)+1][2*j+1] = 2*(n2-1-i)
for... | Title: Start of the session
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Before the start of the football season in Berland a strange magic ritual is held. The most experienced magicians have to find a magic matrix of the size *n*<=×<=*n* (*n* is even number). Gods will never allow to start... | ```python
n = int(input())
n2 = n//2
res = [[-1]*n for _ in range(n)]
for i in range(n2):
for j in range(n2-1-i,-1,-1):
res[2*(n2-1-i-j)][2*j] = 2*(n2-1-i)
res[2*(n2-1-i-j)][2*j+1] = 2*(n2-1-i)+1
res[2*(n2-1-i-j)+1][2*j] = 2*(n2-1-i)+1
res[2*(n2-1-i-j)+1][2*j+1] = 2*(n2-1-i... | 0 |
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sas... | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output":... | 1,653,040,294 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 46 | 0 | x,y=input().split()
x=int(x)
y=int(y)
if((x//y)%2==0):
print("NO")
else:
print("YES")
| Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with ... | ```python
x,y=input().split()
x=int(x)
y=int(y)
if((x//y)%2==0):
print("NO")
else:
print("YES")
``` | 3 | |
224 | B | Array | PROGRAMMING | 1,500 | [
"bitmasks",
"implementation",
"two pointers"
] | null | null | You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers.
Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤... | The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). | Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. | [
"4 2\n1 2 2 3\n",
"8 3\n1 1 2 2 3 3 4 5\n",
"7 4\n4 7 7 4 7 4 7\n"
] | [
"1 2\n",
"2 5\n",
"-1 -1\n"
] | In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sam... | 1,000 | [
{
"input": "4 2\n1 2 2 3",
"output": "1 2"
},
{
"input": "8 3\n1 1 2 2 3 3 4 5",
"output": "2 5"
},
{
"input": "7 4\n4 7 7 4 7 4 7",
"output": "-1 -1"
},
{
"input": "5 1\n1 7 2 3 2",
"output": "1 1"
},
{
"input": "1 2\n666",
"output": "-1 -1"
},
{
"inp... | 1,560,648,506 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 14 | 278 | 1,126,400 | def main():
n,k = map(int,input().split())
arr = list(map(int,input().split()))
curr = set()
indices = {}
if k == 1:
print(1,1)
return
min_l = -1
min_r = n
l = 0
for i in range(n):
curr.add(arr[i])
#print(curr)
if len(cu... | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<... | ```python
def main():
n,k = map(int,input().split())
arr = list(map(int,input().split()))
curr = set()
indices = {}
if k == 1:
print(1,1)
return
min_l = -1
min_r = n
l = 0
for i in range(n):
curr.add(arr[i])
#print(curr)
... | -1 | |
39 | J | Spelling Check | PROGRAMMING | 1,500 | [
"hashing",
"implementation",
"strings"
] | J. Spelling Check | 2 | 256 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he d... | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible... | [
"abdrakadabra\nabrakadabra\n",
"aa\na\n",
"competition\ncodeforces\n"
] | [
"1\n3\n",
"2\n1 2\n",
"0\n"
] | none | 0 | [
{
"input": "abdrakadabra\nabrakadabra",
"output": "1\n3 "
},
{
"input": "aa\na",
"output": "2\n1 2 "
},
{
"input": "competition\ncodeforces",
"output": "0"
},
{
"input": "ab\na",
"output": "1\n2 "
},
{
"input": "bb\nb",
"output": "2\n1 2 "
},
{
"input"... | 1,618,761,485 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 184 | 0 | def h_suff(s):
x = [0]
for j in range(len(s)):
x.append((x[j] + (ord(s[len(s) - j - 1]) - ord('a') + 1) * ((P ** j) % M1 % M2)) % M1 % M2)
return x
P = 27
M1 = 1000000007
M2 = 1000000009
S = input()
T = input()
pref_S = 0
suff_S = h_suff(S)
pref_T = 0
suff_T = h_suff(T)
ans = []
f... | Title: Spelling Check
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and ... | ```python
def h_suff(s):
x = [0]
for j in range(len(s)):
x.append((x[j] + (ord(s[len(s) - j - 1]) - ord('a') + 1) * ((P ** j) % M1 % M2)) % M1 % M2)
return x
P = 27
M1 = 1000000007
M2 = 1000000009
S = input()
T = input()
pref_S = 0
suff_S = h_suff(S)
pref_T = 0
suff_T = h_suff(T)
a... | 0 |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first... | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999... | 1,623,906,659 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 466 | 0 | y, k, n = map(int, input().split())
i = y//k+1
if k*i > n:
print(-1)
else:
while k*i <= n:
print(k*i-y, end=' ')
i += 1
| Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota... | ```python
y, k, n = map(int, input().split())
i = y//k+1
if k*i > n:
print(-1)
else:
while k*i <= n:
print(k*i-y, end=' ')
i += 1
``` | 3 | |
706 | B | Interesting drink | PROGRAMMING | 1,100 | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single i... | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | 1,000 | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "... | 1,693,536,014 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 1 | 109 | 5,734,400 | # INPUT
def binarySearch(list, x, low, high):
mid = (low + high) // 2
if mid < 0:
return 0
if int(list[mid]) == x:
if mid != high and int(list[mid + 1]) == x:
return binarySearch(list, x, mid + 1, high)
else:
retu... | Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha... | ```python
# INPUT
def binarySearch(list, x, low, high):
mid = (low + high) // 2
if mid < 0:
return 0
if int(list[mid]) == x:
if mid != high and int(list[mid + 1]) == x:
return binarySearch(list, x, mid + 1, high)
else:
... | -1 | |
384 | A | Coder | PROGRAMMING | 800 | [
"implementation"
] | null | null | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1).
... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard.
On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'.
If there are multiple correct answers, you can print any. | [
"2\n"
] | [
"2\nC.\n.C\n"
] | none | 500 | [
{
"input": "2",
"output": "2\nC.\n.C"
},
{
"input": "3",
"output": "5\nC.C\n.C.\nC.C"
},
{
"input": "4",
"output": "8\nC.C.\n.C.C\nC.C.\n.C.C"
},
{
"input": "10",
"output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C... | 1,657,276,733 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | n=int(input())
if n%2==0:
print((n*n)/2)
else:
print((n*n+1)/2)
if n%2!=0:
for i in range(n):
if i%2==0:
print("C."*int((n-1)/2),end="")
print("C")
else:
print(".C"*int((n-1)/2),end='')
print(".")
else:
for i ... | Title: Coder
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or... | ```python
n=int(input())
if n%2==0:
print((n*n)/2)
else:
print((n*n+1)/2)
if n%2!=0:
for i in range(n):
if i%2==0:
print("C."*int((n-1)/2),end="")
print("C")
else:
print(".C"*int((n-1)/2),end='')
print(".")
else:
... | 0 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,674,582,668 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | a,b=map(int,input().split())
print(min(a,b),end=" ")
print(int((abs(a-b))/2))
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a,b=map(int,input().split())
print(min(a,b),end=" ")
print(int((abs(a-b))/2))
``` | 3 | |
812 | A | Sagheer and Crossroads | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane... | The input consists of four lines with each line describing a road part given in a counter-clockwise order.
Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light. | On a single line, print "YES" if an accident is possible, and "NO" otherwise. | [
"1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n",
"0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n",
"1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.
In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur. | 500 | [
{
"input": "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
... | 1,496,683,882 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | def check(a,c):
if a[(c+1)%4][0]==0 and a[(c+2)%4][1]==0 and a[(c+3)%4][2]==0:
return False
else:
return True
def src(a):
f = True
for i in range(4):
if a[i][3]==1:
if sum(a[i])-a[i][3]>0:
return "YES"
f = f and check(a,i)
if f:
return "YES"
else:
return "NO"
def test():
... | Title: Sagheer and Crossroads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 l... | ```python
def check(a,c):
if a[(c+1)%4][0]==0 and a[(c+2)%4][1]==0 and a[(c+3)%4][2]==0:
return False
else:
return True
def src(a):
f = True
for i in range(4):
if a[i][3]==1:
if sum(a[i])-a[i][3]>0:
return "YES"
f = f and check(a,i)
if f:
return "YES"
else:
return "NO"
def ... | 0 | |
811 | B | Vladik and Complicated Book | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], where *p**i* denotes the number of page that should be read *i*-th in turn.
So... | First line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — permutation *P*. Note that elements in p... | For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | [
"5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n",
"6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3\n"
] | [
"Yes\nNo\nYes\nYes\nNo\n",
"Yes\nNo\nYes\nNo\nYes\n"
] | Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No". 1. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Ye... | 1,000 | [
{
"input": "5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3",
"output": "Yes\nNo\nYes\nYes\nNo"
},
{
"input": "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3",
"output": "Yes\nNo\nYes\nNo\nYes"
},
{
"input": "10 10\n10 1 6 7 9 8 4 3 5 2\n1 1 1\n4 4 4\n7 7 7\n3 3 3\n1 6 5\n2 6 2\n6... | 1,597,385,981 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 10,854,400 | n,m=map(int, input().split())
a=list(map(int, input().split()))
for _ in range(m):
l,r,x=map(int, input().split())
k=a[x-1]
#print(k)
if l-1<=x-1<=r-1:
b=a[l-1:r]
b=sorted(b)
i=b.index(k)
#print(i)
if i+l-1==x-1:
print('Yes')
... | Title: Vladik and Complicated Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<... | ```python
n,m=map(int, input().split())
a=list(map(int, input().split()))
for _ in range(m):
l,r,x=map(int, input().split())
k=a[x-1]
#print(k)
if l-1<=x-1<=r-1:
b=a[l-1:r]
b=sorted(b)
i=b.index(k)
#print(i)
if i+l-1==x-1:
print('... | 0 | |
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"inp... | 1,514,637,963 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 5,529,600 | n,a,b=map(int,input().split())
for i in range(2,(a+b)//n+1):
if a//i+b//i<n:
print(i-1)
exit()
print(1) | Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Iv... | ```python
n,a,b=map(int,input().split())
for i in range(2,(a+b)//n+1):
if a//i+b//i<n:
print(i-1)
exit()
print(1)
``` | 0 | |
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be... | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands ... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000... | 1,695,094,287 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | m=[*open(0)][1:]
e=any(len({*s})>2 for s in m)
print('YNEOS'[e|any(i[0]==l[0]for i,l in zip(m,m[1:]))::2]) | Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of... | ```python
m=[*open(0)][1:]
e=any(len({*s})>2 for s in m)
print('YNEOS'[e|any(i[0]==l[0]for i,l in zip(m,m[1:]))::2])
``` | 3.977 |
0 | none | none | none | 0 | [
"none"
] | null | null | Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at ... | The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.
The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**... | Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable. | [
"4 1 2\n1 3\n1 2\n",
"3 3 1\n2\n1 2\n1 3\n2 3\n"
] | [
"2\n",
"0\n"
] | For the first sample test, the graph looks like this:
For the second sample test, the graph looks like this: | 0 | [
{
"input": "4 1 2\n1 3\n1 2",
"output": "2"
},
{
"input": "3 3 1\n2\n1 2\n1 3\n2 3",
"output": "0"
},
{
"input": "10 3 2\n1 10\n1 2\n1 3\n4 5",
"output": "33"
},
{
"input": "1 0 1\n1",
"output": "0"
},
{
"input": "1000 0 1\n72",
"output": "499500"
},
{
... | 1,481,996,233 | 3,733 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 62 | 5,017,600 | import collections
n, m, k = [int(x) for x in input().split()]
c = set([int(x) for x in input().split()])
pa = {x:x for x in range(1, n+1)}
def get_root(x):
root = x
while pa[root] != root:
root = pa[root]
while x != root:
pa[x], x = root, pa[x]
return root
def connect(x, y):
rx,... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the no... | ```python
import collections
n, m, k = [int(x) for x in input().split()]
c = set([int(x) for x in input().split()])
pa = {x:x for x in range(1, n+1)}
def get_root(x):
root = x
while pa[root] != root:
root = pa[root]
while x != root:
pa[x], x = root, pa[x]
return root
def connect(x, y... | 0 | |
801 | B | Valued Keys | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th cha... | The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. | If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. | [
"ab\naa\n",
"nzwzl\nniwel\n",
"ab\nba\n"
] | [
"ba\n",
"xiyez\n",
"-1\n"
] | The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) = "ba". | 1,000 | [
{
"input": "ab\naa",
"output": "ba"
},
{
"input": "nzwzl\nniwel",
"output": "xiyez"
},
{
"input": "ab\nba",
"output": "-1"
},
{
"input": "r\nl",
"output": "l"
},
{
"input": "d\ny",
"output": "-1"
},
{
"input": "yvowz\ncajav",
"output": "cajav"
},... | 1,606,751,027 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 93 | 0 | x = input()
y = input()
result = ""
for i in range(len(x)):
if ord(x[i])<ord(y[i]):
print(-1)
exit(0)
elif ord(x[i])==ord(y[i]):
result+=chr(ord(x[i])+1)
else:
result+=y[i]
print(result) | Title: Valued Keys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string... | ```python
x = input()
y = input()
result = ""
for i in range(len(x)):
if ord(x[i])<ord(y[i]):
print(-1)
exit(0)
elif ord(x[i])==ord(y[i]):
result+=chr(ord(x[i])+1)
else:
result+=y[i]
print(result)
``` | 0 | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,553,979,405 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 0 | y = int(input())
o = input().split()
o = [int(i) for i in o]
o.sort()
print(o[1]) | Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
y = int(input())
o = input().split()
o = [int(i) for i in o]
o.sort()
print(o[1])
``` | 0 |
777 | B | Game of Credit Cards | PROGRAMMING | 1,300 | [
"data structures",
"dp",
"greedy",
"sortings"
] | null | null | After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on the... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use.
The second line contains *n* digits — Sherlock's credit card number.
The third line contains *n* digits — Moriarty's credit card number. | First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty. | [
"3\n123\n321\n",
"2\n88\n00\n"
] | [
"0\n2\n",
"2\n0\n"
] | First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks. | 1,000 | [
{
"input": "3\n123\n321",
"output": "0\n2"
},
{
"input": "2\n88\n00",
"output": "2\n0"
},
{
"input": "1\n4\n5",
"output": "0\n1"
},
{
"input": "1\n8\n7",
"output": "1\n0"
},
{
"input": "2\n55\n55",
"output": "0\n0"
},
{
"input": "3\n534\n432",
"out... | 1,510,500,205 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 62 | 0 | def main():
read = lambda: tuple(map(int, input().split()))
v = lambda: list(map(int, list(input())))
n = read()[0]
a, b = v(), v()
a.sort()
b.sort()
suka = 0
blya = 0
for v in b:
if v > a[0]:
break
suka += 1
for i in rang... | Title: Game of Credit Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simpl... | ```python
def main():
read = lambda: tuple(map(int, input().split()))
v = lambda: list(map(int, list(input())))
n = read()[0]
a, b = v(), v()
a.sort()
b.sort()
suka = 0
blya = 0
for v in b:
if v > a[0]:
break
suka += 1
for... | 0 | |
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabb... | 1,662,980,788 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 1,000 | 11,059,200 | import sys
input = sys.stdin.readline
a = int(input())
res = ""
for i in range(a):
if i == 0:
res += "a"
elif i % 4 == 0 or i % 4 == 3:
res += "a"
else:
res += "b"
print(res) | Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each o... | ```python
import sys
input = sys.stdin.readline
a = int(input())
res = ""
for i in range(a):
if i == 0:
res += "a"
elif i % 4 == 0 or i % 4 == 3:
res += "a"
else:
res += "b"
print(res)
``` | 0 | |
875 | A | Classroom Watch | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 500 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"i... | 1,689,600,654 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 31 | 0 | ans=[]
n = int(input())
s = len(str(n))
for i in range(n-s*9,n):
a = str(i)
p = 0
for j in a:
p += int(j)
if(i +p == n):
ans.append(i)
print(len(ans))
for y in ans:
print(y) | Title: Classroom Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answe... | ```python
ans=[]
n = int(input())
s = len(str(n))
for i in range(n-s*9,n):
a = str(i)
p = 0
for j in a:
p += int(j)
if(i +p == n):
ans.append(i)
print(len(ans))
for y in ans:
print(y)
``` | -1 | |
441 | A | Valera and Antique Items | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfec... | The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space... | In the first line, print integer *p* — the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. | [
"3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n",
"3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n"
] | [
"3\n1 2 3\n",
"0\n\n"
] | In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the... | 500 | [
{
"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000",
"output": "3\n1 2 3"
},
{
"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000",
"output": "0"
},
{
"input": "2 100001\n1 895737\n1 541571",
"output": "0"
},
{
"input": "1 1000000\n1 100... | 1,645,804,781 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 |
n,v=input().split()
n=int(n)
v=int(v)
final=[]
for i in range(n):
l=[int(i) for i in input().split()]
t=l.pop(0)
#print(l,t)
l.sort()
p=len(l)
count=0
for i in range(p):
if l[i]<v:
final.append(t)
break
print(len(final))
for i in final:
print(i,end=" ")
| Title: Valera and Antique Items
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the... | ```python
n,v=input().split()
n=int(n)
v=int(v)
final=[]
for i in range(n):
l=[int(i) for i in input().split()]
t=l.pop(0)
#print(l,t)
l.sort()
p=len(l)
count=0
for i in range(p):
if l[i]<v:
final.append(t)
break
print(len(final))
for i in final:
print(i,end=" ")
``... | 0 | |
181 | A | Series of Crimes | PROGRAMMING | 800 | [
"brute force",
"geometry",
"implementation"
] | null | null | The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital.
The capital's main detective Polycarpus took a map and m... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly.
Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A charact... | Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. | [
"3 2\n.*\n..\n**\n",
"3 3\n*.*\n*..\n...\n"
] | [
"1 1\n",
"2 3\n"
] | none | 500 | [
{
"input": "3 2\n.*\n..\n**",
"output": "1 1"
},
{
"input": "2 5\n*....\n*...*",
"output": "1 5"
},
{
"input": "7 2\n..\n**\n..\n..\n..\n..\n.*",
"output": "7 1"
},
{
"input": "7 2\n*.\n..\n..\n..\n..\n..\n**",
"output": "1 2"
},
{
"input": "2 10\n*......*..\n....... | 1,659,286,493 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 124 | 2,764,800 | n,m = map(int,input().split())
s = [list(input()) for _ in range(n)]
x = {}
y = {}
for i in range(n):
for j in range(m):
if s[i][j] == "*":
if not i in x:
x[i] = 0
if not j in y:
y[j] = 0
x[i] += 1
y[j] += 1
a = ... | Title: Series of Crimes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the ma... | ```python
n,m = map(int,input().split())
s = [list(input()) for _ in range(n)]
x = {}
y = {}
for i in range(n):
for j in range(m):
if s[i][j] == "*":
if not i in x:
x[i] = 0
if not j in y:
y[j] = 0
x[i] += 1
y[j] ... | -1 | |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,693,926,118 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 102,400 | # Read the input values
n = int(input())
results = input().strip()
# Count the number of 'A's and 'D's
anton_wins = results.count('A')
danik_wins = results.count('D')
# Compare the counts to determine the winner
if anton_wins > danik_wins:
print("Anton")
elif danik_wins > anton_wins:
print("Danik"... | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
# Read the input values
n = int(input())
results = input().strip()
# Count the number of 'A's and 'D's
anton_wins = results.count('A')
danik_wins = results.count('D')
# Compare the counts to determine the winner
if anton_wins > danik_wins:
print("Anton")
elif danik_wins > anton_wins:
pri... | 3 | |
591 | B | Rebranding | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slog... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descr... | Print the new name of the corporation. | [
"6 1\npolice\np m\n",
"11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n"
] | [
"molice\n",
"cdcbcdcfcdc\n"
] | In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.co... | 1,000 | [
{
"input": "6 1\npolice\np m",
"output": "molice"
},
{
"input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b",
"output": "cdcbcdcfcdc"
},
{
"input": "1 1\nf\nz h",
"output": "f"
},
{
"input": "1 1\na\na b",
"output": "b"
},
{
"input": "10 10\nlellelleel\ne l\n... | 1,520,841,608 | 2,408 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 5,632,000 | n, m = map(int, (input().split(" ")))
name = list(input())
for i in range(m):
inp = input().split(" ")
for j in range(n):
if name[j] == inp[0]:
name[j] = inp[1]
elif name[j] == inp[1]:
name[j] = inp[0]
print("".join(name))
| Title: Rebranding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand ... | ```python
n, m = map(int, (input().split(" ")))
name = list(input())
for i in range(m):
inp = input().split(" ")
for j in range(n):
if name[j] == inp[0]:
name[j] = inp[1]
elif name[j] == inp[1]:
name[j] = inp[0]
print("".join(name))
``` | 0 | |
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge... | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input... | 1,652,017,057 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 560 | 21,196,800 | import heapq
from sys import stdin, stdout
inf = 1000000000012
n,m = map(int, stdin.readline().strip().split())
relation = [[] for i in range(n+3)]
dis=[inf for x in range(n+3)]
par= [0 for x in range(n+3)]
for i in range(0,m):
a,b,w = map(int, stdin.readline().strip().split())
relation[a].append((b... | Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* a... | ```python
import heapq
from sys import stdin, stdout
inf = 1000000000012
n,m = map(int, stdin.readline().strip().split())
relation = [[] for i in range(n+3)]
dis=[inf for x in range(n+3)]
par= [0 for x in range(n+3)]
for i in range(0,m):
a,b,w = map(int, stdin.readline().strip().split())
relation[a]... | 3.562072 |
277 | A | Learning Languages | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu"
] | null | null | The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official la... | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of employees and the number of languages.
Then *n* lines follow — each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≤<=*k**i*<=≤<=*m*) — the number of languages the *i*-th employee knows. Next... | Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). | [
"5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n",
"8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n",
"2 2\n1 2\n0\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | 500 | [
{
"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5",
"output": "0"
},
{
"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1",
"output": "2"
},
{
"input": "2 2\n1 2\n0",
"output": "1"
},
{
"input": "2 2\n0\n0",
"output": "2"
},
{
"input": "5 5\n1 3\n0\n0\n2 4... | 1,606,762,376 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 310 | 1,536,000 | n,m = list(map(int,input().split()))
arr = []
for _ in range(n):
lang = list(map(int,input().split()))
lang = lang[1::]
lang = set(lang)
f = 0
for i in range(len(arr)):
x = arr[i].intersection(lang)
if x!=set():
arr[i].update(lang)
f = 1
... | Title: Learning Languages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have th... | ```python
n,m = list(map(int,input().split()))
arr = []
for _ in range(n):
lang = list(map(int,input().split()))
lang = lang[1::]
lang = set(lang)
f = 0
for i in range(len(arr)):
x = arr[i].intersection(lang)
if x!=set():
arr[i].update(lang)
f = 1
... | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,643,518,869 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 62 | 0 | a=input()
u=0
for i in a:
if(i>='A' and i<='Z'):
u+=1
l=len(a)-u
if(l>=u):
print(a.lower())
else:
print(a.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
a=input()
u=0
for i in a:
if(i>='A' and i<='Z'):
u+=1
l=len(a)-u
if(l>=u):
print(a.lower())
else:
print(a.upper())
``` | 3.9845 |
0 | none | none | none | 0 | [
"none"
] | null | null | Codeforces is a wonderful platform and one its feature shows how much someone contributes to the community. Every registered user has contribution — an integer number, not necessarily positive. There are *n* registered users and the *i*-th of them has contribution *t**i*.
Limak is a little polar bear and he's new into... | The first line contains four integers *n*, *k*, *b* and *c* (2<=≤<=*k*<=≤<=*n*<=≤<=200<=000,<=1<=≤<=*b*,<=*c*<=≤<=1000) — the number of registered users, the required minimum number of users with the same contribution, time needed to read and upvote a blog, and time needed to read and upvote a comment, respectively.
T... | Print the minimum number of minutes Limak will spend to get a tie between at least *k* registered users. | [
"4 3 100 30\n12 2 6 1\n",
"4 3 30 100\n12 2 6 1\n",
"6 2 987 789\n-8 42 -4 -65 -8 -8\n"
] | [
"220\n",
"190\n",
"0\n"
] | In the first sample, there are 4 registered users and Limak wants a tie between at least 3 of them. Limak should behave as follows.
- He spends 100 minutes to read one blog of the 4-th user and increase his contribution from 1 to 6. - Then he spends 4·30 = 120 minutes to read four comments of the 2-nd user and incre... | 0 | [] | 1,689,426,385 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689426385.3061762")# 1689426385.3061962 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codeforces is a wonderful platform and one its feature shows how much someone contributes to the community. Every registered user has contribution — an integer number, not necessarily positive. There are *n* registered users and t... | ```python
print("_RANDOM_GUESS_1689426385.3061762")# 1689426385.3061962
``` | 0 | |
31 | A | Worms Evolution | PROGRAMMING | 1,200 | [
"implementation"
] | A. Worms Evolution | 2 | 256 | Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. | Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. | [
"5\n1 2 3 5 7\n",
"5\n1 8 1 5 1\n"
] | [
"3 2 1\n",
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 5 7",
"output": "3 2 1"
},
{
"input": "5\n1 8 1 5 1",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "6\n86 402 133 524 405 610",
"output": "6 4 1"
},
{
"input": "8\n217 779 418 895 996 473 3 22",
"output":... | 1,594,201,557 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 248 | 20,172,800 | n = int(input())
A = list(map(int, input().split()))
for i in range(n):
for j in range(n):
if j == i:
continue
for k in range(n):
if k == i or k == j:
continue
if A[i] == A[j]+A[k]:
print(A[i], A[j], A[k])
exit()
el... | Title: Worms Evolution
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his... | ```python
n = int(input())
A = list(map(int, input().split()))
for i in range(n):
for j in range(n):
if j == i:
continue
for k in range(n):
if k == i or k == j:
continue
if A[i] == A[j]+A[k]:
print(A[i], A[j], A[k])
... | 0 |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,652,679,062 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 62 | 28,467,200 | def combination_lock():
a=input()
b=input()
c=input()
ans=0
for i in range(int(a)):
ans+=min(abs(int(b[i])-int(c[i])),10-abs(int(b[i])-int(c[i])))
print(ans)
combination_lock()
| Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
def combination_lock():
a=input()
b=input()
c=input()
ans=0
for i in range(int(a)):
ans+=min(abs(int(b[i])-int(c[i])),10-abs(int(b[i])-int(c[i])))
print(ans)
combination_lock()
``` | 3 | |
777 | C | Alyona and Spreadsheet | PROGRAMMING | 1,600 | [
"binary search",
"data structures",
"dp",
"greedy",
"implementation",
"two pointers"
] | null | null | During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By *a**i*,<=*j* we will denote the integer located at the *i*-th row and the *j*-th column. We say that the tab... | The first line of the input contains two positive integers *n* and *m* (1<=≤<=*n*·*m*<=≤<=100<=000) — the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the followi... | Print "Yes" to the *i*-th line of the output if the table consisting of rows from *l**i* to *r**i* inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No". | [
"5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n"
] | [
"Yes\nNo\nYes\nYes\nYes\nNo\n"
] | In the sample, the whole table is not sorted in any column. However, rows 1–3 are sorted in column 1, while rows 4–5 are sorted in column 3. | 1,500 | [
{
"input": "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5",
"output": "Yes\nNo\nYes\nYes\nYes\nNo"
},
{
"input": "1 1\n1\n1\n1 1",
"output": "Yes"
},
{
"input": "10 1\n523130301\n127101624\n15573616\n703140639\n628818570\n957494759\n161270109\n38686565... | 1,514,823,048 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 8,396,800 | n, m = map(int,input().split())
a = []
b = [[1 for j in range(m)] for i in range(n)]
for i in range(n):
a.append(list(map(int,input().split())))
for i in range (1, n):
for j in range(m):
if a[i][j] >= a[i-1][j]:
b[i][j] = b[i-1][j] + 1
else:
... | Title: Alyona and Spreadsheet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By ... | ```python
n, m = map(int,input().split())
a = []
b = [[1 for j in range(m)] for i in range(n)]
for i in range(n):
a.append(list(map(int,input().split())))
for i in range (1, n):
for j in range(m):
if a[i][j] >= a[i-1][j]:
b[i][j] = b[i-1][j] + 1
else... | 0 | |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*... | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
... | 1,598,940,076 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 280 | 0 | s=list(input())
m=max(s)
c=s.count(m)
print(m*c) | Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ... | ```python
s=list(input())
m=max(s)
c=s.count(m)
print(m*c)
``` | 3 | |
811 | A | Vladik and Courtesy | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving eac... | Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. | Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. | [
"1 1\n",
"7 6\n"
] | [
"Valera\n",
"Vladik\n"
] | Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e... | 500 | [
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
... | 1,552,714,924 | 724 | Python 3 | OK | TESTS | 42 | 155 | 3,072,000 | a, b = map(int, input().split())
N = 100005
rec = [0] * N
rec[1] = 1
rec[2] = 2
for i in range(3, N):
rec[i] = rec[i - 2] + i
for i in range(1, 100005):
if i % 2 != 0:
if a - rec[i] < 0:
print('Vladik')
exit()
else:
if b - rec[i] < 0:
print... | Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla... | ```python
a, b = map(int, input().split())
N = 100005
rec = [0] * N
rec[1] = 1
rec[2] = 2
for i in range(3, N):
rec[i] = rec[i - 2] + i
for i in range(1, 100005):
if i % 2 != 0:
if a - rec[i] < 0:
print('Vladik')
exit()
else:
if b - rec[i] < 0:
... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,642,060,649 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | n = int(input())
x2 = 0
y2 = 0
z2 = 0
for i in range(n):
x, y, z = map(int, input().split())
if -100 <= x and y and z <= 100:
x2 += x
y2 += y
z2 += z
if x2 == 0 and y2 == 0 and z2 == 0:
print('YES')
else:
print('NO')
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
x2 = 0
y2 = 0
z2 = 0
for i in range(n):
x, y, z = map(int, input().split())
if -100 <= x and y and z <= 100:
x2 += x
y2 += y
z2 += z
if x2 == 0 and y2 == 0 and z2 == 0:
print('YES')
else:
print('NO')
``` | 0 |
644 | C | Hostname Aliases | PROGRAMMING | 2,100 | [
"*special",
"binary search",
"data structures",
"implementation",
"sortings",
"strings"
] | null | null | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.
You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostnam... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of page queries. Then follow *n* lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where:
- <hostname> consists of lowercase English letters and dots, ther... | First print *k* — the number of groups of server names that correspond to one website. You should count only groups of size greater than one.
Next *k* lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both gro... | [
"10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test\n",
"14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp:... | [
"1\nhttp://abacaba.de http://abacaba.ru \n",
"2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc \n"
] | none | 1,500 | [
{
"input": "10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test",
"output": "1\nhttp://abacaba.de http://abacaba.ru "
},
{
"... | 1,458,253,149 | 134,349 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 6 | 5,000 | 26,214,400 | n = int(input())
d = {};
for i in range(n):
s = input()
j = s.find("/",7)
if j < 0:
buf = s[:]
buf1 = ""
else:
buf = s[:j]
buf1 = s[j:]
if d.get(buf) is None:
d[buf] = set([buf1])
else:
d[buf].add(buf1)
newd = []
for i in d.values()... | Title: Hostname Aliases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.
You are given a list of page... | ```python
n = int(input())
d = {};
for i in range(n):
s = input()
j = s.find("/",7)
if j < 0:
buf = s[:]
buf1 = ""
else:
buf = s[:j]
buf1 = s[j:]
if d.get(buf) is None:
d[buf] = set([buf1])
else:
d[buf].add(buf1)
newd = []
for i in ... | 0 | |
897 | B | Chtholly's request | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | — I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation with... | The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109). | Output single integer — answer to the problem. | [
"2 100\n",
"5 30\n"
] | [
"33\n",
"15\n"
] | In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 1,000 | [
{
"input": "2 100",
"output": "33"
},
{
"input": "5 30",
"output": "15"
},
{
"input": "42147 412393322",
"output": "251637727"
},
{
"input": "77809 868097296",
"output": "440411873"
},
{
"input": "5105 443422097",
"output": "363192634"
},
{
"input": "7... | 1,512,250,370 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 171 | 30,310,400 | import sys
from functools import reduce
cnt = 1
arr = []
n, k = map(int, sys.stdin.readline().strip().split())
while cnt <= n:
st = str(cnt)
arr.append(int(st + st[::-1]))
# print(arr[cnt-1])
cnt += 1
cnt = 1
ans = reduce(lambda x, y: (x+y)%k, arr)
sys.stdout.write(str(ans%k)) | Title: Chtholly's request
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
— I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thi... | ```python
import sys
from functools import reduce
cnt = 1
arr = []
n, k = map(int, sys.stdin.readline().strip().split())
while cnt <= n:
st = str(cnt)
arr.append(int(st + st[::-1]))
# print(arr[cnt-1])
cnt += 1
cnt = 1
ans = reduce(lambda x, y: (x+y)%k, arr)
sys.stdout.write(str(ans%k))
``` | 3 | |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,682,244,888 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 62 | 0 | a,b=map(int,input().split())
for i in range(a):
if i%4==0 or i%4==2:
print('#'*b)
elif i%4==1:
print('.'*(b-1) + '#')
else:
print('#' + '.'*(b-1)) | Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*... | ```python
a,b=map(int,input().split())
for i in range(a):
if i%4==0 or i%4==2:
print('#'*b)
elif i%4==1:
print('.'*(b-1) + '#')
else:
print('#' + '.'*(b-1))
``` | 3 | |
53 | A | Autocomplete | PROGRAMMING | 1,100 | [
"implementation"
] | A. Autocomplete | 2 | 256 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase... | If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' o... | [
"next\n2\nnextpermutation\nnextelement\n",
"find\n4\nfind\nfindfirstof\nfindit\nfand\n",
"find\n4\nfondfind\nfondfirstof\nfondit\nfand\n"
] | [
"nextelement\n",
"find\n",
"find\n"
] | none | 500 | [
{
"input": "next\n2\nnextpermutation\nnextelement",
"output": "nextelement"
},
{
"input": "find\n4\nfind\nfindfirstof\nfindit\nfand",
"output": "find"
},
{
"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand",
"output": "find"
},
{
"input": "kudljmxcse\n4\nkudljmxcse\nszje... | 1,635,660,331 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 154 | 28,467,200 | s=input()
n=int(input())
m="z"
f=0
for i in range(n):
t=input()
if t.find(s)==0:
f=1
if t<=m:
m=t
if f==0:
print(s)
else:
print(m) | Title: Autocomplete
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens... | ```python
s=input()
n=int(input())
m="z"
f=0
for i in range(n):
t=input()
if t.find(s)==0:
f=1
if t<=m:
m=t
if f==0:
print(s)
else:
print(m)
``` | 3.908476 |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"i... | 1,695,391,760 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | def main():
k = int(input())
l = int(input())
m = int(input())
n = int(input())
d = int(input())
xk = [i % k == 0 for i in range(1, d + 1)]
xl = [i % l == 0 for i in range(1, d + 1)]
xm = [i % m == 0 for i in range(1, d + 1)]
xn = [i % n == 0 for i in range(1, d + 1)]
print(d - sum([any(i) for i in zip(xk, ... | Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entert... | ```python
def main():
k = int(input())
l = int(input())
m = int(input())
n = int(input())
d = int(input())
xk = [i % k == 0 for i in range(1, d + 1)]
xl = [i % l == 0 for i in range(1, d + 1)]
xm = [i % m == 0 for i in range(1, d + 1)]
xn = [i % n == 0 for i in range(1, d + 1)]
print(d - sum([any(i) for i i... | 0 | |
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,... | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict... | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for whic... | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9... | 1,619,076,367 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(raw_input())
a = map(int,raw_input().split())
b = []
d = []
if(n==3):
print abs(a[0]-a[2])
else:
for i in range(1,n-1):
b = a[:i]+a[i+1:]
c = [x - b[i - 1] for i, x in enumerate(b)][1:]
d.append(max(c))
print min(d) | Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 fo... | ```python
n = int(raw_input())
a = map(int,raw_input().split())
b = []
d = []
if(n==3):
print abs(a[0]-a[2])
else:
for i in range(1,n-1):
b = a[:i]+a[i+1:]
c = [x - b[i - 1] for i, x in enumerate(b)][1:]
d.append(max(c))
print min(d)
``` | -1 | |
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,686,125,406 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | from sys import maxsize
n = int(input(""))
a = list(map(int, input("").split()))
lst = []
if a[0] == 1:
lst.append(-1)
else:
lst.append(1)
for i in range(1, n):
if a[i] == a[i-1]:
if a[i] == 1:
lst[-1] += -1
else:
lst[-1] += 1
elif a[i] == 1:
... | 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
from sys import maxsize
n = int(input(""))
a = list(map(int, input("").split()))
lst = []
if a[0] == 1:
lst.append(-1)
else:
lst.append(1)
for i in range(1, n):
if a[i] == a[i-1]:
if a[i] == 1:
lst[-1] += -1
else:
lst[-1] += 1
elif a[i]... | 0 | |
897 | B | Chtholly's request | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | — I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation with... | The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109). | Output single integer — answer to the problem. | [
"2 100\n",
"5 30\n"
] | [
"33\n",
"15\n"
] | In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 1,000 | [
{
"input": "2 100",
"output": "33"
},
{
"input": "5 30",
"output": "15"
},
{
"input": "42147 412393322",
"output": "251637727"
},
{
"input": "77809 868097296",
"output": "440411873"
},
{
"input": "5105 443422097",
"output": "363192634"
},
{
"input": "7... | 1,667,053,593 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 124 | 2,048,000 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
k, p = map(int, input().split())
ans = 0
for i in range(1, k + 1):
u = int(str(i) + str(i)[::-1])
ans += u
ans %= p
print(ans) | Title: Chtholly's request
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
— I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thi... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
k, p = map(int, input().split())
ans = 0
for i in range(1, k + 1):
u = int(str(i) + str(i)[::-1])
ans += u
ans %= p
print(ans)
``` | 3 | |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,587,758,962 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 108 | 0 | # import sys
# sys.stdin = open('tc.txt','r')
n = int(input())
x = len(str(n))
ans = 1
for i in range(1,x):
ans+=(1<<i)
v = list(str(n))
v = ['1' if i!='4' else '0' for i in v]
v = "".join(v)
ans+=int(v,2)
print(ans)
| Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
# import sys
# sys.stdin = open('tc.txt','r')
n = int(input())
x = len(str(n))
ans = 1
for i in range(1,x):
ans+=(1<<i)
v = list(str(n))
v = ['1' if i!='4' else '0' for i in v]
v = "".join(v)
ans+=int(v,2)
print(ans)
``` | 3 | |
577 | A | Multiplication Table | PROGRAMMING | 1,000 | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num... | The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | 500 | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 10000000... | 1,654,172,795 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 61 | 0 | n,x = map(int,input().split(" "))
count = 0
for i in range(1,n+1):
if(x%i==0 and x//i<=n):
count += 1
print(count) | Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
Y... | ```python
n,x = map(int,input().split(" "))
count = 0
for i in range(1,n+1):
if(x%i==0 and x//i<=n):
count += 1
print(count)
``` | 3 | |
919 | B | Perfect Number | PROGRAMMING | 1,100 | [
"binary search",
"brute force",
"dp",
"implementation",
"number theory"
] | null | null | We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. | A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). | A single number, denoting the $k$-th smallest perfect integer. | [
"1\n",
"2\n"
] | [
"19\n",
"28\n"
] | The first perfect integer is $19$ and the second one is $28$. | 750 | [
{
"input": "1",
"output": "19"
},
{
"input": "2",
"output": "28"
},
{
"input": "13",
"output": "136"
},
{
"input": "101",
"output": "1432"
},
{
"input": "1023",
"output": "100270"
},
{
"input": "9999",
"output": "10800010"
},
{
"input": "10... | 1,668,080,067 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 |
def digit_sum(number):
result = 0
while number > 0:
result += number % 10
number //= 10
return result
k = int(input())
number = 1
while k != 0:
if digit_sum(number) == 10:
k -= 1
number += 1
print(number)
| Title: Perfect Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
Input Specification:
A singl... | ```python
def digit_sum(number):
result = 0
while number > 0:
result += number % 10
number //= 10
return result
k = int(input())
number = 1
while k != 0:
if digit_sum(number) == 10:
k -= 1
number += 1
print(number)
``` | 0 | |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i... | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "64009798... | 1,665,425,853 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 |
n,m = list(map(int,input().split(' ')))
if(m-n+1<3):
print(-1)
elif(n%2==0):
print(n,' ',n+1,' ',n+2)
elif(m-n+1>3):
print(n+1,' ',n+2,' ',n+3)
| Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different st... | ```python
n,m = list(map(int,input().split(' ')))
if(m-n+1<3):
print(-1)
elif(n%2==0):
print(n,' ',n+1,' ',n+2)
elif(m-n+1>3):
print(n+1,' ',n+2,' ',n+3)
``` | 0 | |
841 | B | Godsend | PROGRAMMING | 1,100 | [
"games",
"math"
] | null | null | Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts... | First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array.
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). | [
"4\n1 3 2 3\n",
"2\n2 2\n"
] | [
"First\n",
"Second\n"
] | In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose. | 1,000 | [
{
"input": "4\n1 3 2 3",
"output": "First"
},
{
"input": "2\n2 2",
"output": "Second"
},
{
"input": "4\n2 4 6 8",
"output": "Second"
},
{
"input": "5\n1 1 1 1 1",
"output": "First"
},
{
"input": "4\n720074544 345031254 849487632 80870826",
"output": "Second"
... | 1,506,642,002 | 2,147,483,647 | Python 3 | OK | TESTS | 88 | 810 | 78,438,400 | import sys
import math
"""files=False
if files:
fn='symposium'
sys.stdin=open(fn+'.in')
sys.stdout=open(fn+'.out',mode='w')
"""
def ria():
return [int(i) for i in input().split()]
sz=ria()[0]
ar=ria()
suma=sum(ar)
if suma%2==1:
print('First')
exit(0)
there=False
therek=False
... | Title: Godsend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero l... | ```python
import sys
import math
"""files=False
if files:
fn='symposium'
sys.stdin=open(fn+'.in')
sys.stdout=open(fn+'.out',mode='w')
"""
def ria():
return [int(i) for i in input().split()]
sz=ria()[0]
ar=ria()
suma=sum(ar)
if suma%2==1:
print('First')
exit(0)
there=False
ther... | 3 | |
792 | A | New Bus Route | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d... | The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct. | Print two integer numbers — the minimal distance and the quantity of pairs with this distance. | [
"4\n6 -3 0 4\n",
"3\n-2 0 2\n"
] | [
"2 1\n",
"2 2\n"
] | In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance. | 0 | [
{
"input": "4\n6 -3 0 4",
"output": "2 1"
},
{
"input": "3\n-2 0 2",
"output": "2 2"
},
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "2\n1000000000 -1000000000",
"output": "2000000000 1"
},
{
"input": "5\n-979619606 -979619602 -979619604 -979619605 -97961960... | 1,491,745,725 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 4,608,000 | import numpy
num=int(input())
cityinput=input()
city=[int(n) for n in cityinput.split()]
city.sort()
dis=[]
dis1=[]
i=0
while i<num-1:
for m in numpy.arange(i+1,num):
dis1.append(abs(city[i]-city[m]))
dis.append(min(dis1))
i+=1
min_dis=min(dis)
num_min=dis.count(min_dis)
print(min_dis... | Title: New Bus Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from on... | ```python
import numpy
num=int(input())
cityinput=input()
city=[int(n) for n in cityinput.split()]
city.sort()
dis=[]
dis1=[]
i=0
while i<num-1:
for m in numpy.arange(i+1,num):
dis1.append(abs(city[i]-city[m]))
dis.append(min(dis1))
i+=1
min_dis=min(dis)
num_min=dis.count(min_dis)
pri... | -1 | |
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st... | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"... | 1,697,027,316 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 2,000 | 43,827,200 | import math
def judge(a):#生成10^6以内质数表
b=False
for i in range(2,math.ceil(math.sqrt(a))+1):#平方数是上限
if a%i==0:
b=True
break
if b==False:
d[a]=1
else:
d[a]=0
d={}
d[1]=0
d[2]=1#2要特判
for a in range(3,1000001):
judge(a)
def ch(i):
if math.sqrt(i)%1==0 a... | Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an ar... | ```python
import math
def judge(a):#生成10^6以内质数表
b=False
for i in range(2,math.ceil(math.sqrt(a))+1):#平方数是上限
if a%i==0:
b=True
break
if b==False:
d[a]=1
else:
d[a]=0
d={}
d[1]=0
d[2]=1#2要特判
for a in range(3,1000001):
judge(a)
def ch(i):
if math.sqrt... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of tree... | The first line contains a single integer *h* (2<=≤<=*h*<=≤<=105) — the height of the tree.
The second line contains *h*<=+<=1 integers — the sequence *a*0,<=*a*1,<=...,<=*a**h* (1<=≤<=*a**i*<=≤<=2·105). The sum of all *a**i* does not exceed 2·105. It is guaranteed that there is at least one tree matching this sequence... | If there is only one tree matching this sequence, print "perfect".
Otherwise print "ambiguous" in the first line. In the second and in the third line print descriptions of two trees in the following format: in one line print integers, the *k*-th of them should be the parent of vertex *k* or be equal to zero, if the *... | [
"2\n1 1 1\n",
"2\n1 2 2\n"
] | [
"perfect\n",
"ambiguous\n0 1 1 3 3\n0 1 1 3 2\n"
] | The only tree in the first example and the two printed trees from the second example are shown on the picture:
<img class="tex-graphics" src="https://espresso.codeforces.com/ae5d1889e09854f9d8ad6e29ab7afbe690ca4702.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 0 | [
{
"input": "2\n1 1 1",
"output": "perfect"
},
{
"input": "2\n1 2 2",
"output": "ambiguous\n0 1 1 3 3\n0 1 1 3 2"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1 1",
"output": "perfect"
},
{
"input": "10\n1 1 1 1 1 2 1 1 1 1 1",
"output": "perfect"
},
{
"input": "10\n1 1 1 ... | 1,513,701,536 | 3,836 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 2,000 | 11,161,600 | h = int(input())
A = input().split()
A = [int(Ai) for Ai in A]
ind = -1
for i in range(h):
if A[i] > 1 and A[i + 1] > 1:
ind = i
break
if ind == -1:
print("perfect")
else:
t1 = [0]
t2 = [0]
p = 1
for i in range(1, h + 1):
for j in range(A[i]):
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that... | ```python
h = int(input())
A = input().split()
A = [int(Ai) for Ai in A]
ind = -1
for i in range(h):
if A[i] > 1 and A[i + 1] > 1:
ind = i
break
if ind == -1:
print("perfect")
else:
t1 = [0]
t2 = [0]
p = 1
for i in range(1, h + 1):
for j in range(A[i]):... | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,662,206,432 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | import math
a = input()
y = [int(x) for x in a.split(" ")]
print(math.ceil(y[0]/y[2]) * math.ceil(y[1]/y[2]))
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
import math
a = input()
y = [int(x) for x in a.split(" ")]
print(math.ceil(y[0]/y[2]) * math.ceil(y[1]/y[2]))
``` | 3.977 |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,698,566,243 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | import math
k,r=map(int,input().split())
blist=[]
c=0
for y in range(1,1000):
if (k*y)%10==0:
c=y
break
for x in range(1,1000):
if (k*x-r)%10==0:
blist.append(x)
break
if len(blist)!=0:
print(min(c,blist[0]))
else:
print(c) | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
import math
k,r=map(int,input().split())
blist=[]
c=0
for y in range(1,1000):
if (k*y)%10==0:
c=y
break
for x in range(1,1000):
if (k*x-r)%10==0:
blist.append(x)
break
if len(blist)!=0:
print(min(c,blist[0]))
else:
print(c)
``` | 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,698,408,324 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 307,200 | n = int(input())
students = list(map(int, input().split()))
subjects = [list() for i in range(3)]
for i in range(len(students)):
subjects[students[i] - 1].append(i + 1)
if not all(subjects):
print(0)
else:
print(min(len(s) for s in subjects))
for i in range(min(len(s) for s in subjects)):... | 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())
students = list(map(int, input().split()))
subjects = [list() for i in range(3)]
for i in range(len(students)):
subjects[students[i] - 1].append(i + 1)
if not all(subjects):
print(0)
else:
print(min(len(s) for s in subjects))
for i in range(min(len(s) for s in s... | 3 | |
161 | D | Distance in Tree | PROGRAMMING | 1,800 | [
"dfs and similar",
"dp",
"trees"
] | null | null | A tree is a connected graph that doesn't contain any cycles.
The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.
You are given a tree with *n* vertices and a positive number *k*. Find the number of distinct pairs of the vertices which have a distance of ex... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50000, 1<=≤<=*k*<=≤<=500) — the number of vertices and the required distance between the vertices.
Next *n*<=-<=1 lines describe the edges as "*a**i* *b**i*" (without the quotes) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*), where *a**i* and *b**i* ... | Print a single integer — the number of distinct pairs of the tree's vertices which have a distance of exactly *k* between them.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"5 2\n1 2\n2 3\n3 4\n2 5\n",
"5 3\n1 2\n2 3\n3 4\n4 5\n"
] | [
"4\n",
"2\n"
] | In the first sample the pairs of vertexes at distance 2 from each other are (1, 3), (1, 5), (3, 5) and (2, 4). | 2,000 | [
{
"input": "5 2\n1 2\n2 3\n3 4\n2 5",
"output": "4"
},
{
"input": "5 3\n1 2\n2 3\n3 4\n4 5",
"output": "2"
},
{
"input": "10 1\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6",
"output": "9"
},
{
"input": "10 2\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6",
"output": "10"
... | 1,537,140,498 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 3,000 | 287,744,000 | import sys
sys.setrecursionlimit(10000000)
def get(graph, u, par):
q, s = [0], set([0])
for x in q:
graph[x] = [x for x in graph[x] if x not in s]
s.update(graph[x])
q.extend(graph[x])
res = 0
count = [None] * n
for u in q[::-1]:
count[u] = {0: 1}
for v in gra... | Title: Distance in Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tree is a connected graph that doesn't contain any cycles.
The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.
You are given a tree with *n* vertices an... | ```python
import sys
sys.setrecursionlimit(10000000)
def get(graph, u, par):
q, s = [0], set([0])
for x in q:
graph[x] = [x for x in graph[x] if x not in s]
s.update(graph[x])
q.extend(graph[x])
res = 0
count = [None] * n
for u in q[::-1]:
count[u] = {0: 1}
fo... | 0 | |
915 | C | Permute Digits | PROGRAMMING | 1,700 | [
"dp",
"greedy"
] | null | null | You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is. | The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists. | Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*. | [
"123\n222\n",
"3921\n10000\n",
"4940\n5000\n"
] | [
"213\n",
"9321\n",
"4940\n"
] | none | 0 | [
{
"input": "123\n222",
"output": "213"
},
{
"input": "3921\n10000",
"output": "9321"
},
{
"input": "4940\n5000",
"output": "4940"
},
{
"input": "23923472834\n23589234723",
"output": "23498743322"
},
{
"input": "102391019\n491010301",
"output": "399211100"
},... | 1,639,803,424 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 10 | 124 | 2,764,800 | #OMM NAMH SHIVAY
#JAI SHREE RAM
import sys,math,heapq,queue
from collections import deque
from functools import cmp_to_key
fast_input=sys.stdin.readline
A=[int(i) for i in input()]
B=[int(i) for i in input()]
def printer(x):
for i in x:
print(i,end='')
print()
if len(A)<len(B) or sorted(A)=... | Title: Permute Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allow... | ```python
#OMM NAMH SHIVAY
#JAI SHREE RAM
import sys,math,heapq,queue
from collections import deque
from functools import cmp_to_key
fast_input=sys.stdin.readline
A=[int(i) for i in input()]
B=[int(i) for i in input()]
def printer(x):
for i in x:
print(i,end='')
print()
if len(A)<len(B) or ... | 0 | |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,699,424,647 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 2,355,200 | n = int(input())
t = input()
a = []
d = []
for i in t:
if i == "A":
a.append(i)
elif i == "D":
d.append(i)
if len(t) == n:
if len(a) == len(d):
print("Friendship")
elif len(a) > len(d):
print("Anton")
elif len(a) < len(d):
print("Danik") | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
n = int(input())
t = input()
a = []
d = []
for i in t:
if i == "A":
a.append(i)
elif i == "D":
d.append(i)
if len(t) == n:
if len(a) == len(d):
print("Friendship")
elif len(a) > len(d):
print("Anton")
elif len(a) < len(d):
print("Dan... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 0 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,619,089,476 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | def permutation(arr, d):
if(len(arr) == 0):
return []
max_pos = arr.index(max(arr))
left = arr[:max_pos]
right = arr[max_pos+1:]
return permutation(left, d+1) + [str(d)] + permutation(right, d+1)
t = int(input())
for i in range(t):
n = int(input())
arr = list(map(int, input().s... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into t... | ```python
def permutation(arr, d):
if(len(arr) == 0):
return []
max_pos = arr.index(max(arr))
left = arr[:max_pos]
right = arr[max_pos+1:]
return permutation(left, d+1) + [str(d)] + permutation(right, d+1)
t = int(input())
for i in range(t):
n = int(input())
arr = list(map(int,... | -1 | |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,622,304,242 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | a,b,n=list(map(int,input().split()))
mn=1
alk = 10
ten=a
if a%10==0 and b%10==0:
print(a*b)
else:
for i in range(n):
while (i<alk):
if ((a*10)+i)%b==0:
a=(a*10)+i
break
i+=1
if a==ten:
print(-1)
else:
print(a) | Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
a,b,n=list(map(int,input().split()))
mn=1
alk = 10
ten=a
if a%10==0 and b%10==0:
print(a*b)
else:
for i in range(n):
while (i<alk):
if ((a*10)+i)%b==0:
a=(a*10)+i
break
i+=1
if a==ten:
print(-1)
else:
prin... | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.