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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
... | 1,695,680,136 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a = str(input())
n = 0
for i in range(0, len(a)):
if a[i]!="4" or a[i]!="7":
n+=1
if n=0:
print("YES")
else:
print("NO") | Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
a = str(input())
n = 0
for i in range(0, len(a)):
if a[i]!="4" or a[i]!="7":
n+=1
if n=0:
print("YES")
else:
print("NO")
``` | -1 |
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,689,245,157 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 186 | 1,945,600 | n=int(input())
sum=0
max=0
for i in range(0,n):
x=input()
var=x.split()
a=int(var[0])
b=int(var[1])
sum=sum+b-a
if max<sum:
max=sum
print(max) | 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
n=int(input())
sum=0
max=0
for i in range(0,n):
x=input()
var=x.split()
a=int(var[0])
b=int(var[1])
sum=sum+b-a
if max<sum:
max=sum
print(max)
``` | 3 | |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,694,766,267 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 77 | 0 | n = str(input())
n = list(n)
if int(n[0]) > 5 and int(n[0]) < 9:
n[0] = str(9 - int(n[0]))
for i in range(1, len(n)):
if int(n[i]) > 5:
n[i] = str(9 - int(n[i]))
n = ''.join(n)
print(int(n)) | Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
n = str(input())
n = list(n)
if int(n[0]) > 5 and int(n[0]) < 9:
n[0] = str(9 - int(n[0]))
for i in range(1, len(n)):
if int(n[i]) > 5:
n[i] = str(9 - int(n[i]))
n = ''.join(n)
print(int(n))
``` | 0 | |
708 | A | Letters Cyclic Shift | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation",
"strings"
] | null | null | You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is ... | The only line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) consisting of lowercase English letters. | Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring. | [
"codeforces\n",
"abacaba\n"
] | [
"bncdenqbdr\n",
"aaacaba\n"
] | String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≤ *i* ≤ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i*... | 500 | [
{
"input": "codeforces",
"output": "bncdenqbdr"
},
{
"input": "abacaba",
"output": "aaacaba"
},
{
"input": "babbbabaababbaa",
"output": "aabbbabaababbaa"
},
{
"input": "bcbacaabcababaccccaaaabacbbcbbaa",
"output": "abaacaabcababaccccaaaabacbbcbbaa"
},
{
"input": "... | 1,521,470,340 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 78 | 7,065,600 | IL = lambda: list(map(int, input().split()))
I = lambda: int(input())
s = list(map(ord, input()))
started = False
for i, ss in enumerate(s):
if ss > 97:
started = True
if started:
if ss > 97:
s[i] -= 1
else:
break
print("".join(map(chr, s)))
| Title: Letters Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each cha... | ```python
IL = lambda: list(map(int, input().split()))
I = lambda: int(input())
s = list(map(ord, input()))
started = False
for i, ss in enumerate(s):
if ss > 97:
started = True
if started:
if ss > 97:
s[i] -= 1
else:
break
print("".join(map(chr, s... | 0 | |
818 | A | Diplomas and Certificates | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and ... | The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas. | Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.
It's possible that there are no winners. | [
"18 2\n",
"9 10\n",
"1000000000000 5\n",
"1000000000000 499999999999\n"
] | [
"3 6 9\n",
"0 0 9\n",
"83333333333 416666666665 500000000002\n",
"1 499999999999 500000000000\n"
] | none | 0 | [
{
"input": "18 2",
"output": "3 6 9"
},
{
"input": "9 10",
"output": "0 0 9"
},
{
"input": "1000000000000 5",
"output": "83333333333 416666666665 500000000002"
},
{
"input": "1000000000000 499999999999",
"output": "1 499999999999 500000000000"
},
{
"input": "1 1",... | 1,625,161,113 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 77 | 0 | import math
n, k = map(int, input().split())
a = (math.floor(math.floor(n/2)/(k+1)))
b = a*k
rest = n - a - b
print(a, b, rest)
| Title: Diplomas and Certificates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with... | ```python
import math
n, k = map(int, input().split())
a = (math.floor(math.floor(n/2)/(k+1)))
b = a*k
rest = n - a - b
print(a, b, rest)
``` | 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,476,397,440 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 77 | 4,608,000 | s = input()
la = list('hello')
cp = -1
r = True
for l in la:
i = s.find(l, cp+1)
if i == -1:
r = False
break
cp = i
print('YES' if r else '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 = input()
la = list('hello')
cp = -1
r = True
for l in la:
i = s.find(l, cp+1)
if i == -1:
r = False
break
cp = i
print('YES' if r else 'NO')
``` | 3.952917 |
633 | A | Ebony and Ivory | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of ... | The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. | Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. | [
"4 6 15\n",
"3 2 7\n",
"6 11 6\n"
] | [
"No\n",
"Yes\n",
"Yes\n"
] | In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. | 250 | [
{
"input": "4 6 15",
"output": "No"
},
{
"input": "3 2 7",
"output": "Yes"
},
{
"input": "6 11 6",
"output": "Yes"
},
{
"input": "3 12 15",
"output": "Yes"
},
{
"input": "5 5 10",
"output": "Yes"
},
{
"input": "6 6 7",
"output": "No"
},
{
"... | 1,585,827,631 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def extended_gcd(a,b):
global g,x,y
if b==0:
g=a
x,y=1,0
else:
extended_gcd(b,a%b)
temp = x # value of x is preserved
x = y
y = temp - ((a//b)*y)
if __name__=="__main__":
a,b,c=map(int,input().split())
g=x=y=int()
... | Title: Ebony and Ivory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
F... | ```python
def extended_gcd(a,b):
global g,x,y
if b==0:
g=a
x,y=1,0
else:
extended_gcd(b,a%b)
temp = x # value of x is preserved
x = y
y = temp - ((a//b)*y)
if __name__=="__main__":
a,b,c=map(int,input().split())
g=x... | -1 | |
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"ou... | 1,693,001,021 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n, k = map(int, input().split())
j = 1
for i in range(k):
if j >= n:
print(-1)
break
while n % j != 0:
j += 1
j += 1
else:
print(j - 1)
| Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specificatio... | ```python
n, k = map(int, input().split())
j = 1
for i in range(k):
if j >= n:
print(-1)
break
while n % j != 0:
j += 1
j += 1
else:
print(j - 1)
``` | 0 | |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,624,898,949 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 17 | 124 | 0 | x=input()
x=x.replace('144',"")
x=x.replace('14',"")
x=x.replace('1',"")
if(len(x)==0):
print("YES")
else:
print("NO")
| Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
x=input()
x=x.replace('144',"")
x=x.replace('14',"")
x=x.replace('1',"")
if(len(x)==0):
print("YES")
else:
print("NO")
``` | 0 | |
36 | A | Extra-terrestrial Intelligence | PROGRAMMING | 1,300 | [
"implementation"
] | A. Extra-terrestrial Intelligence | 2 | 64 | Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | [
"8\n00111000\n",
"7\n1001011\n",
"7\n1010100\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "8\n00111000",
"output": "YES"
},
{
"input": "7\n1001011",
"output": "NO"
},
{
"input": "7\n1010100",
"output": "YES"
},
{
"input": "5\n10101",
"output": "YES"
},
{
"input": "3\n111",
"output": "YES"
},
{
"input": "10\n0011111011",
"outp... | 1,586,261,119 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 248 | 307,200 | ip = open("input.txt", "r")
op = open("output.txt", "w")
n = int(ip.readline())
signals = ip.readline()
sigs = 0
signallen = len(signals)
ans = True
for i in range(signallen):
if signals[i] == '1':
if sigs == 0:
sigs = 1
prev = i
else:
if sigs == 1:
distance = i-prev
sigs = 2
prev = i
else... | Title: Extra-terrestrial Intelligence
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* da... | ```python
ip = open("input.txt", "r")
op = open("output.txt", "w")
n = int(ip.readline())
signals = ip.readline()
sigs = 0
signallen = len(signals)
ans = True
for i in range(signallen):
if signals[i] == '1':
if sigs == 0:
sigs = 1
prev = i
else:
if sigs == 1:
distance = i-prev
sigs = 2
prev =... | 3.935711 |
25 | B | Phone numbers | PROGRAMMING | 1,100 | [
"implementation"
] | B. Phone numbers | 2 | 256 | Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups. | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | [
"6\n549871\n",
"7\n1198733\n"
] | [
"54-98-71",
"11-987-33\n"
] | none | 0 | [
{
"input": "6\n549871",
"output": "54-98-71"
},
{
"input": "7\n1198733",
"output": "119-87-33"
},
{
"input": "2\n74",
"output": "74"
},
{
"input": "2\n33",
"output": "33"
},
{
"input": "3\n074",
"output": "074"
},
{
"input": "3\n081",
"output": "08... | 1,653,107,519 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 92 | 0 |
a = int(input())
b = input()
c = ''
d = ''
if a % 2 == 0:
for i in range(0,a,2):
c += b[i]+b[i+1]+'-'
else:
for i in range(0,a-3,2):
d += b[i]+b[i+1]+'-'
if a % 2 == 0:
print(c[:-1])
else:
print(d+b[-3:])
| Title: Phone numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33.... | ```python
a = int(input())
b = input()
c = ''
d = ''
if a % 2 == 0:
for i in range(0,a,2):
c += b[i]+b[i+1]+'-'
else:
for i in range(0,a-3,2):
d += b[i]+b[i+1]+'-'
if a % 2 == 0:
print(c[:-1])
else:
print(d+b[-3:])
``` | 3.977 |
808 | G | Anthem of Berland | PROGRAMMING | 2,300 | [
"dp",
"strings"
] | null | null | Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.
Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible.
H... | The first line contains string of small Latin letters and question marks *s* (1<=≤<=|*s*|<=≤<=105).
The second line contains string of small Latin letters *t* (1<=≤<=|*t*|<=≤<=105).
Product of lengths of strings |*s*|·|*t*| won't exceed 107. | Output the maximum number of occurrences of string *t* you can achieve by replacing all the question marks in string *s* with small Latin letters. | [
"winlose???winl???w??\nwin\n",
"glo?yto?e??an?\nor\n",
"??c?????\nabcab\n"
] | [
"5\n",
"3\n",
"2\n"
] | In the first example the resulting string *s* is "winlosewinwinlwinwin"
In the second example the resulting string *s* is "glorytoreorand". The last letter of the string can be arbitrary.
In the third example occurrences of string *t* are overlapping. String *s* with maximal number of occurrences of *t* is "abcabcab"... | 0 | [
{
"input": "winlose???winl???w??\nwin",
"output": "5"
},
{
"input": "glo?yto?e??an?\nor",
"output": "3"
},
{
"input": "??c?????\nabcab",
"output": "2"
},
{
"input": "ddddd\nd",
"output": "5"
},
{
"input": "ww?ww\nw",
"output": "5"
},
{
"input": "?????\... | 1,566,122,547 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 3,000 | 52,121,600 | from string import ascii_lowercase
def prefix_function(s):
n = len(s)
pi = [0]*n
for i in range(1, n):
j = pi[i-1]
while j>0 and s[i] != s[j]:
j = pi[j-1]
if s[i] == s[j]:
j+=1
pi[i] = j
return pi
s = input()
t = input()
pi = prefix_function(t+'... | Title: Anthem of Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.
Though there are lots and lots of victories in history of Berland, there i... | ```python
from string import ascii_lowercase
def prefix_function(s):
n = len(s)
pi = [0]*n
for i in range(1, n):
j = pi[i-1]
while j>0 and s[i] != s[j]:
j = pi[j-1]
if s[i] == s[j]:
j+=1
pi[i] = j
return pi
s = input()
t = input()
pi = prefix_fu... | 0 | |
934 | A | A Compatible Pair | PROGRAMMING | 1,400 | [
"brute force",
"games"
] | null | null | Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big B... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109. | Print a single integer — the brightness of the chosen pair. | [
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] | [
"252\n",
"2\n"
] | In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | 500 | [
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 ... | 1,518,699,432 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 5,632,000 | n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
mx1=0
mx2=0
for i in range(n):
for j in range(m):
if a[i]*b[j]>mx1:
mx2=mx1
mx1=a[i]*b[j]
else:
mx2=max(mx2,a[i]*b[j])
print(mx2) | Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cr... | ```python
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
mx1=0
mx2=0
for i in range(n):
for j in range(m):
if a[i]*b[j]>mx1:
mx2=mx1
mx1=a[i]*b[j]
else:
mx2=max(mx2,a[i]*b[j])
print(mx2)
``` | 0 | |
492 | A | Vanya and Cubes | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must... | The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya. | Print the maximum possible height of the pyramid in the single line. | [
"1\n",
"25\n"
] | [
"1\n",
"4\n"
] | Illustration to the second sample: | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "25",
"output": "4"
},
{
"input": "2",
"output": "1"
},
{
"input": "4115",
"output": "28"
},
{
"input": "9894",
"output": "38"
},
{
"input": "7969",
"output": "35"
},
{
"input": "6560",
"outpu... | 1,689,658,891 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 0 | n = int(input())
h= 0
sc= 0
while sc <= n:
h += 1
sc += (h* (h + 1)) // 2
print(h - 1) | Title: Vanya and Cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the t... | ```python
n = int(input())
h= 0
sc= 0
while sc <= n:
h += 1
sc += (h* (h + 1)) // 2
print(h - 1)
``` | 3 | |
967 | A | Mind the Gap | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute.
He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minut... | The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, i... | Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | [
"6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n",
"16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n",
"3 17\n0 30\n1 0\n12 0\n"
] | [
"6 1\n",
"24 50\n",
"0 0\n"
] | In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.
In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert th... | 500 | [
{
"input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40",
"output": "6 1"
},
{
"input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59",
"output": "24 50"
},
{
"input": "3 17\n0 30\n1 0\n12 0",
"output": "0 0"
},
{
... | 1,525,010,015 | 2,315 | Python 3 | OK | TESTS | 34 | 93 | 7,065,600 | def next(h1, m1, minutes):
return (h1 + (m1 + minutes) // 60, (m1 + minutes) % 60)
n, s = map(int, input().split())
schedule = []
for i in range(n):
schedule.append(tuple(map(int, input().split())))
if schedule[0][0] * 60 + schedule[0][1] >= s + 1:
print('0 0')
else:
for i in range(1, len... | Title: Mind the Gap
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing ... | ```python
def next(h1, m1, minutes):
return (h1 + (m1 + minutes) // 60, (m1 + minutes) % 60)
n, s = map(int, input().split())
schedule = []
for i in range(n):
schedule.append(tuple(map(int, input().split())))
if schedule[0][0] * 60 + schedule[0][1] >= s + 1:
print('0 0')
else:
for i in ra... | 3 | |
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht... | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n100000... | 1,699,192,887 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
t = input()
c=0
for i in t:
if i==0:
c+=1
print(bin(2**c))
| Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two... | ```python
n = int(input())
t = input()
c=0
for i in t:
if i==0:
c+=1
print(bin(2**c))
``` | 0 | |
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,541,493,921 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 248 | 0 | n=int(input())
matrix=[[int(x) for x in input().split()]for y in range(n)]
m=0
z=0
d=0
p=0
for y in range(n):
m=m+matrix[y][0]
if m==0:
p=0
else :
p=p+1
for y in range(n):
d=d+matrix[y][1]
if d==0:
p=0
else :
p=p+1
for y in range(n):
... | 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())
matrix=[[int(x) for x in input().split()]for y in range(n)]
m=0
z=0
d=0
p=0
for y in range(n):
m=m+matrix[y][0]
if m==0:
p=0
else :
p=p+1
for y in range(n):
d=d+matrix[y][1]
if d==0:
p=0
else :
p=p+1
for y in ran... | 3.938 |
596 | B | Wilbur and Array | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input.
The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109). | Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*. | [
"5\n1 2 3 4 5\n",
"4\n1 2 2 1\n"
] | [
"5",
"3"
] | In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.
In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1. | 1,000 | [
{
"input": "5\n1 2 3 4 5",
"output": "5"
},
{
"input": "4\n1 2 2 1",
"output": "3"
},
{
"input": "3\n1 2 4",
"output": "4"
},
{
"input": "6\n1 2 3 6 5 4",
"output": "8"
},
{
"input": "10\n2 1 4 3 6 5 8 7 10 9",
"output": "19"
},
{
"input": "7\n12 6 12 ... | 1,483,811,111 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 217 | 22,016,000 | a=int(input())
x=list(map(int,input().split()))
t=abs(x[0])
if a>1:
for i in range(1,a):
t+=abs(x[i-1]-x[i])
print(t)
| Title: Wilbur and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+... | ```python
a=int(input())
x=list(map(int,input().split()))
t=abs(x[0])
if a>1:
for i in range(1,a):
t+=abs(x[i-1]-x[i])
print(t)
``` | 3 | |
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,... | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"i... | 1,489,911,641 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 93 | 5,836,800 | from fractions import gcd
n,m,z = map(int , input().split())
gc = n*m//gcd(n,m)
print(z//gc)
| Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com... | ```python
from fractions import gcd
n,m,z = map(int , input().split())
gc = n*m//gcd(n,m)
print(z//gc)
``` | 3 | |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,686,928,603 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | m = list(map(int, input().split()))
num = 0
d = dict()
for i in m:
d[i] = m.count(i)
print(4 - len(d)) | Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
m = list(map(int, input().split()))
num = 0
d = dict()
for i in m:
d[i] = m.count(i)
print(4 - len(d))
``` | 3 | |
710 | A | King Moves | PROGRAMMING | 800 | [
"implementation"
] | null | null | The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik... | The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. | Print the only integer *x* — the number of moves permitted for the king. | [
"e4\n"
] | [
"8\n"
] | none | 0 | [
{
"input": "e4",
"output": "8"
},
{
"input": "a1",
"output": "3"
},
{
"input": "h8",
"output": "3"
},
{
"input": "a4",
"output": "5"
},
{
"input": "g7",
"output": "8"
},
{
"input": "e1",
"output": "5"
},
{
"input": "b2",
"output": "8"
... | 1,517,596,057 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 5,632,000 | t = input("")
if (t == 'a1' or t == 'h1' or t == 'h8' or t == 'h1' ):
print('3')
else :
for i in t:
if (t[1]==1 or t[1]==8):
print('5')
else:
print('8')
| Title: King Moves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check... | ```python
t = input("")
if (t == 'a1' or t == 'h1' or t == 'h8' or t == 'h1' ):
print('3')
else :
for i in t:
if (t[1]==1 or t[1]==8):
print('5')
else:
print('8')
``` | 0 | |
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ... | The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"outpu... | 1,567,446,064 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 109 | 0 |
n = int(input())
l = list(map(int,input().split()))
l.sort()
for i in range(n-1):
if i % 2 == 0:
l.pop()
else:
l.pop(0)
for i in l:
print(i) | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the... | ```python
n = int(input())
l = list(map(int,input().split()))
l.sort()
for i in range(n-1):
if i % 2 == 0:
l.pop()
else:
l.pop(0)
for i in l:
print(i)
``` | 3 | |
717 | B | R3D3’s Summer Adventure | PROGRAMMING | 2,700 | [
"dp",
"greedy"
] | null | null | R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The White Buttons" and their hit song "Dacan the Baker", he met anoth... | The first line of input contains three integers *n* (2<=≤<=*n*<=≤<=108), *c*0 and *c*1 (0<=≤<=*c*0,<=*c*1<=≤<=108) — the number of letters in the alphabet, and costs of '0' and '1', respectively. | Output a single integer — minimum possible total a cost of the whole alphabet. | [
"4 1 2\n"
] | [
"12\n"
] | There are 4 letters in the alphabet. The optimal encoding is "00", "01", "10", "11". There are 4 zeroes and 4 ones used, so the total cost is 4·1 + 4·2 = 12. | 0 | [
{
"input": "4 1 2",
"output": "12"
},
{
"input": "2 1 5",
"output": "6"
},
{
"input": "3 1 1",
"output": "5"
},
{
"input": "5 5 5",
"output": "60"
},
{
"input": "4 0 0",
"output": "0"
},
{
"input": "6 0 6",
"output": "30"
},
{
"input": "6 6... | 1,473,591,828 | 7,428 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | import math
k,l,r=map(int,input().split())
print('%g'%(math.factorial(k)/2**(r-l)))
| Title: R3D3’s Summer Adventure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of p... | ```python
import math
k,l,r=map(int,input().split())
print('%g'%(math.factorial(k)/2**(r-l)))
``` | 0 | |
825 | A | Binary Protocol | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in ord... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*.
The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts... | Print the decoded number. | [
"3\n111\n",
"9\n110011101\n"
] | [
"3\n",
"2031\n"
] | none | 0 | [
{
"input": "3\n111",
"output": "3"
},
{
"input": "9\n110011101",
"output": "2031"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n100",
"output": "100"
},
{
"input": "5\n10001",
"output": "1001"
},
{
"input": "14\n11001100011000",
"output": "... | 1,500,218,872 | 1,372 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 78 | 23,142,400 | input()
print(join(map(lambda x:str(x), map(lambda x: len(x),input().split('0')))))
| Title: Binary Protocol
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' charact... | ```python
input()
print(join(map(lambda x:str(x), map(lambda x: len(x),input().split('0')))))
``` | -1 | |
886 | A | ACM ICPC | PROGRAMMING | 1,000 | [
"brute force"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. ... | The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 500 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
... | 1,532,757,175 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 124 | 0 | data = list(map(int, input().split()))
s = sum(data)
if s % 2 == 1:
print("no")
else:
ans = False
for i in range(1, 5):
for j in range(i + 1, 6):
if data[0] + data[i] + data[j] == s // 2:
ans = True
if ans:
print("yes")
else:
print("no... | Title: ACM ICPC
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build ... | ```python
data = list(map(int, input().split()))
s = sum(data)
if s % 2 == 1:
print("no")
else:
ans = False
for i in range(1, 5):
for j in range(i + 1, 6):
if data[0] + data[i] + data[j] == s // 2:
ans = True
if ans:
print("yes")
else:
... | 3 | |
389 | B | Fox and Cross | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
Ciel wants to draw several... | The first line contains an integer *n* (3<=≤<=*n*<=≤<=100) — the size of the board.
Each of the next *n* lines describes one row of the board. The *i*-th line describes the *i*-th row of the board and consists of *n* characters. Each character is either a symbol '.', or a symbol '#'. | Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO". | [
"5\n.#...\n####.\n.####\n...#.\n.....\n",
"4\n####\n####\n####\n####\n",
"6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.\n",
"6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.\n",
"3\n...\n...\n...\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In example 1, you can draw two crosses. The picture below shows what they look like.
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all. | 1,000 | [
{
"input": "4\n####\n####\n####\n####",
"output": "NO"
},
{
"input": "6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.",
"output": "YES"
},
{
"input": "6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.",
"output": "NO"
},
{
"input": "5\n.....\n.#...\n####.\n.####\n...#.",
... | 1,684,315,054 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 77 | 2,252,800 | def check(a, b, n):
return a>=0 and b>=0 and a<n and b<n
def solve():
n = int(input())
ar = []
for i in range(n):
ar.append(input())
cross = [[0]*n for _ in range(n)]
addc = [(1, 0), (2, 0), (1, -1), (1, 1)]
for i in range(n):
for j in range(n):
if ar[i][j] == "#" and cross[i][j] == 0:
cross[i][j]... | Title: Fox and Cross
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of t... | ```python
def check(a, b, n):
return a>=0 and b>=0 and a<n and b<n
def solve():
n = int(input())
ar = []
for i in range(n):
ar.append(input())
cross = [[0]*n for _ in range(n)]
addc = [(1, 0), (2, 0), (1, -1), (1, 1)]
for i in range(n):
for j in range(n):
if ar[i][j] == "#" and cross[i][j] == 0:
c... | 3 | |
246 | A | Buggy Sorting | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n* in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. ... | You've got a single integer *n* (1<=≤<=*n*<=≤<=50) — the size of the sorted array. | Print *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the counter-example, for which Valera's algorithm won't work correctly. If the counter-example that meets the described conditions is impossible to give, print -1.
If there are several counter-examples, consisting of *n* numbers, yo... | [
"1\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "3 2 1 "
},
{
"input": "4",
"output": "4 3 2 1 "
},
{
"input": "5",
"output": "5 4 3 2 1 "
},
{
"input": "6",
"output": "6 5 4 3 2 1 "
},
{
"input... | 1,547,271,130 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 92 | 0 | n = int(input())
if n == 1 or n == 2:
print(-1)
exit()
ans = []
for i in range(1,n-1):
for j in range(i,n-1):
ans.append(i)
if ans[j]>ans[j-1]:
a[j-1],a[j]=a[j-1],a[j]
print(ans)
| Title: Buggy Sorting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a*... | ```python
n = int(input())
if n == 1 or n == 2:
print(-1)
exit()
ans = []
for i in range(1,n-1):
for j in range(i,n-1):
ans.append(i)
if ans[j]>ans[j-1]:
a[j-1],a[j]=a[j-1],a[j]
print(ans)
``` | -1 | |
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht... | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n100000... | 1,650,560,871 | 171 | PyPy 3 | OK | TESTS | 14 | 77 | 0 | import sys
input = sys.stdin.buffer.readline
def process(S):
if S=='0':
sys.stdout.write('0')
return
d = [0, 0]
for c in S:
d[int(c)]+=1
answer = ['1']
for i in range(d[0]):
answer.append('0')
answer = ''.join(answer)
sys.stdout.write(answer)
... | Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two... | ```python
import sys
input = sys.stdin.buffer.readline
def process(S):
if S=='0':
sys.stdout.write('0')
return
d = [0, 0]
for c in S:
d[int(c)]+=1
answer = ['1']
for i in range(d[0]):
answer.append('0')
answer = ''.join(answer)
sys.stdout.write(... | 3 | |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,592,544,920 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 280 | 0 | n=int(input())
l=list(map(int,input().split()))
c1=0
c2=0
for i in l:
if(i%2==0):
c1+=1
else:
c2+=1
if(c2%2==0):
print(c1)
else:
print(1) | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
n=int(input())
l=list(map(int,input().split()))
c1=0
c2=0
for i in l:
if(i%2==0):
c1+=1
else:
c2+=1
if(c2%2==0):
print(c1)
else:
print(1)
``` | 0 | |
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel... | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input"... | 1,598,416,042 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 614,400 | n,m=map(int,input().split())
a=[0]*m
b=[0]*m
for i in range(m):
a[i],b[i]=map(str,input().split())
c=list(map(str,input().split()))
s=[]
for i in c:
for j in range(len(a)):
if(a[j]==i or b[j]==i):
if(len(a[j])<=len(b[j])):
s.append(a[j])
else:
... | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
n,m=map(int,input().split())
a=[0]*m
b=[0]*m
for i in range(m):
a[i],b[i]=map(str,input().split())
c=list(map(str,input().split()))
s=[]
for i in c:
for j in range(len(a)):
if(a[j]==i or b[j]==i):
if(len(a[j])<=len(b[j])):
s.append(a[j])
else... | 0 | |
290 | A | Mysterious strings | PROGRAMMING | 1,400 | [
"*special",
"implementation"
] | null | null | The input contains a single integer *a* (1<=≤<=*a*<=≤<=40).
Output a single string. | The input contains a single integer *a* (1<=≤<=*a*<=≤<=40). | Output a single string. | [
"2\n",
"8\n",
"29\n"
] | [
"Adams\n",
"Van Buren\n",
"Harding\n"
] | none | 0 | [
{
"input": "2",
"output": "Adams"
},
{
"input": "8",
"output": "Van Buren"
},
{
"input": "29",
"output": "Harding"
},
{
"input": "1",
"output": "Washington"
},
{
"input": "3",
"output": "Jefferson"
},
{
"input": "4",
"output": "Madison"
},
{
... | 1,580,567,612 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
string arrPresidents[40] = { "Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson", "Van Buren", "Harrison", "Tyler", "Polk", "Taylor", "Fillmore", "Pierce", "Buchanan", "Lincoln", ... | Title: Mysterious strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=40).
Output a single string.
Input Specification:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=40).
Output Specification:
Output a single string.
D... | ```python
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
string arrPresidents[40] = { "Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson", "Van Buren", "Harrison", "Tyler", "Polk", "Taylor", "Fillmore", "Pierce", "Buchanan", "... | -1 | |
672 | A | Summer Camp | PROGRAMMING | 800 | [
"implementation"
] | null | null | Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. | Print the *n*-th digit of the line. | [
"3\n",
"11\n"
] | [
"3\n",
"0\n"
] | In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | 500 | [
{
"input": "3",
"output": "3"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "2"
},
{
"input": "1000",
"output": "3"
... | 1,636,228,952 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 4,300,800 |
s = ''
for i in range(1,371):
s+=str(i)
def solve():
n = int(input())
print(s[n-1])
for _ in range(1):
solve()
| Title: Summer Camp
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1... | ```python
s = ''
for i in range(1,371):
s+=str(i)
def solve():
n = int(input())
print(s[n-1])
for _ in range(1):
solve()
``` | 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,631,613,311 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int a[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
}
}
int s=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
s+=a[i][j];
}
... | 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
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int a[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
}
}
int s=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
s+=a[i][j];
... | -1 |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,608,652,505 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 109 | 0 | line1=input()
line2=input()
output=[]
for i in range(len(line1)):
if line1[i]==line2[i]:
output.append('0')
else:
output.append('1')
print(''.join(output)) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
line1=input()
line2=input()
output=[]
for i in range(len(line1)):
if line1[i]==line2[i]:
output.append('0')
else:
output.append('1')
print(''.join(output))
``` | 3.97275 |
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer — the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
... | 1,624,733,896 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 154 | 0 | n,k = [*map(int, input().split())]
a = [*map(int, input().split())]
print(sum(sum(c in '47' for c in str(x))<=k for x in a))
| Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits... | ```python
n,k = [*map(int, input().split())]
a = [*map(int, input().split())]
print(sum(sum(c in '47' for c in str(x))<=k for x in a))
``` | 3 | |
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
... | 1,697,616,334 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 62 | 0 | n = int(input())
mod = 10**9 + 7
dp=[0,0,0,1]
for step in range(1,n+1):
sumdp=sum(dp)%mod
dpPrime=[sumdp]*4
dpPrime[0]-=dp[0]%mod
dpPrime[1]-=dp[1]%mod
dpPrime[2]-=dp[2]%mod
dpPrime[3]-=dp[3]%mod
dp=dpPrime
print(dp[3]) | Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each m... | ```python
n = int(input())
mod = 10**9 + 7
dp=[0,0,0,1]
for step in range(1,n+1):
sumdp=sum(dp)%mod
dpPrime=[sumdp]*4
dpPrime[0]-=dp[0]%mod
dpPrime[1]-=dp[1]%mod
dpPrime[2]-=dp[2]%mod
dpPrime[3]-=dp[3]%mod
dp=dpPrime
print(dp[3])
``` | 0 | |
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,555,519,428 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 1,341 | 8,192,000 | a, b, n = map(int, input().split())
res = -1
for d in range(10):
if (a*10+d) % b == 0:
res = a*10+d
for i in range(1, n):
res *= 10
break
print(res)
| 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 = map(int, input().split())
res = -1
for d in range(10):
if (a*10+d) % b == 0:
res = a*10+d
for i in range(1, n):
res *= 10
break
print(res)
``` | 3 | |
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments c... | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 ... | 1,606,393,696 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 716 | 10,035,200 | n = int(input())
lst = []
for i in range(n):
lst.append(list(map(int, input().split())))
max_val = lst[0][0]
min_val = lst[0][1]
for index in range(len(lst)):
if lst[index][0] <= min_val:
min_val = lst[index][0]
if lst[index][1] >= max_val:
max_val = lst[index][1]
if [mi... | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments ... | ```python
n = int(input())
lst = []
for i in range(n):
lst.append(list(map(int, input().split())))
max_val = lst[0][0]
min_val = lst[0][1]
for index in range(len(lst)):
if lst[index][0] <= min_val:
min_val = lst[index][0]
if lst[index][1] >= max_val:
max_val = lst[index][1]... | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,674,685,360 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | count = int(input())
for i in range(count):
i = input()
if len(i) <= 10:
print(i)
else:
print(i[0] + str(len(i) - 2) + i[-1])
| 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
count = int(input())
for i in range(count):
i = input()
if len(i) <= 10:
print(i)
else:
print(i[0] + str(len(i) - 2) + i[-1])
``` | 3.977 |
899 | C | Dividing the numbers | PROGRAMMING | 1,300 | [
"constructive algorithms",
"graphs",
"math"
] | null | null | Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has. | Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. | [
"4\n",
"2\n"
] | [
"0\n2 1 4 \n",
"1\n1 1 \n"
] | In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and on... | 1,500 | [
{
"input": "4",
"output": "0\n2 1 4 "
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "3",
"output": "0\n1\n3 "
},
{
"input": "5",
"output": "1\n3\n1 2 5 "
},
{
"input": "59998",
"output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 4... | 1,513,539,355 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 124 | 7,782,400 | n=int(input())
l=list(range(1,n+1))
r=[]
if n%4==0:
r=list(range(1,n//2,2)) + list(range(n,n//2,-2))
print(0)
print(len(r), *r)
if n%4==2 and n!=2:
r=list(range(1,n//2,2)) + list(range(n,n//2,-2))
print(1)
print(len(r), *r)
if n%4==1:
r=list(range(1,n//2,2)) + list(range(n,n//2,-2))
#... | Title: Dividing the numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help P... | ```python
n=int(input())
l=list(range(1,n+1))
r=[]
if n%4==0:
r=list(range(1,n//2,2)) + list(range(n,n//2,-2))
print(0)
print(len(r), *r)
if n%4==2 and n!=2:
r=list(range(1,n//2,2)) + list(range(n,n//2,-2))
print(1)
print(len(r), *r)
if n%4==1:
r=list(range(1,n//2,2)) + list(range(n,n//2,... | 3 | |
688 | B | Lovely Palindromes | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). | Print the *n*-th even-length palindrome number. | [
"1\n",
"10\n"
] | [
"11\n",
"1001\n"
] | The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001. | 1,000 | [
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "... | 1,685,527,550 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 409,600 | from sys import stdin,stdout
# from bisect import bisect_left,bisect
# from heapq import heapify,heappop,heappush
# from sys import setrecursionlimit
# from collections import defaultdict,Counter
# from itertools import permutations
# from math import gcd,ceil,sqrt,factorial
# setrecursionlimit(int(1e5))
#input... | Title: Lovely Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is tr... | ```python
from sys import stdin,stdout
# from bisect import bisect_left,bisect
# from heapq import heapify,heappop,heappush
# from sys import setrecursionlimit
# from collections import defaultdict,Counter
# from itertools import permutations
# from math import gcd,ceil,sqrt,factorial
# setrecursionlimit(int(1e5... | 3 | |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,611,411,429 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 62 | 0 | def solve(n):
if n == 1:
return 1
return n-round(n/3)
def main():
n =int(input())
print(solve(n))
main() | Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
def solve(n):
if n == 1:
return 1
return n-round(n/3)
def main():
n =int(input())
print(solve(n))
main()
``` | 3 | |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,694,619,193 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
list1=[]
list1.append(a+b+c)
list1.append(a*b*c)
list1.append((a+b)*c)
list1.append(a*(b+c))
list1.append(a+(b*c))
list1.append((a*b)+c)
print(max(list1))
| Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
list1=[]
list1.append(a+b+c)
list1.append(a*b*c)
list1.append((a+b)*c)
list1.append(a*(b+c))
list1.append(a+(b*c))
list1.append((a*b)+c)
print(max(list1))
``` | -1 | |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,690,492,279 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 124 | 1,638,400 | x=int(input())
d = False
s= True
for n in range(1001):
y=str(n)
for i in range(len(y)):
if y[i] != '4' :
if y[i] !='7':
continue
else:
if x % n ==0:
print("YES")
d ... | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
x=int(input())
d = False
s= True
for n in range(1001):
y=str(n)
for i in range(len(y)):
if y[i] != '4' :
if y[i] !='7':
continue
else:
if x % n ==0:
print("YES")
... | 0 | |
180 | C | Letter | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to... | The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105. | Print a single number — the least number of actions needed to make the message fancy. | [
"PRuvetSTAaYA\n",
"OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n",
"helloworld\n"
] | [
"5\n",
"0\n",
"0\n"
] | none | 0 | [
{
"input": "PRuvetSTAaYA",
"output": "5"
},
{
"input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA",
"output": "0"
},
{
"input": "helloworld",
"output": "0"
},
{
"input": "P",
"output": "0"
},
{
"input": "t",
"output": "0"
},
{
"input": "XdJ",
"output": "1... | 1,546,786,038 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 280 | 1,126,400 | s=input()
mina=c=0
for i in range(len(s)):
if ord(s[i])>=97:
mina=min(c+1,mina)
c+=1
else:
mina=min(mina+1,c)
print(mina)
| Title: Letter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them... | ```python
s=input()
mina=c=0
for i in range(len(s)):
if ord(s[i])>=97:
mina=min(c+1,mina)
c+=1
else:
mina=min(mina+1,c)
print(mina)
``` | 3 | |
349 | B | Color the Fence | PROGRAMMING | 1,700 | [
"data structures",
"dp",
"greedy",
"implementation"
] | null | null | Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d... | The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105). | Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1. | [
"5\n5 4 3 2 1 2 3 4 5\n",
"2\n9 11 1 12 5 8 9 10 6\n",
"0\n1 1 1 1 1 1 1 1 1\n"
] | [
"55555\n",
"33\n",
"-1\n"
] | none | 1,000 | [
{
"input": "5\n5 4 3 2 1 2 3 4 5",
"output": "55555"
},
{
"input": "2\n9 11 1 12 5 8 9 10 6",
"output": "33"
},
{
"input": "0\n1 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "50\n5 3 10 2 2 4 3 6 5",
"output": "5555555555555555555555555"
},
{
"input": "22\n405 3... | 1,642,123,013 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 92 | 0 | v = int(input())
s = input().split()
s = [int(i) for i in s]
mini = max(s)
mp = 0
for i in range(9):
if(s[i]<=mini):
mini = min(mini,s[i])
mp = (i+1)
if(v == 0 or v<mini):
print(-1)
else:
t = ''
while(v>0):
v -= mini
t += str(mp)
print(t) | Title: Color the Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. ... | ```python
v = int(input())
s = input().split()
s = [int(i) for i in s]
mini = max(s)
mp = 0
for i in range(9):
if(s[i]<=mini):
mini = min(mini,s[i])
mp = (i+1)
if(v == 0 or v<mini):
print(-1)
else:
t = ''
while(v>0):
v -= mini
t += str(mp)
print(t)
``` | 0 | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,699,053,554 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | import math
x = int(input())
print(math.ceil(x/5)) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
import math
x = int(input())
print(math.ceil(x/5))
``` | 3 | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,575,541,623 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 216 | 0 | n = int(input())
x = list(map(int,input().split()))
c, bi, ba = 0, 0, 0
for i in range(1,n+1):
if i%3==0:
ba += i
elif i%2==0:
bi += i
else:
c += i
ex = {'ba1':'back','bi1':'biceps','c1':'chest'}
o = max(bi,ba,c)
if o==ba:
print(ex['ba1'])
elif o==bi:
print(ex['bi1'])
else:
print(ex['c1']) | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n = int(input())
x = list(map(int,input().split()))
c, bi, ba = 0, 0, 0
for i in range(1,n+1):
if i%3==0:
ba += i
elif i%2==0:
bi += i
else:
c += i
ex = {'ba1':'back','bi1':'biceps','c1':'chest'}
o = max(bi,ba,c)
if o==ba:
print(ex['ba1'])
elif o==bi:
print(ex['bi1'])
else:
print(... | 0 | |
965 | C | Greedy Arkady | PROGRAMMING | 2,000 | [
"math"
] | null | null | $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies ... | The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can ... | Print a single integer — the maximum possible number of candies Arkady can give to himself.
Note that it is always possible to choose some valid $x$. | [
"20 4 5 2\n",
"30 9 4 1\n"
] | [
"8\n",
"4\n"
] | In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total... | 1,500 | [
{
"input": "20 4 5 2",
"output": "8"
},
{
"input": "30 9 4 1",
"output": "4"
},
{
"input": "2 2 1 1",
"output": "1"
},
{
"input": "42 20 5 29",
"output": "5"
},
{
"input": "1000000000000000000 135 1000000000000000 1000",
"output": "8325624421831635"
},
{
... | 1,524,680,566 | 2,866 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 77 | 7,065,600 | n, k, M, D = list(map(int, input().split(" ")))
gain = M
for i in range(2, D + 1):
x = n // ((i - 1) * k + 1)
if x > M:
break
if x * i > gain:
gain = x * i
print(gain)
| Title: Greedy Arkady
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arka... | ```python
n, k, M, D = list(map(int, input().split(" ")))
gain = M
for i in range(2, D + 1):
x = n // ((i - 1) * k + 1)
if x > M:
break
if x * i > gain:
gain = x * i
print(gain)
``` | 0 | |
631 | A | Interview | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109).
The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). | Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. | [
"5\n1 2 4 3 2\n2 3 3 12 1\n",
"10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n"
] | [
"22",
"46"
] | Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation.
In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *... | 500 | [
{
"input": "5\n1 2 4 3 2\n2 3 3 12 1",
"output": "22"
},
{
"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6",
"output": "46"
},
{
"input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 9... | 1,593,425,309 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 124 | 6,963,200 | n = int(input())
a = input().split()
b = input().split()
or_a = 0
or_b = 0
for i in range(n):
or_a |= int(a[i])
or_b |= int(b[i])
print(or_a + or_b)
| Title: Interview
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of... | ```python
n = int(input())
a = input().split()
b = input().split()
or_a = 0
or_b = 0
for i in range(n):
or_a |= int(a[i])
or_b |= int(b[i])
print(or_a + or_b)
``` | 3 | |
716 | B | Complete the Word | PROGRAMMING | 1,300 | [
"greedy",
"two pointers"
] | null | null | ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not n... | The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember... | If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line.
Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks... | [
"ABC??FGHIJK???OPQR?TUVWXY?\n",
"WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n",
"??????????????????????????\n",
"AABCDEFGHIJKLMNOPQRSTUVW??M\n"
] | [
"ABCDEFGHIJKLMNOPQRZTUVWXYS",
"-1",
"MNBVCXZLKJHGFDSAQPWOEIRUYT",
"-1"
] | In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZT... | 1,000 | [
{
"input": "ABC??FGHIJK???OPQR?TUVWXY?",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO",
"output": "-1"
},
{
"input": "??????????????????????????",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "AABCDEFGHIJKLMNO... | 1,572,287,348 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | s=input()
if len(s) < 26:
print("-1")
possible=False
for i in range(len(s)-25):
cur=""
possible=True
for j in range(i, i+26):
if s[j] in cur:
possible=False
break
elif s[j] != "?":
cur += s[j]
else:
cur += "*"
if ... | Title: Complete the Word
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In pa... | ```python
s=input()
if len(s) < 26:
print("-1")
possible=False
for i in range(len(s)-25):
cur=""
possible=True
for j in range(i, i+26):
if s[j] in cur:
possible=False
break
elif s[j] != "?":
cur += s[j]
else:
cur += "*... | 0 | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,689,815,995 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n, m = list(map(int, input().split()))
ans = 0
b = []
a = [int(i) for i in input().split()]
a.sort()
for i in range(m):
b.append(a[i])
for k in range(len(b)):
if b[k] < 0:
ans += abs(b[k])
elif b[k] == 0:
ans += 0
else:
ans += -(b[k])
print(ans) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
n, m = list(map(int, input().split()))
ans = 0
b = []
a = [int(i) for i in input().split()]
a.sort()
for i in range(m):
b.append(a[i])
for k in range(len(b)):
if b[k] < 0:
ans += abs(b[k])
elif b[k] == 0:
ans += 0
else:
ans += -(b[k])
print(ans)
``` | 0 |
903 | A | Hungry Student Problem | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | 0 | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\... | 1,593,500,077 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 124 | 20,172,800 | for _ in range(int(input())):
x = int(input())
if x%3==0 or x%7==0:
print('YES')
else:
tmp = x//7
flag = True
while (x-tmp)%3!=0:
tmp -= 7
if tmp<=0:
flag = False
break
if flag:
print('YE... | Title: Hungry Student Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chun... | ```python
for _ in range(int(input())):
x = int(input())
if x%3==0 or x%7==0:
print('YES')
else:
tmp = x//7
flag = True
while (x-tmp)%3!=0:
tmp -= 7
if tmp<=0:
flag = False
break
if flag:
... | 0 | |
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}... | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All sub... | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"... | 1,611,846,605 | 2,147,483,647 | PyPy 3 | OK | TESTS | 133 | 108 | 0 |
s=input()
while(1):
if(len(s)==1):
print(0)
break
elif(s==s[::-1]):
s=s[1:]
else:
print(len(s))
break | Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar... | ```python
s=input()
while(1):
if(len(s)==1):
print(0)
break
elif(s==s[::-1]):
s=s[1:]
else:
print(len(s))
break
``` | 3 | |
898 | A | Rounding | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which int... | The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. | Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. | [
"5\n",
"113\n",
"1000000000\n",
"5432359\n"
] | [
"0\n",
"110\n",
"1000000000\n",
"5432360\n"
] | In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10. | 500 | [
{
"input": "5",
"output": "0"
},
{
"input": "113",
"output": "110"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "5432359",
"output": "5432360"
},
{
"input": "999999994",
"output": "999999990"
},
{
"input": "10",
"output": "10"
... | 1,651,064,967 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 46 | 0 | n=int(input())
k=n%10
if k>0 and k<6:
print(n-k)
if k==0:
print(n)
if k>5 and k<10:
print (n+10-k) | Title: Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5... | ```python
n=int(input())
k=n%10
if k>0 and k<6:
print(n-k)
if k==0:
print(n)
if k>5 and k<10:
print (n+10-k)
``` | 3 | |
6 | B | President's Office | PROGRAMMING | 1,100 | [
"implementation"
] | B. President's Office | 2 | 64 | President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ... | The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each ... | Print the only number — the amount of President's deputies. | [
"3 4 R\nG.B.\n.RR.\nTTT.\n",
"3 3 Z\n...\n.H.\n..Z\n"
] | [
"2\n",
"0\n"
] | none | 0 | [
{
"input": "3 4 R\nG.B.\n.RR.\nTTT.",
"output": "2"
},
{
"input": "3 3 Z\n...\n.H.\n..Z",
"output": "0"
},
{
"input": "1 1 C\nC",
"output": "0"
},
{
"input": "2 2 W\nKW\nKW",
"output": "1"
},
{
"input": "1 10 H\n....DDHHHH",
"output": "1"
},
{
"input":... | 1,539,460,051 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | // lose small or win big.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;
typedef vector <int> vi;
typedef pair <int, int> ii;
... | Title: President's Office
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides ... | ```python
// lose small or win big.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;
typedef vector <int> vi;
typedef pair <int,... | -1 |
331 | C1 | The Great Julya Calendar | PROGRAMMING | 1,100 | [
"dp"
] | null | null | Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
"May the Great Beaver bless you! May your chacres open ... | The single line contains the magic integer *n*, 0<=≤<=*n*.
- to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with co... | Print a single integer — the minimum number of subtractions that turns the magic number to a zero. | [
"24\n"
] | [
"5"
] | In the first test sample the minimum number of operations can be reached by the following sequence of subtractions: | 20 | [
{
"input": "24",
"output": "5"
},
{
"input": "0",
"output": "0"
},
{
"input": "3",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "31",
"output": "6"
},
... | 1,636,656,060 | 2,147,483,647 | PyPy 3-64 | OK | TESTS1 | 24 | 154 | 33,177,600 | import sys
#rrange = lambda mi, ma: range(ma-1, mi-1, -1)
dp = {}
def one_step(n):
val = max(int(c) for c in str(n))
return n - val
def solve_iter(n):
res = 0
while n > 0:
n = one_step(n)
res += 1
return res
# compute dp[m, 1, a] (go from x9a to x'9b where x' = ... | Title: The Great Julya Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on i... | ```python
import sys
#rrange = lambda mi, ma: range(ma-1, mi-1, -1)
dp = {}
def one_step(n):
val = max(int(c) for c in str(n))
return n - val
def solve_iter(n):
res = 0
while n > 0:
n = one_step(n)
res += 1
return res
# compute dp[m, 1, a] (go from x9a to x'9b w... | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,592,511,085 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 218 | 0 | word = input()
print(word.lower()) | 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
word = input()
print(word.lower())
``` | 0 |
492 | A | Vanya and Cubes | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must... | The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya. | Print the maximum possible height of the pyramid in the single line. | [
"1\n",
"25\n"
] | [
"1\n",
"4\n"
] | Illustration to the second sample: | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "25",
"output": "4"
},
{
"input": "2",
"output": "1"
},
{
"input": "4115",
"output": "28"
},
{
"input": "9894",
"output": "38"
},
{
"input": "7969",
"output": "35"
},
{
"input": "6560",
"outpu... | 1,699,195,124 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 46 | 0 | n = int(input()) #25
f = 1
for i in range(2,10000) : #2 3 4 5 6 7
f += i #3 #6 #10 #15 #21 #28
if f > n :
print(i-1)
break
else :
n -= f | Title: Vanya and Cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the t... | ```python
n = int(input()) #25
f = 1
for i in range(2,10000) : #2 3 4 5 6 7
f += i #3 #6 #10 #15 #21 #28
if f > n :
print(i-1)
break
else :
n -= f
``` | 0 | |
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least... | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
... | 1,591,598,861 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 1,000 | 1,536,000 | n,d=[int(x) for x in input().split(" ")]
l=[int(x) for x in input().split(" ")]
m=0
for i in range(1,len(l)):
while l[i]<=l[i-1]:
l[i]=l[i]+d
m+=1
print(m) | Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*... | ```python
n,d=[int(x) for x in input().split(" ")]
l=[int(x) for x in input().split(" ")]
m=0
for i in range(1,len(l)):
while l[i]<=l[i-1]:
l[i]=l[i]+d
m+=1
print(m)
``` | 0 |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,624,913,240 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | x=input()
cont=0
for e in x:
if e in "aeiou" or e in "02468":
cont+=1
print(cont)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
x=input()
cont=0
for e in x:
if e in "aeiou" or e in "02468":
cont+=1
print(cont)
``` | 0 | |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,623,588,722 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 216 | 0 | import math
n = int(input())
radii = list(map(int, input().split()))
radii.sort()
result = 0
counter = 0
if n % 2 == 1:
result += math.pi*(radii[0]**2)
counter += 2
try:
while True:
r2 = radii[counter]
r1 = radii[counter -1]
result += math.pi*(r2**2 - r1**2)
cou... | Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
import math
n = int(input())
radii = list(map(int, input().split()))
radii.sort()
result = 0
counter = 0
if n % 2 == 1:
result += math.pi*(radii[0]**2)
counter += 2
try:
while True:
r2 = radii[counter]
r1 = radii[counter -1]
result += math.pi*(r2**2 - r1**2)
... | 0 | |
747 | C | Servers | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*.
It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three integers: *t**i* — the moment in seconds in which the task will come, *k**i* — the number of se... | The first line contains two positive integers *n* and *q* (1<=≤<=*n*<=≤<=100, 1<=≤<=*q*<=≤<=105) — the number of servers and the number of tasks.
Next *q* lines contains three integers each, the *i*-th line contains integers *t**i*, *k**i* and *d**i* (1<=≤<=*t**i*<=≤<=106, 1<=≤<=*k**i*<=≤<=*n*, 1<=≤<=*d**i*<=≤<=1000)... | Print *q* lines. If the *i*-th task will be performed by the servers, print in the *i*-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. | [
"4 3\n1 3 2\n2 2 1\n3 4 3\n",
"3 2\n3 2 3\n5 1 2\n",
"8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n"
] | [
"6\n-1\n10\n",
"3\n3\n",
"6\n9\n30\n-1\n15\n36\n"
] | In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third t... | 1,500 | [
{
"input": "4 3\n1 3 2\n2 2 1\n3 4 3",
"output": "6\n-1\n10"
},
{
"input": "3 2\n3 2 3\n5 1 2",
"output": "3\n3"
},
{
"input": "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8",
"output": "6\n9\n30\n-1\n15\n36"
},
{
"input": "4 1\n6 1 1",
"output": "1"
},
{
"inp... | 1,482,210,109 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 61 | 4,608,000 | import heapq as pq
n, q = [int(i) for i in input().split(' ')]
server = [i for i in range(1, n+1)]
running = []
for _ in range(q):
t, k, d = [int(i) for i in input().split(' ')]
while running:
if t >= running[0][0]:
server += pq.heappop(running)[1]
else:
ser... | Title: Servers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*.
It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three in... | ```python
import heapq as pq
n, q = [int(i) for i in input().split(' ')]
server = [i for i in range(1, n+1)]
running = []
for _ in range(q):
t, k, d = [int(i) for i in input().split(' ')]
while running:
if t >= running[0][0]:
server += pq.heappop(running)[1]
else:
... | 0 | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,698,372,070 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | # Read input
n = int(input())
p_info = list(map(int, input().split()))
q_info = list(map(int, input().split()))
# Create sets to store the levels Little X and Little Y can pass
p_levels = set(p_info[1:])
q_levels = set(q_info[1:])
# Create a set of all levels from 1 to n
all_levels = set(range(1, n + 1))
... | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
# Read input
n = int(input())
p_info = list(map(int, input().split()))
q_info = list(map(int, input().split()))
# Create sets to store the levels Little X and Little Y can pass
p_levels = set(p_info[1:])
q_levels = set(q_info[1:])
# Create a set of all levels from 1 to n
all_levels = set(range(1, ... | 3 | |
194 | A | Exams | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could ha... | The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. | Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. | [
"4 8\n",
"4 10\n",
"1 3\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | 500 | [
{
"input": "4 8",
"output": "4"
},
{
"input": "4 10",
"output": "2"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "50 234",
"output": "0"
},
{
"input": "50 100",
"... | 1,405,029,644 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 154 | 0 | n , k = map(int,input().split())
x = (3 * n) - k
if x <= 0 :
print("0")
else:
print(x) | Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend ... | ```python
n , k = map(int,input().split())
x = (3 * n) - k
if x <= 0 :
print("0")
else:
print(x)
``` | 3 | |
574 | B | Bear and Three Musketeers | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"graphs",
"hashing"
] | null | null | Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.
There are *n* warriors. Richelimakieu wants to choose thre... | The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other.
*i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**... | If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). | [
"5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n",
"7 4\n2 1\n3 6\n5 1\n1 7\n"
] | [
"2\n",
"-1\n"
] | In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recogniti... | 1,000 | [
{
"input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5",
"output": "2"
},
{
"input": "7 4\n2 1\n3 6\n5 1\n1 7",
"output": "-1"
},
{
"input": "5 0",
"output": "-1"
},
{
"input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4",
"output": "5"
},
{
... | 1,558,144,298 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 819,200 | # Bear and Three Musketeers
n, m = map(int, input().split())
g = [set() for i in range(n)]
for _ in range(m):
i, j = map(int, input().split())
g[i-1].add(j-1)
g[j-1].add(i-1)
m = float('inf')
for i in range(len(g)-1):
wi = len(g[i])
for j in range(1, len(g)):
wj = len(g[j])
if i in... | Title: Bear and Three Musketeers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three br... | ```python
# Bear and Three Musketeers
n, m = map(int, input().split())
g = [set() for i in range(n)]
for _ in range(m):
i, j = map(int, input().split())
g[i-1].add(j-1)
g[j-1].add(i-1)
m = float('inf')
for i in range(len(g)-1):
wi = len(g[i])
for j in range(1, len(g)):
wj = len(g[j])
... | 0 | |
459 | B | Pashmak and Flowers | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation",
"sortings"
] | null | null | Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). | The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. | [
"2\n1 2\n",
"3\n1 4 5\n",
"5\n3 1 2 3 1\n"
] | [
"1 1",
"4 1",
"2 4"
] | In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers. | 500 | [
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "3\n1 4 5",
"output": "4 1"
},
{
"input": "5\n3 1 2 3 1",
"output": "2 4"
},
{
"input": "2\n1 1",
"output": "0 1"
},
{
"input": "3\n1 1 1",
"output": "0 3"
},
{
"input": "4\n1 1 1 1",
"output": "0 ... | 1,694,575,270 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 171 | 16,588,800 | n=int(input())
str=input().split()
list=[int(ele) for ele in str]
p = 0
for i in range(0,n):
if list[i]>p:
p=list[i]
r=p
for i in range(0,n):
if list[i]<r:
r=list[i]
print(p-r)
c = 0
ca = 0
for i in range(0,n):
if list[i]==p:
c+=1
elif list[i]==r:
... | Title: Pashmak and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have th... | ```python
n=int(input())
str=input().split()
list=[int(ele) for ele in str]
p = 0
for i in range(0,n):
if list[i]>p:
p=list[i]
r=p
for i in range(0,n):
if list[i]<r:
r=list[i]
print(p-r)
c = 0
ca = 0
for i in range(0,n):
if list[i]==p:
c+=1
elif list[i]==... | 0 | |
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider t... | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling t... | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
... | 1,667,384,221 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 154 | 13,619,200 | n = int(input())
cities = list(map(int, input().split()))
ans_time = 10**10
ans = 0
for i in range(n):
if cities[i] < ans_time:
ans_time = cities[i]
ans = i+1
elif cities[i] == ans_time:
ans = 'Still Rozdil'
print(ans) | Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha... | ```python
n = int(input())
cities = list(map(int, input().split()))
ans_time = 10**10
ans = 0
for i in range(n):
if cities[i] < ans_time:
ans_time = cities[i]
ans = i+1
elif cities[i] == ans_time:
ans = 'Still Rozdil'
print(ans)
``` | 3 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,684,960,295 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | s=input().split("WUB")
m=""
for i in s :
m+=i+" "
print(m) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
s=input().split("WUB")
m=""
for i in s :
m+=i+" "
print(m)
``` | 3 | |
883 | M | Quadcopter Competition | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point.
Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point w... | The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point.
The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag.
It is guaranteed that the quadcopter sta... | Print the length of minimal path of the quadcopter to surround the flag and return back. | [
"1 5\n5 2\n",
"0 1\n0 0\n"
] | [
"18\n",
"8\n"
] | none | 0 | [
{
"input": "1 5\n5 2",
"output": "18"
},
{
"input": "0 1\n0 0",
"output": "8"
},
{
"input": "-100 -100\n100 100",
"output": "804"
},
{
"input": "-100 -100\n-100 100",
"output": "406"
},
{
"input": "-100 -100\n100 -100",
"output": "406"
},
{
"input": "1... | 1,660,928,485 | 2,147,483,647 | Python 3 | OK | TESTS | 100 | 46 | 0 | x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
a, b = abs(x2-x1), abs(y2-y1)
if a == 0:
print(4 + 2 * (b + 1))
elif b == 0:
print(2 * (a + 1) + 4)
else:
print(2*(a+1)+2*(b+1))
| Title: Quadcopter Competition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting p... | ```python
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
a, b = abs(x2-x1), abs(y2-y1)
if a == 0:
print(4 + 2 * (b + 1))
elif b == 0:
print(2 * (a + 1) + 4)
else:
print(2*(a+1)+2*(b+1))
``` | 3 | |
681 | A | A Good Contest | PROGRAMMING | 800 | [
"implementation"
] | null | null | Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of hi... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*be... | Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. | [
"3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n",
"3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n"
] | [
"YES",
"NO"
] | In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before... | 500 | [
{
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "NO"
},
{
"input": "1\nDb -3373 3591",
"output": "NO"
},
{
"input": "5\nQ2bz 960 2342... | 1,540,206,968 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 109 | 0 | n=int(input())
can=False
for i in range(n):
s,x,y=input().split()
x=int(x)
y=int(y)
if x>=2400 and y>x:
can=True
break
if can:
print("YES")
else:
print("NO") | Title: A Good Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part ... | ```python
n=int(input())
can=False
for i in range(n):
s,x,y=input().split()
x=int(x)
y=int(y)
if x>=2400 and y>x:
can=True
break
if can:
print("YES")
else:
print("NO")
``` | 3 | |
414 | B | Mashmokh and ACM | PROGRAMMING | 1,400 | [
"combinatorics",
"dp",
"number theory"
] | null | null | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced prog... | The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000). | Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7). | [
"3 2\n",
"6 4\n",
"2 1\n"
] | [
"5\n",
"39\n",
"2\n"
] | In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3]. | 1,000 | [
{
"input": "3 2",
"output": "5"
},
{
"input": "6 4",
"output": "39"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "1478 194",
"output": "312087753"
},
{
"input": "1415 562",
"output": "953558593"
},
{
"input": "1266 844",
"output": "735042656"
... | 1,655,547,601 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 93 | 3,379,200 | import math
def dividors(n):
d = []
for i in range(1, int(math.sqrt(n))+1):
if n%i == 0:
d.append(i)
if i*i != n:
d.append(n//i)
return d
nm, km = map(int, input().split())
dp = [[0]*(nm+1) for i in range(km+1)]
div = [dividors(i) for i in range(nm+1)]
for... | Title: Mashmokh and ACM
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join h... | ```python
import math
def dividors(n):
d = []
for i in range(1, int(math.sqrt(n))+1):
if n%i == 0:
d.append(i)
if i*i != n:
d.append(n//i)
return d
nm, km = map(int, input().split())
dp = [[0]*(nm+1) for i in range(km+1)]
div = [dividors(i) for i in range(... | 0 | |
898 | C | Phone Numbers | PROGRAMMING | 1,400 | [
"implementation",
"strings"
] | null | null | Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a f... | First line contains the integer *n* (1<=≤<=*n*<=≤<=20) — number of entries in Vasya's phone books.
The following *n* lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase E... | Print out the ordered information about the phone numbers of Vasya's friends. First output *m* — number of friends that are found in Vasya's phone books.
The following *m* lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each... | [
"2\nivan 1 00123\nmasha 1 00123\n",
"3\nkarl 2 612 12\npetr 1 12\nkatya 1 612\n",
"4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789\n"
] | [
"2\nmasha 1 00123 \nivan 1 00123 \n",
"3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 \n",
"2\ndasha 2 23 789 \nivan 4 789 123 2 456 \n"
] | none | 1,500 | [
{
"input": "2\nivan 1 00123\nmasha 1 00123",
"output": "2\nmasha 1 00123 \nivan 1 00123 "
},
{
"input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612",
"output": "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 "
},
{
"input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndash... | 1,538,209,079 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 124 | 0 | n=int(input())
d={}
for i in range(n) :
a,*b=input().split()
d[a]=d.get(a,[])+b[1:]
print(len(d))
for x in d :
L=list(set(d[x]))
l=[]
for i in range(len(L)) :
flaf=True
for j in range(len(L)) :
if i!=j and L[j].endswith(L[i]) :
flaf=False
... | Title: Phone Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize information about the phone numbers of friend... | ```python
n=int(input())
d={}
for i in range(n) :
a,*b=input().split()
d[a]=d.get(a,[])+b[1:]
print(len(d))
for x in d :
L=list(set(d[x]))
l=[]
for i in range(len(L)) :
flaf=True
for j in range(len(L)) :
if i!=j and L[j].endswith(L[i]) :
flaf=... | 3 | |
845 | C | Two TVs | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at a... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows.
Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=109) — starting and ending time of *i*-th show. | If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes). | [
"3\n1 2\n2 3\n4 5\n",
"4\n1 2\n2 3\n2 3\n1 2\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 2\n2 3\n4 5",
"output": "YES"
},
{
"input": "4\n1 2\n2 3\n2 3\n1 2",
"output": "NO"
},
{
"input": "4\n0 1\n1 2\n2 3\n3 4",
"output": "YES"
},
{
"input": "3\n1 2\n2 3\n2 4",
"output": "NO"
},
{
"input": "3\n0 100\n0 100\n0 100",
"output": "NO"
... | 1,503,332,785 | 4,885 | Python 3 | WRONG_ANSWER | TESTS | 10 | 607 | 9,011,200 | n = int(input())
a = [n]
b = [n]
for i in range(n):
x, y = map(int, input().split())
a.append(x)
b.append(y)
a.pop(0)
b.pop(0)
def huj(n):
for i in range(n - 1):
if a[i] >= a[i+1] or b[i] >= b[i+1]:
return False
return True
if huj(n) == True:
print('YES')
else:
print('... | Title: Two TVs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He ... | ```python
n = int(input())
a = [n]
b = [n]
for i in range(n):
x, y = map(int, input().split())
a.append(x)
b.append(y)
a.pop(0)
b.pop(0)
def huj(n):
for i in range(n - 1):
if a[i] >= a[i+1] or b[i] >= b[i+1]:
return False
return True
if huj(n) == True:
print('YES')
else:
... | 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,590,387,801 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 248 | 0 | list1=list(map(int,input().split()))
list2=[]
co=0
count=0
a=0
for j in range(len(list1)):
while list1[j]>2:
list1[j]-=3
count+=1
co=list1[j]
list2.append(co)
for j in range(len(list2)):
a+=list2[j]
b=a/3
if a%3==0:
count+=b
print(int(count))
| 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
list1=list(map(int,input().split()))
list2=[]
co=0
count=0
a=0
for j in range(len(list1)):
while list1[j]>2:
list1[j]-=3
count+=1
co=list1[j]
list2.append(co)
for j in range(len(list2)):
a+=list2[j]
b=a/3
if a%3==0:
count+=b
print(int(count))
``` | 0 | |
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such th... | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multi... | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | 1,620,687,837 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 6,963,200 | def hw6problemE():
x = str(input())
xsplit = x.split()
n = int(xsplit[0])
m = int(xsplit[1])
if n == m:
rsnt = ""
for i in range(0, n):
rsnt = rsnt + "B"
rsnt = rsnt + "G"
print(rsnt)
elif n > m:
r = n - m
rsnt = ""
for i in... | Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by n... | ```python
def hw6problemE():
x = str(input())
xsplit = x.split()
n = int(xsplit[0])
m = int(xsplit[1])
if n == m:
rsnt = ""
for i in range(0, n):
rsnt = rsnt + "B"
rsnt = rsnt + "G"
print(rsnt)
elif n > m:
r = n - m
rsnt = ""
... | 0 | |
873 | A | Chores | PROGRAMMING | 800 | [
"implementation"
] | null | null | Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted.
Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of ... | The first line contains three integers *n*,<=*k*,<=*x* (1<=≤<=*k*<=≤<=*n*<=≤<=100,<=1<=≤<=*x*<=≤<=99) — the number of chores Luba has to do, the number of chores she can do in *x* units of time, and the number *x* itself.
The second line contains *n* integer numbers *a**i* (2<=≤<=*a**i*<=≤<=100) — the time Luba has to... | Print one number — minimum time Luba needs to do all *n* chores. | [
"4 2 2\n3 6 7 10\n",
"5 2 1\n100 100 100 100 100\n"
] | [
"13\n",
"302\n"
] | In the first example the best option would be to do the third and the fourth chore, spending *x* = 2 time on each instead of *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, respectively. Then the answer is 3 + 6 + 2 + 2 = 13.
In the second example Luba can choose any two chores to spend *x... | 0 | [
{
"input": "4 2 2\n3 6 7 10",
"output": "13"
},
{
"input": "5 2 1\n100 100 100 100 100",
"output": "302"
},
{
"input": "1 1 1\n100",
"output": "1"
},
{
"input": "100 1 99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ... | 1,613,669,403 | 2,147,483,647 | PyPy 3 | OK | TESTS | 11 | 93 | 0 | if __name__ == "__main__":
n, k, x = list(map(int, input().split()))
chore_times = list(map(int, input().split()))
for i in range(1, k + 1):
chore_times[-i] = x
print(sum(chore_times))
| Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted.
Also Luba can work really hard on s... | ```python
if __name__ == "__main__":
n, k, x = list(map(int, input().split()))
chore_times = list(map(int, input().split()))
for i in range(1, k + 1):
chore_times[-i] = x
print(sum(chore_times))
``` | 3 | |
551 | B | ZgukistringZ | PROGRAMMING | 1,800 | [
"brute force",
"constructive algorithms",
"implementation",
"strings"
] | null | null | Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.
GukiZ has strings *a*, *b*, and *c*. He wants to obtain string *k* by swapping some letters in *a*, so that *k* should contain as many non-overlapping substrings equal either to *b* or *c* as possible. Subst... | The first line contains string *a*, the second line contains string *b*, and the third line contains string *c* (1<=≤<=|*a*|,<=|*b*|,<=|*c*|<=≤<=105, where |*s*| denotes the length of string *s*).
All three strings consist only of lowercase English letters.
It is possible that *b* and *c* coincide. | Find one of possible strings *k*, as described in the problem statement. If there are multiple possible answers, print any of them. | [
"aaa\na\nb\n",
"pozdravstaklenidodiri\nniste\ndobri\n",
"abbbaaccca\nab\naca\n"
] | [
"aaa",
"nisteaadddiiklooprrvz",
"ababacabcc"
] | In the third sample, this optimal solutions has three non-overlaping substrings equal to either *b* or *c* on positions 1 – 2 (*ab*), 3 – 4 (*ab*), 5 – 7 (*aca*). In this sample, there exist many other optimal solutions, one of them would be *acaababbcc*. | 1,250 | [
{
"input": "aaa\na\nb",
"output": "aaa"
},
{
"input": "pozdravstaklenidodiri\nniste\ndobri",
"output": "nisteaadddiiklooprrvz"
},
{
"input": "abbbaaccca\nab\naca",
"output": "ababacabcc"
},
{
"input": "lemigazalemiolemilicomzalemljenje\nlemi\nzlo",
"output": "lemilemilemi... | 1,434,134,038 | 6,538 | Python 3 | MEMORY_LIMIT_EXCEEDED | PRETESTS | 6 | 1,247 | 268,390,400 | from fileinput import *
for line in input():
if lineno() == 1:
a = line.strip()
if lineno() == 2:
b = line.strip()
if lineno() == 3:
c = line.strip()
la = len(a)
list_a = list(a)
ld = []
lb = len(b)
lc = len(c)
def how_many_sets(substring, string):
ls = len(substring)
ran... | Title: ZgukistringZ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.
GukiZ has strings *a*, *b*, and *c*. He wants to obtain string *k* by swapping some letters in *a*, so that *... | ```python
from fileinput import *
for line in input():
if lineno() == 1:
a = line.strip()
if lineno() == 2:
b = line.strip()
if lineno() == 3:
c = line.strip()
la = len(a)
list_a = list(a)
ld = []
lb = len(b)
lc = len(c)
def how_many_sets(substring, string):
ls = len(substrin... | 0 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,636,353,085 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 77 | 28,364,800 | ans = 0 ; pre = ord('a')
for i in input():
x = ord(i)
m = abs(x-pre)
if m>13: m = 26-m
ans += m ; pre = x
print(ans) | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
ans = 0 ; pre = ord('a')
for i in input():
x = ord(i)
m = abs(x-pre)
if m>13: m = 26-m
ans += m ; pre = x
print(ans)
``` | 3 | |
177 | F1 | Script Generation | PROGRAMMING | 1,800 | [] | null | null | The Smart Beaver from ABBYY was offered a job of a screenwriter for the ongoing TV series. In particular, he needs to automate the hard decision: which main characters will get married by the end of the series.
There are *n* single men and *n* single women among the main characters. An opinion poll showed that viewers... | The first input line contains integers *n*, *k* and *t* (1<=≤<=*k*<=≤<=*min*(100,<=*n*2), 1<=≤<=*t*<=≤<=2·105), separated by single spaces. Next *k* lines contain triples of integers (*h*,<=*w*,<=*r*) (1<=≤<=*h*,<=*w*<=≤<=*n*; 1<=≤<=*r*<=≤<=1000), separated by single spaces, which describe the possible marriages. It is... | Print a single number — the value of the *t*-th acceptable variant. | [
"2 4 3\n1 1 1\n1 2 2\n2 1 3\n2 2 7\n",
"2 4 7\n1 1 1\n1 2 2\n2 1 3\n2 2 7\n"
] | [
"2\n",
"8\n"
] | The figure shows 7 acceptable sets of marriages that exist in the first sample. | 30 | [
{
"input": "2 4 3\n1 1 1\n1 2 2\n2 1 3\n2 2 7",
"output": "2"
},
{
"input": "2 4 7\n1 1 1\n1 2 2\n2 1 3\n2 2 7",
"output": "8"
},
{
"input": "2 2 1\n1 2 8\n2 2 1",
"output": "0"
},
{
"input": "5 25 140\n3 5 40\n3 3 42\n4 5 62\n2 4 7\n4 2 57\n1 5 69\n3 2 37\n2 5 43\n2 3 14\n1 ... | 1,475,450,266 | 2,147,483,647 | Python 3 | OK | TESTS1 | 12 | 124 | 0 | I=lambda:list(map(int,input().split()))
n,k,T=I()
t=[I()for _ in '0'*k]
def b(h,w,r,a):
if h>n:a+=[r]
else:
b(h+1,w,r,a)
for f,s,v in t:
if f==h and s in w:b(h+1,w-set([s]),r+v,a)
return a
print(sorted(b(1,set(range(1,n+1)), 0,[]))[T-1]) | Title: Script Generation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY was offered a job of a screenwriter for the ongoing TV series. In particular, he needs to automate the hard decision: which main characters will get married by the end of the series.
There... | ```python
I=lambda:list(map(int,input().split()))
n,k,T=I()
t=[I()for _ in '0'*k]
def b(h,w,r,a):
if h>n:a+=[r]
else:
b(h+1,w,r,a)
for f,s,v in t:
if f==h and s in w:b(h+1,w-set([s]),r+v,a)
return a
print(sorted(b(1,set(range(1,n+1)), 0,[]))[T-1])
``` | 3 | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,695,839,178 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 62 | 0 | import math
r, x, y, nx, ny = map(int,input().split())
step = 2*r
d = math.sqrt((nx-x)**2 + (ny-y)**2)
l, r = 0, 10**10
ans = 10**10
while l <= r :
mid = (l+r)//2
cur = step*mid
if(cur + 10**(-9) > d) :
ans = mid
r = mid - 1
else :
l = mid + 1
print(ans) | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
import math
r, x, y, nx, ny = map(int,input().split())
step = 2*r
d = math.sqrt((nx-x)**2 + (ny-y)**2)
l, r = 0, 10**10
ans = 10**10
while l <= r :
mid = (l+r)//2
cur = step*mid
if(cur + 10**(-9) > d) :
ans = mid
r = mid - 1
else :
l = mid + 1
print(ans)
`... | 3 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,694,571,740 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | k, n, w = map(int, input().split())
sum = 0
lal = w + 1
for i in range(1, lal):
sum += k * i
if sum > 17:
print(sum-n)
else:
print(0)
| Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
k, n, w = map(int, input().split())
sum = 0
lal = w + 1
for i in range(1, lal):
sum += k * i
if sum > 17:
print(sum-n)
else:
print(0)
``` | 0 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,698,489,805 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | def solve():
years = 0
a = int(input())
b = int(input())
while a <= b:
a *= 3
b *= 2
years += 1
return years
# Read input
# Calculate and print the number of years
print(solve()) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
def solve():
years = 0
a = int(input())
b = int(input())
while a <= b:
a *= 3
b *= 2
years += 1
return years
# Read input
# Calculate and print the number of years
print(solve())
``` | -1 | |
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,606,611,859 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 3 | 2,012 | 268,390,400 | import sys
input = sys.stdin.readline
def inInt():
return int(input())
def inStr():
return input().strip("\n")
def inIList():
return(list(map(int, input().split())))
def inSList():
return(input().split())
def bsearch(nums, target):
N = len(nums or [])
l = 0
r... | 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
import sys
input = sys.stdin.readline
def inInt():
return int(input())
def inStr():
return input().strip("\n")
def inIList():
return(list(map(int, input().split())))
def inSList():
return(input().split())
def bsearch(nums, target):
N = len(nums or [])
l ... | 0 | |
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen... | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $... | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"... | 1,562,564,693 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 140 | 0 | n, m = map(int, input().split(" "))
sequence = list(map(int, input().split(" ")))
fingerprints = list(map(int, input().split(" ")))
for ele in sequence:
if ele in fingerprints:
print(ele, end = ' ') | Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keyp... | ```python
n, m = map(int, input().split(" "))
sequence = list(map(int, input().split(" ")))
fingerprints = list(map(int, input().split(" ")))
for ele in sequence:
if ele in fingerprints:
print(ele, end = ' ')
``` | 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,677,506,476 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | n = int(input())
a = 0
b = 0
c = 0
for i in range(n):
xyz = list(map(int,input().split()))
a += xyz[0]
b += xyz[1]
c += xyz[2]
if (a,b,c) == (0,0,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())
a = 0
b = 0
c = 0
for i in range(n):
xyz = list(map(int,input().split()))
a += xyz[0]
b += xyz[1]
c += xyz[2]
if (a,b,c) == (0,0,0):
print('YES')
else:
print('NO')
``` | 3.977 |
755 | B | PolandBall and Game | PROGRAMMING | 1,100 | [
"binary search",
"data structures",
"games",
"greedy",
"sortings",
"strings"
] | null | null | PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively.
Then *n* strings follow, one per line — words familiar to PolandBall.
Then *m* strings follow, one per line — words familiar to EnemyBall.
Note that one Ball cannot know a w... | In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally. | [
"5 1\npolandball\nis\na\ncool\ncharacter\nnope\n",
"2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n",
"1 2\na\na\nb\n"
] | [
"YES",
"YES",
"NO"
] | In the first example PolandBall knows much more words and wins effortlessly.
In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins. | 1,000 | [
{
"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope",
"output": "YES"
},
{
"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska",
"output": "YES"
},
{
"input": "1 2\na\na\nb",
"output": "NO"
},
{
"input": "2 2\na\nb\nb\nc",
"output": "YES"
},
{
"input": "... | 1,698,481,996 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 1,433,600 | n, m = list(map(int, input().split()))
PolandBall = set()
EnemyBall = set()
for i in range(n):
PolandBall.add(input())
for i in range(m):
EnemyBall.add(input())
intersectionSet = PolandBall.intersection(EnemyBall)
PolandBall = PolandBall.difference(intersectionSet)
EnemyBall = EnemyBall.difference(inte... | Title: PolandBall and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You... | ```python
n, m = list(map(int, input().split()))
PolandBall = set()
EnemyBall = set()
for i in range(n):
PolandBall.add(input())
for i in range(m):
EnemyBall.add(input())
intersectionSet = PolandBall.intersection(EnemyBall)
PolandBall = PolandBall.difference(intersectionSet)
EnemyBall = EnemyBall.diffe... | 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,452,824,750 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 716,800 | import fileinput as fi
def odd_one_out(nums):
even_found, odd_found = False, False
for index in range(len(nums)):
next = nums[index]
if (((next % 2 == 0) and odd_found) or ((next % 2 == 1) and even_found)):
return index + 1
elif ((next % 2 == 0) and not (even_found)):
even_found = True
elif (... | 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
import fileinput as fi
def odd_one_out(nums):
even_found, odd_found = False, False
for index in range(len(nums)):
next = nums[index]
if (((next % 2 == 0) and odd_found) or ((next % 2 == 1) and even_found)):
return index + 1
elif ((next % 2 == 0) and not (even_found)):
even_found = True... | 0 |
946 | B | Weird Subtraction Process | PROGRAMMING | 1,100 | [
"math",
"number theory"
] | null | null | You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then s... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*. | Print two integers — the values of *a* and *b* after the end of the process. | [
"12 5\n",
"31 12\n"
] | [
"0 1\n",
"7 12\n"
] | Explanations to the samples:
1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0... | 0 | [
{
"input": "12 5",
"output": "0 1"
},
{
"input": "31 12",
"output": "7 12"
},
{
"input": "1000000000000000000 7",
"output": "8 7"
},
{
"input": "31960284556200 8515664064180",
"output": "14928956427840 8515664064180"
},
{
"input": "1000000000000000000 100000000000... | 1,568,953,882 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 217 | 716,800 | a,b = map(int,input().split())
def one(a,b):
if(a==0) or (b==0):
print(a,b)
exit()
else:
two(a,b)
def two(a,b):
if(a>=2*b):
a=a-2*b
one(a,b)
else:
three(a,b)
def three(a,b):
if(b>=2*a):
b=b-2*a
one(... | Title: Weird Subtraction Process
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then... | ```python
a,b = map(int,input().split())
def one(a,b):
if(a==0) or (b==0):
print(a,b)
exit()
else:
two(a,b)
def two(a,b):
if(a>=2*b):
a=a-2*b
one(a,b)
else:
three(a,b)
def three(a,b):
if(b>=2*a):
b=b-2*a
... | -1 | |
455 | C | Civilization | PROGRAMMING | 2,100 | [
"dfs and similar",
"dp",
"dsu",
"ternary search",
"trees"
] | null | null | Andrew plays a game called "Civilization". Dima helps him.
The game has *n* cities and *m* bidirectional roads. The cities are numbered from 1 to *n*. Between any pair of cities there either is a single (unique) path, or there is no path at all. A path is such a sequence of distinct cities *v*1,<=*v*2,<=...,<=*v**k*, ... | The first line contains three integers *n*, *m*, *q* (1<=≤<=*n*<=≤<=3·105; 0<=≤<=*m*<=<<=*n*; 1<=≤<=*q*<=≤<=3·105) — the number of cities, the number of the roads we already have and the number of queries, correspondingly.
Each of the following *m* lines contains two integers, *a**i* and *b**i* (*a**i*<=≠<=*b**i*; ... | For each event of the first type print the answer on a separate line. | [
"6 0 6\n2 1 2\n2 3 4\n2 5 6\n2 3 2\n2 5 3\n1 1\n"
] | [
"4\n"
] | none | 1,500 | [] | 1,677,044,926 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 1 | 982 | 268,390,400 | import fractions
import gc
import heapq
import itertools
from itertools import combinations, permutations
import math
import random
from collections import Counter, deque, defaultdict
from sys import stdout
import time
from math import factorial, log, gcd
import sys
from decimal import Decimal
import threa... | Title: Civilization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrew plays a game called "Civilization". Dima helps him.
The game has *n* cities and *m* bidirectional roads. The cities are numbered from 1 to *n*. Between any pair of cities there either is a single (unique) path, or ... | ```python
import fractions
import gc
import heapq
import itertools
from itertools import combinations, permutations
import math
import random
from collections import Counter, deque, defaultdict
from sys import stdout
import time
from math import factorial, log, gcd
import sys
from decimal import Decimal
im... | 0 | |
796 | B | Find The Bone | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*.
The problematic bone is initially at the position *x*<==<=1. Zane will co... | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.
The second line contains *m* distinct integers *h*1,<=*h*2,<=...,<=*h**m* (1<=≤<=*h**i*<=≤<=*... | Print one integer — the final position along the *x*-axis of the bone. | [
"7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n",
"5 1 2\n2\n1 2\n2 4\n"
] | [
"1",
"2"
] | In the first sample, after the operations, the bone becomes at *x* = 2, *x* = 5, *x* = 7, and *x* = 1, respectively.
In the second sample, after the first operation, the bone becomes at *x* = 2, and falls into the hole onto the ground. | 750 | [
{
"input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1",
"output": "1"
},
{
"input": "5 1 2\n2\n1 2\n2 4",
"output": "2"
},
{
"input": "10000 1 9\n55\n44 1\n2929 9292\n9999 9998\n44 55\n49 94\n55 53\n100 199\n55 50\n53 11",
"output": "55"
},
{
"input": "100000 3 7\n2 3 4\n1 5\n5 1\n1 5... | 1,547,826,798 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 20,377,600 | n,m,k = (int(i) for i in input().split(' '))
a = [int(i) for i in input().split()]
i = 0
j = 1
f = 0
s = 0
while (i < k):
b = [int(i) for i in input().split(' ')]
if (s == 0):
if(j == b[0]):
j = b[1]
if (j in a):
f = j
s= 1
elif(j == b[1])... | Title: Find The Bone
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at t... | ```python
n,m,k = (int(i) for i in input().split(' '))
a = [int(i) for i in input().split()]
i = 0
j = 1
f = 0
s = 0
while (i < k):
b = [int(i) for i in input().split(' ')]
if (s == 0):
if(j == b[0]):
j = b[1]
if (j in a):
f = j
s= 1
elif(... | 0 | |
369 | A | Valera and Plates | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can... | The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Val... | Print a single integer — the minimum number of times Valera will need to wash a plate/bowl. | [
"3 1 1\n1 2 1\n",
"4 3 1\n1 1 1 1\n",
"3 1 2\n2 2 2\n",
"8 2 2\n1 2 1 2 1 2 1 2\n"
] | [
"1\n",
"1\n",
"0\n",
"4\n"
] | In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all... | 500 | [
{
"input": "3 1 1\n1 2 1",
"output": "1"
},
{
"input": "4 3 1\n1 1 1 1",
"output": "1"
},
{
"input": "3 1 2\n2 2 2",
"output": "0"
},
{
"input": "8 2 2\n1 2 1 2 1 2 1 2",
"output": "4"
},
{
"input": "2 100 100\n2 2",
"output": "0"
},
{
"input": "1 1 1\... | 1,500,468,778 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 46 | 4,608,000 | n,m,k=[int(i) for i in input().split()]
t=0
a=[int(i) for i in input().split()]
kases=a.count(1)
if m==kases:
result=(n-kases)-m
result=max(0,result)
if m<kases:
result=kases-m
result2=max((n-kases)-m,0)
result=result2+result
else:
j1=m-kases
k=j1+n
resault=max(0,(n-kases)-... | Title: Valera and Plates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, ... | ```python
n,m,k=[int(i) for i in input().split()]
t=0
a=[int(i) for i in input().split()]
kases=a.count(1)
if m==kases:
result=(n-kases)-m
result=max(0,result)
if m<kases:
result=kases-m
result2=max((n-kases)-m,0)
result=result2+result
else:
j1=m-kases
k=j1+n
resault=max(0,... | -1 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,690,187,704 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | def watermelon(w):
if w%2!=0:
return "NO"
else:
half=w//2
if half%2==0:
return "YES"
else:
return "NO"
weight=8
result=watermelon(weight)
print(result) | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
def watermelon(w):
if w%2!=0:
return "NO"
else:
half=w//2
if half%2==0:
return "YES"
else:
return "NO"
weight=8
result=watermelon(weight)
print(result)
``` | 0 |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,690,003,736 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 124 | 0 | s=input()
l=['H','Q','9']
flag=0
for i in l:
if i in s:
flag=1
if flag:
print("YES")
else:
print("NO") | Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in... | ```python
s=input()
l=['H','Q','9']
flag=0
for i in l:
if i in s:
flag=1
if flag:
print("YES")
else:
print("NO")
``` | 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,445,890,101 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 1,029 | 93,798,400 | def main(name, n, m):
for i in range(m):
name = (lambda word, x, y: (y if i == x else (x if i == y else i) for i in word))(name, *input().split())
return "".join(name)
n, m = map(int, input().split())
name = input()
print(main(name, n, m))
| 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
def main(name, n, m):
for i in range(m):
name = (lambda word, x, y: (y if i == x else (x if i == y else i) for i in word))(name, *input().split())
return "".join(name)
n, m = map(int, input().split())
name = input()
print(main(name, n, m))
``` | -1 | |
938 | B | Run For Your Prize | PROGRAMMING | 1,100 | [
"brute force",
"greedy"
] | null | null | You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these tw... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order. | Print one integer — the minimum number of seconds it will take to collect all prizes. | [
"3\n2 3 9\n",
"2\n2 999995\n"
] | [
"8\n",
"5\n"
] | In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.
In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5. | 0 | [
{
"input": "3\n2 3 9",
"output": "8"
},
{
"input": "2\n2 999995",
"output": "5"
},
{
"input": "1\n20",
"output": "19"
},
{
"input": "6\n2 3 500000 999997 999998 999999",
"output": "499999"
},
{
"input": "1\n999999",
"output": "1"
},
{
"input": "1\n5100... | 1,594,661,341 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 171 | 30,515,200 | n=int(input())
a=list(map(int,input().split()))
a.sort()
c=0
for i in range(n-1):
c=c+min(a[i]-1,a[i+1]-a[i],(1000000-a[i]))
c=c+min(a[n-1]-1,(1000000-a[n-1]),a[n-1]-a[n-2])
if((c-1)<0):
print(0)
else:
print(c-1) | Title: Run For Your Prize
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are di... | ```python
n=int(input())
a=list(map(int,input().split()))
a.sort()
c=0
for i in range(n-1):
c=c+min(a[i]-1,a[i+1]-a[i],(1000000-a[i]))
c=c+min(a[n-1]-1,(1000000-a[n-1]),a[n-1]-a[n-2])
if((c-1)<0):
print(0)
else:
print(c-1)
``` | 0 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,697,385,020 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | x=input().strip()
capt=x[0].upper()+x[1:]
print(capt) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
x=input().strip()
capt=x[0].upper()+x[1:]
print(capt)
``` | 3 | |
820 | B | Mister B and Angle in Polygon | PROGRAMMING | 1,300 | [
"constructive algorithms",
"geometry",
"math"
] | null | null | On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides).
That's why Mister B decided to use this polygon. Now Mister B must... | First and only line contains two space-separated integers *n* and *a* (3<=≤<=*n*<=≤<=105, 1<=≤<=*a*<=≤<=180) — the number of vertices in the polygon and the needed angle, in degrees. | Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order. | [
"3 15\n",
"4 67\n",
"4 68\n"
] | [
"1 2 3\n",
"2 1 3\n",
"4 1 2\n"
] | In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.
Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: ... | 1,000 | [
{
"input": "3 15",
"output": "2 1 3"
},
{
"input": "4 67",
"output": "2 1 3"
},
{
"input": "4 68",
"output": "2 1 4"
},
{
"input": "3 1",
"output": "2 1 3"
},
{
"input": "3 180",
"output": "2 1 3"
},
{
"input": "100000 1",
"output": "2 1 558"
},
... | 1,498,576,982 | 2,882 | PyPy 3 | WRONG_ANSWER | PRETESTS | 6 | 93 | 23,142,400 | """
Author : Arif Ahmad
Date :
Algo :
Difficulty :
"""
from sys import stdin, stdout
def main():
n, a = [int(_) for _ in stdin.readline().strip().split()]
if n == 3:
stdout.write('1 2 3\n')
return
smallest = 180 / n
required = a // smallest
if required == 0: ans = 3
else:
... | Title: Mister B and Angle in Polygon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *... | ```python
"""
Author : Arif Ahmad
Date :
Algo :
Difficulty :
"""
from sys import stdin, stdout
def main():
n, a = [int(_) for _ in stdin.readline().strip().split()]
if n == 3:
stdout.write('1 2 3\n')
return
smallest = 180 / n
required = a // smallest
if required == 0: ans = 3
... | 0 | |
44 | H | Phone Number | PROGRAMMING | 1,700 | [
"dp"
] | H. Phone Number | 2 | 256 | Alas, finding one's true love is not easy. Masha has been unsuccessful in that yet. Her friend Dasha told Masha about a way to determine the phone number of one's Prince Charming through arithmancy.
The phone number is divined like that. First one needs to write down one's own phone numbers. For example, let's suppos... | The first line contains nonempty sequence consisting of digits from 0 to 9 — Masha's phone number. The sequence length does not exceed 50. | Output the single number — the number of phone numbers Masha will dial. | [
"12345\n",
"09\n"
] | [
"48\n",
"15\n"
] | none | 0 | [
{
"input": "12345",
"output": "48"
},
{
"input": "09",
"output": "15"
},
{
"input": "3",
"output": "9"
},
{
"input": "55",
"output": "14"
},
{
"input": "737",
"output": "23"
},
{
"input": "21583",
"output": "55"
},
{
"input": "33408349",
... | 1,658,301,723 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 122 | 0 | import os
import sys
from math import floor, ceil
if os.getenv('LOCALCFTEST'):
sys.stdin = open('cfinput.txt')
MOD = 998244353
def solve(s):
s = list(map(int, s))
n = len(s)
dp = [[0] * 10 for _ in range(n)]
dp[0] = [1] * 10
flag = True
for i in range(n - 1):
t = (... | Title: Phone Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Alas, finding one's true love is not easy. Masha has been unsuccessful in that yet. Her friend Dasha told Masha about a way to determine the phone number of one's Prince Charming through arithmancy.
The phone number is divin... | ```python
import os
import sys
from math import floor, ceil
if os.getenv('LOCALCFTEST'):
sys.stdin = open('cfinput.txt')
MOD = 998244353
def solve(s):
s = list(map(int, s))
n = len(s)
dp = [[0] * 10 for _ in range(n)]
dp[0] = [1] * 10
flag = True
for i in range(n - 1):
... | 3.9695 |
6 | D | Lizards and Basements 2 | PROGRAMMING | 2,600 | [
"brute force",
"dp"
] | D. Lizards and Basements 2 | 2 | 64 | This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the las... | The first line of the input contains three integers *n*,<=*a*,<=*b* (3<=≤<=*n*<=≤<=10; 1<=≤<=*b*<=<<=*a*<=≤<=10). The second line contains a sequence of *n* integers — *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=15), where *h**i* is the amount of health points the *i*-th archer has. | In the first line print *t* — the required minimum amount of fire balls.
In the second line print *t* numbers — indexes of the archers that Polycarp should hit to kill all the archers in *t* shots. All these numbers should be between 2 and *n*<=-<=1. Separate numbers with spaces. If there are several solutions, output... | [
"3 2 1\n2 2 2\n",
"4 3 1\n1 4 1 1\n"
] | [
"3\n2 2 2 ",
"4\n2 2 3 3 "
] | none | 0 | [
{
"input": "3 2 1\n2 2 2",
"output": "3\n2 2 2 "
},
{
"input": "4 3 1\n1 4 1 1",
"output": "4\n2 2 3 3 "
},
{
"input": "3 5 3\n1 2 1",
"output": "1\n2 "
},
{
"input": "3 5 3\n3 2 2",
"output": "2\n2 2 "
},
{
"input": "3 5 3\n3 2 2",
"output": "2\n2 2 "
},
... | 1,430,980,417 | 2,147,483,647 | Python 3 | OK | TESTS | 117 | 124 | 0 | __author__ = 'Darren'
def solve():
n, a, b = map(int, input().split())
h = [0]
h.extend(map(int, input().split()))
fires = []
count = h[1] // b + 1 if h[1] >= 0 else 0
fires.extend([2 for i in range(count)])
h[1] -= b * count
h[2] -= a * count
h[3] -= b * count
c... | Title: Lizards and Basements 2
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer ro... | ```python
__author__ = 'Darren'
def solve():
n, a, b = map(int, input().split())
h = [0]
h.extend(map(int, input().split()))
fires = []
count = h[1] // b + 1 if h[1] >= 0 else 0
fires.extend([2 for i in range(count)])
h[1] -= b * count
h[2] -= a * count
h[3] -= b * co... | 3.969 |
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.