contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 11 | title stringclasses 522
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 425k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 14
values | testset stringclasses 12
values | passedTestCount int64 0 1k | timeConsumedMillis int64 0 15k | memoryConsumedBytes int64 0 805M | code stringlengths 3 65.5k | prompt stringlengths 262 8.2k | response stringlengths 17 65.5k | score float64 -1 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,645,989,355 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 264 | 13,516,800 | n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
count = 0
Max = 0
for i in range(2*n):
b[a[i]-1] += 1
if b[a[i]-1] == 2:
count -= 1
elif b[a[i]-1] == 1:
count += 1
Max = max(Max, count)
print(Max) | Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
count = 0
Max = 0
for i in range(2*n):
b[a[i]-1] += 1
if b[a[i]-1] == 2:
count -= 1
elif b[a[i]-1] == 1:
count += 1
Max = max(Max, count)
print(Max)
``` | 3 | |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,694,514,624 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 60 | 0 | a = input()
d = 0
for i in range(len(a)):
if a[i] == 'H' or a[i] == 'Q' or a[i] == '9' or a[i] == '+':
d = d + 1
if d > 0:
print('YES')
else:
print('NO') | Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in... | ```python
a = input()
d = 0
for i in range(len(a)):
if a[i] == 'H' or a[i] == 'Q' or a[i] == '9' or a[i] == '+':
d = d + 1
if d > 0:
print('YES')
else:
print('NO')
``` | 0 | |
656 | D | Rosetta Problem | PROGRAMMING | 2,100 | [
"*special"
] | null | null | The input contains a single integer *a* (0<=≤<=*a*<=≤<=1<=000<=000). | Output a single integer. | [
"129\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "129",
"output": "1"
},
{
"input": "0",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "6",
"output": "0"
},
{
"input": "16",
"output": "0"
},
{
"input": "299593",
"output": "7"
},
{
"input": "398929",
"output":... | 1,609,308,681 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 108 | 0 | n=eval(input())
cnt=0
while n:
a=n%8
n=n//8
if a==1:
cnt+=1
print(cnt) | Title: Rosetta Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains a single integer *a* (0<=≤<=*a*<=≤<=1<=000<=000).
Output Specification:
Output a single integer.
Demo Input:
['129\n']
Demo Output:
['1\n']
Note:
none | ```python
n=eval(input())
cnt=0
while n:
a=n%8
n=n//8
if a==1:
cnt+=1
print(cnt)
``` | 3 | ||
846 | B | Math Show | PROGRAMMING | 1,800 | [
"brute force",
"greedy"
] | null | null | Polycarp takes part in a math show. He is given *n* tasks, each consists of *k* subtasks, numbered 1 through *k*. It takes him *t**j* minutes to solve the *j*-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
... | The first line contains three integer numbers *n*, *k* and *M* (1<=≤<=*n*<=≤<=45, 1<=≤<=*k*<=≤<=45, 0<=≤<=*M*<=≤<=2·109).
The second line contains *k* integer numbers, values *t**j* (1<=≤<=*t**j*<=≤<=1000000), where *t**j* is the time in minutes required to solve *j*-th subtask of any task. | Print the maximum amount of points Polycarp can earn in *M* minutes. | [
"3 4 11\n1 2 3 4\n",
"5 5 10\n1 2 4 8 16\n"
] | [
"6\n",
"7\n"
] | In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of tw... | 0 | [
{
"input": "3 4 11\n1 2 3 4",
"output": "6"
},
{
"input": "5 5 10\n1 2 4 8 16",
"output": "7"
},
{
"input": "1 1 0\n2",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "2"
},
{
"input": "2 1 0\n2",
"output": "0"
},
{
"input": "2 2 2\n2 3",
"outpu... | 1,506,289,852 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n,k,M = map(int, input().split(' '))
t = map(int, input().split(' '))
st_but_long = list(sorted(t))
max_point = 0
for finished_tasks in range(n+1):
iteration_point = 0
remaining_minutes = M
remaining_minutes -= (sum(st_but_long) * finished_tasks)
iteration_point += ((k+1) * finished_tasks)... | Title: Math Show
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp takes part in a math show. He is given *n* tasks, each consists of *k* subtasks, numbered 1 through *k*. It takes him *t**j* minutes to solve the *j*-th subtask of any task. Thus, time required to solve a subtask dep... | ```python
n,k,M = map(int, input().split(' '))
t = map(int, input().split(' '))
st_but_long = list(sorted(t))
max_point = 0
for finished_tasks in range(n+1):
iteration_point = 0
remaining_minutes = M
remaining_minutes -= (sum(st_but_long) * finished_tasks)
iteration_point += ((k+1) * finis... | 0 | |
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,616,772,075 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | l,r,x,y,k=map(int,input().split())
flag=0
while l<=r:
if k%l==0:
if x<=k//l<=y:
flag=1
print("YES")
break
l+=1
if flag==0:
print("NO") | Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
l,r,x,y,k=map(int,input().split())
flag=0
while l<=r:
if k%l==0:
if x<=k//l<=y:
flag=1
print("YES")
break
l+=1
if flag==0:
print("NO")
``` | 0 | |
180 | C | Letter | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to... | The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105. | Print a single number — the least number of actions needed to make the message fancy. | [
"PRuvetSTAaYA\n",
"OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n",
"helloworld\n"
] | [
"5\n",
"0\n",
"0\n"
] | none | 0 | [
{
"input": "PRuvetSTAaYA",
"output": "5"
},
{
"input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA",
"output": "0"
},
{
"input": "helloworld",
"output": "0"
},
{
"input": "P",
"output": "0"
},
{
"input": "t",
"output": "0"
},
{
"input": "XdJ",
"output": "1... | 1,594,886,419 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 280 | 20,172,800 | from sys import stdin
def operations(s):
count = upper = 0
for v in reversed(s):
if v.isupper():
upper += 1
else:
if upper:
count += upper
upper = 0
print(count)
def solution():
input = stdin.readline
s = in... | Title: Letter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them... | ```python
from sys import stdin
def operations(s):
count = upper = 0
for v in reversed(s):
if v.isupper():
upper += 1
else:
if upper:
count += upper
upper = 0
print(count)
def solution():
input = stdin.readline
... | 0 | |
922 | C | Cave Painting | PROGRAMMING | 1,600 | [
"brute force",
"number theory"
] | null | null | Imp is watching a documentary about cave painting.
Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all integers *i* from 1 to *k*. Unfortunately, there are too many integers to analyze for Imp.
Imp wan... | The only line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1018). | Print "Yes", if all the remainders are distinct, and "No" otherwise.
You can print each letter in arbitrary case (lower or upper). | [
"4 4\n",
"5 3\n"
] | [
"No\n",
"Yes\n"
] | In the first sample remainders modulo 1 and 4 coincide. | 1,250 | [
{
"input": "4 4",
"output": "No"
},
{
"input": "5 3",
"output": "Yes"
},
{
"input": "1 1",
"output": "Yes"
},
{
"input": "744 18",
"output": "No"
},
{
"input": "47879 10",
"output": "Yes"
},
{
"input": "1000000000000000000 1000000000000000000",
"ou... | 1,592,633,241 | 2,147,483,647 | PyPy 3 | OK | TESTS | 90 | 155 | 0 | #https://codeforces.com/problemset/problem/922/C
n,k=map(int,input().split())
if k>=n and n!=1:
print('No')
elif n&1==0:
if k==1:
print('Yes')
else:
print('No')
else:
s={}
f=0
for i in range(1,k+1):
if n%i not in s:
s[n%i]=1
else:
f=1
print('No')
break
if not f:
print('Yes')
| Title: Cave Painting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp is watching a documentary about cave painting.
Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all ... | ```python
#https://codeforces.com/problemset/problem/922/C
n,k=map(int,input().split())
if k>=n and n!=1:
print('No')
elif n&1==0:
if k==1:
print('Yes')
else:
print('No')
else:
s={}
f=0
for i in range(1,k+1):
if n%i not in s:
s[n%i]=1
else:
f=1
print('No')
break
if not f:
print('Yes')
``` | 3 | |
225 | E | Unsolvable | PROGRAMMING | 2,100 | [
"math",
"number theory"
] | null | null | Consider the following equation:
Let's find all integer *z* (*z*<=><=0), for which this equation is unsolvable in positive integers. The phrase "unsolvable in positive integers" means that there are no such positive integers *x* and *y* (*x*,<=*y*<=><=0), for which the given above equation holds.
Let's write o... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=40). | Print a single integer — the number *z**n* modulo 1000000007 (109<=+<=7). It is guaranteed that the answer exists. | [
"1\n",
"2\n",
"3\n"
] | [
"1",
"3",
"15"
] | none | 3,000 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "3",
"output": "15"
},
{
"input": "4",
"output": "63"
},
{
"input": "5",
"output": "4095"
},
{
"input": "6",
"output": "65535"
},
{
"input": "7",
"output": "26... | 1,678,628,741 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 7 | 154 | 2,150,400 | n = int(input())
M = 10 ** 9 + 7
ans = [0, 1, 2, 4, 6, 12, 16, 18]
print((2 ** ans[n] - 1) % M)
| Title: Unsolvable
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the following equation:
Let's find all integer *z* (*z*<=><=0), for which this equation is unsolvable in positive integers. The phrase "unsolvable in positive integers" means that there are no such positive int... | ```python
n = int(input())
M = 10 ** 9 + 7
ans = [0, 1, 2, 4, 6, 12, 16, 18]
print((2 ** ans[n] - 1) % M)
``` | -1 | |
459 | B | Pashmak and Flowers | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation",
"sortings"
] | null | null | Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). | The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. | [
"2\n1 2\n",
"3\n1 4 5\n",
"5\n3 1 2 3 1\n"
] | [
"1 1",
"4 1",
"2 4"
] | In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers. | 500 | [
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "3\n1 4 5",
"output": "4 1"
},
{
"input": "5\n3 1 2 3 1",
"output": "2 4"
},
{
"input": "2\n1 1",
"output": "0 1"
},
{
"input": "3\n1 1 1",
"output": "0 3"
},
{
"input": "4\n1 1 1 1",
"output": "0 ... | 1,673,761,973 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 187 | 18,022,400 | input()
b=list(map(int,input().split()))
b.sort()
diff=b[-1]-b[0]
M=b.count(b[-1])
m=b.count(b[0])
if b[-1]>b[0]:
ways=M*m
else:
ways=int((m-1)*m/2)
print(diff,ways) | Title: Pashmak and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have th... | ```python
input()
b=list(map(int,input().split()))
b.sort()
diff=b[-1]-b[0]
M=b.count(b[-1])
m=b.count(b[0])
if b[-1]>b[0]:
ways=M*m
else:
ways=int((m-1)*m/2)
print(diff,ways)
``` | 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,585,371,259 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 0 | s = input()
lo = 'abcdefghijklmnopqrstuvwxyz'
lonum = 0
for c in s:
if(c in lo) : lonum += 1
if(lonum >= len(s) - lonum) : print(s.lower())
else : print(s.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
s = input()
lo = 'abcdefghijklmnopqrstuvwxyz'
lonum = 0
for c in s:
if(c in lo) : lonum += 1
if(lonum >= len(s) - lonum) : print(s.lower())
else : print(s.upper())
``` | 3.93 |
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,657,771,466 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 124 | 0 | f1,f2,f3=map(int,input().split(" "))
import math
vol=4*int(math.sqrt(f1*f2*f3))
print(vol//f1+vol//f2+vol//f3) | 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
f1,f2,f3=map(int,input().split(" "))
import math
vol=4*int(math.sqrt(f1*f2*f3))
print(vol//f1+vol//f2+vol//f3)
``` | 3 | |
817 | E | Choosing The Commander | PROGRAMMING | 2,000 | [
"bitmasks",
"data structures",
"trees"
] | null | null | As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires.
Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and he wants to choose the person who will be respected by warriors.
Ea... | The first line contains one integer *q* (1<=≤<=*q*<=≤<=100000) — the number of events.
Then *q* lines follow. Each line describes the event:
- 1 *p**i* (1<=≤<=*p**i*<=≤<=108) — one warrior with personality *p**i* joins Vova's army; - 2 *p**i* (1<=≤<=*p**i*<=≤<=108) — one warrior with personality *p**i* leaves Vova'... | For each event of the third type print one integer — the number of warriors who respect the commander Vova tries to hire in the event. | [
"5\n1 3\n1 4\n3 6 3\n2 4\n3 6 3\n"
] | [
"1\n0\n"
] | In the example the army consists of two warriors with personalities 3 and 4 after first two events. Then Vova tries to hire a commander with personality 6 and leadership 3, and only one warrior respects him (<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3d8e4cd0a5c3c0cdc8b35097f3dc7317604... | 0 | [
{
"input": "5\n1 3\n1 4\n3 6 3\n2 4\n3 6 3",
"output": "1\n0"
}
] | 1,689,002,959 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 857 | 105,881,600 | from collections import *
from functools import *
from itertools import *
from operator import *
from bisect import *
from heapq import *
import math
import re
import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def I():
return input().decode('utf-8').strip()
def II... | Title: Choosing The Commander
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires.
Vova managed to build a large army, but forgot about the main person in the army - the commande... | ```python
from collections import *
from functools import *
from itertools import *
from operator import *
from bisect import *
from heapq import *
import math
import re
import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def I():
return input().decode('utf-8').strip()
... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,632,209,131 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 124 | 6,963,200 | n = int(input("# of vectors: "))
vectors = []
placeholder = []
for i in range(n):
xi = int(input("x: "))
yi = int(input("y: "))
zi = int(input("z: "))
vectors.append(xi+yi+zi)
for i in vectors:
if i != 0:
placeholder.append(i)
else:
vectors.remove(i)
if vectors[0... | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input("# of vectors: "))
vectors = []
placeholder = []
for i in range(n):
xi = int(input("x: "))
yi = int(input("y: "))
zi = int(input("z: "))
vectors.append(xi+yi+zi)
for i in vectors:
if i != 0:
placeholder.append(i)
else:
vectors.remove(i)
if... | -1 |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,671,647,858 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 |
s=[int(c)for c in input().split()]
f=0
n=0
if s[0]>s[1]:
f=s[1]
n=s[0]-s[1]
else:
f=s[1]
n=s[1]-s[0]
print(f,int(n/2))
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
s=[int(c)for c in input().split()]
f=0
n=0
if s[0]>s[1]:
f=s[1]
n=s[0]-s[1]
else:
f=s[1]
n=s[1]-s[0]
print(f,int(n/2))
``` | 0 | |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,668,411,688 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 11,980,800 | n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(m):
b=int(input())
t=[]
for i in range(b-1,len(a)):
if a[i] not in t:
t.append(a[i])
print(len(t))
| Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(m):
b=int(input())
t=[]
for i in range(b-1,len(a)):
if a[i] not in t:
t.append(a[i])
print(len(t))
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;*m*] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integer point, that belongs each of segments in the picture. Having discovered this fact, Teodo... | First line of input contains two integer numbers: *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100<=000) — amount of segments of Teodor's picture and maximal coordinate of point that Sasha can ask about.
*i*th of next *n* lines contains two integer numbers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*m*) — left and right ends ... | Single line of output should contain one integer number *k* – size of largest set (*x**i*,<=*cnt*(*x**i*)) where all *x**i* are different, 1<=≤<=*x**i*<=≤<=*m*, and *cnt*(*x**i*) is amount of segments, containing point with coordinate *x**i*, such that one can't be sure that there doesn't exist point, belonging to all ... | [
"2 4\n1 2\n3 4\n",
"4 6\n1 3\n2 3\n4 6\n5 6\n"
] | [
"4\n",
"5\n"
] | First example shows situation where Sasha can never be sure that Teodor isn't lying to him, because even if one knows *cnt*(*x*<sub class="lower-index">*i*</sub>) for each point in segment [1;4], he can't distinguish this case from situation Teodor has drawn whole [1;4] segment.
In second example Sasha can ask about 5... | 0 | [
{
"input": "2 4\n1 2\n3 4",
"output": "4"
},
{
"input": "4 6\n1 3\n2 3\n4 6\n5 6",
"output": "5"
},
{
"input": "43 1319\n750 1030\n857 946\n941 1203\n407 1034\n947 1290\n546 585\n630 1201\n72 342\n693 1315\n34 719\n176 1097\n36 931\n198 973\n5 1025\n892 1054\n461 1287\n195 1273\n832 1039... | 1,640,936,446 | 7,006 | PyPy 3-64 | OK | TESTS | 52 | 295 | 147,558,400 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
from collections import defaultdict, deque
from itertools import permutations
p = print
r = range
def I(): return int(input())
def II(): return list(map(int, input().split()))
def S(): return input()[:-1]
def M(n): return [list(map(int, input... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;*m*] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integ... | ```python
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
from collections import defaultdict, deque
from itertools import permutations
p = print
r = range
def I(): return int(input())
def II(): return list(map(int, input().split()))
def S(): return input()[:-1]
def M(n): return [list(map(... | 3 | |
278 | A | Circle Line | PROGRAMMING | 800 | [
"implementation"
] | null | null | The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) —... | Print a single number — the length of the shortest path between stations number *s* and *t*. | [
"4\n2 3 4 9\n1 3\n",
"4\n5 8 2 100\n4 1\n",
"3\n1 1 1\n3 1\n",
"3\n31 41 59\n1 1\n"
] | [
"5\n",
"15\n",
"1\n",
"0\n"
] | In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.
In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15.
In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2.
In the fourth sample the numbers of st... | 500 | [
{
"input": "4\n2 3 4 9\n1 3",
"output": "5"
},
{
"input": "4\n5 8 2 100\n4 1",
"output": "15"
},
{
"input": "3\n1 1 1\n3 1",
"output": "1"
},
{
"input": "3\n31 41 59\n1 1",
"output": "0"
},
{
"input": "5\n16 13 10 30 15\n4 2",
"output": "23"
},
{
"inpu... | 1,587,755,466 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 248 | 307,200 | n=int(input())
l=list(map(int,input().split()))
a,b=list(map(int,input().split()))
t=[]
if a<=b:
s=sum(l[a-1:b-1])
print(s)
else:
s=sum(l[b-1:a-1])
t +=[s]
p=sum(l[a-1:]+l[:b-1])
t +=[p]
print(min(t))
| Title: Circle Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd... | ```python
n=int(input())
l=list(map(int,input().split()))
a,b=list(map(int,input().split()))
t=[]
if a<=b:
s=sum(l[a-1:b-1])
print(s)
else:
s=sum(l[b-1:a-1])
t +=[s]
p=sum(l[a-1:]+l[:b-1])
t +=[p]
print(min(t))
``` | 0 | |
991 | A | If at first you don't succeed... | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them... | The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$). | If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. ... | [
"10 10 5 20\n",
"2 2 0 4\n",
"2 2 2 1\n"
] | [
"5",
"-1",
"-1"
] | The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students... | 500 | [
{
"input": "10 10 5 20",
"output": "5"
},
{
"input": "2 2 0 4",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "-1"
},
{
"input": "98 98 97 100",
"output": "1"
},
{
"input": "1 5 2 10",
"output": "-1"
},
{
"input": "5 1 2 10",
"output": "-1"
}... | 1,587,825,915 | 2,147,483,647 | PyPy 3 | OK | TESTS | 76 | 140 | 0 | a,b,c,n=list(map(int,input().split()))
if n-(a+b-c)>=1 and a>=c and b>=c:
print(n-(a+b-c))
else:
print(-1)
| Title: If at first you don't succeed...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group w... | ```python
a,b,c,n=list(map(int,input().split()))
if n-(a+b-c)>=1 and a>=c and b>=c:
print(n-(a+b-c))
else:
print(-1)
``` | 3 | |
888 | E | Maximum Subsequence | PROGRAMMING | 1,800 | [
"bitmasks",
"divide and conquer",
"meet-in-the-middle"
] | null | null | You are given an array *a* consisting of *n* integers, and additionally an integer *m*. You have to choose some sequence of indices *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b*1<=<<=*b*2<=<<=...<=<<=*b**k*<=≤<=*n*) in such a way that the value of is maximized. Chosen sequence can be empty.
Print the maximum possibl... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=35, 1<=≤<=*m*<=≤<=109).
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum possible value of . | [
"4 4\n5 2 4 1\n",
"3 20\n199 41 299\n"
] | [
"3\n",
"19\n"
] | In the first example you can choose a sequence *b* = {1, 2}, so the sum <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c856546022c2feee13d02a4ec9cd1d361ab3a756.png" style="max-width: 100.0%;max-height: 100.0%;"/> is equal to 7 (and that's 3 after taking it modulo 4).
In the second example... | 0 | [
{
"input": "4 4\n5 2 4 1",
"output": "3"
},
{
"input": "3 20\n199 41 299",
"output": "19"
},
{
"input": "5 10\n47 100 49 2 56",
"output": "9"
},
{
"input": "5 1000\n38361 75847 14913 11499 8297",
"output": "917"
},
{
"input": "10 10\n48 33 96 77 67 59 35 15 14 86"... | 1,689,550,929 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 61 | 0 | n, m=map(int, input().split())
arr=list(map(int, input().split()))
first, second=arr[:n//2], arr[n//2:]
def subsets(nums, m):
max_sums=[0 for i in range(2**(len(nums)))]
for i in range(0, 2**(len(nums))):
bit_count, total=0, 0
for j in range(len(nums)):
if (i & (2**j))!=0... | Title: Maximum Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* consisting of *n* integers, and additionally an integer *m*. You have to choose some sequence of indices *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b*1<=<<=*b*2<=<<=...<=<<=*b**k*<=≤<=*n*... | ```python
n, m=map(int, input().split())
arr=list(map(int, input().split()))
first, second=arr[:n//2], arr[n//2:]
def subsets(nums, m):
max_sums=[0 for i in range(2**(len(nums)))]
for i in range(0, 2**(len(nums))):
bit_count, total=0, 0
for j in range(len(nums)):
if (i & ... | 0 | |
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,587,325,512 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 216 | 307,200 | n = int(input())
l = list(map(int, input().split()))
o = 0
e = 0
g = 0
for i in range(0, 3):
if l[i] % 2 == 0:
e += 1
else:
o += 1
if o == 2:
for i in l:
if i % 2 == 0:
g = l.index(i)
break
else:
for i in l:
if i % 2 != 0:
... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
l = list(map(int, input().split()))
o = 0
e = 0
g = 0
for i in range(0, 3):
if l[i] % 2 == 0:
e += 1
else:
o += 1
if o == 2:
for i in l:
if i % 2 == 0:
g = l.index(i)
break
else:
for i in l:
if i % 2 != 0... | 0 |
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge... | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input... | 1,632,842,426 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 482 | 27,238,400 | from heapq import heappush, heappop
def Dijkstra(graph,source,n):
q = []
dist=[float('inf')]*(n + 1)
visited=[False]*(n + 1)
prev=[-1]*(n + 1)
conn = False
dist[source]=0
heappush(q, (dist[source],source))
while len(q)!=0:
poped=heappop(q)
d=poped[0]
u=poped[1]
... | Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* a... | ```python
from heapq import heappush, heappop
def Dijkstra(graph,source,n):
q = []
dist=[float('inf')]*(n + 1)
visited=[False]*(n + 1)
prev=[-1]*(n + 1)
conn = False
dist[source]=0
heappush(q, (dist[source],source))
while len(q)!=0:
poped=heappop(q)
d=poped[0]
u=... | 3.556058 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,639,085,431 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
string x = "hello";
int y=0;
int count=0;
for(int i=0;i<s.length();i++)
{
if(s[i] == x[y])
{
y++;
count++;
if(count == 5)
break;
}... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
string x = "hello";
int y=0;
int count=0;
for(int i=0;i<s.length();i++)
{
if(s[i] == x[y])
{
y++;
count++;
if(count == 5)
break;... | -1 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,685,762,239 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 31 | 0 | word, hello, i = input(), 'hello', 0
for letter in word:
if i < len(hello) and letter == hello[i]:
i += 1
print('YES' if i == 5 else 'NO')
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
word, hello, i = input(), 'hello', 0
for letter in word:
if i < len(hello) and letter == hello[i]:
i += 1
print('YES' if i == 5 else 'NO')
``` | 3.9845 |
301 | D | Yaroslav and Divisors | PROGRAMMING | 2,200 | [
"data structures"
] | null | null | Yaroslav has an array *p*<==<=*p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*), consisting of *n* distinct integers. Also, he has *m* queries:
- Query number *i* is represented as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The answer to the query *l**i*,<=*r**i* is the number of pairs of... | The first line contains the integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*). The following *m* lines contain Yaroslav's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the answers to Yaroslav's queries in the order they appear in the input.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"1 1\n1\n1 1\n",
"10 9\n1 2 3 4 5 6 7 8 9 10\n1 10\n2 9\n3 8\n4 7\n5 6\n2 2\n9 10\n5 10\n4 10\n"
] | [
"1\n",
"27\n14\n8\n4\n2\n1\n2\n7\n9\n"
] | none | 2,000 | [] | 1,692,075,778 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1692075778.8874342")# 1692075778.8874483 | Title: Yaroslav and Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array *p*<==<=*p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*), consisting of *n* distinct integers. Also, he has *m* queries:
- Query number *i* is represented as a pair of integers *l**i*, *r*... | ```python
print("_RANDOM_GUESS_1692075778.8874342")# 1692075778.8874483
``` | 0 | |
499 | A | Watching a movie | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | You have decided to watch the best moments of some movie. There are two buttons on your player:
1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie... | The first line contains two space-separated integers *n*, *x* (1<=≤<=*n*<=≤<=50, 1<=≤<=*x*<=≤<=105) — the number of the best moments of the movie and the value of *x* for the second button.
The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains tw... | Output a single number — the answer to the problem. | [
"2 3\n5 6\n10 12\n",
"1 1\n1 100000\n"
] | [
"6\n",
"100000\n"
] | In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch th... | 500 | [
{
"input": "2 3\n5 6\n10 12",
"output": "6"
},
{
"input": "1 1\n1 100000",
"output": "100000"
},
{
"input": "10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728",
"output": "53974"
},
{
"input": "1... | 1,617,049,845 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 93 | 0 | n, x = map(int, input().split())
ans = 0
prev = 0
for _ in range(n):
l, r = map(int, input().split())
ans += r - l + 1 + (l - prev - 1) % x
prev = r
print(ans) | Title: Watching a movie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have decided to watch the best moments of some movie. There are two buttons on your player:
1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the pl... | ```python
n, x = map(int, input().split())
ans = 0
prev = 0
for _ in range(n):
l, r = map(int, input().split())
ans += r - l + 1 + (l - prev - 1) % x
prev = r
print(ans)
``` | 3 | |
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,559,379,592 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 109 | 0 | # import sys
# sys.stdin=open("input.in",'r')
# sys.stdout=open("out.out",'w')
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=min(a)
y=min(b)
s=100
for i in range(n):
if a[i] in b:
s=min(s,a[i])
if s==100:
s=min(x,y)*10+max(x,y)
print(s) | 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
# import sys
# sys.stdin=open("input.in",'r')
# sys.stdout=open("out.out",'w')
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=min(a)
y=min(b)
s=100
for i in range(n):
if a[i] in b:
s=min(s,a[i])
if s==100:
s=min(x,y)*10+max(x,y)
print(s)
... | 3 | |
474 | D | Flowers | PROGRAMMING | 1,700 | [
"dp"
] | null | null | We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty... | Input contains several test cases.
The first line contains two integers *t* and *k* (1<=≤<=*t*,<=*k*<=≤<=105), where *t* represents the number of test cases.
The next *t* lines contain two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=105), describing the *i*-th test. | Print *t* lines to the standard output. The *i*-th line should contain the number of ways in which Marmot can eat between *a**i* and *b**i* flowers at dinner modulo 1000000007 (109<=+<=7). | [
"3 2\n1 3\n2 3\n4 4\n"
] | [
"6\n5\n5\n"
] | - For *K* = 2 and length 1 Marmot can eat (*R*). - For *K* = 2 and length 2 Marmot can eat (*RR*) and (*WW*). - For *K* = 2 and length 3 Marmot can eat (*RRR*), (*RWW*) and (*WWR*). - For *K* = 2 and length 4 Marmot can eat, for example, (*WWWW*) or (*RWWR*), but for example he can't eat (*WWWR*). | 2,000 | [
{
"input": "3 2\n1 3\n2 3\n4 4",
"output": "6\n5\n5"
},
{
"input": "1 1\n1 3",
"output": "14"
},
{
"input": "1 2\n64329 79425",
"output": "0"
}
] | 1,676,398,069 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 46 | 512,000 | def calculate(n, k):
if n <= 0: return 1
sum = 0
if n >= k:
sum += calculate(n-k, k)
sum += calculate(n-1, k)
return sum
def main():
t, k = map(int, input().split())
while t:
t-=1
a, b = map(int, input().split())
ans = 0
for i in range(a... | Title: Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequenc... | ```python
def calculate(n, k):
if n <= 0: return 1
sum = 0
if n >= k:
sum += calculate(n-k, k)
sum += calculate(n-1, k)
return sum
def main():
t, k = map(int, input().split())
while t:
t-=1
a, b = map(int, input().split())
ans = 0
for i ... | -1 | |
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,626,983,499 | 2,147,483,647 | Python 3 | OK | TESTS | 84 | 77 | 6,758,400 | L = int(input())
A = int(input())
P = int(input())
x = min(L, A//2, P//4)
print(x*7) | 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
L = int(input())
A = int(input())
P = int(input())
x = min(L, A//2, P//4)
print(x*7)
``` | 3 | |
182 | D | Common Divisors | PROGRAMMING | 1,400 | [
"brute force",
"hashing",
"implementation",
"math",
"strings"
] | null | null | Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.
String *a* is the divisor of string *b* if and only if there exists a positive integer *x* such that if we write out string *a* consecutively *x* times, we get string *b*. For exam... | The first input line contains a non-empty string *s*1.
The second input line contains a non-empty string *s*2.
Lengths of strings *s*1 and *s*2 are positive and do not exceed 105. The strings only consist of lowercase Latin letters. | Print the number of common divisors of strings *s*1 and *s*2. | [
"abcdabcd\nabcdabcdabcdabcd\n",
"aaa\naa\n"
] | [
"2\n",
"1\n"
] | In first sample the common divisors are strings "abcd" and "abcdabcd".
In the second sample the common divisor is a single string "a". String "aa" isn't included in the answer as it isn't a divisor of string "aaa". | 1,000 | [
{
"input": "abcdabcd\nabcdabcdabcdabcd",
"output": "2"
},
{
"input": "aaa\naa",
"output": "1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "3"
},
{
"input": "aaaaaaaaaaaaaa\naaaaaaaaaaaaaa",
"output": "4"
},
{
"input": "a\nb",
... | 1,529,260,840 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 1,024,000 |
s1 = input()
s2 = input()
d1 = []
for i in range(0,len(s1)):
x = s1[0:i+1]
if (x*(len(s1)//len(x)) == s1):
d1.append(x)
d2 = []
for i in range(0,len(s2)):
x = s2[0:i+1]
if (x*(len(s2)//len(x)) == s2):
d2.append(x)
c = 0
for x in d1:
if x in d2:
c ... | Title: Common Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.
String *a* is the divisor of string *b* if and only if there exists a positive ... | ```python
s1 = input()
s2 = input()
d1 = []
for i in range(0,len(s1)):
x = s1[0:i+1]
if (x*(len(s1)//len(x)) == s1):
d1.append(x)
d2 = []
for i in range(0,len(s2)):
x = s2[0:i+1]
if (x*(len(s2)//len(x)) == s2):
d2.append(x)
c = 0
for x in d1:
if x in d2:
... | 0 | |
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer — the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
... | 1,614,605,183 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 154 | 0 | n, k = [int(i) for i in input().split()]
lst = [i for i in input().split()]
count = 0
for i in range(n):
count += 1 if lst[i].count('4') + lst[i].count('7') <= k else 0
print(count)
| Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits... | ```python
n, k = [int(i) for i in input().split()]
lst = [i for i in input().split()]
count = 0
for i in range(n):
count += 1 if lst[i].count('4') + lst[i].count('7') <= k else 0
print(count)
``` | 3 | |
304 | A | Pythagorean Theorem II | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the s... | The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. | Print a single integer — the answer to the problem. | [
"5\n",
"74\n"
] | [
"1\n",
"35\n"
] | none | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "74",
"output": "35"
},
{
"input": "1000",
"output": "881"
},
{
"input": "586",
"output": "472"
},
{
"input": "2",
"output": "0"
},
{
"input": "362",
"output": "258"
},
{
"input": "778",
"outp... | 1,632,028,438 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 872 | 21,708,800 | from math import *
n = int(input())
s = 0
for i in range(5,n+1):
for j in range(1,i):
u = i*i - j*j
if(sqrt(u) == int(sqrt(u))):
s += 1
print(s//2) | Title: Pythagorean Theorem II
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the squar... | ```python
from math import *
n = int(input())
s = 0
for i in range(5,n+1):
for j in range(1,i):
u = i*i - j*j
if(sqrt(u) == int(sqrt(u))):
s += 1
print(s//2)
``` | 3 | |
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,688,122,196 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | import math
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
def game_winner(a, b, n):
player_turn = 0 # 0 for Simon, 1 for Antisimon
stones_left = n
while stones_left > 0:
gcd_value = gcd(a if player_turn == 0 else b, stones_left)
if gcd_value > stones_left... | 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
import math
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
def game_winner(a, b, n):
player_turn = 0 # 0 for Simon, 1 for Antisimon
stones_left = n
while stones_left > 0:
gcd_value = gcd(a if player_turn == 0 else b, stones_left)
if gcd_value > s... | 0 | |
777 | B | Game of Credit Cards | PROGRAMMING | 1,300 | [
"data structures",
"dp",
"greedy",
"sortings"
] | null | null | After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on the... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use.
The second line contains *n* digits — Sherlock's credit card number.
The third line contains *n* digits — Moriarty's credit card number. | First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty. | [
"3\n123\n321\n",
"2\n88\n00\n"
] | [
"0\n2\n",
"2\n0\n"
] | First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks. | 1,000 | [
{
"input": "3\n123\n321",
"output": "0\n2"
},
{
"input": "2\n88\n00",
"output": "2\n0"
},
{
"input": "1\n4\n5",
"output": "0\n1"
},
{
"input": "1\n8\n7",
"output": "1\n0"
},
{
"input": "2\n55\n55",
"output": "0\n0"
},
{
"input": "3\n534\n432",
"out... | 1,488,089,577 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main () {
int n;
string a, b;
cin>>n;
cin>>a>>b;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int j = n-1;
for (int i = n-1; i >= 0; i--)
if (b[j] >... | Title: Game of Credit Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simpl... | ```python
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main () {
int n;
string a, b;
cin>>n;
cin>>a>>b;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int j = n-1;
for (int i = n-1; i >= 0; i--)
... | -1 | |
447 | A | DZY Loves Hash | PROGRAMMING | 800 | [
"implementation"
] | null | null | DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==... | The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109). | Output a single integer — the answer to the problem. | [
"10 5\n0\n21\n53\n41\n53\n",
"5 5\n0\n1\n2\n3\n4\n"
] | [
"4\n",
"-1\n"
] | none | 500 | [
{
"input": "10 5\n0\n21\n53\n41\n53",
"output": "4"
},
{
"input": "5 5\n0\n1\n2\n3\n4",
"output": "-1"
},
{
"input": "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537",
"output": "4"
},
{
"input": "2 2\n788371161\n801743052",
"output": "-1"
},
{
... | 1,602,776,265 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 108 | 0 | p, n = map(int, input().split())
b = list()
for i in range(n):
a = int(input())
if a%p in b:
print(i+1)
exit(0)
else:
b.append(a%p)
print(-1) | Title: DZY Loves Hash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbere... | ```python
p, n = map(int, input().split())
b = list()
for i in range(n):
a = int(input())
if a%p in b:
print(i+1)
exit(0)
else:
b.append(a%p)
print(-1)
``` | 3 | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,687,868,216 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 93 | 0 | a,b = [int(x) for x in input().split()]
time = a
rem = a
while a>0:
a = rem//b
rem = rem%b
time = time + a
rem = rem + a
print(time) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
a,b = [int(x) for x in input().split()]
time = a
rem = a
while a>0:
a = rem//b
rem = rem%b
time = time + a
rem = rem + a
print(time)
``` | 3 | |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,689,515,959 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 154 | 0 | s = list(input().split())
s1 = set(s)
print(4-len(s1)) | Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
s = list(input().split())
s1 = set(s)
print(4-len(s1))
``` | 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,662,271,858 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n,m,a=map(int,input().rstrip().split())
sq=(n//a+(n%a!=0))*(m//a+(m%a!=0))
print(sq) | 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().rstrip().split())
sq=(n//a+(n%a!=0))*(m//a+(m%a!=0))
print(sq)
``` | 3.977 |
446 | A | DZY Loves Sequences | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"two pointers"
] | null | null | DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment.
Your task is to find the longest subsegment of *a*, such that it is possible ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | [
"6\n7 2 3 1 5 6\n"
] | [
"5\n"
] | You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4. | 500 | [
{
"input": "6\n7 2 3 1 5 6",
"output": "5"
},
{
"input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422",
"output": "9"
},
{
"input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 1... | 1,406,049,587 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 61 | 0 | import sys
#Length of the sequence
sequenceLength = int(sys.stdin.readline())
#populate sequence
sequence = list(map(int, sys.stdin.readline().split()))
ans = 0
leftList = [1] * sequenceLength
rightlist = [1] * sequenceLength
for i in range(1, sequenceLength):
if sequence[i - 1] < sequence[i]:
leftList[i] +... | Title: DZY Loves Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the... | ```python
import sys
#Length of the sequence
sequenceLength = int(sys.stdin.readline())
#populate sequence
sequence = list(map(int, sys.stdin.readline().split()))
ans = 0
leftList = [1] * sequenceLength
rightlist = [1] * sequenceLength
for i in range(1, sequenceLength):
if sequence[i - 1] < sequence[i]:
lef... | 0 | |
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ... | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1... | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "1010110111100100001010010001101010110111001011011... | 1,649,040,253 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | og = input()
nums = []
ans = ""
for i in range(10):
number = input()
nums[i] = number
for i in range(0, len(og), 10):
ans += nums[og[i:i + 10]]
print(ans) | Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff a... | ```python
og = input()
nums = []
ans = ""
for i in range(10):
number = input()
nums[i] = number
for i in range(0, len(og), 10):
ans += nums[og[i:i + 10]]
print(ans)
``` | -1 |
431 | C | k-Tree | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"trees"
] | null | null | Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes... | A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*). | Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"3 3 2\n",
"3 3 3\n",
"4 3 2\n",
"4 5 2\n"
] | [
"3\n",
"1\n",
"6\n",
"7\n"
] | none | 1,500 | [
{
"input": "3 3 2",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 3 2",
"output": "6"
},
{
"input": "4 5 2",
"output": "7"
},
{
"input": "28 6 3",
"output": "110682188"
},
{
"input": "5 100 1",
"output": "16"
},
{
"inp... | 1,660,578,951 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 77 | 3,481,600 | MOD = int(1e9 + 7)
def solve():
n, k, d = map(int, input().split())
dp = []
dp2 = []
for _ in range(n + 1):
dp.append([0 for __ in range(n + 1)])
dp2.append([0 for __ in range(n + 1)])
dp[0][0] = 1
ans = 0
for i in range(1, n + 1):
for j in range(1,... | Title: k-Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex ... | ```python
MOD = int(1e9 + 7)
def solve():
n, k, d = map(int, input().split())
dp = []
dp2 = []
for _ in range(n + 1):
dp.append([0 for __ in range(n + 1)])
dp2.append([0 for __ in range(n + 1)])
dp[0][0] = 1
ans = 0
for i in range(1, n + 1):
for j i... | 3 | |
814 | B | An express train to reveries | PROGRAMMING | 1,300 | [
"constructive algorithms"
] | null | null | Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.
On that night, Sengoku constructed a permutation *p*1,<=*p*2,<=...,<=*p**n* of intege... | The first line of input contains a positive integer *n* (2<=≤<=*n*<=≤<=1<=000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of colours in the firs... | Output *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n*, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them.
Input guarantees that such permutation exists. | [
"5\n1 2 3 4 3\n1 2 5 4 5\n",
"5\n4 4 2 3 1\n5 4 5 3 1\n",
"4\n1 1 3 4\n1 4 3 4\n"
] | [
"1 2 5 4 3\n",
"5 4 2 3 1\n",
"1 2 3 4\n"
] | In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.
In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints. | 1,000 | [
{
"input": "5\n1 2 3 4 3\n1 2 5 4 5",
"output": "1 2 5 4 3"
},
{
"input": "5\n4 4 2 3 1\n5 4 5 3 1",
"output": "5 4 2 3 1"
},
{
"input": "4\n1 1 3 4\n1 4 3 4",
"output": "1 2 3 4"
},
{
"input": "10\n1 2 3 4 7 6 7 8 9 10\n1 2 3 4 5 6 5 8 9 10",
"output": "1 2 3 4 5 6 7 8 9... | 1,496,862,819 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 77 | 409,600 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# generate all 4 possibilities
dupa = []
dupb = []
for i in range(len(a)):
try:
index = a[i+1:].index(a[i])
dupa.append(i)
dupa.append(index+i+1)
break
except ValueError:
... | Title: An express train to reveries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her... | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# generate all 4 possibilities
dupa = []
dupb = []
for i in range(len(a)):
try:
index = a[i+1:].index(a[i])
dupa.append(i)
dupa.append(index+i+1)
break
except Val... | 3 | |
592 | C | The Big Race | PROGRAMMING | 1,800 | [
"math"
] | null | null | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While ... | The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. | Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*. | [
"10 3 2\n",
"7 1 2\n"
] | [
"3/10\n",
"3/7\n"
] | In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | 1,500 | [
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
... | 1,446,315,332 | 6,332 | Python 3 | WRONG_ANSWER | PRETESTS | 7 | 46 | 0 | data = input().split()
t = int(data[0])
w = int(data[1])
v = int(data[2])
mini = min(v, w)
largest = max(v,w)
q = mini - 1
if (largest%mini != 0):
largest = v*w
z = int(t/largest)
if z!= 0:
q += (z -1)*mini
q += max(min(t - largest, mini), 1)
a = q
b = t
while a!=0 and b!=0:
if a > b:
... | Title: The Big Race
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the... | ```python
data = input().split()
t = int(data[0])
w = int(data[1])
v = int(data[2])
mini = min(v, w)
largest = max(v,w)
q = mini - 1
if (largest%mini != 0):
largest = v*w
z = int(t/largest)
if z!= 0:
q += (z -1)*mini
q += max(min(t - largest, mini), 1)
a = q
b = t
while a!=0 and b!=0:
if a >... | 0 | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,655,911,890 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 92 | 0 | n = int(input())
b = input()
b = b.split(' ')
mdict={}
l = []
for i in b:
if i in mdict.keys():
mdict[i] += 1
else:
mdict[i] =1
m = 0
count = 0
for i in mdict.values():
count +=1
if i > m:
m = i
print(m,count)
| Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
n = int(input())
b = input()
b = b.split(' ')
mdict={}
l = []
for i in b:
if i in mdict.keys():
mdict[i] += 1
else:
mdict[i] =1
m = 0
count = 0
for i in mdict.values():
count +=1
if i > m:
m = i
print(m,count)
``` | 3.977 |
276 | D | Little Girl and Maximum XOR | PROGRAMMING | 1,700 | [
"bitmasks",
"dp",
"greedy",
"implementation",
"math"
] | null | null | A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). Your task is to find the maximum value among all considered ones.
Expression means applying bitw... | The single line contains space-separated integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | In a single line print a single integer — the maximum value of for all pairs of integers *a*, *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). | [
"1 2\n",
"8 16\n",
"1 1\n"
] | [
"3\n",
"31\n",
"0\n"
] | none | 2,000 | [
{
"input": "1 2",
"output": "3"
},
{
"input": "8 16",
"output": "31"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "506 677",
"output": "1023"
},
{
"input": "33 910",
"output": "1023"
},
{
"input": "36 94",
"output": "127"
},
{
"input": ... | 1,637,662,727 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 0 | from sys import stdin, stdout
l, r = list(map(int, stdin.readline().split()))
mx = 0
if l == r:
mx = 0
else:
for i in range(l, r+1):
res = (i ^ (i+1))
mx = max(mx, res)
print(mx)
| Title: Little Girl and Maximum XOR
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<... | ```python
from sys import stdin, stdout
l, r = list(map(int, stdin.readline().split()))
mx = 0
if l == r:
mx = 0
else:
for i in range(l, r+1):
res = (i ^ (i+1))
mx = max(mx, res)
print(mx)
``` | 0 | |
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,697,907,863 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | t = int(input())
ps = list(map(int, input().split()))
total_volume = sum(ps)
weighted_sum = sum((p / 100) * total_volume for p in ps)
fraction_of_orange_juice = weighted_sum / total_volume
print(f"{fraction_of_orange_juice:.12f}")
| 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
t = int(input())
ps = list(map(int, input().split()))
total_volume = sum(ps)
weighted_sum = sum((p / 100) * total_volume for p in ps)
fraction_of_orange_juice = weighted_sum / total_volume
print(f"{fraction_of_orange_juice:.12f}")
``` | 0 | |
658 | A | Bear and Reverse Radewoosh | PROGRAMMING | 800 | [
"implementation"
] | null | null | Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by diff... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=50,<=1<=≤<=*c*<=≤<=1000) — the number of problems and the constant representing the speed of loosing points.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1000,<=*p**i*<=<<=*p**i*<=+<=1) — initial scores.
The third... | Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points. | [
"3 2\n50 85 250\n10 15 25\n",
"3 6\n50 85 250\n10 15 25\n",
"8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n"
] | [
"Limak\n",
"Radewoosh\n",
"Tie\n"
] | In the first sample, there are 3 problems. Limak solves them as follows:
1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*·10 = 50 - 2·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85... | 500 | [
{
"input": "3 2\n50 85 250\n10 15 25",
"output": "Limak"
},
{
"input": "3 6\n50 85 250\n10 15 25",
"output": "Radewoosh"
},
{
"input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76",
"output": "Tie"
},
{
"input": "4 1\n3 5 6 9\n1 2 4 8",
"output": "Limak"
},
{... | 1,576,289,410 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 124 | 0 | n,c=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
Limak,Radewoosh=0,0
for i in range(len(a)):
Limak+=max([0,a[i]-c*sum(b[0:i+1])])
for j in range(len(a)-1,0,-1):
Radewoosh+=max([0,a[j]-c*sum(b[j::])])
if Limak>Radewoosh:
print('Limak')
elif Radewo... | Title: Bear and Reverse Radewoosh
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-... | ```python
n,c=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
Limak,Radewoosh=0,0
for i in range(len(a)):
Limak+=max([0,a[i]-c*sum(b[0:i+1])])
for j in range(len(a)-1,0,-1):
Radewoosh+=max([0,a[j]-c*sum(b[j::])])
if Limak>Radewoosh:
print('Limak')
e... | 0 | |
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all... | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3... | 1,645,275,223 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #先输入行数n,输入二维数组l[][]
#求出所有路径,动作有n-1个D和n-1个R组成2n-2长度的数组,求出所有情况字符串的组合["..."]
#如何求出情况?迭代函数,迭代函数的同时求出积,储存在{}中
#编辑D和R的动作
#循环,将所有情况动作计算得出所有情况的值,判断0的最小个数min,将最小个数的情况字符串带入lmin
#如何求最少的尾数0的个数:循环/10,个数+1,直到%10不为0
from itertools import combinations
n=int(input())
a=[]
for i in range(n):
a.append(list(map(int,inp... | Title: The least round way
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down fro... | ```python
#先输入行数n,输入二维数组l[][]
#求出所有路径,动作有n-1个D和n-1个R组成2n-2长度的数组,求出所有情况字符串的组合["..."]
#如何求出情况?迭代函数,迭代函数的同时求出积,储存在{}中
#编辑D和R的动作
#循环,将所有情况动作计算得出所有情况的值,判断0的最小个数min,将最小个数的情况字符串带入lmin
#如何求最少的尾数0的个数:循环/10,个数+1,直到%10不为0
from itertools import combinations
n=int(input())
a=[]
for i in range(n):
a.append(list(m... | -1 |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,686,579,896 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 216 | 2,048,000 | s = int(input())
lst = [0]
for i in range(s):
g = list(map(int,input().split()))
lst.append(lst[i]-g[0]+g[1])
print(max(lst)) | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
s = int(input())
lst = [0]
for i in range(s):
g = list(map(int,input().split()))
lst.append(lst[i]-g[0]+g[1])
print(max(lst))
``` | 3 | |
858 | A | k-rounding | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
W... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 750 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output":... | 1,690,223,833 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 96 | 62 | 0 | from math import lcm
n, k = map(int, input().split())
print(lcm(n, 10**k)) | Title: k-rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000.... | ```python
from math import lcm
n, k = map(int, input().split())
print(lcm(n, 10**k))
``` | 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,600,791,993 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 280 | 9,523,200 |
s = list(input())
s2 = list(reversed(s))
#print(s , s2)
for i in s :
print(i , end = '')
for i in s2 :
print(i , end = '')
| 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
s = list(input())
s2 = list(reversed(s))
#print(s , s2)
for i in s :
print(i , end = '')
for i in s2 :
print(i , end = '')
``` | 3 | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,683,807,524 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 93 | 0 | n = int(input())
initial_position = input()
combination = input()
total_actions = 0
for i in range(n):
diff = abs(int(initial_position[i]) - int(combination[i]))
cw_diff = (int(combination[i]) - int(initial_position[i]) + 10) % 10
ccw_diff = (int(initial_position[i]) - int(combination[i]) + 10) % 10
t... | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
n = int(input())
initial_position = input()
combination = input()
total_actions = 0
for i in range(n):
diff = abs(int(initial_position[i]) - int(combination[i]))
cw_diff = (int(combination[i]) - int(initial_position[i]) + 10) % 10
ccw_diff = (int(initial_position[i]) - int(combination[i]) + 10) ... | 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,505,565,992 | 1,952 | Python 3 | OK | TESTS | 161 | 62 | 0 | n,k=map(int,input().split())
n=str(n)
if n.count('0')<k:
print(len(n)-1)
else:
n=n[::-1]
ans=0
j=0
for i in range(0,len(n)):
if n[i]=='0' and j<k:
j+=1
ans=i
print(ans-j+1)
| 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
n,k=map(int,input().split())
n=str(n)
if n.count('0')<k:
print(len(n)-1)
else:
n=n[::-1]
ans=0
j=0
for i in range(0,len(n)):
if n[i]=='0' and j<k:
j+=1
ans=i
print(ans-j+1)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Leha like all kinds of strange things. Recently he liked the function *F*(*n*,<=*k*). Consider all possible *k*-element subsets of the set [1,<=2,<=...,<=*n*]. For subset find minimal element in it. *F*(*n*,<=*k*) — mathematical expectation of the minimal element among all *k*-element subsets.
But only function does n... | First line of input data contains single integer *m* (1<=≤<=*m*<=≤<=2·105) — length of arrays *A* and *B*.
Next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — array *A*.
Next line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=109) — array *B*. | Output *m* integers *a*'1,<=*a*'2,<=...,<=*a*'*m* — array *A*' which is permutation of the array *A*. | [
"5\n7 3 5 3 4\n2 1 3 2 3\n",
"7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2\n"
] | [
"4 7 3 5 3\n",
"2 6 4 5 8 8 6\n"
] | none | 0 | [
{
"input": "5\n7 3 5 3 4\n2 1 3 2 3",
"output": "4 7 3 5 3"
},
{
"input": "7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2",
"output": "2 6 4 5 8 8 6"
}
] | 1,508,564,308 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 1,232 | 53,145,600 | # -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
"""
created by shhuan at 2017/10/21 13:33
"""
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
A = sorted([(x, i) f... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha like all kinds of strange things. Recently he liked the function *F*(*n*,<=*k*). Consider all possible *k*-element subsets of the set [1,<=2,<=...,<=*n*]. For subset find minimal element in it. *F*(*n*,<=*k*) — mathematical e... | ```python
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
"""
created by shhuan at 2017/10/21 13:33
"""
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
A = sorted... | 3 | |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000... | 1,602,875,310 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 93 | 0 | # https://codeforces.com/problemset/problem/664/A
a, b = input().split()
if a == b:
print(a)
else:
print(1) | Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
# https://codeforces.com/problemset/problem/664/A
a, b = input().split()
if a == b:
print(a)
else:
print(1)
``` | 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,694,672,396 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 6,451,200 | x = int(input())
y = 1378**x
y = str(y)
print(y[len(y)-1]) | 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
x = int(input())
y = 1378**x
y = str(y)
print(y[len(y)-1])
``` | 0 | |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,580,304,270 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 109 | 0 | l=list(map(int,input().split()))
f=l[3]*2+l[0]*l[1]
s=l[4]*2+l[0]*l[2]
if f<s:
print('First')
elif f>s:
print('Second')
else:
print('Friendship') | Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
l=list(map(int,input().split()))
f=l[3]*2+l[0]*l[1]
s=l[4]*2+l[0]*l[2]
if f<s:
print('First')
elif f>s:
print('Second')
else:
print('Friendship')
``` | 3 | |
609 | B | The Best Gift | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation"
] | null | null | Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack decides to buy two books of different genres.
Based on the genre of books on sale in the shop, find th... | The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres.
The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book.
It is guaranteed ... | Print the only integer — the number of ways in which Jack can choose books.
It is guaranteed that the answer doesn't exceed the value 2·109. | [
"4 3\n2 1 3 1\n",
"7 4\n4 2 3 1 2 4 3\n"
] | [
"5\n",
"18\n"
] | The answer to the first test sample equals 5 as Sasha can choose:
1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books. | 0 | [
{
"input": "4 3\n2 1 3 1",
"output": "5"
},
{
"input": "7 4\n4 2 3 1 2 4 3",
"output": "18"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "3 2\n1 2 2",
"output": "2"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 10",
"output": "45"
},
{
"input": "9 2... | 1,540,574,769 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 78 | 0 | # http://codeforces.com/problemset/problem/609/B
"""
With n of genders, m of books => (m-n) books had duplicated
Tinh chinh hop cua 2 trong m books - Chinh hop 2 trong (m-n)books
formula : (m)! /
"""
def calculate_chinh_hop_of_2(number_books):
return number_books * (number_books - 1) / 2
number_bo... | Title: The Best Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack deci... | ```python
# http://codeforces.com/problemset/problem/609/B
"""
With n of genders, m of books => (m-n) books had duplicated
Tinh chinh hop cua 2 trong m books - Chinh hop 2 trong (m-n)books
formula : (m)! /
"""
def calculate_chinh_hop_of_2(number_books):
return number_books * (number_books - 1) / 2
... | 0 | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,649,424,622 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 0 | n = int(input())
lst = [[1 for i in range (n)]]
for i in range (n-1):
arr = []
for j in range (n):
arr.append(sum(lst[-1][:j+1]))
lst.append(arr)
print(lst[-1][-1]) | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
n = int(input())
lst = [[1 for i in range (n)]]
for i in range (n-1):
arr = []
for j in range (n):
arr.append(sum(lst[-1][:j+1]))
lst.append(arr)
print(lst[-1][-1])
``` | 3 | |
651 | A | Joysticks | PROGRAMMING | 1,100 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n... | The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst... | 500 | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
... | 1,591,778,666 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 108 | 0 | def solve():
a1,a2=map(int,input().strip().split())
c=0
if a1==1 and a2==1:
print(0)
else:
while a1>0 and a2>0:
a1,a2=max(a1,a2)-2,min(a1,a2)+1
c+=1
#print(a1,a2)
#print(c)
print(c)
if __name__=="__main__":
... | Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on... | ```python
def solve():
a1,a2=map(int,input().strip().split())
c=0
if a1==1 and a2==1:
print(0)
else:
while a1>0 and a2>0:
a1,a2=max(a1,a2)-2,min(a1,a2)+1
c+=1
#print(a1,a2)
#print(c)
print(c)
if __name__=="__ma... | 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,602,827,094 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 154 | 0 | def iq_test(numbers):
if numbers[0] % 2 == 0:
for value in range(len(numbers)):
if numbers[value] % 2 != 0:
return value + 1
else:
for value in range(len(numbers)):
if numbers[value] % 2 == 0:
return value + 1
n = int(input... | 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
def iq_test(numbers):
if numbers[0] % 2 == 0:
for value in range(len(numbers)):
if numbers[value] % 2 != 0:
return value + 1
else:
for value in range(len(numbers)):
if numbers[value] % 2 == 0:
return value + 1
n =... | 0 |
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order... | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som... | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
... | 1,545,834,068 | 2,147,483,647 | Python 3 | OK | TESTS | 150 | 124 | 0 | n=int(input())
a=[]
for i in range(n):
r=list(map(int,input().split()))
a.append(r)
b=sorted(a,reverse=True)
for i in a:
if(i[1]-i[0]!=0):
print("rated")
exit(0)
for i in range(n):
if a[i]!=b[i]:
print("unrated")
exit(0)
c=0
for i in a:
if(i[1]-i[0]=... | Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number ... | ```python
n=int(input())
a=[]
for i in range(n):
r=list(map(int,input().split()))
a.append(r)
b=sorted(a,reverse=True)
for i in a:
if(i[1]-i[0]!=0):
print("rated")
exit(0)
for i in range(n):
if a[i]!=b[i]:
print("unrated")
exit(0)
c=0
for i in a:
if(... | 3 | |
672 | B | Different is Good | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters. | If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | [
"2\naa\n",
"4\nkoko\n",
"5\nmurat\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | 1,000 | [
{
"input": "2\naa",
"output": "1"
},
{
"input": "4\nkoko",
"output": "2"
},
{
"input": "5\nmurat",
"output": "0"
},
{
"input": "6\nacbead",
"output": "1"
},
{
"input": "7\ncdaadad",
"output": "4"
},
{
"input": "25\npeoaicnbisdocqofsqdpgobpn",
"outp... | 1,623,771,585 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 62 | 0 | n=int(input())
s=input()
set_s=set(s)
if len(s)>26:
print(-1)
else:
print(n-len(set_s))
| Title: Different is Good
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are di... | ```python
n=int(input())
s=input()
set_s=set(s)
if len(s)>26:
print(-1)
else:
print(n-len(set_s))
``` | 3 | |
294 | A | Shaass and Oskols | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*... | The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i... | On the *i*-th line of the output print the number of birds on the *i*-th wire. | [
"5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"3\n2 4 1\n1\n2 2\n"
] | [
"0\n12\n5\n0\n16\n",
"3\n0\n3\n"
] | none | 500 | [
{
"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6",
"output": "0\n12\n5\n0\n16"
},
{
"input": "3\n2 4 1\n1\n2 2",
"output": "3\n0\n3"
},
{
"input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43",
"output": "0\n66\n57\n7\n0"
},
{
"input": "10\n48 53 10 28 91 56 8... | 1,572,782,529 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | a = int(input())
b = list(map(int, input().rstrip().split()))
m = int(input())
for i in range(m):
l = list(map(int, input().rstrip().split()))
x = l[0]
y = l[1]
if x == 1:
b[x] += (b[x-1] - y)
b[x-1] = 0
elif x == len(b):
b[x-2] += (y-1)
else:
b[x-2] ... | Title: Shaass and Oskols
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each... | ```python
a = int(input())
b = list(map(int, input().rstrip().split()))
m = int(input())
for i in range(m):
l = list(map(int, input().rstrip().split()))
x = l[0]
y = l[1]
if x == 1:
b[x] += (b[x-1] - y)
b[x-1] = 0
elif x == len(b):
b[x-2] += (y-1)
else:
... | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,668,106,600 | 2,147,483,647 | Python 3 | IDLENESS_LIMIT_EXCEEDED | TESTS | 0 | 0 | 0 | import turtle
from turtle import *
turtle.title("rainbow test 1")
speed(55)
bgcolor("black")
r,g,b = 255,0,0
for i in range(255*2):
colormode(255)
if i < 255 //3:
g +=3
elif i<255*2//3:
r-=3
elif i<255:
b+=3
elif i<255*4//33:
g-=3
elif i<255*5/... | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
import turtle
from turtle import *
turtle.title("rainbow test 1")
speed(55)
bgcolor("black")
r,g,b = 255,0,0
for i in range(255*2):
colormode(255)
if i < 255 //3:
g +=3
elif i<255*2//3:
r-=3
elif i<255:
b+=3
elif i<255*4//33:
g-=3
eli... | -1 |
142 | E | Help Greg the Dwarf 2 | PROGRAMMING | 3,000 | [
"geometry"
] | null | null | Greg the Dwarf has been really busy recently with excavations by the Neverland Mountain. However for the well-known reasons (as you probably remember he is a very unusual dwarf and he cannot stand sunlight) Greg can only excavate at night. And in the morning he should be in his crypt before the first sun ray strikes. T... | The first input line contains space-separated integers *r* and *h* (1<=≤<=*r*,<=*h*<=≤<=1000) — the base radius and the cone height correspondingly. The second and third lines contain coordinates of two points on the cone surface, groups of three space-separated real numbers. The coordinates of the points are given in ... | Print the length of the shortest path between the points given in the input, with absolute or relative error not exceeding 10<=-<=6. | [
"2 2\n1.0 0.0 0.0\n-1.0 0.0 0.0\n",
"2 2\n1.0 0.0 0.0\n1.0 0.0 1.0\n",
"2 2\n1.0 0.0 1.0\n-1.0 0.0 1.0\n",
"2 2\n1.0 0.0 0.0\n0.0 1.0 1.0\n"
] | [
"2.000000000",
"2.414213562",
"2.534324263",
"3.254470198"
] | none | 2,500 | [
{
"input": "2 2\n1.0 0.0 0.0\n-1.0 0.0 0.0",
"output": "2.0000000000000000"
},
{
"input": "2 2\n1.0 0.0 0.0\n1.0 0.0 1.0",
"output": "2.414213562373095"
},
{
"input": "2 2\n1.0 0.0 1.0\n-1.0 0.0 1.0",
"output": "2.534324262661599"
},
{
"input": "2 2\n1.0 0.0 0.0\n0.0 1.0 1.0"... | 1,697,187,022 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | import math
# Read input
r, h = map(float, input().split())
p1 = list(map(float, input().split()))
p2 = list(map(float, input().split()))
# Calculate the distance along the base
base_distance = math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
# Calculate the distance along the curved surface
surface_dis... | Title: Help Greg the Dwarf 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg the Dwarf has been really busy recently with excavations by the Neverland Mountain. However for the well-known reasons (as you probably remember he is a very unusual dwarf and he cannot stand sunlight) Greg c... | ```python
import math
# Read input
r, h = map(float, input().split())
p1 = list(map(float, input().split()))
p2 = list(map(float, input().split()))
# Calculate the distance along the base
base_distance = math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
# Calculate the distance along the curved surface
s... | 0 | |
465 | B | Inbox (100500) | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox.
The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. | Print a single number — the minimum number of operations needed to make all the letters read. | [
"5\n0 1 0 1 0\n",
"5\n1 1 0 0 1\n",
"2\n0 0\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already... | 1,000 | [
{
"input": "5\n0 1 0 1 0",
"output": "3"
},
{
"input": "5\n1 1 0 0 1",
"output": "4"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "9\n1 0 1 0 1 0 1 0 1",
"output": "9"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
},
{
"input": "14\n0 0 1 1 1 0 1 ... | 1,621,655,068 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 77 | 0 | n = int(input())
a = list(map(int,input().split()))
l=0
c=0
for i in range(n):
if(c==0 and a[i]==1):
c=1
l=i
elif(a[i]==1):
c += min(2,i-l)
l=i
print(c) | Title: Inbox (100500)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soo... | ```python
n = int(input())
a = list(map(int,input().split()))
l=0
c=0
for i in range(n):
if(c==0 and a[i]==1):
c=1
l=i
elif(a[i]==1):
c += min(2,i-l)
l=i
print(c)
``` | 3 | |
841 | B | Godsend | PROGRAMMING | 1,100 | [
"games",
"math"
] | null | null | Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts... | First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array.
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). | [
"4\n1 3 2 3\n",
"2\n2 2\n"
] | [
"First\n",
"Second\n"
] | In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose. | 1,000 | [
{
"input": "4\n1 3 2 3",
"output": "First"
},
{
"input": "2\n2 2",
"output": "Second"
},
{
"input": "4\n2 4 6 8",
"output": "Second"
},
{
"input": "5\n1 1 1 1 1",
"output": "First"
},
{
"input": "4\n720074544 345031254 849487632 80870826",
"output": "Second"
... | 1,595,673,922 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 6,656,000 | n=int(input())
arr=list(map(int,input().split()))
sum=0
for item in arr:
sum+=item
if sum%2!=0:
print("First")
else:
print("Second") | Title: Godsend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero l... | ```python
n=int(input())
arr=list(map(int,input().split()))
sum=0
for item in arr:
sum+=item
if sum%2!=0:
print("First")
else:
print("Second")
``` | 0 | |
598 | A | Tricky Sum | PROGRAMMING | 900 | [
"math"
] | null | null | In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for *t* values of *n*. | The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed.
Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). | Print the requested sum for each of *t* integers *n* given in the input. | [
"2\n4\n1000000000\n"
] | [
"-4\n499999998352516354\n"
] | The answer for the first sample is explained in the statement. | 0 | [
{
"input": "2\n4\n1000000000",
"output": "-4\n499999998352516354"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25"
},
{
"input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53",
"output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130... | 1,632,539,785 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 1,000 | 29,184,000 | #!/usr/bin/env python
# coding: utf-8
# In[ ]:
two=[2**i for i in range(10000000)]
t=int(input())
sum=0
for i in range(t):
long=int(input())
for j in range(long+1):
if(j in two):
j*=-1
sum+=j
print(sum)
| Title: Tricky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, be... | ```python
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
two=[2**i for i in range(10000000)]
t=int(input())
sum=0
for i in range(t):
long=int(input())
for j in range(long+1):
if(j in two):
j*=-1
sum+=j
print(sum)
``` | 0 | |
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabb... | 1,600,495,152 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 202 | 7,065,600 | n = int(input())
s=""
a=0
if n%2==0:
#s = "aa"
print("aa", end='')
a=2
else:
print('b', end='')
a=1
for i in range(a,n,2):
#print(i)
if (i//2)%2 ==0:
print("aa", end='')
else:
print("bb", end='') | Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each o... | ```python
n = int(input())
s=""
a=0
if n%2==0:
#s = "aa"
print("aa", end='')
a=2
else:
print('b', end='')
a=1
for i in range(a,n,2):
#print(i)
if (i//2)%2 ==0:
print("aa", end='')
else:
print("bb", end='')
``` | 3 | |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,693,586,105 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 0 | num = int(input())
def SUM(n):
flag = 1
sum = 0
for i in range(1,n+1):
if i%2==0:
sum+=i
else:
sum-=i
return sum
print(SUM(num)) | Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
num = int(input())
def SUM(n):
flag = 1
sum = 0
for i in range(1,n+1):
if i%2==0:
sum+=i
else:
sum-=i
return sum
print(SUM(num))
``` | 0 | |
779 | A | Pupils Redistribution | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consists of exactly *n* students. An academic performance of each student is known — integer value between 1 and ... | The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=100) — number of students in both groups.
The second line contains sequence of integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5), where *a**i* is academic performance of the *i*-th student of the group *A*.
The third line contains se... | Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained. | [
"4\n5 4 4 4\n5 5 4 5\n",
"6\n1 1 1 1 1 1\n5 5 5 5 5 5\n",
"1\n5\n3\n",
"9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n"
] | [
"1\n",
"3\n",
"-1\n",
"4\n"
] | none | 500 | [
{
"input": "4\n5 4 4 4\n5 5 4 5",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1\n5 5 5 5 5 5",
"output": "3"
},
{
"input": "1\n5\n3",
"output": "-1"
},
{
"input": "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1",
"output": "4"
},
{
"input": "1\n1\n2",
"output": "-1"
... | 1,651,695,910 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 62 | 102,400 | import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
w = input()[:-1].replace(' ','')
s = input()[:-1].replace(' ','')
s = Counter(w + s)
for i in s.values():
if i % 2 == 1:
print(-1)
break
else:
w = Counter(w)
c = 0
for i in w:
... | Title: Pupils Redistribution
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consis... | ```python
import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
w = input()[:-1].replace(' ','')
s = input()[:-1].replace(' ','')
s = Counter(w + s)
for i in s.values():
if i % 2 == 1:
print(-1)
break
else:
w = Counter(w)
c = 0
for i in w:... | 3 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,685,950,267 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 124 | 0 | line = list(input())
count1 = count0 = 0
flag = False
for i in line:
if i=='0':
count0 += 1
count1 = 0
else:
count1 += 1
count0 = 0
if count0>=7 or count1>=7:
flag = True
break
if flag:
print("YES")
else:
print("NO") | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
line = list(input())
count1 = count0 = 0
flag = False
for i in line:
if i=='0':
count0 += 1
count1 = 0
else:
count1 += 1
count0 = 0
if count0>=7 or count1>=7:
flag = True
break
if flag:
print("YES")
else:
print("NO")
``` | 3.969 |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,695,099,981 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | n = int(input())
d = {}
for i in range(n):
l = []
a = input()
if a not in l:
d[a] = 1
l.append(a)
else:
d[a] += 1
l = max([x for x in d.values()])
for v in d.keys():
if d[v] == l:
print(v)
break | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
n = int(input())
d = {}
for i in range(n):
l = []
a = input()
if a not in l:
d[a] = 1
l.append(a)
else:
d[a] += 1
l = max([x for x in d.values()])
for v in d.keys():
if d[v] == l:
print(v)
break
``` | 0 |
386 | A | Second-Price Auction | PROGRAMMING | 800 | [
"implementation"
] | null | null | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the au... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. | The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. | [
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] | [
"2 5\n",
"1 8\n",
"6 9\n"
] | none | 500 | [
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{... | 1,619,125,458 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 77 | 0 |
def find_max(l):
maximum = l[0]
ind_max = 0
for i in range(len(l)):
if maximum < l[i]:
maximum = l[i]
ind_max = i
return ind_max
def main_function():
n = int(input())
a = [int(i) for i in input().split(" ")]
ind_max = find_max(a)
a.po... | Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is... | ```python
def find_max(l):
maximum = l[0]
ind_max = 0
for i in range(len(l)):
if maximum < l[i]:
maximum = l[i]
ind_max = i
return ind_max
def main_function():
n = int(input())
a = [int(i) for i in input().split(" ")]
ind_max = find_max(a)... | 3 | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,547,736,266 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 0 |
from math import ceil
r,x1,y1,x2,y2 = map(int,input().split())
d = (abs(x1-x2)**2 + abs(y1-y2)**2)**0.5
print(ceil(d/(2*r)))
| Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
from math import ceil
r,x1,y1,x2,y2 = map(int,input().split())
d = (abs(x1-x2)**2 + abs(y1-y2)**2)**0.5
print(ceil(d/(2*r)))
``` | 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,695,996,261 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 62 | 0 | def polycheck(n):
if n==180:
return False
if 360/(180-n)==int(360/(180-n)):
return True
return False
n=int(input())
result=[]
for i in range(n):
x=int(input())
if polycheck(x):
result.append("YES")
else:
result.append("NO")
for res in result:
... | 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
def polycheck(n):
if n==180:
return False
if 360/(180-n)==int(360/(180-n)):
return True
return False
n=int(input())
result=[]
for i in range(n):
x=int(input())
if polycheck(x):
result.append("YES")
else:
result.append("NO")
for res in r... | 3 | |
52 | A | 123-sequence | PROGRAMMING | 900 | [
"implementation"
] | A. 123-sequence | 2 | 256 | There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3). | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | [
"9\n1 3 2 2 2 1 1 2 3\n"
] | [
"5\n"
] | In the example all the numbers equal to 1 and 3 should be replaced by 2. | 500 | [
{
"input": "9\n1 3 2 2 2 1 1 2 3",
"output": "5"
},
{
"input": "6\n3 3 2 2 1 3",
"output": "3"
},
{
"input": "12\n3 1 3 1 2 1 3 2 2 1 2 1",
"output": "7"
},
{
"input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2",
"output": "10"
},
{
"input": "2\n2 1",
"output": "1"
... | 1,580,761,216 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 1,060 | 14,950,400 | from collections import deque
from math import ceil,floor,sqrt,gcd
def ii(): return int(input())
def mi(): return map(int,input().split())
def li(): return list(mi())
def si():return input()
n=ii()
a=li()
m={}
for i in a:
if i not in m:
m[i]=1
else:
m[i]+=1
b=[]
for i in m.keys():... | Title: 123-sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each... | ```python
from collections import deque
from math import ceil,floor,sqrt,gcd
def ii(): return int(input())
def mi(): return map(int,input().split())
def li(): return list(mi())
def si():return input()
n=ii()
a=li()
m={}
for i in a:
if i not in m:
m[i]=1
else:
m[i]+=1
b=[]
for i in... | 3.707153 |
733 | B | Parade | PROGRAMMING | 1,100 | [
"math"
] | null | null | Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits beg... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of columns.
The next *n* lines contain the pairs of integers *l**i* and *r**i* (1<=≤<=*l**i*,<=*r**i*<=≤<=500) — the number of soldiers in the *i*-th column which start to march from the left or the right leg respectively. | Print single integer *k* — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached.
Consider that columns are numbered from 1 to *n* in the order they are given in the input data.
If there are several answers, print any of them. | [
"3\n5 6\n8 9\n10 3\n",
"2\n6 5\n5 6\n",
"6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32\n"
] | [
"3\n",
"1\n",
"0\n"
] | In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.
If you give the order to change the leg to the third co... | 1,000 | [
{
"input": "3\n5 6\n8 9\n10 3",
"output": "3"
},
{
"input": "2\n6 5\n5 6",
"output": "1"
},
{
"input": "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32",
"output": "0"
},
{
"input": "2\n500 499\n500 500",
"output": "0"
},
{
"input": "1\n139 252",
"output": "0"
},
{
... | 1,584,571,190 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 358 | 307,200 | t=int(input(''))
q=0;s=0;e=0;f=0;b=0;c=0;x=0;g=0;r=0;j=0;r1=0;q1=0;u=0;y=0
for z in range(0,t):
a=(list(map(int, input().split())))
b+=a[0];c+=a[1]
if(a[0]-a[1]>0):
if (a[0]-a[1])>q:
q=a[0];u=z;q1=a[1]
if(a[1]-a[0]>s):
if a[1]-a[0]>0:
x=z;r=a[0];r1=a[1]
... | Title: Parade
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should... | ```python
t=int(input(''))
q=0;s=0;e=0;f=0;b=0;c=0;x=0;g=0;r=0;j=0;r1=0;q1=0;u=0;y=0
for z in range(0,t):
a=(list(map(int, input().split())))
b+=a[0];c+=a[1]
if(a[0]-a[1]>0):
if (a[0]-a[1])>q:
q=a[0];u=z;q1=a[1]
if(a[1]-a[0]>s):
if a[1]-a[0]>0:
x=z;r=a[0... | 0 | |
774 | B | Significant Cups | PROGRAMMING | 2,100 | [
"*special",
"binary search",
"data structures",
"two pointers"
] | null | null | Stepan is a very experienced olympiad participant. He has *n* cups for Physics olympiads and *m* cups for Informatics olympiads. Each cup is characterized by two parameters — its significance *c**i* and width *w**i*.
Stepan decided to expose some of his cups on a shelf with width *d* in such a way, that:
- there is ... | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100<=000, 1<=≤<=*d*<=≤<=109) — the number of cups for Physics olympiads, the number of cups for Informatics olympiads and the width of the shelf.
Each of the following *n* lines contains two integers *c**i* and *w**i* (1<=≤<=*c**i*,<=*w**i*<=... | Print the maximum possible total significance, which Stepan can get exposing cups on the shelf with width *d*, considering all the rules described in the statement.
If there is no way to expose cups on the shelf, then print 0. | [
"3 1 8\n4 2\n5 5\n4 2\n3 2\n",
"4 3 12\n3 4\n2 4\n3 5\n3 4\n3 5\n5 2\n3 4\n",
"2 2 2\n5 3\n6 3\n4 2\n8 1\n"
] | [
"8\n",
"11\n",
"0\n"
] | In the first example Stepan has only one Informatics cup which must be exposed on the shelf. Its significance equals 3 and width equals 2, so after Stepan exposes it, the width of free space on the shelf becomes equal to 6. Also, Stepan must expose the second Physics cup (which has width 5), because it is the most sign... | 0 | [
{
"input": "3 1 8\n4 2\n5 5\n4 2\n3 2",
"output": "8"
},
{
"input": "4 3 12\n3 4\n2 4\n3 5\n3 4\n3 5\n5 2\n3 4",
"output": "11"
},
{
"input": "2 2 2\n5 3\n6 3\n4 2\n8 1",
"output": "0"
},
{
"input": "10 10 229\n15 17\n5 4\n4 15\n4 17\n15 11\n7 6\n5 19\n14 8\n4 1\n10 12\n20 13... | 1,691,348,080 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 904 | 35,123,200 | n, m, d = map(int, input().split())
ph = [[int(j) for j in input().split()] for i in range(n)]
inf = [[int(j) for j in input().split()] for i in range(m)]
for i in range(n):
ph[i][1] = -ph[i][1]
for i in range(m):
inf[i][1] = -inf[i][1]
ph.sort(reverse=True)
inf.sort(reverse=True)
sw, sc = 0, 0
for p ... | Title: Significant Cups
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Stepan is a very experienced olympiad participant. He has *n* cups for Physics olympiads and *m* cups for Informatics olympiads. Each cup is characterized by two parameters — its significance *c**i* and width *w**i*.
... | ```python
n, m, d = map(int, input().split())
ph = [[int(j) for j in input().split()] for i in range(n)]
inf = [[int(j) for j in input().split()] for i in range(m)]
for i in range(n):
ph[i][1] = -ph[i][1]
for i in range(m):
inf[i][1] = -inf[i][1]
ph.sort(reverse=True)
inf.sort(reverse=True)
sw, sc = 0,... | 3 | |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,690,890,850 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | name=input().upper()
residenc=input().upper()
letters=input(). upper()
holeString=name+residenc
temp=0
for letter in holeString:
if letter in letters :
if holeString.count(letter)==letters.count(letter):
temp=1
else:
break
else:
break
if temp==1:
print (... | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
name=input().upper()
residenc=input().upper()
letters=input(). upper()
holeString=name+residenc
temp=0
for letter in holeString:
if letter in letters :
if holeString.count(letter)==letters.count(letter):
temp=1
else:
break
else:
break
if temp==1:
... | 0 | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,636,290,514 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 6,656,000 | n = int(input())
m = list(map(int, input().split()))
c = m.copy()
def partition(array, low, high):
pivot = array[high]
i = low - 1
for j in range(low, high):
if array[j] <= pivot:
i = i + 1
(array[i], array[j]) = (array[j], array[i])
(array[i + 1], array[high]... | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
n = int(input())
m = list(map(int, input().split()))
c = m.copy()
def partition(array, low, high):
pivot = array[high]
i = low - 1
for j in range(low, high):
if array[j] <= pivot:
i = i + 1
(array[i], array[j]) = (array[j], array[i])
(array[i + 1], a... | 0 | |
180 | C | Letter | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to... | The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105. | Print a single number — the least number of actions needed to make the message fancy. | [
"PRuvetSTAaYA\n",
"OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n",
"helloworld\n"
] | [
"5\n",
"0\n",
"0\n"
] | none | 0 | [
{
"input": "PRuvetSTAaYA",
"output": "5"
},
{
"input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA",
"output": "0"
},
{
"input": "helloworld",
"output": "0"
},
{
"input": "P",
"output": "0"
},
{
"input": "t",
"output": "0"
},
{
"input": "XdJ",
"output": "1... | 1,629,639,679 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 18 | 342 | 7,372,800 | S=input()
lst=[]
p=len(S)-1
x=""
for i in range(len(S)-1,0,-1):
if S[i].isupper()!=S[i-1].isupper():
if S[i].isupper():
x=1
else:
x=0
lst.append((p-i+1,x))
p=i-1
if p>-1:
if S[0].isupper():
x=1
else:
x=0
lst.ap... | Title: Letter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them... | ```python
S=input()
lst=[]
p=len(S)-1
x=""
for i in range(len(S)-1,0,-1):
if S[i].isupper()!=S[i-1].isupper():
if S[i].isupper():
x=1
else:
x=0
lst.append((p-i+1,x))
p=i-1
if p>-1:
if S[0].isupper():
x=1
else:
x=0
... | -1 | |
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,694,072,357 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | first_word=input()
second_word=input()
if first_word==second_word[::-1]:
print('YES')
else:
print('NO')
| 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
first_word=input()
second_word=input()
if first_word==second_word[::-1]:
print('YES')
else:
print('NO')
``` | 3.977 |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,629,378,450 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 6,758,400 | no,h=map(int,input().split())
b=max(no,h)
c=7-b
print(c/6)
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
no,h=map(int,input().split())
b=max(no,h)
c=7-b
print(c/6)
``` | 0 |
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge... | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input... | 1,549,658,437 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 |
def dij(edges):
unvisited = {node: None for node in nodes}
visited = {}
current = '1'
currentDistance = 0
unvisited[current] = currentDistance
while True:
for neighbour, distance in distances[current].items():
if neighbour not in unvisited: continue
... | Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* a... | ```python
def dij(edges):
unvisited = {node: None for node in nodes}
visited = {}
current = '1'
currentDistance = 0
unvisited[current] = currentDistance
while True:
for neighbour, distance in distances[current].items():
if neighbour not in unvisited: continue
... | -1 |
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th ... | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697... | 1,673,414,737 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | import math
bacteria = int(input())
factorial = 1
tempFactorial = 0
while factorial < bacteria:
tempFactorial = factorial*2
if tempFactorial > bacteria:
break
else:
factorial *= 2
if factorial < bacteria:
print(1 + (bacteria-factorial))
elif factorial == bacteria:
... | Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split... | ```python
import math
bacteria = int(input())
factorial = 1
tempFactorial = 0
while factorial < bacteria:
tempFactorial = factorial*2
if tempFactorial > bacteria:
break
else:
factorial *= 2
if factorial < bacteria:
print(1 + (bacteria-factorial))
elif factorial == bac... | 0 | |
991 | B | Getting an A | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that... | The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works. | Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. | [
"3\n4 4 4\n",
"4\n5 4 5 5\n",
"4\n5 3 3 5\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so t... | 1,000 | [
{
"input": "3\n4 4 4",
"output": "2"
},
{
"input": "4\n5 4 5 5",
"output": "0"
},
{
"input": "4\n5 3 3 5",
"output": "1"
},
{
"input": "1\n5",
"output": "0"
},
{
"input": "4\n3 2 5 4",
"output": "2"
},
{
"input": "5\n5 4 3 2 5",
"output": "2"
},
... | 1,680,061,452 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | n = int(input())
l = input()
notes = [int(i) for i in l.split()]
c=0
for i in range(n):
if (sum(notes)/n >= 4.5):
break
elif(notes[i]< 4.5):
c=c+1
notes[i] = 5
print(c)
| Title: Getting an A
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming t... | ```python
n = int(input())
l = input()
notes = [int(i) for i in l.split()]
c=0
for i in range(n):
if (sum(notes)/n >= 4.5):
break
elif(notes[i]< 4.5):
c=c+1
notes[i] = 5
print(c)
``` | 0 | |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,689,865,299 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n = int(input())
import math
if n == 1:
print(1)
else:
print(n*2/3)
| Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
n = int(input())
import math
if n == 1:
print(1)
else:
print(n*2/3)
``` | 0 | |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,695,034,569 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | a,b,c = map(int, input().split())
w = a+b+c
x = a+b*c
y = a*b+c
z = a*b*c
print(max(w,x,y,z)) | Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
a,b,c = map(int, input().split())
w = a+b+c
x = a+b*c
y = a*b+c
z = a*b*c
print(max(w,x,y,z))
``` | -1 | |
650 | D | Zip-line | PROGRAMMING | 2,600 | [
"binary search",
"data structures",
"dp",
"hashing"
] | null | null | Vasya has decided to build a zip-line on trees of a nearby forest. He wants the line to be as long as possible but he doesn't remember exactly the heights of all trees in the forest. He is sure that he remembers correct heights of all trees except, possibly, one of them.
It is known that the forest consists of *n* tre... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=400<=000) — the number of the trees in the forest and the number of Petya's assumptions, respectively.
The following line contains *n* integers *h**i* (1<=≤<=*h**i*<=≤<=109) — the heights of trees according to Vasya.
Each of the follow... | For each of the Petya's assumptions output one integer, indicating the maximum length of a zip-line that can be built under this assumption. | [
"4 4\n1 2 3 4\n1 1\n1 4\n4 3\n4 5\n",
"4 2\n1 3 2 6\n3 5\n2 4\n"
] | [
"4\n3\n3\n4\n",
"4\n3\n"
] | Consider the first sample. The first assumption actually coincides with the height remembered by Vasya. In the second assumption the heights of the trees are (4, 2, 3, 4), in the third one they are (1, 2, 3, 3) and in the fourth one they are (1, 2, 3, 5). | 2,000 | [] | 1,692,730,167 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1692730167.3546042")# 1692730167.354621 | Title: Zip-line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has decided to build a zip-line on trees of a nearby forest. He wants the line to be as long as possible but he doesn't remember exactly the heights of all trees in the forest. He is sure that he remembers correct height... | ```python
print("_RANDOM_GUESS_1692730167.3546042")# 1692730167.354621
``` | 0 | |
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,544,681,929 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 0 | n = int(input())
a = [int(x) for x in input().split()]
evenness = 0
sing = 0
e = None
s = None
ex = 0
for i in range(n):
if a[i] % 2 == 0:
e = i+1
evenness += 1
if a[i] % 2 != 0:
s = i+1
sing += 1
if evenness > 1 and ex != 1:
if not s is None:
... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
a = [int(x) for x in input().split()]
evenness = 0
sing = 0
e = None
s = None
ex = 0
for i in range(n):
if a[i] % 2 == 0:
e = i+1
evenness += 1
if a[i] % 2 != 0:
s = i+1
sing += 1
if evenness > 1 and ex != 1:
if not s is None:... | 3.9455 |
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o... | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase... | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.3... | 1,627,483,564 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 6,963,200 | main=dict()
replica=dict()
n,m=map(int,input().split())
for i in range(n+m):
n,p=input().split(' ')
if p[-1]==';':
replica[n]=p[:len(p)-1]
else:
main[n]=p
for j in replica:
for i in main:
if main[i]==replica[j]:
print(str(j)+' '+str(main[i])+'; #'+str(i)) | Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server ... | ```python
main=dict()
replica=dict()
n,m=map(int,input().split())
for i in range(n+m):
n,p=input().split(' ')
if p[-1]==';':
replica[n]=p[:len(p)-1]
else:
main[n]=p
for j in replica:
for i in main:
if main[i]==replica[j]:
print(str(j)+' '+str(main[i])+'; #'+str(i))
``` | 0 | |
615 | D | Multipliers | PROGRAMMING | 2,000 | [
"math",
"number theory"
] | null | null | Ayrat has number *n*, represented as it's prime factorization *p**i* of size *m*, i.e. *n*<==<=*p*1·*p*2·...·*p**m*. Ayrat got secret information that that the product of all divisors of *n* taken modulo 109<=+<=7 is the password to the secret data base. Now he wants to calculate this value. | The first line of the input contains a single integer *m* (1<=≤<=*m*<=≤<=200<=000) — the number of primes in factorization of *n*.
The second line contains *m* primes numbers *p**i* (2<=≤<=*p**i*<=≤<=200<=000). | Print one integer — the product of all divisors of *n* modulo 109<=+<=7. | [
"2\n2 3\n",
"3\n2 3 2\n"
] | [
"36\n",
"1728\n"
] | In the first sample *n* = 2·3 = 6. The divisors of 6 are 1, 2, 3 and 6, their product is equal to 1·2·3·6 = 36.
In the second sample 2·3·2 = 12. The divisors of 12 are 1, 2, 3, 4, 6 and 12. 1·2·3·4·6·12 = 1728. | 2,000 | [
{
"input": "2\n2 3",
"output": "36"
},
{
"input": "3\n2 3 2",
"output": "1728"
},
{
"input": "1\n2017",
"output": "2017"
},
{
"input": "2\n63997 63997",
"output": "135893224"
},
{
"input": "5\n11 7 11 7 11",
"output": "750455957"
},
{
"input": "5\n2 2 ... | 1,603,899,332 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 140 | 0 | if __name__ == "__main__" :
length = int(input())
dict = {}
lst = list(map(int,input().strip().split()))
for i in lst :
if dict.get(i,0) == 0 :
dict[i] = 1
else :
dict[i] += 1
res = 1
for i in dict.keys() :
res *= ((i ** (dict[i] * length)) % (1000... | Title: Multipliers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ayrat has number *n*, represented as it's prime factorization *p**i* of size *m*, i.e. *n*<==<=*p*1·*p*2·...·*p**m*. Ayrat got secret information that that the product of all divisors of *n* taken modulo 109<=+<=7 is the pa... | ```python
if __name__ == "__main__" :
length = int(input())
dict = {}
lst = list(map(int,input().strip().split()))
for i in lst :
if dict.get(i,0) == 0 :
dict[i] = 1
else :
dict[i] += 1
res = 1
for i in dict.keys() :
res *= ((i ** (dict[i] * length... | 0 | |
687 | A | NP-Hard Problem | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or bot... | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively.
Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting ... | If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes).
If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number ... | [
"4 2\n1 2\n2 3\n",
"3 3\n1 2\n2 3\n1 3\n"
] | [
"1\n2 \n2\n1 3 \n",
"-1\n"
] | In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).
In the second sample, there is no way to satisfy both Pari and Arya. | 500 | [
{
"input": "4 2\n1 2\n2 3",
"output": "1\n2 \n2\n1 3 "
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "-1"
},
{
"input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5",
"output": "-1"
},
{
"input": "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8",
"output": "-1"
... | 1,665,583,960 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 623 | 15,564,800 | from collections import defaultdict, deque
n, m = map(int, input().split())
red, blue = set(), set()
visited = list()
edges, res = defaultdict(list), 0
for i in range(m):
first, second = map(int, input().split())
edges[first].append(second)
edges[second].append(first)
visited.append(first... | Title: NP-Hard Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of ... | ```python
from collections import defaultdict, deque
n, m = map(int, input().split())
red, blue = set(), set()
visited = list()
edges, res = defaultdict(list), 0
for i in range(m):
first, second = map(int, input().split())
edges[first].append(second)
edges[second].append(first)
visited.ap... | 0 | |
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel... | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input"... | 1,657,051,561 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 202 | 4,403,200 |
n,m=list(map(int,input().split()))
a=[]
b=[]
for i in range(m):
ai,bi=list(map(str,input().split()))
a.append(ai)
b.append(bi)
lec=list(map(str,input().split()))
res=''
for x in lec:
idx=a.index(x)
if(len(x)<=len(b[idx])):
res+=x+' '
else:
res+=b[idx]+' '
print(r... | 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=list(map(int,input().split()))
a=[]
b=[]
for i in range(m):
ai,bi=list(map(str,input().split()))
a.append(ai)
b.append(bi)
lec=list(map(str,input().split()))
res=''
for x in lec:
idx=a.index(x)
if(len(x)<=len(b[idx])):
res+=x+' '
else:
res+=b[idx]+' ... | 3 | |
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr... | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO... | 1,698,071,430 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 122 | 0 | n=int(input())
a=(n*(n+1))/2
if a%n==0:
print("YES")
else:
print("NO") | Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t... | ```python
n=int(input())
a=(n*(n+1))/2
if a%n==0:
print("YES")
else:
print("NO")
``` | 0 |
340 | C | Tourist Problem | PROGRAMMING | 1,600 | [
"combinatorics",
"implementation",
"math"
] | null | null | Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are *n* destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The *n* destinations are described by a non-negative integers sequence *a*1, *a*2, ..., *a**n*. The number *a*... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105). Next line contains *n* distinct integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=107). | Output two integers — the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible. | [
"3\n2 3 5\n"
] | [
"22 3"
] | Consider 6 possible routes:
- [2, 3, 5]: total distance traveled: |2 – 0| + |3 – 2| + |5 – 3| = 5; - [2, 5, 3]: |2 – 0| + |5 – 2| + |3 – 5| = 7; - [3, 2, 5]: |3 – 0| + |2 – 3| + |5 – 2| = 7; - [3, 5, 2]: |3 – 0| + |5 – 3| + |2 – 5| = 8; - [5, 2, 3]: |5 – 0| + |2 – 5| + |3 – 2| = 9; - [5, 3, 2]: |5 – 0| + |3 – 5|... | 2,000 | [
{
"input": "3\n2 3 5",
"output": "22 3"
},
{
"input": "4\n1 5 77 2",
"output": "547 4"
},
{
"input": "5\n3 3842 288 199 334",
"output": "35918 5"
},
{
"input": "7\n1 2 3 40 52 33 86",
"output": "255 1"
},
{
"input": "7\n1 10 100 1000 10000 1000000 10000000",
"... | 1,377,905,223 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 468 | 8,908,800 | from fractions import Fraction
n = int(input())
l = [int(x) for x in input().split()]
l.sort()
f = Fraction(sum([(3-2*n+4*i)*l[i] for i in range(n)]),n)
print(f.numerator,f.denominator)
##import itertools
##tot2 = 0
##for i in itertools.permutations(l):
## loc = 0
## tot = 0
## for e in i:
##... | Title: Tourist Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are *n* destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The *n* d... | ```python
from fractions import Fraction
n = int(input())
l = [int(x) for x in input().split()]
l.sort()
f = Fraction(sum([(3-2*n+4*i)*l[i] for i in range(n)]),n)
print(f.numerator,f.denominator)
##import itertools
##tot2 = 0
##for i in itertools.permutations(l):
## loc = 0
## tot = 0
## for e... | 3 | |
616 | A | Comparing Two Long Integers | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As input/output can r... | The first line contains a non-negative integer *a*.
The second line contains a non-negative integer *b*.
The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits. | Print the symbol "<" if *a*<=<<=*b* and the symbol ">" if *a*<=><=*b*. If the numbers are equal print the symbol "=". | [
"9\n10\n",
"11\n10\n",
"00012345\n12345\n",
"0123\n9\n",
"0123\n111\n"
] | [
"<\n",
">\n",
"=\n",
">\n",
">\n"
] | none | 0 | [
{
"input": "9\n10",
"output": "<"
},
{
"input": "11\n10",
"output": ">"
},
{
"input": "00012345\n12345",
"output": "="
},
{
"input": "0123\n9",
"output": ">"
},
{
"input": "0123\n111",
"output": ">"
},
{
"input": "9\n9",
"output": "="
},
{
... | 1,675,796,921 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 2,000 | 2,867,200 | def comparing_integer(a, b):
if a > b:
return ">"
elif a < b:
return "<"
else:
return "="
if __name__ == "__main__":
a = int(input())
b = int(input())
print(comparing_integer(a, b))
| Title: Comparing Two Long Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal.
The input size is very large so don't use th... | ```python
def comparing_integer(a, b):
if a > b:
return ">"
elif a < b:
return "<"
else:
return "="
if __name__ == "__main__":
a = int(input())
b = int(input())
print(comparing_integer(a, b))
``` | 0 | |
724 | C | Ray Tracing | PROGRAMMING | 1,800 | [
"greedy",
"hashing",
"implementation",
"math",
"number theory",
"sortings"
] | null | null | There are *k* sensors located in the rectangular room of size *n*<=×<=*m* meters. The *i*-th sensor is located at point (*x**i*,<=*y**i*). All sensors are located at distinct points strictly inside the rectangle.
Opposite corners of the room are located at points (0,<=0) and (*n*,<=*m*). Walls of the room are paralle... | The first line of the input contains three integers *n*, *m* and *k* (2<=≤<=*n*,<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100<=000) — lengths of the room's walls and the number of sensors.
Each of the following *k* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=*n*<=-<=1, 1<=≤<=*y**i*<=≤<=*m*<=-<=1) — coordin... | Print *k* integers. The *i*-th of them should be equal to the number of seconds when the ray first passes through the point where the *i*-th sensor is located, or <=-<=1 if this will never happen. | [
"3 3 4\n1 1\n1 2\n2 1\n2 2\n",
"3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3\n",
"7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3\n"
] | [
"1\n-1\n-1\n2\n",
"1\n-1\n-1\n2\n5\n-1\n",
"13\n2\n9\n5\n-1\n"
] | In the first sample, the ray will consequently pass through the points (0, 0), (1, 1), (2, 2), (3, 3). Thus, it will stop at the point (3, 3) after 3 seconds.
In the second sample, the ray will consequently pass through the following points: (0, 0), (1, 1), (2, 2), (3, 3), (2, 4), (1, 3), (0, 2), (1, 1), (2, 0), (3, 1... | 1,500 | [
{
"input": "3 3 4\n1 1\n1 2\n2 1\n2 2",
"output": "1\n-1\n-1\n2"
},
{
"input": "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3",
"output": "1\n-1\n-1\n2\n5\n-1"
},
{
"input": "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3",
"output": "13\n2\n9\n5\n-1"
},
{
"input": "10 10 10\n3 8\n1 7\n2 3\n4 2\n4 8\n... | 1,585,891,606 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 1,123 | 76,595,200 |
"""
NTC here
"""
import sys
inp = sys.stdin.readline
def input(): return inp().strip()
# flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**26)
def iin(): return int(input())
def lin(): return list(map(int, input().split()))
# range = xrange
# input = raw_input
... | Title: Ray Tracing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *k* sensors located in the rectangular room of size *n*<=×<=*m* meters. The *i*-th sensor is located at point (*x**i*,<=*y**i*). All sensors are located at distinct points strictly inside the rectangle.
Opposite... | ```python
"""
NTC here
"""
import sys
inp = sys.stdin.readline
def input(): return inp().strip()
# flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**26)
def iin(): return int(input())
def lin(): return list(map(int, input().split()))
# range = xrange
# input = ra... | 3 | |
228 | B | Two Tables | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | You've got two rectangular tables with sizes *n**a*<=×<=*m**a* and *n**b*<=×<=*m**b* cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the *i*-th row and the *j*-t... | The first line contains two space-separated integers *n**a*,<=*m**a* (1<=≤<=*n**a*,<=*m**a*<=≤<=50) — the number of rows and columns in the first table. Then *n**a* lines contain *m**a* characters each — the elements of the first table. Each character is either a "0", or a "1".
The next line contains two space-separat... | Print two space-separated integers *x*,<=*y* (|*x*|,<=|*y*|<=≤<=109) — a shift with maximum overlap factor. If there are multiple solutions, print any of them. | [
"3 2\n01\n10\n00\n2 3\n001\n111\n",
"3 3\n000\n010\n000\n1 1\n1\n"
] | [
"0 1\n",
"-1 -1\n"
] | none | 1,000 | [
{
"input": "3 2\n01\n10\n00\n2 3\n001\n111",
"output": "0 1"
},
{
"input": "3 3\n000\n010\n000\n1 1\n1",
"output": "-1 -1"
},
{
"input": "2 4\n1010\n0011\n5 5\n01100\n01110\n00111\n00110\n00110",
"output": "1 1"
},
{
"input": "3 1\n0\n1\n0\n2 2\n11\n00",
"output": "-1 1"
... | 1,685,854,266 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 92 | 0 | '''
Khushal Sindhav
Indian Institute Of Technology, Jodhpur
4 June 2023
'''
import sys
input = sys.stdin.readline
# print = sys.stdout.write
def exe():
maxi=0
indexes=[]
for x in range(-max(n,p),max(n,p)+1):
for y in range(-max(m,q),max(m,q)+1):
ans=0
... | Title: Two Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got two rectangular tables with sizes *n**a*<=×<=*m**a* and *n**b*<=×<=*m**b* cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will de... | ```python
'''
Khushal Sindhav
Indian Institute Of Technology, Jodhpur
4 June 2023
'''
import sys
input = sys.stdin.readline
# print = sys.stdout.write
def exe():
maxi=0
indexes=[]
for x in range(-max(n,p),max(n,p)+1):
for y in range(-max(m,q),max(m,q)+1):
ans=0
... | -1 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.