contestId int64 0 1.01k | index stringclasses 40
values | name stringlengths 2 54 | type stringclasses 2
values | rating int64 0 3.4k | tags listlengths 0 7 | title stringclasses 393
values | time-limit stringclasses 7
values | memory-limit stringclasses 6
values | problem-description stringlengths 0 2.97k | input-specification stringlengths 4 1.87k | output-specification stringlengths 4 1.12k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 3.5k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 1
value | testset stringclasses 9
values | passedTestCount int64 1 402 | timeConsumedMillis int64 15 8.06k | memoryConsumedBytes int64 0 514M | code stringlengths 11 61.4k | prompt stringlengths 297 7.35k | response stringlengths 25 61.4k | score float64 2.82 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,696,000,342 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | a, b, c = int(input()), int(input()), int(input())
a, c = min([a, c]), max([a, c])
if a == 1 or b == 1:
result = a + b
if c == 1:
result += 1
else: result *= c
else:
result = a * b * c
print(result)
| 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 = int(input()), int(input()), int(input())
a, c = min([a, c]), max([a, c])
if a == 1 or b == 1:
result = a + b
if c == 1:
result += 1
else: result *= c
else:
result = a * b * c
print(result)
``` | 3 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,695,958,154 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | # -*- coding: utf-8 -*-
"""
Created on Fri Sep 29 11:21:27 2023
@author: ZHAO XUDI
"""
w = input()
l = list(w)
l[0]=l[0].upper()
print("".join(l)) | 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
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 29 11:21:27 2023
@author: ZHAO XUDI
"""
w = input()
l = list(w)
l[0]=l[0].upper()
print("".join(l))
``` | 3 | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=β€<=*n*<=β€<=*m*<=β€<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=β€<=*f**i*<=β€<=1000) β the quantities of pieces in the puzzles sold in the shop. | Print a single integer β the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,677,946,141 | 2,147,483,647 | PyPy 3 | OK | TESTS | 18 | 154 | 0 | n, m = [int(i) for i in input().split(' ')]
A = [int(i) for i in input().split(' ')]
A.sort()
res = []
for item in range(m-n+1):
res.append(abs(A[item] - A[item+n-1]))
print(min(res))
| Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
n, m = [int(i) for i in input().split(' ')]
A = [int(i) for i in input().split(' ')]
A.sort()
res = []
for item in range(m-n+1):
res.append(abs(A[item] - A[item+n-1]))
print(min(res))
``` | 3 | |
950 | A | Left-handers, Right-handers and Ambidexters | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ... | The only line contains three integers *l*, *r* and *a* (0<=β€<=*l*,<=*r*,<=*a*<=β€<=100) β the number of left-handers, the number of right-handers and the number of ambidexters at the training. | Print a single even integerΒ β the maximum number of players in the team. It is possible that the team can only have zero number of players. | [
"1 4 2\n",
"5 5 5\n",
"0 2 0\n"
] | [
"6\n",
"14\n",
"0\n"
] | In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five l... | 500 | [
{
"input": "1 4 2",
"output": "6"
},
{
"input": "5 5 5",
"output": "14"
},
{
"input": "0 2 0",
"output": "0"
},
{
"input": "30 70 34",
"output": "128"
},
{
"input": "89 32 24",
"output": "112"
},
{
"input": "89 44 77",
"output": "210"
},
{
... | 1,620,206,432 | 2,147,483,647 | Python 3 | OK | TESTS | 79 | 62 | 0 | l,r,a=map(int,input().split())
x=min(l,r)
d=abs(l-r)
if d>a:
ans=(x+a)*2
elif d<=a:
a=a-d
ans=(x+d+a//2)*2
print(ans) | Title: Left-handers, Right-handers and Ambidexters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.... | ```python
l,r,a=map(int,input().split())
x=min(l,r)
d=abs(l-r)
if d>a:
ans=(x+a)*2
elif d<=a:
a=a-d
ans=(x+d+a//2)*2
print(ans)
``` | 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,696,168,349 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | a=input()
M=0
for i in a:
if ord(i)<91:
M=M+1
if 2*M>len(a):
print(a.upper())
else:
print(a.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
a=input()
M=0
for i in a:
if ord(i)<91:
M=M+1
if 2*M>len(a):
print(a.upper())
else:
print(a.lower())
``` | 3.977 |
609 | A | USB Flash Drives | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | The first line contains positive integer *n* (1<=β€<=*n*<=β€<=100) β the number of USB flash drives.
The second line contains positive integer *m* (1<=β€<=*m*<=β€<=105) β the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=β€<=*a**i*<=β€<=1000) β the sizes of USB flash drives in megabyt... | Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. | [
"3\n5\n2\n1\n3\n",
"3\n6\n2\n3\n2\n",
"2\n5\n5\n10\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first example Sean needs only two USB flash drives β the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive β the first or the second. | 0 | [
{
"input": "3\n5\n2\n1\n3",
"output": "2"
},
{
"input": "3\n6\n2\n3\n2",
"output": "3"
},
{
"input": "2\n5\n5\n10",
"output": "1"
},
{
"input": "5\n16\n8\n1\n3\n4\n9",
"output": "2"
},
{
"input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100",
"output": "2"
... | 1,567,814,306 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 0 | n = int(input())
list_size = []
for i in range(n+1):
if i == 0:
file_size = int(input())
else:
size = int(input())
list_size.append(size)
list_size.sort(reverse=True)
for i in range(n):
file_size = file_size - list_size[i]
if file_size <= 0:
print("{}".format(i+1))
... | Title: USB Flash Drives
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of... | ```python
n = int(input())
list_size = []
for i in range(n+1):
if i == 0:
file_size = int(input())
else:
size = int(input())
list_size.append(size)
list_size.sort(reverse=True)
for i in range(n):
file_size = file_size - list_size[i]
if file_size <= 0:
print("{}".format(i+... | 3 | |
641 | A | Little Artem and Grasshopper | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1<=Γ<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Gr... | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=100<=000)Β β length of the strip.
Next line contains a string of length *n* which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains *n* integers *d**i* (1<=β€<=*d*... | Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes). | [
"2\n><\n1 2\n",
"3\n>><\n2 1 1\n"
] | [
"FINITE\n",
"INFINITE"
] | In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite. | 500 | [
{
"input": "2\n><\n1 2",
"output": "FINITE"
},
{
"input": "3\n>><\n2 1 1",
"output": "INFINITE"
},
{
"input": "1\n>\n1000000000",
"output": "FINITE"
},
{
"input": "1\n<\n1000000000",
"output": "FINITE"
},
{
"input": "2\n>>\n1 1",
"output": "FINITE"
},
{
... | 1,462,115,713 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 124 | 12,288,000 | n, s = int(input()), input()
a = [int(i) for i in input().split()]
c = i = 0
while True:
if s[i] == '>':
i += a[i]
else:
i -= a[i]
if i < 0 or i >= n:
print("FINITE")
exit()
c += 1
if c > n:
print("INFINITE")
exit() | Title: Little Artem and Grasshopper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1<=Γ<=*n*. Each cell contains the direction for the next jump and t... | ```python
n, s = int(input()), input()
a = [int(i) for i in input().split()]
c = i = 0
while True:
if s[i] == '>':
i += a[i]
else:
i -= a[i]
if i < 0 or i >= n:
print("FINITE")
exit()
c += 1
if c > n:
print("INFINITE")
exit()
``` | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line β the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,592,416,339 | 2,147,483,647 | PyPy 3 | OK | TESTS | 102 | 156 | 0 | def func(x,y):
s = ''
for i in range(len(x)):
s += str(int(x[i])^int(y[i]))
print(s)
x = input()
y = input()
func(x,y) | 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
def func(x,y):
s = ''
for i in range(len(x)):
s += str(int(x[i])^int(y[i]))
print(s)
x = input()
y = input()
func(x,y)
``` | 3.961 |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=β€<=*A*<=β€<=1000). | Output should contain required average value in format Β«X/YΒ», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,678,432,528 | 2,147,483,647 | Python 3 | OK | TESTS | 99 | 92 | 0 | import math
def convert_base(n, base):
digits = []
while n > 0:
digits.append(n % base)
n //= base
return digits
def sum_digits(n):
return sum(n)
A = int(input())
total_sum = 0
count = 0
for base in range(2, A):
digits = convert_base(A, base)
if digits:
... | Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
import math
def convert_base(n, base):
digits = []
while n > 0:
digits.append(n % base)
n //= base
return digits
def sum_digits(n):
return sum(n)
A = int(input())
total_sum = 0
count = 0
for base in range(2, A):
digits = convert_base(A, base)
i... | 3.954 |
63 | A | Sinking Ship | PROGRAMMING | 900 | [
"implementation",
"sortings",
"strings"
] | A. Sinking Ship | 2 | 256 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a stri... | The first line contains an integer *n*, which is the number of people in the crew (1<=β€<=*n*<=β€<=100). Then follow *n* lines. The *i*-th of those lines contains two words β the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spa... | Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. | [
"6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n"
] | [
"Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n"
] | none | 500 | [
{
"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"
},
{
"input": "1\nA captain",
"output": "A"
},
{
"input": "1\nAbcdefjhij captain",
"output": "Abcdefjhij"
},
{
"input": "5\nA captain... | 1,619,277,401 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 216 | 0 | n=int(input())
rat=[]
wc=[]
man=[]
cap=[]
for i in range(n):
s=input().split()
if(s[1]=="rat"):
rat.append(s[0])
elif(s[1]=="woman" or s[1]=="child"):
wc.append(s[0])
elif(s[1]=="man"):
man.append(s[0])
else:
cap.append(s[0])
for i in rat:
print(i)... | Title: Sinking Ship
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to ... | ```python
n=int(input())
rat=[]
wc=[]
man=[]
cap=[]
for i in range(n):
s=input().split()
if(s[1]=="rat"):
rat.append(s[0])
elif(s[1]=="woman" or s[1]=="child"):
wc.append(s[0])
elif(s[1]=="man"):
man.append(s[0])
else:
cap.append(s[0])
for i in rat:
... | 3.946 |
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,681,686,646 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 154 | 0 | n = int(input())
phone_number = input()
if n % 2 == 0:
groups = [phone_number[i:i+2] for i in range(0, n, 2)]
else:
groups = [phone_number[0:3]] + [phone_number[i:i+2] for i in range(3, n, 2)]
print("-".join(groups))
| 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
n = int(input())
phone_number = input()
if n % 2 == 0:
groups = [phone_number[i:i+2] for i in range(0, n, 2)]
else:
groups = [phone_number[0:3]] + [phone_number[i:i+2] for i in range(3, n, 2)]
print("-".join(groups))
``` | 3.9615 |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=β€<=*l**i*<=β€<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=β€<=*a**i*<=β€<=105) β the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=β€<=*l**i*<=β€<=*n*). | Print *m* lines β on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,667,951,516 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 998 | 16,896,000 | n,m=map(int,input().split())
l=list(map(int,input().split()))
l.reverse()
s,l1={l[0]},[1]
for i in range(1,len(l)):
if l[i] not in s:
s.add(l[i])
l1.append(l1[i-1]+1)
else:
l1.append(l1[i-1])
for j in range(m):
x=int(input())
print(l1[n-x])
| Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
n,m=map(int,input().split())
l=list(map(int,input().split()))
l.reverse()
s,l1={l[0]},[1]
for i in range(1,len(l)):
if l[i] not in s:
s.add(l[i])
l1.append(l1[i-1]+1)
else:
l1.append(l1[i-1])
for j in range(m):
x=int(input())
print(l1[n-x])
``` | 3 | |
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city... | The first line contains three space-separated integers, *n*, *x*, *y* (1<=β€<=*n*,<=*x*,<=*y*<=β€<=104,<=*x*<=β€<=*n*) β the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to... | Print a single integer β the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 1... | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
... | 1,612,370,586 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 154 | 0 | a,b,c=map(int,input().split())
x=a*c
y=0
if x%100!=0: y=1
y+=(int(x/100))
if b>=y:print(0)
else:print(y-b)
| Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n... | ```python
a,b,c=map(int,input().split())
x=a*c
y=0
if x%100!=0: y=1
y+=(int(x/100))
if b>=y:print(0)
else:print(y-b)
``` | 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,656,607,025 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | a = list(map(int,input().split()))
count = 0
for i in range(1,a[2]+1):
if(i%a[0]==0 and i%a[1]==0):
count = count + 1
print(count) | 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
a = list(map(int,input().split()))
count = 0
for i in range(1,a[2]+1):
if(i%a[0]==0 and i%a[1]==0):
count = count + 1
print(count)
``` | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=Γ<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* β board sizes in squares (1<=β€<=*M*<=β€<=*N*<=β€<=16). | Output one number β the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,613,657,754 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | dim=input()
m,n = dim.split(" ")
m=int(m)
n=int(n)
result = (m*n)//2
print(result)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=Γ<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
dim=input()
m,n = dim.split(" ")
m=int(m)
n=int(n)
result = (m*n)//2
print(result)
``` | 3.969 |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=Γ<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer β the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,695,725,568 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | def search():
for i in range(5):
line=input().split()
for j in range(5):
if line[j]=='1':
return abs(i-2)+abs(j-2)
print(search()) | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=Γ<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
def search():
for i in range(5):
line=input().split()
for j in range(5):
if line[j]=='1':
return abs(i-2)+abs(j-2)
print(search())
``` | 3 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100) β the number of lines in the description. Then follow *n* lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,600,397,368 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 186 | 0 | import sys
def main():
n = int(sys.stdin.readline())
count = {}
for _ in range(n):
temp = sys.stdin.readline()
count[temp] = count.get(temp, 0) + 1
sys.stdout.write(f'{max(count, key=count.get)}')
if __name__ == '__main__':
main() | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
import sys
def main():
n = int(sys.stdin.readline())
count = {}
for _ in range(n):
temp = sys.stdin.readline()
count[temp] = count.get(temp, 0) + 1
sys.stdout.write(f'{max(count, key=count.get)}')
if __name__ == '__main__':
main()
``` | 3.9535 |
32 | A | Reconnaissance | PROGRAMMING | 800 | [
"brute force"
] | A. Reconnaissance | 2 | 256 | According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som... | The first line contains two integers *n* and *d* (1<=β€<=*n*<=β€<=1000,<=1<=β€<=*d*<=β€<=109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 1... | Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*. | [
"5 10\n10 20 50 60 65\n",
"5 1\n55 30 29 31 55\n"
] | [
"6\n",
"6\n"
] | none | 500 | [
{
"input": "5 10\n10 20 50 60 65",
"output": "6"
},
{
"input": "5 1\n55 30 29 31 55",
"output": "6"
},
{
"input": "6 10\n4 6 4 1 9 3",
"output": "30"
},
{
"input": "7 100\n19 1694 261 162 1 234 513",
"output": "8"
},
{
"input": "8 42\n37 53 74 187 568 22 5 65",
... | 1,626,275,548 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 686 | 6,963,200 | n,d = map(int, input().split())
count = 0
l = list(map(int, input().split()))
for x in l:
for y in l:
if abs(x - y) <= d:
count += 1
print(count - len(l))
| Title: Reconnaissance
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob h... | ```python
n,d = map(int, input().split())
count = 0
l = list(map(int, input().split()))
for x in l:
for y in l:
if abs(x - y) <= d:
count += 1
print(count - len(l))
``` | 3.81553 |
568 | A | Primes or Palindromes? | PROGRAMMING | 1,600 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this!
Let us remind you... | The input consists of two positive integers *p*, *q*, the numerator and denominator of the fraction that is the value of *A*Β (,Β ). | If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes). | [
"1 1\n",
"1 42\n",
"6 4\n"
] | [
"40\n",
"1\n",
"172\n"
] | none | 500 | [
{
"input": "1 1",
"output": "40"
},
{
"input": "1 42",
"output": "1"
},
{
"input": "6 4",
"output": "172"
},
{
"input": "3 1",
"output": "2530"
},
{
"input": "42 1",
"output": "1179858"
},
{
"input": "10000 239",
"output": "1168638"
},
{
"i... | 1,439,936,696 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 1,746 | 5,222,400 | '''
Created on 19 AΔu 2015
@author: enesoncu
'''
pr = [0]*1300000
def prime():
pr[1] = 1;
for i in range(2,1300000):
if pr[i]==1: continue
for j in range(2*i,1300000,i):
pr[j] = 1
def palindrom(s):
s = str(s)
return s==s[::-1]
(p,q) = map(int,input().split())
res = "... | Title: Primes or Palindromes?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a nu... | ```python
'''
Created on 19 AΔu 2015
@author: enesoncu
'''
pr = [0]*1300000
def prime():
pr[1] = 1;
for i in range(2,1300000):
if pr[i]==1: continue
for j in range(2*i,1300000,i):
pr[j] = 1
def palindrom(s):
s = str(s)
return s==s[::-1]
(p,q) = map(int,input().split()... | 3 | |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* β the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,698,003,479 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 156 | 0 | broj = input()
lista = broj.split("+")
listaintova=[]
for el in lista:
listaintova.append(int(el))
listaintova.sort()
g = len(listaintova)
g-=1
for i in range(len(listaintova)):
if i == g:
print(f"{listaintova[i]}")
break
print(f"{listaintova[i]}+",end="")
| Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
broj = input()
lista = broj.split("+")
listaintova=[]
for el in lista:
listaintova.append(int(el))
listaintova.sort()
g = len(listaintova)
g-=1
for i in range(len(listaintova)):
if i == g:
print(f"{listaintova[i]}")
break
print(f"{listaintova[i]}+",end="")
``` | 3 | |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* β a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=β€<=*n*<=β€<=105) β the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=β€<=*x**i*<=β€<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,676,997,444 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 483 | 8,089,600 | n = int(input())
x=[int(i) for i in input().split()]
y= len(x)
for i in range(y-1):
print(min(abs(x[i+1]-x[i]),abs(x[i]-x[i-1])),max(abs(x[y-1]-x[i]),abs(x[i]-x[0])))
print(x[y-1]-x[y-2],x[y-1]-x[0]) | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* β a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
n = int(input())
x=[int(i) for i in input().split()]
y= len(x)
for i in range(y-1):
print(min(abs(x[i+1]-x[i]),abs(x[i]-x[i-1])),max(abs(x[y-1]-x[i]),abs(x[i]-x[0])))
print(x[y-1]-x[y-2],x[y-1]-x[0])
``` | 3 | |
794 | A | Bank Robbery | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe f... | The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=β€<=*b*<=<<=*a*<=<<=*c*<=β€<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively.
The next line of input contains a single integer *n* (1<=β€<=*n*<=β€<=105), denoting the numbe... | Output a single integer: the maximum number of banknotes Oleg can take. | [
"5 3 7\n8\n4 7 5 5 3 6 2 8\n",
"6 5 7\n5\n1 5 7 92 3\n"
] | [
"4\n",
"0\n"
] | In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first se... | 500 | [
{
"input": "5 3 7\n8\n4 7 5 5 3 6 2 8",
"output": "4"
},
{
"input": "6 5 7\n5\n1 5 7 92 3",
"output": "0"
},
{
"input": "3 2 4\n1\n3",
"output": "1"
},
{
"input": "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6",
"output": "8"
},
{
"input": "7 3 10\n5\n3 3 3 3 3",
"output... | 1,658,649,378 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 93 | 8,294,400 | l=list(map(int,input().split()))
a=l[0]
b=l[1]
c=l[2]
n=int(input())
m=list(map(int,input().split()))
count=0
for i in m:
if i>=c or i<=b:
continue
else:
count+=1
print(count) | Title: Bank Robbery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and... | ```python
l=list(map(int,input().split()))
a=l[0]
b=l[1]
c=l[2]
n=int(input())
m=list(map(int,input().split()))
count=0
for i in m:
if i>=c or i<=b:
continue
else:
count+=1
print(count)
``` | 3 | |
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* β lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his... | The first line contains two integers *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=100) β the number of baloons and friends.
Next line contains string *s* β colors of baloons. | Answer to the task β Β«YESΒ» or Β«NOΒ» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is Β«NOΒ». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"... | 1,545,646,298 | 2,147,483,647 | Python 3 | OK | TESTS | 114 | 124 | 0 | n,m=map(int,input().split())
s=input()
ans="YES"
for i in [s.count(k) for k in set(s)]:
if(i>m):
ans="NO"
break
print(ans) | Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* β lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same colo... | ```python
n,m=map(int,input().split())
s=input()
ans="YES"
for i in [s.count(k) for k in set(s)]:
if(i>m):
ans="NO"
break
print(ans)
``` | 3 | |
43 | B | Letter | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | B. Letter | 2 | 256 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help ... | The first line contains a newspaper heading *s*1. The second line contains the letter text *s*2. *s*1 ΠΈ *s*2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces o... | If Vasya can write the given anonymous letter, print YES, otherwise print NO | [
"Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog\n",
"Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears\n",
"Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n",
"... | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | none | 1,000 | [
{
"input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog",
"output": "NO"
},
{
"input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears",
"output": "YES"
},
{
"input": "Instead of doggi... | 1,624,930,707 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 204,800 | import sys
from collections import Counter
input = lambda:sys.stdin.readline()
int_arr = lambda: list(map(int,input().split()))
str_arr = lambda: list(map(str,input().split()))
get_str = lambda: map(str,input().split())
get_int = lambda: map(int,input().split())
get_flo = lambda: map(float,input().split())
... | Title: Letter
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to... | ```python
import sys
from collections import Counter
input = lambda:sys.stdin.readline()
int_arr = lambda: list(map(int,input().split()))
str_arr = lambda: list(map(str,input().split()))
get_str = lambda: map(str,input().split())
get_int = lambda: map(int,input().split())
get_flo = lambda: map(float,input().sp... | 3.968619 |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winnerΒ β Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=100<=000)Β β the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D'Β β the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while DanikΒ β only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,694,200,111 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 62 | 1,740,800 | x=int (input())
sum_of_A=0
sum_of_D=0
s=input().upper()
for i in s:
if i=="A":
sum_of_A+=1
elif i=="D":
sum_of_D+=1
if sum_of_A>sum_of_D:
print("Anton")
elif sum_of_D>sum_of_A:
print("Danik")
else:
print("Friendship")
| Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winnerΒ β Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
x=int (input())
sum_of_A=0
sum_of_D=0
s=input().upper()
for i in s:
if i=="A":
sum_of_A+=1
elif i=="D":
sum_of_D+=1
if sum_of_A>sum_of_D:
print("Anton")
elif sum_of_D>sum_of_A:
print("Danik")
else:
print("Friendship")
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<... | The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. | Print the minimum number of steps modulo 109<=+<=7. | [
"ab\n",
"aab\n"
] | [
"1\n",
"3\n"
] | The first example: "ab" βββ "bba".
The second example: "aab" βββ "abba" βββ "bbaba" βββ "bbbbaa". | 0 | [
{
"input": "ab",
"output": "1"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaaaabaabababaaaaaba",
"output": "17307"
},
{
"input": "abaabaaabbabaabab",
"output": "1795"
},
{
"input": "abbaa",
"output": "2"
},
{
"input": "abbaaabaabaaaaabbbbaababaa... | 1,592,494,619 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 483 | 3,174,400 | s = input()
cnt = 0
ans = 0
mod = 1000000007
for i in reversed(range(len(s))):
if(s[i] == 'a'):
ans = (ans + cnt) % mod
cnt = (cnt * 2) % mod
else:
cnt += 1
print(ans) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is don... | ```python
s = input()
cnt = 0
ans = 0
mod = 1000000007
for i in reversed(range(len(s))):
if(s[i] == 'a'):
ans = (ans + cnt) % mod
cnt = (cnt * 2) % mod
else:
cnt += 1
print(ans)
``` | 3 | |
760 | A | Petr and a calendar | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
Petr wants to ... | The only line contain two integers *m* and *d* (1<=β€<=*m*<=β€<=12, 1<=β€<=*d*<=β€<=7)Β β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday). | Print single integer: the number of columns the table should have. | [
"1 7\n",
"1 1\n",
"11 6\n"
] | [
"6\n",
"5\n",
"5\n"
] | The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough. | 500 | [
{
"input": "1 7",
"output": "6"
},
{
"input": "1 1",
"output": "5"
},
{
"input": "11 6",
"output": "5"
},
{
"input": "2 7",
"output": "5"
},
{
"input": "2 1",
"output": "4"
},
{
"input": "8 6",
"output": "6"
},
{
"input": "1 1",
"output... | 1,485,109,184 | 284 | Python 3 | OK | TESTS | 104 | 78 | 4,710,400 | month, day = list(map(int, input().split()))
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
fs = 7 - day + 1
counter = 1
while fs + 7 <= months[month - 1]:
counter += 1
fs += 7
if (fs != months[month - 1]):
counter += 1
print(counter) | Title: Petr and a calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells... | ```python
month, day = list(map(int, input().split()))
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
fs = 7 - day + 1
counter = 1
while fs + 7 <= months[month - 1]:
counter += 1
fs += 7
if (fs != months[month - 1]):
counter += 1
print(counter)
``` | 3 | |
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis... | The first line contains the positive integer *n* (1<=β€<=*n*<=β€<=200<=000)Β β the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.... | In the first line print the only integerΒ β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 59... | 1,696,852,513 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 155 | 28,057,600 | n = int(input())
s = input()
ans = 1000000000
flag = False
arr = list(map(int,input().split()))
for i in range(n-1):
if s[i] == 'R' and s[i+1] == 'L':
ans = min(ans, ((arr[i+1] - arr[i])/2))
flag = True
if flag:
print(int(ans))
else:
print(-1)
| Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be... | ```python
n = int(input())
s = input()
ans = 1000000000
flag = False
arr = list(map(int,input().split()))
for i in range(n-1):
if s[i] == 'R' and s[i+1] == 'L':
ans = min(ans, ((arr[i+1] - arr[i])/2))
flag = True
if flag:
print(int(ans))
else:
print(-1)
``` | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line β the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,687,957,466 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 0 | x = list(input())
y = list(input())
res = []
for i in range(len(x)):
if x[i] == y[i]:
res.append(0)
else:
res.append(1)
for j in range(len(res)):
print(res[j],end='')
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
x = list(input())
y = list(input())
res = []
for i in range(len(x)):
if x[i] == y[i]:
res.append(0)
else:
res.append(1)
for j in range(len(res)):
print(res[j],end='')
``` | 3.9885 |
855 | B | Marvolo Gaunt's Ring | PROGRAMMING | 1,500 | [
"brute force",
"data structures",
"dp"
] | null | null | Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he... | First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=β€<=*p*,<=*q*,<=*r*<=β€<=109,<=1<=β€<=*n*<=β€<=105).
Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=β€<=*a**i*<=β€<=109). | Output a single integer the maximum value of *p*Β·*a**i*<=+<=*q*Β·*a**j*<=+<=*r*Β·*a**k* that can be obtained provided 1<=β€<=*i*<=β€<=*j*<=β€<=*k*<=β€<=*n*. | [
"5 1 2 3\n1 2 3 4 5\n",
"5 1 2 -3\n-1 -2 -3 -4 -5\n"
] | [
"30\n",
"12\n"
] | In the first sample case, we can take *i*β=β*j*β=β*k*β=β5, thus making the answer as 1Β·5β+β2Β·5β+β3Β·5β=β30.
In second sample case, selecting *i*β=β*j*β=β1 and *k*β=β5 gives the answer 12. | 1,000 | [
{
"input": "5 1 2 3\n1 2 3 4 5",
"output": "30"
},
{
"input": "5 1 2 -3\n-1 -2 -3 -4 -5",
"output": "12"
},
{
"input": "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777",
"output": "376059240645059046"
},
{
"input": "4 -96405765 -495906217 6... | 1,581,968,417 | 2,147,483,647 | Python 3 | OK | TESTS | 82 | 514 | 11,571,200 | n,p,q,r=map(int,input().split())
arr=[int(i) for i in input().split()]
# leftmax=[arr[0]]
# for i in range(1,len(arr)):
# leftmax.append(max(leftmax[-1],arr[i]))
# print(leftmax)
# rightmax=[arr[-1]]
# for i in range(len(arr)-2,-1,-1):
# rightmax.append(max(rightmax[-1],arr[i]))
# rightmax.reverse()
# print(rightma... | Title: Marvolo Gaunt's Ring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed i... | ```python
n,p,q,r=map(int,input().split())
arr=[int(i) for i in input().split()]
# leftmax=[arr[0]]
# for i in range(1,len(arr)):
# leftmax.append(max(leftmax[-1],arr[i]))
# print(leftmax)
# rightmax=[arr[-1]]
# for i in range(len(arr)-2,-1,-1):
# rightmax.append(max(rightmax[-1],arr[i]))
# rightmax.reverse()
# pri... | 3 | |
724 | A | Checking the Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong t... | The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". | Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes). | [
"monday\ntuesday\n",
"sunday\nsunday\n",
"saturday\ntuesday\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday. | 500 | [
{
"input": "monday\ntuesday",
"output": "NO"
},
{
"input": "sunday\nsunday",
"output": "YES"
},
{
"input": "saturday\ntuesday",
"output": "YES"
},
{
"input": "tuesday\nthursday",
"output": "YES"
},
{
"input": "friday\nwednesday",
"output": "NO"
},
{
"i... | 1,585,699,776 | 2,147,483,647 | Python 3 | OK | TESTS | 68 | 109 | 307,200 | import sys
import math
#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read integers
get_int = lambda: int(sys.stdin.readline())
#--------------------------------WhiteHat010----------... | Title: Checking the Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the fir... | ```python
import sys
import math
#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read integers
get_int = lambda: int(sys.stdin.readline())
#--------------------------------WhiteHat010... | 3 | |
1,004 | C | Sonya and Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya wi... | The first line contains a single integer $n$ ($1\leq n\leq 10^5$)Β β the number of numbers in a row.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$)Β β the numbers in a row. | Print one numberΒ β the number of possible pairs that Sonya can give to robots so that they will not meet. | [
"5\n1 5 4 1 3\n",
"7\n1 2 1 1 1 3 2\n"
] | [
"9\n",
"7\n"
] | In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$).
In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$). | 1,500 | [
{
"input": "5\n1 5 4 1 3",
"output": "9"
},
{
"input": "7\n1 2 1 1 1 3 2",
"output": "7"
},
{
"input": "10\n2 2 4 4 3 1 1 2 3 2",
"output": "14"
},
{
"input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4",
"output": "20"
},
{
"input": "1\n1",
"output": "0"
}
] | 1,671,679,550 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 124 | 20,992,000 | n = int(input())
l = list(map(int, input().split()))
d = dict()
s = set()
t = [0 for i in range(n)]
ans = 0
diff = 0
for i in range(n):
if l[i] in d:
d[l[i]] += [i]
else:
d[l[i]] = [i]
diff += 1
t[i] = diff
# print(t)
# print(d)
for x in d:
i = d[x][-1]
# ... | Title: Sonya and Robots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot ... | ```python
n = int(input())
l = list(map(int, input().split()))
d = dict()
s = set()
t = [0 for i in range(n)]
ans = 0
diff = 0
for i in range(n):
if l[i] in d:
d[l[i]] += [i]
else:
d[l[i]] = [i]
diff += 1
t[i] = diff
# print(t)
# print(d)
for x in d:
i = d[x][-... | 3 | |
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"... | 1,678,480,588 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 85 | 62 | 3,891,200 | def main():
s = input()
ab = []
ba = []
for i in range(len(s)-1):
if s[i:i+2]=="AB":
if any(abs(x-i)>1 for x in ba):
print("YES")
return
ab.append(i)
elif s[i:i+2]=="BA":
if any(abs(x-i)>1 for x in ab):
print("YES")
return
ba.append(i)
print("NO")
main()
| Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contain... | ```python
def main():
s = input()
ab = []
ba = []
for i in range(len(s)-1):
if s[i:i+2]=="AB":
if any(abs(x-i)>1 for x in ba):
print("YES")
return
ab.append(i)
elif s[i:i+2]=="BA":
if any(abs(x-i)>1 for x in ab):
print("YES")
return
ba.append(i)
print("NO")
main()
... | 3 | |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave ViΔkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=β€<=*A*,<=*B*<=β€<=109,<=*min*(*A*,<=*B*)<=β€<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4!β=β1Β·2Β·3Β·4β=β24. 3!β=β1Β·2Β·3β=β6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,662,568,197 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | n, m= map(int,input().split())
x = min(n,m)
for i in range(1,x):
x = x*i
print(x)
| Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
n, m= map(int,input().split())
x = min(n,m)
for i in range(1,x):
x = x*i
print(x)
``` | 3 | |
697 | B | Barnicle | PROGRAMMING | 1,400 | [
"brute force",
"implementation",
"math",
"strings"
] | null | null | Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.
Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance ... | The first and only line of input contains a single string of form *a*.*deb* where *a*, *d* and *b* are integers and *e* is usual character 'e' (0<=β€<=*a*<=β€<=9,<=0<=β€<=*d*<=<<=10100,<=0<=β€<=*b*<=β€<=100)Β β the scientific notation of the desired distance value.
*a* and *b* contain no leading zeros and *d* contains no... | Print the only real number *x* (the desired distance value) in the only line in its decimal notation.
Thus if *x* is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.
Otherwise print *x* in a form of *p*.*q* such that *p* is an integer that have no leading zeroe... | [
"8.549e2\n",
"8.549e3\n",
"0.33e0\n"
] | [
"854.9\n",
"8549\n",
"0.33\n"
] | none | 1,000 | [
{
"input": "8.549e2",
"output": "854.9"
},
{
"input": "8.549e3",
"output": "8549"
},
{
"input": "0.33e0",
"output": "0.33"
},
{
"input": "1.31e1",
"output": "13.1"
},
{
"input": "1.038e0",
"output": "1.038"
},
{
"input": "8.25983e5",
"output": "825... | 1,509,093,922 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 62 | 512,000 | from decimal import *
a = input()
b = Decimal(a)
if round(b) == b:
print("%d" % b)
else:
print(b)
| Title: Barnicle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.
Barney asked the bar tender Carl abou... | ```python
from decimal import *
a = input()
b = Decimal(a)
if round(b) == b:
print("%d" % b)
else:
print(b)
``` | 3 | |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should cons... | The first line contains two positive integers *n* and *k* (2<=β€<=*n*<=β€<=100, 2<=β€<=*k*<=β€<=*min*(*n*,<=26)) β the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords β java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords β python, because its length is equal to 6 and it consists of 6 distinct lowercase letter... | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,637,887,061 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 61 | 0 | if __name__ == "__main__":
n, k = map(int, input().split())
alphabet = list('abcdefghijklmnopqrstuvwxyz')
password = ''
i = 0
while k > 0:
password= password + alphabet[i]
k= k - 1
i= i + 1
i = 0
while len(password) < n:
if i == k:
i = 0
... | Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the foll... | ```python
if __name__ == "__main__":
n, k = map(int, input().split())
alphabet = list('abcdefghijklmnopqrstuvwxyz')
password = ''
i = 0
while k > 0:
password= password + alphabet[i]
k= k - 1
i= i + 1
i = 0
while len(password) < n:
if i == k:
i = ... | 3 | |
884 | B | Japanese Crosswords Strike Back | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
For example:
- If *x*<==<... | The first line contains two integer numbers *n* and *x* (1<=β€<=*n*<=β€<=100000, 1<=β€<=*x*<=β€<=109) β the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=β€<=*a**i*<=β€<=10000) β the encoding. | Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. | [
"2 4\n1 3\n",
"3 10\n3 3 2\n",
"2 10\n1 3\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2 4\n1 3",
"output": "NO"
},
{
"input": "3 10\n3 3 2",
"output": "YES"
},
{
"input": "2 10\n1 3",
"output": "NO"
},
{
"input": "1 1\n1",
"output": "YES"
},
{
"input": "1 10\n10",
"output": "YES"
},
{
"input": "1 10000\n10000",
"output":... | 1,659,061,738 | 2,147,483,647 | Python 3 | OK | TESTS | 66 | 62 | 6,553,600 | ###~~~LOTA~~~###
a,b=map(int,input().split())
l=list(map(int,input().split()))
if sum(l)+(a-1)==b:
print('YES')
else:
print('NO') | Title: Japanese Crosswords Strike Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely ... | ```python
###~~~LOTA~~~###
a,b=map(int,input().split())
l=list(map(int,input().split()))
if sum(l)+(a-1)==b:
print('YES')
else:
print('NO')
``` | 3 | |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=β€<=*n*<=β€<=100) β the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers β the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,624,341,140 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 280 | 3,993,600 | n = int(input())
n_sqr = n**2
r = range(1, n**2+1)
for i in range(n_sqr//2):
print(r[i], r[n_sqr-1-i])
| Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
n = int(input())
n_sqr = n**2
r = range(1, n**2+1)
for i in range(n_sqr//2):
print(r[i], r[n_sqr-1-i])
``` | 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,668,789,162 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 0 | s = input()
temp = 'hello'
ind = 0
for i in s:
if i == temp[ind]:
ind += 1
if ind == len(temp):
break
if ind == len(temp):
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s = input()
temp = 'hello'
ind = 0
for i in s:
if i == temp[ind]:
ind += 1
if ind == len(temp):
break
if ind == len(temp):
print("YES")
else:
print("NO")
``` | 3.969 |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation β the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub>β=β3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits β that results in number 11010<sub class="lower-index">2</sub>β=β26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,670,267,323 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 124 | 0 | s = input()
if '0' in s:
e = s.split('0',1)
if len(e) == 1:
print(e[0])
else:
print(e[0]+e[1])
else:
print(s[1:])
| Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
s = input()
if '0' in s:
e = s.split('0',1)
if len(e) == 1:
print(e[0])
else:
print(e[0]+e[1])
else:
print(s[1:])
``` | 3 | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=600)Β β participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integerΒ β the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,575,397,740 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 124 | 0 | n=int(input())
l=list(map(int,input().split()))
s=set(l)
if 0 in s:print(len(s)-1)
else:print(len(s)) | Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
n=int(input())
l=list(map(int,input().split()))
s=set(l)
if 0 in s:print(len(s)-1)
else:print(len(s))
``` | 3 | |
368 | A | Sereja and Coat Rack | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Sereja owns a restaurant for *n* people. The restaurant hall has a coat rack with *n* hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the *i*-th hook costs *a**i* rubles. Only one person can hang clothes on one hook.
Tonight Sereja expects *m* guests in the restaurant. Naturally, each gu... | The first line contains two integers *n* and *d* (1<=β€<=*n*,<=*d*<=β€<=100). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=β€<=*a**i*<=β€<=100). The third line contains integer *m* (1<=β€<=*m*<=β€<=100). | In a single line print a single integer β the answer to the problem. | [
"2 1\n2 1\n2\n",
"2 1\n2 1\n10\n"
] | [
"3\n",
"-5\n"
] | In the first test both hooks will be used, so Sereja gets 1β+β2β=β3 rubles.
In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3β-β8β=ββ-β5. | 500 | [
{
"input": "2 1\n2 1\n2",
"output": "3"
},
{
"input": "2 1\n2 1\n10",
"output": "-5"
},
{
"input": "1 1\n1\n2",
"output": "0"
},
{
"input": "3 96\n83 22 17\n19",
"output": "-1414"
},
{
"input": "8 4\n27 72 39 70 13 68 100 36\n95",
"output": "77"
},
{
"... | 1,684,753,752 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 62 | 0 | # https://codeforces.com/contest/368
import sys
input = lambda: sys.stdin.readline().rstrip() # faster!
n, d = map(int, input().split())
a = list(map(int, input().split()))
m = int(input())
if m >= n:
ans = sum(a) - (m - n) * d
else:
a.sort()
ans = sum(a[:m])
print(ans)
| Title: Sereja and Coat Rack
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja owns a restaurant for *n* people. The restaurant hall has a coat rack with *n* hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the *i*-th hook costs *a**i* rubles. Only one per... | ```python
# https://codeforces.com/contest/368
import sys
input = lambda: sys.stdin.readline().rstrip() # faster!
n, d = map(int, input().split())
a = list(map(int, input().split()))
m = int(input())
if m >= n:
ans = sum(a) - (m - n) * d
else:
a.sort()
ans = sum(a[:m])
print(ans)
``` | 3 | |
844 | A | Diversity | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"strings"
] | null | null | Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. | First line of input contains string *s*, consisting only of lowercase Latin letters (1<=β€<=|*s*|<=β€<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=β€<=*k*<=β€<=26). | Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. | [
"yandex\n6\n",
"yahoo\n5\n",
"google\n7\n"
] | [
"0\n",
"1\n",
"impossible\n"
] | In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*',β'*h*',β'*o*',β'*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for... | 500 | [
{
"input": "yandex\n6",
"output": "0"
},
{
"input": "yahoo\n5",
"output": "1"
},
{
"input": "google\n7",
"output": "impossible"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "z\n2",
"output": "impossible"
},
{
"input": "fwgfrwgkuwghfiruhewgirueguhe... | 1,508,265,190 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 62 | 5,529,600 | s = input()
k = int(input())
n = 0
a = list()
for i in s:
test = False
for j in a:
if i == j:
test = True
if not test:
a.append(i)
if len(s) < k:
print('impossible')
else:
print(max(k - len(a),0))
| Title: Diversity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it... | ```python
s = input()
k = int(input())
n = 0
a = list()
for i in s:
test = False
for j in a:
if i == j:
test = True
if not test:
a.append(i)
if len(s) < k:
print('impossible')
else:
print(max(k - len(a),0))
``` | 3 | |
808 | D | Array Division | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"implementation"
] | null | null | Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element ... | The first line contains single integer *n* (1<=β€<=*n*<=β€<=100000) β the size of the array.
The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=β€<=*a**i*<=β€<=109) β the elements of the array. | Print YES if Vasya can divide the array after moving one element. Otherwise print NO. | [
"3\n1 3 2\n",
"5\n1 2 3 4 5\n",
"5\n2 2 3 4 5\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | 0 | [
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "5\n2 2 3 4 5",
"output": "YES"
},
{
"input": "5\n72 32 17 46 82",
"output": "NO"
},
{
"input": "6\n26 10 70 11 69 57",
"output": "NO"
},
{
"input": "7\n4... | 1,565,187,757 | 2,147,483,647 | PyPy 3 | OK | TESTS | 115 | 327 | 15,462,400 | def possible(a):
if len(a)==1:
return False
if len(a)==2:
return a[0]==a[1]
total = sum(a)
vals = set([a[0]])
running = a[0]
for el in a[1:]:
running += el
vals.add(el)
if running == total-running:
return True
if (running - (total-running))%2==0 and (running - (total-running))//2 i... | Title: Array Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to... | ```python
def possible(a):
if len(a)==1:
return False
if len(a)==2:
return a[0]==a[1]
total = sum(a)
vals = set([a[0]])
running = a[0]
for el in a[1:]:
running += el
vals.add(el)
if running == total-running:
return True
if (running - (total-running))%2==0 and (running - (total-runn... | 3 | |
104 | A | Blackjack | PROGRAMMING | 800 | [
"implementation"
] | A. Blackjack | 2 | 256 | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to... | The only line contains *n* (1<=β€<=*n*<=β€<=25) β the required sum of points. | Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. | [
"12\n",
"20\n",
"10\n"
] | [
"4",
"15",
"0"
] | In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there ... | 500 | [
{
"input": "12",
"output": "4"
},
{
"input": "20",
"output": "15"
},
{
"input": "10",
"output": "0"
},
{
"input": "11",
"output": "4"
},
{
"input": "15",
"output": "4"
},
{
"input": "18",
"output": "4"
},
{
"input": "25",
"output": "0"
... | 1,626,073,614 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 154 | 6,758,400 | n = int(input())
reqNumber = n - 10
if reqNumber in [2,3,4,5,6,7,8,9] :
print(4)
elif reqNumber == 10:
print(15)
elif reqNumber == 11:
print(4)
elif reqNumber == 1 :
print(4)
else :
print(0) | Title: Blackjack
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Co... | ```python
n = int(input())
reqNumber = n - 10
if reqNumber in [2,3,4,5,6,7,8,9] :
print(4)
elif reqNumber == 10:
print(15)
elif reqNumber == 11:
print(4)
elif reqNumber == 1 :
print(4)
else :
print(0)
``` | 3.948911 |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of int... | A single line contains two integers *n*,<=*m* (1<=β€<=*n*,<=*m*<=β€<=1000) β the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3,β0). In the second sample the suitable pair is integers (3,β5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10"... | 1,667,490,038 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 124 | 0 | def solve(n, m):
valid_pairs_count = 0
valid_pairs = {}
a = 0
while (a ** 2) <= n:
b = n - (a ** 2)
if int(b) == b: # checks to see if b is an integer
valid_pairs[(a, b)] = True
a += 1
b = 0
while (b ** 2) <= m:
a = m - (b ** 2)
... | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi... | ```python
def solve(n, m):
valid_pairs_count = 0
valid_pairs = {}
a = 0
while (a ** 2) <= n:
b = n - (a ** 2)
if int(b) == b: # checks to see if b is an integer
valid_pairs[(a, b)] = True
a += 1
b = 0
while (b ** 2) <= m:
a = m - (b ... | 3 | |
999 | B | Reversing Encryption | PROGRAMMING | 900 | [
"implementation"
] | null | null | A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algor... | The first line of input consists of a single integer $n$ ($1 \le n \le 100$) β the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters. | Print a string $s$ such that the above algorithm results in $t$. | [
"10\nrocesfedoc\n",
"16\nplmaetwoxesisiht\n",
"1\nz\n"
] | [
"codeforces\n",
"thisisexampletwo\n",
"z\n"
] | The first example is described in the problem statement. | 0 | [
{
"input": "10\nrocesfedoc",
"output": "codeforces"
},
{
"input": "16\nplmaetwoxesisiht",
"output": "thisisexampletwo"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nir",
"output": "ri"
},
{
"input": "3\nilj",
"output": "jli"
},
{
"input": "4\nj... | 1,613,939,704 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 62 | 0 | n=int(input())
s=input()
for i in range(2, n+1):
if n%i==0:
z=str()
for j in range(i-1, -1, -1):
z=z+s[j]
for j in range(i, n):
z=z+s[j]
s=z
print(s) | Title: Reversing Encryption
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$... | ```python
n=int(input())
s=input()
for i in range(2, n+1):
if n%i==0:
z=str()
for j in range(i-1, -1, -1):
z=z+s[j]
for j in range(i, n):
z=z+s[j]
s=z
print(s)
``` | 3 | |
515 | B | Drazil and His Happy Friends | PROGRAMMING | 1,300 | [
"brute force",
"dsu",
"meet-in-the-middle",
"number theory"
] | null | null | Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are *n* boys and *m* girls among his friends. Let's number them from 0 to *n*<=-<=1 and 0 to *m*<=-<=1 separately. In *i*-th day, Drazil invites -th ... | The first line contains two integer *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100).
The second line contains integer *b* (0<=β€<=*b*<=β€<=*n*), denoting the number of happy boys among friends of Drazil, and then follow *b* distinct integers *x*1,<=*x*2,<=...,<=*x**b* (0<=β€<=*x**i*<=<<=*n*), denoting the list of indices of hap... | If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No". | [
"2 3\n0\n1 0\n",
"2 4\n1 0\n1 2\n",
"2 3\n1 0\n1 1\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | By <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/169ade208e6eb4f9263c57aaff716529d59c3288.png" style="max-width: 100.0%;max-height: 100.0%;"/> we define the remainder of integer division of *i* by *k*.
In first sample case:
- On the 0-th day, Drazil invites 0-th boy and 0-th girl. Bec... | 1,000 | [
{
"input": "2 3\n0\n1 0",
"output": "Yes"
},
{
"input": "2 4\n1 0\n1 2",
"output": "No"
},
{
"input": "2 3\n1 0\n1 1",
"output": "Yes"
},
{
"input": "16 88\n6 5 14 2 0 12 7\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82",
"outpu... | 1,599,329,127 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 140 | 1,331,200 | n, m = [int(p) for p in input().split()]
arrb = [int(p) for p in input().split()]
arrg = [int(p) for p in input().split()]
arrb.pop(0)
arrg.pop(0)
cb = [False]*n
cg = [False]*m
for i in arrb:
cb[i] = True
for i in arrg:
cg[i] = True
i = 0
while i < 10**5:
b = cb[i%n]
g = cg[i%m]
if b and g:
i += 1
continue
e... | Title: Drazil and His Happy Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are *n* boys and *m* girls among hi... | ```python
n, m = [int(p) for p in input().split()]
arrb = [int(p) for p in input().split()]
arrg = [int(p) for p in input().split()]
arrb.pop(0)
arrg.pop(0)
cb = [False]*n
cg = [False]*m
for i in arrb:
cb[i] = True
for i in arrg:
cg[i] = True
i = 0
while i < 10**5:
b = cb[i%n]
g = cg[i%m]
if b and g:
i += 1
c... | 3 | |
817 | C | Really Big Numbers | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math"
] | null | null | Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different... | The first (and the only) line contains two integers *n* and *s* (1<=β€<=*n*,<=*s*<=β€<=1018). | Print one integer β the quantity of really big numbers that are not greater than *n*. | [
"12 1\n",
"25 20\n",
"10 9\n"
] | [
"3\n",
"0\n",
"1\n"
] | In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30β-β3ββ₯β20).
In the third example 10 is the only really big number (10β-β1ββ₯β9). | 0 | [
{
"input": "12 1",
"output": "3"
},
{
"input": "25 20",
"output": "0"
},
{
"input": "10 9",
"output": "1"
},
{
"input": "300 1000",
"output": "0"
},
{
"input": "500 1000",
"output": "0"
},
{
"input": "1000 2000",
"output": "0"
},
{
"input":... | 1,497,543,367 | 4,267 | Python 3 | OK | TESTS | 68 | 62 | 0 | def f(x):
ans = x
while x > 0:
ans -= x % 10
x //= 10
return ans
n, s = map(int, input().split())
if f(n) < s:
print(0)
exit(0)
l, r = 1, n
while l < r:
m = (l + r) // 2
if f(m) >= s:
r = (m // 10) * 10
else:
l = m + 1
print(n - l + 1)
| Title: Really Big Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its... | ```python
def f(x):
ans = x
while x > 0:
ans -= x % 10
x //= 10
return ans
n, s = map(int, input().split())
if f(n) < s:
print(0)
exit(0)
l, r = 1, n
while l < r:
m = (l + r) // 2
if f(m) >= s:
r = (m // 10) * 10
else:
l = m + 1
print(n - l + 1)
``` | 3 | |
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | The first line contains a single integer *n* (2<=β€<=*n*<=β€<=1000)Β β the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=4126)Β β the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order... | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som... | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
... | 1,598,376,402 | 2,147,483,647 | Python 3 | OK | TESTS | 150 | 124 | 307,200 | n = int(input())
a=[[int(i) for i in input().split()] for i in range(n)]
ans = 'maybe'
for i in range(n):
if a[i][0] != a[i][1]:
ans = 'rated'
break
else:
for i in range(n-1):
if a[i][0] < a[i+1][0]:
ans = 'unrated'
break
print(ans)
| Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number ... | ```python
n = int(input())
a=[[int(i) for i in input().split()] for i in range(n)]
ans = 'maybe'
for i in range(n):
if a[i][0] != a[i][1]:
ans = 'rated'
break
else:
for i in range(n-1):
if a[i][0] < a[i+1][0]:
ans = 'unrated'
break
print(ans)
``` | 3 | |
570 | A | Elections | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in ... | The first line of the input contains two integers *n*, *m* (1<=β€<=*n*,<=*m*<=β€<=100) β the number of candidates and of cities, respectively.
Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=β€<=*j*<=β€<=*n*, 1<=β€<=*i*<=β€<=*m*, 0<=β€<=*a**ij*<=β€<=109) denotes ... | Print a single number β the index of the candidate who won the elections. The candidates are indexed starting from one. | [
"3 3\n1 2 3\n2 3 1\n1 2 1\n",
"3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n"
] | [
"2",
"1"
] | Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm... | 500 | [
{
"input": "3 3\n1 2 3\n2 3 1\n1 2 1",
"output": "2"
},
{
"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7",
"output": "1"
},
{
"input": "1 3\n5\n3\n2",
"output": "1"
},
{
"input": "3 1\n1 2 3",
"output": "3"
},
{
"input": "3 1\n100 100 100",
"output": "1"
},
{... | 1,472,980,234 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 62 | 102,400 | lineInput = list(map(int,str(input()).split()))
m = lineInput[0]
n = lineInput[1]
city = [0] * 110
for i in range(0,n):
cnt = list(map(int,str(input()).split()))
winner = 0
for j in range(0,m):
if(cnt[j] > cnt[winner]):
winner = j
city[winner] += 1
answer = int(0)
for i in range(0,m):
if(ci... | Title: Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusu... | ```python
lineInput = list(map(int,str(input()).split()))
m = lineInput[0]
n = lineInput[1]
city = [0] * 110
for i in range(0,n):
cnt = list(map(int,str(input()).split()))
winner = 0
for j in range(0,m):
if(cnt[j] > cnt[winner]):
winner = j
city[winner] += 1
answer = int(0)
for i in range(0,m... | 3 | |
735 | B | Urbanization | PROGRAMMING | 1,100 | [
"greedy",
"number theory",
"sortings"
] | null | null | Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* of them is equal to *a**i*. Authorities plan to build two cities, first for *n*1 people and second ... | The first line of the input contains three integers *n*, *n*1 and *n*2 (1<=β€<=*n*,<=*n*1,<=*n*2<=β€<=100<=000, *n*1<=+<=*n*2<=β€<=*n*)Β β the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line conta... | Print one real valueΒ β the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your ... | [
"2 1 1\n1 5\n",
"4 2 1\n1 4 2 3\n"
] | [
"6.00000000\n",
"6.50000000\n"
] | In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (*a*<sub class="lower-index">3</sub>β+β*a*<sub class=... | 1,000 | [
{
"input": "2 1 1\n1 5",
"output": "6.00000000"
},
{
"input": "4 2 1\n1 4 2 3",
"output": "6.50000000"
},
{
"input": "3 1 2\n1 2 3",
"output": "4.50000000"
},
{
"input": "10 4 6\n3 5 7 9 12 25 67 69 83 96",
"output": "88.91666667"
},
{
"input": "19 7 12\n1 2 4 8 1... | 1,614,342,549 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 171 | 10,649,600 | n,n1,n2=map(int,input().split())
n1,n2=min(n1,n2),max(n1,n2)
l=sorted(list(map(int,input().split())))
l.reverse()
print(sum(l[:n1])/n1+sum(l[n1:n1+n2])/n2)
| Title: Urbanization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* o... | ```python
n,n1,n2=map(int,input().split())
n1,n2=min(n1,n2),max(n1,n2)
l=sorted(list(map(int,input().split())))
l.reverse()
print(sum(l[:n1])/n1+sum(l[n1:n1+n2])/n2)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color *i* before drawing the last ball of... | The first line of input will have one integer *k* (1<=β€<=*k*<=β€<=1000) the number of colors.
Then, *k* lines will follow. The *i*-th line will contain *c**i*, the number of balls of the *i*-th color (1<=β€<=*c**i*<=β€<=1000).
The total number of balls doesn't exceed 1000. | A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1<=000<=000<=007. | [
"3\n2\n2\n1\n",
"4\n1\n2\n3\n4\n"
] | [
"3\n",
"1680\n"
] | In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: | 0 | [
{
"input": "3\n2\n2\n1",
"output": "3"
},
{
"input": "4\n1\n2\n3\n4",
"output": "1680"
},
{
"input": "10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "12520708"
},
{
"input": "5\n10\n10\n10\n10\n10",
"output": "425711769"
},
{
"input": "11\n291\n3... | 1,533,046,157 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 171 | 0 | import math
MOD = 1000000007
MAXN = 1005
def fac(n, k):
res = 1
for i in range(n + 1 - k, n + 1):
res *= i
return res
k = int(input())
sum = 0
ans = 1
for i in range(0, k):
num = int(input())
sum += num
ans = ans * fac(sum - 1, num - 1) // fac(num - 1, num - 1)
print (... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is... | ```python
import math
MOD = 1000000007
MAXN = 1005
def fac(n, k):
res = 1
for i in range(n + 1 - k, n + 1):
res *= i
return res
k = int(input())
sum = 0
ans = 1
for i in range(0, k):
num = int(input())
sum += num
ans = ans * fac(sum - 1, num - 1) // fac(num - 1, num - 1... | 3 | |
145 | A | Lucky Conversion | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits... | The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. | Print on the single line the single number β the minimum number of operations needed to convert string *a* into string *b*. | [
"47\n74\n",
"774\n744\n",
"777\n444\n"
] | [
"1\n",
"1\n",
"3\n"
] | In the first sample it is enough simply to swap the first and the second digit.
In the second sample we should replace the second digit with its opposite.
In the third number we should replace all three digits with their opposites. | 500 | [
{
"input": "47\n74",
"output": "1"
},
{
"input": "774\n744",
"output": "1"
},
{
"input": "777\n444",
"output": "3"
},
{
"input": "74747474\n77777777",
"output": "4"
},
{
"input": "444444444444\n777777777777",
"output": "12"
},
{
"input": "4744744447774... | 1,617,813,459 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 248 | 1,945,600 | a = list(input())
b = list(input())
a_copy = a[:]
a_copy.sort()
b_copy = b[:]
b_copy.sort()
replace_counter = 0
swap_counter = 0
for i in range(len(a_copy)):
if(a_copy[i] != b_copy[i]):
replace_counter += 1
for i in range(len(a)):
if (a[i] != b[i]):
swap_counter += 1
swap... | Title: Lucky Conversion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are no... | ```python
a = list(input())
b = list(input())
a_copy = a[:]
a_copy.sort()
b_copy = b[:]
b_copy.sort()
replace_counter = 0
swap_counter = 0
for i in range(len(a_copy)):
if(a_copy[i] != b_copy[i]):
replace_counter += 1
for i in range(len(a)):
if (a[i] != b[i]):
swap_counter +=... | 3 | |
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | First line of input contains an integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i*β=β5 there exists *j*β=β3 such that *s*<sub class="lower-index">*i*</sub>β=β*s*<sub class="lower-index">*j*</sub> and *j*β<β*i*, which means that answer for *i*β=β5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb... | 1,646,909,372 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 46 | 0 | memory=dict()
for _ in [0]*int(input()):
s=input()
try:memory[s]+=1;print('YES')
except:memory[s]=0;print('NO') | Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ... | ```python
memory=dict()
for _ in [0]*int(input()):
s=input()
try:memory[s]+=1;print('YES')
except:memory[s]=0;print('NO')
``` | 3 | |
104 | A | Blackjack | PROGRAMMING | 800 | [
"implementation"
] | A. Blackjack | 2 | 256 | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to... | The only line contains *n* (1<=β€<=*n*<=β€<=25) β the required sum of points. | Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. | [
"12\n",
"20\n",
"10\n"
] | [
"4",
"15",
"0"
] | In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there ... | 500 | [
{
"input": "12",
"output": "4"
},
{
"input": "20",
"output": "15"
},
{
"input": "10",
"output": "0"
},
{
"input": "11",
"output": "4"
},
{
"input": "15",
"output": "4"
},
{
"input": "18",
"output": "4"
},
{
"input": "25",
"output": "0"
... | 1,545,760,108 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 218 | 0 | c = int(input())
c = c-10
if (c >= 1 and c < 10) or (c is 11):
print(4)
elif c is 10:
print(15)
else:
print(0)
| Title: Blackjack
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Co... | ```python
c = int(input())
c = c-10
if (c >= 1 and c < 10) or (c is 11):
print(4)
elif c is 10:
print(15)
else:
print(0)
``` | 3.9455 |
930 | D | Game with Tokens | PROGRAMMING | 2,500 | [
"data structures",
"games",
"implementation"
] | null | null | Consider the following game for two players. There is one white token and some number of black tokens. Each token is placed on a plane in a point with integer coordinates *x* and *y*.
The players take turn making moves, white starts. On each turn, a player moves all tokens of their color by 1 to up, down, left or righ... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=105) β the number of black points.
The (*i*<=+<=1)-th line contains two integers *x**i*, *y**i* (<=-<=105<=β€<=*x**i*,<=*y**i*,<=<=β€<=105) β the coordinates of the point where the *i*-th black token is initially located.
It is guaranteed that initial position... | Print the number of points where the white token can be located initially, such that if both players play optimally, the black player wins. | [
"4\n-2 -1\n0 1\n0 -3\n2 -1\n",
"4\n-2 0\n-1 1\n0 -2\n1 -1\n",
"16\n2 1\n1 2\n-1 1\n0 1\n0 0\n1 1\n2 -1\n2 0\n1 0\n-1 -1\n1 -1\n2 2\n0 -1\n-1 0\n0 2\n-1 2\n"
] | [
"4\n",
"2\n",
"4\n"
] | In the first and second examples initial positions of black tokens are shown with black points, possible positions of the white token (such that the black player wins) are shown with white points.
The first example: <img class="tex-graphics" src="https://espresso.codeforces.com/5054b8d2df2fac92c92f96fae82d21c365d12983... | 2,000 | [
{
"input": "4\n-2 -1\n0 1\n0 -3\n2 -1",
"output": "4"
},
{
"input": "4\n-2 0\n-1 1\n0 -2\n1 -1",
"output": "2"
},
{
"input": "16\n2 1\n1 2\n-1 1\n0 1\n0 0\n1 1\n2 -1\n2 0\n1 0\n-1 -1\n1 -1\n2 2\n0 -1\n-1 0\n0 2\n-1 2",
"output": "4"
},
{
"input": "1\n1 2",
"output": "0"
... | 1,632,748,661 | 2,147,483,647 | PyPy 3 | OK | TESTS | 62 | 795 | 121,548,800 | #FB HACKERCUP
import os,sys,math
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from _builtin_ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
from bisect import bisect_left as lower_bound, bisect_right as upper_bound
def so(): return int(input())
d... | Title: Game with Tokens
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the following game for two players. There is one white token and some number of black tokens. Each token is placed on a plane in a point with integer coordinates *x* and *y*.
The players take turn making move... | ```python
#FB HACKERCUP
import os,sys,math
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from _builtin_ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
from bisect import bisect_left as lower_bound, bisect_right as upper_bound
def so(): return int(i... | 3 | |
991 | A | If at first you don't succeed... | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them... | The first line contains four integersΒ β $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$). | If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ β BeaverKing, $C$ β both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integerΒ β amount of students (including Vasya) who did not pass the exam. ... | [
"10 10 5 20\n",
"2 2 0 4\n",
"2 2 2 1\n"
] | [
"5",
"-1",
"-1"
] | The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students... | 500 | [
{
"input": "10 10 5 20",
"output": "5"
},
{
"input": "2 2 0 4",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "-1"
},
{
"input": "98 98 97 100",
"output": "1"
},
{
"input": "1 5 2 10",
"output": "-1"
},
{
"input": "5 1 2 10",
"output": "-1"
}... | 1,606,661,164 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 124 | 0 | a,b,c,d=list(map(int,input().split()))
print(-1 if d-a-b+c<=0 or a<c or b<c else d-a-b+c) | Title: If at first you don't succeed...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group w... | ```python
a,b,c,d=list(map(int,input().split()))
print(-1 if d-a-b+c<=0 or a<c or b<c else d-a-b+c)
``` | 3 | |
343 | B | Alternating Current | PROGRAMMING | 1,600 | [
"data structures",
"greedy",
"implementation"
] | null | null | Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended u... | The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=β€<=*n*<=β€<=100000). The *i*-th (1<=β€<=*i*<=β€<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | [
"-++-\n",
"+-\n",
"++\n",
"-\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"No\n"
] | The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.
In the second testcase the "plus" wire makes one full rev... | 1,000 | [
{
"input": "-++-",
"output": "Yes"
},
{
"input": "+-",
"output": "No"
},
{
"input": "++",
"output": "Yes"
},
{
"input": "-",
"output": "No"
},
{
"input": "+-+-",
"output": "No"
},
{
"input": "-+-",
"output": "No"
},
{
"input": "-++-+--+",
... | 1,602,432,838 | 2,147,483,647 | PyPy 3 | OK | TESTS | 62 | 280 | 5,017,600 |
s = input()
ss = []
for i in s:
if len(ss) > 0 and ss[-1] == i:
ss.pop()
else:
ss.append(i)
if len(ss) == 0:
print("Yes")
else:
print("No")
| Title: Alternating Current
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it... | ```python
s = input()
ss = []
for i in s:
if len(ss) > 0 and ss[-1] == i:
ss.pop()
else:
ss.append(i)
if len(ss) == 0:
print("Yes")
else:
print("No")
``` | 3 | |
447 | B | DZY Loves Strings | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to in... | The first line contains a single string *s*Β (1<=β€<=|*s*|<=β€<=103).
The second line contains a single integer *k*Β (0<=β€<=*k*<=β€<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. | Print a single integer β the largest possible value of the resulting string DZY could get. | [
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] | [
"41\n"
] | In the test sample DZY can obtain "abcbbc", *value*β=β1Β·1β+β2Β·2β+β3Β·2β+β4Β·2β+β5Β·2β+β6Β·2β=β41. | 1,000 | [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetyw... | 1,405,259,264 | 2,864 | Python 3 | OK | TESTS | 24 | 77 | 0 | st=input()
k=int(input())
w=list(map(int,input().split()))
w2={chr(ord('a')+i):w[i] for i in range(26)}
m=max(w)
print(sum([w2[st[i]]*(i+1) for i in range(len(st))])+sum([i*m for i in range(len(st)+1,len(st)+1+k)])) | Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the str... | ```python
st=input()
k=int(input())
w=list(map(int,input().split()))
w2={chr(ord('a')+i):w[i] for i in range(26)}
m=max(w)
print(sum([w2[st[i]]*(i+1) for i in range(len(st))])+sum([i*m for i in range(len(st)+1,len(st)+1+k)]))
``` | 3 | |
478 | C | Table Decorations | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color?
Your task is to write a pro... | The single line contains three integers *r*, *g* and *b* (0<=β€<=*r*,<=*g*,<=*b*<=β€<=2Β·109) β the number of red, green and blue baloons respectively. The numbers are separated by exactly one space. | Print a single integer *t* β the maximum number of tables that can be decorated in the required manner. | [
"5 4 3\n",
"1 1 1\n",
"2 3 3\n"
] | [
"4\n",
"1\n",
"2\n"
] | In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively. | 1,500 | [
{
"input": "5 4 3",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "0 1 0",
"output": "0"
},
{
"input": "0 3 3",
"output": "2"
},
{
"input": "4 0 4",
"output": "2"
},
{
"input": "100000... | 1,668,599,366 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 77 | 0 | r,g,b = map(int,input().split())
print(min(r+g,r+b,b+g,(r+b+g)//3))
| Title: Table Decorations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *... | ```python
r,g,b = map(int,input().split())
print(min(r+g,r+b,b+g,(r+b+g)//3))
``` | 3 | |
879 | A | Borya's Diagnosis | PROGRAMMING | 900 | [
"implementation"
] | null | null | It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get t... | First line contains an integer *n* β number of doctors (1<=β€<=*n*<=β€<=1000).
Next *n* lines contain two numbers *s**i* and *d**i* (1<=β€<=*s**i*,<=*d**i*<=β€<=1000). | Output a single integer β the minimum day at which Borya can visit the last doctor. | [
"3\n2 2\n1 2\n2 2\n",
"2\n10 1\n6 5\n"
] | [
"4\n",
"11\n"
] | In the first sample case, Borya can visit all doctors on days 2, 3 and 4.
In the second sample case, Borya can visit all doctors on days 10 and 11. | 500 | [
{
"input": "3\n2 2\n1 2\n2 2",
"output": "4"
},
{
"input": "2\n10 1\n6 5",
"output": "11"
},
{
"input": "3\n6 10\n3 3\n8 2",
"output": "10"
},
{
"input": "4\n4 8\n10 10\n4 2\n8 2",
"output": "14"
},
{
"input": "5\n7 1\n5 1\n6 1\n1 6\n6 8",
"output": "14"
},
... | 1,548,411,327 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 124 | 0 | n = int(input())
cur = 0
for i in range(n):
s, d = map(int, input().split())
q = max(0, cur - s + d) // d
cur = q * d + s
print(cur)
| Title: Borya's Diagnosis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed o... | ```python
n = int(input())
cur = 0
for i in range(n):
s, d = map(int, input().split())
q = max(0, cur - s + d) // d
cur = q * d + s
print(cur)
``` | 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,561,213,214 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 109 | 0 | n = int(input())
flag = 'NO'
for i in range(n):
text, f, s = input().split()
if int(s) > int(f) >= 2400:
flag = 'YES'
print(flag) | 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())
flag = 'NO'
for i in range(n):
text, f, s = input().split()
if int(s) > int(f) >= 2400:
flag = 'YES'
print(flag)
``` | 3 | |
629 | B | Far Relativeβs Problem | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible.
Far cars are as weird as... | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=5000)Β β then number of Famil Door's friends.
Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i... | Print the maximum number of people that may come to Famil Door's party. | [
"4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n",
"6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n"
] | [
"2\n",
"4\n"
] | In the first sample, friends 3 and 4 can come on any day in range [117,β128].
In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. | 1,000 | [
{
"input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128",
"output": "2"
},
{
"input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200",
"output": "4"
},
{
"input": "1\nF 68 307",
"output": "0"
},
{
"input": "40\nM 55 363\nF 117 252\nM 157 282\nF 322 345\... | 1,489,481,431 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 546 | 5,017,600 | n = int(input())
gender = []
fromdate = []
todate = []
for k in range(n):
a, b, c = input().split()
gender.append(a)
fromdate.append(int(b))
todate.append(int(c))
minimum = min(fromdate)
maximum = max(todate)
#print("min = {} max = {}".format(minimum,maximum))
ans = 0
for i in range(minimum... | Title: Far Relativeβs Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, F... | ```python
n = int(input())
gender = []
fromdate = []
todate = []
for k in range(n):
a, b, c = input().split()
gender.append(a)
fromdate.append(int(b))
todate.append(int(c))
minimum = min(fromdate)
maximum = max(todate)
#print("min = {} max = {}".format(minimum,maximum))
ans = 0
for i in ran... | 3 | |
769 | B | News About Credit | PROGRAMMING | 1,200 | [
"*special",
"greedy",
"two pointers"
] | null | null | Polycarp studies at the university in the group which consists of *n* students (including himself). All they are registrated in the social net "TheContacnt!".
Not all students are equally sociable. About each student you know the value *a**i* β the maximum number of messages which the *i*-th student is agree to send p... | The first line contains the positive integer *n* (2<=β€<=*n*<=β€<=100) β the number of students.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=100), where *a**i* equals to the maximum number of messages which can the *i*-th student agree to send. Consider that Polycarp always has th... | Print -1 to the first line if it is impossible to inform all students about credit.
Otherwise, in the first line print the integer *k* β the number of messages which will be sent. In each of the next *k* lines print two distinct integers *f* and *t*, meaning that the student number *f* sent the message with news to t... | [
"4\n1 2 1 0\n",
"6\n2 0 1 3 2 0\n",
"3\n0 2 2\n"
] | [
"3\n1 2\n2 4\n2 3\n",
"6\n1 3\n3 4\n1 2\n4 5\n5 6\n4 6\n",
"-1\n"
] | In the first test Polycarp (the student number 1) can send the message to the student number 2, who after that can send the message to students number 3 and 4. Thus, all students knew about the credit. | 1,000 | [
{
"input": "4\n1 2 1 0",
"output": "3\n1 2\n2 3\n2 4"
},
{
"input": "6\n2 0 1 3 2 0",
"output": "5\n1 4\n1 5\n4 3\n4 2\n4 6"
},
{
"input": "3\n0 2 2",
"output": "-1"
},
{
"input": "2\n0 0",
"output": "-1"
},
{
"input": "2\n1 0",
"output": "1\n1 2"
},
{
... | 1,546,334,404 | 2,147,483,647 | PyPy 3 | OK | TESTS | 60 | 140 | 0 | n = int(input())
call = list(map(int, input().split()))
cp = []
ans = []
for i in range(1, n):
x = call[i]
cp.append([x, i + 1])
cp.sort(reverse=True)
l = [[call[0], 1]]
j = 0
while len(cp) > 0 and len(l) > 0 and j < len(cp):
s = l[0]
x = s[0]
p = s[1]
for i in range(j, min(j + x, ... | Title: News About Credit
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp studies at the university in the group which consists of *n* students (including himself). All they are registrated in the social net "TheContacnt!".
Not all students are equally sociable. About each student... | ```python
n = int(input())
call = list(map(int, input().split()))
cp = []
ans = []
for i in range(1, n):
x = call[i]
cp.append([x, i + 1])
cp.sort(reverse=True)
l = [[call[0], 1]]
j = 0
while len(cp) > 0 and len(l) > 0 and j < len(cp):
s = l[0]
x = s[0]
p = s[1]
for i in range(j, m... | 3 | |
1,005 | A | Tanya and Stairways | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $3$ steps, and the second contains $4$ ... | The first line contains $n$ ($1 \le n \le 1000$) β the total number of numbers pronounced by Tanya.
The second line contains integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1000$) β all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway wit... | In the first line, output $t$ β the number of stairways that Tanya climbed. In the second line, output $t$ numbers β the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways. | [
"7\n1 2 3 1 2 3 4\n",
"4\n1 1 1 1\n",
"5\n1 2 3 4 5\n",
"5\n1 2 1 2 1\n"
] | [
"2\n3 4 ",
"4\n1 1 1 1 ",
"1\n5 ",
"3\n2 2 1 "
] | none | 0 | [
{
"input": "7\n1 2 3 1 2 3 4",
"output": "2\n3 4 "
},
{
"input": "4\n1 1 1 1",
"output": "4\n1 1 1 1 "
},
{
"input": "5\n1 2 3 4 5",
"output": "1\n5 "
},
{
"input": "5\n1 2 1 2 1",
"output": "3\n2 2 1 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"inp... | 1,637,832,748 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 62 | 0 | n = int(input())
li = list(map(int, input().split()))
count = 1
newli = []
for i in range(1,n):
if li[i]<li[i-1]:
count +=1
newli.append(li[i-1])
if li[i]==li[i-1]:
count +=1
newli.append(li[i-1])
newli.append(li[-1])
print(count)
print(" ".join([str(x) for x in ne... | Title: Tanya and Stairways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For ... | ```python
n = int(input())
li = list(map(int, input().split()))
count = 1
newli = []
for i in range(1,n):
if li[i]<li[i-1]:
count +=1
newli.append(li[i-1])
if li[i]==li[i-1]:
count +=1
newli.append(li[i-1])
newli.append(li[-1])
print(count)
print(" ".join([str(x) f... | 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,649,615,359 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 92 | 0 | n=int(input(''))
l=list(map(int,input().split()))
c,bc,bk=[],[],[]
for i in range(0,n,3):
c.append(l[i])
for j in range(1,n,3):
bc.append(l[j])
for k in range(2,n,3):
bk.append(l[k])
t=[sum(c),sum(bc),sum(bk)]
m=t.index(max(t))
if m==0:
print('chest')
elif m==1:
print('biceps')
else:
... | 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(''))
l=list(map(int,input().split()))
c,bc,bk=[],[],[]
for i in range(0,n,3):
c.append(l[i])
for j in range(1,n,3):
bc.append(l[j])
for k in range(2,n,3):
bk.append(l[k])
t=[sum(c),sum(bc),sum(bk)]
m=t.index(max(t))
if m==0:
print('chest')
elif m==1:
print('biceps... | 3 | |
448 | A | Rewards | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present β a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize c... | The first line contains integers *a*1, *a*2 and *a*3 (0<=β€<=*a*1,<=*a*2,<=*a*3<=β€<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=β€<=*b*1,<=*b*2,<=*b*3<=β€<=100). The third line contains integer *n* (1<=β€<=*n*<=β€<=100).
The numbers in the lines are separated by single spaces. | Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes). | [
"1 1 1\n1 1 1\n4\n",
"1 1 3\n2 3 4\n2\n",
"1 0 0\n1 0 0\n1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "1 1 1\n1 1 1\n4",
"output": "YES"
},
{
"input": "1 1 3\n2 3 4\n2",
"output": "YES"
},
{
"input": "1 0 0\n1 0 0\n1",
"output": "NO"
},
{
"input": "0 0 0\n0 0 0\n1",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n100",
"output": "YES"
},
... | 1,655,994,472 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 186 | 12,800,000 | import sys
import math
import collections
import heapq
import decimal
input=sys.stdin.readline
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
n=int(input())
if(math.ceil(sum(a)/5)+math.ceil(sum(b)/10)<=n):
print("YES")
else:
print("NO") | Title: Rewards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present β a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into ... | ```python
import sys
import math
import collections
import heapq
import decimal
input=sys.stdin.readline
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
n=int(input())
if(math.ceil(sum(a)/5)+math.ceil(sum(b)/10)<=n):
print("YES")
else:
print("NO")
``` | 3 | |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=β€<=*n*<=β€<=1.5Β·105,<=1<=β€<=*k*<=β€<=*n*) β the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=β€<=*h**i*<=β€<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,685,903,866 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 109 | 15,769,600 | n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
from math import *
summ = 0
min_sum = inf
for right in range(k):
summ += arr[right]
min_sum = min(min_sum, summ)
idx = 0
for i in range(k, n):
summ = summ - arr[i - k] + arr[i]
if summ < min_sum:
min_sum =... | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
from math import *
summ = 0
min_sum = inf
for right in range(k):
summ += arr[right]
min_sum = min(min_sum, summ)
idx = 0
for i in range(k, n):
summ = summ - arr[i - k] + arr[i]
if summ < min_sum:
... | 3 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100)Β β the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,692,145,421 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 46 | 0 | A = []
def Color (A) :
for i in A:
for j in i:
if j!='B' and j!='W' and j!='G' :
return '#Color'
return '#Black&White'
a = list(map(int,input().split()))
for i in range(a[0]):
b = list(map(str, input().split()))
A.append(b)
print(Color(A))
... | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
A = []
def Color (A) :
for i in A:
for j in i:
if j!='B' and j!='W' and j!='G' :
return '#Color'
return '#Black&White'
a = list(map(int,input().split()))
for i in range(a[0]):
b = list(map(str, input().split()))
A.append(b)
print(Color(A))
... | 3 | |
707 | C | Pythagorean Triples | PROGRAMMING | 1,500 | [
"math",
"number theory"
] | null | null | Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.
For example, tripl... | The only line of the input contains single integer *n* (1<=β€<=*n*<=β€<=109)Β β the length of some side of a right triangle. | Print two integers *m* and *k* (1<=β€<=*m*,<=*k*<=β€<=1018), such that *n*, *m* and *k* form a Pythagorean triple, in the only line.
In case if there is no any Pythagorean triple containing integer *n*, print <=-<=1 in the only line. If there are many answers, print any of them. | [
"3\n",
"6\n",
"1\n",
"17\n",
"67\n"
] | [
"4 5",
"8 10",
"-1",
"144 145",
"2244 2245"
] | Illustration for the first sample. | 1,500 | [
{
"input": "3",
"output": "4 5"
},
{
"input": "6",
"output": "8 10"
},
{
"input": "1",
"output": "-1"
},
{
"input": "17",
"output": "144 145"
},
{
"input": "67",
"output": "2244 2245"
},
{
"input": "10",
"output": "24 26"
},
{
"input": "14"... | 1,681,307,754 | 2,147,483,647 | Python 3 | OK | TESTS | 90 | 46 | 0 | n = int(input())
if n < 3:
print(-1)
elif n % 2 == 1:
k = 1
a = (n**2//k - k)//2
b = (n**2//k + k)//2
print(a, b)
else:
k = 2
a = (n ** 2 // k - k) // 2
b = (n ** 2 // k + k) // 2
print(a, b)
| Title: Pythagorean Triples
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segm... | ```python
n = int(input())
if n < 3:
print(-1)
elif n % 2 == 1:
k = 1
a = (n**2//k - k)//2
b = (n**2//k + k)//2
print(a, b)
else:
k = 2
a = (n ** 2 // k - k) // 2
b = (n ** 2 // k + k) // 2
print(a, b)
``` | 3 | |
52 | A | 123-sequence | PROGRAMMING | 900 | [
"implementation"
] | A. 123-sequence | 2 | 256 | There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | The first line contains an integer *n* (1<=β€<=*n*<=β€<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=3). | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | [
"9\n1 3 2 2 2 1 1 2 3\n"
] | [
"5\n"
] | In the example all the numbers equal to 1 and 3 should be replaced by 2. | 500 | [
{
"input": "9\n1 3 2 2 2 1 1 2 3",
"output": "5"
},
{
"input": "6\n3 3 2 2 1 3",
"output": "3"
},
{
"input": "12\n3 1 3 1 2 1 3 2 2 1 2 1",
"output": "7"
},
{
"input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2",
"output": "10"
},
{
"input": "2\n2 1",
"output": "1"
... | 1,600,524,465 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 904 | 14,643,200 | n=int(input())
count=0
one=0
two=0
three=0
x=list(map(int,input().split()))
for i in x:
if i==1:
one=one+1
elif i==2:
two=two+1
elif i==3:
three=three+1
max_=max(one,two ,three)
answer=n-max_
print(answer) | Title: 123-sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each... | ```python
n=int(input())
count=0
one=0
two=0
three=0
x=list(map(int,input().split()))
for i in x:
if i==1:
one=one+1
elif i==2:
two=two+1
elif i==3:
three=three+1
max_=max(one,two ,three)
answer=n-max_
print(answer)
``` | 3.746725 |
1,009 | C | Annoying Present | PROGRAMMING | 1,700 | [
"greedy",
"math"
] | null | null | Alice got an array of length $n$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $m$ changes of the following form. For some int... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) β the number of elements of the array and the number of changes.
Each of the next $m$ lines contains two integers $x_i$ and $d_i$ ($-10^3 \le x_i, d_i \le 10^3$) β the parameters for the $i$-th change. | Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $10^{-6}$. | [
"2 3\n-1 3\n0 0\n-1 -4\n",
"3 2\n0 2\n5 0\n"
] | [
"-2.500000000000000\n",
"7.000000000000000\n"
] | none | 0 | [
{
"input": "2 3\n-1 3\n0 0\n-1 -4",
"output": "-2.500000000000000"
},
{
"input": "3 2\n0 2\n5 0",
"output": "7.000000000000000"
},
{
"input": "8 8\n-21 -60\n-96 -10\n-4 -19\n-27 -4\n57 -15\n-95 62\n-42 1\n-17 64",
"output": "-16.500000000000000"
},
{
"input": "1 1\n0 0",
... | 1,682,173,812 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 124 | 3,891,200 | import sys
input = sys.stdin.readline
def f(u):
return u*(u+1)//2
n, m = map(int, input().split())
x1, x2 = n//2, (n-1)//2
x, y, c, d = f(x1) + f(x2), f(n-1), 0, 0
for i in range(m):
a, b = map(int, input().split())
c += a
d += max(b*x, b*y)
print((c*n+d)/n) | Title: Annoying Present
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice got an array of length $n$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some c... | ```python
import sys
input = sys.stdin.readline
def f(u):
return u*(u+1)//2
n, m = map(int, input().split())
x1, x2 = n//2, (n-1)//2
x, y, c, d = f(x1) + f(x2), f(n-1), 0, 0
for i in range(m):
a, b = map(int, input().split())
c += a
d += max(b*x, b*y)
print((c*n+d)/n)
``` | 3 | |
92 | A | Chips | PROGRAMMING | 800 | [
"implementation",
"math"
] | A. Chips | 2 | 256 | There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The pre... | The first line contains two integers *n* and *m* (1<=β€<=*n*<=β€<=50, 1<=β€<=*m*<=β€<=104) β the number of walruses and the number of chips correspondingly. | Print the number of chips the presenter ended up with. | [
"4 11\n",
"17 107\n",
"3 8\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the ... | 500 | [
{
"input": "4 11",
"output": "0"
},
{
"input": "17 107",
"output": "2"
},
{
"input": "3 8",
"output": "1"
},
{
"input": "46 7262",
"output": "35"
},
{
"input": "32 6864",
"output": "0"
},
{
"input": "36 6218",
"output": "14"
},
{
"input": "... | 1,507,366,718 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 124 | 0 | n,m = map(int,input().split())
s = int(n*(n+1)/2)
m = m%s
for i in range(1,n):
if(m<i):
break
m= m-i
print(m) | Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu... | ```python
n,m = map(int,input().split())
s = int(n*(n+1)/2)
m = m%s
for i in range(1,n):
if(m<i):
break
m= m-i
print(m)
``` | 3.969 |
774 | D | Lie or Truth | PROGRAMMING | 1,500 | [
"*special",
"constructive algorithms",
"implementation",
"sortings"
] | null | null | Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,<=*a*2,<=...,<=*a**n*.
While Vasya was walking, his little brother Stepan played with Vasya's cub... | The first line contains three integers *n*, *l*, *r* (1<=β€<=*n*<=β€<=105, 1<=β€<=*l*<=β€<=*r*<=β€<=*n*) β the number of Vasya's cubes and the positions told by Stepan.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=*n*) β the sequence of integers written on cubes in the Vasya's order.
... | Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes). | [
"5 2 4\n3 4 2 3 1\n3 2 3 4 1\n",
"3 1 2\n1 2 3\n3 1 2\n",
"4 2 4\n1 1 1 1\n1 1 1 1\n"
] | [
"TRUTH\n",
"LIE\n",
"TRUTH\n"
] | In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and... | 0 | [
{
"input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1",
"output": "TRUTH"
},
{
"input": "3 1 2\n1 2 3\n3 1 2",
"output": "LIE"
},
{
"input": "4 2 4\n1 1 1 1\n1 1 1 1",
"output": "TRUTH"
},
{
"input": "5 1 3\n2 2 2 1 2\n2 2 2 1 2",
"output": "TRUTH"
},
{
"input": "7 1 4\n2 5 5 5... | 1,491,407,788 | 1,288 | Python 3 | OK | TESTS | 52 | 140 | 15,155,200 | import sys
def main():
yes = True
array = sys.stdin.readline().strip().split(' ')
array1 = sys.stdin.readline().strip().split(' ')
array2 = sys.stdin.readline().strip().split(' ')
for i in range(len(array1)):
if i < int(array[1])-1 or i >= int(array[2]):
if array1[i] != array2[i... | Title: Lie or Truth
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,... | ```python
import sys
def main():
yes = True
array = sys.stdin.readline().strip().split(' ')
array1 = sys.stdin.readline().strip().split(' ')
array2 = sys.stdin.readline().strip().split(' ')
for i in range(len(array1)):
if i < int(array[1])-1 or i >= int(array[2]):
if array1[i] !... | 3 | |
776 | B | Sherlock and his girlfriend | PROGRAMMING | 1,200 | [
"constructive algorithms",
"number theory"
] | null | null | Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pie... | The only line contains single integer *n* (1<=β€<=*n*<=β€<=100000)Β β the number of jewelry pieces. | The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
... | [
"3\n",
"4\n"
] | [
"2\n1 1 2 ",
"2\n2 1 1 2\n"
] | In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | 1,000 | [
{
"input": "3",
"output": "2\n1 1 2 "
},
{
"input": "4",
"output": "2\n1 1 2 1 "
},
{
"input": "17",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 "
},
{
"input": "25",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 "
},
{
"input": "85",
"ou... | 1,521,092,554 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 623 | 6,758,400 | n=int(input())
a=[0]*(n+2)
for i in range(2,n+2):
for j in range(i,n+2,i):
a[j]+=1
if n>2:print(2)
else:print(1)
for i in range(2,n+2):
if a[i]==1:
print(1,end=' ')
else:
print(2,end=' ') | Title: Sherlock and his girlfriend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the ... | ```python
n=int(input())
a=[0]*(n+2)
for i in range(2,n+2):
for j in range(i,n+2,i):
a[j]+=1
if n>2:print(2)
else:print(1)
for i in range(2,n+2):
if a[i]==1:
print(1,end=' ')
else:
print(2,end=' ')
``` | 3 | |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction β "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,689,393,338 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 92 | 0 | print(["NO", "YES"][bool(set("HQ9") & set(input()))])
| 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
print(["NO", "YES"][bool(set("HQ9") & set(input()))])
``` | 3 | |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894"... | 1,663,689,304 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 0 | n, k = input().split()
n = int(n)
k = int(k)
print(n-(n%k)+k) | Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *... | ```python
n, k = input().split()
n = int(n)
k = int(k)
print(n-(n%k)+k)
``` | 3 | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=β€<=*n*<=β€<=100) β amount of numbers in the sequence. The second line contains *n* space-separated integer numbers β elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,671,630,512 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n1=int(input())
lis=list(map(int,input().split()))
lis=list(set(lis))
lis.sort()
if len(lis)>1:
print(lis[1])
else:
print("NO")
| Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
n1=int(input())
lis=list(map(int,input().split()))
lis=list(set(lis))
lis.sort()
if len(lis)>1:
print(lis[1])
else:
print("NO")
``` | 3.977 |
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" β the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power us... | The only line of the input contains a single integer *n* (2<=β€<=*n*<=β€<=2Β·1018) β the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,694,440,621 | 2,147,483,647 | Python 3 | OK | TESTS | 5 | 31 | 0 | n= int(input())
if n==0:
m='0'
p=1
print(m,end='')
print(p)
elif n==1:
m=0
p=5
print(m,end='')
print(p)
else:
m=25
print(m) | Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" β the HR manager thought. "Just raise number 5 to the power of *n* and ge... | ```python
n= int(input())
if n==0:
m='0'
p=1
print(m,end='')
print(p)
elif n==1:
m=0
p=5
print(m,end='')
print(p)
else:
m=25
print(m)
``` | 3 | |
628 | B | New Skateboard | PROGRAMMING | 1,300 | [
"dp"
] | null | null | Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which... | The only line contains string *s* (1<=β€<=|*s*|<=β€<=3Β·105). The string *s* contains only digits from 0 to 9. | Print integer *a* β the number of substrings of the string *s* that are divisible by 4.
Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"124\n",
"04\n",
"5810438174\n"
] | [
"4\n",
"3\n",
"9\n"
] | none | 0 | [
{
"input": "124",
"output": "4"
},
{
"input": "04",
"output": "3"
},
{
"input": "5810438174",
"output": "9"
},
{
"input": "1",
"output": "0"
},
{
"input": "039",
"output": "1"
},
{
"input": "97247",
"output": "6"
},
{
"input": "5810438174",... | 1,679,977,212 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 265 | 614,400 | a=input()
l=r=0
for i in range(len(a)):
r=l+(a[i]in'048')+i*(i and int(a[i-1:i+1])%4==0)
l=r
print(r)
| Title: New Skateboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother... | ```python
a=input()
l=r=0
for i in range(len(a)):
r=l+(a[i]in'048')+i*(i and int(a[i-1:i+1])%4==0)
l=r
print(r)
``` | 3 | |
651 | A | Joysticks | PROGRAMMING | 1,100 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n... | The first line of the input contains two positive integers *a*1 and *a*2 (1<=β€<=*a*1,<=*a*2<=β€<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst... | 500 | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
... | 1,623,950,979 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 62 | 0 | a,b=map(int,input().split())
m=0
if a==1 and b==1:
print("0")
else:
while a>0 and b>0:
if a==b:
a+=1
b-=2
m+=1
elif a==1:
a+=1
b-=2
m+=1
elif b==1:
b+=1
a-=2
m+=1
... | Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on... | ```python
a,b=map(int,input().split())
m=0
if a==1 and b==1:
print("0")
else:
while a>0 and b>0:
if a==b:
a+=1
b-=2
m+=1
elif a==1:
a+=1
b-=2
m+=1
elif b==1:
b+=1
a-=2
... | 3 | |
505 | A | Mr. Kitayuta's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "tes... | The only line of the input contains a string *s* (1<=β€<=|*s*|<=β€<=10). Each character in *s* is a lowercase English letter. | If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted. | [
"revive\n",
"ee\n",
"kitayuta\n"
] | [
"reviver\n",
"eye",
"NA\n"
] | For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | 500 | [
{
"input": "revive",
"output": "reviver"
},
{
"input": "ee",
"output": "eee"
},
{
"input": "kitayuta",
"output": "NA"
},
{
"input": "evima",
"output": "NA"
},
{
"input": "a",
"output": "aa"
},
{
"input": "yutampo",
"output": "NA"
},
{
"inpu... | 1,422,577,299 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 0 | def ispal(s):
i = 0
j = len(s) - 1
while i < j:
if s[i] != s[j]:
return False
i += 1
j -= 1
return True
alpha = 'abcdefghijklmnopqrstuvwxyz'
found = 0
s = input()
for i in range(0,len(s)+1):
for j in range(len(alpha)):
temp = s[:i] + alpha[j] + s[i:]
if ispal(temp):
found = 1
print(temp)
bre... | Title: Mr. Kitayuta's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that re... | ```python
def ispal(s):
i = 0
j = len(s) - 1
while i < j:
if s[i] != s[j]:
return False
i += 1
j -= 1
return True
alpha = 'abcdefghijklmnopqrstuvwxyz'
found = 0
s = input()
for i in range(0,len(s)+1):
for j in range(len(alpha)):
temp = s[:i] + alpha[j] + s[i:]
if ispal(temp):
found = 1
print(te... | 3 | |
607 | A | Chain Reaction | PROGRAMMING | 1,600 | [
"binary search",
"dp"
] | null | null | There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however.... | The first line of input contains a single integer *n* (1<=β€<=*n*<=β€<=100<=000) β the initial number of beacons.
The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=β€<=*a**i*<=β€<=1<=000<=000, 1<=β€<=*b**i*<=β€<=1<=000<=000)Β β the position and power level of the *i*-th beacon respectively. No two beac... | Print a single integerΒ β the minimum number of beacons that could be destroyed if exactly one beacon is added. | [
"4\n1 9\n3 1\n6 1\n7 4\n",
"7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n"
] | [
"1\n",
"3\n"
] | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | 500 | [
{
"input": "4\n1 9\n3 1\n6 1\n7 4",
"output": "1"
},
{
"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1",
"output": "3"
},
{
"input": "1\n0 1",
"output": "0"
},
{
"input": "1\n0 1000000",
"output": "0"
},
{
"input": "1\n1000000 1000000",
"output": "0"
},
{
... | 1,681,265,733 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 561 | 8,499,200 | from sys import stdin
from bisect import bisect_left
def main():
n = int(input())
beacons = [tuple(map(int, input().split())) for _ in range(n)]
beacons.sort()
# dp[i] stores the number of beacons that can be saved when considering the beacons from the rightmost one to the i-th one
dp = [... | Title: Chain Reaction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of d... | ```python
from sys import stdin
from bisect import bisect_left
def main():
n = int(input())
beacons = [tuple(map(int, input().split())) for _ in range(n)]
beacons.sort()
# dp[i] stores the number of beacons that can be saved when considering the beacons from the rightmost one to the i-th one
... | 3 | |
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ... | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters β The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1... | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "1010110111100100001010010001101010110111001011011... | 1,697,709,407 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 124 | 0 | n=input()
m=[]
seq_size = 10
seq_num = 8
a=''
for i in range(seq_num):
m.append(n[i*seq_size:(i+1)*seq_size])
mas=[]
for i in range(10):
l=input()
mas.append(l)
for i in m:
a+=str(mas.index(i))
print(a) | Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff a... | ```python
n=input()
m=[]
seq_size = 10
seq_num = 8
a=''
for i in range(seq_num):
m.append(n[i*seq_size:(i+1)*seq_size])
mas=[]
for i in range(10):
l=input()
mas.append(l)
for i in m:
a+=str(mas.index(i))
print(a)
``` | 3.969 |
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,698,690,299 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 358 | 819,200 | IN = lambda x:list(map(x, input().split()))
n, m = IN(x = int)
l1 = []
l2 = []
for x in range(m):
a,b = IN(x = str)
l1 += [a]; l2 += [b]
for y in input().split():
if y in l1:
if len(l2[l1.index(y)]) < len(y): print(l2[l1.index(y)], end = " ")
else: print(y, end = " ")
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
IN = lambda x:list(map(x, input().split()))
n, m = IN(x = int)
l1 = []
l2 = []
for x in range(m):
a,b = IN(x = str)
l1 += [a]; l2 += [b]
for y in input().split():
if y in l1:
if len(l2[l1.index(y)]) < len(y): print(l2[l1.index(y)], end = " ")
else: print(y, end = " ")
... | 3 | |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=100) β the number of bits in the cell.
The second line contains a string consisting of *n* characters β the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer β the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample β with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,688,650,266 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 61 | 0 | import sys
input = sys.stdin.readline
n = int(input())
data = input().rstrip()[::-1]
tmp = bin(int(data, 2) + 1)[2:]
tmp = (n - len(tmp)) * '0' + tmp
cnt = 0
for i in range(n):
if data[-(i + 1)] != tmp[-(i + 1)]:
cnt += 1
print(cnt)
| Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
import sys
input = sys.stdin.readline
n = int(input())
data = input().rstrip()[::-1]
tmp = bin(int(data, 2) + 1)[2:]
tmp = (n - len(tmp)) * '0' + tmp
cnt = 0
for i in range(n):
if data[-(i + 1)] != tmp[-(i + 1)]:
cnt += 1
print(cnt)
``` | 3 | |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | In the first line of input there is one integer $n$ ($0 \le n \le 6$)Β β the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ... | In the first line output one integer $m$ ($0 \le m \le 6$)Β β the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReal... | 1,581,040,004 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 124 | 0 | a=['purple', 'green', 'blue', 'orange', 'red', 'yellow']
b=['Power', 'Time', 'Space', 'Soul', 'Reality', 'Mind']
n=int(input())
c=[input() for _ in [0]*n]
d=[b[x] for x,y in enumerate(a) if y not in c]
print(len(d),*d,sep='\n') | Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So... | ```python
a=['purple', 'green', 'blue', 'orange', 'red', 'yellow']
b=['Power', 'Time', 'Space', 'Soul', 'Reality', 'Mind']
n=int(input())
c=[input() for _ in [0]*n]
d=[b[x] for x,y in enumerate(a) if y not in c]
print(len(d),*d,sep='\n')
``` | 3 | |
507 | C | Guess Your Way Out! | PROGRAMMING | 1,700 | [
"implementation",
"math",
"trees"
] | null | null | Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height *h*. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.
Let's index all the leaf nodes from the left t... | Input consists of two integers *h*,<=*n* (1<=β€<=*h*<=β€<=50, 1<=β€<=*n*<=β€<=2*h*). | Output a single integer representing the number of nodes (excluding the exit node) Amr is going to visit before reaching the exit by following this algorithm. | [
"1 2\n",
"2 3\n",
"3 6\n",
"10 1024\n"
] | [
"2",
"5",
"10",
"2046"
] | A perfect binary tree of height *h* is a binary tree consisting of *h*β+β1 levels. Level 0 consists of a single node called root, level *h* consists of 2<sup class="upper-index">*h*</sup> nodes called leaves. Each node that is not a leaf has exactly two children, left and right one.
Following picture illustrates the ... | 1,500 | [
{
"input": "1 2",
"output": "2"
},
{
"input": "2 3",
"output": "5"
},
{
"input": "3 6",
"output": "10"
},
{
"input": "10 1024",
"output": "2046"
},
{
"input": "10 577",
"output": "1345"
},
{
"input": "11 550",
"output": "408"
},
{
"input": ... | 1,606,941,942 | 2,147,483,647 | PyPy 3 | OK | TESTS | 62 | 140 | 0 | import sys
import math
MAXNUM = math.inf
MINNUM = -1 * math.inf
ASCIILOWER = 97
ASCIIUPPER = 65
def getInt():
return int(sys.stdin.readline().rstrip())
def getInts():
return map(int, sys.stdin.readline().rstrip().split(" "))
def getString():
return sys.stdin.readline().rstrip()
def printOutput(ans)... | Title: Guess Your Way Out!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height *h*. The player is initially standing at the root of the tree ... | ```python
import sys
import math
MAXNUM = math.inf
MINNUM = -1 * math.inf
ASCIILOWER = 97
ASCIIUPPER = 65
def getInt():
return int(sys.stdin.readline().rstrip())
def getInts():
return map(int, sys.stdin.readline().rstrip().split(" "))
def getString():
return sys.stdin.readline().rstrip()
def printO... | 3 | |
584 | A | Olesya and Rodion | PROGRAMMING | 1,000 | [
"math"
] | null | null | Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-... | The single line contains two numbers, *n* and *t* (1<=β€<=*n*<=β€<=100, 2<=β€<=*t*<=β€<=10) β the length of the number and the number it should be divisible by. | Print one such positive number without leading zeroes, β the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. | [
"3 2\n"
] | [
"712"
] | none | 500 | [
{
"input": "3 2",
"output": "222"
},
{
"input": "2 2",
"output": "22"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 3",
"output": "33333"
},
{
"input": "10 7",
"output": "7777777777"
},
{
"input": "2 9",
"output": "99"
},
{
"input"... | 1,696,287,260 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 65 | 62 | 0 | n,k = map(int,input().split())
if n==1 and k==10:
print(-1)
elif k==10:
print('1'+'0'*(n-1))
else:
print(str(k)*n) | Title: Olesya and Rodion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larg... | ```python
n,k = map(int,input().split())
if n==1 and k==10:
print(-1)
elif k==10:
print('1'+'0'*(n-1))
else:
print(str(k)*n)
``` | 3 | |
793 | A | Oleg and shares | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. ... | The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=105,<=1<=β€<=*k*<=β€<=109)Β β the number of share prices, and the amount of rubles some price decreases each second.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109)Β β the initial prices. | Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. | [
"3 3\n12 9 15\n",
"2 2\n10 9\n",
"4 1\n1 1000000000 1000000000 1000000000\n"
] | [
"3",
"-1",
"2999999997"
] | Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
Ther... | 500 | [
{
"input": "3 3\n12 9 15",
"output": "3"
},
{
"input": "2 2\n10 9",
"output": "-1"
},
{
"input": "4 1\n1 1000000000 1000000000 1000000000",
"output": "2999999997"
},
{
"input": "1 11\n123",
"output": "0"
},
{
"input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50... | 1,593,018,892 | 2,147,483,647 | PyPy 3 | OK | TESTS | 88 | 234 | 34,099,200 | n , k = map(int,input().split())
l = list(map(int,input().split()))
st = set(l)
cnt = 0
if len(st) == 1 :
print(0)
exit()
else:
x = min(l)
for i in l :
c = i - x
if c % k == 0 :
cnt += c // k
else:
print(-1)
exit()
prin... | Title: Oleg and shares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly o... | ```python
n , k = map(int,input().split())
l = list(map(int,input().split()))
st = set(l)
cnt = 0
if len(st) == 1 :
print(0)
exit()
else:
x = min(l)
for i in l :
c = i - x
if c % k == 0 :
cnt += c // k
else:
print(-1)
exit()
... | 3 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=β€<=*n*<=β€<=1000) β the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers β they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number β the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,692,593,754 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 | n = int(input())
points = list(map(int, input().split()))
amazing_performance = 0
highest_point = points[0]
lowest_point = points[0]
for i in range(1, n):
if points[i] > highest_point:
highest_point = points[i]
amazing_performa... | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n = int(input())
points = list(map(int, input().split()))
amazing_performance = 0
highest_point = points[0]
lowest_point = points[0]
for i in range(1, n):
if points[i] > highest_point:
highest_point = points[i]
amazin... | 3 | |
930 | A | Peculiar apple-tree | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near base of tree and any other inflorescence with number *i* (*i*<=><=1) is situated at the ... | First line of input contains single integer number *n* (2<=β€<=*n*<=β€<=100<=000) Β β number of inflorescences.
Second line of input contains sequence of *n*<=-<=1 integer numbers *p*2,<=*p*3,<=...,<=*p**n* (1<=β€<=*p**i*<=<<=*i*), where *p**i* is number of inflorescence into which the apple from *i*-th inflorescence r... | Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest. | [
"3\n1 1\n",
"5\n1 2 2 2\n",
"18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n"
] | [
"1\n",
"3\n",
"4\n"
] | In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.
In the second example Arcady will be able to collect 3 apples. First one is one initial... | 500 | [
{
"input": "3\n1 1",
"output": "1"
},
{
"input": "5\n1 2 2 2",
"output": "3"
},
{
"input": "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4",
"output": "4"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "3\n1 2",
"output": "3"
},
{
"input": "20\n1 1 1 1 1 ... | 1,644,592,407 | 2,147,483,647 | Python 3 | OK | TESTS | 90 | 156 | 14,950,400 | n=int(input())
a=[*map(int,input().split())]
q={}
for i in range(1,n+1):
q[i]=0
for i in range(n-1):
q[i+2]=q[a[i]]+1
z={}
for i in q.values():
z[i]=z.get(i,0)+1
print(sum(z[i]%2 for i in z)) | Title: Peculiar apple-tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is ... | ```python
n=int(input())
a=[*map(int,input().split())]
q={}
for i in range(1,n+1):
q[i]=0
for i in range(n-1):
q[i+2]=q[a[i]]+1
z={}
for i in q.values():
z[i]=z.get(i,0)+1
print(sum(z[i]%2 for i in z))
``` | 3 | |
515 | C | Drazil and Factorial | PROGRAMMING | 1,400 | [
"greedy",
"math",
"sortings"
] | null | null | Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they shoul... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=15) β the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. | Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. | [
"4\n1234\n",
"3\n555\n"
] | [
"33222\n",
"555\n"
] | In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "4\n1234",
"output": "33222"
},
{
"input": "3\n555",
"output": "555"
},
{
"input": "15\n012345781234578",
"output": "7777553333222222222222"
},
{
"input": "1\n8",
"output": "7222"
},
{
"input": "10\n1413472614",
"output": "75333332222222"
},
{
... | 1,625,917,931 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 109 | 0 | l=[""," ","2","3","322","5","53","7","7222","7332"]
s=""
n=int(input())
k=input()
for i in range(n):
s=s+l[int(k[i])]
s=list(s)
s.sort(reverse=True)
print(*s,sep="") | Title: Drazil and Factorial
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that cont... | ```python
l=[""," ","2","3","322","5","53","7","7222","7332"]
s=""
n=int(input())
k=input()
for i in range(n):
s=s+l[int(k[i])]
s=list(s)
s.sort(reverse=True)
print(*s,sep="")
``` | 3 | |
667 | A | Pouring Rain | PROGRAMMING | 1,100 | [
"geometry",
"math"
] | null | null | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition β when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything ... | The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=β€<=*d*,<=*h*,<=*v*,<=*e*<=β€<=104), where:
- *d* β the diameter of your cylindrical cup, - *h* β the initial level of water in the cup, - *v* β the speed of drinking process from the cup in milliliters per second, - *e* β the growth ... | If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number β time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is... | [
"1 2 3 100\n",
"1 1 1 1\n"
] | [
"NO\n",
"YES\n3.659792366325\n"
] | In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we ca... | 500 | [
{
"input": "1 2 3 100",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "YES\n3.659792366325"
},
{
"input": "48 7946 7992 72",
"output": "NO"
},
{
"input": "72 6791 8546 46",
"output": "NO"
},
{
"input": "100 5635 9099 23",
"output": "NO"
},
{
"input... | 1,461,953,619 | 5,919 | Python 3 | OK | TESTS | 23 | 62 | 4,608,000 | import math
(d,h,v,e) = tuple([int(p) for p in input().strip('\n').split(' ')])
increaseByRain = math.pi * (d/2) * (d/2) * e
totalRate = v - increaseByRain
if totalRate <= 0:
print('NO')
else:
print('YES')
currentVol = math.pi * (d/2) * (d/2) * h
print(str(currentVol/totalRate)) | Title: Pouring Rain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition β when it rains, you go on the street and stay silent for a moment, cont... | ```python
import math
(d,h,v,e) = tuple([int(p) for p in input().strip('\n').split(' ')])
increaseByRain = math.pi * (d/2) * (d/2) * e
totalRate = v - increaseByRain
if totalRate <= 0:
print('NO')
else:
print('YES')
currentVol = math.pi * (d/2) * (d/2) * h
print(str(currentVol/totalRate))
``` | 3 | |
946 | A | Partition | PROGRAMMING | 800 | [
"greedy"
] | null | null | You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequenc... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=100) β the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=β€<=*a**i*<=β€<=100) β the elements of sequence *a*. | Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. | [
"3\n1 -2 0\n",
"6\n16 23 16 15 42 8\n"
] | [
"3\n",
"120\n"
] | In the first example we may choose *b*β=β{1,β0}, *c*β=β{β-β2}. Then *B*β=β1, *C*β=ββ-β2, *B*β-β*C*β=β3.
In the second example we choose *b*β=β{16,β23,β16,β15,β42,β8}, *c*β=β{} (an empty sequence). Then *B*β=β120, *C*β=β0, *B*β-β*C*β=β120. | 0 | [
{
"input": "3\n1 -2 0",
"output": "3"
},
{
"input": "6\n16 23 16 15 42 8",
"output": "120"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "100\n-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 -10... | 1,573,835,228 | 2,147,483,647 | Python 3 | OK | TESTS | 72 | 109 | 0 | n=int(input())
a=list(map(int,input().split()))
sum=0
for i in a:
sum+=abs(i)
print(sum)
| Title: Partition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of eleme... | ```python
n=int(input())
a=list(map(int,input().split()))
sum=0
for i in a:
sum+=abs(i)
print(sum)
``` | 3 | |
954 | A | Diagonal Walking | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | The first line of the input contains one integer *n* (1<=β€<=*n*<=β€<=100)Β β the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. | Print the minimum possible length of the sequence of moves after all replacements are done. | [
"5\nRUURU\n",
"17\nUUURRRRRUUURURUUU\n"
] | [
"3\n",
"13\n"
] | In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | 0 | [
{
"input": "5\nRUURU",
"output": "3"
},
{
"input": "17\nUUURRRRRUUURURUUU",
"output": "13"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "100"
},
{
"input": "100\nRRURRUUUURURRRURRRRURRRRRR... | 1,638,205,130 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 46 | 0 | # -*- coding: utf-8 -*-
"""diagonal walking .ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1pAmw3SAXBpNn-FeuwNJCdgpcYI-BxCEJ
"""
n=int(input())
a=input()
count=n
i=0
while i<n-1:
if a[i]!=a[i+1]:
count-=1
i+=2
else:
i+=1
print(c... | Title: Diagonal Walking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence movi... | ```python
# -*- coding: utf-8 -*-
"""diagonal walking .ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1pAmw3SAXBpNn-FeuwNJCdgpcYI-BxCEJ
"""
n=int(input())
a=input()
count=n
i=0
while i<n-1:
if a[i]!=a[i+1]:
count-=1
i+=2
else:
i+... | 3 | |
259 | B | Little Elephant and Magic Square | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=Γ<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals ... | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented... | Print three lines, in each line print three integers β the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditio... | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | 1,000 | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 5... | 1,603,861,637 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 218 | 0 | l,q=[0]*3,0
for i in range(3):l[i]=list(map(int,input().split()));q+=sum(l[i])
for i in range(3):l[i][i]=q//2-sum(l[i]);print(*l[i]) | Title: Little Elephant and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Elephant loves magic squares very much.
A magic square is a 3<=Γ<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table ... | ```python
l,q=[0]*3,0
for i in range(3):l[i]=list(map(int,input().split()));q+=sum(l[i])
for i in range(3):l[i][i]=q//2-sum(l[i]);print(*l[i])
``` | 3 | |
753 | B | Interactive Bulls and Cows (Easy) | PROGRAMMING | 1,600 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get responses in the online mode. Please be sure to use the stream flushing operation after each query's output in order not to leave part of your output in some buffer. For exa... | To read answers to the queries, the program must use the standard input.
The program will receive pairs of non-negative integers in the input, one pair per line. The first number in a pair is a number of bulls and the second one is a number of cows of the string *s* and the string *x**i* printed by your program. If th... | The program must use the standard output to print queries.
Your program must output requests β 4-digit strings *x*1,<=*x*2,<=..., one per line. After the output of each line the program must execute flush operation. The program should read the answer to the query from the standard input.
Your program is allowed to do... | [
"0 1\n2 0\n1 1\n0 4\n2 1\n4 0\n"
] | [
"8000\n0179\n3159\n3210\n0112\n0123"
] | The secret string *s* in the example is "0123". | 1,000 | [
{
"input": "0123",
"output": "20"
},
{
"input": "1234",
"output": "20"
},
{
"input": "9876",
"output": "20"
},
{
"input": "7158",
"output": "20"
},
{
"input": "7590",
"output": "20"
},
{
"input": "7325",
"output": "20"
},
{
"input": "7524",... | 1,483,003,948 | 1,648 | Python 3 | OK | TESTS | 41 | 62 | 4,608,000 | from sys import stdout
from itertools import permutations
var = []
for i in range(10):
print(str(i) * 4)
stdout.flush()
a, b = map(int, input().split())
if a:
var.append(str(i))
for t in permutations(var):
print(''.join(t))
stdout.flush()
a, b = map(int, input... | Title: Interactive Bulls and Cows (Easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get responses in the online mode. Please be sure to use th... | ```python
from sys import stdout
from itertools import permutations
var = []
for i in range(10):
print(str(i) * 4)
stdout.flush()
a, b = map(int, input().split())
if a:
var.append(str(i))
for t in permutations(var):
print(''.join(t))
stdout.flush()
a, b = map(... | 3 | |
63 | B | Settlers' Training | PROGRAMMING | 1,200 | [
"implementation"
] | B. Settlers' Training | 2 | 256 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly *n* soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either i... | The first line contains two integers *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains *n* numbers in the non-decreasing order. The *i*-th of them, *a**i*, represents the rank of the *i*-th soldier in the defense buil... | Print a single integer β the number of golden coins needed to raise all the soldiers to the maximal rank. | [
"4 4\n1 2 2 3\n",
"4 3\n1 1 1 1\n"
] | [
"4",
"5"
] | In the first example the ranks will be raised in the following manner:
1 2 2 3 βββ 2 2 3 4 βββ 2 3 4 4 βββ 3 4 4 4 βββ 4 4 4 4
Thus totals to 4 training sessions that require 4 golden coins. | 1,000 | [
{
"input": "4 4\n1 2 2 3",
"output": "4"
},
{
"input": "4 3\n1 1 1 1",
"output": "5"
},
{
"input": "3 3\n1 2 3",
"output": "2"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 5\n1",
"output": "4"
},
{
"input": "1 5\n4",
"output": "1"
},
... | 1,622,060,653 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 218 | 1,331,200 | n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
c=0
while a!=[k]*n:
a.sort()
for i in range(1,n):
if a[i]!=a[i-1]:
a[i-1]+=1
if a[n-1]<k:
a[n-1]+=1
c+=1
print(c) | Title: Settlers' Training
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly *n* soldiers... | ```python
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
c=0
while a!=[k]*n:
a.sort()
for i in range(1,n):
if a[i]!=a[i-1]:
a[i-1]+=1
if a[n-1]<k:
a[n-1]+=1
c+=1
print(c)
``` | 3.94302 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.