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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
690 | F1 | Tree of Life (easy) | PROGRAMMING | 1,300 | [] | null | null | Heidi has finally found the mythical Tree of Life β a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies.
On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of *n* points... | The first line of the input contains a single integer *n* β the number of vertices in the tree (1<=β€<=*n*<=β€<=10000). The vertices are labeled with the numbers from 1 to *n*. Then *n*<=-<=1 lines follow, each describing one edge using two space-separated numbers *a*β*b* β the labels of the vertices connected by the edg... | Print one integer β the number of lifelines in the tree. | [
"4\n1 2\n1 3\n1 4\n",
"5\n1 2\n2 3\n3 4\n3 5\n"
] | [
"3",
"4"
] | In the second sample, there are four lifelines: paths between vertices 1 and 3, 2 and 4, 2 and 5, and 4 and 5. | 0 | [
{
"input": "4\n1 2\n1 3\n1 4",
"output": "3"
},
{
"input": "5\n1 2\n2 3\n3 4\n3 5",
"output": "4"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "3\n2 1\n3 2",
"output": "1"
},
{
"input": "10\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4",
"output": "11"
... | 1,578,067,375 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 124 | 102,400 | n = int(input())
bounds_amount = [-1]*n
for _ in range(n-1):
for el in map(int, input().split(' ')): bounds_amount[el-1] += 1
print(sum(map(lambda x: (x*(x+1))//2, bounds_amount))) | Title: Tree of Life (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Heidi has finally found the mythical Tree of Life β a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies.
On the surface, the Tree of Life is just a r... | ```python
n = int(input())
bounds_amount = [-1]*n
for _ in range(n-1):
for el in map(int, input().split(' ')): bounds_amount[el-1] += 1
print(sum(map(lambda x: (x*(x+1))//2, bounds_amount)))
``` | 3 | |
892 | B | Wrath | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=<<=*i* and *... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=106) β the number of guilty people.
Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=β€<=*L**i*<=β€<=109), where *L**i* is the length of the *i*-th person's claw. | Print one integer β the total number of alive people after the bell rings. | [
"4\n0 1 0 10\n",
"2\n0 0\n",
"10\n1 1 3 0 0 0 2 1 0 3\n"
] | [
"1\n",
"2\n",
"3\n"
] | In first sample the last person kills everyone in front of him. | 1,000 | [
{
"input": "4\n0 1 0 10",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "10\n1 1 3 0 0 0 2 1 0 3",
"output": "3"
},
{
"input": "10\n0 0 2 0 0 3 3 2 2 0",
"output": "2"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 0 0 1 0"... | 1,580,269,535 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 1,169 | 76,492,800 | # -*-coding:utf-8-*-
if __name__ == "__main__":
n = int(input())
a = list(map(int, input().split()))
s = []
for i, v in enumerate(a):
if s:
pre = i - v
while s and s[-1] >= pre:
s.pop()
s.append(i)
print(len(s))
| Title: Wrath
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same ... | ```python
# -*-coding:utf-8-*-
if __name__ == "__main__":
n = int(input())
a = list(map(int, input().split()))
s = []
for i, v in enumerate(a):
if s:
pre = i - v
while s and s[-1] >= pre:
s.pop()
s.append(i)
print(len(s))
... | 3 | |
656 | F | Ace It! | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output a single integer. | The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). | Output a single integer. | [
"A221033\n",
"A223635\n",
"A232726\n"
] | [
"21\n",
"22\n",
"23\n"
] | none | 0 | [
{
"input": "A221033",
"output": "21"
},
{
"input": "A223635",
"output": "22"
},
{
"input": "A232726",
"output": "23"
},
{
"input": "A102210",
"output": "25"
},
{
"input": "A231010",
"output": "26"
},
{
"input": "A222222",
"output": "13"
},
{
... | 1,589,547,954 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 109 | 6,656,000 | nums = input()
counter = 0
for i in nums:
if i == 'A':
counter += 1
elif i == '1':
counter += 10
else:
counter += int(i)
print(counter)
| Title: Ace It!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output a single integer.
Input Specificat... | ```python
nums = input()
counter = 0
for i in nums:
if i == 'A':
counter += 1
elif i == '1':
counter += 10
else:
counter += int(i)
print(counter)
``` | 3 | |
961 | B | Lecture Sleep | PROGRAMMING | 1,200 | [
"data structures",
"dp",
"implementation",
"two pointers"
] | null | null | Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ... | The first line of the input contains two integer numbers *n* and *k* (1<=β€<=*k*<=β€<=*n*<=β€<=105) β the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=β€<=*a**i*<=β€<=104) β the number of theore... | Print only one integer β the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. | [
"6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n"
] | [
"16\n"
] | In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16. | 0 | [
{
"input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "16"
},
{
"input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0",
"output": "30000"
},
{
"input": "3 3\n10 10 10\n1 1 0",
"output": "30"
},
{
"input": "1 1\n423\n0",
"output": "423"
},
{
"input": "6 6\n1 3 5 2 5 4... | 1,587,530,365 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 217 | 11,673,600 | n,d=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
summ=0
for i in range(len(a)):
if b[i]==1:
summ+=a[i]
a[i]=0
for i in range(1,len(a)):
a[i]+=a[i-1]
a.insert(0,0)
maxx=0
for i in range(d,len(a)):
maxx=max(maxx,a[i]-a[i-d])
print(max... | Title: Lecture Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for al... | ```python
n,d=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
summ=0
for i in range(len(a)):
if b[i]==1:
summ+=a[i]
a[i]=0
for i in range(1,len(a)):
a[i]+=a[i-1]
a.insert(0,0)
maxx=0
for i in range(d,len(a)):
maxx=max(maxx,a[i]-a[i-d])
... | 3 | |
742 | A | Arpaβs hard exam and Mehrdadβs naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=β€<=<=*n*<=<=β€<=<=109). | Print single integerΒ β the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup>β=β1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup>β=β1378Β·1378β=β1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,647,021,972 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 77 | 0 | import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
n = int(input())
ans = n%4
arr = [6,8,4,2]
if(n==0):
print(1)
else:
print(arr[ans])
if __name__ == '__main__':
main() | Title: Arpaβs hard exam and Mehrdadβs naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpaβs land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpaβs land. Arpa has prepared an exam. Exam has only one ques... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
n = int(input())
ans = n%4
arr = [6,8,4,2]
if(n==0):
print(1)
else:
print(arr[ans])
if __name__ == '__main__':
main()
``` | 3 | |
960 | B | Minimize the error | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1.
Output the min... | The first line contains three space-separated integers *n* (1<=β€<=*n*<=β€<=103), *k*1 and *k*2 (0<=β€<=*k*1<=+<=*k*2<=β€<=103, *k*1 and *k*2 are non-negative) β size of arrays and number of operations to perform on *A* and *B* respectively.
Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-... | Output a single integer β the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. | [
"2 0 0\n1 2\n2 3\n",
"2 1 0\n1 2\n2 2\n",
"2 5 7\n3 4\n14 4\n"
] | [
"2",
"0",
"1"
] | In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E*β=β(1β-β2)<sup class="upper-index">2</sup>β+β(2β-β3)<sup class="upper-index">2</sup>β=β2.
In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we... | 1,000 | [
{
"input": "2 0 0\n1 2\n2 3",
"output": "2"
},
{
"input": "2 1 0\n1 2\n2 2",
"output": "0"
},
{
"input": "2 5 7\n3 4\n14 4",
"output": "1"
},
{
"input": "2 0 1\n1 2\n2 2",
"output": "0"
},
{
"input": "2 1 1\n0 0\n1 1",
"output": "0"
},
{
"input": "5 5 ... | 1,585,213,063 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 124 | 307,200 | n, k1, k2 = [int(elem) for elem in input().split(" ")]
list1 = [int(elem) for elem in input().split(" ")]
list2 = [int(elem) for elem in input().split(" ")]
lst = list1.copy()
# num_zero = 0
# sum = 0
for i in range(len(lst)):
lst[i] = abs(list1[i]-list2[i])
# if lst[i] == 0:
# num_zero += 1
# sum... | Title: Minimize the error
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one ... | ```python
n, k1, k2 = [int(elem) for elem in input().split(" ")]
list1 = [int(elem) for elem in input().split(" ")]
list2 = [int(elem) for elem in input().split(" ")]
lst = list1.copy()
# num_zero = 0
# sum = 0
for i in range(len(lst)):
lst[i] = abs(list1[i]-list2[i])
# if lst[i] == 0:
# num_zero += 1... | 3 | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers β the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number β the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1βΓβ1βΓβ1, in the second oneΒ β 2βΓβ2βΓβ3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,607,727,483 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 186 | 0 | import math
A1, A2, A3 = [int(j) for j in input().split()]
a = math.sqrt((A1*A2)/A3)
b = math.sqrt((A1*A3)/A2)
c = math.sqrt((A2*A3)/A1)
print(int(4*a + 4*b + 4*c))
| Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
import math
A1, A2, A3 = [int(j) for j in input().split()]
a = math.sqrt((A1*A2)/A3)
b = math.sqrt((A1*A3)/A2)
c = math.sqrt((A2*A3)/A1)
print(int(4*a + 4*b + 4*c))
``` | 3 | |
18 | C | Stripe | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | C. Stripe | 2 | 64 | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ... | The first input line contains integer *n* (1<=β€<=*n*<=β€<=105) β amount of squares in the stripe. The second line contains *n* space-separated numbers β they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"3\n1 1 1\n",
"2\n0 0\n"
] | [
"3\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "9\n1 5 -6 7 9 -16 0 -2 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "4\n100 1 10 111",
"output": "1"
},
{
"input": "10\n0 4 -3 0 -2 2 -3 -3 2 5",
"output": "3"
},
{
"input": "... | 1,559,410,948 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 404 | 7,680,000 | n = int(input())
arr = list(map(int, input().split()))
prefix_arr = [arr[0]]
for i in range(1, n):
prefix_arr.append(arr[i] + prefix_arr[i - 1])
out = 0
for i in range(n - 1):
if prefix_arr[i] == (prefix_arr[n - 1] - prefix_arr[i]):
out += 1
print(out)
| Title: Stripe
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that ... | ```python
n = int(input())
arr = list(map(int, input().split()))
prefix_arr = [arr[0]]
for i in range(1, n):
prefix_arr.append(arr[i] + prefix_arr[i - 1])
out = 0
for i in range(n - 1):
if prefix_arr[i] == (prefix_arr[n - 1] - prefix_arr[i]):
out += 1
print(out)
``` | 3.84178 |
900 | A | Find Extra One | PROGRAMMING | 800 | [
"geometry",
"implementation"
] | null | null | You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. | The first line contains a single positive integer *n* (2<=β€<=*n*<=β€<=105).
The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=β€<=109, *x**i*<=β <=0). No two points coincide. | Print "Yes" if there is such a point, "No" β otherwise.
You can print every letter in any case (upper or lower). | [
"3\n1 1\n-1 -1\n2 -1\n",
"4\n1 1\n2 2\n-1 1\n-2 2\n",
"3\n1 2\n2 1\n4 60\n"
] | [
"Yes",
"No",
"Yes"
] | In the first example the second point can be removed.
In the second example there is no suitable for the condition point.
In the third example any point can be removed. | 500 | [
{
"input": "3\n1 1\n-1 -1\n2 -1",
"output": "Yes"
},
{
"input": "4\n1 1\n2 2\n-1 1\n-2 2",
"output": "No"
},
{
"input": "3\n1 2\n2 1\n4 60",
"output": "Yes"
},
{
"input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1",
"output": "Yes"
},
{
"input": "2\n1... | 1,579,903,617 | 2,147,483,647 | PyPy 3 | OK | TESTS | 71 | 935 | 10,956,800 | n = int(input())
l1=[]
l2=[]
l3=[]
for i in range(n):
p,q= map(int,input().split())
if(p>0 ):
l1.append([p,q])
if(p<0):
l2.append([p,q])
if(len(l1)>1 and len(l2)>1):
print("No")
else:
print("Yes") | Title: Find Extra One
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
Input Specification:
The first li... | ```python
n = int(input())
l1=[]
l2=[]
l3=[]
for i in range(n):
p,q= map(int,input().split())
if(p>0 ):
l1.append([p,q])
if(p<0):
l2.append([p,q])
if(len(l1)>1 and len(l2)>1):
print("No")
else:
print("Yes")
``` | 3 | |
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen... | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $... | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"... | 1,614,838,300 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 77 | 0 | # Fingerprints
n, m = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
ans = []
for i in a:
if i in b:
ans.append(i)
print(*ans) | Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keyp... | ```python
# Fingerprints
n, m = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
ans = []
for i in a:
if i in b:
ans.append(i)
print(*ans)
``` | 3 | |
779 | B | Weird Rounding | PROGRAMMING | 1,100 | [
"brute force",
"greedy"
] | null | null | Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For example, if *k*<==<=3, in the number 30020 it is enough to delete a single digit (2). In this case, t... | The only line of the input contains two integer numbers *n* and *k* (0<=β€<=*n*<=β€<=2<=000<=000<=000, 1<=β€<=*k*<=β€<=9).
It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. | Print *w* β the required minimal number of digits to erase. After removing the appropriate *w* digits from the number *n*, the result should have a value that is divisible by 10*k*. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). | [
"30020 3\n",
"100 9\n",
"10203049 2\n"
] | [
"1\n",
"2\n",
"3\n"
] | In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. | 1,000 | [
{
"input": "30020 3",
"output": "1"
},
{
"input": "100 9",
"output": "2"
},
{
"input": "10203049 2",
"output": "3"
},
{
"input": "0 1",
"output": "0"
},
{
"input": "0 9",
"output": "0"
},
{
"input": "100 2",
"output": "0"
},
{
"input": "102... | 1,502,051,743 | 2,147,483,647 | Python 3 | OK | TESTS | 161 | 62 | 4,608,000 | def solve(test):
n, k = test.split()
k = int(k)
cnt = 0
rm_cnt = 0
res = []
for d in reversed(n):
if d == '0' and cnt < k:
res.append(d)
cnt += 1
elif cnt >= k:
res.append(d)
else:
rm_cnt += 1
if cnt < k:
return ... | Title: Weird Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For e... | ```python
def solve(test):
n, k = test.split()
k = int(k)
cnt = 0
rm_cnt = 0
res = []
for d in reversed(n):
if d == '0' and cnt < k:
res.append(d)
cnt += 1
elif cnt >= k:
res.append(d)
else:
rm_cnt += 1
if cnt < k:
... | 3 | |
408 | B | Garland | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter.
The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each pie... | The first line contains a non-empty sequence of *n* (1<=β€<=*n*<=β€<=1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color.
The second line contains a non-empty sequence of *m* (1<=β€<=*m*<=β€<=1000) small English letters that correspond to the colors of the ... | Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer. | [
"aaabbac\naabbccac\n",
"a\nz\n"
] | [
"6\n",
"-1"
] | In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.
In the second test sample Vasya cannot mak... | 1,000 | [
{
"input": "aaabbac\naabbccac",
"output": "6"
},
{
"input": "a\nz",
"output": "-1"
},
{
"input": "r\nr",
"output": "1"
},
{
"input": "stnsdn\nndnndsn",
"output": "4"
},
{
"input": "yqfqfp\ntttwtqq",
"output": "-1"
},
{
"input": "zzbbrrtrtzr\ntbbtrrrzr"... | 1,560,943,937 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 170 | 1,740,800 | from collections import Counter
c1 = Counter(input())
c2 = Counter(input())
count = 0
for ch in c2:
if ch not in c1:
print(-1)
exit()
else:
count += min(c1[ch], c2[ch])
print(count)
| Title: Garland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter.... | ```python
from collections import Counter
c1 = Counter(input())
c2 = Counter(input())
count = 0
for ch in c2:
if ch not in c1:
print(-1)
exit()
else:
count += min(c1[ch], c2[ch])
print(count)
``` | 3 | |
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=β€<=*n*<=β€<=100) β the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=β€<=*x**i*,<=*y**i*<=β€<=1000) β the coordinates of the *i*-th snow drift.
Note that the north direction coinΡides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,673,129,265 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 92 | 0 | def dfs(n):
n[2] = True
for s in a:
if not s[2] and (n[0] == s[0] or n[1] == s[1]):
dfs(s)
n = int(input())
a = []
for i in range(n):
x, y = map(int, input().split())
a.append([x, y, False])
rj = 0
for i in a:
if not i[2]:
rj += 1
dfs(i)
print(rj-1)
... | Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha... | ```python
def dfs(n):
n[2] = True
for s in a:
if not s[2] and (n[0] == s[0] or n[1] == s[1]):
dfs(s)
n = int(input())
a = []
for i in range(n):
x, y = map(int, input().split())
a.append([x, y, False])
rj = 0
for i in a:
if not i[2]:
rj += 1
dfs(i)
print(rj-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,480,491,666 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 62 | 0 | a = list(input())
b = list(input())
n = len(b)
l = []
for i in range(n):
if a[i] != b[i]:
l.append("1")
else:
l.append("0")
print(''.join(l))
| 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
a = list(input())
b = list(input())
n = len(b)
l = []
for i in range(n):
if a[i] != b[i]:
l.append("1")
else:
l.append("0")
print(''.join(l))
``` | 3.9845 |
753 | A | Santa Claus and Candies | PROGRAMMING | 1,000 | [
"dp",
"greedy",
"math"
] | null | null | Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. | The only line contains positive integer number *n* (1<=β€<=*n*<=β€<=1000) β number of candies Santa Claus has. | Print to the first line integer number *k* β maximal number of kids which can get candies.
Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*.
If there are many solutions, print any of them. | [
"5\n",
"9\n",
"2\n"
] | [
"2\n2 3\n",
"3\n3 5 1\n",
"1\n2 \n"
] | none | 500 | [
{
"input": "5",
"output": "2\n1 4 "
},
{
"input": "9",
"output": "3\n1 2 6 "
},
{
"input": "2",
"output": "1\n2 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "3",
"output": "2\n1 2 "
},
{
"input": "1000",
"output": "44\n1 2 3 4 5 6 7 8 9 10 ... | 1,560,535,528 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 109 | 0 | n = int(input())
res = []
s = 0
for i in range(1, 10000):
if s + i < n:
res.append(i)
s += i
else:
el = n - s
while el in res:
s -= res[-1]
res = res[:-1]
el = n - s
res.append(n - s)
break
print(len(res))
pr... | Title: Santa Claus and Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer n... | ```python
n = int(input())
res = []
s = 0
for i in range(1, 10000):
if s + i < n:
res.append(i)
s += i
else:
el = n - s
while el in res:
s -= res[-1]
res = res[:-1]
el = n - s
res.append(n - s)
break
print(len... | 3 | |
803 | B | Distances to Zero | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | null | null | You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array. | The first line contains integer *n* (1<=β€<=*n*<=β€<=2Β·105) β length of the array *a*. The second line contains integer elements of the array separated by single spaces (<=-<=109<=β€<=*a**i*<=β€<=109). | Print the sequence *d*0,<=*d*1,<=...,<=*d**n*<=-<=1, where *d**i* is the difference of indices between *i* and nearest *j* such that *a**j*<==<=0. It is possible that *i*<==<=*j*. | [
"9\n2 1 0 3 0 0 3 2 4\n",
"5\n0 1 2 3 4\n",
"7\n5 6 0 1 -2 3 4\n"
] | [
"2 1 0 1 0 0 1 2 3 ",
"0 1 2 3 4 ",
"2 1 0 1 2 3 4 "
] | none | 0 | [
{
"input": "9\n2 1 0 3 0 0 3 2 4",
"output": "2 1 0 1 0 0 1 2 3 "
},
{
"input": "5\n0 1 2 3 4",
"output": "0 1 2 3 4 "
},
{
"input": "7\n5 6 0 1 -2 3 4",
"output": "2 1 0 1 2 3 4 "
},
{
"input": "1\n0",
"output": "0 "
},
{
"input": "2\n0 0",
"output": "0 0 "
... | 1,567,178,994 | 2,147,483,647 | Python 3 | OK | TESTS | 164 | 451 | 23,040,000 | # 803B
import collections
def do():
N = int(input())
nums = [int(i) for i in input().split(" ")]
q = collections.deque()
seen = [0] * N
res = [float('inf')] * N
for i,n in enumerate(nums):
if n == 0:
q.append((i, 0))
seen[i] = 1
while q:
cur, dis = q.p... | Title: Distances to Zero
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the give... | ```python
# 803B
import collections
def do():
N = int(input())
nums = [int(i) for i in input().split(" ")]
q = collections.deque()
seen = [0] * N
res = [float('inf')] * N
for i,n in enumerate(nums):
if n == 0:
q.append((i, 0))
seen[i] = 1
while q:
cur,... | 3 | |
626 | B | Cards | PROGRAMMING | 1,300 | [
"constructive algorithms",
"dp",
"math"
] | null | null | Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adja... | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=200)Β β the total number of cards.
The next line contains a string *s* of length *n* β the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively. | Print a single string of up to three charactersΒ β the possible colors of the final card (using the same symbols as the input) in alphabetical order. | [
"2\nRB\n",
"3\nGRG\n",
"5\nBBBBB\n"
] | [
"G\n",
"BR\n",
"B\n"
] | In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.
In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue car... | 750 | [
{
"input": "2\nRB",
"output": "G"
},
{
"input": "3\nGRG",
"output": "BR"
},
{
"input": "5\nBBBBB",
"output": "B"
},
{
"input": "1\nR",
"output": "R"
},
{
"input": "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBB... | 1,604,686,279 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 156 | 0 | from sys import stdin, stdout
n=int(stdin.readline())
s=stdin.readline()[:-1]
c1=0
c2=0
c3=0
for i in s:
if i=='R':
c1+=1
elif i=='B':
c2+=1
else:
c3+=1
if (c1>0 and c2>0 and c3>0) or (c1>1 and c2>1) or (c1>1 and c3>1) or (c2>1 and c3>1):
print('BGR')
elif c1>0:
if c2>1:
print('GR')
elif... | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors... | ```python
from sys import stdin, stdout
n=int(stdin.readline())
s=stdin.readline()[:-1]
c1=0
c2=0
c3=0
for i in s:
if i=='R':
c1+=1
elif i=='B':
c2+=1
else:
c3+=1
if (c1>0 and c2>0 and c3>0) or (c1>1 and c2>1) or (c1>1 and c3>1) or (c2>1 and c3>1):
print('BGR')
elif c1>0:
if c2>1:
print('G... | 3 | |
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011Β β are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=106). | In the first line print a single integer *k*Β β the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers β the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not... | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201... | 1,447,829,659 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | n=input().rstrip()
ans=[]
while n!="0":
sub=""
for i in n:
if int(i)>=1:
sub+='1'
else:
sub+='0'
ans.append(sub)
n=str(int(n)-int(sub))
print(len(ans))
print(*ans)
| Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011Β β are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Repr... | ```python
n=input().rstrip()
ans=[]
while n!="0":
sub=""
for i in n:
if int(i)>=1:
sub+='1'
else:
sub+='0'
ans.append(sub)
n=str(int(n)-int(sub))
print(len(ans))
print(*ans)
``` | 3 | |
710 | B | Optimal Point on a Line | PROGRAMMING | 1,400 | [
"brute force",
"sortings"
] | null | null | You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. | The first line contains integer *n* (1<=β€<=*n*<=β€<=3Β·105) β the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=β€<=*x**i*<=β€<=109) β the coordinates of the given *n* points. | Print the only integer *x* β the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer. | [
"4\n1 2 3 4\n"
] | [
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "5\n-1 -10 2 6 7",
"output": "2"
},
{
"input": "10\n-68 10 87 22 30 89 82 -97 -52 25",
"output": "22"
},
{
"input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -... | 1,473,258,259 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 327 | 26,009,600 | import math
n = int(input())
T = input()
num = [int(x) for x in T.split()]
num.sort()
p = math.ceil(n / 2)
print(num[p - 1]) | Title: Optimal Point on a Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
Input Specification:
The first line contains integer *n* (1<=β€<=*n*<=... | ```python
import math
n = int(input())
T = input()
num = [int(x) for x in T.split()]
num.sort()
p = math.ceil(n / 2)
print(num[p - 1])
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,679,504,037 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | a=input()
b=0
s=""
for i in a:
if i.isupper():
b+=1
c=int(len(a)/2)
if b>c:
for i in a:
if i.islower():
s+=i.upper()
else:
s+=i
else:
for i in a:
if i.isupper():
s+=i.lower()
else:
s+=i
print(s) | 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()
b=0
s=""
for i in a:
if i.isupper():
b+=1
c=int(len(a)/2)
if b>c:
for i in a:
if i.islower():
s+=i.upper()
else:
s+=i
else:
for i in a:
if i.isupper():
s+=i.lower()
else:
s+=i
print... | 3.977 |
776 | A | A Serial Killer | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=β€<=*n*<=β€<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and t... | Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] | [
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | 500 | [
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\n... | 1,613,632,004 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 62 | 307,200 | n = list(input().split(" "))
num = int(input())
first = f'{n[0]} {n[1]}'
anslist =[first]
for _ in range(num):
newstring = list(input().split(" "))
if(newstring[0] in n):
if(newstring[0] == n[0]):
n[0]=newstring[1]
else:
n[1]=newstring[1]
anslist.append(f'{n[0]} {n[1]}')
for i in anslist:
print(i)
... | Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The... | ```python
n = list(input().split(" "))
num = int(input())
first = f'{n[0]} {n[1]}'
anslist =[first]
for _ in range(num):
newstring = list(input().split(" "))
if(newstring[0] in n):
if(newstring[0] == n[0]):
n[0]=newstring[1]
else:
n[1]=newstring[1]
anslist.append(f'{n[0]} {n[1]}')
for i in anslist:
prin... | 3 | |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* β the number of cupboards in the kitchen (2<=β€<=*n*<=β€<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=β€<=*l**i*,<=*r**i*<=β€<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* β the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,681,234,347 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 124 | 307,200 | n = int(input())
m = [[int(el) for el in input().split()] for i in range(n)]
x = [[i[j] for i in m] for j in range(2)]
print(min(sum(x[0]), n - sum(x[0])) + min(sum(x[1]), n - sum(x[1]))) | Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long... | ```python
n = int(input())
m = [[int(el) for el in input().split()] for i in range(n)]
x = [[i[j] for i in m] for j in range(2)]
print(min(sum(x[0]), n - sum(x[0])) + min(sum(x[1]), n - sum(x[1])))
``` | 3 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=β€<=*n*<=β€<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=β€<=*a**i*<=β€<=105). | Print a single integer β the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2,β2,β2,β2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,674,768,929 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 47 | 93 | 11,264,000 | input()
L=[0]*(100002)
for i in input().split():
L[int(i)]+=int(i)
a,b=0,0
for i in L:
a, b = b, max(b,a+i)
print(b)
| Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
input()
L=[0]*(100002)
for i in input().split():
L[int(i)]+=int(i)
a,b=0,0
for i in L:
a, b = b, max(b,a+i)
print(b)
``` | 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,679,987,045 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 124 | 0 | # -*- coding: utf-8 -*-
"""
Created on Tue Mar 28 12:24:38 2023
@author: Srusty Sahoo
"""
n=int(input())
scores=list(map(int,input().split()))
temp=[scores[0]]
a=0
for i in range(1,n):
if scores[i]>max(temp) or scores[i]<min(temp):
a=a+1
temp.append(scores[i])
print(a) | 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
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 28 12:24:38 2023
@author: Srusty Sahoo
"""
n=int(input())
scores=list(map(int,input().split()))
temp=[scores[0]]
a=0
for i in range(1,n):
if scores[i]>max(temp) or scores[i]<min(temp):
a=a+1
temp.append(scores[i])
print(a)
`... | 3 | |
981 | B | Businessmen Problems | PROGRAMMING | 1,000 | [
"sortings"
] | null | null | Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the ... | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) Β β the number of elements discovered by ChemForces.
The $i$-th of the next $n$ lines contains two integers $a_i$ and $x_i$ ($1 \leq a_i \leq 10^9$, $1 \leq x_i \leq 10^9$) Β β the index of the $i$-th element and the income of its usage on the exhibitio... | Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets. | [
"3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4\n",
"1\n1000000000 239\n3\n14 15\n92 65\n35 89\n"
] | [
"24\n",
"408\n"
] | In the first example ChemForces can choose the set ($3, 7$), while TopChemist can choose ($1, 2, 4$). This way the total income is $(10 + 2) + (4 + 4 + 4) = 24$.
In the second example ChemForces can choose the only element $10^9$, while TopChemist can choose ($14, 92, 35$). This way the total income is $(239) + (15 + ... | 750 | [
{
"input": "3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4",
"output": "24"
},
{
"input": "1\n1000000000 239\n3\n14 15\n92 65\n35 89",
"output": "408"
},
{
"input": "10\n598654597 488228616\n544064902 21923894\n329635457 980089248\n988262691 654502493\n967529230 543358150\n835120075 128123793\... | 1,527,434,873 | 2,273 | Python 3 | OK | TESTS | 33 | 811 | 20,275,200 | # -*- coding: utf - 8 -*-
"""""""""""""""""""""""""""""""""""""""""""""
| author: mr.math - Hakimov Rahimjon |
| e-mail: [emailΒ protected] |
| created: 27.05.2018 20:20 |
"""""""""""""""""""""""""""""""""""""""""""""
# inp = open("input.txt", "r"); input = inp.readline; out = op... | Title: Businessmen Problems
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both... | ```python
# -*- coding: utf - 8 -*-
"""""""""""""""""""""""""""""""""""""""""""""
| author: mr.math - Hakimov Rahimjon |
| e-mail: [emailΒ protected] |
| created: 27.05.2018 20:20 |
"""""""""""""""""""""""""""""""""""""""""""""
# inp = open("input.txt", "r"); input = inp.readline... | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=Γ<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=β€<=<=*n*,<=*m*,<=*a*<=β€<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,689,503,751 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 31 | 0 | n, m, a = map(int, input().split())
if n%a == 0:
l1 = n//a
else:
l1 = n//a+1
if m%a == 0:
l2 = m//a
else:
l2 = m//a+1
print(l1*l2)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n, m, a = map(int, input().split())
if n%a == 0:
l1 = n//a
else:
l1 = n//a+1
if m%a == 0:
l2 = m//a
else:
l2 = m//a+1
print(l1*l2)
``` | 3.9845 |
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=β€<=*n*<=β€<=50) β the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red... | Print a single integer β the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "... | 1,697,945,289 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | n = input()
x = input()
result = 0
for i, char in enumerate(x):
if i > 0:
if char == x[i - 1]:
result += 1
print(result) | Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ... | ```python
n = input()
x = input()
result = 0
for i, char in enumerate(x):
if i > 0:
if char == x[i - 1]:
result += 1
print(result)
``` | 3 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=β€<=<=*n*<=<=β€<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,638,085,716 | 1,716 | PyPy 3-64 | OK | TESTS | 20 | 154 | 2,355,200 | def main():
n = int(input())
scores = {}
rounds = []
for i in range(n):
round = input()
rounds.append(round)
name, val = round.split()
if name in scores:
scores[name] += int(val)
else:
scores[name] = int(val)
max_score =... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
def main():
n = int(input())
scores = {}
rounds = []
for i in range(n):
round = input()
rounds.append(round)
name, val = round.split()
if name in scores:
scores[name] += int(val)
else:
scores[name] = int(val)
m... | 3.905452 |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=β€<=*n*<=β€<=100) β amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,652,864,541 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 4,505,600 | n=int(input())
li=list(map(int,input().split()))
c=d=0
for i in li[:3]:
if i%2!=0:c+=1
else:d+=1
if c>d:
for i in range(n):
if li[i]%2==0: print(i+1)
else:
for i in range(n):
if li[i]%2!=0: print(i+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β t... | ```python
n=int(input())
li=list(map(int,input().split()))
c=d=0
for i in li[:3]:
if i%2!=0:c+=1
else:d+=1
if c>d:
for i in range(n):
if li[i]%2==0: print(i+1)
else:
for i in range(n):
if li[i]%2!=0: print(i+1)
``` | 3.968608 |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibitΒ β the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integerΒ β the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,641,666,085 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | wheel = 'abcdefghijklmnopqrstuvwxyz'
def dist(c1, c2):
d1 = abs(wheel.index(c1) - wheel.index(c2))
return min(d1, 26 - d1)
word=input()
distances = [dist(c1, c2) for (c1, c2) in zip('a' + word, word)]
print(sum(distances))
| Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
wheel = 'abcdefghijklmnopqrstuvwxyz'
def dist(c1, c2):
d1 = abs(wheel.index(c1) - wheel.index(c2))
return min(d1, 26 - d1)
word=input()
distances = [dist(c1, c2) for (c1, c2) in zip('a' + word, word)]
print(sum(distances))
``` | 3 | |
299 | A | Ksusha and Array | PROGRAMMING | 1,000 | [
"brute force",
"number theory",
"sortings"
] | null | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | The first line contains integer *n* (1<=β€<=*n*<=β€<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109) β the array elements. | Print a single integer β the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them. | [
"3\n2 2 4\n",
"5\n2 1 3 1 6\n",
"3\n2 3 5\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 500 | [
{
"input": "3\n2 2 4",
"output": "2"
},
{
"input": "5\n2 1 3 1 6",
"output": "1"
},
{
"input": "3\n2 3 5",
"output": "-1"
},
{
"input": "1\n331358794",
"output": "331358794"
},
{
"input": "5\n506904227 214303304 136194869 838256937 183952885",
"output": "-1"
... | 1,541,932,386 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 312 | 8,089,600 | n=int(input())
l=[int(i) for i in input().split()]
from math import gcd
g=0
for i in l: g=gcd(g,i)
if g in l:
print(g)
else:
print(-1) | Title: Ksusha and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that ... | ```python
n=int(input())
l=[int(i) for i in input().split()]
from math import gcd
g=0
for i in l: g=gcd(g,i)
if g in l:
print(g)
else:
print(-1)
``` | 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,695,649,745 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 62 | 0 | a=list(map(int, input().split('+')))
a.sort()
print(*a,sep='+') | 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
a=list(map(int, input().split('+')))
a.sort()
print(*a,sep='+')
``` | 3 | |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=β€<=*f**i*<=β€<=*n* and *f**i*<=β <=*i*.
We call a love triangle a situation ... | The first line contains a single integer *n* (2<=β€<=*n*<=β€<=5000)Β β the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=β€<=*f**i*<=β€<=*n*, *f**i*<=β <=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output Β«YESΒ» if there is a love triangle consisting of planes on Earth. Otherwise, output Β«NOΒ».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"... | 1,677,342,145 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 16 | 61 | 2,048,000 | n = int(input())
planes = [0] + [int(x) for x in input().split()] + [0]
print("YES") if sum([1 if planes[planes[planes[i]]]==i and planes[i]!=i else 0 for i in range(len(planes))]) >=3 else print("NO")
| Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with ... | ```python
n = int(input())
planes = [0] + [int(x) for x in input().split()] + [0]
print("YES") if sum([1 if planes[planes[planes[i]]]==i and planes[i]!=i else 0 for i in range(len(planes))]) >=3 else print("NO")
``` | 3 | |
732 | C | Sanatorium | PROGRAMMING | 1,200 | [
"binary search",
"constructive algorithms",
"greedy",
"implementation",
"math"
] | null | null | Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes ho... | The only line contains three integers *b*, *d* and *s* (0<=β€<=*b*,<=*d*,<=*s*<=β€<=1018,<=<=*b*<=+<=*d*<=+<=*s*<=β₯<=1)Β β the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium. | Print single integerΒ β the minimum possible number of meals which Vasiliy could have missed during his vacation. | [
"3 2 1\n",
"1 0 0\n",
"1 1 1\n",
"1000000000000000000 0 1000000000000000000\n"
] | [
"1\n",
"0\n",
"0\n",
"999999999999999999\n"
] | In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it,... | 1,500 | [
{
"input": "3 2 1",
"output": "1"
},
{
"input": "1 0 0",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1000000000000000000 0 1000000000000000000",
"output": "999999999999999999"
},
{
"input": "1000 0 0",
"output": "1998"
},
{
"input... | 1,689,428,387 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 83 | 62 | 0 | a=list(map(int,input().split(' ')))
print(sum(max(0,max(a)-x-1)for x in a)) | Title: Sanatorium
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in th... | ```python
a=list(map(int,input().split(' ')))
print(sum(max(0,max(a)-x-1)for x in a))
``` | 3 | |
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | Β«PolygonΒ» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=3000) β the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=3000) β indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
... | 1,615,538,536 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 409,600 | n = int(input())
arr = list(map(int, input().split()))
print(sorted(set(range(1, max(arr)+2)) - set(arr))[0]) | Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Β«PolygonΒ» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the... | ```python
n = int(input())
arr = list(map(int, input().split()))
print(sorted(set(range(1, max(arr)+2)) - set(arr))[0])
``` | 3.960737 |
348 | A | Mafia | PROGRAMMING | 1,600 | [
"binary search",
"math",
"sortings"
] | null | null | One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the min... | The first line contains integer *n* (3<=β€<=*n*<=β€<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109) β the *i*-th number in the list is the number of rounds the *i*-th person wants to play. | In a single line print a single integer β the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3\n3 2 2\n",
"4\n2 2 2 2\n"
] | [
"4\n",
"3\n"
] | You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | 500 | [
{
"input": "3\n3 2 2",
"output": "4"
},
{
"input": "4\n2 2 2 2",
"output": "3"
},
{
"input": "7\n9 7 7 8 8 7 8",
"output": "9"
},
{
"input": "10\n13 12 10 13 13 14 10 10 12 12",
"output": "14"
},
{
"input": "10\n94 96 91 95 99 94 96 92 95 99",
"output": "106"
... | 1,619,879,838 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 310 | 8,806,400 | import math
n = int(input())
x = input().split()
a = []
max = 0
sum = 0
t = 0
for i in range(n):
tmp = int(x[i])
a.append(tmp)
for i in range(n):
sum += a[i]
if a[i] > max:
max = a[i]
t = math.ceil(sum/(n-1))
if t > max:
print(t)
else:
print(max) | Title: Mafia
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a... | ```python
import math
n = int(input())
x = input().split()
a = []
max = 0
sum = 0
t = 0
for i in range(n):
tmp = int(x[i])
a.append(tmp)
for i in range(n):
sum += a[i]
if a[i] > max:
max = a[i]
t = math.ceil(sum/(n-1))
if t > max:
print(t)
else:
print(max)
``` | 3 | |
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"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 loves tickets very much. As we know, each ticket has a number that is a positive integer. It... | The first line contains an even integer *n* (2<=β€<=*n*<=β€<=50) β the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* β the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4ββ β7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
... | 1,622,031,033 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 216 | 0 | n=int(input())
l=input()
rsn=["0","1","2","3","5","6","8","9"]
st=0
for jk in range(0,len(rsn)):
if rsn[jk] in l:
print("NO")
st=1
break
if st==0:
l1=[]
l2=[]
... | Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n=int(input())
l=input()
rsn=["0","1","2","3","5","6","8","9"]
st=0
for jk in range(0,len(rsn)):
if rsn[jk] in l:
print("NO")
st=1
break
if st==0:
l1=[]
l2... | 3 | |
252 | A | Little Xor | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that.
... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230. | Print a single integer β the required maximal *xor* of a segment of consecutive elements. | [
"5\n1 2 1 1 2\n",
"3\n1 2 7\n",
"4\n4 2 4 8\n"
] | [
"3\n",
"7\n",
"14\n"
] | In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one.
The second sample contains only one optimal segment, which contains exactly one array element (element with index three). | 500 | [
{
"input": "5\n1 2 1 1 2",
"output": "3"
},
{
"input": "3\n1 2 7",
"output": "7"
},
{
"input": "4\n4 2 4 8",
"output": "14"
},
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "15"
},
{
"inpu... | 1,610,483,817 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 154 | 307,200 | n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
x = a[i]
b.append(x)
for j in range(i+1,n):
x ^= a[j]
b.append(x)
print(max(b)) | Title: Little Xor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, ... | ```python
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
x = a[i]
b.append(x)
for j in range(i+1,n):
x ^= a[j]
b.append(x)
print(max(b))
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. ... | The single line contains six integers *a*1,<=...,<=*a*6 (0<=β€<=*a**i*<=β€<=1000) β scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β of 3rd, 4th and 5th: team scores are 1β+β3β+β1β=β2β+β1β+β2β=β5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 0 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
... | 1,510,503,088 | 388 | Python 3 | OK | TESTS | 53 | 62 | 0 | A = [int(i) for i in input().split()]
S = sum(A)
A.sort()
def meme(A,S):
if S%2 != 0:
return "NO"
S= S//2
S-=A[5]
for i in range(5):
for j in range(i+1,5):
if A[i]+A[j]==S:
return "YES"
return "NO"
print(meme(A,S))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exac... | ```python
A = [int(i) for i in input().split()]
S = sum(A)
A.sort()
def meme(A,S):
if S%2 != 0:
return "NO"
S= S//2
S-=A[5]
for i in range(5):
for j in range(i+1,5):
if A[i]+A[j]==S:
return "YES"
return "NO"
print(meme(A,S))
... | 3 | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=β€<=*k*<=β€<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=β€<=|*s*|<=β€<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,652,451,522 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | k=int(input())
s=input()
d=dict()
for i in s:
if(i in d):
d[i]+=1
else:
d[i]=1
ans=""
for i in d.keys():
if(d[i]%k!=0):
ans=-1
break
if(ans==-1):
print(-1)
else:
l=""
for i in d.keys():
l+=i*(d[i]//k)
print(l*(len(s)//len(l))) | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
k=int(input())
s=input()
d=dict()
for i in s:
if(i in d):
d[i]+=1
else:
d[i]=1
ans=""
for i in d.keys():
if(d[i]%k!=0):
ans=-1
break
if(ans==-1):
print(-1)
else:
l=""
for i in d.keys():
l+=i*(d[i]//k)
print(l*(len(s)//len(l)))
``` | 3 | |
501 | A | Contest | PROGRAMMING | 900 | [
"implementation"
] | null | null | Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ... | The first line contains four integers *a*, *b*, *c*, *d* (250<=β€<=*a*,<=*b*<=β€<=3500, 0<=β€<=*c*,<=*d*<=β€<=180).
It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). | Output on a single line:
"Misha" (without the quotes), if Misha got more points than Vasya.
"Vasya" (without the quotes), if Vasya got more points than Misha.
"Tie" (without the quotes), if both of them got the same number of points. | [
"500 1000 20 30\n",
"1000 1000 1 1\n",
"1500 1000 176 177\n"
] | [
"Vasya\n",
"Tie\n",
"Misha\n"
] | none | 500 | [
{
"input": "500 1000 20 30",
"output": "Vasya"
},
{
"input": "1000 1000 1 1",
"output": "Tie"
},
{
"input": "1500 1000 176 177",
"output": "Misha"
},
{
"input": "1500 1000 74 177",
"output": "Misha"
},
{
"input": "750 2500 175 178",
"output": "Vasya"
},
{
... | 1,585,580,243 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 140 | 0 | a, b, c, d = map(int, input().split())
f = max(0.3 * a, a - (a / 250) * c)
s = max(0.3 * b, b - (b / 250) * d)
if f > s:
print("Misha")
elif s > f:
print("Vasya")
else:
print("Tie")
| Title: Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t... | ```python
a, b, c, d = map(int, input().split())
f = max(0.3 * a, a - (a / 250) * c)
s = max(0.3 * b, b - (b / 250) * d)
if f > s:
print("Misha")
elif s > f:
print("Vasya")
else:
print("Tie")
``` | 3 | |
899 | A | Splitting in Teams | PROGRAMMING | 800 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of tea... | The first line contains single integer *n* (2<=β€<=*n*<=β€<=2Β·105) β the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) an... | 500 | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
}... | 1,513,514,475 | 315 | Python 3 | OK | TESTS | 67 | 124 | 9,523,200 | input()
L = list(map(int, input().split()))
ans = min(L.count(2), L.count(1))
ans += max(0, (L.count(1) - ans)//3)
print(ans) | Title: Splitting in Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The co... | ```python
input()
L = list(map(int, input().split()))
ans = min(L.count(2), L.count(1))
ans += max(0, (L.count(1) - ans)//3)
print(ans)
``` | 3 | |
688 | B | Lovely Palindromes | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro... | The only line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=10100<=000). | Print the *n*-th even-length palindrome number. | [
"1\n",
"10\n"
] | [
"11\n",
"1001\n"
] | The first 10 even-length palindrome numbers are 11,β22,β33,β... ,β88,β99 and 1001. | 1,000 | [
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "... | 1,690,899,970 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 234 | 512,000 | n = int(input())
# Convert the input number to a string
s = str(n)
# Create the palindrome string
palindrome = s + s[::-1]
print(palindrome)
| Title: Lovely Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is tr... | ```python
n = int(input())
# Convert the input number to a string
s = str(n)
# Create the palindrome string
palindrome = s + s[::-1]
print(palindrome)
``` | 3 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=β€<=*n*<=β€<=100) β amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,674,505,638 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | n = int(input())
l = [int(i) for i in input().split()]
res = []
for x in l:
d = x % 2
res.append(d)
un = 0
eve = 0
for h in res:
if h == 1:
un += 1
else:
eve += 1
if un > eve:
print(res.index(0) + 1)
else:
print(res.index(1) + 1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β t... | ```python
n = int(input())
l = [int(i) for i in input().split()]
res = []
for x in l:
d = x % 2
res.append(d)
un = 0
eve = 0
for h in res:
if h == 1:
un += 1
else:
eve += 1
if un > eve:
print(res.index(0) + 1)
else:
print(res.index(1) + 1)
``` | 3.977 |
305 | B | Continued Fractions | PROGRAMMING | 1,700 | [
"brute force",
"implementation",
"math"
] | null | null | A continued fraction of height *n* is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height *n*. Check if they are equal. | The first line contains two space-separated integers *p*,<=*q* (1<=β€<=*q*<=β€<=*p*<=β€<=1018) β the numerator and the denominator of the first fraction.
The second line contains integer *n* (1<=β€<=*n*<=β€<=90) β the height of the second fraction. The third line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a... | Print "YES" if these fractions are equal and "NO" otherwise. | [
"9 4\n2\n2 4\n",
"9 4\n3\n2 3 1\n",
"9 4\n3\n1 2 4\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5ff92f27aebea2560d99ad61202d20bab5ee5390.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/221368c79c05fc0ecad4e5f7a64f3... | 1,000 | [
{
"input": "9 4\n2\n2 4",
"output": "YES"
},
{
"input": "9 4\n3\n2 3 1",
"output": "YES"
},
{
"input": "9 4\n3\n1 2 4",
"output": "NO"
},
{
"input": "39088169 24157817\n36\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2",
"output": "YES"
},
{
... | 1,368,972,922 | 4,522 | Python 3 | OK | TESTS | 49 | 78 | 102,400 | #!/usr/bin/python3
p, q = tuple(map(int, input().strip().split()))
n = int(input().strip())
a = list(map(int, input().strip().split()))
a.reverse()
def gcd(a, b):
while a:
a, b = b % a, a
return b
g = gcd(p, q)
p, q = p // g, q // g
u, v = 0, 1;
for i in a:
v, u = v * i + u, v
g = gcd(u, v)... | Title: Continued Fractions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A continued fraction of height *n* is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height *n*. Check if they are equal.
In... | ```python
#!/usr/bin/python3
p, q = tuple(map(int, input().strip().split()))
n = int(input().strip())
a = list(map(int, input().strip().split()))
a.reverse()
def gcd(a, b):
while a:
a, b = b % a, a
return b
g = gcd(p, q)
p, q = p // g, q // g
u, v = 0, 1;
for i in a:
v, u = v * i + u, v
g =... | 3 | |
463 | D | Gargari and Permutations | PROGRAMMING | 1,900 | [
"dfs and similar",
"dp",
"graphs",
"implementation"
] | null | null | Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found *k* permutations. Each of them consists of numbers 1,<=2,<=...,<=*n* in some order. Now he should find the length of the longest common subsequence of these permutatio... | The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=1000;Β 2<=β€<=*k*<=β€<=5). Each of the next *k* lines contains integers 1,<=2,<=...,<=*n* in some order β description of the current permutation. | Print the length of the longest common subsequence. | [
"4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3\n"
] | [
"3\n"
] | The answer for the first test sample is subsequence [1, 2, 3]. | 2,000 | [
{
"input": "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3",
"output": "3"
},
{
"input": "6 3\n2 5 1 4 6 3\n5 1 4 3 2 6\n5 4 2 6 3 1",
"output": "3"
},
{
"input": "41 4\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\n22 13 25 24 38 35 2... | 1,622,802,220 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 389 | 7,372,800 | n, k = map(int, input().split())
ra = [[0] * k for _ in range(n)]
for p in range(k):
for i, v in enumerate(map(int, input().split())):
v -= 1
ra[v][p] = i
g = [[] for _ in range(n)]
for u in range(n):
for v in range(n):
if all(x < y for x, y in zip(ra[u], ra[v])):
g... | Title: Gargari and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found *k* permutations. Each of them consists of numbers 1,<=2,... | ```python
n, k = map(int, input().split())
ra = [[0] * k for _ in range(n)]
for p in range(k):
for i, v in enumerate(map(int, input().split())):
v -= 1
ra[v][p] = i
g = [[] for _ in range(n)]
for u in range(n):
for v in range(n):
if all(x < y for x, y in zip(ra[u], ra[v])):
... | 3 | |
494 | A | Treasure | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that th... | The first line of the input contains a string *s* (1<=β€<=|*s*|<=β€<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character. | If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with.
If there are several possible answers, you may output any of them. | [
"(((#)((#)\n",
"()((#((#(#()\n",
"#\n",
"(#)\n"
] | [
"1\n2\n",
"2\n2\n1",
"-1\n",
"-1\n"
] | |*s*| denotes the length of the string *s*. | 500 | [
{
"input": "(((#)((#)",
"output": "1\n2"
},
{
"input": "()((#((#(#()",
"output": "1\n1\n3"
},
{
"input": "#",
"output": "-1"
},
{
"input": "(#)",
"output": "-1"
},
{
"input": "(((((#(#(#(#()",
"output": "1\n1\n1\n5"
},
{
"input": "#))))",
"output":... | 1,597,187,839 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 187 | 26,316,800 | s=input()
array=[]
c=0
for r in s:
if r=='(':c+=1
else:
if r=='#':array.append(1)
c-=1
if c<0:
print(-1)
exit(0)
array[-1]+=c
i=0
c=0
for r in s:
if r=='(':c+=1
else:
if r=='#':
c-=array[i]
i+=1
else:
c-=... | Title: Treasure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open... | ```python
s=input()
array=[]
c=0
for r in s:
if r=='(':c+=1
else:
if r=='#':array.append(1)
c-=1
if c<0:
print(-1)
exit(0)
array[-1]+=c
i=0
c=0
for r in s:
if r=='(':c+=1
else:
if r=='#':
c-=array[i]
i+=1
else:
... | 3 | |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=150) β the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter Β«XΒ»). Thus, there are no empty statements. The operation and th... | Print a single integer β the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,697,705,276 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | n = int(input())
l = 0
for i in range(n):
k = input()
if "++" in k:
l += 1
if "--" in k:
l -= 1
print(l) | Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ incre... | ```python
n = int(input())
l = 0
for i in range(n):
k = input()
if "++" in k:
l += 1
if "--" in k:
l -= 1
print(l)
``` | 3 | |
441 | A | Valera and Antique Items | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfec... | The first line contains two space-separated integers *n*,<=*v* (1<=β€<=*n*<=β€<=50;Β 104<=β€<=*v*<=β€<=106) β the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=β€<=*k**i*<=β€<=50) the number of items of the *i*-th seller. Then go *k**i* space... | In the first line, print integer *p* β the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=β€<=*q**i*<=β€<=*n*) β the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. | [
"3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n",
"3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n"
] | [
"3\n1 2 3\n",
"0\n\n"
] | In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the... | 500 | [
{
"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000",
"output": "3\n1 2 3"
},
{
"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000",
"output": "0"
},
{
"input": "2 100001\n1 895737\n1 541571",
"output": "0"
},
{
"input": "1 1000000\n1 100... | 1,560,401,618 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 109 | 0 | n,v=map(int,input().split())
ans=[]
for i in range(n):
l1=list(map(int,input().split()))
for item in l1[1:]:
if item<v:
ans.append(i+1)
break
print(len(ans))
print(' '.join(str(x) for x in ans)) | Title: Valera and Antique Items
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the... | ```python
n,v=map(int,input().split())
ans=[]
for i in range(n):
l1=list(map(int,input().split()))
for item in l1[1:]:
if item<v:
ans.append(i+1)
break
print(len(ans))
print(' '.join(str(x) for x in ans))
``` | 3 | |
697 | A | Pineapple Incident | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc.
Barney woke up in the morn... | The first and only line of input contains three integers *t*, *s* and *x* (0<=β€<=*t*,<=*x*<=β€<=109, 2<=β€<=*s*<=β€<=109)Β β the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively. | Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output. | [
"3 10 4\n",
"3 10 3\n",
"3 8 51\n",
"3 8 52\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and ... | 500 | [
{
"input": "3 10 4",
"output": "NO"
},
{
"input": "3 10 3",
"output": "YES"
},
{
"input": "3 8 51",
"output": "YES"
},
{
"input": "3 8 52",
"output": "YES"
},
{
"input": "456947336 740144 45",
"output": "NO"
},
{
"input": "33 232603 599417964",
"ou... | 1,687,992,461 | 2,147,483,647 | Python 3 | OK | TESTS | 95 | 46 | 0 | vals = list(map(int, input().split()))
start = vals[0]
interval = vals[1]
time = vals[2]
if time == start:
print("YES")
elif time < interval + start:
print("NO")
else:
diff = time - start
if diff % interval == 0 or diff % interval == 1:
print("YES")
else:
print("NO") | Title: Pineapple Incident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times... | ```python
vals = list(map(int, input().split()))
start = vals[0]
interval = vals[1]
time = vals[2]
if time == start:
print("YES")
elif time < interval + start:
print("NO")
else:
diff = time - start
if diff % interval == 0 or diff % interval == 1:
print("YES")
else:
print... | 3 | |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportio... | The first input line contains a single integer *n* (1<=β€<=*n*<=β€<=100) β the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=β€<=*p**i*<=β€<=100) β the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ... | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39... | 1,684,166,074 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n = int(input())
arr = [int(i) for i in input().split()]
print(sum(arr)/n) | Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*... | ```python
n = int(input())
arr = [int(i) for i in input().split()]
print(sum(arr)/n)
``` | 3 | |
347 | A | Difference Row | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation",
"sortings"
] | null | null | You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.
More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permu... | The first line of the input contains integer *n* (2<=β€<=*n*<=β€<=100). The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (|*a**i*|<=β€<=1000). | Print the required sequence *x*1,<=*x*2,<=...,<=*x**n*. Sequence *x* should be the lexicographically smallest permutation of *a* that corresponds to an arrangement of the largest possible value. | [
"5\n100 -100 50 0 -50\n"
] | [
"100 -50 0 50 -100 \n"
] | In the sample test case, the value of the output arrangement is (100β-β(β-β50))β+β((β-β50)β-β0)β+β(0β-β50)β+β(50β-β(β-β100))β=β200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one.
Sequence *x*<sub class="lower-inde... | 500 | [
{
"input": "5\n100 -100 50 0 -50",
"output": "100 -50 0 50 -100 "
},
{
"input": "10\n764 -367 0 963 -939 -795 -26 -49 948 -282",
"output": "963 -795 -367 -282 -49 -26 0 764 948 -939 "
},
{
"input": "20\n262 -689 -593 161 -678 -555 -633 -697 369 258 673 50 833 737 -650 198 -651 -621 -396 ... | 1,426,072,903 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 92 | 0 | n = int(input())
d = list(map( int, input().strip().split(' ')))
min = min(d)
max = max(d)
d.remove(min)
d.remove(max)
d.sort()
d = list(map(str, d))
print( str(max) + ' ' + ' '.join(d) + ' ' +str(min)) | Title: Difference Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.
More formally, let's denote ... | ```python
n = int(input())
d = list(map( int, input().strip().split(' ')))
min = min(d)
max = max(d)
d.remove(min)
d.remove(max)
d.sort()
d = list(map(str, d))
print( str(max) + ' ' + ' '.join(d) + ' ' +str(min))
``` | 3 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) β the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) β the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,692,878,610 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 60 | 0 | k = 3
valid = []
for i in range(1, 1000):
x = i * 180
if x / k == x // k:
valid.append(x//k)
k += 1
for i in range(int(input())):
if int(input()) in valid:
print('YES')
else:
print('NO') | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
k = 3
valid = []
for i in range(1, 1000):
x = i * 180
if x / k == x // k:
valid.append(x//k)
k += 1
for i in range(int(input())):
if int(input()) in valid:
print('YES')
else:
print('NO')
``` | 3 | |
620 | B | Grandfather Dovletβs calculator | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typi... | The only line contains two integers *a*,<=*b* (1<=β€<=*a*<=β€<=*b*<=β€<=106) β the first and the last number typed by Max. | Print the only integer *a* β the total number of printed segments. | [
"1 3\n",
"10 15\n"
] | [
"12\n",
"39\n"
] | none | 0 | [
{
"input": "1 3",
"output": "12"
},
{
"input": "10 15",
"output": "39"
},
{
"input": "1 100",
"output": "928"
},
{
"input": "100 10000",
"output": "188446"
},
{
"input": "213 221442",
"output": "5645356"
},
{
"input": "1 1000000",
"output": "287333... | 1,492,082,946 | 2,147,483,647 | PyPy 3 | OK | TESTS | 11 | 358 | 92,057,600 | '''input
1 1000000
'''
a, b = map(int, input().split())
s = 0
n = str(list(range(a, b+1)))
d = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
for x in range(10):
s += d[x] * n.count(str(x))
print(s) | Title: Grandfather Dovletβs calculator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](... | ```python
'''input
1 1000000
'''
a, b = map(int, input().split())
s = 0
n = str(list(range(a, b+1)))
d = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
for x in range(10):
s += d[x] * n.count(str(x))
print(s)
``` | 3 | |
735 | A | Ostap and Grasshopper | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The gr... | The first line of the input contains two integers *n* and *k* (2<=β€<=*n*<=β€<=100, 1<=β€<=*k*<=β€<=*n*<=-<=1)Β β the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the correspondi... | If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). | [
"5 2\n#G#T#\n",
"6 1\nT....G\n",
"7 3\nT..#..G\n",
"6 2\n..GT..\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is freeΒ β he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a sin... | 500 | [
{
"input": "5 2\n#G#T#",
"output": "YES"
},
{
"input": "6 1\nT....G",
"output": "YES"
},
{
"input": "7 3\nT..#..G",
"output": "NO"
},
{
"input": "6 2\n..GT..",
"output": "NO"
},
{
"input": "2 1\nGT",
"output": "YES"
},
{
"input": "100 5\nG####.####.###... | 1,565,632,037 | 2,147,483,647 | PyPy 3 | OK | TESTS | 83 | 140 | 0 | n, k = map(int, input().split())
s = input()
if abs(s.find('G') - s.find('T')) % k == 0:
for i in range(min(s.find('G'), s.find('T')), max(s.find('G'), s.find('T')), k):
if s[i] == '#':
print('NO')
exit()
print('YES')
else:
print('NO')
| Title: Ostap and Grasshopper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles.... | ```python
n, k = map(int, input().split())
s = input()
if abs(s.find('G') - s.find('T')) % k == 0:
for i in range(min(s.find('G'), s.find('T')), max(s.find('G'), s.find('T')), k):
if s[i] == '#':
print('NO')
exit()
print('YES')
else:
print('NO')
``` | 3 | |
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,691,833,309 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 1,228,800 | import math
n,l=[int(x) for x in input().split()]
d={}
for _ in range(l):
a,b=input().split()
if len(a)<=len(b):
ans=a
else:
ans=b
d[a]=ans
d[b]=ans
s=list(map(str,input().split()))
for x in s:
print(d[x],end=" ")
| 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
import math
n,l=[int(x) for x in input().split()]
d={}
for _ in range(l):
a,b=input().split()
if len(a)<=len(b):
ans=a
else:
ans=b
d[a]=ans
d[b]=ans
s=list(map(str,input().split()))
for x in s:
print(d[x],end=" ")
``` | 3 | |
399 | A | Pages | PROGRAMMING | 0 | [
"implementation"
] | null | null | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and wh... | The first and the only line contains three integers *n*, *p*, *k* (3<=β€<=*n*<=β€<=100; 1<=β€<=*p*<=β€<=*n*; 1<=β€<=*k*<=β€<=*n*) | Print the proper navigation. Follow the format of the output from the test samples. | [
"17 5 2\n",
"6 5 2\n",
"6 1 2\n",
"6 2 2\n",
"9 6 3\n",
"10 6 3\n",
"8 5 4\n"
] | [
"<< 3 4 (5) 6 7 >> ",
"<< 3 4 (5) 6 ",
"(1) 2 3 >> ",
"1 (2) 3 4 >>",
"<< 3 4 5 (6) 7 8 9",
"<< 3 4 5 (6) 7 8 9 >>",
"1 2 3 4 (5) 6 7 8 "
] | none | 500 | [
{
"input": "17 5 2",
"output": "<< 3 4 (5) 6 7 >> "
},
{
"input": "6 5 2",
"output": "<< 3 4 (5) 6 "
},
{
"input": "6 1 2",
"output": "(1) 2 3 >> "
},
{
"input": "6 2 2",
"output": "1 (2) 3 4 >> "
},
{
"input": "9 6 3",
"output": "<< 3 4 5 (6) 7 8 9 "
},
{... | 1,542,459,011 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 109 | 0 | n,p,k=map(int,input().split())
s=str()
if p-k>1:s+="<< "
for _ in range(max(1,p-k),min(n,p+k)+1):s+=(str(_) if _!=p else"("+str(_)+")")+" "
if p+k<n:s+=">>"
print(s) | Title: Pages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will lo... | ```python
n,p,k=map(int,input().split())
s=str()
if p-k>1:s+="<< "
for _ in range(max(1,p-k),min(n,p+k)+1):s+=(str(_) if _!=p else"("+str(_)+")")+" "
if p+k<n:s+=">>"
print(s)
``` | 3 | |
250 | B | Restoring IPv6 | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons β 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer *n* β the number of records to restore (1<=β€<=*n*<=β€<=100).
Each of the following *n* lines contains a string β the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | [
"6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n"
] | [
"a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n"
] | none | 1,000 | [
{
"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0",
"output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000... | 1,672,306,961 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | n = int(input())
for i in range(n):
s = input().split(':')
if (s[0] == ''):
s[0] = '0'*4
if s[-1] == '':
s[-1] = '0'*4
idx = -1
for i in range(len(s)):
if s[i] == '':
idx = i
break
for i in range(len(s)):
if (len(s[i]) < 4):
... | Title: Restoring IPv6
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons β 8 blocks in total, each block has four hexadecimal digits. He... | ```python
n = int(input())
for i in range(n):
s = input().split(':')
if (s[0] == ''):
s[0] = '0'*4
if s[-1] == '':
s[-1] = '0'*4
idx = -1
for i in range(len(s)):
if s[i] == '':
idx = i
break
for i in range(len(s)):
if (len(s[i]... | 3 | |
658 | A | Bear and Reverse Radewoosh | PROGRAMMING | 800 | [
"implementation"
] | null | null | Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by diff... | The first line contains two integers *n* and *c* (1<=β€<=*n*<=β€<=50,<=1<=β€<=*c*<=β€<=1000)Β β the number of problems and the constant representing the speed of loosing points.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=β€<=*p**i*<=β€<=1000,<=*p**i*<=<<=*p**i*<=+<=1)Β β initial scores.
The third... | Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points. | [
"3 2\n50 85 250\n10 15 25\n",
"3 6\n50 85 250\n10 15 25\n",
"8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n"
] | [
"Limak\n",
"Radewoosh\n",
"Tie\n"
] | In the first sample, there are 3 problems. Limak solves them as follows:
1. Limak spends 10 minutes on the 1-st problem and he gets 50β-β*c*Β·10β=β50β-β2Β·10β=β30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10β+β15β=β25 minutes after the start of the contest. For the 2-nd problem he gets 85... | 500 | [
{
"input": "3 2\n50 85 250\n10 15 25",
"output": "Limak"
},
{
"input": "3 6\n50 85 250\n10 15 25",
"output": "Radewoosh"
},
{
"input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76",
"output": "Tie"
},
{
"input": "4 1\n3 5 6 9\n1 2 4 8",
"output": "Limak"
},
{... | 1,562,334,814 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 124 | 0 | m,n = list(map(int,input().split(' ')))
l1= list(map(int,input().split(' ')))
l2= list(map(int,input().split(' ')))
k1=0
t=0
k2=0
for i in range(m):
t = t+l2[i]
c=l1[i] -n*t
if c>0:
k1=k1+c
i=m-1
t=0
while i>=0:
t = t+l2[i]
c=l1[i]-n*t
if c>0:
k2=k2+c
i=i-... | Title: Bear and Reverse Radewoosh
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-... | ```python
m,n = list(map(int,input().split(' ')))
l1= list(map(int,input().split(' ')))
l2= list(map(int,input().split(' ')))
k1=0
t=0
k2=0
for i in range(m):
t = t+l2[i]
c=l1[i] -n*t
if c>0:
k1=k1+c
i=m-1
t=0
while i>=0:
t = t+l2[i]
c=l1[i]-n*t
if c>0:
k2=k2+c... | 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,499,857,382 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 6,041,600 | import re
Cadena = str(input())
Mayus = re.sub('[^A-Z]','',Cadena)
Minus = re.sub('[^a-z]', '', Cadena)
if(len(Minus)>=len(Mayus)):
print(Cadena.lower())
else:
print(Cadena.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
import re
Cadena = str(input())
Mayus = re.sub('[^A-Z]','',Cadena)
Minus = re.sub('[^a-z]', '', Cadena)
if(len(Minus)>=len(Mayus)):
print(Cadena.lower())
else:
print(Cadena.upper())
``` | 3.950247 |
992 | A | Nastya and an Array | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
- In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to ze... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=105) β the size of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=β€<=*a**i*<=β€<=105) β the elements of the array. | Print a single integer β the minimum number of seconds needed to make all elements of the array equal to zero. | [
"5\n1 1 1 1 1\n",
"3\n2 0 -1\n",
"4\n5 -6 -5 1\n"
] | [
"1\n",
"2\n",
"4\n"
] | In the first example you can add β-β1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add β-β2 on the first second, then the array becomes equal to [0,β0,ββ-β3]. On the second second you can add 3 to the third (the only non-zero) element. | 500 | [
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "3\n2 0 -1",
"output": "2"
},
{
"input": "4\n5 -6 -5 1",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n21794 -79194",
"output": "2"
},
{
"input": "3\n-63526 95085 -5239",
... | 1,544,180,690 | 2,147,483,647 | Python 3 | OK | TESTS | 79 | 170 | 7,372,800 | n=int(input())
l=list(map(int,input().split()))
y=list(set(l))
x=[]
for i in range(len(y)):
if y[i]!=0:
x.append(y[i])
print(len(x)) | Title: Nastya and an Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
- In one second ... | ```python
n=int(input())
l=list(map(int,input().split()))
y=list(set(l))
x=[]
for i in range(len(y)):
if y[i]!=0:
x.append(y[i])
print(len(x))
``` | 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,678,932,280 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 0 | a = list(map(int, input().split()))
b = list(map(int, input().split()))
n = int(input())
total_cups = sum(a)
total_medals = sum(b)
if total_cups % 5 == 0:
shelves_for_cups = total_cups // 5
else:
shelves_for_cups = total_cups // 5 + 1
if total_medals % 10 == 0:
shelves_for_medals = total_medal... | 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
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n = int(input())
total_cups = sum(a)
total_medals = sum(b)
if total_cups % 5 == 0:
shelves_for_cups = total_cups // 5
else:
shelves_for_cups = total_cups // 5 + 1
if total_medals % 10 == 0:
shelves_for_medals = t... | 3 | |
626 | A | Robot Sequence | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L'Β β instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the s... | The first line of the input contains a single positive integer, *n* (1<=β€<=*n*<=β€<=200)Β β the number of commands.
The next line contains *n* characters, each either 'U', 'R', 'D', or 'L'Β β Calvin's source code. | Print a single integerΒ β the number of contiguous substrings that Calvin can execute and return to his starting square. | [
"6\nURLLDR\n",
"4\nDLUU\n",
"7\nRLRLRLR\n"
] | [
"2\n",
"0\n",
"12\n"
] | In the first case, the entire source code works, as well as the "RL" substring in the second and third characters.
Note that, in the third case, the substring "LR" appears three times, and is therefore counted three times to the total result. | 500 | [
{
"input": "6\nURLLDR",
"output": "2"
},
{
"input": "4\nDLUU",
"output": "0"
},
{
"input": "7\nRLRLRLR",
"output": "12"
},
{
"input": "1\nR",
"output": "0"
},
{
"input": "100\nURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDL... | 1,459,461,735 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 4,608,000 | n = int(input())
s = input()
a,b = 0,0
E = [[0,0]]
times = [1]
for i in range(n):
if s[i] == "U":
b += 1
elif s[i] == "R":
a += 1
elif s[i] == "D":
b -= 1
else:
a -= 1
if [a,b] not in E:
E.append([a,b])
times.append(1)
else:
... | Title: Robot Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L'Β β instructions to move a single square up, right, down, or left, respectively... | ```python
n = int(input())
s = input()
a,b = 0,0
E = [[0,0]]
times = [1]
for i in range(n):
if s[i] == "U":
b += 1
elif s[i] == "R":
a += 1
elif s[i] == "D":
b -= 1
else:
a -= 1
if [a,b] not in E:
E.append([a,b])
times.append(1)
el... | 3 | |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*... | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
... | 1,690,908,090 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 62 | 0 |
string = input()
m = ""
for i in string:
if i > m:
m = i
for i in string:
if i == m:
print(i, end="")
| Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ... | ```python
string = input()
m = ""
for i in string:
if i > m:
m = i
for i in string:
if i == m:
print(i, end="")
``` | 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,666,672,196 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | import math
c,d = (int(x) for x in input().split())
def gof(c, d) :
return math.factorial(min(c, d))
print(gof(c, d))
| 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
import math
c,d = (int(x) for x in input().split())
def gof(c, d) :
return math.factorial(min(c, d))
print(gof(c, d))
``` | 3 | |
1,006 | B | Polycarp's Practice | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"sortings"
] | null | null | Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cann... | The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) β the number of problems and the number of days, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2000$) β difficulties of problems in Polycarp's list, in the order they are p... | In the first line of the output print the maximum possible total profit.
In the second line print exactly $k$ positive integers $t_1, t_2, \dots, t_k$ ($t_1 + t_2 + \dots + t_k$ must equal $n$), where $t_j$ means the number of problems Polycarp will solve during the $j$-th day in order to achieve the maximum possible ... | [
"8 3\n5 4 2 6 5 1 9 2\n",
"5 1\n1 1 1 1 1\n",
"4 2\n1 2000 2000 2\n"
] | [
"20\n3 2 3",
"1\n5\n",
"4000\n2 2\n"
] | The first example is described in the problem statement.
In the second example there is only one possible distribution.
In the third example the best answer is to distribute problems in the following way: $[1, 2000], [2000, 2]$. The total profit of this distribution is $2000 + 2000 = 4000$. | 0 | [
{
"input": "8 3\n5 4 2 6 5 1 9 2",
"output": "20\n4 1 3"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "1\n5"
},
{
"input": "4 2\n1 2000 2000 2",
"output": "4000\n2 2"
},
{
"input": "1 1\n2000",
"output": "2000\n1"
},
{
"input": "1 1\n1234",
"output": "1234\n1"
... | 1,612,361,219 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 109 | 2,969,600 | n,k = map(int,input().split())
a = list(map(int,input().split()))
p = sorted(a)
p = p[-k:]
s = sum(p)
print(s)
idx = 0
i = 0
count = 0
ans = []
while len(ans)<k-1:
idx+=1
count+=1
if a[i] in p:
p.remove(a[i])
ans.append(count)
count = 0
i+=1
for i in ans:
p... | Title: Polycarp's Practice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least... | ```python
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = sorted(a)
p = p[-k:]
s = sum(p)
print(s)
idx = 0
i = 0
count = 0
ans = []
while len(ans)<k-1:
idx+=1
count+=1
if a[i] in p:
p.remove(a[i])
ans.append(count)
count = 0
i+=1
for i in a... | 3 | |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed... | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=200<=000)Β β the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i*Β β the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one numberΒ β the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20β+β6β+β4β+β12β=β42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,697,460,496 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 1,091 | 9,216,000 | n=int(input())
sum=0
for i in range(n):
k=input()
if k=='Tetrahedron':sum+=4
elif k=='Cube':sum+=6
elif k=='Octahedron':sum+=8
elif k=='Dodecahedron':sum+=12
else:sum+=20
print(sum) | Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe... | ```python
n=int(input())
sum=0
for i in range(n):
k=input()
if k=='Tetrahedron':sum+=4
elif k=='Cube':sum+=6
elif k=='Octahedron':sum+=8
elif k=='Dodecahedron':sum+=12
else:sum+=20
print(sum)
``` | 3 | |
748 | C | Santa Claus and Robot | PROGRAMMING | 1,400 | [
"constructive algorithms",
"math"
] | null | null | Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of *m* points *p*1,<=*p*2,<=...,<=*p**m* with integer coordinates, do the following: denote its initial location by *p*0. First, the robot will move from *p*0 to *p*1 along one of the shortest paths betwe... | The first line of input contains the only positive integer *n* (1<=β€<=*n*<=β€<=2Β·105) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of *n* letters, each being equal either L, or R, or U, or D. *k*-th letter stands for the direction which Robo... | The only line of input should contain the minimum possible length of the sequence. | [
"4\nRURD\n",
"6\nRRULDD\n",
"26\nRRRULURURUULULLLDLDDRDRDLD\n",
"3\nRLL\n",
"4\nLRLR\n"
] | [
"2\n",
"2\n",
"7\n",
"2\n",
"4\n"
] | The illustrations to the first three tests are given below.
<img class="tex-graphics" src="https://espresso.codeforces.com/832fb8f97a482be815e0f87edde26c9791a0d330.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/119a8ba68772b2c2bf76f2acdc58027f6c5cde1... | 1,500 | [
{
"input": "4\nRURD",
"output": "2"
},
{
"input": "6\nRRULDD",
"output": "2"
},
{
"input": "26\nRRRULURURUULULLLDLDDRDRDLD",
"output": "7"
},
{
"input": "3\nRLL",
"output": "2"
},
{
"input": "4\nLRLR",
"output": "4"
},
{
"input": "5\nLRDLR",
"outpu... | 1,611,800,276 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 140 | 3,993,600 | import sys
input = sys.stdin.readline
'''
'''
start = cur = (0, 0)
steps = 0
result = 0
n = int(input())
for char in input().rstrip():
steps += 1
r, c = cur
sr, sc = start
prev = cur
if char == "R":
c += 1
elif char == "L":
c -= 1
elif char == "U":
r += 1
else... | Title: Santa Claus and Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of *m* points *p*1,<=*p*2,<=...,<=*p**m* with integer coordinates, do the following: denote its i... | ```python
import sys
input = sys.stdin.readline
'''
'''
start = cur = (0, 0)
steps = 0
result = 0
n = int(input())
for char in input().rstrip():
steps += 1
r, c = cur
sr, sc = start
prev = cur
if char == "R":
c += 1
elif char == "L":
c -= 1
elif char == "U":
r += ... | 3 | |
716 | B | Complete the Word | PROGRAMMING | 1,300 | [
"greedy",
"two pointers"
] | null | null | ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not n... | The first and only line of the input contains a single string *s* (1<=β€<=|*s*|<=β€<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember... | If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line.
Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks... | [
"ABC??FGHIJK???OPQR?TUVWXY?\n",
"WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n",
"??????????????????????????\n",
"AABCDEFGHIJKLMNOPQRSTUVW??M\n"
] | [
"ABCDEFGHIJKLMNOPQRZTUVWXYS",
"-1",
"MNBVCXZLKJHGFDSAQPWOEIRUYT",
"-1"
] | In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZT... | 1,000 | [
{
"input": "ABC??FGHIJK???OPQR?TUVWXY?",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO",
"output": "-1"
},
{
"input": "??????????????????????????",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "AABCDEFGHIJKLMNO... | 1,676,951,821 | 2,147,483,647 | Python 3 | OK | TESTS | 115 | 78 | 307,200 | from collections import defaultdict, deque, Counter
from heapq import heapify, heappop, heappush
def main():
t = 1
# t = int(input())
for _ in range(t):
run_test_case()
def run_test_case():
word = input()
if len(word) < 26:
print(-1)
else:
question = 0
... | Title: Complete the Word
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In pa... | ```python
from collections import defaultdict, deque, Counter
from heapq import heapify, heappop, heappush
def main():
t = 1
# t = int(input())
for _ in range(t):
run_test_case()
def run_test_case():
word = input()
if len(word) < 26:
print(-1)
else:
questi... | 3 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=β€<=*n*<=β€<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integerΒ β the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,678,282,103 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 77 | 2,355,200 | """
Since nββ€β100, we can iterate on the place of first 'Q','A' and second 'Q'.
The brute force solution will work in O(n3) time which can surely pass.
If we only iterate on the place of 'A', we can get the number of 'Q' before and after it using prefix sums, and it leads to O(n) solution.
"""
"""
a = input()
... | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
"""
Since nββ€β100, we can iterate on the place of first 'Q','A' and second 'Q'.
The brute force solution will work in O(n3) time which can surely pass.
If we only iterate on the place of 'A', we can get the number of 'Q' before and after it using prefix sums, and it leads to O(n) solution.
"""
"""
a =... | 3 | |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,693,589,462 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 124 | 0 | word = input().lower()
new_word = ""
for letter in word:
if letter in {"a", "i", "u", "e", "o", "y"}:
continue
else:
new_word += "." + letter
print(new_word) | Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
word = input().lower()
new_word = ""
for letter in word:
if letter in {"a", "i", "u", "e", "o", "y"}:
continue
else:
new_word += "." + letter
print(new_word)
``` | 3 | |
56 | A | Bar | PROGRAMMING | 1,000 | [
"implementation"
] | A. Bar | 2 | 256 | According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can chec... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input da... | Print a single number which is the number of people Vasya should check to guarantee the law enforcement. | [
"5\n18\nVODKA\nCOKE\n19\n17\n"
] | [
"2\n"
] | In the sample test the second and fifth clients should be checked. | 500 | [
{
"input": "5\n18\nVODKA\nCOKE\n19\n17",
"output": "2"
},
{
"input": "2\n2\nGIN",
"output": "2"
},
{
"input": "3\nWHISKEY\n3\nGIN",
"output": "3"
},
{
"input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWI... | 1,620,644,860 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 124 | 6,758,400 | n=int(input())
b = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA','VODKA', 'WHISKEY', 'WINE']
c=0
for i in range(n):
a=input()
if a.isdigit():
if int(a)<18:
c+=1
else:
if a in b:
c+=1
print(c) | Title: Bar
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya h... | ```python
n=int(input())
b = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA','VODKA', 'WHISKEY', 'WINE']
c=0
for i in range(n):
a=input()
if a.isdigit():
if int(a)<18:
c+=1
else:
if a in b:
c+=1
print(c)
``` | 3.956411 |
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,686,153,853 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 140 | 7,168,000 | n,m = map(int,input().split())
import sys
wordDict = {}
for _ in range(m):
w1,w2 = input().split()
n1,n2 = len(w1),len(w2)
if n1 <= n2:
wordDict[w1] = w1
else:
wordDict[w1] = w2
c = input().split()
ans=""
for i in range(n):
ans+=wordDict[c[i]]+" "
sys.st... | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
n,m = map(int,input().split())
import sys
wordDict = {}
for _ in range(m):
w1,w2 = input().split()
n1,n2 = len(w1),len(w2)
if n1 <= n2:
wordDict[w1] = w1
else:
wordDict[w1] = w2
c = input().split()
ans=""
for i in range(n):
ans+=wordDict[c[i]]+" "
... | 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,678,665,006 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 436 | 8,089,600 | x=int(input());y=list(map(int,input().split()))
print(y[1]-y[0],y[-1]-y[0])
for i in range(1,x-1):
print(min(y[i]-y[i-1],y[i+1]-y[i]),max(y[-1]-y[i],y[i]-y[0]))
print(y[-1]-y[-2],y[-1]-y[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
x=int(input());y=list(map(int,input().split()))
print(y[1]-y[0],y[-1]-y[0])
for i in range(1,x-1):
print(min(y[i]-y[i-1],y[i+1]-y[i]),max(y[-1]-y[i],y[i]-y[0]))
print(y[-1]-y[-2],y[-1]-y[0])
``` | 3 | |
23 | B | Party | PROGRAMMING | 1,600 | [
"constructive algorithms",
"graphs",
"math"
] | B. Party | 2 | 256 | *n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among those who stayed by the moment of their leaving, did the same.
What is the maximum amo... | The first input line contains one number *t* β amount of tests (1<=β€<=*t*<=β€<=105). Each of the following *t* lines contains one integer number *n* (1<=β€<=*n*<=β€<=105). | For each test output in a separate line one number β the maximum amount of people that could stay in the end. | [
"1\n3\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "1\n3",
"output": "1"
}
] | 1,697,123,010 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 2 | 1,900 | 8,089,600 | t = int(input())
while(t>0):
t-=1
n= int(input())
print(max(0,n-2)) | Title: Party
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among ... | ```python
t = int(input())
while(t>0):
t-=1
n= int(input())
print(max(0,n-2))
``` | 3.509932 |
810 | A | Straight <<A>> | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Noora is a student of one famous high school. It's her final year in schoolΒ β she is going to study in university next year. However, she has to get an Β«AΒ» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, wh... | The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=100,<=1<=β€<=*k*<=β€<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=*k*) denoting marks received by Noora before Leha's hack. | Print a single integerΒ β minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. | [
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] | [
"4",
"3"
] | Consider the first example testcase.
Maximal mark is 10, Noora received two marksΒ β 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10,β10,β10,β10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc... | 500 | [
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 2... | 1,506,185,133 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 62 | 0 | n,k=map(int,input().split(' '))
m=list(map(int,input().split(' ')))
print(max(int((n*k-sum(m))*2-n),0)) | Title: Straight <<A>>
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Noora is a student of one famous high school. It's her final year in schoolΒ β she is going to study in university next year. However, she has to get an Β«AΒ» graduation certificate in order to apply to a prestigious one.
... | ```python
n,k=map(int,input().split(' '))
m=list(map(int,input().split(' ')))
print(max(int((n*k-sum(m))*2-n),0))
``` | 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,661,415,890 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 90 | 62 | 0 | import sys
input = sys.stdin.readline
n = int(input())
x = n * n
if x % 2:
a = (x+1)//2
b = a-1
else:
a = (x+4)//4
b = a-2
if n in [2, 1]:
print(-1)
exit(0)
print(b, a) | 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
import sys
input = sys.stdin.readline
n = int(input())
x = n * n
if x % 2:
a = (x+1)//2
b = a-1
else:
a = (x+4)//4
b = a-2
if n in [2, 1]:
print(-1)
exit(0)
print(b, a)
``` | 3 | |
644 | B | Processing Queries | PROGRAMMING | 1,700 | [
"*special",
"constructive algorithms",
"data structures",
"two pointers"
] | null | null | In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct.
When a query appears server may react in three possible ways:
1. If ser... | The first line of the input contains two integers *n* and *b* (1<=β€<=*n*,<=*b*<=β€<=200<=000)Β β the number of queries and the maximum possible size of the query queue.
Then follow *n* lines with queries descriptions (in chronological order). Each description consists of two integers *t**i* and *d**i* (1<=β€<=*t**i*,<=*d... | Print the sequence of *n* integers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the moment the server will finish to process the *i*-th query (queries are numbered in the order they appear in the input) or <=-<=1 if the corresponding query will be rejected. | [
"5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n",
"4 1\n2 8\n4 8\n10 9\n15 2\n"
] | [
"11 19 -1 21 22 \n",
"10 18 27 -1 \n"
] | Consider the first sample.
1. The server will start to process first query at the moment 2 and will finish to process it at the moment 11. 1. At the moment 4 second query appears and proceeds to the queue. 1. At the moment 10 third query appears. However, the server is still busy with query 1, *b*β=β1 and there is... | 1,000 | [
{
"input": "5 1\n2 9\n4 8\n10 9\n15 2\n19 1",
"output": "11 19 -1 21 22 "
},
{
"input": "4 1\n2 8\n4 8\n10 9\n15 2",
"output": "10 18 27 -1 "
},
{
"input": "1 1\n1000000000 1000000000",
"output": "2000000000 "
},
{
"input": "4 3\n999999996 1000000000\n999999997 1000000000\n99... | 1,458,465,016 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 654 | 29,286,400 | import sys
import collections
n, queue_size = map(int, input().split())
results = [-1 for _ in range(n)]
next_server_free_time = 1
queue = collections.deque()
for idx, line in enumerate(sys.stdin):
t, d = map(int, line.split())
while queue and next_server_free_time <= t:
idx1, d1 = queue.... | Title: Processing Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* ar... | ```python
import sys
import collections
n, queue_size = map(int, input().split())
results = [-1 for _ in range(n)]
next_server_free_time = 1
queue = collections.deque()
for idx, line in enumerate(sys.stdin):
t, d = map(int, line.split())
while queue and next_server_free_time <= t:
idx1, d... | 3 | |
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,659,718,016 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n = int(input())
m = int(input())
lis = []
for i in range(n):
weight = int(input())
lis.append(weight)
lis.sort(reverse = True)
for j in range(len(lis)):
if m <= lis[j]:
print(j + 1)
break
else:
m -= lis[j]
| 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())
m = int(input())
lis = []
for i in range(n):
weight = int(input())
lis.append(weight)
lis.sort(reverse = True)
for j in range(len(lis)):
if m <= lis[j]:
print(j + 1)
break
else:
m -= lis[j]
... | 3 | |
746 | A | Compote | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruitsΒ β ... | The first line contains the positive integer *a* (1<=β€<=*a*<=β€<=1000)Β β the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=β€<=*b*<=β€<=1000)Β β the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=β€<=*c*<=β€<=1000)Β β the number of pears Nikolay has... | Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. | [
"2\n5\n7\n",
"4\n7\n13\n",
"2\n3\n2\n"
] | [
"7\n",
"21\n",
"0\n"
] | In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1β+β2β+β4β=β7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3β+β6β+β12β=β21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | 500 | [
{
"input": "2\n5\n7",
"output": "7"
},
{
"input": "4\n7\n13",
"output": "21"
},
{
"input": "2\n3\n2",
"output": "0"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n4",
"output": "7"
},
{
"input": "1000\n1000\n1000",
"output": "1750"
}... | 1,690,741,351 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 84 | 61 | 0 | a,b,c,ans=int(input()),int(input()),int(input()),0
while a>0 and b>0 and c>0:
a-=1
b-=2
c-=4
if a>=0 and b>=0 and c>=0:
ans+=7
print(ans) | Title: Compote
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exa... | ```python
a,b,c,ans=int(input()),int(input()),int(input()),0
while a>0 and b>0 and c>0:
a-=1
b-=2
c-=4
if a>=0 and b>=0 and c>=0:
ans+=7
print(ans)
``` | 3 | |
333 | A | Secrets | PROGRAMMING | 1,600 | [
"greedy"
] | null | null | Gerald has been selling state secrets at leisure. All the secrets cost the same: *n* marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of o... | The single line contains a single integer *n* (1<=β€<=*n*<=β€<=1017).
Please, do not use the %lld specifier to read or write 64 bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | In a single line print an integer: the maximum number of coins the unlucky buyer could have paid with. | [
"1\n",
"4\n"
] | [
"1\n",
"2\n"
] | In the first test case, if a buyer has exactly one coin of at least 3 marks, then, to give Gerald one mark, he will have to give this coin. In this sample, the customer can not have a coin of one mark, as in this case, he will be able to give the money to Gerald without any change.
In the second test case, if the buye... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "3",
"output": "1"
},
{
"input": "8",
"output": "3"
},
{
"input": "10",
"output": "4"
},
{
"input": "100000000000000000",
"output": "33333333333333334"
},
{
"input... | 1,423,522,587 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 122 | 0 | n, f = int(input()), 3
while n % f == 0:
f *= 3
print(n // f + 1) | Title: Secrets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has been selling state secrets at leisure. All the secrets cost the same: *n* marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations th... | ```python
n, f = int(input()), 3
while n % f == 0:
f *= 3
print(n // f + 1)
``` | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,610,535,185 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 186 | 0 | s = input()
t = input()
print(["NO", "YES"][s == t[::-1]]) | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s = input()
t = input()
print(["NO", "YES"][s == t[::-1]])
``` | 3.9535 |
870 | A | Search for Pretty Integers | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=9) β the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=9) β the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2... | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among t... | 500 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output"... | 1,690,508,641 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 52 | 140 | 0 | n, m = map(int, input().split())
lista_1 = list(map(int, input().split()))
lista_2 = list(map(int, input().split()))
lista = lista_1 + lista_2
lista.sort()
igual = False
dic = {}
for elemento in lista:
if elemento in dic:
dic[elemento] += 1
print(elemento)
igual = True
... | Title: Search for Pretty Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the sm... | ```python
n, m = map(int, input().split())
lista_1 = list(map(int, input().split()))
lista_2 = list(map(int, input().split()))
lista = lista_1 + lista_2
lista.sort()
igual = False
dic = {}
for elemento in lista:
if elemento in dic:
dic[elemento] += 1
print(elemento)
igual = True... | 3 | |
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,585,985,337 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 404 | 1,843,200 | a=input()
a=list(a)
if '0' in a:
i=a.index('0')
a.pop(i)
else:
a.pop(1)
print(*a,sep="")
| 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
a=input()
a=list(a)
if '0' in a:
i=a.index('0')
a.pop(i)
else:
a.pop(1)
print(*a,sep="")
``` | 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,329,296 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | def uppr(string):
return string[0].upper()+string[1:]
string = input()
print(uppr(string)) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
def uppr(string):
return string[0].upper()+string[1:]
string = input()
print(uppr(string))
``` | 3 | |
682 | B | Alyona and Mex | PROGRAMMING | 1,200 | [
"sortings"
] | null | null | Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular,... | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=100<=000)Β β the number of elements in the Alyona's array.
The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109)Β β the elements of the array. | Print one positive integerΒ β the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. | [
"5\n1 3 3 3 6\n",
"2\n2 1\n"
] | [
"5\n",
"3\n"
] | In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements. | 1,000 | [
{
"input": "5\n1 3 3 3 6",
"output": "5"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "1\n1000000000",
"output": "2"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"... | 1,546,149,585 | 2,147,483,647 | Python 3 | OK | TESTS | 127 | 234 | 8,806,400 | n=int(input())
a=sorted([int(x) for x in input().split()])
flag=True
a[0]=1
for i in range(1,n):
if a[i]>a[i-1]:
a[i]=a[i-1]+1
for i in range(1,n):
if a[i]-a[i-1]>1:
print(a[i-1]+1)
flag=False
break
if flag:
print(a[n-1]+1)
| Title: Alyona and Mex
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is small... | ```python
n=int(input())
a=sorted([int(x) for x in input().split()])
flag=True
a[0]=1
for i in range(1,n):
if a[i]>a[i-1]:
a[i]=a[i-1]+1
for i in range(1,n):
if a[i]-a[i-1]>1:
print(a[i-1]+1)
flag=False
break
if flag:
print(a[n-1]+1)
``` | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,594,664,377 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 20,172,800 | [print(sum([1 if (sum(a)+i) % n else 0 for i in range(5)])) for n, a in [(int(input())+1, list(map(int,input().split())))]] | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
[print(sum([1 if (sum(a)+i) % n else 0 for i in range(5)])) for n, a in [(int(input())+1, list(map(int,input().split())))]]
``` | 3 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=β€<=*n*<=β€<=105) β the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,688,380,926 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 62 | 1,331,200 | n = int(input())
c = 0
for i in range(1, n+1):
if (n-i)%i==0:
c+=1
print(c-1) | Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
n = int(input())
c = 0
for i in range(1, n+1):
if (n-i)%i==0:
c+=1
print(c-1)
``` | 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,497,461,509 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 155 | 8,601,600 | a,b,c=[int(i) for i in input().split()]
n=int(input())
x=[int(i) for i in input().split()]
t=0
for i in range(n):
if b==c:
if a<b:
if x[i]<b:
t+=1
elif a>b:
if x[i]>b:
t+=1
else:
if x[i]>b and x[i]<c:
t+=1
... | 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
a,b,c=[int(i) for i in input().split()]
n=int(input())
x=[int(i) for i in input().split()]
t=0
for i in range(n):
if b==c:
if a<b:
if x[i]<b:
t+=1
elif a>b:
if x[i]>b:
t+=1
else:
if x[i]>b and x[i]<c:
... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time,... | The first line contains two integers *a* and *b* (*a*<=β <=*b*,<=1<=β€<=*a*,<=*b*<=β€<=106). | Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency. | [
"3 7\n",
"5 3\n",
"2 3\n"
] | [
"Dasha\n",
"Masha\n",
"Equal\n"
] | Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0,β6], he will go to both girls ... | 0 | [
{
"input": "3 7",
"output": "Dasha"
},
{
"input": "5 3",
"output": "Masha"
},
{
"input": "2 3",
"output": "Equal"
},
{
"input": "31 88",
"output": "Dasha"
},
{
"input": "8 75",
"output": "Dasha"
},
{
"input": "32 99",
"output": "Dasha"
},
{
... | 1,590,189,991 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 218 | 0 | from math import gcd
a, b = (int(x) for x in input().split())
upper = a * b / gcd(a,b)
m, d = upper/b, upper/a
if a < b: d -= 1
else: m -= 1
if d > m: print("Dasha")
elif m > d: print("Masha")
else: print("Equal")
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has so... | ```python
from math import gcd
a, b = (int(x) for x in input().split())
upper = a * b / gcd(a,b)
m, d = upper/b, upper/a
if a < b: d -= 1
else: m -= 1
if d > m: print("Dasha")
elif m > d: print("Masha")
else: print("Equal")
``` | 3 | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=β€<=*n*<=β€<=1000, 1<=β€<=*h*<=β€<=1000)Β β the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integerΒ β the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.
In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,698,849,991 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | nandh=input().split()
manh=input().split()
manhights=[]
wall_h=int(nandh[1])
wideroad=0
for i in manh:
manhights.append(int(i))
for x in manhights:
if x>wall_h:wideroad+=2
else:wideroad+=1
print(wideroad)
| Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
nandh=input().split()
manh=input().split()
manhights=[]
wall_h=int(nandh[1])
wideroad=0
for i in manh:
manhights.append(int(i))
for x in manhights:
if x>wall_h:wideroad+=2
else:wideroad+=1
print(wideroad)
``` | 3 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*Β·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=β€<=<=*k*,<=*w*<=<=β€<=<=1000, 0<=β€<=*n*<=β€<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer β the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,698,042,004 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 15 | 62 | 9,625,600 | arr = list(map(int,input().split()))
k,n,w = arr[0],arr[1],arr[2]
price = sum(list(range(1,w+1))*k)
print("0") if price<n else print(price-n) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*Β·*k* dollars for the *i*-th banana).
He h... | ```python
arr = list(map(int,input().split()))
k,n,w = arr[0],arr[1],arr[2]
price = sum(list(range(1,w+1))*k)
print("0") if price<n else print(price-n)
``` | 3 | |
569 | B | Inventory | PROGRAMMING | 1,200 | [
"greedy",
"math"
] | null | null | Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.
During an audit, you were surprised to find out that the... | The first line contains a single integer *n*Β β the number of items (1<=β€<=*n*<=β€<=105).
The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=105)Β β the initial inventory numbers of the items. | Print *n* numbersΒ β the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them. | [
"3\n1 3 2\n",
"4\n2 2 3 3\n",
"1\n2\n"
] | [
"1 3 2 \n",
"2 1 3 4 \n",
"1 \n"
] | In the first test the numeration is already a permutation, so there is no need to change anything.
In the second test there are two pairs of equal numbers, in each pair you need to replace one number.
In the third test you need to replace 2 by 1, as the numbering should start from one. | 1,000 | [
{
"input": "3\n1 3 2",
"output": "1 3 2 "
},
{
"input": "4\n2 2 3 3",
"output": "2 1 3 4 "
},
{
"input": "1\n2",
"output": "1 "
},
{
"input": "3\n3 3 1",
"output": "3 2 1 "
},
{
"input": "5\n1 1 1 1 1",
"output": "1 2 3 4 5 "
},
{
"input": "5\n5 3 4 4 ... | 1,590,553,326 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 217 | 10,854,400 | n = int(input())
a = [int(x) for x in input().split()]
s = set(a)
exist = set(s)
next = 1
for i in range(n):
if a[i] <= n and a[i] in s:
s.remove(a[i])
else:
while next in exist:
next += 1
a[i] = next
next += 1
print(' '.join(str(x) for x in a)) | Title: Inventory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numb... | ```python
n = int(input())
a = [int(x) for x in input().split()]
s = set(a)
exist = set(s)
next = 1
for i in range(n):
if a[i] <= n and a[i] in s:
s.remove(a[i])
else:
while next in exist:
next += 1
a[i] = next
next += 1
print(' '.join(str(x) for x in a))
``` | 3 | |
369 | A | Valera and Plates | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can... | The first line of the input contains three integers *n*, *m*, *k* (1<=β€<=*n*,<=*m*,<=*k*<=β€<=1000)Β β the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=2). If *a**i* equals one, then on day *i* Val... | Print a single integer β the minimum number of times Valera will need to wash a plate/bowl. | [
"3 1 1\n1 2 1\n",
"4 3 1\n1 1 1 1\n",
"3 1 2\n2 2 2\n",
"8 2 2\n1 2 1 2 1 2 1 2\n"
] | [
"1\n",
"1\n",
"0\n",
"4\n"
] | In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all... | 500 | [
{
"input": "3 1 1\n1 2 1",
"output": "1"
},
{
"input": "4 3 1\n1 1 1 1",
"output": "1"
},
{
"input": "3 1 2\n2 2 2",
"output": "0"
},
{
"input": "8 2 2\n1 2 1 2 1 2 1 2",
"output": "4"
},
{
"input": "2 100 100\n2 2",
"output": "0"
},
{
"input": "1 1 1\... | 1,673,789,168 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 46 | 0 | number, plates_1, plates_2 = (int(i) for i in input().split())
dishes = tuple(input().split())
total = 0
for i in dishes:
if i == '1':
if plates_1 > 0:
plates_1 -= 1
else:
total += 1
else:
if plates_2 > 0:
plates_2 -= 1
elif plate... | Title: Valera and Plates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, ... | ```python
number, plates_1, plates_2 = (int(i) for i in input().split())
dishes = tuple(input().split())
total = 0
for i in dishes:
if i == '1':
if plates_1 > 0:
plates_1 -= 1
else:
total += 1
else:
if plates_2 > 0:
plates_2 -= 1
... | 3 | |
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,631,927,807 | 2,147,483,647 | PyPy 3 | OK | TESTS | 99 | 216 | 21,401,600 | from abc import ABCMeta
import math
A = int(input())
sum = 0
for i in range(2, A):
d = A
while (d >= i) :
sum += d%i
d //= i
sum += d
A -= 2
gcd = math.gcd(A, sum)
print(f'{sum//gcd}/{A//gcd}')
| 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
from abc import ABCMeta
import math
A = int(input())
sum = 0
for i in range(2, A):
d = A
while (d >= i) :
sum += d%i
d //= i
sum += d
A -= 2
gcd = math.gcd(A, sum)
print(f'{sum//gcd}/{A//gcd}')
``` | 3.732546 |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=β€<=*a*,<=*b*,<=*n*<=β€<=100) β the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*,β*b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,674,723,734 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 92 | 0 | from math import gcd
a, b, n = map(int, input().split())
ans = 1
while n > 0:
ans = (ans + 1) % 2
if ans:
n -= gcd(n, b)
else:
n -= gcd(n, a)
print(ans) | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
from math import gcd
a, b, n = map(int, input().split())
ans = 1
while n > 0:
ans = (ans + 1) % 2
if ans:
n -= gcd(n, b)
else:
n -= gcd(n, a)
print(ans)
``` | 3 | |
513 | G3 | Inversions problem | PROGRAMMING | 3,100 | [
"dp"
] | null | null | You are given a permutation of *n* numbers *p*1,<=*p*2,<=...,<=*p**n*. We perform *k* operations of the following type: choose uniformly at random two indices *l* and *r* (*l*<=β€<=*r*) and reverse the order of the elements *p**l*,<=*p**l*<=+<=1,<=...,<=*p**r*. Your task is to find the expected value of the number of in... | The first line of input contains two integers *n* and *k* (1<=β€<=*n*<=β€<=100, 1<=β€<=*k*<=β€<=109). The next line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* β the given permutation. All *p**i* are different and in range from 1 to *n*.
The problem consists of three subproblems. The subproblems have different constr... | Output the answer with absolute or relative error no more than 1*e*<=-<=9. | [
"3 1\n1 2 3\n",
"3 4\n1 3 2\n"
] | [
"0.833333333333333\n",
"1.458333333333334\n"
] | Consider the first sample test. We will randomly pick an interval of the permutation (1,β2,β3) (which has no inversions) and reverse the order of its elements. With probability <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb946338365d9781f7d2e9ec692c26702d0ae3a7.png" style="max-width: 10... | 16 | [
{
"input": "3 1\n1 2 3",
"output": "0.833333333333333"
},
{
"input": "3 4\n1 3 2",
"output": "1.458333333333334"
},
{
"input": "6 1\n4 2 5 1 3 6",
"output": "6.380952380952381"
},
{
"input": "6 2\n1 4 6 5 2 3",
"output": "6.954648526077097"
},
{
"input": "4 4\n2 3... | 1,512,119,586 | 2,147,483,647 | PyPy 3 | OK | TESTS3 | 66 | 1,512 | 32,870,400 | f = lambda: map(int, input().split())
n, k = f()
p = list(f())
r = range
u = [l * l + l >> 1 for l in r(n + 1)]
v = [(i, j) for i in r(n) for j in r(i + 1, n)]
t = [[p[i] > p[j] for j in r(n)] for i in r(n)]
a = [[0] * n for i in r(n)]
b = [[0] * n for i in r(n)]
c = [[0] * n for i in r(n)]
for l in r(m... | Title: Inversions problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a permutation of *n* numbers *p*1,<=*p*2,<=...,<=*p**n*. We perform *k* operations of the following type: choose uniformly at random two indices *l* and *r* (*l*<=β€<=*r*) and reverse the order of the el... | ```python
f = lambda: map(int, input().split())
n, k = f()
p = list(f())
r = range
u = [l * l + l >> 1 for l in r(n + 1)]
v = [(i, j) for i in r(n) for j in r(i + 1, n)]
t = [[p[i] > p[j] for j in r(n)] for i in r(n)]
a = [[0] * n for i in r(n)]
b = [[0] * n for i in r(n)]
c = [[0] * n for i in r(n)]
fo... | 3 | |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=β€<=*n*<=β€<=100) β the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=100) β the number of cookies in the *i*-th bag. | Print in the only line the only number β the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies β 5β+β3β=β8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,585,169,109 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 310 | 0 | n=int(input())
l=list(map(int,input().split()))
s=0
k=0
m=0
for i in l:
s=s+i
if i%2==0:
k+=1
else:
m+=1
if s%2==0:
print(k)
else:
print(m) | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
n=int(input())
l=list(map(int,input().split()))
s=0
k=0
m=0
for i in l:
s=s+i
if i%2==0:
k+=1
else:
m+=1
if s%2==0:
print(k)
else:
print(m)
``` | 3 | |
415 | A | Mashmokh and Lights | PROGRAMMING | 900 | [
"implementation"
] | null | null | Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. If Mashmokh pushes button with index *i*, then each light with index not less than *i* that is still turn... | The first line of the input contains two space-separated integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100), the number of the factory lights and the pushed buttons respectively. The next line contains *m* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**m*Β (1<=β€<=*b**i*<=β€<=*n*).
It is guaranteed that all lights... | Output *n* space-separated integers where the *i*-th number is index of the button that turns the *i*-th light off. | [
"5 4\n4 3 1 2\n",
"5 5\n5 4 3 2 1\n"
] | [
"1 1 3 4 4 \n",
"1 2 3 4 5 \n"
] | In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus bu... | 500 | [
{
"input": "5 4\n4 3 1 2",
"output": "1 1 3 4 4 "
},
{
"input": "5 5\n5 4 3 2 1",
"output": "1 2 3 4 5 "
},
{
"input": "16 11\n8 5 12 10 14 2 6 3 15 9 1",
"output": "1 2 2 2 5 5 5 8 8 8 8 8 8 8 8 8 "
},
{
"input": "79 22\n76 32 48 28 33 44 58 59 1 51 77 13 15 64 49 72 74 21 6... | 1,578,691,299 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 109 | 307,200 | a,b=map(int,input().split())
l=list(map(int,input().split()))
k,c=[],a
for x in l:
if x<=c:
for y in range(c-x+1):k.append(x)
c=x-1
k.reverse()
print(*k) | Title: Mashmokh and Lights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. ... | ```python
a,b=map(int,input().split())
l=list(map(int,input().split()))
k,c=[],a
for x in l:
if x<=c:
for y in range(c-x+1):k.append(x)
c=x-1
k.reverse()
print(*k)
``` | 3 | |
796 | A | Buying A House | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house ... | The first line contains three integers *n*, *m*, and *k* (2<=β€<=*n*<=β€<=100, 1<=β€<=*m*<=β€<=*n*, 1<=β€<=*k*<=β€<=100)Β β the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=... | Print one integerΒ β the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. | [
"5 1 20\n0 27 32 21 19\n",
"7 3 50\n62 0 0 0 99 33 22\n",
"10 5 100\n1 0 1 0 0 0 0 0 1 1\n"
] | [
"40",
"30",
"20"
] | In the first sample, with *k*β=β20 dollars, Zane can buy only house 5. The distance from house *m*β=β1 to house 5 is 10β+β10β+β10β+β10β=β40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m*β=β3 and house 6 are only 30 meters away, while house *m*β=β3 a... | 500 | [
{
"input": "5 1 20\n0 27 32 21 19",
"output": "40"
},
{
"input": "7 3 50\n62 0 0 0 99 33 22",
"output": "30"
},
{
"input": "10 5 100\n1 0 1 0 0 0 0 0 1 1",
"output": "20"
},
{
"input": "5 3 1\n1 1 0 0 1",
"output": "10"
},
{
"input": "5 5 5\n1 0 5 6 0",
"outpu... | 1,691,910,419 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 46 | 0 | n, m, k = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
s = float('inf')
for i in range(n):
if a[i] and a[i] - k <= 0:
s = min(abs(m - (i + 1)), s)
print(10 * s)
| Title: Buying A House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight li... | ```python
n, m, k = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
s = float('inf')
for i in range(n):
if a[i] and a[i] - k <= 0:
s = min(abs(m - (i + 1)), s)
print(10 * s)
``` | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.