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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
735 | A | Ostap and Grasshopper | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The gr... | The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the correspondi... | If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). | [
"5 2\n#G#T#\n",
"6 1\nT....G\n",
"7 3\nT..#..G\n",
"6 2\n..GT..\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a sin... | 500 | [
{
"input": "5 2\n#G#T#",
"output": "YES"
},
{
"input": "6 1\nT....G",
"output": "YES"
},
{
"input": "7 3\nT..#..G",
"output": "NO"
},
{
"input": "6 2\n..GT..",
"output": "NO"
},
{
"input": "2 1\nGT",
"output": "YES"
},
{
"input": "100 5\nG####.####.###... | 1,549,503,676 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 11 | 93 | 0 | box_len, hop_len = [int(x) for x in input().split()]
cells = input()
grasshopper = target = -1
# find G and T positions
for idx in range(box_len):
if cells[idx] == "G":
grasshopper = idx
elif cells[idx] == "T":
target = idx
# find hop direction
if target < grasshopper:
hop_l... | Title: Ostap and Grasshopper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles.... | ```python
box_len, hop_len = [int(x) for x in input().split()]
cells = input()
grasshopper = target = -1
# find G and T positions
for idx in range(box_len):
if cells[idx] == "G":
grasshopper = idx
elif cells[idx] == "T":
target = idx
# find hop direction
if target < grasshopper:
... | -1 | |
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,594,685,155 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 278 | 20,172,800 | x , y= map(int,input().split())
if (6-max(x,y)+1) %2 ==0:
print(str(int((6-max(x,y)+1)/2))+'/'+str(int(6/2)))
elif (6-max(x,y)+1)%3 ==0:
print('1/2')
elif x == y:
print('1/1')
else:
print(str((6-max(x,y)+1))+'/'+'6') | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
x , y= map(int,input().split())
if (6-max(x,y)+1) %2 ==0:
print(str(int((6-max(x,y)+1)/2))+'/'+str(int(6/2)))
elif (6-max(x,y)+1)%3 ==0:
print('1/2')
elif x == y:
print('1/1')
else:
print(str((6-max(x,y)+1))+'/'+'6')
``` | 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,683,999,591 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 124 | 0 | n = int(input())
p = list(map(int,input().split(maxsplit = n)))
c = 0
for i in range(n):
c += p[i]
print(c/n) | Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*... | ```python
n = int(input())
p = list(map(int,input().split(maxsplit = n)))
c = 0
for i in range(n):
c += p[i]
print(c/n)
``` | 3 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,690,218,886 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | k=int(input())
t=list(map(int,input().split()))
p=[0]*k
for i in range(k):
p[t[i]-1]=i+1
print(' '.join(map(str,p))) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
k=int(input())
t=list(map(int,input().split()))
p=[0]*k
for i in range(k):
p[t[i]-1]=i+1
print(' '.join(map(str,p)))
``` | 3 | |
526 | B | Om Nom and Dark Park | PROGRAMMING | 1,400 | [
"dfs and similar",
"greedy",
"implementation"
] | null | null | Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2*n*<=+<=1<=-<=1 squares connected by roads so... | The first line contains integer *n* (1<=≤<=*n*<=≤<=10) — the number of roads on the path from the entrance to any exit.
The next line contains 2*n*<=+<=1<=-<=2 numbers *a*2,<=*a*3,<=... *a*2*n*<=+<=1<=-<=1 — the initial numbers of street lights on each road of the park. Here *a**i* is the number of street lights on th... | Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe. | [
"2\n1 2 3 4 5 6\n"
] | [
"5\n"
] | Picture for the sample test. Green color denotes the additional street lights. | 500 | [
{
"input": "2\n1 2 3 4 5 6",
"output": "5"
},
{
"input": "2\n1 2 3 3 2 2",
"output": "0"
},
{
"input": "1\n39 52",
"output": "13"
},
{
"input": "2\n59 96 34 48 8 72",
"output": "139"
},
{
"input": "3\n87 37 91 29 58 45 51 74 70 71 47 38 91 89",
"output": "210"... | 1,684,464,712 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 77 | 3,481,600 | n=int(input())
a=[0,0]+list(map(int,input().split()))
# print(a)
ans=0
def dfs(i,d):
global ans
if d==n+1: return 0
# print(i,d)
left=dfs(2*i,d+1)
right=dfs(2*i+1,d+1)
ans+=abs(left-right)
return max(left,right)+a[i]
dfs(1,0)
print(ans) | Title: Om Nom and Dark Park
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless a... | ```python
n=int(input())
a=[0,0]+list(map(int,input().split()))
# print(a)
ans=0
def dfs(i,d):
global ans
if d==n+1: return 0
# print(i,d)
left=dfs(2*i,d+1)
right=dfs(2*i+1,d+1)
ans+=abs(left-right)
return max(left,right)+a[i]
dfs(1,0)
print(ans)
``` | 3 | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,613,769,956 | 2,147,483,647 | PyPy 3 | OK | TESTS | 83 | 186 | 0 | '''
Jana Goodman6
6a construct triangle from 4 stick
'''
SPACE = ' '
TRI = 'TRIANGLE'
SEG = 'SEGMENT'
IMP = 'IMPOSSIBLE'
def case(a, b, c):
# good: long side < sum(2 shortest)
# SEGMENT: long side = sum(2 shortest)
if c < a + b:
return TRI
if c == a + b:
return SEG
... | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
'''
Jana Goodman6
6a construct triangle from 4 stick
'''
SPACE = ' '
TRI = 'TRIANGLE'
SEG = 'SEGMENT'
IMP = 'IMPOSSIBLE'
def case(a, b, c):
# good: long side < sum(2 shortest)
# SEGMENT: long side = sum(2 shortest)
if c < a + b:
return TRI
if c == a + b:
r... | 3.9535 |
909 | B | Segments | PROGRAMMING | 1,300 | [
"constructive algorithms",
"math"
] | null | null | You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoin... | The only input line contains a single integer *N* (1<=≤<=*N*<=≤<=100). | Output a single integer - the minimal number of layers required to draw the segments for the given *N*. | [
"2\n",
"3\n",
"4\n"
] | [
"2\n",
"4\n",
"6\n"
] | As an example, here are the segments and their optimal arrangement into layers for *N* = 4. | 1,000 | [
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "4"
},
{
"input": "4",
"output": "6"
},
{
"input": "21",
"output": "121"
},
{
"input": "100",
"output": "2550"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "9"
... | 1,514,452,611 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 5,529,600 | n = int(input())
print(round((n/2+1)*n/2))
| Title: Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in se... | ```python
n = int(input())
print(round((n/2+1)*n/2))
``` | 3 | |
610 | C | Harmony Analysis | PROGRAMMING | 1,800 | [
"constructive algorithms"
] | null | null | The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vec... | The only line of the input contains a single integer *k* (0<=≤<=*k*<=≤<=9). | Print 2*k* lines consisting of 2*k* characters each. The *j*-th character of the *i*-th line must be equal to '<=*<=' if the *j*-th coordinate of the *i*-th vector is equal to <=-<=1, and must be equal to '<=+<=' if it's equal to <=+<=1. It's guaranteed that the answer always exists.
If there are many correct answers,... | [
"2\n"
] | [
"++**\n+*+*\n++++\n+**+"
] | Consider all scalar products in example:
- Vectors 1 and 2: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( + 1) + ( - 1)·( - 1) = 0 - Vectors 1 and 3: ( + 1)·( + 1) + ( + 1)·( + 1) + ( - 1)·( + 1) + ( - 1)·( + 1) = 0 - Vectors 1 and 4: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( - 1) + ( - 1)·( + 1) = 0 - Vectors 2 and 3: ... | 1,500 | [
{
"input": "2",
"output": "++++\n+*+*\n++**\n+**+"
},
{
"input": "1",
"output": "++\n+*"
},
{
"input": "3",
"output": "++++++++\n+*+*+*+*\n++**++**\n+**++**+\n++++****\n+*+**+*+\n++****++\n+**+*++*"
},
{
"input": "0",
"output": "+"
},
{
"input": "4",
"output":... | 1,451,584,006 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | k = int(input())
answer = [['+', '+'], ['+', '*']]
length = 2
for i in range(k - 1):
new = []
for i in answer:
temp = []
for j in range(length):
if i[j] == '+':
temp += ['+', '+']
else:
temp += ['*', '*']
new.append(te... | Title: Harmony Analysis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave t... | ```python
k = int(input())
answer = [['+', '+'], ['+', '*']]
length = 2
for i in range(k - 1):
new = []
for i in answer:
temp = []
for j in range(length):
if i[j] == '+':
temp += ['+', '+']
else:
temp += ['*', '*']
new... | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,650,399,759 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 92 | 0 | i = int(input())
res = []
while i > 0:
x = [int(i) for i in input().split()]
res.extend(x)
i-=1
if sum(res) == 0:
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
i = int(input())
res = []
while i > 0:
x = [int(i) for i in input().split()]
res.extend(x)
i-=1
if sum(res) == 0:
print("YES")
else:
print("NO")
``` | 0 |
1,009 | B | Minimum Ternary String | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For e... | The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). | Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). | [
"100210\n",
"11222121\n",
"20\n"
] | [
"001120\n",
"11112222\n",
"20\n"
] | none | 0 | [
{
"input": "100210",
"output": "001120"
},
{
"input": "11222121",
"output": "11112222"
},
{
"input": "20",
"output": "20"
},
{
"input": "1002",
"output": "0012"
},
{
"input": "10",
"output": "01"
},
{
"input": "000021",
"output": "000012"
},
{
... | 1,564,988,946 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 1,843,200 | from collections import Counter
def main():
s = [c for c in input().strip()]
n = len(s)
start = 0
cnt = Counter()
found2 = False
for i in range(n):
cnt[s[i]] += 1
if s[i] == '2':
found2 = True
if s[i] == '0' and found2:
cnt['2'] -= ... | Title: Minimum Ternary String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) ... | ```python
from collections import Counter
def main():
s = [c for c in input().strip()]
n = len(s)
start = 0
cnt = Counter()
found2 = False
for i in range(n):
cnt[s[i]] += 1
if s[i] == '2':
found2 = True
if s[i] == '0' and found2:
cn... | 0 | |
844 | B | Rectangles | PROGRAMMING | 1,300 | [
"combinatorics",
"math"
] | null | null | You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column. | The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly.
The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored wh... | Output single integer — the number of non-empty sets from the problem description. | [
"1 1\n0\n",
"2 3\n1 0 1\n0 1 0\n"
] | [
"1\n",
"8\n"
] | In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets. | 1,000 | [
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "2 3\n1 0 1\n0 1 0",
"output": "8"
},
{
"input": "2 2\n1 1\n1 1",
"output": "8"
},
{
"input": "1 10\n0 0 0 0 0 0 0 0 0 0",
"output": "1023"
},
{
"input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "2047"... | 1,649,221,295 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | N,M = map(int ,input().split())
A = []
for _ in range(N):
A.append(list(map(int, input().split())))
ans = N*M
for k in range(N):
for i in range(M):
for j in range(i+1,M):
if A[k][i]==A[k][j]:
ans += 1
for k in range(M):
for i in range(N):
for j in range(i+1,N):
if A[i][k]==A[j][k]:
... | Title: Rectangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or ... | ```python
N,M = map(int ,input().split())
A = []
for _ in range(N):
A.append(list(map(int, input().split())))
ans = N*M
for k in range(N):
for i in range(M):
for j in range(i+1,M):
if A[k][i]==A[k][j]:
ans += 1
for k in range(M):
for i in range(N):
for j in range(i+1,N):
if A[i][k]==... | 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,694,247,993 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | str_list = input().split()
m = int(str_list[0])
n = int(str_list[1])
a = int(str_list[2])
if m % a = 0:
length = m // a
else:
length = m // a + 1
if n % a = 0:
width = n // a
else:
width = n // a + 1
result = length * width
print(result) | 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
str_list = input().split()
m = int(str_list[0])
n = int(str_list[1])
a = int(str_list[2])
if m % a = 0:
length = m // a
else:
length = m // a + 1
if n % a = 0:
width = n // a
else:
width = n // a + 1
result = length * width
print(result)
``` | -1 |
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7... | 1,695,822,659 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | n = int(input())
first_list = list(map(int, input().split()))
ans_list = 0
max_len = 1
for i in range(len(first_list)):
if first_list[i - 1] < first_list[i]:
ans_list += 1
else:
ans_list = 1
print(ans_list)
| Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called... | ```python
n = int(input())
first_list = list(map(int, input().split()))
ans_list = 0
max_len = 1
for i in range(len(first_list)):
if first_list[i - 1] < first_list[i]:
ans_list += 1
else:
ans_list = 1
print(ans_list)
``` | 0 | |
369 | B | Valera and Contest | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valer... | The first line of the input contains exactly six integers *n*,<=*k*,<=*l*,<=*r*,<=*s**all*,<=*s**k* (1<=≤<=*n*,<=*k*,<=*l*,<=*r*<=≤<=1000; *l*<=≤<=*r*; *k*<=≤<=*n*; 1<=≤<=*s**k*<=≤<=*s**all*<=≤<=106).
It's guaranteed that the input is such that the answer exists. | Print exactly *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order. | [
"5 3 1 3 13 9\n",
"5 3 1 3 15 9\n"
] | [
"2 3 2 3 3 ",
"3 3 3 3 3 "
] | none | 1,000 | [
{
"input": "5 3 1 3 13 9",
"output": "2 3 2 3 3 "
},
{
"input": "5 3 1 3 15 9",
"output": "3 3 3 3 3 "
},
{
"input": "50 25 1 1 50 25",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "1000 700 782... | 1,589,473,051 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 140 | 20,172,800 | n,k,l,r,sa,s=map(int,input().split())
rm=s%k
print((( (str(s//k)) +' ' )*(k-rm))+((str((s//k)+1)+' ')*rm),end='')
if sa !=s:
re=sa-s
z2=re%(n-k)
print(((str(re//(n-k))+' ')*(n-k-z2))+((str((re//(n-k))+1)+' ')*z2))
| Title: Valera and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual c... | ```python
n,k,l,r,sa,s=map(int,input().split())
rm=s%k
print((( (str(s//k)) +' ' )*(k-rm))+((str((s//k)+1)+' ')*rm),end='')
if sa !=s:
re=sa-s
z2=re%(n-k)
print(((str(re//(n-k))+' ')*(n-k-z2))+((str((re//(n-k))+1)+' ')*z2))
``` | 3 | |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,643,612,701 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | l=[[1,1,1],[1,1,1],[1,1,1]]
for i in range(3):
z=list(map(int,input().split()))
for j in range(3):
if z[j]%2==1:
if j+1<3:
l[i][j+1]=(l[i][j+1]+1)%2
if i+1<3:
l[i+1][j]=(l[i+1][j]+1)%2
if j-1>=0:
l[i][j-1]=(l[i][j-1]+1)%2
if i-1>=0:
l[i-1][j]=(l[i-1][j]+1)%2
l[i][j]=(l[i]... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
l=[[1,1,1],[1,1,1],[1,1,1]]
for i in range(3):
z=list(map(int,input().split()))
for j in range(3):
if z[j]%2==1:
if j+1<3:
l[i][j+1]=(l[i][j+1]+1)%2
if i+1<3:
l[i+1][j]=(l[i+1][j]+1)%2
if j-1>=0:
l[i][j-1]=(l[i][j-1]+1)%2
if i-1>=0:
l[i-1][j]=(l[i-1][j]+1)%2
l[i... | 3 | |
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,593,680,498 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 280 | 0 | a, b = map(int, input().split(' '))
a = max(a, b)
if a == 1:
a = '1/1'
elif a == 2:
a = '5/6'
elif a == 3:
a = '2/3'
elif a == 4:
a = '1/2'
elif a == 5:
a = '1/3'
elif a == 6:
a = '1/6'
print(a)
| 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
a, b = map(int, input().split(' '))
a = max(a, b)
if a == 1:
a = '1/1'
elif a == 2:
a = '5/6'
elif a == 3:
a = '2/3'
elif a == 4:
a = '1/2'
elif a == 5:
a = '1/3'
elif a == 6:
a = '1/6'
print(a)
``` | 3.86 |
920 | B | Tea Queue | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Recently *n* students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
*i*-th s... | The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=1000).
Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of students.
Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=... | For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea. | [
"2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n"
] | [
"1 2 \n1 0 2 \n"
] | The example contains 2 tests:
1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and ... | 0 | [
{
"input": "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3",
"output": "1 2 \n1 0 2 "
},
{
"input": "19\n1\n1 1\n1\n1 2\n1\n1 1000\n1\n1 2000\n1\n2 2\n1\n2 3\n1\n2 1000\n1\n2 2000\n1\n1999 1999\n1\n1999 2000\n1\n2000 2000\n2\n1 1\n1 1\n2\n1 1\n1 2\n2\n1 2\n1 1\n2\n1 2000\n1 1\n2\n1 1\n1 2000\n2\n1 2000\n2 2\n2\n2... | 1,517,583,268 | 1,168 | Python 3 | OK | TESTS | 8 | 61 | 5,734,400 | t = int(input())
ans1 = []
for i in range(t):
n=int(input())
st=[]
for i in range(n):
l,r = map(int,input().split())
st.append((l,r,i))
st = sorted(st, key=lambda x: (x[0], x[2]))
ans = []
f = -1
for s in st:
if s[1] < f:
ans.append(0)
... | Title: Tea Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently *n* students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use ... | ```python
t = int(input())
ans1 = []
for i in range(t):
n=int(input())
st=[]
for i in range(n):
l,r = map(int,input().split())
st.append((l,r,i))
st = sorted(st, key=lambda x: (x[0], x[2]))
ans = []
f = -1
for s in st:
if s[1] < f:
ans.append(... | 3 | |
557 | C | Arthur and Table | PROGRAMMING | 1,900 | [
"brute force",
"data structures",
"dp",
"greedy",
"math",
"sortings"
] | null | null | Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
In total the table Arthur bought has *n* legs, the length of the *i*-th leg is *l**i*.
Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number *d... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the initial number of legs in the table Arthur bought.
The second line of the input contains a sequence of *n* integers *l**i* (1<=≤<=*l**i*<=≤<=105), where *l**i* is equal to the length of the *i*-th leg of the table.
The third line of the input ... | Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable. | [
"2\n1 5\n3 2\n",
"3\n2 4 4\n1 1 1\n",
"6\n2 2 1 1 3 3\n4 3 5 5 2 1\n"
] | [
"2\n",
"0\n",
"8\n"
] | none | 1,500 | [
{
"input": "2\n1 5\n3 2",
"output": "2"
},
{
"input": "3\n2 4 4\n1 1 1",
"output": "0"
},
{
"input": "6\n2 2 1 1 3 3\n4 3 5 5 2 1",
"output": "8"
},
{
"input": "10\n20 1 15 17 11 2 15 3 16 3\n129 114 183 94 169 16 18 104 49 146",
"output": "652"
},
{
"input": "10\... | 1,435,683,339 | 6,939 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 46 | 0 | class Noha:
def __init__(self, dlzka, celkova_cena, pocet, vsetky_nohy):
self.dlzka = dlzka
self.celkova_cena = celkova_cena
self.pocet = pocet
self.vsetky_nohy = vsetky_nohy
def __repr__(self):
return 'D: {} - C: {} - P: {}\n'.format(self.dlzka, self.celkova_cena, self.pocet)
n = int(input())
legs = [(i... | Title: Arthur and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
In total the table Arthur bought has *n* legs, the length of the *i*-th leg is *l**i*.
Arth... | ```python
class Noha:
def __init__(self, dlzka, celkova_cena, pocet, vsetky_nohy):
self.dlzka = dlzka
self.celkova_cena = celkova_cena
self.pocet = pocet
self.vsetky_nohy = vsetky_nohy
def __repr__(self):
return 'D: {} - C: {} - P: {}\n'.format(self.dlzka, self.celkova_cena, self.pocet)
n = int(input())
... | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,590,820,384 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 184 | 0 | n=int(input())
sumat=0
for i in range(n):
z=list(map(int,input().split()))
sumat=sumat+sum(z)
if suma==0:
print('YES')
else:
print('NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n=int(input())
sumat=0
for i in range(n):
z=list(map(int,input().split()))
sumat=sumat+sum(z)
if suma==0:
print('YES')
else:
print('NO')
``` | -1 |
277 | A | Learning Languages | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu"
] | null | null | The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official la... | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of employees and the number of languages.
Then *n* lines follow — each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≤<=*k**i*<=≤<=*m*) — the number of languages the *i*-th employee knows. Next... | Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). | [
"5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n",
"8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n",
"2 2\n1 2\n0\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | 500 | [
{
"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5",
"output": "0"
},
{
"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1",
"output": "2"
},
{
"input": "2 2\n1 2\n0",
"output": "1"
},
{
"input": "2 2\n0\n0",
"output": "2"
},
{
"input": "5 5\n1 3\n0\n0\n2 4... | 1,672,814,063 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 186 | 3,379,200 | def main():
n, m = read_ints()
languages_per_employee = []
for _ in range(n):
k, *languages = read_ints()
languages_per_employee.append(set(languages))
if all(len(languages) == 0 for languages in languages_per_employee):
print(n)
return
dsu = DisjointSetU... | Title: Learning Languages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have th... | ```python
def main():
n, m = read_ints()
languages_per_employee = []
for _ in range(n):
k, *languages = read_ints()
languages_per_employee.append(set(languages))
if all(len(languages) == 0 for languages in languages_per_employee):
print(n)
return
dsu = Di... | 3 | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,639,293,096 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 92 | 0 | n = int(input())
a = list(map(int, input().split()))
eil = [sum(a[i::3]) for i in [0, 1, 2]]
if eil[0] == max(eil):
print("chest")
elif eil[1] == max(eil):
print("biceps")
else:
print("back") | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n = int(input())
a = list(map(int, input().split()))
eil = [sum(a[i::3]) for i in [0, 1, 2]]
if eil[0] == max(eil):
print("chest")
elif eil[1] == max(eil):
print("biceps")
else:
print("back")
``` | 3 | |
553 | C | Love Triangles | PROGRAMMING | 2,200 | [
"dfs and similar",
"dsu",
"graphs"
] | null | null | There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has *n* characters. The characters are labeled from 1 to *n*. Every pair of two characters can either mutually love each other or mutually hate each other ... | The first line of input will contain two integers *n*,<=*m* (3<=≤<=*n*<=≤<=100<=000, 0<=≤<=*m*<=≤<=100<=000).
The next *m* lines will contain the description of the known relationships. The *i*-th line will contain three integers *a**i*,<=*b**i*,<=*c**i*. If *c**i* is 1, then *a**i* and *b**i* are in love, otherwise, ... | Print a single integer equal to the number of ways to fill in the remaining pairs so that you are happy with every triangle modulo 1<=000<=000<=007. | [
"3 0\n",
"4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0\n",
"4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1\n"
] | [
"4\n",
"1\n",
"0\n"
] | In the first sample, the four ways are to:
- Make everyone love each other - Make 1 and 2 love each other, and 3 hate 1 and 2 (symmetrically, we get 3 ways from this).
In the second sample, the only possible solution is to make 1 and 3 love each other and 2 and 4 hate each other. | 1,000 | [
{
"input": "3 0",
"output": "4"
},
{
"input": "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0",
"output": "1"
},
{
"input": "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1",
"output": "0"
},
{
"input": "100000 0",
"output": "303861760"
},
{
"input": "100 3\n1 2 0\n2 3 0\n3 1 0",
"output": ... | 1,549,726,130 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 8 | 889 | 35,635,200 | class Node(object):
def __init__(self, label):
self.label = label
self.par = self
self.rank = 0
class DisjointSet(object):
def __init__(self, n):
self.n = n
self.nodes = [Node(i) for i in range(n)]
def find(self, u):
if u == u.par:
... | Title: Love Triangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has *n* characters. The characters are labeled from 1 t... | ```python
class Node(object):
def __init__(self, label):
self.label = label
self.par = self
self.rank = 0
class DisjointSet(object):
def __init__(self, n):
self.n = n
self.nodes = [Node(i) for i in range(n)]
def find(self, u):
if u == u.par:
... | -1 | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,561,744,728 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 280 | 0 | s = input()
letters = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']
for i in range(len(s)):
if s[-i - 1].isalpha() and s[-i - 1] in letters:
print('YES')
exit()
if s[-i - 1].isalpha() and s[-i - 1] not in letters:
print('NO')
exit()
| Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
s = input()
letters = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']
for i in range(len(s)):
if s[-i - 1].isalpha() and s[-i - 1] in letters:
print('YES')
exit()
if s[-i - 1].isalpha() and s[-i - 1] not in letters:
print('NO')
exit()
``` | 3.93 |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
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. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output... | 1,693,499,985 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 122 | 0 | import math
a, b = map(int, input().split())
if b < math.ceil(a/2):
print(2*(b-1)+1)
else:
print(2*(a-math.ceil(a/2))) | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ... | ```python
import math
a, b = map(int, input().split())
if b < math.ceil(a/2):
print(2*(b-1)+1)
else:
print(2*(a-math.ceil(a/2)))
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Alice and Bob begin their day with a quick game. They first choose a starting number *X*0<=≥<=3 and try to reach one million by the process described below.
Alice goes first and then they take alternating turns. In the *i*-th turn, the player whose turn it is selects a prime number smaller than the current number, an... | The input contains a single integer *X*2 (4<=≤<=*X*2<=≤<=106). It is guaranteed that the integer *X*2 is composite, that is, is not prime. | Output a single integer — the minimum possible *X*0. | [
"14\n",
"20\n",
"8192\n"
] | [
"6\n",
"15\n",
"8191\n"
] | In the first test, the smallest possible starting number is *X*<sub class="lower-index">0</sub> = 6. One possible course of the game is as follows:
- Alice picks prime 5 and announces *X*<sub class="lower-index">1</sub> = 10 - Bob picks prime 7 and announces *X*<sub class="lower-index">2</sub> = 14.
In the second ... | 0 | [
{
"input": "14",
"output": "6"
},
{
"input": "20",
"output": "15"
},
{
"input": "8192",
"output": "8191"
},
{
"input": "1000000",
"output": "998677"
},
{
"input": "959806",
"output": "239958"
},
{
"input": "1452",
"output": "1206"
},
{
"inp... | 1,520,700,670 | 4,570 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 62 | 5,632,000 | prime_number = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71
,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173
,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281
,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409
,419,4... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice and Bob begin their day with a quick game. They first choose a starting number *X*0<=≥<=3 and try to reach one million by the process described below.
Alice goes first and then they take alternating turns. In the *i*-th tu... | ```python
prime_number = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71
,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173
,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281
,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,4... | 0 | |
851 | B | Arpa and an exam about geometry | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old ... | The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct. | Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower). | [
"0 1 1 1 1 0\n",
"1 1 0 0 1000 1000\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test, you can't find any solution. | 1,000 | [
{
"input": "0 1 1 1 1 0",
"output": "Yes"
},
{
"input": "1 1 0 0 1000 1000",
"output": "No"
},
{
"input": "1 0 2 0 3 0",
"output": "No"
},
{
"input": "3 4 0 0 4 3",
"output": "Yes"
},
{
"input": "-1000000000 1 0 0 1000000000 1",
"output": "Yes"
},
{
"i... | 1,504,554,302 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 204,800 | from sys import stdin, stdout
INF = float('inf')
def angle(a, b):
return (a[0] * b[1] - a[1] * b[0])
def find_coordinates(x1, y1, x2, y2, x3, y3):
A = x2 - x1
B = y2 - y1
C = x3 - x1
D = y3 - y1
E = A * (x1 + x2) + B * (y1 + y2)
F = C * (x1 + x3) + D * (y1 + y3)
G = ... | Title: Arpa and an exam about geometry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle... | ```python
from sys import stdin, stdout
INF = float('inf')
def angle(a, b):
return (a[0] * b[1] - a[1] * b[0])
def find_coordinates(x1, y1, x2, y2, x3, y3):
A = x2 - x1
B = y2 - y1
C = x3 - x1
D = y3 - y1
E = A * (x1 + x2) + B * (y1 + y2)
F = C * (x1 + x3) + D * (y1 + y3)... | 0 | |
257 | A | Sockets | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"sortings"
] | null | null | Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supp... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=50) —... | Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1. | [
"3 5 3\n3 1 2\n",
"4 7 2\n3 3 2 4\n",
"5 5 1\n1 3 1 2 1\n"
] | [
"1\n",
"2\n",
"-1\n"
] | In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to ... | 500 | [
{
"input": "3 5 3\n3 1 2",
"output": "1"
},
{
"input": "4 7 2\n3 3 2 4",
"output": "2"
},
{
"input": "5 5 1\n1 3 1 2 1",
"output": "-1"
},
{
"input": "4 5 8\n3 2 4 3",
"output": "0"
},
{
"input": "5 10 1\n4 3 4 2 4",
"output": "3"
},
{
"input": "7 13 2... | 1,585,747,495 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 280 | 0 | from sys import stdin,stdout
ii1 = lambda: int(stdin.readline())
is1 = lambda: stdin.readline()
iia = lambda : map(int, stdin.readline().split())
isa = lambda: stdin.readline().split()
n, m, k = iia()
arr = sorted(iia(),reverse = True)
count = 0
for i in arr:
if m <= k:
print(count)
b... | Title: Sockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his f... | ```python
from sys import stdin,stdout
ii1 = lambda: int(stdin.readline())
is1 = lambda: stdin.readline()
iia = lambda : map(int, stdin.readline().split())
isa = lambda: stdin.readline().split()
n, m, k = iia()
arr = sorted(iia(),reverse = True)
count = 0
for i in arr:
if m <= k:
print(count)
... | 3 | |
617 | B | Chocolate | PROGRAMMING | 1,300 | [
"combinatorics"
] | null | null | Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.
You are asked to calculate the number of ways he can... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of pieces in the chocolate bar.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1), where 0 represents a piece without the nut and 1 stands for a piece with the nut. | Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut. | [
"3\n0 1 0\n",
"5\n1 0 1 0 1\n"
] | [
"1\n",
"4\n"
] | In the first sample there is exactly one nut, so the number of ways equals 1 — Bob shouldn't make any breaks.
In the second sample you can break the bar in four ways:
10|10|1
1|010|1
10|1|01
1|01|01 | 1,000 | [
{
"input": "3\n0 1 0",
"output": "1"
},
{
"input": "5\n1 0 1 0 1",
"output": "4"
},
{
"input": "10\n0 0 1 0 0 0 1 1 0 1",
"output": "8"
},
{
"input": "20\n0 0 0 0 1 1 1 0 1 0 0 1 0 1 1 0 1 1 1 0",
"output": "24"
},
{
"input": "50\n0 1 1 1 1 1 1 0 1 1 0 1 1 1 0 0 1... | 1,694,574,135 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | def break_chocolate(n, pieces):
dp = [0] * (n + 1)
dp[0] = 1
for i in range(1, n + 1):
dp[i] = 0
for j in range(i):
if pieces[i - 1] == 1 or (i == n and j == 0):
dp[i] += dp[j]
return dp[n]
n = int(input())
chocolate = list(map(int, input().split()))
print... | Title: Chocolate
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any bre... | ```python
def break_chocolate(n, pieces):
dp = [0] * (n + 1)
dp[0] = 1
for i in range(1, n + 1):
dp[i] = 0
for j in range(i):
if pieces[i - 1] == 1 or (i == n and j == 0):
dp[i] += dp[j]
return dp[n]
n = int(input())
chocolate = list(map(int, input().split(... | 0 | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,584,684,029 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 109 | 0 | n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(len(l)):
if l[i]==0:
count += 1
for j in range(count):
l.remove(0)
print(len(set(l)))
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(len(l)):
if l[i]==0:
count += 1
for j in range(count):
l.remove(0)
print(len(set(l)))
``` | 3 | |
979 | B | Treasure Hunt | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination... | The first line contains an integer $n$ ($0 \leq n \leq 10^{9}$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $10^{5}$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the lengt... | Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw". | [
"3\nKuroo\nShiro\nKatie\n",
"7\ntreasurehunt\nthreefriends\nhiCodeforces\n",
"1\nabcabc\ncbabac\nababca\n",
"15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE\n"
] | [
"Kuro\n",
"Shiro\n",
"Katie\n",
"Draw\n"
] | In the first example, after $3$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $5$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $4$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Th... | 1,000 | [
{
"input": "3\nKuroo\nShiro\nKatie",
"output": "Kuro"
},
{
"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces",
"output": "Shiro"
},
{
"input": "1\nabcabc\ncbabac\nababca",
"output": "Katie"
},
{
"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE",
"output": "Draw"
},
{... | 1,666,098,147 | 1,047 | PyPy 3 | OK | TESTS | 184 | 93 | 4,505,600 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
x = [0] * 3
for i in range(3):
s = list(input().rstrip())
cnt = [0] * 130
for j in s:
cnt[j] += 1
m = max(cnt)
c = min(m + n, len(s))
if m == len(s) and n == 1:
c = m - ... | Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friend... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
x = [0] * 3
for i in range(3):
s = list(input().rstrip())
cnt = [0] * 130
for j in s:
cnt[j] += 1
m = max(cnt)
c = min(m + n, len(s))
if m == len(s) and n == 1:
... | 3 | |
818 | E | Card Game Again | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"number theory",
"two pointers"
] | null | null | Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of *n* cards and a magic number *k*. The order of the cards in the deck is fixed. Each card has a number written on it; number *a**i* is written on the *i*-th card in the deck.
After re... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=109).
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — the numbers written on the cards. | Print the number of ways to choose *x* and *y* so the resulting deck is valid. | [
"3 4\n6 2 8\n",
"3 6\n9 1 14\n"
] | [
"4\n",
"1\n"
] | In the first example the possible values of *x* and *y* are:
1. *x* = 0, *y* = 0; 1. *x* = 1, *y* = 0; 1. *x* = 2, *y* = 0; 1. *x* = 0, *y* = 1. | 0 | [
{
"input": "3 4\n6 2 8",
"output": "4"
},
{
"input": "3 6\n9 1 14",
"output": "1"
},
{
"input": "5 1\n1 3 1 3 1",
"output": "15"
},
{
"input": "5 1\n5 5 5 5 5",
"output": "15"
},
{
"input": "5 1\n5 4 4 4 4",
"output": "15"
},
{
"input": "100 1\n1 1 1 1... | 1,630,601,457 | 3,657 | PyPy 3 | OK | TESTS | 135 | 373 | 31,744,000 | import bisect
import sys
input = sys.stdin.readline
def prime_factorize(n):
ans = []
for i in range(2, int(n ** (1 / 2)) + 1):
while True:
if n % i:
break
ans.append(i)
n //= i
if n == 1:
break
if not n == 1:
... | Title: Card Game Again
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of *n* cards and a magic number *k*. The order of the cards in the deck is fixed. Eac... | ```python
import bisect
import sys
input = sys.stdin.readline
def prime_factorize(n):
ans = []
for i in range(2, int(n ** (1 / 2)) + 1):
while True:
if n % i:
break
ans.append(i)
n //= i
if n == 1:
break
if not n ... | 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,678,966,619 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n,m,a = map(int,input().split())
print(((n+a-1)/a)*((m+a-1)/a))
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m,a = map(int,input().split())
print(((n+a-1)/a)*((m+a-1)/a))
``` | 0 |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,696,410,709 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n, k = map(int, input().split())
time = int((240 - k)/5)
p = 0
while time>0:
time -= p+1
p+=1
if p > n:
print(n)
else:
print(p) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
n, k = map(int, input().split())
time = int((240 - k)/5)
p = 0
while time>0:
time -= p+1
p+=1
if p > n:
print(n)
else:
print(p)
``` | 0 | |
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
... | 1,616,150,137 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 154 | 0 | n=int(input())
print(((2*n-1)%1000000007)*((n-1)%1000000007)%1000000007) | Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each m... | ```python
n=int(input())
print(((2*n-1)%1000000007)*((n-1)%1000000007)%1000000007)
``` | 0 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,695,069,925 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 101 | 124 | 1,536,000 | n=int(input())
d={}
l=""
x=list(map(int, input().split(" ")))
for i in range(len(x)):
d[x[i]]=i+1
for i in range(1,n+1,1):
for j,k in d.items():
if j==i:
l+=str(k)+" "
print(l)
| Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n=int(input())
d={}
l=""
x=list(map(int, input().split(" ")))
for i in range(len(x)):
d[x[i]]=i+1
for i in range(1,n+1,1):
for j,k in d.items():
if j==i:
l+=str(k)+" "
print(l)
``` | 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,643,999,696 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 23,859,200 | n = input()
y = str(pow(1378,int (n)))
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
n = input()
y = str(pow(1378,int (n)))
print(y[len(y)-1])
``` | 0 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,680,722,091 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 62 | 0 | from math import floor
a,b = map(int,input().split())
f= min(a,b)
c= max(a,b)
c-=f
c= floor(c/2)
print(f,c) | 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
from math import floor
a,b = map(int,input().split())
f= min(a,b)
c= max(a,b)
c-=f
c= floor(c/2)
print(f,c)
``` | 3 | |
612 | C | Replace To Make Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"data structures",
"expression parsing",
"math"
] | null | null | You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following d... | The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106. | If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*. | [
"[<}){}\n",
"{()}[]\n",
"]]\n"
] | [
"2",
"0",
"Impossible"
] | none | 0 | [
{
"input": "[<}){}",
"output": "2"
},
{
"input": "{()}[]",
"output": "0"
},
{
"input": "]]",
"output": "Impossible"
},
{
"input": ">",
"output": "Impossible"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{}",
"output": "0"
},
{
"input": ... | 1,685,522,163 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 31 | 0 | s=input()
sl=[]
sll=[]
o={'>':'<','}':'{',']':'[',')':'('}
def of(c):
if o[c]==sl[-1]:
del sl[-1]
return
sl.append(c)
flag=0
for i in s:
if i in '<{[(':
sl.append(i)
continue
if []==sl:
print('Impossible')
flag=1
break
of(i)
cnt=0
if 0==flag... | Title: Replace To Make Regular Bracket Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another... | ```python
s=input()
sl=[]
sll=[]
o={'>':'<','}':'{',']':'[',')':'('}
def of(c):
if o[c]==sl[-1]:
del sl[-1]
return
sl.append(c)
flag=0
for i in s:
if i in '<{[(':
sl.append(i)
continue
if []==sl:
print('Impossible')
flag=1
break
of(i)
cnt=0
... | 0 | |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,645,889,819 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 124 | 0 | a=int(input())
d={}
for i in range(a):
a,b=map(str,input().split())
d.setdefault(b,[])
d[b].append(a)
c=0
for i,j in d.items():
j=set(j)
c+=len(j)
print(c)
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
a=int(input())
d={}
for i in range(a):
a,b=map(str,input().split())
d.setdefault(b,[])
d[b].append(a)
c=0
for i,j in d.items():
j=set(j)
c+=len(j)
print(c)
``` | 3.969 |
384 | A | Coder | PROGRAMMING | 800 | [
"implementation"
] | null | null | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1).
... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard.
On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'.
If there are multiple correct answers, you can print any. | [
"2\n"
] | [
"2\nC.\n.C\n"
] | none | 500 | [
{
"input": "2",
"output": "2\nC.\n.C"
},
{
"input": "3",
"output": "5\nC.C\n.C.\nC.C"
},
{
"input": "4",
"output": "8\nC.C.\n.C.C\nC.C.\n.C.C"
},
{
"input": "10",
"output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C... | 1,575,618,962 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 | n=int(input())
print(((n**2)+1)//2)
for x in range(1,n+1):
for y in range(1,n+1):
if x%2==1:
if y!=n:
if y%2==1:print("C",end="")
else:print(".",end="")
else:
print(".")
else:
if y!=n:
if y%2==1:print(".",end="")
else:print("C",end="")
else:
print("C") | Title: Coder
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or... | ```python
n=int(input())
print(((n**2)+1)//2)
for x in range(1,n+1):
for y in range(1,n+1):
if x%2==1:
if y!=n:
if y%2==1:print("C",end="")
else:print(".",end="")
else:
print(".")
else:
if y!=n:
if y%2==1:print(".",end="")
else:print("C",end="")
else:
print("C")
`... | 0 | |
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,658,038,820 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 1,000 | 102,400 | a,b=map(int,input().split())
ans=a
while a//b!=0:
ans+=a//b
a%=b
a+=ans
print(ans) | 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=map(int,input().split())
ans=a
while a//b!=0:
ans+=a//b
a%=b
a+=ans
print(ans)
``` | 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,913,127 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 307,200 | n = int(input())
li = list(input().split())
le=[]
lo=[]
for i in li:
if(int(i)%2 == 0):
le.append(i)
else:
lo.append(i)
if(len(le) == 1):
for i in range(len(li)):
if(le[0] == li[i]):
print(i+1)
elif(len(lo) == 1):
for i in range(len(li)):
if(lo[... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
li = list(input().split())
le=[]
lo=[]
for i in li:
if(int(i)%2 == 0):
le.append(i)
else:
lo.append(i)
if(len(le) == 1):
for i in range(len(li)):
if(le[0] == li[i]):
print(i+1)
elif(len(lo) == 1):
for i in range(len(li)):
... | 3.944928 |
0 | none | none | none | 0 | [
"none"
] | null | null | Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*.
Greg wrote down *k* qu... | The first line contains integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the initial array.
Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=... | On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the array after executing all the queries. Separate the printed numbers by spaces.
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 of the %I64d specifier. | [
"3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n",
"1 1 1\n1\n1 1 1\n1 1\n",
"4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n"
] | [
"9 18 17\n",
"2\n",
"5 18 31 20\n"
] | none | 0 | [
{
"input": "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3",
"output": "9 18 17"
},
{
"input": "1 1 1\n1\n1 1 1\n1 1",
"output": "2"
},
{
"input": "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3",
"output": "5 18 31 20"
},
{
"input": "1 1 1\n0\n1 1 0\n1 1... | 1,674,294,191 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 10 | 109 | 3,788,800 | import heapq
from collections import *
import math
def solve():
n, m, k = map(int, input().split())
arr = [int(i) for i in input().split()]
a = [0] * n
t = []
for _ in range(m):
l, r, d = map(int, input().split())
t.append([l, r, d])
for _ in range(k):
x, y ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements ... | ```python
import heapq
from collections import *
import math
def solve():
n, m, k = map(int, input().split())
arr = [int(i) for i in input().split()]
a = [0] * n
t = []
for _ in range(m):
l, r, d = map(int, input().split())
t.append([l, r, d])
for _ in range(k):
... | -1 | |
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million... | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "N... | 1,621,701,849 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | import math
n,x,y = map(int,input().split())
a = int(math.ceil((y/100)*n)) - x
print(a) | Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa... | ```python
import math
n,x,y = map(int,input().split())
a = int(math.ceil((y/100)*n)) - x
print(a)
``` | -1 | |
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,696,159,145 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 46 | 0 | n = int(input())
ans = (n+1)//2
if n % 2 == 1:
print(-ans)
else:
print(ans)
| 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
n = int(input())
ans = (n+1)//2
if n % 2 == 1:
print(-ans)
else:
print(ans)
``` | 3 | |
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all... | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3... | 1,398,182,675 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 122 | 0 | # -*- coding: utf-8 -*-
n = int(input())
def arrayWent(array, variants):
for variant in variants:
pos = [0,0]
mul = array[pos[0]][pos[1]]
for elem in variant:
if elem == 'R':
pos[1] += 1
elif elem == 'D':
pos[0] += 1
... | 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
# -*- coding: utf-8 -*-
n = int(input())
def arrayWent(array, variants):
for variant in variants:
pos = [0,0]
mul = array[pos[0]][pos[1]]
for elem in variant:
if elem == 'R':
pos[1] += 1
elif elem == 'D':
pos[0] ... | 0 |
548 | A | Mike and Fax | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages ... | The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000).
The second line contains integer *k* (1<=≤<=*k*<=≤<=1000). | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | [
"saba\n2\n",
"saddastavvat\n2\n"
] | [
"NO\n",
"YES\n"
] | Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | 500 | [
{
"input": "saba\n2",
"output": "NO"
},
{
"input": "saddastavvat\n2",
"output": "YES"
},
{
"input": "aaaaaaaaaa\n3",
"output": "NO"
},
{
"input": "aaaaaa\n3",
"output": "YES"
},
{
"input": "abaacca\n2",
"output": "NO"
},
{
"input": "a\n1",
"output"... | 1,622,871,302 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 11 | 202 | 2,048,000 | s=input()
n=int(input())
c=0
for i in range(0,len(s),len(s)//n):
#print(s[i:i+len(s)//n],s[i:i+len(s)//n][::-1])
if s[i:i+len(s)//n]==s[i:i+len(s)//n][::-1]:
c+=1
if c==n and len(s)%n==0:
print('YES')
else:
print('NO') | Title: Mike and Fax
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure ... | ```python
s=input()
n=int(input())
c=0
for i in range(0,len(s),len(s)//n):
#print(s[i:i+len(s)//n],s[i:i+len(s)//n][::-1])
if s[i:i+len(s)//n]==s[i:i+len(s)//n][::-1]:
c+=1
if c==n and len(s)%n==0:
print('YES')
else:
print('NO')
``` | -1 | |
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,595,941,624 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 7,372,800 | n, m = map(int, input().split())
words = {}
for _ in range(m):
a, b = map(str, input().split())
if len(a) < len(b) or len(a) == len(b):
words[b] = a
else:
words[a] = b
a = list(map(str, input().split()))
for i in range(n):
if a[i] in words:
a[i] = words[a[i]]
print(*a... | Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
n, m = map(int, input().split())
words = {}
for _ in range(m):
a, b = map(str, input().split())
if len(a) < len(b) or len(a) == len(b):
words[b] = a
else:
words[a] = b
a = list(map(str, input().split()))
for i in range(n):
if a[i] in words:
a[i] = words[a[i]]... | 3 | |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,689,936,402 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 62 | 0 | n = int(input())
height = list(map(int, input().split()))
max = height[0]
min = height[0]
max_i = 0
min_i = 0
for i in range(n):
if height[i] > max: # 가장 앞에 있는 최댓값 구하기
max = height[i]
max_i = i
if height[i] <= min: # 가장 뒤에 있는 최댓값 구하기
min = height[i]
min_i = i
... | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
n = int(input())
height = list(map(int, input().split()))
max = height[0]
min = height[0]
max_i = 0
min_i = 0
for i in range(n):
if height[i] > max: # 가장 앞에 있는 최댓값 구하기
max = height[i]
max_i = i
if height[i] <= min: # 가장 뒤에 있는 최댓값 구하기
min = height[i]
m... | 3 | |
990 | A | Commentary Boxes | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations wil... | The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box. | Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$. | [
"9 7 3 8\n",
"2 7 3 7\n",
"30 6 17 19\n"
] | [
"15\n",
"14\n",
"0\n"
] | In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes eq... | 0 | [
{
"input": "9 7 3 8",
"output": "15"
},
{
"input": "2 7 3 7",
"output": "14"
},
{
"input": "30 6 17 19",
"output": "0"
},
{
"input": "500000000001 1000000000000 100 100",
"output": "49999999999900"
},
{
"input": "1000000000000 750000000001 10 100",
"output": "... | 1,535,703,058 | 2,147,483,647 | Python 3 | OK | TESTS | 109 | 124 | 0 | n, m, a, b = map(int, input().split())
aa = m - (n % m)
bb = n % m
print(min(aa*a, bb*b)) | Title: Commentary Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation shou... | ```python
n, m, a, b = map(int, input().split())
aa = m - (n % m)
bb = n % m
print(min(aa*a, bb*b))
``` | 3 | |
475 | A | Bayan Bus | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
The event coordinator has a list of *k* participants who should be picked up at the airport. When a... | The only line of input contains integer *k*, (0<=≤<=*k*<=≤<=34), denoting the number of participants. | Print the figure of a bus with *k* passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six ... | [
"9\n",
"20\n"
] | [
"+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+\n",
"+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|... | none | 500 | [
{
"input": "9",
"output": "+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "20",
"output": "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.... | 1,414,050,618 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 62 | 0 | from sys import stdin
def main():
n=int(stdin.readline().strip())
b=[['+','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','+'],['|','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','|','D','|',')'],['|','#','.','#','.','#'... | Title: Bayan Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
The ... | ```python
from sys import stdin
def main():
n=int(stdin.readline().strip())
b=[['+','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','+'],['|','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','#','.','|','D','|',')'],['|','#','.','... | 3 | |
598 | D | Igor In the Museum | PROGRAMMING | 1,700 | [
"dfs and similar",
"graphs",
"shortest paths"
] | null | null | Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one i... | First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process.
Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that ... | Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position. | [
"5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n",
"4 4 1\n****\n*..*\n*.**\n****\n3 2\n"
] | [
"6\n4\n10\n",
"8\n"
] | none | 0 | [
{
"input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3",
"output": "6\n4\n10"
},
{
"input": "4 4 1\n****\n*..*\n*.**\n****\n3 2",
"output": "8"
},
{
"input": "3 3 1\n***\n*.*\n***\n2 2",
"output": "4"
},
{
"input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\... | 1,682,109,320 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n, m = map(int, input().split())
s = [input() for i in range(n)]
vis = [[0] * m for i in range(n)]
vis2 = [[0] * m for i in range(n)]
dist = [[0] * m for i in range(n)]
def DFS(i, j):
if (vis[i][j] and s[i][j] == '.') or i < 0 or j < 0 or i >= n or j >= m:
return 0
if s[i][j] == '*':
... | Title: Igor In the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.'... | ```python
n, m = map(int, input().split())
s = [input() for i in range(n)]
vis = [[0] * m for i in range(n)]
vis2 = [[0] * m for i in range(n)]
dist = [[0] * m for i in range(n)]
def DFS(i, j):
if (vis[i][j] and s[i][j] == '.') or i < 0 or j < 0 or i >= n or j >= m:
return 0
if s[i][j] == ... | -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,633,402,160 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 61 | 6,963,200 | #https://codeforces.com/problemset/problem/58/A
s = input()
j = 0
if s[0] == "h":
j += 1
l_flag = True
for i in range(1, len(s)):
if s[i] == s[i-1] and l_flag:
continue
if s[i] == "hello"[j]:
if j == 4:
j += 1
break
j += 1
if j == 3: l_flag = False
else: l_flag = True
co... | 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
#https://codeforces.com/problemset/problem/58/A
s = input()
j = 0
if s[0] == "h":
j += 1
l_flag = True
for i in range(1, len(s)):
if s[i] == s[i-1] and l_flag:
continue
if s[i] == "hello"[j]:
if j == 4:
j += 1
break
j += 1
if j == 3: l_flag = False
else: l_flag = T... | 3.95653 |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,624,332,947 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 62 | 0 |
a,b = [int(i) for i in input().split()]
pa =0
pb = 0
pd = 0
if a > b:
numdis = a-b-1
if numdis%2 !=0:
pd+=1
max_ = b + int(numdis/2)
pb = max_
pa = 6- max_ -pd
elif a == b:
pd = 6
else:
numdis = b-a-1
if numdis%2 !=0:
pd+=1
max_ = a + int(numdis/2)
pa = max_
pb = 6- max_ - pd
... | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
a,b = [int(i) for i in input().split()]
pa =0
pb = 0
pd = 0
if a > b:
numdis = a-b-1
if numdis%2 !=0:
pd+=1
max_ = b + int(numdis/2)
pb = max_
pa = 6- max_ -pd
elif a == b:
pd = 6
else:
numdis = b-a-1
if numdis%2 !=0:
pd+=1
max_ = a + int(numdis/2)
pa = max_
pb = 6- ... | 3 | |
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power us... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,698,637,184 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def last_two_digits_of_5_power_n(n):
result = pow(5, n, 100)
result_str = str(result)
if result < 10:
result_str = "0" + result_str
return result_str
def main():
n = int(input("Enter the value of n: "))
result = last_two_digits_of_5_power_n(n)
print(result)
if __name__ ... | Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and ge... | ```python
def last_two_digits_of_5_power_n(n):
result = pow(5, n, 100)
result_str = str(result)
if result < 10:
result_str = "0" + result_str
return result_str
def main():
n = int(input("Enter the value of n: "))
result = last_two_digits_of_5_power_n(n)
print(result)
if... | 0 | |
656 | F | Ace It! | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output a single integer. | The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). | Output a single integer. | [
"A221033\n",
"A223635\n",
"A232726\n"
] | [
"21\n",
"22\n",
"23\n"
] | none | 0 | [
{
"input": "A221033",
"output": "21"
},
{
"input": "A223635",
"output": "22"
},
{
"input": "A232726",
"output": "23"
},
{
"input": "A102210",
"output": "25"
},
{
"input": "A231010",
"output": "26"
},
{
"input": "A222222",
"output": "13"
},
{
... | 1,459,579,249 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 4,608,000 | #5
k = str(int(input(), 16))
t = sum(map(int, k))
was = False
result = str(t)
while t > 32:
t -= 1
was = True
if was:
result = str(t)
result = result[1] + result[0]
print(result) | Title: Ace It!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output a single integer.
Input Specificat... | ```python
#5
k = str(int(input(), 16))
t = sum(map(int, k))
was = False
result = str(t)
while t > 32:
t -= 1
was = True
if was:
result = str(t)
result = result[1] + result[0]
print(result)
``` | 0 | |
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power us... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,695,383,519 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | z = int(input())
print (5**z) | Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and ge... | ```python
z = int(input())
print (5**z)
``` | 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,488,814,382 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | '''
http://codeforces.com/problemset/problem/779/A
'''
n = int(input())
groupA = list(map(int, input().split()))
groupB = list(map(int, input().split()))
def num_switches(n, groupA, groupB):
diff = [0, 0, 0, 0, 0]
for score in range(1, 6):
if abs(groupA.count(score) - groupB.count(score)) %... | 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
'''
http://codeforces.com/problemset/problem/779/A
'''
n = int(input())
groupA = list(map(int, input().split()))
groupB = list(map(int, input().split()))
def num_switches(n, groupA, groupB):
diff = [0, 0, 0, 0, 0]
for score in range(1, 6):
if abs(groupA.count(score) - groupB.count... | 0 | |
604 | B | More Cowbell | PROGRAMMING | 1,400 | [
"binary search",
"greedy"
] | null | null | Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a sin... | The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively.
The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000... | Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*. | [
"2 1\n2 5\n",
"4 3\n2 3 5 9\n",
"3 2\n3 5 7\n"
] | [
"7\n",
"9\n",
"8\n"
] | In the first sample, Kevin must pack his two cowbells into the same box.
In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.
In the third sample, the optimal solution is {3, 5} and {7}. | 1,000 | [
{
"input": "2 1\n2 5",
"output": "7"
},
{
"input": "4 3\n2 3 5 9",
"output": "9"
},
{
"input": "3 2\n3 5 7",
"output": "8"
},
{
"input": "20 11\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10 10\n3 15 31 61 63 63 68 94 98 100",
"outp... | 1,587,384,683 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 8 | 202 | 10,547,200 | from sys import stdin,stdout
from math import gcd,ceil
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
n, k = iia()
arr = iia()
res = []
l, r = 0,... | Title: More Cowbell
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order t... | ```python
from sys import stdin,stdout
from math import gcd,ceil
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
n, k = iia()
arr = iia()
res = []
... | -1 | |
289 | B | Polo the Penguin and Matrix | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add ... | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). | In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). | [
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] | [
"4\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"outpu... | 1,594,832,126 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 6,860,800 | str_inp=[int(ele) for ele in input().split(" ")]
n=str_inp[0]
m=str_inp[1]
d=str_inp[1]
flag=0
main_array=[]
count_for_moves=0
average=0
for i_index in range(0,n):
list_temp=[int(element) for element in input().split()]
main_array.append(list_temp)
average+=sum(list_temp)
# print(average)
avera... | Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represe... | ```python
str_inp=[int(ele) for ele in input().split(" ")]
n=str_inp[0]
m=str_inp[1]
d=str_inp[1]
flag=0
main_array=[]
count_for_moves=0
average=0
for i_index in range(0,n):
list_temp=[int(element) for element in input().split()]
main_array.append(list_temp)
average+=sum(list_temp)
# print(avera... | 0 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,677,242,305 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 92 | 0 | n = int(input())
sieve = [0 for i in range(n+1)]
for i in range(2,n+1):
if(sieve[i]==0):
x = 2*i
while(x<=n):
sieve[x]+=1
x+=i
c=0
for i in range(1,n+1):
if(sieve[i]==2):
c+=1
print(c) | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
n = int(input())
sieve = [0 for i in range(n+1)]
for i in range(2,n+1):
if(sieve[i]==0):
x = 2*i
while(x<=n):
sieve[x]+=1
x+=i
c=0
for i in range(1,n+1):
if(sieve[i]==2):
c+=1
print(c)
``` | 3.977 |
697 | B | Barnicle | PROGRAMMING | 1,400 | [
"brute force",
"implementation",
"math",
"strings"
] | null | null | Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.
Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance ... | The first and only line of input contains a single string of form *a*.*deb* where *a*, *d* and *b* are integers and *e* is usual character 'e' (0<=≤<=*a*<=≤<=9,<=0<=≤<=*d*<=<<=10100,<=0<=≤<=*b*<=≤<=100) — the scientific notation of the desired distance value.
*a* and *b* contain no leading zeros and *d* contains no... | Print the only real number *x* (the desired distance value) in the only line in its decimal notation.
Thus if *x* is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.
Otherwise print *x* in a form of *p*.*q* such that *p* is an integer that have no leading zeroe... | [
"8.549e2\n",
"8.549e3\n",
"0.33e0\n"
] | [
"854.9\n",
"8549\n",
"0.33\n"
] | none | 1,000 | [
{
"input": "8.549e2",
"output": "854.9"
},
{
"input": "8.549e3",
"output": "8549"
},
{
"input": "0.33e0",
"output": "0.33"
},
{
"input": "1.31e1",
"output": "13.1"
},
{
"input": "1.038e0",
"output": "1.038"
},
{
"input": "8.25983e5",
"output": "825... | 1,468,600,861 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 61 | 921,600 | from decimal import Decimal,getcontext
getcontext().prec=250
s = "{:.250f}".format(Decimal(input()))
print(s)
if '.' in s:
while s[-1] == '0':
s = s[:-1]
if s[-1] == '.':
s = s[:-1]
print(s) | Title: Barnicle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.
Barney asked the bar tender Carl abou... | ```python
from decimal import Decimal,getcontext
getcontext().prec=250
s = "{:.250f}".format(Decimal(input()))
print(s)
if '.' in s:
while s[-1] == '0':
s = s[:-1]
if s[-1] == '.':
s = s[:-1]
print(s)
``` | 0 | |
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output"... | 1,695,355,058 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | n=int(input())
a=[]
for i in range(n):
if i%2==0:
a.append("I hate")
else:
a.append("I love")
if i!=n-1:
a.append("that")
a.append("it")
print(" ".join(a)) | Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and... | ```python
n=int(input())
a=[]
for i in range(n):
if i%2==0:
a.append("I hate")
else:
a.append("I love")
if i!=n-1:
a.append("that")
a.append("it")
print(" ".join(a))
``` | 3 | |
1,006 | A | Adjacent Replacements | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!).
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps:
- Replace each occu... | The first line of the input contains one integer number $n$ ($1 \le n \le 1000$) — the number of elements in Mishka's birthday present (surprisingly, an array).
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array. | Print $n$ integers — $b_1, b_2, \dots, b_n$, where $b_i$ is the final value of the $i$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $a$. Note that you cannot change the order of elements in the array. | [
"5\n1 2 4 5 10\n",
"10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\n"
] | [
"1 1 3 5 9\n",
"9999 9 50605065 1 5 89 5 999999999 60506055 999999999\n"
] | The first example is described in the problem statement. | 0 | [
{
"input": "5\n1 2 4 5 10",
"output": "1 1 3 5 9"
},
{
"input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000",
"output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"
},
{
"input": "1\n999999999",
"output": "999999999"
},
{
"input": "1\n1000000000",... | 1,637,763,233 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def replace(a):
return (a-1) if (a%2==0) else (a+1)
def solve(arr,n):
for i in arr:
for j in range (0,n):
if arr[j]==i:
arr[j]=replace(arr[j]);
return " ".join(str(_) for _ in arr)
def main():
n = int(input())
arr = list(map(int, input().split(" ")))... | Title: Adjacent Replacements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!).
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjace... | ```python
def replace(a):
return (a-1) if (a%2==0) else (a+1)
def solve(arr,n):
for i in arr:
for j in range (0,n):
if arr[j]==i:
arr[j]=replace(arr[j]);
return " ".join(str(_) for _ in arr)
def main():
n = int(input())
arr = list(map(int, input().sp... | 0 | |
650 | A | Watchmen | PROGRAMMING | 1,400 | [
"data structures",
"geometry",
"math"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha... | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs... | 500 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
... | 1,578,466,177 | 2,147,483,647 | PyPy 3 | OK | TESTS | 71 | 1,980 | 49,971,200 | from collections import defaultdict
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
xCnt = defaultdict(int)
yCnt = defaultdict(int)
same = defaultdict(int)
for x, y in a:
xCnt[x] += 1
yCnt[y] += 1
same[(x, y)] += 1
ret = 0
for cnt in xCnt.values():
ret += cnt * ... | Title: Watchmen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They n... | ```python
from collections import defaultdict
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
xCnt = defaultdict(int)
yCnt = defaultdict(int)
same = defaultdict(int)
for x, y in a:
xCnt[x] += 1
yCnt[y] += 1
same[(x, y)] += 1
ret = 0
for cnt in xCnt.values():
ret... | 3 | |
948 | A | Protect Sheep | PROGRAMMING | 900 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or... | First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively.
Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' a... | If it is impossible to protect all sheep, output a single line with the word "No".
Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a she... | [
"6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n",
"1 2\nSW\n",
"5 5\n.S...\n...S.\nS....\n...S.\n.S...\n"
] | [
"Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n",
"No\n",
"Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n"
] | In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.
In the second example, there are no empty spots to put dogs that would guard the lone sheep.
In the third example, there are no wolves... | 500 | [
{
"input": "1 2\nSW",
"output": "No"
},
{
"input": "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S",
"output": "Yes\nDDDDWDWDWD\nDDDDDDDDDS\nDSDSDDDSDD\nWDDDDDDDSS\nDWDDWDDDDD\nDWDDDWDDDD\nSDDSDDDSDS\nDDDDWDDDSD\nDDSD... | 1,520,752,704 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def check(r,c):
if row[r][c+1]=='W' or row[r][c-1]=='W' or row[r+1][c]=='W' or row[r-1][c]=='W':
return 1
else:
return 0
r,c=map(int,raw_input().split())
row=[' '*1000]
for i in range(1,r+1):
row.append(raw_input())
row[i]=' '+row[i]
flag=0
for i in range(1,r+1):
for j ... | Title: Protect Sheep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is ... | ```python
def check(r,c):
if row[r][c+1]=='W' or row[r][c-1]=='W' or row[r+1][c]=='W' or row[r-1][c]=='W':
return 1
else:
return 0
r,c=map(int,raw_input().split())
row=[' '*1000]
for i in range(1,r+1):
row.append(raw_input())
row[i]=' '+row[i]
flag=0
for i in range(1,r+1):
... | -1 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,621,610,265 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 62 | 0 | k=int(input())
a=["Sheldon","Leonard","Penny","Rajesh","Howard"]
r=1
while(r*5<k):
k-=r*5
r*=2
print(a[(k-1)//r])
| Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
k=int(input())
a=["Sheldon","Leonard","Penny","Rajesh","Howard"]
r=1
while(r*5<k):
k-=r*5
r*=2
print(a[(k-1)//r])
``` | 3.969 |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,697,544,972 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 62 | 0 | tmp = input()
tmp = tmp.split()
n = int(tmp[0])
h = int(tmp[1])
friends = input()
friends = friends.split()
width = 0
for friend in friends:
if int(friend) > h:
width += 2
print(int(0.5 * width + len(friends))) | Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
tmp = input()
tmp = tmp.split()
n = int(tmp[0])
h = int(tmp[1])
friends = input()
friends = friends.split()
width = 0
for friend in friends:
if int(friend) > h:
width += 2
print(int(0.5 * width + len(friends)))
``` | 3 | |
476 | B | Dreamoon and WiFi | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"combinatorics",
"dp",
"math",
"probabilities"
] | null | null | Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, de... | The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes ... | Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. | [
"++-+-\n+-+-+\n",
"+-+-\n+-??\n",
"+++\n??-\n"
] | [
"1.000000000000\n",
"0.500000000000\n",
"0.000000000000\n"
] | For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="low... | 1,500 | [
{
"input": "++-+-\n+-+-+",
"output": "1.000000000000"
},
{
"input": "+-+-\n+-??",
"output": "0.500000000000"
},
{
"input": "+++\n??-",
"output": "0.000000000000"
},
{
"input": "++++++++++\n+++??++?++",
"output": "0.125000000000"
},
{
"input": "--+++---+-\n????????... | 1,653,754,588 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 512,000 | class Solution:
def solve(self, a, b):
pos_a, pos_b, n = 0, 0, 0
for char_a, char_b in zip(a, b):
if char_a == "+":
pos_a += 1
else:
pos_a -= 1
if char_b == "+":
pos_b += 1
elif char_b == "-":
... | Title: Dreamoon and WiFi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go... | ```python
class Solution:
def solve(self, a, b):
pos_a, pos_b, n = 0, 0, 0
for char_a, char_b in zip(a, b):
if char_a == "+":
pos_a += 1
else:
pos_a -= 1
if char_b == "+":
pos_b += 1
elif char_b... | 0 | |
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,613,121,128 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | s = input()
p = 0
c = 0
for x in s:
if x.islower() == True: c += 1
else: p += 1
if p > c: print(s.upper())
if p < c or p == c: print(s.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s = input()
p = 0
c = 0
for x in s:
if x.islower() == True: c += 1
else: p += 1
if p > c: print(s.upper())
if p < c or p == c: print(s.lower())
``` | 3.969 |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,658,570,821 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n=input()
if 0 and 2 and 3 and 5 and 6 and 7 and 8 and 9 in n:print('No')
else:print('Yes') | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
n=input()
if 0 and 2 and 3 and 5 and 6 and 7 and 8 and 9 in n:print('No')
else:print('Yes')
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet... | The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$) — the maximum distance to Mars and the number of elements in the sequence $p$. | none | [
"5 2\n1\n-1\n-1\n1\n0\n"
] | [
"1\n2\n4\n5\n3\n"
] | In the example, hacking would look like this:
5 2 3
1 0
This means that the current distance to Mars is equal to $3$, Natasha knows that it does not exceed $5$, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ...
Really:
on the first query ($1$) the correct answer is $1$, the rocket... | 0 | [
{
"input": "5 2 3\n1 0",
"output": "3 queries, x=3"
},
{
"input": "1 1 1\n1",
"output": "1 queries, x=1"
},
{
"input": "3 2 3\n1 0",
"output": "4 queries, x=3"
},
{
"input": "6 3 5\n1 1 1",
"output": "5 queries, x=5"
},
{
"input": "10 4 3\n0 0 1 0",
"output": ... | 1,534,893,248 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 0 | import sys
n = [int(i) for i in input().split()]
low1 = 1
high1 = n[0]
low2 = 1
high2 = n[0]
count = 0
while(1>0):
mid1 = (low1 + high1)//2
mid2 = (low2 + high2)//2
if(count%n[1] == 0):
print(mid1)
sys.stdout.flush()
x = int(input())
if(x==1):
low1 = mid1 + 1
elif(x==-1):
high1 = mid1 - 1
else:
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. Sh... | ```python
import sys
n = [int(i) for i in input().split()]
low1 = 1
high1 = n[0]
low2 = 1
high2 = n[0]
count = 0
while(1>0):
mid1 = (low1 + high1)//2
mid2 = (low2 + high2)//2
if(count%n[1] == 0):
print(mid1)
sys.stdout.flush()
x = int(input())
if(x==1):
low1 = mid1 + 1
elif(x==-1):
high1 = mid1 - 1
... | 0 | |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ... | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c... | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ... | 1,680,575,580 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 63 | 77 | 13,107,200 | I, IN, M, R, LN, LS, P, S, ST, A, SO, MX, MN = int, input, map, range, len, list, print, sum, str, abs, sorted, max, min; inp = lambda: LS(M(I, IN().split()))
n, a, s, m = I(IN()), inp(), 0, 0
for i in a: s += i; m = MN(m, s)
P(A(m)) | Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of... | ```python
I, IN, M, R, LN, LS, P, S, ST, A, SO, MX, MN = int, input, map, range, len, list, print, sum, str, abs, sorted, max, min; inp = lambda: LS(M(I, IN().split()))
n, a, s, m = I(IN()), inp(), 0, 0
for i in a: s += i; m = MN(m, s)
P(A(m))
``` | 3 | |
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"inp... | 1,549,286,894 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | s=list(map(int,input.split()))
a=min(s[1],s[2])
print(min(a-(s[1]*s[2])//s[0],(s[1]*s[2])//s[0])) | Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Iv... | ```python
s=list(map(int,input.split()))
a=min(s[1],s[2])
print(min(a-(s[1]*s[2])//s[0],(s[1]*s[2])//s[0]))
``` | -1 | |
79 | B | Colorful Field | PROGRAMMING | 1,400 | [
"implementation",
"sortings"
] | B. Colorful Field | 2 | 256 | Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in f... | In the first line there are four positive integers *n*,<=*m*,<=*k*,<=*t* (1<=≤<=*n*<=≤<=4·104,<=1<=≤<=*m*<=≤<=4·104,<=1<=≤<=*k*<=≤<=103,<=1<=≤<=*t*<=≤<=103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in ... | For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. | [
"4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n"
] | [
"Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n"
] | The sample corresponds to the figure in the statement. | 1,000 | [
{
"input": "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1",
"output": "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots"
},
{
"input": "2 3 2 2\n1 1\n2 2\n2 1\n2 2",
"output": "Grapes\nWaste"
},
{
"input": "31 31 31 4\n4 9\n16 27\n11 29\n8 28\n11 2\n10 7\n22 6\n1 25\n14 8... | 1,697,011,094 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,969,600 | from collections import deque
from sys import stdin, stdout
input = stdin.readline
n,m,k,t = map(int, input().split().strip)
matrix = []
column = [None]
for i in range (n):
matrix.append(column*m)
for i in range(k):
a,b = map(int, input().split())
matrix[a-1][b-1] = 0
veggies = deque(['... | Title: Colorful Field
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
... | ```python
from collections import deque
from sys import stdin, stdout
input = stdin.readline
n,m,k,t = map(int, input().split().strip)
matrix = []
column = [None]
for i in range (n):
matrix.append(column*m)
for i in range(k):
a,b = map(int, input().split())
matrix[a-1][b-1] = 0
veggies ... | -1 |
254 | A | Cards with Numbers | PROGRAMMING | 1,200 | [
"constructive algorithms",
"sortings"
] | null | null | Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces. | If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You... | [
"3\n20 30 10 30 20 10\n",
"1\n1 2\n"
] | [
"4 2\n1 5\n6 3\n",
"-1"
] | none | 500 | [
{
"input": "3\n20 30 10 30 20 10",
"output": "4 2\n1 5\n6 3"
},
{
"input": "1\n1 2",
"output": "-1"
},
{
"input": "5\n2 2 2 2 2 1 2 2 1 2",
"output": "2 1\n3 4\n7 5\n6 9\n10 8"
},
{
"input": "5\n2 1 2 2 1 1 1 1 1 2",
"output": "3 1\n2 5\n7 6\n8 9\n10 4"
},
{
"inpu... | 1,655,485,591 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 47,923,200 | import math as mth
from collections import defaultdict,deque
from bisect import bisect_left as b_l
from bisect import bisect_right as b_r
import sys
sys.stdin=open("input.txt")
sys.stdout=open("output.txt",'w')
n=int(input())
a=[int(x) for x in input().split()]
cnt=defaultdict(int)
for i in a:
cnt[... | Title: Cards with Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card wit... | ```python
import math as mth
from collections import defaultdict,deque
from bisect import bisect_left as b_l
from bisect import bisect_right as b_r
import sys
sys.stdin=open("input.txt")
sys.stdout=open("output.txt",'w')
n=int(input())
a=[int(x) for x in input().split()]
cnt=defaultdict(int)
for i in a:... | 0 | |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i... | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "64009798... | 1,687,466,425 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 46 | 0 | minimum_number, maximum_number = map(int, input().split())
insuficient_number_in_interval = maximum_number - minimum_number + 1 < 3
is_minimum_number_odd = minimum_number % 2 == 1
if insuficient_number_in_interval or (is_minimum_number_odd and maximum_number - minimum_number + 1 < 4):
print('-1')
elif is_minimum... | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different st... | ```python
minimum_number, maximum_number = map(int, input().split())
insuficient_number_in_interval = maximum_number - minimum_number + 1 < 3
is_minimum_number_odd = minimum_number % 2 == 1
if insuficient_number_in_interval or (is_minimum_number_odd and maximum_number - minimum_number + 1 < 4):
print('-1')
elif ... | 3 | |
612 | D | The Union of k-Segments | PROGRAMMING | 1,800 | [
"greedy",
"sortings"
] | null | null | You are given *n* segments on the coordinate axis Ox and the number *k*. The point is satisfied if it belongs to at least *k* segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others. | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=106) — the number of segments and the value of *k*.
The next *n* lines contain two integers *l**i*,<=*r**i* (<=-<=109<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) each — the endpoints of the *i*-th segment. The segments can degenerate and intersect each other. ... | First line contains integer *m* — the smallest number of segments.
Next *m* lines contain two integers *a**j*,<=*b**j* (*a**j*<=≤<=*b**j*) — the ends of *j*-th segment in the answer. The segments should be listed in the order from left to right. | [
"3 2\n0 5\n-3 2\n3 8\n",
"3 2\n0 5\n-3 3\n3 8\n"
] | [
"2\n0 2\n3 5\n",
"1\n0 5\n"
] | none | 0 | [
{
"input": "3 2\n0 5\n-3 2\n3 8",
"output": "2\n0 2\n3 5"
},
{
"input": "3 2\n0 5\n-3 3\n3 8",
"output": "1\n0 5"
},
{
"input": "1 1\n-1 1",
"output": "1\n-1 1"
},
{
"input": "10 2\n27 96\n-22 45\n-68 26\n46 69\n-91 86\n12 73\n-89 76\n-11 33\n17 47\n-57 78",
"output": "1\... | 1,552,829,213 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 186 | 1,024,000 | n,k=[int(i) for i in input().split()]
otr=[]
st=[]
f=[]
for i in range(n):
s=[int(i) for i in input().split()]
st.append(s[0])
f.append(s[1])
res=0
line=min(st)
ends=[]
ressa=0
sign=0
while line<max(f):
ressa+=st.count(line)
ressa-=f.count(line)
if ressa>=k:
if sign==0:
... | Title: The Union of k-Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* segments on the coordinate axis Ox and the number *k*. The point is satisfied if it belongs to at least *k* segments. Find the smallest (by the number of segments) set of segments on the coordi... | ```python
n,k=[int(i) for i in input().split()]
otr=[]
st=[]
f=[]
for i in range(n):
s=[int(i) for i in input().split()]
st.append(s[0])
f.append(s[1])
res=0
line=min(st)
ends=[]
ressa=0
sign=0
while line<max(f):
ressa+=st.count(line)
ressa-=f.count(line)
if ressa>=k:
if... | -1 | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,697,382,290 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 26 | 31 | 0 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = sorted(set(a + b))
ans = "I become the guy."
for i in range(1,n+1):
if i in x:
continue
else:
ans = "Oh, my keyboard!"
break
print(ans)
| Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = sorted(set(a + b))
ans = "I become the guy."
for i in range(1,n+1):
if i in x:
continue
else:
ans = "Oh, my keyboard!"
break
print(ans)
``` | 0 | |
569 | A | Music | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite ... | The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=<<=*T*<=≤<=105). | Print a single integer — the number of times the song will be restarted. | [
"5 2 2\n",
"5 4 7\n",
"6 2 3\n"
] | [
"2\n",
"1\n",
"1\n"
] | In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test,... | 500 | [
{
"input": "5 2 2",
"output": "2"
},
{
"input": "5 4 7",
"output": "1"
},
{
"input": "6 2 3",
"output": "1"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "2 1 3",
"output": "1"
},
{
"input": "2 1 10000",
"output": "1"
},
{
"input": "12... | 1,685,431,460 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | if __name__ == "__main__":
target = int(input())
bacteria = 1
a = target % 2
print(bacteria + a) | Title: Music
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the... | ```python
if __name__ == "__main__":
target = int(input())
bacteria = 1
a = target % 2
print(bacteria + a)
``` | -1 | |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,586,250,461 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a,n,m=map(str,input().split())
for i in range(10):
b=a+str(i)
if int(b)%int(n)==0:
for j in range(int(m)-1):
b=str(b)
b=b+"0"
break
else:
b=a
if b==a:
print("-1)
else:
print(b)
| Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
a,n,m=map(str,input().split())
for i in range(10):
b=a+str(i)
if int(b)%int(n)==0:
for j in range(int(m)-1):
b=str(b)
b=b+"0"
break
else:
b=a
if b==a:
print("-1)
else:
print(b)
``` | -1 | |
740 | B | Alyona and flowers | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | null | null | Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choos... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother.
The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100).
The next *m* lines contain the description of the ... | Print single integer — the maximum possible value added to the Alyona's happiness. | [
"5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n",
"4 3\n1 2 3 4\n1 3\n2 4\n1 1\n",
"2 2\n-1 -2\n1 1\n1 2\n"
] | [
"7\n",
"16\n",
"0\n"
] | The first example is the situation described in the statements.
In the second example Alyona should choose all subarrays.
The third example has answer 0 because Alyona can choose none of the subarrays. | 1,000 | [
{
"input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4",
"output": "7"
},
{
"input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1",
"output": "16"
},
{
"input": "2 2\n-1 -2\n1 1\n1 2",
"output": "0"
},
{
"input": "5 6\n1 1 1 -1 0\n2 4\n1 3\n4 5\n1 5\n1 4\n4 5",
"output": "8"
},
{
"inpu... | 1,480,175,592 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | a=list(map(int,input().split(' ')))
b=list(map(int,input().split(' ')))
f=-101
e=0
for x in range (a[1]):
c=list(map(int,input().split(' ')))
d=sum(b[c[0]-1:c[1]])
if d>0:
e+=d
if d<=0 and d>f:
f=d
if e>0:
print(e)
else:
print(f)
| Title: Alyona and flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarra... | ```python
a=list(map(int,input().split(' ')))
b=list(map(int,input().split(' ')))
f=-101
e=0
for x in range (a[1]):
c=list(map(int,input().split(' ')))
d=sum(b[c[0]-1:c[1]])
if d>0:
e+=d
if d<=0 and d>f:
f=d
if e>0:
print(e)
else:
print(f)
``` | 0 | |
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,698,076,967 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 8,704,000 | a=int(input())
x=pow(1378,a)
print(x%10) | 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
a=int(input())
x=pow(1378,a)
print(x%10)
``` | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,674,885,734 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a=int(input())
while(t-->0):
s=input()
if(s.len()>10):
print(s[0],s.len()-2,s[s.len()-1])
else:
print(s) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
a=int(input())
while(t-->0):
s=input()
if(s.len()>10):
print(s[0],s.len()-2,s[s.len()-1])
else:
print(s)
``` | -1 |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,642,108,986 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 124 | 409,600 | from re import match
print(match(r"^(14?4?)*$", input()) and 'YES' or 'NO') | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
from re import match
print(match(r"^(14?4?)*$", input()) and 'YES' or 'NO')
``` | 3 | |
488 | A | Giga Tower | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it ... | The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). | Print the minimum *b* in a line. | [
"179\n",
"-1\n",
"18\n"
] | [
"1\n",
"9\n",
"10\n"
] | For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | 500 | [
{
"input": "179",
"output": "1"
},
{
"input": "-1",
"output": "9"
},
{
"input": "18",
"output": "10"
},
{
"input": "-410058385",
"output": "1"
},
{
"input": "-586825624",
"output": "1"
},
{
"input": "852318890",
"output": "1"
},
{
"input": ... | 1,489,747,757 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 4,608,000 | import sys
a = int(input())
p = 0
if a==0:
print(8)
sys.exit()
while True:
a+=1
p+=1
j=a
while j!=0:
if j%10==8:
print(p)
sys.exit()
else:
j=j//10
| Title: Giga Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Ever... | ```python
import sys
a = int(input())
p = 0
if a==0:
print(8)
sys.exit()
while True:
a+=1
p+=1
j=a
while j!=0:
if j%10==8:
print(p)
sys.exit()
else:
j=j//10
``` | 0 | |
199 | A | Hexadecimal's theorem | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"implementation",
"number theory"
] | null | null | Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F... | The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. | Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them. | [
"3\n",
"13\n"
] | [
"1 1 1\n",
"2 3 8\n"
] | none | 500 | [
{
"input": "3",
"output": "1 1 1"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input... | 1,692,965,408 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 62 | 0 | import math
def squ(x) :
if x>0 :
s=int(math.sqrt(x))
return s*s==x
n=int(input())
k=[]
for i in range(n-1,0,-1) :
if squ((i*i*5)-4) or squ((i*i*5)+4) :
k.append(i)
break
l=n-k[0]
k.append(k[0]-l)
k.append(l-k[1])
if n==0 :
print(0,0,0)
elif n==1 :
print(0,0... | Title: Hexadecimal's theorem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let'... | ```python
import math
def squ(x) :
if x>0 :
s=int(math.sqrt(x))
return s*s==x
n=int(input())
k=[]
for i in range(n-1,0,-1) :
if squ((i*i*5)-4) or squ((i*i*5)+4) :
k.append(i)
break
l=n-k[0]
k.append(k[0]-l)
k.append(l-k[1])
if n==0 :
print(0,0,0)
elif n==1 :
... | -1 | |
371 | D | Vessels | PROGRAMMING | 1,800 | [
"data structures",
"dsu",
"implementation",
"trees"
] | null | null | There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a**i* liters.
Initially, all the vessels are empty. In some vessels water is poured. All the w... | The first line contains integer *n* — the number of vessels (1<=≤<=*n*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the vessels' capacities (1<=≤<=*a**i*<=≤<=109). The vessels' capacities do not necessarily increase from the top vessels to the bottom ones (see the second sample). The t... | For each query, print on a single line the number of liters of water in the corresponding vessel. | [
"2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2\n",
"3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3\n"
] | [
"4\n5\n8\n",
"7\n10\n5\n"
] | none | 2,000 | [
{
"input": "2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2",
"output": "4\n5\n8"
},
{
"input": "3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3",
"output": "7\n10\n5"
},
{
"input": "10\n71 59 88 55 18 98 38 73 53 58\n20\n1 5 93\n1 7 69\n2 3\n1 1 20\n2 10\n1 6 74\n1 7 100\n1 9 14\n2 3\n... | 1,617,463,378 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 307,200 | n = int(input())
string = input().split()
vessels = []
transbordaEm = 300000
for i in range(n):
vessels.append([0,int(string[i])])
m = int(input())
for q in range(m):
query = input().split()
if(query[0] == '2'):
position = int(query[1]) - 1
print(vessels[position][0])
elif(query[0] == '1... | Title: Vessels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a*... | ```python
n = int(input())
string = input().split()
vessels = []
transbordaEm = 300000
for i in range(n):
vessels.append([0,int(string[i])])
m = int(input())
for q in range(m):
query = input().split()
if(query[0] == '2'):
position = int(query[1]) - 1
print(vessels[position][0])
elif(quer... | 0 | |
148 | B | Escape | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | The princess is going to escape the dragon's cave, and she needs to plan it carefully.
The princess runs at *v**p* miles per hour, and the dragon flies at *v**d* miles per hour. The dragon will discover the escape after *t* hours and will chase the princess immediately. Looks like there's no chance to success, but the... | The input data contains integers *v**p*,<=*v**d*,<=*t*,<=*f* and *c*, one per line (1<=≤<=*v**p*,<=*v**d*<=≤<=100, 1<=≤<=*t*,<=*f*<=≤<=10, 1<=≤<=*c*<=≤<=1000). | Output the minimal number of bijous required for the escape to succeed. | [
"1\n2\n1\n1\n10\n",
"1\n2\n1\n1\n8\n"
] | [
"2\n",
"1\n"
] | In the first case one hour after the escape the dragon will discover it, and the princess will be 1 mile away from the cave. In two hours the dragon will overtake the princess 2 miles away from the cave, and she will need to drop the first bijou. Return to the cave and fixing the treasury will take the dragon two more ... | 1,000 | [
{
"input": "1\n2\n1\n1\n10",
"output": "2"
},
{
"input": "1\n2\n1\n1\n8",
"output": "1"
},
{
"input": "5\n8\n1\n2\n100",
"output": "2"
},
{
"input": "2\n100\n10\n10\n739",
"output": "22"
},
{
"input": "17\n99\n2\n3\n293",
"output": "3"
},
{
"input": "5... | 1,698,301,128 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 62 | 0 | vp = int(input())
vd = int(input())
t = int(input())
f = int(input())
c = int(input())
iss = False
l = vp*t
ans = 0
if vp >= vd:
print(0)
iss = True
while True:
x = l*1/(vd-vp)
l += vp*x
if l - c >=0:
break
else:
ans += 1
l += (x + f) *vp
if iss==Fa... | Title: Escape
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The princess is going to escape the dragon's cave, and she needs to plan it carefully.
The princess runs at *v**p* miles per hour, and the dragon flies at *v**d* miles per hour. The dragon will discover the escape after *t* hou... | ```python
vp = int(input())
vd = int(input())
t = int(input())
f = int(input())
c = int(input())
iss = False
l = vp*t
ans = 0
if vp >= vd:
print(0)
iss = True
while True:
x = l*1/(vd-vp)
l += vp*x
if l - c >=0:
break
else:
ans += 1
l += (x + f) *vp
... | -1 | |
962 | B | Students in Railway Carriage | PROGRAMMING | 1,300 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of $a$ student-programmers and $b$ student-athletes. Determine the largest number of students from all $a+b$ students, which you can put in the railway carri... | The first line contain three integers $n$, $a$ and $b$ ($1 \le n \le 2\cdot10^{5}$, $0 \le a, b \le 2\cdot10^{5}$, $a + b > 0$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes.
The second line contains a string with length $n$, consisting o... | Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete. | [
"5 1 1\n*...*\n",
"6 2 3\n*...*.\n",
"11 3 10\n.*....**.*.\n",
"3 2 3\n***\n"
] | [
"2\n",
"4\n",
"7\n",
"0\n"
] | In the first example you can put all student, for example, in the following way: *.AB*
In the second example you can put four students, for example, in the following way: *BAB*B
In the third example you can put seven students, for example, in the following way: B*ABAB**A*B
The letter A means a student-programmer, an... | 0 | [
{
"input": "5 1 1\n*...*",
"output": "2"
},
{
"input": "6 2 3\n*...*.",
"output": "4"
},
{
"input": "11 3 10\n.*....**.*.",
"output": "7"
},
{
"input": "3 2 3\n***",
"output": "0"
},
{
"input": "9 5 3\n*...*...*",
"output": "6"
},
{
"input": "9 2 4\n*.... | 1,699,578,301 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define sz(s) (int)s.size()
#define pb push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
ll oo = 1e12;
int ioo = 1e9 + 7;
int mod = 1e9 +... | Title: Students in Railway Carriage
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of $a$ student-programmers and $b$ student-... | ```python
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define sz(s) (int)s.size()
#define pb push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
ll oo = 1e12;
int ioo = 1e9 + 7;
int m... | -1 | |
602 | A | Two Bases | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers *X* and *Y* realised that they have different bases, which complicated their relations.
You're given a number *X* represented in base *b**x* and a number *Y* represented in base *b**y*. Compare those two numbers. | The first line of the input contains two space-separated integers *n* and *b**x* (1<=≤<=*n*<=≤<=10, 2<=≤<=*b**x*<=≤<=40), where *n* is the number of digits in the *b**x*-based representation of *X*.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=<<=*b**x*) — the dig... | Output a single character (quotes for clarity):
- '<' if *X*<=<<=*Y* - '>' if *X*<=><=*Y* - '=' if *X*<==<=*Y* | [
"6 2\n1 0 1 1 1 1\n2 10\n4 7\n",
"3 3\n1 0 2\n2 5\n2 4\n",
"7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n"
] | [
"=\n",
"<\n",
">\n"
] | In the first sample, *X* = 101111<sub class="lower-index">2</sub> = 47<sub class="lower-index">10</sub> = *Y*.
In the second sample, *X* = 102<sub class="lower-index">3</sub> = 21<sub class="lower-index">5</sub> and *Y* = 24<sub class="lower-index">5</sub> = 112<sub class="lower-index">3</sub>, thus *X* < *Y*.
In ... | 500 | [
{
"input": "6 2\n1 0 1 1 1 1\n2 10\n4 7",
"output": "="
},
{
"input": "3 3\n1 0 2\n2 5\n2 4",
"output": "<"
},
{
"input": "7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0",
"output": ">"
},
{
"input": "2 2\n1 0\n2 3\n1 0",
"output": "<"
},
{
"input": "2 2\n1 0\n1 3\n1"... | 1,579,853,129 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 109 | 0 | Answer = []
for i in range(2):
Temp = list(map(int, input().split()))
Num = input().replace(" ", "")
Answer.append(int(Num, Temp[1]))
print("=" if Answer[1] == Answer[0] else ("<" if Answer[0] < Answer[1] else ">"))
# Show you deserve being the best to whom doesn't believe in you.
| Title: Two Bases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers *X* and *Y* realised that they have different bases, which complicated their relations.
You're given a number *X* represented in base *b**x* ... | ```python
Answer = []
for i in range(2):
Temp = list(map(int, input().split()))
Num = input().replace(" ", "")
Answer.append(int(Num, Temp[1]))
print("=" if Answer[1] == Answer[0] else ("<" if Answer[0] < Answer[1] else ">"))
# Show you deserve being the best to whom doesn't believe in you.
``` | 0 | |
614 | B | Gena's Code | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not en... | The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country.
It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total leng... | Print a single number without leading zeroes — the product of the number of tanks presented by each country. | [
"3\n5 10 1\n",
"4\n1 1 10 11\n",
"5\n0 3 1 100 1\n"
] | [
"50",
"110",
"0"
] | In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.
In sample 3 number 3 is not beautiful, all others are beautiful. | 1,000 | [
{
"input": "3\n5 10 1",
"output": "50"
},
{
"input": "4\n1 1 10 11",
"output": "110"
},
{
"input": "5\n0 3 1 100 1",
"output": "0"
},
{
"input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 ... | 1,474,461,722 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n = int(input())
ll = input().split()
zero = 0
nb = ''
flag = 1
for x in ll:
if x == '0':
flag = 0
break
else:
if x.count('1') == 1:
zero += len(x) - 1
else:
nb = x
if flag == 0:
print(0)
else:
print(nb + ('0' * zer... | Title: Gena's Code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from eac... | ```python
n = int(input())
ll = input().split()
zero = 0
nb = ''
flag = 1
for x in ll:
if x == '0':
flag = 0
break
else:
if x.count('1') == 1:
zero += len(x) - 1
else:
nb = x
if flag == 0:
print(0)
else:
print(nb + ... | 0 | |
903 | A | Hungry Student Problem | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | 0 | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\... | 1,568,638,820 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
for testcase in range(n):
a=int(input())
if a%3==0:
print("YES")
elif a%7==0
print("YES")
else
r=a%7
if r%3==0
print("YES")
else
print("NO") | Title: Hungry Student Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chun... | ```python
n=int(input())
for testcase in range(n):
a=int(input())
if a%3==0:
print("YES")
elif a%7==0
print("YES")
else
r=a%7
if r%3==0
print("YES")
else
print("NO")
``` | -1 | |
719 | A | Vitya in the Countryside | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.
Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=15) — Vitya's records.
It's guaranteed that the input data is consistent. | If Vitya can be sure that the size of visible part of the moon on day *n*<=+<=1 will be less than the size of the visible part on day *n*, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly ... | [
"5\n3 4 5 6 7\n",
"7\n12 13 14 15 14 13 12\n",
"1\n8\n"
] | [
"UP\n",
"DOWN\n",
"-1\n"
] | In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".
In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".
In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus t... | 500 | [
{
"input": "5\n3 4 5 6 7",
"output": "UP"
},
{
"input": "7\n12 13 14 15 14 13 12",
"output": "DOWN"
},
{
"input": "1\n8",
"output": "-1"
},
{
"input": "44\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10",
"out... | 1,535,644,781 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 109 | 0 | import sys
'''
'''
def main():
n = int(sys.stdin.readline())
moon = [int(x) for x in sys.stdin.readline().split()]
if n is 1:
print(-1)
else:
last1 = moon[n-1]
last2 = moon[n-2]
if last1 != 0:
if last2 > last1:
print("DOWN")
else... | Title: Vitya in the Countryside
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the momen... | ```python
import sys
'''
'''
def main():
n = int(sys.stdin.readline())
moon = [int(x) for x in sys.stdin.readline().split()]
if n is 1:
print(-1)
else:
last1 = moon[n-1]
last2 = moon[n-2]
if last1 != 0:
if last2 > last1:
print("DOWN")
... | 0 | |
299 | B | Ksusha the Squirrel | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know ... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters e... | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | [
"2 1\n..\n",
"5 2\n.#.#.\n",
"7 3\n.#.###.\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 1,000 | [
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "5 2\n.#.#.",
"output": "YES"
},
{
"input": "7 3\n.#.###.",
"output": "NO"
},
{
"input": "2 200\n..",
"output": "YES"
},
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "2 2\n..",
"output": "Y... | 1,622,127,460 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 154 | 1,024,000 | n,k=map(int,input().split())
print('YNEOS'['#'*k in input()::2]) | Title: Ksusha the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to t... | ```python
n,k=map(int,input().split())
print('YNEOS'['#'*k in input()::2])
``` | 3 | |
680 | A | Bear and Five Cards | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards wi... | The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards. | Print the minimum possible sum of numbers written on remaining cards. | [
"7 3 7 3 20\n",
"7 9 3 1 8\n",
"10 10 10 10 10\n"
] | [
"26\n",
"28\n",
"20\n"
] | In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20... | 500 | [
{
"input": "7 3 7 3 20",
"output": "26"
},
{
"input": "7 9 3 1 8",
"output": "28"
},
{
"input": "10 10 10 10 10",
"output": "20"
},
{
"input": "8 7 1 8 7",
"output": "15"
},
{
"input": "7 7 7 8 8",
"output": "16"
},
{
"input": "8 8 8 2 2",
"output"... | 1,583,400,380 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 155 | 0 | cards = list(map(int, input().split()))
cards.sort()
test=[]
for i in cards:
if cards.count(i)>1 and i not in test:
test.append(i)
compare=0
check=0
number=0
if test==[]:
print(sum(cards))
else:
for i in test:
compare= cards.count(i)*i
check=max(check, compare)
... | Title: Bear and Five Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers... | ```python
cards = list(map(int, input().split()))
cards.sort()
test=[]
for i in cards:
if cards.count(i)>1 and i not in test:
test.append(i)
compare=0
check=0
number=0
if test==[]:
print(sum(cards))
else:
for i in test:
compare= cards.count(i)*i
check=max(check, compa... | 3 | |
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris a... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and t... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ... | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
... | 1,621,773,518 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 77 | 0 | t=int(input())
rows=[]
flag=0
for temp in range(t):
rows.append(input())
for i in range(len(rows)):
if 'OO' in rows[i]:
print("YES")
idx=rows[i].index('OO')
temp=rows[i][:idx]+'++'+rows[i][idx+2:]
rows[i]=temp
flag=1
break
if flag==1:
for i in ... | Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pai... | ```python
t=int(input())
rows=[]
flag=0
for temp in range(t):
rows.append(input())
for i in range(len(rows)):
if 'OO' in rows[i]:
print("YES")
idx=rows[i].index('OO')
temp=rows[i][:idx]+'++'+rows[i][idx+2:]
rows[i]=temp
flag=1
break
if flag==1:
... | 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,628,655,988 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 154 | 6,963,200 | n = int(input(""))
l = []
for i in range(0,n):
o,m,p = str(input("")).split(" ")
o,m,p = int(o),int(m),int(p)
k = [o,m,p]
l.append(k)
x = 0
for i in range(0,len(l)):
x = 0
for j in range(0,3):
x += l[j][i]
if x != 0:
print("NO")
break
else:
print("... | 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(""))
l = []
for i in range(0,n):
o,m,p = str(input("")).split(" ")
o,m,p = int(o),int(m),int(p)
k = [o,m,p]
l.append(k)
x = 0
for i in range(0,len(l)):
x = 0
for j in range(0,3):
x += l[j][i]
if x != 0:
print("NO")
break
else:
... | 0 |
340 | A | The Wall | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints th... | The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*). | Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink. | [
"2 3 6 18\n"
] | [
"3"
] | Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. | 500 | [
{
"input": "2 3 6 18",
"output": "3"
},
{
"input": "4 6 20 201",
"output": "15"
},
{
"input": "15 27 100 10000",
"output": "74"
},
{
"input": "105 60 3456 78910",
"output": "179"
},
{
"input": "1 1 1000 100000",
"output": "99001"
},
{
"input": "3 2 5 5... | 1,698,350,185 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | import math
x, y, a, b = map(int, input().split())
lcms = x * y // math.gcd(x, y)
num_multiple = (b // lcms) - ((a - 1) // lcms)
print(num_multiple)
| Title: The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub ... | ```python
import math
x, y, a, b = map(int, input().split())
lcms = x * y // math.gcd(x, y)
num_multiple = (b // lcms) - ((a - 1) // lcms)
print(num_multiple)
``` | 3 | |
412 | C | Pattern | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.
In this task, a pattern will be a string con... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of patterns. Next *n* lines contain the patterns.
It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does no... | In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them. | [
"2\n?ab\n??b\n",
"2\na\nb\n",
"1\n?a?b\n"
] | [
"xab\n",
"?\n",
"cacb\n"
] | Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of ot... | 1,500 | [
{
"input": "2\n?ab\n??b",
"output": "xab"
},
{
"input": "2\na\nb",
"output": "?"
},
{
"input": "1\n?a?b",
"output": "cacb"
},
{
"input": "1\n?",
"output": "x"
},
{
"input": "3\nabacaba\nabacaba\nabacaba",
"output": "abacaba"
},
{
"input": "3\nabc?t\n?b... | 1,398,852,335 | 4,835 | Python 3 | OK | TESTS | 70 | 421 | 6,758,400 | n = int(input())
S = [0] * n
A = ''
for i in range(n):
S[i] = list(input())
for j in range(len(S[0])):
set0 = set()
for i in range(n):
set0.add(S[i][j])
set0 = ''.join(map(str, list(set0)))
if set0 == '?':
A += 'x'
elif len(set0) == 1:
A += set0
elif len... | Title: Pattern
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check wheth... | ```python
n = int(input())
S = [0] * n
A = ''
for i in range(n):
S[i] = list(input())
for j in range(len(S[0])):
set0 = set()
for i in range(n):
set0.add(S[i][j])
set0 = ''.join(map(str, list(set0)))
if set0 == '?':
A += 'x'
elif len(set0) == 1:
A += set0
... | 3 |
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.