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
0
none
none
none
0
[ "none" ]
null
null
Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some subsequent elements of the array. The *i*-th subarray is described with two integers *l**...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The next *m* lines contain information about the subarrays chosen by Alyona. The *i*-th of these lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), that describe the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,...
In the first line print single integer — the maximum possible minimum mex. In the second line print *n* integers — the array *a*. All the elements in *a* should be between 0 and 109. It is guaranteed that there is an optimal answer in which all the elements in *a* are between 0 and 109. If there are multiple solutio...
[ "5 3\n1 3\n2 5\n4 5\n", "4 2\n1 4\n2 4\n" ]
[ "2\n1 0 2 1 0\n", "3\n5 2 0 1" ]
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
0
[ { "input": "5 3\n1 3\n2 5\n4 5", "output": "2\n0 1 0 1 0" }, { "input": "4 2\n1 4\n2 4", "output": "3\n0 1 2 0" }, { "input": "1 1\n1 1", "output": "1\n0" }, { "input": "2 1\n2 2", "output": "1\n0 0" }, { "input": "5 6\n2 4\n2 3\n1 4\n3 4\n2 5\n1 3", "output":...
1,479,928,199
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
n, m = map(int, input().split()) for i in range(m): li, ri = map(int, input().split()) ansi = min(ri - li + 1, ansi) print(ansi) for i in range(n): print(i % ansi, end=' ')
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some...
```python n, m = map(int, input().split()) for i in range(m): li, ri = map(int, input().split()) ansi = min(ri - li + 1, ansi) print(ansi) for i in range(n): print(i % ansi, end=' ') ```
-1
160
A
Twins
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't w...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
In the single line print the single number — the minimum needed number of coins.
[ "2\n3 3\n", "3\n2 1 2\n" ]
[ "2\n", "2\n" ]
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum. In the second sample one coin isn't e...
500
[ { "input": "2\n3 3", "output": "2" }, { "input": "3\n2 1 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "5\n4 2 2 2 2", "output": "3" }, { "input": "7\n1 10 1 2 1 1 1", "output": "1" }, { "input": "5\n3 2 3 3 1", "output": "3" ...
1,694,699,115
2,147,483,647
Python 3
IDLENESS_LIMIT_EXCEEDED
TESTS
0
0
0
import tkinter as tk from tkinter import E,W,N,S window = tk.Tk() title_label = tk.Label( master=window, text="Enter your information", ) title_label.grid(row=0,column=0,columnspan=2) label_input_name = tk.Label( master=window, text='First Name : ', height=5, ) entry_name = tk.Ent...
Title: Twins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w...
```python import tkinter as tk from tkinter import E,W,N,S window = tk.Tk() title_label = tk.Label( master=window, text="Enter your information", ) title_label.grid(row=0,column=0,columnspan=2) label_input_name = tk.Label( master=window, text='First Name : ', height=5, ) entry_nam...
-1
322
B
Ciel and Flowers
PROGRAMMING
1,600
[ "combinatorics", "math" ]
null
null
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3...
The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers.
Print the maximal number of bouquets Fox Ciel can make.
[ "3 6 9\n", "4 4 4\n", "0 0 0\n" ]
[ "6\n", "4\n", "0\n" ]
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets. In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
1,000
[ { "input": "3 6 9", "output": "6" }, { "input": "4 4 4", "output": "4" }, { "input": "0 0 0", "output": "0" }, { "input": "0 3 6", "output": "3" }, { "input": "7 8 9", "output": "7" }, { "input": "8 8 9", "output": "8" }, { "input": "15 3 9...
1,560,863,478
2,147,483,647
Python 3
OK
TESTS
40
248
0
r,g,b = map(int, input().split(" ")) res = 0 res += r//3 res += g//3 res += b//3 if r > 0 and b > 0 and g > 0: r -= 1 g -= 1 b -= 1 res = max(res,r//3+b//3+g//3+1) if r > 0 and b > 0 and g > 0: r -= 1 g -= 1 b -= 1 res = max(res, r//3+b//3+g//3+2) print(res)
Title: Ciel and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red fl...
```python r,g,b = map(int, input().split(" ")) res = 0 res += r//3 res += g//3 res += b//3 if r > 0 and b > 0 and g > 0: r -= 1 g -= 1 b -= 1 res = max(res,r//3+b//3+g//3+1) if r > 0 and b > 0 and g > 0: r -= 1 g -= 1 b -= 1 res = max(res, r//3+b//3+g//3+2) print(res) ```
3
146
A
Lucky Ticket
PROGRAMMING
800
[ "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It...
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
[ "2\n47\n", "4\n4738\n", "4\n4774\n" ]
[ "NO\n", "NO\n", "YES\n" ]
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
500
[ { "input": "2\n47", "output": "NO" }, { "input": "4\n4738", "output": "NO" }, { "input": "4\n4774", "output": "YES" }, { "input": "4\n4570", "output": "NO" }, { "input": "6\n477477", "output": "YES" }, { "input": "6\n777777", "output": "YES" }, ...
1,595,621,908
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
216
6,963,200
n = int(input()) def lucky(n): x = list(set(list(n))) if x!=['4','7'] and x!=['7','4']: return False else: return True a = input() if lucky(a): x = [int(i) for i in a[:n//2]] y = [int(i) for i in a[n//2:]] if sum(x) == sum(y): print("YES") else: ...
Title: Lucky Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python n = int(input()) def lucky(n): x = list(set(list(n))) if x!=['4','7'] and x!=['7','4']: return False else: return True a = input() if lucky(a): x = [int(i) for i in a[:n//2]] y = [int(i) for i in a[n//2:]] if sum(x) == sum(y): print("YES") else:...
0
940
B
Our Tanya is Crying Out Loud
PROGRAMMING
1,400
[ "dp", "greedy" ]
null
null
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations: 1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*....
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109). The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109). The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109).
Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1.
[ "9\n2\n3\n1\n", "5\n5\n2\n20\n", "19\n3\n4\n2\n" ]
[ "6\n", "8\n", "12\n" ]
In the first testcase, the optimal strategy is as follows: - Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin. The total cost is 6 coins. In the second test case the optimal strategy is to subtra...
1,250
[ { "input": "9\n2\n3\n1", "output": "6" }, { "input": "5\n5\n2\n20", "output": "8" }, { "input": "19\n3\n4\n2", "output": "12" }, { "input": "1845999546\n999435865\n1234234\n2323423", "output": "1044857680578777" }, { "input": "1604353664\n1604353665\n9993432\n1", ...
1,620,669,977
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
124
22,528,000
import sys import string from collections import Counter, defaultdict from math import fsum, sqrt, gcd, ceil, factorial from itertools import combinations, permutations # input = sys.stdin.readline flush = lambda: sys.stdout.flush comb = lambda x, y: (factorial(x) // factorial(y)) // factorial(x - y) # ...
Title: Our Tanya is Crying Out Loud Time Limit: None seconds Memory Limit: None megabytes Problem Description: Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perf...
```python import sys import string from collections import Counter, defaultdict from math import fsum, sqrt, gcd, ceil, factorial from itertools import combinations, permutations # input = sys.stdin.readline flush = lambda: sys.stdout.flush comb = lambda x, y: (factorial(x) // factorial(y)) // factorial(x - ...
0
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { ...
1,698,347,299
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
92
0
n = input() s = 0 for i in range(len(n)): if n[i] in ["7", "4"]: s += 1 if s == len(n): print("YES") else: print("NO")
Title: Nearly Lucky Number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python n = input() s = 0 for i in range(len(n)): if n[i] in ["7", "4"]: s += 1 if s == len(n): print("YES") else: print("NO") ```
0
6
C
Alice, Bob and Chocolate
PROGRAMMING
1,200
[ "greedy", "two pointers" ]
C. Alice, Bob and Chocolate
2
64
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them wi...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right).
Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob.
[ "5\n2 9 8 2 7\n" ]
[ "2 3\n" ]
none
0
[ { "input": "5\n2 9 8 2 7", "output": "2 3" }, { "input": "1\n1", "output": "1 0" }, { "input": "2\n1 1", "output": "1 1" }, { "input": "3\n1 1 1", "output": "2 1" }, { "input": "4\n1 1 1 1", "output": "2 2" }, { "input": "1\n6", "output": "1 0" }...
1,674,156,005
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
8
122
0
n = int(input()) t = list(map(int,input().split())) i = 0 j = n-1 t1,t2 = 0,0 a,b = 0,0 while i<=j: t1+=t[i] t2+=t[j] if i==j and t1==t2: a+=1 break elif i==j: a+=(t1<t2) b+=(t2<t1) break a+=1 b+=1 i+=1 j-=1 print(a,b)
Title: Alice, Bob and Chocolate Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. Fo...
```python n = int(input()) t = list(map(int,input().split())) i = 0 j = n-1 t1,t2 = 0,0 a,b = 0,0 while i<=j: t1+=t[i] t2+=t[j] if i==j and t1==t2: a+=1 break elif i==j: a+=(t1<t2) b+=(t2<t1) break a+=1 b+=1 i+=1 j-=1 print(...
0
478
B
Random Teams
PROGRAMMING
1,300
[ "combinatorics", "constructive algorithms", "greedy", "math" ]
null
null
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul...
The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively.
The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.
[ "5 1\n", "3 2\n", "6 3\n" ]
[ "10 10\n", "1 1\n", "3 6\n" ]
In the first sample all the participants get into one team, so there will be exactly ten pairs of friends. In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one. ...
1,000
[ { "input": "5 1", "output": "10 10" }, { "input": "3 2", "output": "1 1" }, { "input": "6 3", "output": "3 6" }, { "input": "5 3", "output": "2 3" }, { "input": "10 2", "output": "20 36" }, { "input": "10 6", "output": "4 10" }, { "input": ...
1,648,578,853
2,147,483,647
PyPy 3-64
OK
TESTS
26
61
0
n,m = map(int,input().split()) temp = n-(m-1) kmax = (temp*(temp-1))//2 a = n//m temp1 = m*(a*(a-1))//2 + a*(n%m) print(temp1,kmax)
Title: Random Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is ...
```python n,m = map(int,input().split()) temp = n-(m-1) kmax = (temp*(temp-1))//2 a = n//m temp1 = m*(a*(a-1))//2 + a*(n%m) print(temp1,kmax) ```
3
793
B
Igor and his way to work
PROGRAMMING
1,600
[ "dfs and similar", "graphs", "implementation", "shortest paths" ]
null
null
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the grid. Each of the next *n* lines contains *m* characters denoting the corresponding row of the grid. The following characters can occur: - "." — an empty cell; - "*" — a cell with road ...
In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.
[ "5 5\n..S..\n****.\nT....\n****.\n.....\n", "5 5\nS....\n****.\n.....\n.****\n..T..\n" ]
[ "YES", "NO" ]
The first sample is shown on the following picture: In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture:
1,000
[ { "input": "5 5\nS....\n****.\n.....\n.****\n..T..", "output": "NO" }, { "input": "1 2\nST", "output": "YES" }, { "input": "3 1\nS\n*\nT", "output": "NO" }, { "input": "3 3\n*..\n...\nTS.", "output": "YES" }, { "input": "3 3\nT.*\n*.*\n*S*", "output": "YES" ...
1,492,967,358
1,458
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
8
3,000
127,897,600
n, m = map(int, input().split()) b = [input() for _ in range(n)] (xs, ys, xt, yt) = (-1, -1, -1, -1) for i in range(n): for j in range(m): if b[i][j] == 'S': xs = i ys = j elif b[i][j] == 'T': xt = i yt= j s0 = set() s0.add((xs,ys)) for _ in range(3)...
Title: Igor and his way to work Time Limit: None seconds Memory Limit: None megabytes Problem Description: Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, th...
```python n, m = map(int, input().split()) b = [input() for _ in range(n)] (xs, ys, xt, yt) = (-1, -1, -1, -1) for i in range(n): for j in range(m): if b[i][j] == 'S': xs = i ys = j elif b[i][j] == 'T': xt = i yt= j s0 = set() s0.add((xs,ys)) for _ i...
0
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,643,195,751
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
if input() == input()[::-1]: print("yes") else: print("no")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python if input() == input()[::-1]: print("yes") else: print("no") ```
0
868
B
Race Against Time
PROGRAMMING
1,400
[ "implementation" ]
null
null
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other. The entire universe turned into an enormous clock face with ...
Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2). Misha's position and the target time do not coincide with the position of any hand.
Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "12 30 45 3 11\n", "12 0 1 12 1\n", "3 47 0 4 9\n" ]
[ "NO\n", "YES\n", "YES\n" ]
The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same.
500
[ { "input": "12 30 45 3 11", "output": "NO" }, { "input": "12 0 1 12 1", "output": "YES" }, { "input": "3 47 0 4 9", "output": "YES" }, { "input": "10 22 59 6 10", "output": "YES" }, { "input": "3 1 13 12 3", "output": "NO" }, { "input": "11 19 28 9 10"...
1,562,677,074
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
140
0
h,m,s,t1,t2=list(map(float,input().split())) m=m*12/60 s=s*12/60 if t1>t2: t3=t1 t1=t2 t2=t3 numb=0 if t1<h<t2: numb+=1 if t1<m<t2: numb+=1 if numb==0 or numb==2: print('YES') else: print('NO')
Title: Race Against Time Time Limit: None seconds Memory Limit: None megabytes Problem Description: Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time par...
```python h,m,s,t1,t2=list(map(float,input().split())) m=m*12/60 s=s*12/60 if t1>t2: t3=t1 t1=t2 t2=t3 numb=0 if t1<h<t2: numb+=1 if t1<m<t2: numb+=1 if numb==0 or numb==2: print('YES') else: print('NO') ```
0
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ...
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Print a single line containing a positive integer *m* — the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" ...
1,688,803,721
2,147,483,647
Python 3
OK
TESTS
10
46
0
n = int(input()) s = [] x = [[0] * n for _ in range(n)] for i in range(n): x[i][0] = 1 x[0][i] = 1 for i in range(1, n): for j in range(1, n): x[i][j] = x[i - 1][j] + x[i][j - 1] for row in x: s.append(max(row)) m = max(s) print(m)
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t...
```python n = int(input()) s = [] x = [[0] * n for _ in range(n)] for i in range(n): x[i][0] = 1 x[0][i] = 1 for i in range(1, n): for j in range(1, n): x[i][j] = x[i - 1][j] + x[i][j - 1] for row in x: s.append(max(row)) m = max(s) print(m) ```
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,695,037,991
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
60
0
n = int(input()) l = list(map(int, input().split())) a,b = l.index(max(l)), l.index(min(l)) count = 0 if a > b: while a != 0: a-=1 count+=1 b+=1 if(b>a): while b != 0: b-=1 count+=1 print(count)
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()) l = list(map(int, input().split())) a,b = l.index(max(l)), l.index(min(l)) count = 0 if a > b: while a != 0: a-=1 count+=1 b+=1 if(b>a): while b != 0: b-=1 count+=1 print(count) ```
0
468
A
24 Game
PROGRAMMING
1,500
[ "constructive algorithms", "greedy", "math" ]
null
null
Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game. Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them, let's denote them *a* and *b*, erase them from the sequence, and append to the sequence eit...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105).
If it's possible, print "YES" in the first line. Otherwise, print "NO" (without the quotes). If there is a way to obtain 24 as the result number, in the following *n*<=-<=1 lines print the required operations an operation per line. Each operation should be in form: "*a* *op* *b* = *c*". Where *a* and *b* are the numbe...
[ "1\n", "8\n" ]
[ "NO\n", "YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24\n" ]
none
500
[ { "input": "1", "output": "NO" }, { "input": "8", "output": "YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24" }, { "input": "12", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 =...
1,626,961,482
2,147,483,647
PyPy 3
OK
TESTS
31
249
26,828,800
n=int(input()) if n>=4: print("YES") if n==4: print("4 * 3 = 12") print("12 * 2 = 24") print("24 * 1 = 24") elif n==5: print("5 * 4 = 20") print("20 + 3 = 23") print("23 + 2 = 25") print("25 - 1 = 24") else: print("4 * 3 = 12")...
Title: 24 Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game. Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them...
```python n=int(input()) if n>=4: print("YES") if n==4: print("4 * 3 = 12") print("12 * 2 = 24") print("24 * 1 = 24") elif n==5: print("5 * 4 = 20") print("20 + 3 = 23") print("23 + 2 = 25") print("25 - 1 = 24") else: print("4 ...
3
868
A
Bark to Unlock
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters. Mu-mu's enemy Kashtanka wants to unlock Mu-mu's p...
The first line contains two lowercase English letters — the password on the phone. The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows. The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to b...
Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "ya\n4\nah\noy\nto\nha\n", "hp\n2\nht\ntp\n", "ah\n1\nha\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES". In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" produ...
250
[ { "input": "ya\n4\nah\noy\nto\nha", "output": "YES" }, { "input": "hp\n2\nht\ntp", "output": "NO" }, { "input": "ah\n1\nha", "output": "YES" }, { "input": "bb\n4\nba\nab\naa\nbb", "output": "YES" }, { "input": "bc\n4\nca\nba\nbb\ncc", "output": "YES" }, { ...
1,507,187,493
393
Python 3
CHALLENGED
CHALLENGES
8
62
0
import sys pw = sys.stdin.readline() n = sys.stdin.readline() wds = [] for i in range(int(n)): wds.append(sys.stdin.readline().strip()) fst = False snd = False for wd in wds: if wd[0] == pw[1]: fst = True if wd[1] == pw[0]: snd = True if fst and snd: print("YES") else: print("NO"...
Title: Bark to Unlock Time Limit: None seconds Memory Limit: None megabytes Problem Description: As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a passw...
```python import sys pw = sys.stdin.readline() n = sys.stdin.readline() wds = [] for i in range(int(n)): wds.append(sys.stdin.readline().strip()) fst = False snd = False for wd in wds: if wd[0] == pw[1]: fst = True if wd[1] == pw[0]: snd = True if fst and snd: print("YES") else: ...
-1
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains...
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: ...
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "...
1,682,921,752
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
92
0
from sys import stdin, setrecursionlimit, stdout def solve(): r, c = (int(s) for s in stdin.readline().split()) mas = [stdin.readline().rstrip('\r\n') for _ in range(r)] banned_rows = set() banned_cols = set() for i in range(r): for j in range(c): if mas[i][j] == ...
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each ti...
```python from sys import stdin, setrecursionlimit, stdout def solve(): r, c = (int(s) for s in stdin.readline().split()) mas = [stdin.readline().rstrip('\r\n') for _ in range(r)] banned_rows = set() banned_cols = set() for i in range(r): for j in range(c): if mas...
0
897
B
Chtholly's request
PROGRAMMING
1,300
[ "brute force" ]
null
null
— I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation with...
The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109).
Output single integer — answer to the problem.
[ "2 100\n", "5 30\n" ]
[ "33\n", "15\n" ]
In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
1,000
[ { "input": "2 100", "output": "33" }, { "input": "5 30", "output": "15" }, { "input": "42147 412393322", "output": "251637727" }, { "input": "77809 868097296", "output": "440411873" }, { "input": "5105 443422097", "output": "363192634" }, { "input": "7...
1,645,098,773
2,147,483,647
PyPy 3-64
OK
TESTS
26
93
2,150,400
a, k = map(int, input().split()) sm = 0 for i in range(1, a + 1): r = str(i) sm += int(r + r[::-1]) sm %= k print(sm % k)
Title: Chtholly's request Time Limit: None seconds Memory Limit: None megabytes Problem Description: — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thi...
```python a, k = map(int, input().split()) sm = 0 for i in range(1, a + 1): r = str(i) sm += int(r + r[::-1]) sm %= k print(sm % k) ```
3
46
A
Ball Game
PROGRAMMING
800
[ "brute force", "implementation" ]
A. Ball Game
2
256
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is...
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle.
In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.
[ "10\n", "3\n" ]
[ "2 4 7 1 6 2 9 7 6\n", "2 1\n" ]
none
0
[ { "input": "10", "output": "2 4 7 1 6 2 9 7 6" }, { "input": "3", "output": "2 1" }, { "input": "4", "output": "2 4 3" }, { "input": "5", "output": "2 4 2 1" }, { "input": "6", "output": "2 4 1 5 4" }, { "input": "7", "output": "2 4 7 4 2 1" }, ...
1,670,394,381
2,147,483,647
Python 3
OK
TESTS
33
92
0
aruncari = int(input('')) def nr_ce_primesc_mingea(aruncari): numar = 1 for i in range(1, aruncari): numar = numar + i if numar > aruncari: numar = numar - aruncari print(numar, end=' ') nr_ce_primesc_mingea(aruncari)
Title: Ball Game Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think...
```python aruncari = int(input('')) def nr_ce_primesc_mingea(aruncari): numar = 1 for i in range(1, aruncari): numar = numar + i if numar > aruncari: numar = numar - aruncari print(numar, end=' ') nr_ce_primesc_mingea(aruncari) ```
3.977
979
A
Pizza, Pizza, Pizza!!!
PROGRAMMING
1,000
[ "math" ]
null
null
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele...
A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces.
A single integer — the number of straight cuts Shiro needs.
[ "3\n", "4\n" ]
[ "2", "5" ]
To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them. To cut the round pizza into five equal parts one has to make five cuts.
500
[ { "input": "3", "output": "2" }, { "input": "4", "output": "5" }, { "input": "10", "output": "11" }, { "input": "10000000000", "output": "10000000001" }, { "input": "1234567891", "output": "617283946" }, { "input": "7509213957", "output": "37546069...
1,665,434,219
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
15
0
if (__name__=="__main__"): friends=1 input(int(friends)) friends=friends+1 if(friends%2==0): print(friends/2) else: print(friends)
Title: Pizza, Pizza, Pizza!!! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthd...
```python if (__name__=="__main__"): friends=1 input(int(friends)) friends=friends+1 if(friends%2==0): print(friends/2) else: print(friends) ```
0
1
C
Ancient Berland Circus
PROGRAMMING
2,100
[ "geometry", "math" ]
C. Ancient Berland Circus
2
64
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different. In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a spec...
The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point.
Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100.
[ "0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000\n" ]
[ "1.00000000\n" ]
0
[ { "input": "0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000", "output": "1.00000000" }, { "input": "71.756151 7.532275\n-48.634784 100.159986\n91.778633 158.107739", "output": "9991.27897663" }, { "input": "18.716839 40.852752\n66.147248 -4.083161\n111.083161 43.347248", "out...
1,659,707,511
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
12
122
0
import math def dot(a, b): return a[0]*b[0] + a[1]*b[1] def rad2deg(x): return 180 * x / math.pi def deg2rad(x): return math.pi* x / 180 def center_from_three_points(a, b, c): a11 = 2*(a[0] - b[0]) a12 = 2*(a[1] - b[1]) a21 = 2*(a[0] - c[0]) a22 = 2*(a[1] - c[1]) b1 = a[0]*a[0] - b[...
Title: Ancient Berland Circus Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different. In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and t...
```python import math def dot(a, b): return a[0]*b[0] + a[1]*b[1] def rad2deg(x): return 180 * x / math.pi def deg2rad(x): return math.pi* x / 180 def center_from_three_points(a, b, c): a11 = 2*(a[0] - b[0]) a12 = 2*(a[1] - b[1]) a21 = 2*(a[0] - c[0]) a22 = 2*(a[1] - c[1]) b1 = a[0]...
0
498
A
Crazy Town
PROGRAMMING
1,700
[ "geometry" ]
null
null
Crazy Town is a plane on which there are *n* infinite line roads. Each road is defined by the equation *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, where *a**i* and *b**i* are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We ...
The first line contains two space-separated integers *x*1, *y*1 (<=-<=106<=≤<=*x*1,<=*y*1<=≤<=106) — the coordinates of your home. The second line contains two integers separated by a space *x*2, *y*2 (<=-<=106<=≤<=*x*2,<=*y*2<=≤<=106) — the coordinates of the university you are studying at. The third line contains a...
Output the answer to the problem.
[ "1 1\n-1 -1\n2\n0 1 0\n1 0 0\n", "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3\n" ]
[ "2\n", "2\n" ]
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
500
[ { "input": "1 1\n-1 -1\n2\n0 1 0\n1 0 0", "output": "2" }, { "input": "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3", "output": "2" }, { "input": "841746 527518\n595261 331297\n10\n-946901 129987 670374\n-140388 -684770 309555\n-302589 415564 -387435\n-565799 -72069 -395358\n-523453 -511446 85489...
1,556,901,076
2,147,483,647
Python 3
OK
TESTS
51
109
0
x1,y1=map(int,input().split()) x2,y2=map(int,input().split()) a1=y1-y2 b1=x2-x1 c1=x2*(y2-y1)-y2*(x2-x1) def intersect(a2,b2,c2): global a1,b1,c1,x1,y1,x2,y2 if(a1*b2==a2*b1): return False x=(b1*c2-b2*c1)/(a1*b2-b1*a2) y=(a1*c2-c1*a2)/(b1*a2-a1*b2) ...
Title: Crazy Town Time Limit: None seconds Memory Limit: None megabytes Problem Description: Crazy Town is a plane on which there are *n* infinite line roads. Each road is defined by the equation *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, where *a**i* and *b**i* are not both equal to the zero. The roads divide the pl...
```python x1,y1=map(int,input().split()) x2,y2=map(int,input().split()) a1=y1-y2 b1=x2-x1 c1=x2*(y2-y1)-y2*(x2-x1) def intersect(a2,b2,c2): global a1,b1,c1,x1,y1,x2,y2 if(a1*b2==a2*b1): return False x=(b1*c2-b2*c1)/(a1*b2-b1*a2) y=(a1*c2-c1*a2)/(b1*a2-a1*b...
3
672
A
Summer Camp
PROGRAMMING
800
[ "implementation" ]
null
null
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to...
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print.
Print the *n*-th digit of the line.
[ "3\n", "11\n" ]
[ "3\n", "0\n" ]
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit. In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
500
[ { "input": "3", "output": "3" }, { "input": "11", "output": "0" }, { "input": "12", "output": "1" }, { "input": "13", "output": "1" }, { "input": "29", "output": "9" }, { "input": "30", "output": "2" }, { "input": "1000", "output": "3" ...
1,590,842,682
2,147,483,647
PyPy 3
OK
TESTS
37
140
0
s="" for i in range(1,1000): f=str(i) s=s+f n=int(input()) print(s[n-1])
Title: Summer Camp Time Limit: None seconds Memory Limit: None megabytes Problem Description: Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1...
```python s="" for i in range(1,1000): f=str(i) s=s+f n=int(input()) print(s[n-1]) ```
3
417
A
Elimination
PROGRAMMING
1,500
[ "dp", "implementation", "math" ]
null
null
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of *c* problems, the winners of the round are the first *n* people in the rating list....
The first line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100) — the number of problems in the main and additional rounds, correspondingly. The second line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Finally, the third line contains an integer *k* (1<=≤<=*k*<=≤<=100) — the number of the pre...
In the first line, print a single integer — the minimum number of problems the jury needs to prepare.
[ "1 10\n7 2\n1\n", "2 2\n2 1\n2\n" ]
[ "2\n", "0\n" ]
none
500
[ { "input": "1 10\n7 2\n1", "output": "2" }, { "input": "2 2\n2 1\n2", "output": "0" }, { "input": "8 9\n2 2\n3", "output": "8" }, { "input": "5 5\n8 8\n7", "output": "40" }, { "input": "1 8\n8 10\n8", "output": "9" }, { "input": "5 7\n9 1\n8", "out...
1,600,197,308
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
34
109
0
I=lambda:map(int,input().split());c,d=I();n,m=I();k=int(input());l=n*m-k;z=min(l//n*c,l*d)+min(c,l%n*d) print(z if z>0 else 0)
Title: Elimination Time Limit: None seconds Memory Limit: None megabytes Problem Description: The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination round...
```python I=lambda:map(int,input().split());c,d=I();n,m=I();k=int(input());l=n*m-k;z=min(l//n*c,l*d)+min(c,l%n*d) print(z if z>0 else 0) ```
0
137
C
History
PROGRAMMING
1,500
[ "sortings" ]
null
null
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history. Everybody knows that the Wo...
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th...
Print the only integer — the answer to the problem.
[ "5\n1 10\n2 9\n3 8\n4 7\n5 6\n", "5\n1 100\n2 50\n51 99\n52 98\n10 60\n", "1\n1 1000000000\n" ]
[ "4\n", "4\n", "0\n" ]
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first. In the second example all events except the first one are contained in the first. In the third example only one event, so the answer is 0.
1,500
[ { "input": "5\n1 10\n2 9\n3 8\n4 7\n5 6", "output": "4" }, { "input": "5\n1 100\n2 50\n51 99\n52 98\n10 60", "output": "4" }, { "input": "1\n1 1000000000", "output": "0" }, { "input": "2\n100 1000\n500 1500", "output": "0" }, { "input": "4\n1 100\n50 150\n120 200\...
1,581,794,741
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
186
307,200
n = int(input()) arr = [] s_arr = [] e_arr = [] for i in range(n): a, b = input().split(" ") s_arr.append((a, i)) e_arr.append((b, i)) if len(s_arr) <= 1: print(0) else: s_s_arr = sorted(s_arr, key= lambda x: x[0]) s_e_arr = sorted(e_arr, key= lambda x: x[0], reverse=True) r_c_m = dic...
Title: History Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other ...
```python n = int(input()) arr = [] s_arr = [] e_arr = [] for i in range(n): a, b = input().split(" ") s_arr.append((a, i)) e_arr.append((b, i)) if len(s_arr) <= 1: print(0) else: s_s_arr = sorted(s_arr, key= lambda x: x[0]) s_e_arr = sorted(e_arr, key= lambda x: x[0], reverse=True) r...
0
369
A
Valera and Plates
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Valera is a lazy student. He has *m* clean bowls and *k* clean plates. Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can...
The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Val...
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
[ "3 1 1\n1 2 1\n", "4 3 1\n1 1 1 1\n", "3 1 2\n2 2 2\n", "8 2 2\n1 2 1 2 1 2 1 2\n" ]
[ "1\n", "1\n", "0\n", "4\n" ]
In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all...
500
[ { "input": "3 1 1\n1 2 1", "output": "1" }, { "input": "4 3 1\n1 1 1 1", "output": "1" }, { "input": "3 1 2\n2 2 2", "output": "0" }, { "input": "8 2 2\n1 2 1 2 1 2 1 2", "output": "4" }, { "input": "2 100 100\n2 2", "output": "0" }, { "input": "1 1 1\...
1,620,705,832
2,147,483,647
PyPy 3
OK
TESTS
63
108
20,172,800
n, m, k = map(int, input().split()) daf = list(map(int, input().split())) c = 0 total = 0 while (m>0 or k>0) and c < n: f = daf[c] if f == 1: if m > 0: m -= 1 else: total += 1 else: if k > 0: k -= 1 elif m > 0: ...
Title: Valera and Plates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a lazy student. He has *m* clean bowls and *k* clean plates. Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, ...
```python n, m, k = map(int, input().split()) daf = list(map(int, input().split())) c = 0 total = 0 while (m>0 or k>0) and c < n: f = daf[c] if f == 1: if m > 0: m -= 1 else: total += 1 else: if k > 0: k -= 1 elif m > 0: ...
3
912
A
Tricky Alchemy
PROGRAMMING
800
[ "implementation" ]
null
null
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ...
The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained.
Print a single integer — the minimum number of crystals that Grisha should acquire in addition.
[ "4 3\n2 1 1\n", "3 9\n1 1 3\n", "12345678 87654321\n43043751 1000000000 53798715\n" ]
[ "2\n", "1\n", "2147483648\n" ]
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.
500
[ { "input": "4 3\n2 1 1", "output": "2" }, { "input": "3 9\n1 1 3", "output": "1" }, { "input": "12345678 87654321\n43043751 1000000000 53798715", "output": "2147483648" }, { "input": "12 12\n3 5 2", "output": "0" }, { "input": "770 1390\n170 442 311", "output"...
1,626,983,763
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
61
6,656,000
# Tricky alchemy [A,B] = map(int,input().split()) [x,y,z] = map(int,input().split()) x == ((x * 2 + y * 2 + z * 3) - (A + B)) if x < 0: print(0) else: print((x * 2 + y * 2 + z * 3) - (A + B))
Title: Tricky Alchemy Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obta...
```python # Tricky alchemy [A,B] = map(int,input().split()) [x,y,z] = map(int,input().split()) x == ((x * 2 + y * 2 + z * 3) - (A + B)) if x < 0: print(0) else: print((x * 2 + y * 2 + z * 3) - (A + B)) ```
0
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,496,998,234
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
9
124
0
str1, str2 = input(), input() for i in range(len(str1)): if str1[i] != str2[len(str1) - 1 - i]: print('NO') exit() print('YES')
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python str1, str2 = input(), input() for i in range(len(str1)): if str1[i] != str2[len(str1) - 1 - i]: print('NO') exit() print('YES') ```
-1
721
A
One-dimensional Japanese Crossword
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers repr...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
[ "3\nBBW\n", "5\nBWBWB\n", "4\nWWWW\n", "4\nBBBB\n", "13\nWBBBBWWBWBBBW\n" ]
[ "1\n2 ", "3\n1 1 1 ", "0\n", "1\n4 ", "3\n4 1 3 " ]
The last sample case correspond to the picture in the statement.
500
[ { "input": "3\nBBW", "output": "1\n2 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "4\nWWWW", "output": "0" }, { "input": "4\nBBBB", "output": "1\n4 " }, { "input": "13\nWBBBBWWBWBBBW", "output": "3\n4 1 3 " }, { "input": "1\nB", ...
1,618,969,100
2,147,483,647
Python 3
OK
TESTS
54
62
0
n = int(input()) row = input() row_arr = row.split("W") row_arr = [i for i in row_arr if i != ''] print(len(row_arr)) #print(row_arr) # debugging for i in row_arr: print(len(i),end=" ")
Title: One-dimensional Japanese Crossword Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the...
```python n = int(input()) row = input() row_arr = row.split("W") row_arr = [i for i in row_arr if i != ''] print(len(row_arr)) #print(row_arr) # debugging for i in row_arr: print(len(i),end=" ") ```
3
977
F
Consecutive Subsequence
PROGRAMMING
1,700
[ "dp" ]
null
null
You are given an integer array of length $n$. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to $[x, x + 1, \dots, x + k - 1]$ for some value $x$ and length $k$. Su...
The first line of the input containing integer number $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the array. The second line of the input containing $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the array itself.
On the first line print $k$ — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
[ "7\n3 3 4 7 5 6 8\n", "6\n1 3 5 2 4 6\n", "4\n10 9 8 7\n", "9\n6 7 8 3 4 5 9 10 11\n" ]
[ "4\n2 3 5 6 \n", "2\n1 4 \n", "1\n1 \n", "6\n1 2 3 7 8 9 \n" ]
All valid answers for the first example (as sequences of indices): - $[1, 3, 5, 6]$ - $[2, 3, 5, 6]$ All valid answers for the second example: - $[1, 4]$ - $[2, 5]$ - $[3, 6]$ All valid answers for the third example: - $[1]$ - $[2]$ - $[3]$ - $[4]$ All valid answers for the fourth example: - $[1, 2...
0
[ { "input": "7\n3 3 4 7 5 6 8", "output": "4\n2 3 5 6 " }, { "input": "6\n1 3 5 2 4 6", "output": "2\n1 4 " }, { "input": "4\n10 9 8 7", "output": "1\n1 " }, { "input": "9\n6 7 8 3 4 5 9 10 11", "output": "6\n1 2 3 7 8 9 " }, { "input": "1\n1337", "output": "1\...
1,694,507,036
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
l = int(input()) nums = list(map(int,input().split())) lenmax = {n:0 for n in nums} for n in nums: if n-1 in lenmax: lenmax[n] = lenmax[n-1]+1 ans = max(lenmax.values()) res = [] for i in range(l-1,-1,-1): if lenmax[nums[i]] == ans: res.append(i) ans-=1 print(len(re...
Title: Consecutive Subsequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an integer array of length $n$. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words t...
```python l = int(input()) nums = list(map(int,input().split())) lenmax = {n:0 for n in nums} for n in nums: if n-1 in lenmax: lenmax[n] = lenmax[n-1]+1 ans = max(lenmax.values()) res = [] for i in range(l-1,-1,-1): if lenmax[nums[i]] == ans: res.append(i) ans-=1 pr...
0
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,614,517,340
2,147,483,647
Python 3
OK
TESTS
35
124
0
m, n = map(int, input().split()) if ((int(m) * int(n)) % 2) == 0: y = ((int(m) * int(n) * 0.5)) print(int(y)) elif((int(m) * int(n)) % 2) == 1: y = (((int(m) * int(n)) - 1) * 0.5) print(int(y))
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python m, n = map(int, input().split()) if ((int(m) * int(n)) % 2) == 0: y = ((int(m) * int(n) * 0.5)) print(int(y)) elif((int(m) * int(n)) % 2) == 1: y = (((int(m) * int(n)) - 1) * 0.5) print(int(y)) ```
3.969
0
none
none
none
0
[ "none" ]
null
null
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately. Organizers are st...
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1018) — the number of players to participate in the tournament.
Print the maximum number of games in which the winner of the tournament can take part.
[ "2\n", "3\n", "4\n", "10\n" ]
[ "1\n", "2\n", "2\n", "4\n" ]
In all samples we consider that player number 1 is the winner. In the first sample, there would be only one game so the answer is 1. In the second sample, player 1 can consequently beat players 2 and 3. In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't p...
0
[ { "input": "2", "output": "1" }, { "input": "3", "output": "2" }, { "input": "4", "output": "2" }, { "input": "10", "output": "4" }, { "input": "1000", "output": "14" }, { "input": "2500", "output": "15" }, { "input": "690000", "output"...
1,484,482,814
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
4,608,000
n = int(input()) f = [0] * 200 f[0] = 0 f[1] = 2 for k in range(2, 101): f[k] = f[k-1] * 2 - 1 for k in range(1, 100): if n >= f[k] and n < f[k+1]: print(k) exit()
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That me...
```python n = int(input()) f = [0] * 200 f[0] = 0 f[1] = 2 for k in range(2, 101): f[k] = f[k-1] * 2 - 1 for k in range(1, 100): if n >= f[k] and n < f[k+1]: print(k) exit() ```
0
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th...
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 58697...
1,698,323,129
2,147,483,647
PyPy 3-64
OK
TESTS
34
122
0
shoes = list(input().split()) shoes = list(map(int, shoes)) colours = [] count = 0 for i in range(len(shoes)): if shoes[i] in colours: count += 1 else: colours.append(shoes[i]) print(count)
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ...
```python shoes = list(input().split()) shoes = list(map(int, shoes)) colours = [] count = 0 for i in range(len(shoes)): if shoes[i] in colours: count += 1 else: colours.append(shoes[i]) print(count) ```
3
73
A
The Elder Trolls IV: Oblivon
PROGRAMMING
1,600
[ "greedy", "math" ]
A. The Elder Trolls IV: Oblivon
2
256
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so ...
The first line of input contains four integer numbers *x*,<=*y*,<=*z*,<=*k* (1<=≤<=*x*,<=*y*,<=*z*<=≤<=106,<=0<=≤<=*k*<=≤<=109).
Output the only number — the answer for the problem. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
[ "2 2 2 3\n", "2 2 2 1\n" ]
[ "8", "2" ]
In the first sample Vasya make 3 pairwise perpendicular cuts. He cuts monster on two parts with the first cut, then he divides each part on two with the second cut, and finally he divides each of the 4 parts on two.
500
[ { "input": "2 2 2 3", "output": "8" }, { "input": "2 2 2 1", "output": "2" }, { "input": "1 1 1 1", "output": "1" }, { "input": "1 2 3 3", "output": "6" }, { "input": "20 4 5 12", "output": "120" }, { "input": "100 500 100500 1000000000", "output":...
1,450,801,697
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
x,y,z,k=map(int,input().split()) if k==1: print (2) if k==2: print (4) if k==3: print (8) if k>(x-1)+(y-1)+(z-1): print (x*y*z) if 3<k<=(x-1)+(y-1)+(z-1): print (4*k-4)
Title: The Elder Trolls IV: Oblivon Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monste...
```python x,y,z,k=map(int,input().split()) if k==1: print (2) if k==2: print (4) if k==3: print (8) if k>(x-1)+(y-1)+(z-1): print (x*y*z) if 3<k<=(x-1)+(y-1)+(z-1): print (4*k-4) ```
0
24
E
Berland collider
PROGRAMMING
2,300
[ "binary search" ]
E. Berland collider
1
256
Recently the construction of Berland collider has been completed. Collider can be represented as a long narrow tunnel that contains *n* particles. We associate with collider 1-dimensional coordinate system, going from left to right. For each particle we know its coordinate and velocity at the moment of start of the col...
The first line contains single integer *n* (1<=≤<=*n*<=≤<=5·105) — amount of particles in the collider. Next *n* lines contain description of particles. Each particle is described by two integers *x**i*, *v**i* (<=-<=109<=≤<=*x**i*,<=*v**i*<=≤<=109,<=*v**i*<=≠<=0) — coordinate and velocity respectively. All the coordin...
If there will be no big bang, output -1. Otherwise output one number — how much time in seconds elapses after the launch of the collider before the big bang happens. Your answer must have a relative or absolute error less than 10<=-<=9.
[ "3\n-5 9\n0 1\n5 -1\n", "6\n1 3\n2 3\n3 3\n4 -3\n5 -1\n6 -100\n" ]
[ "1.00000000000000000000\n", "0.02912621359223301065\n" ]
none
0
[ { "input": "3\n-5 9\n0 1\n5 -1", "output": "1.00000000000000000000" }, { "input": "6\n1 3\n2 3\n3 3\n4 -3\n5 -1\n6 -100", "output": "0.02912621359223301065" }, { "input": "2\n-1000000000 1\n1000000000 -1", "output": "1000000000.00000000000000000000" }, { "input": "2\n-1000000...
1,680,729,013
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
17
1,500
34,816,000
def can(particles, mid, pl, pr): pos_right = particles[pr][0] pos_left = particles[pl][0] for i in range(pr, pl + 1): x, v = particles[i] aux = x + v * mid if v > 0: if aux > pos_right: pos_right = aux pos_left = particles[pl][0] ...
Title: Berland collider Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Recently the construction of Berland collider has been completed. Collider can be represented as a long narrow tunnel that contains *n* particles. We associate with collider 1-dimensional coordinate system, going from left...
```python def can(particles, mid, pl, pr): pos_right = particles[pr][0] pos_left = particles[pl][0] for i in range(pr, pl + 1): x, v = particles[i] aux = x + v * mid if v > 0: if aux > pos_right: pos_right = aux pos_left = particles[pl][0...
0
786
C
Till I Collapse
PROGRAMMING
2,400
[ "data structures", "divide and conquer" ]
null
null
Rick and Morty want to find MR. PBH and they can't do it alone. So they need of Mr. Meeseeks. They Have generated *n* Mr. Meeseeks, standing in a line numbered from 1 to *n*. Each of them has his own color. *i*-th Mr. Meeseeks' color is *a**i*. Rick and Morty are gathering their army and they want to divide Mr. Meese...
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105) — number of Mr. Meeseeks. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* separated by spaces (1<=≤<=*a**i*<=≤<=*n*) — colors of Mr. Meeseeks in order they standing in a line.
In the first and only line of input print *n* integers separated by spaces. *i*-th integer should be the minimum number of presidios needed if the value of *k* is *i*.
[ "5\n1 3 4 3 3\n", "8\n1 5 7 8 1 7 6 1\n" ]
[ "4 2 1 1 1 \n", "8 4 3 2 1 1 1 1 \n" ]
For the first sample testcase, some optimal ways of dividing army into squads for each *k* are: 1. [1], [3], [4], [3, 3] 1. [1], [3, 4, 3, 3] 1. [1, 3, 4, 3, 3] 1. [1, 3, 4, 3, 3] 1. [1, 3, 4, 3, 3] For the second testcase, some optimal ways of dividing army into squads for each *k* are: 1. [1], [5], [7], [8],...
1,500
[ { "input": "5\n1 3 4 3 3", "output": "4 2 1 1 1 " }, { "input": "8\n1 5 7 8 1 7 6 1", "output": "8 4 3 2 1 1 1 1 " }, { "input": "10\n4 1 2 6 8 5 3 9 3 9", "output": "10 4 3 2 2 2 2 1 1 1 " }, { "input": "85\n23 11 69 1 49 10 7 13 66 35 81 4 51 2 62 55 31 18 85 34 59 44 20 28...
1,686,380,144
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
26,112,000
import os,sys,collections,heapq,itertools if os.path.exists('in.txt'): file = open('in.txt') input = file.readline else : input = sys.stdin.readline from functools import reduce from itertools import accumulate,chain,combinations,count from itertools import groupby,permutations,product,zip_l...
Title: Till I Collapse Time Limit: None seconds Memory Limit: None megabytes Problem Description: Rick and Morty want to find MR. PBH and they can't do it alone. So they need of Mr. Meeseeks. They Have generated *n* Mr. Meeseeks, standing in a line numbered from 1 to *n*. Each of them has his own color. *i*-th Mr. M...
```python import os,sys,collections,heapq,itertools if os.path.exists('in.txt'): file = open('in.txt') input = file.readline else : input = sys.stdin.readline from functools import reduce from itertools import accumulate,chain,combinations,count from itertools import groupby,permutations,pro...
0
894
A
QAQ
PROGRAMMING
800
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are...
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integer — the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
500
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { ...
1,607,593,338
2,147,483,647
Python 3
OK
TESTS
43
109
0
t = list(input()) q_inds = [i for i, x in enumerate(t) if x == "Q"] a_inds = [i for i, x in enumerate(t) if x == "A"] ans = 0 for i, qi in enumerate(q_inds): for ai in a_inds: if qi < ai: for qi_2 in q_inds[i+1:]: if ai < qi_2: ans += 1 print(ans)
Title: QAQ Time Limit: None seconds Memory Limit: None megabytes Problem Description: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"...
```python t = list(input()) q_inds = [i for i, x in enumerate(t) if x == "Q"] a_inds = [i for i, x in enumerate(t) if x == "A"] ans = 0 for i, qi in enumerate(q_inds): for ai in a_inds: if qi < ai: for qi_2 in q_inds[i+1:]: if ai < qi_2: ans += 1 print(ans) ...
3
230
B
T-primes
PROGRAMMING
1,300
[ "binary search", "implementation", "math", "number theory" ]
null
null
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st...
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
[ "3\n4 5 6\n" ]
[ "YES\nNO\nNO\n" ]
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
500
[ { "input": "3\n4 5 6", "output": "YES\nNO\nNO" }, { "input": "2\n48 49", "output": "NO\nYES" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO" }, { "input": "1\n36", "output": "NO" }, { "input": "1\n999966000289", "...
1,697,386,984
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
56
2,000
14,336,000
def is_prime4(x): if (x == 2) or (x == 3): return True if (x % 6 != 1) and (x % 6 != 5): return False for i in range(5, int(x ** 0.5) + 1, 6): if (x % i == 0) or (x % (i + 2) == 0): return False return True n=int(input()) s=[int(i) for i in input().split()] ...
Title: T-primes Time Limit: None seconds Memory Limit: None megabytes Problem Description: We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an ar...
```python def is_prime4(x): if (x == 2) or (x == 3): return True if (x % 6 != 1) and (x % 6 != 5): return False for i in range(5, int(x ** 0.5) + 1, 6): if (x % i == 0) or (x % (i + 2) == 0): return False return True n=int(input()) s=[int(i) for i in input()...
0
534
A
Exam
PROGRAMMING
1,100
[ "constructive algorithms", "implementation", "math" ]
null
null
An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other...
A single line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of students at an exam.
In the first line print integer *k* — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is the number of the student on the *i*-th position...
[ "6", "3\n" ]
[ "6\n1 5 3 6 2 4", "2\n1 3" ]
none
500
[ { "input": "6", "output": "6\n5 3 1 6 4 2 " }, { "input": "3", "output": "2\n1 3" }, { "input": "1", "output": "1\n1 " }, { "input": "2", "output": "1\n1" }, { "input": "4", "output": "4\n3 1 4 2 " }, { "input": "5", "output": "5\n5 3 1 4 2 " }, ...
1,617,611,086
2,147,483,647
Python 3
OK
TESTS
36
62
204,800
def odd(lst,n): for i in range(1,n+1,2): lst.append(i) def even(lst,n): start=2 if len(lst)==1 or n==3: start=4 for j in range(start,n+1,2): lst.append(j) n=int(input()) lst=[] if n%2==0 and n>2: even(lst, n) odd(lst, n) ...
Title: Exam Time Limit: None seconds Memory Limit: None megabytes Problem Description: An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and bec...
```python def odd(lst,n): for i in range(1,n+1,2): lst.append(i) def even(lst,n): start=2 if len(lst)==1 or n==3: start=4 for j in range(start,n+1,2): lst.append(j) n=int(input()) lst=[] if n%2==0 and n>2: even(lst, n) odd(ls...
3
976
A
Minimum Binary Number
PROGRAMMING
800
[ "implementation" ]
null
null
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"...
The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
Print one string — the minimum correct string that you can obtain from the given one.
[ "4\n1001\n", "1\n1\n" ]
[ "100\n", "1\n" ]
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht...
0
[ { "input": "4\n1001", "output": "100" }, { "input": "1\n1", "output": "1" }, { "input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100", "output": "1000000000000000000000000000000000000000" }, { "input": "100\n100000...
1,665,453,888
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
31
0
n=input();print('1'+(input().count('0')*'0'))
Title: Minimum Binary Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two...
```python n=input();print('1'+(input().count('0')*'0')) ```
0
351
E
Jeff and Permutation
PROGRAMMING
2,200
[ "greedy" ]
null
null
Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence *p*1,<=*p*2,<=...,<=*p**n* for his birthday. Jeff hates inversions in sequences. An inversion in sequence *a*1,<=*a*2,<=...,<=*a**n* is a pair of indexes *i*,<=*j* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*), such...
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000). The next line contains *n* integers — sequence *p*1, *p*2, ..., *p**n* (|*p**i*|<=≤<=105). The numbers are separated by spaces.
In a single line print the answer to the problem — the minimum number of inversions Jeff can get.
[ "2\n2 1\n", "9\n-2 0 -1 0 -1 2 1 0 -1\n" ]
[ "0\n", "6\n" ]
none
2,000
[ { "input": "2\n2 1", "output": "0" }, { "input": "9\n-2 0 -1 0 -1 2 1 0 -1", "output": "6" }, { "input": "9\n0 0 1 1 0 0 1 0 1", "output": "5" }, { "input": "8\n0 1 2 -1 -2 1 -2 2", "output": "3" }, { "input": "24\n-1 -1 2 2 0 -2 2 -1 0 0 2 -2 3 0 2 -3 0 -3 -1 1 0...
1,521,585,972
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
124
7,065,600
print("QUE TE CACHEN PROBLEMA E(DIV1)") print("By: GUillermo Montanez Sosa - Guillermo_0114")
Title: Jeff and Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence *p*1,<=*p*2,<=...,<=*p**n* for his birthday. Jeff hates inversions in sequences. An inversion ...
```python print("QUE TE CACHEN PROBLEMA E(DIV1)") print("By: GUillermo Montanez Sosa - Guillermo_0114") ```
0
409
D
Big Data
PROGRAMMING
1,700
[ "*special" ]
null
null
Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put some important facts to this array. Here are the first few of the facts: - ...
The input will contain a single integer between 1 and 16.
Output a single integer.
[ "1\n", "7\n" ]
[ "1\n", "0\n" ]
none
0
[ { "input": "1", "output": "1" }, { "input": "7", "output": "0" }, { "input": "13", "output": "1" }, { "input": "3", "output": "0" }, { "input": "8", "output": "1" }, { "input": "16", "output": "0" }, { "input": "11", "output": "0" }, ...
1,643,029,745
2,147,483,647
PyPy 3
OK
TESTS
16
77
0
s="01001010111001010" print(s[int(input())])
Title: Big Data Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift ...
```python s="01001010111001010" print(s[int(input())]) ```
3
518
B
Tanya and Postcard
PROGRAMMING
1,400
[ "greedy", "implementation", "strings" ]
null
null
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s...
The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message. The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper. Here |*a*| means the ...
Print two integers separated by a space: - the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message.
[ "AbC\nDCbA\n", "ABC\nabc\n", "abacaba\nAbaCaBA\n" ]
[ "3 0\n", "0 3\n", "3 4\n" ]
none
1,000
[ { "input": "AbC\nDCbA", "output": "3 0" }, { "input": "ABC\nabc", "output": "0 3" }, { "input": "abacaba\nAbaCaBA", "output": "3 4" }, { "input": "zzzzz\nZZZZZ", "output": "0 5" }, { "input": "zzzZZZ\nZZZzzZ", "output": "5 1" }, { "input": "abcdefghijk...
1,635,692,407
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
124
21,401,600
import heapq; stringOne = input() stringTwo = input() hashMapOne = {char: 0 for char in stringOne} hashMapTwo = {char: 0 for char in stringTwo} for char in stringOne: hashMapOne[char] += 1 for char in stringTwo: hashMapTwo[char] += 1 yay = 0 whoo = 0 heap = [] for char in hashMapTwo: heap...
Title: Tanya and Postcard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she f...
```python import heapq; stringOne = input() stringTwo = input() hashMapOne = {char: 0 for char in stringOne} hashMapTwo = {char: 0 for char in stringTwo} for char in stringOne: hashMapOne[char] += 1 for char in stringTwo: hashMapTwo[char] += 1 yay = 0 whoo = 0 heap = [] for char in hashMapTwo:...
0
727
C
Guess the Array
PROGRAMMING
1,400
[ "constructive algorithms", "interactive", "math" ]
null
null
This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output). In this problem you should guess an array *a* which is unknown for you. The only information you have init...
none
none
[ "5\n \n9\n \n7\n \n9\n \n11\n \n6\n " ]
[ "? 1 5\n \n? 2 3\n \n? 4 1\n \n? 5 2\n \n? 3 4\n \n! 4 6 1 5 5" ]
The format of a test to make a hack is: - The first line contains an integer number *n* (3 ≤ *n* ≤ 5000) — the length of the array.- The second line contains *n* numbers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-inde...
1,500
[ { "input": "5\n4 6 1 5 5", "output": "5 out of 5" }, { "input": "3\n1 1 1", "output": "3 out of 3" }, { "input": "4\n100 1 100 1", "output": "4 out of 4" }, { "input": "10\n9 5 10 7 4 4 8 5 10 5", "output": "10 out of 10" }, { "input": "3\n1 1 1", "output": "3...
1,586,955,084
2,147,483,647
PyPy 3
IDLENESS_LIMIT_EXCEEDED
TESTS
0
0
0
from math import ceil,gcd,floor from collections import deque,defaultdict as dict from heapq import heappush as hpush,heappop as hpop, heapify from functools import lru_cache import sys input = sys.stdin.buffer.readline inf=float("inf") def inpi(): return(int(input())) def inpa(): return(list(map(int,input()....
Title: Guess the Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output). In th...
```python from math import ceil,gcd,floor from collections import deque,defaultdict as dict from heapq import heappush as hpush,heappop as hpop, heapify from functools import lru_cache import sys input = sys.stdin.buffer.readline inf=float("inf") def inpi(): return(int(input())) def inpa(): return(list(map(in...
-1
743
B
Chloe and the sequence
PROGRAMMING
1,200
[ "binary search", "bitmasks", "constructive algorithms", "implementation" ]
null
null
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad. Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq...
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1).
Print single integer — the integer at the *k*-th position in the obtained sequence.
[ "3 2\n", "4 8\n" ]
[ "2", "4" ]
In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2. In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4.
1,000
[ { "input": "3 2", "output": "2" }, { "input": "4 8", "output": "4" }, { "input": "5 27", "output": "1" }, { "input": "7 44", "output": "3" }, { "input": "15 18432", "output": "12" }, { "input": "20 259676", "output": "3" }, { "input": "30 6...
1,556,803,691
1,691
Python 3
WRONG_ANSWER
TESTS
2
93
0
N, K = map(int, input().split()) L = [0] * 60 L[0] = 1 for i in range(1, 60): L[i] = 2 * L[i - 1] + 1 def calc(n, k): if k == L[n] // 2: return n + 1 elif k > L[n] // 2: return calc(n - 1, k - L[n] // 2) else: return calc(n - 1, k) print(calc(N - 1, K - 1))
Title: Chloe and the sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad. Let's consider the following a...
```python N, K = map(int, input().split()) L = [0] * 60 L[0] = 1 for i in range(1, 60): L[i] = 2 * L[i - 1] + 1 def calc(n, k): if k == L[n] // 2: return n + 1 elif k > L[n] // 2: return calc(n - 1, k - L[n] // 2) else: return calc(n - 1, k) print(calc(N - 1, ...
0
985
C
Liebig's Barrels
PROGRAMMING
1,500
[ "greedy" ]
null
null
You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to exactly one barrel. Let volume *v**j* of barrel *j* be equal to the length of the minimal stave in it. ...
The first line contains three space-separated integers *n*, *k* and *l* (1<=≤<=*n*,<=*k*<=≤<=105, 1<=≤<=*n*·*k*<=≤<=105, 0<=≤<=*l*<=≤<=109). The second line contains *m*<==<=*n*·*k* space-separated integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — lengths of staves.
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly *n* barrels satisfying the condition |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
[ "4 2 1\n2 2 1 2 3 2 2 3\n", "2 1 0\n10 10\n", "1 2 1\n5 2\n", "3 2 1\n1 2 3 4 5 6\n" ]
[ "7\n", "20\n", "2\n", "0\n" ]
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3]. In the second example you can form the following barrels: [10], [10]. In the third example you can form the following barrels: [2, 5]. In the fourth example difference between volumes of barrels in any partition is at least 2 so...
0
[ { "input": "4 2 1\n2 2 1 2 3 2 2 3", "output": "7" }, { "input": "2 1 0\n10 10", "output": "20" }, { "input": "1 2 1\n5 2", "output": "2" }, { "input": "3 2 1\n1 2 3 4 5 6", "output": "0" }, { "input": "10 3 189\n267 697 667 4 52 128 85 616 142 344 413 660 962 194...
1,526,986,110
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
155
7,782,400
a=list(map(int,input().split())) n=a[0] k=a[1] l=a[2] m=n*k s=list(map(int,input().split())) flag=m s.sort() for i in range(m): if s[i]-s[0]>l: flag=i break if flag==n-1: print("0") else: b=flag-n+1 sum=0 t=0 for i in range(0,b,k): sum=sum+s[i] ...
Title: Liebig's Barrels Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to ex...
```python a=list(map(int,input().split())) n=a[0] k=a[1] l=a[2] m=n*k s=list(map(int,input().split())) flag=m s.sort() for i in range(m): if s[i]-s[0]>l: flag=i break if flag==n-1: print("0") else: b=flag-n+1 sum=0 t=0 for i in range(0,b,k): sum=sum+s[i...
0
408
A
Line to Cashier
PROGRAMMING
900
[ "implementation" ]
null
null
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier. The *i*-th of the next *n* lines contains *k**i*...
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
[ "1\n1\n1\n", "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n" ]
[ "20\n", "100\n" ]
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
500
[ { "input": "1\n1\n1", "output": "20" }, { "input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100" }, { "input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3", "output": "100" }, { "input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"...
1,563,261,273
2,147,483,647
PyPy 3
OK
TESTS
20
140
1,536,000
class CodeforcesTask408ASolution: def __init__(self): self.result = '' self.cash_count = 0 self.client_cashwise = [] self.baskets = [] def read_input(self): self.cash_count = int(input()) self.client_cashwise = [int(x) for x in input().split(" ")] ...
Title: Line to Cashier Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* c...
```python class CodeforcesTask408ASolution: def __init__(self): self.result = '' self.cash_count = 0 self.client_cashwise = [] self.baskets = [] def read_input(self): self.cash_count = int(input()) self.client_cashwise = [int(x) for x in input().split(" ...
3
347
B
Fixed Points
PROGRAMMING
1,100
[ "brute force", "implementation", "math" ]
null
null
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not. A fixed point of a function is a point that is mapped to itself by the function. A p...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation.
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
[ "5\n0 1 3 4 2\n" ]
[ "3\n" ]
none
1,000
[ { "input": "5\n0 1 3 4 2", "output": "3" }, { "input": "10\n6 9 4 7 8 2 3 5 0 1", "output": "2" }, { "input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15...
1,691,671,297
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
13,107,200
n = int(input()) list = list(map(int, input().split())) c=0 u=False for i in range(len(list)): if list[i]!=(i) and u==False: f=list.index(i) if list[i]==f: c+=2 u=True elif list[i]==i : c+=1 if c==len(list): print(c) else: if u==False : ...
Title: Fixed Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<...
```python n = int(input()) list = list(map(int, input().split())) c=0 u=False for i in range(len(list)): if list[i]!=(i) and u==False: f=list.index(i) if list[i]==f: c+=2 u=True elif list[i]==i : c+=1 if c==len(list): print(c) else: if u==...
0
645
A
Amity Assessment
PROGRAMMING
1,200
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the ...
The first two lines of the input consist of a 2<=×<=2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2<=×<=2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaran...
Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).
[ "AB\nXC\nXB\nAC\n", "AB\nXC\nAC\nBX\n" ]
[ "YES\n", "NO\n" ]
The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down. In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all...
500
[ { "input": "AB\nXC\nXB\nAC", "output": "YES" }, { "input": "AB\nXC\nAC\nBX", "output": "NO" }, { "input": "XC\nBA\nCB\nAX", "output": "NO" }, { "input": "AB\nXC\nAX\nCB", "output": "YES" }, { "input": "CB\nAX\nXA\nBC", "output": "YES" }, { "input": "BC...
1,636,754,218
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
61
28,364,800
def solve(s): tem = '' for j in range(4): ix = (i + j) % 4 if s[ix] != 'X': tem += s[ix] if tem in mem: exit(print('YES')) mem[tem] = True a, b, mem = input() + input()[::-1], input() + input()[::-1], dict() for i in range(4): solve(a) solve(...
Title: Amity Assessment Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one ...
```python def solve(s): tem = '' for j in range(4): ix = (i + j) % 4 if s[ix] != 'X': tem += s[ix] if tem in mem: exit(print('YES')) mem[tem] = True a, b, mem = input() + input()[::-1], input() + input()[::-1], dict() for i in range(4): solve(a) ...
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,608,460,061
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
n = input() m = input() for i in range(len(m)): if int(m) ^ int(n): print("1",end="") else: print("0",end="")
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python n = input() m = input() for i in range(len(m)): if int(m) ^ int(n): print("1",end="") else: print("0",end="") ```
0
272
A
Dima and Friends
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show. The numbers in the lines are separated by a single s...
In a single line print the answer to the problem.
[ "1\n1\n", "1\n2\n", "2\n3 5\n" ]
[ "3\n", "2\n", "3\n" ]
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend. In the second sample Dima can show 2 or 4 fingers.
500
[ { "input": "1\n1", "output": "3" }, { "input": "1\n2", "output": "2" }, { "input": "2\n3 5", "output": "3" }, { "input": "2\n3 5", "output": "3" }, { "input": "1\n5", "output": "3" }, { "input": "5\n4 4 3 5 1", "output": "4" }, { "input": "...
1,647,143,270
2,147,483,647
Python 3
OK
TESTS
30
92
0
""" sumOfFinger=sum(fingerShownByFriends) Dima can show 1 to 5 fingers.. so k = [sumOfFingers+i for i in range(1,6)] now we've to check if k[i] prsenet in arithmetic progression whose firstVal=1 and diff=numOfFriens+1 if k[i] is present== =>>then it means if Dima shows i+1 fingers then.. =>>then counting w...
Title: Dima and Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the...
```python """ sumOfFinger=sum(fingerShownByFriends) Dima can show 1 to 5 fingers.. so k = [sumOfFingers+i for i in range(1,6)] now we've to check if k[i] prsenet in arithmetic progression whose firstVal=1 and diff=numOfFriens+1 if k[i] is present== =>>then it means if Dima shows i+1 fingers then.. =>>then ...
3
362
B
Petya and Staircases
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. No...
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty s...
Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO".
[ "10 5\n2 4 8 3 6\n", "10 5\n2 4 5 7 9\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "10 5\n2 4 8 3 6", "output": "NO" }, { "input": "10 5\n2 4 5 7 9", "output": "YES" }, { "input": "10 9\n2 3 4 5 6 7 8 9 10", "output": "NO" }, { "input": "5 2\n4 5", "output": "NO" }, { "input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37", "outp...
1,569,062,662
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
124
0
class CodeforcesTask362BSolution: def __init__(self): self.result = '' self.n_m = [] self.dirty = [] def read_input(self): self.n_m = [int(x) for x in input().split(" ")] self.dirty = [int(x) for x in input().split(" ")] def process_task(self): dirty = {} ...
Title: Petya and Staircases Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump o...
```python class CodeforcesTask362BSolution: def __init__(self): self.result = '' self.n_m = [] self.dirty = [] def read_input(self): self.n_m = [int(x) for x in input().split(" ")] self.dirty = [int(x) for x in input().split(" ")] def process_task(self): dir...
0
701
B
Cells Not Under Attack
PROGRAMMING
1,200
[ "data structures", "math" ]
null
null
Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another. The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there ...
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=*min*(100<=000,<=*n*2)) — the size of the board and the number of rooks. Each of the next *m* lines contains integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the number of the row and the number of the col...
Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put.
[ "3 3\n1 1\n3 1\n2 2\n", "5 2\n1 5\n5 1\n", "100000 1\n300 400\n" ]
[ "4 2 0 \n", "16 9 \n", "9999800001 \n" ]
On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack.
750
[ { "input": "3 3\n1 1\n3 1\n2 2", "output": "4 2 0 " }, { "input": "5 2\n1 5\n5 1", "output": "16 9 " }, { "input": "100000 1\n300 400", "output": "9999800001 " }, { "input": "10 4\n2 8\n1 8\n9 8\n6 9", "output": "81 72 63 48 " }, { "input": "30 30\n3 13\n27 23\n18...
1,626,838,620
2,147,483,647
Python 3
OK
TESTS
40
405
15,052,800
import sys input = lambda:sys.stdin.readline() int_arr = lambda: list(map(int,input().split())) str_arr = lambda: list(map(str,input().split())) get_str = lambda: map(str,input().split()) get_int = lambda: map(int,input().split()) get_flo = lambda: map(float,input().split()) mod = 1000000007 # def solve()...
Title: Cells Not Under Attack Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another. The cell of the field is under rook's a...
```python import sys input = lambda:sys.stdin.readline() int_arr = lambda: list(map(int,input().split())) str_arr = lambda: list(map(str,input().split())) get_str = lambda: map(str,input().split()) get_int = lambda: map(int,input().split()) get_flo = lambda: map(float,input().split()) mod = 1000000007 # d...
3
215
A
Bicycle Chain
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the *i*-th star on the pedal axle has *a**i* (0<=&lt;<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<...
The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing. The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars o...
Print the number of "integer" gears with the maximum ratio among all "integer" gears.
[ "2\n4 5\n3\n12 13 15\n", "4\n1 2 3 4\n5\n10 11 12 13 14\n" ]
[ "2\n", "1\n" ]
In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15.
500
[ { "input": "2\n4 5\n3\n12 13 15", "output": "2" }, { "input": "4\n1 2 3 4\n5\n10 11 12 13 14", "output": "1" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "2\n1 2\n1\n1", "output": "1" }, { "input": "1\n1\n2\n1 2", "output": "1" }, { "input":...
1,697,016,053
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
124
0
n = int(input()) a = list(map(int,input().split())) t = int(input()) s = list(map(int,input().split())) maxi = max(s)//min(a) c = set() for i in range(n) : for j in range(t) : if s[j]/a[i] == maxi : c.add((s[j],a[i])) print(len(c))
Title: Bicycle Chain Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We ...
```python n = int(input()) a = list(map(int,input().split())) t = int(input()) s = list(map(int,input().split())) maxi = max(s)//min(a) c = set() for i in range(n) : for j in range(t) : if s[j]/a[i] == maxi : c.add((s[j],a[i])) print(len(c)) ```
0
296
B
Yaroslav and Two Strings
PROGRAMMING
2,000
[ "combinatorics", "dp" ]
null
null
Yaroslav thinks that two strings *s* and *w*, consisting of digits and having length *n* are non-comparable if there are two numbers, *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*n*), such that *s**i*<=&gt;<=*w**i* and *s**j*<=&lt;<=*w**j*. Here sign *s**i* represents the *i*-th digit of string *s*, similarly, *w**j* represents t...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals *n*. The third line contains the second template in the same format.
In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109<=+<=7).
[ "2\n90\n09\n", "2\n11\n55\n", "5\n?????\n?????\n" ]
[ "1\n", "0\n", "993531194\n" ]
The first test contains no question marks and both strings are incomparable, so the answer is 1. The second test has no question marks, but the given strings are comparable, so the answer is 0.
1,500
[ { "input": "2\n90\n09", "output": "1" }, { "input": "2\n11\n55", "output": "0" }, { "input": "5\n?????\n?????", "output": "993531194" }, { "input": "10\n104?3?1??3\n?1755?1??7", "output": "91015750" }, { "input": "10\n6276405116\n6787?352?9", "output": "46" ...
1,578,672,272
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
218
307,200
mod = 1000000007 n = int(input()) s1 = input() s2 = input() ans = 1 tc = 1 for i in range(n): if s1[i] == '?': ans *= 10 ans %= mod if s2[i] == '?': ans *= 10 ans %= mod for i in range(n): if s1[i] != '?' and s2[i] != '?' and s1[i] > s2[i]: break if s1[i] == '?' and s2[i] == '?': tc *= 55 tc %= mod ...
Title: Yaroslav and Two Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yaroslav thinks that two strings *s* and *w*, consisting of digits and having length *n* are non-comparable if there are two numbers, *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*n*), such that *s**i*<=&gt;<=*w**i* and *s...
```python mod = 1000000007 n = int(input()) s1 = input() s2 = input() ans = 1 tc = 1 for i in range(n): if s1[i] == '?': ans *= 10 ans %= mod if s2[i] == '?': ans *= 10 ans %= mod for i in range(n): if s1[i] != '?' and s2[i] != '?' and s1[i] > s2[i]: break if s1[i] == '?' and s2[i] == '?': tc *= 55 t...
0
981
C
Useful Decomposition
PROGRAMMING
1,400
[ "implementation", "trees" ]
null
null
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)! He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help! The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa...
The first line contains a single integer $n$ ($2 \leq n \leq 10^{5}$) the number of nodes in the tree. Each of the next $n<=-<=1$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n$, $a_i \neq b_i$) — the edges of the tree. It is guaranteed that the given edges form a tree.
If there are no decompositions, print the only line containing "No". Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $m$. Each of the next $m$ lines should contain two integers $u_i$, $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$) denoting that one of ...
[ "4\n1 2\n2 3\n3 4\n", "6\n1 2\n2 3\n3 4\n2 5\n3 6\n", "5\n1 2\n1 3\n1 4\n1 5\n" ]
[ "Yes\n1\n1 4\n", "No\n", "Yes\n4\n1 2\n1 3\n1 4\n1 5\n" ]
The tree from the first example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/9eb4b4c143d3ad267ae05d1e43341bd368b3088b.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see ...
1,250
[ { "input": "4\n1 2\n2 3\n3 4", "output": "Yes\n1\n1 4" }, { "input": "6\n1 2\n2 3\n3 4\n2 5\n3 6", "output": "No" }, { "input": "5\n1 2\n1 3\n1 4\n1 5", "output": "Yes\n4\n1 2\n1 3\n1 4\n1 5" }, { "input": "2\n1 2", "output": "Yes\n1\n1 2" }, { "input": "8\n1 2\n1...
1,527,615,561
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
import sys def dfs(start, visited=set({})): ans = [] visited.add(start) leaf = True for v in g[start]: if v not in visited: leaf = False ans += dfs(v) if leaf: return ans + [start] return ans n = int(sys.stdin.readline().strip()) g = {i:[] for i in range(n+1)} for _ in range(n-1): u,v = map(int,sys.s...
Title: Useful Decomposition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)! He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help! Th...
```python import sys def dfs(start, visited=set({})): ans = [] visited.add(start) leaf = True for v in g[start]: if v not in visited: leaf = False ans += dfs(v) if leaf: return ans + [start] return ans n = int(sys.stdin.readline().strip()) g = {i:[] for i in range(n+1)} for _ in range(n-1): u,v = map...
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,481,130,423
2,147,483,647
Python 3
OK
TESTS
32
124
4,608,000
n=int(input()) m=input().split() jishu=0 oushu=0 for i in range(3): k=int(m[i])/2-int(m[i])//2 if k==0: oushu+=1 else: jishu+=1 if jishu>oushu: for i in range(n): kt=int(m[i])/2-int(m[i])//2 if kt==0: print(i+1) break else: for...
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()) m=input().split() jishu=0 oushu=0 for i in range(3): k=int(m[i])/2-int(m[i])//2 if k==0: oushu+=1 else: jishu+=1 if jishu>oushu: for i in range(n): kt=int(m[i])/2-int(m[i])//2 if kt==0: print(i+1) break else...
3.960417
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,589,206,044
2,147,483,647
Python 3
OK
TESTS
42
109
6,656,000
l,r = map(int,input().split()) range = r - l + 1 if (range < 3) or (l % 2 == 1 and range < 4): print(-1) else: if (l % 2 == 0): print(l,l+1,l+2) else: print(l+1,l+2,l+3)
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 l,r = map(int,input().split()) range = r - l + 1 if (range < 3) or (l % 2 == 1 and range < 4): print(-1) else: if (l % 2 == 0): print(l,l+1,l+2) else: print(l+1,l+2,l+3) ```
3
931
A
Friends Meeting
PROGRAMMING
800
[ "brute force", "greedy", "implementation", "math" ]
null
null
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco...
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*.
Print the minimum possible total tiredness if the friends meet in the same point.
[ "3\n4\n", "101\n99\n", "5\n10\n" ]
[ "1\n", "2\n", "9\n" ]
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, an...
500
[ { "input": "3\n4", "output": "1" }, { "input": "101\n99", "output": "2" }, { "input": "5\n10", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n1000", "output": "250000" }, { "input": "999\n1000", "output": "1" }, { "inpu...
1,573,648,367
2,147,483,647
Python 3
OK
TESTS
40
109
0
import math a = int(input()) b = int(input()) z = math.fabs(a-b)//2 n = 0 for i in range(int((math.fabs(a-b)-z))+1): n+=i for i in range(int(z)+1): n+=i print(n)
Title: Friends Meeting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in...
```python import math a = int(input()) b = int(input()) z = math.fabs(a-b)//2 n = 0 for i in range(int((math.fabs(a-b)-z))+1): n+=i for i in range(int(z)+1): n+=i print(n) ```
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,655,896,843
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
n = int(input()) h = int(input()) j = str(n+h) j = j.replace("2","0") print(int(j))
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python n = int(input()) h = int(input()) j = str(n+h) j = j.replace("2","0") print(int(j)) ```
0
764
A
Taymyr is calling you
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,...
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
[ "1 1 10\n", "1 2 5\n", "2 3 9\n" ]
[ "10\n", "2\n", "1\n" ]
Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
500
[ { "input": "1 1 10", "output": "10" }, { "input": "1 2 5", "output": "2" }, { "input": "2 3 9", "output": "1" }, { "input": "4 8 9", "output": "1" }, { "input": "7 9 2", "output": "0" }, { "input": "10000 10000 10000", "output": "1" }, { "i...
1,618,300,521
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
n,k,z = [int(x) for x in input().split()] a = [n*x for x in range(1,z+1) if n*k <=z] b = [k*x for x in range(1,z+1)if k*x <=z] print(len(set(a)&set(b)))
Title: Taymyr is calling you Time Limit: None seconds Memory Limit: None megabytes Problem Description: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com...
```python n,k,z = [int(x) for x in input().split()] a = [n*x for x in range(1,z+1) if n*k <=z] b = [k*x for x in range(1,z+1)if k*x <=z] print(len(set(a)&set(b))) ```
0
388
A
Fox and Box Accumulation
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100).
Output a single integer — the minimal possible number of piles.
[ "3\n0 0 10\n", "5\n0 1 2 3 4\n", "4\n0 0 0 0\n", "9\n0 1 0 2 0 1 1 2 10\n" ]
[ "2\n", "1\n", "4\n", "3\n" ]
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
500
[ { "input": "3\n0 0 10", "output": "2" }, { "input": "5\n0 1 2 3 4", "output": "1" }, { "input": "4\n0 0 0 0", "output": "4" }, { "input": "9\n0 1 0 2 0 1 1 2 10", "output": "3" }, { "input": "1\n0", "output": "1" }, { "input": "2\n0 0", "output": "...
1,490,908,475
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
62
5,632,000
from collections import Counter def main(): int(input()) c = Counter(map(int, input().split())) ans = 1 for k in c: ans = max(ans, c[k]) print(ans) main()
Title: Fox and Box Accumulation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box...
```python from collections import Counter def main(): int(input()) c = Counter(map(int, input().split())) ans = 1 for k in c: ans = max(ans, c[k]) print(ans) main() ```
0
16
A
Flag
PROGRAMMING
800
[ "implementation" ]
A. Flag
2
64
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be...
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands ...
Output YES, if the flag meets the new ISO standard, and NO otherwise.
[ "3 3\n000\n111\n222\n", "3 3\n000\n000\n111\n", "3 3\n000\n111\n002\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
0
[ { "input": "3 3\n000\n111\n222", "output": "YES" }, { "input": "3 3\n000\n000\n111", "output": "NO" }, { "input": "3 3\n000\n111\n002", "output": "NO" }, { "input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000...
1,560,918,665
365
Python 3
WRONG_ANSWER
TESTS
0
218
0
n,k=map(int,input().strip().split()) v = [] for i in range(2,n+1): if all(i%j!=0 for j in v): v.append(i) c=0 for i in range(len(v)-1): if v[i]+v[i+1]+1 in v: c+=1 if(c>=k): print("YES") else: print("NO")
Title: Flag Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of...
```python n,k=map(int,input().strip().split()) v = [] for i in range(2,n+1): if all(i%j!=0 for j in v): v.append(i) c=0 for i in range(len(v)-1): if v[i]+v[i+1]+1 in v: c+=1 if(c>=k): print("YES") else: print("NO") ```
0
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. Th...
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number — the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0...
1,676,229,881
2,147,483,647
Python 3
OK
TESTS
35
46
0
n=input().split() p=input().split() k=int(n[1]) x=int(n[0]) a=0 o=0 if k>5: o=0 else: for i in p: i=int(i) if k+i<=5: a+=1 if a==3: o+=1 a-=3 print(o)
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi...
```python n=input().split() p=input().split() k=int(n[1]) x=int(n[0]) a=0 o=0 if k>5: o=0 else: for i in p: i=int(i) if k+i<=5: a+=1 if a==3: o+=1 a-=3 print(o) ```
3
1,011
B
Planning The Expedition
PROGRAMMING
1,200
[ "binary search", "brute force", "implementation" ]
null
null
Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant. The warehouse has $m$ daily food packages. Each package has some food type $a_i$. Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat t...
The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 100$) — the number of the expedition participants and the number of the daily food packages available. The second line contains sequence of integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le 100$), where $a_i$ is the type of $i$-th food pac...
Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0.
[ "4 10\n1 5 2 1 1 1 2 5 7 2\n", "100 1\n1\n", "2 5\n5 4 3 2 1\n", "3 9\n42 42 42 42 42 42 42 42 42\n" ]
[ "2\n", "0\n", "1\n", "3\n" ]
In the first example, Natasha can assign type $1$ food to the first participant, the same type $1$ to the second, type $5$ to the third and type $2$ to the fourth. In this case, the expedition can last for $2$ days, since each participant can get two food packages of his food type (there will be used $4$ packages of ty...
1,000
[ { "input": "4 10\n1 5 2 1 1 1 2 5 7 2", "output": "2" }, { "input": "100 1\n1", "output": "0" }, { "input": "2 5\n5 4 3 2 1", "output": "1" }, { "input": "3 9\n42 42 42 42 42 42 42 42 42", "output": "3" }, { "input": "1 1\n100", "output": "1" }, { "inp...
1,532,870,650
5,350
Python 3
WRONG_ANSWER
TESTS
5
109
0
n, m = map(int, input().split()) a = [int(i) for i in input().split()] if m >= n: b = [] for item in set(a): b.append(a.count(item)) if len(b) == 1: print(b[0] // n) else: while len(b) < n: b.sort() b.append(b[-1] // 2) b[-2] = b[-2...
Title: Planning The Expedition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant. The warehouse has $m$ daily food packages. Each package has some food type $a_i$. E...
```python n, m = map(int, input().split()) a = [int(i) for i in input().split()] if m >= n: b = [] for item in set(a): b.append(a.count(item)) if len(b) == 1: print(b[0] // n) else: while len(b) < n: b.sort() b.append(b[-1] // 2) b[...
0
166
B
Polygons
PROGRAMMING
2,100
[ "geometry", "sortings" ]
null
null
You've got another geometrical task. You are given two non-degenerate polygons *A* and *B* as vertex coordinates. Polygon *A* is strictly convex. Polygon *B* is an arbitrary polygon without any self-intersections and self-touches. The vertices of both polygons are given in the clockwise order. For each polygon no three...
The first line contains the only integer *n* (3<=≤<=*n*<=≤<=105) — the number of vertices of polygon *A*. Then *n* lines contain pairs of integers *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=109) — coordinates of the *i*-th vertex of polygon *A*. The vertices are given in the clockwise order. The next line contains a sin...
Print on the only line the answer to the problem — if polygon *B* is strictly inside polygon *A*, print "YES", otherwise print "NO" (without the quotes).
[ "6\n-2 1\n0 3\n3 3\n4 1\n3 -2\n2 -2\n4\n0 1\n2 2\n3 1\n1 0\n", "5\n1 2\n4 2\n3 -3\n-2 -2\n-2 1\n4\n0 1\n1 2\n4 1\n2 -1\n", "5\n-1 2\n2 3\n4 1\n3 -2\n0 -3\n5\n1 0\n1 1\n3 1\n5 -1\n2 -1\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
3,000
[ { "input": "6\n-2 1\n0 3\n3 3\n4 1\n3 -2\n2 -2\n4\n0 1\n2 2\n3 1\n1 0", "output": "YES" }, { "input": "5\n1 2\n4 2\n3 -3\n-2 -2\n-2 1\n4\n0 1\n1 2\n4 1\n2 -1", "output": "NO" }, { "input": "5\n-1 2\n2 3\n4 1\n3 -2\n0 -3\n5\n1 0\n1 1\n3 1\n5 -1\n2 -1", "output": "NO" }, { "inp...
1,668,636,537
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
184
0
import sys class Point: def __init__(self, x, y): self.x = x self.y = y def Left_index(points): minn = 0 for i in range(1,len(points)): if points[i].x < points[minn].x: minn = i elif points[i].x == points[minn].x: if points[i].y ...
Title: Polygons Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got another geometrical task. You are given two non-degenerate polygons *A* and *B* as vertex coordinates. Polygon *A* is strictly convex. Polygon *B* is an arbitrary polygon without any self-intersections and self-touc...
```python import sys class Point: def __init__(self, x, y): self.x = x self.y = y def Left_index(points): minn = 0 for i in range(1,len(points)): if points[i].x < points[minn].x: minn = i elif points[i].x == points[minn].x: if po...
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,578,898,643
2,147,483,647
PyPy 3
OK
TESTS
8
140
0
#903A n = int(input()) for i in range(n): x = int(input()) if x%3==0: print('YES') elif x %3== 1: if x >= 7: print('YES') else: print('NO') else: if x >=14: 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 #903A n = int(input()) for i in range(n): x = int(input()) if x%3==0: print('YES') elif x %3== 1: if x >= 7: print('YES') else: print('NO') else: if x >=14: print('YES') else: print('NO') ```
3
584
A
Olesya and Rodion
PROGRAMMING
1,000
[ "math" ]
null
null
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-...
The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by.
Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
[ "3 2\n" ]
[ "712" ]
none
500
[ { "input": "3 2", "output": "222" }, { "input": "2 2", "output": "22" }, { "input": "4 3", "output": "3333" }, { "input": "5 3", "output": "33333" }, { "input": "10 7", "output": "7777777777" }, { "input": "2 9", "output": "99" }, { "input"...
1,681,657,366
2,147,483,647
Python 3
OK
TESTS
65
61
0
n, t=(map(int,input().split())) if n==1 and t==10: print(-1) elif n>=2 and t ==10: for i in range((n-1)): print('1',end="") print(0) else: for i in range((n)): print(t,end="")
Title: Olesya and Rodion Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larg...
```python n, t=(map(int,input().split())) if n==1 and t==10: print(-1) elif n>=2 and t ==10: for i in range((n-1)): print('1',end="") print(0) else: for i in range((n)): print(t,end="") ```
3
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,676,830,404
2,147,483,647
Python 3
OK
TESTS
63
78
5,324,800
num = int(input()) number = list(map(int,input().split())) counter = 0 number_poles = 0 for i in range(len(number)): if number[i] == -1 and number_poles == 0: counter += 1 elif number[i] == -1 and number_poles > 0: number_poles -= 1 else: number_poles += number[i] print(co...
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 num = int(input()) number = list(map(int,input().split())) counter = 0 number_poles = 0 for i in range(len(number)): if number[i] == -1 and number_poles == 0: counter += 1 elif number[i] == -1 and number_poles > 0: number_poles -= 1 else: number_poles += number[i]...
3
597
A
Divisibility
PROGRAMMING
1,600
[ "math" ]
null
null
Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*.
The only line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=1018;<=-<=1018<=≤<=*a*<=≤<=*b*<=≤<=1018).
Print the required number.
[ "1 1 10\n", "2 -4 4\n" ]
[ "10\n", "5\n" ]
none
500
[ { "input": "1 1 10", "output": "10" }, { "input": "2 -4 4", "output": "5" }, { "input": "1 1 1", "output": "1" }, { "input": "1 0 0", "output": "1" }, { "input": "1 0 1", "output": "2" }, { "input": "1 10181 10182", "output": "2" }, { "inpu...
1,585,834,959
2,147,483,647
PyPy 3
OK
TESTS
81
155
0
print((lambda x : (x[2]//x[0])-((x[1]-1)//x[0]))(list(map(int,input().split()))))
Title: Divisibility Time Limit: None seconds Memory Limit: None megabytes Problem Description: Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*. Input Specification: The onl...
```python print((lambda x : (x[2]//x[0])-((x[1]-1)//x[0]))(list(map(int,input().split())))) ```
3
141
A
Amusing Joke
PROGRAMMING
800
[ "implementation", "sortings", "strings" ]
null
null
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O...
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do...
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
[ "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n", "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n", "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n" ]
[ "YES\n", "NO\n", "NO\n" ]
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
500
[ { "input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS", "output": "YES" }, { "input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI", "output": "NO" }, { "input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER", "output": "NO" }, { "input": "B\nA\nAB", "output": ...
1,690,797,405
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
a = input("") b = input("") d = input("") c = 0 for i in d: if a.count(i) + b.count(i) != d.count(i): c += 1 print("NO") break else: a.replace(i, "") b.replace(i, "") d.replace(i, "") if c == 0 and b == "" and a == "": print("YES") else: pr...
Title: Amusing Joke Time Limit: None seconds Memory Limit: None megabytes Problem Description: So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam...
```python a = input("") b = input("") d = input("") c = 0 for i in d: if a.count(i) + b.count(i) != d.count(i): c += 1 print("NO") break else: a.replace(i, "") b.replace(i, "") d.replace(i, "") if c == 0 and b == "" and a == "": print("YES") els...
0
989
A
A Blend of Springtime
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone." "But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic. The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o...
The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise. You can print each letter in any case (upper or lower).
[ ".BAC.\n", "AA..CB\n" ]
[ "Yes\n", "No\n" ]
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it. In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
500
[ { "input": ".BAC.", "output": "Yes" }, { "input": "AA..CB", "output": "No" }, { "input": ".", "output": "No" }, { "input": "ACB.AAAAAA", "output": "Yes" }, { "input": "B.BC.BBBCA", "output": "Yes" }, { "input": "BA..CAB..B", "output": "Yes" }, ...
1,590,471,248
2,147,483,647
PyPy 3
OK
TESTS
37
124
0
s=input() n=len(s) f=0 for i in range(n-2): if(ord(s[i])+ord(s[i+1])+ord(s[i+2])==198 and s[i]!=s[i+1]): f=1 break if(f==0): print("NO") else: print("YES")
Title: A Blend of Springtime Time Limit: None seconds Memory Limit: None megabytes Problem Description: "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone." "But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimisti...
```python s=input() n=len(s) f=0 for i in range(n-2): if(ord(s[i])+ord(s[i+1])+ord(s[i+2])==198 and s[i]!=s[i+1]): f=1 break if(f==0): print("NO") else: print("YES") ```
3
841
B
Godsend
PROGRAMMING
1,100
[ "games", "math" ]
null
null
Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts...
First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array. Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
[ "4\n1 3 2 3\n", "2\n2 2\n" ]
[ "First\n", "Second\n" ]
In first sample first player remove whole array in one move and win. In second sample first player can't make a move and lose.
1,000
[ { "input": "4\n1 3 2 3", "output": "First" }, { "input": "2\n2 2", "output": "Second" }, { "input": "4\n2 4 6 8", "output": "Second" }, { "input": "5\n1 1 1 1 1", "output": "First" }, { "input": "4\n720074544 345031254 849487632 80870826", "output": "Second" ...
1,669,880,878
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
576
69,529,600
n=int(input()) p=list(map(int, input().split())) eve=0 odd=0 for i in p: if i%2==0: eve+=1 else: odd+=1 if eve > odd: print("Second") else: print("First")
Title: Godsend Time Limit: None seconds Memory Limit: None megabytes Problem Description: Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero l...
```python n=int(input()) p=list(map(int, input().split())) eve=0 odd=0 for i in p: if i%2==0: eve+=1 else: odd+=1 if eve > odd: print("Second") else: print("First") ```
0
327
A
Flipping Game
PROGRAMMING
1,200
[ "brute force", "dp", "implementation" ]
null
null
Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1.
Print an integer — the maximal number of 1s that can be obtained after exactly one move.
[ "5\n1 0 0 1 0\n", "4\n1 0 0 1\n" ]
[ "4\n", "4\n" ]
In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1]. In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all nu...
500
[ { "input": "5\n1 0 0 1 0", "output": "4" }, { "input": "4\n1 0 0 1", "output": "4" }, { "input": "1\n1", "output": "0" }, { "input": "1\n0", "output": "1" }, { "input": "8\n1 0 0 0 1 0 0 0", "output": "7" }, { "input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
1,666,338,048
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
0
n = int(input()) nums = [int(i) for i in input().split()] max_zero = 0 less_ones = 0 has_no_zero = True for i in range(n): for j in range(i, n): now_zero = nums[i:j].count(0) - nums[i:j].count(1) if now_zero > max_zero: max_zero = now_zero less_ones = nums[i:j].coun...
Title: Flipping Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *...
```python n = int(input()) nums = [int(i) for i in input().split()] max_zero = 0 less_ones = 0 has_no_zero = True for i in range(n): for j in range(i, n): now_zero = nums[i:j].count(0) - nums[i:j].count(1) if now_zero > max_zero: max_zero = now_zero less_ones = nums...
0
373
A
Collecting Beats is Fun
PROGRAMMING
900
[ "implementation" ]
null
null
Cucumber boy is fan of Kyubeat, a famous music game. Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel. Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with...
The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand. Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If per...
Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes).
[ "1\n.135\n1247\n3468\n5789\n", "5\n..1.\n1111\n..1.\n..1.\n", "1\n....\n12.1\n.2..\n.2..\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands.
500
[ { "input": "1\n.135\n1247\n3468\n5789", "output": "YES" }, { "input": "5\n..1.\n1111\n..1.\n..1.", "output": "YES" }, { "input": "1\n....\n12.1\n.2..\n.2..", "output": "NO" }, { "input": "1\n6981\n.527\n4163\n2345", "output": "YES" }, { "input": "5\n9999\n9999\n99...
1,606,121,918
2,147,483,647
PyPy 3
OK
TESTS
27
155
0
# https://codeforces.com/problemset/problem/373/A # 900 n = int(input()) n2 = n * 2 x = {} o = "YES" for _ in range(4): r = input() for c in r: if c == ".": continue x.setdefault(c, 0) x[c] += 1 if x[c] > n2: o = "NO" break print(o)
Title: Collecting Beats is Fun Time Limit: None seconds Memory Limit: None megabytes Problem Description: Cucumber boy is fan of Kyubeat, a famous music game. Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel. Each panel has a timing to press (the preff...
```python # https://codeforces.com/problemset/problem/373/A # 900 n = int(input()) n2 = n * 2 x = {} o = "YES" for _ in range(4): r = input() for c in r: if c == ".": continue x.setdefault(c, 0) x[c] += 1 if x[c] > n2: o = "NO" break prin...
3
722
C
Destroying Array
PROGRAMMING
1,600
[ "data structures", "dsu" ]
null
null
You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed. After each element is destroyed you have to find o...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). The third line contains a permutation of integers from 1 to *n* — the order used to destroy elements.
Print *n* lines. The *i*-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first *i* operations are performed.
[ "4\n1 3 2 5\n3 4 1 2\n", "5\n1 2 3 4 5\n4 2 3 5 1\n", "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n" ]
[ "5\n4\n3\n0\n", "6\n5\n5\n1\n0\n", "18\n16\n11\n8\n8\n6\n6\n0\n" ]
Consider the first sample: 1. Third element is destroyed. Array is now 1 3  *  5. Segment with maximum sum 5 consists of one integer 5. 1. Fourth element is destroyed. Array is now 1 3  *   * . Segment with maximum sum 4 consists of two integers 1 3. 1. First element is destroyed. Array is now  *  3  *   * . Segme...
1,000
[ { "input": "4\n1 3 2 5\n3 4 1 2", "output": "5\n4\n3\n0" }, { "input": "5\n1 2 3 4 5\n4 2 3 5 1", "output": "6\n5\n5\n1\n0" }, { "input": "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6", "output": "18\n16\n11\n8\n8\n6\n6\n0" }, { "input": "10\n3 3 3 5 6 9 3 1 7 3\n3 4 6 7 5 1 10 9 2 8"...
1,476,783,916
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
5,324,800
size = int(input()) num = list(map(int, input().split(" "))) rem = list(map(lambda x: int(x) - 1, input().split(" "))) def getTree(lst, l, r): if l == r: return {"s": lst[l], "li": l, "ri": r} c = int((l + r) / 2) lt = getTree(lst, l, c) rt = getTree(lst, c + 1, r) return { ...
Title: Destroying Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defin...
```python size = int(input()) num = list(map(int, input().split(" "))) rem = list(map(lambda x: int(x) - 1, input().split(" "))) def getTree(lst, l, r): if l == r: return {"s": lst[l], "li": l, "ri": r} c = int((l + r) / 2) lt = getTree(lst, l, c) rt = getTree(lst, c + 1, r) retur...
0
165
A
Supercentral Point
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'...
The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one spac...
Print the only number — the number of supercentral points of the given set.
[ "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n", "5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n" ]
[ "2\n", "1\n" ]
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
500
[ { "input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2" }, { "input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1" }, { "input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1", "output": "1" }, { "input": "25\n-651 897\n...
1,595,912,626
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
434
22,323,200
t = int(input()) xs,ys,ps = [],[],[] for x in range(t): l1 = [int(x) for x in input().split()] xs.append(l1[0]) ys.append(l1[1]) ps.append([l1[0],l1[1]]) naughtyx = [min(x),max(x)] naughtyy = [min(y),max(y)] counter=0 for x in ps: if xs.count(x[0])>=3 and ys.count(x[1])>=3 and x not in ...
Title: Supercentral Point Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the give...
```python t = int(input()) xs,ys,ps = [],[],[] for x in range(t): l1 = [int(x) for x in input().split()] xs.append(l1[0]) ys.append(l1[1]) ps.append([l1[0],l1[1]]) naughtyx = [min(x),max(x)] naughtyy = [min(y),max(y)] counter=0 for x in ps: if xs.count(x[0])>=3 and ys.count(x[1])>=3 and...
-1
758
A
Holiday Of Equality
PROGRAMMING
800
[ "implementation", "math" ]
null
null
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl...
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
In the only line print the integer *S* — the minimum number of burles which are had to spend.
[ "5\n0 1 2 3 4\n", "5\n1 1 0 1 1\n", "3\n1 3 1\n", "1\n12\n" ]
[ "10", "1", "4", "0" ]
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the thi...
500
[ { "input": "5\n0 1 2 3 4", "output": "10" }, { "input": "5\n1 1 0 1 1", "output": "1" }, { "input": "3\n1 3 1", "output": "4" }, { "input": "1\n12", "output": "0" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "14\n52518 718438 358883 462189 853...
1,660,820,047
2,147,483,647
PyPy 3
OK
TESTS
41
108
0
n = int(input()) l = list(map(int,input().split())) p = max(l) v=0 r=0 for i in l: v = p-i r+=v print(r)
Title: Holiday Of Equality Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens...
```python n = int(input()) l = list(map(int,input().split())) p = max(l) v=0 r=0 for i in l: v = p-i r+=v print(r) ```
3
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*...
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }...
1,689,711,126
2,147,483,647
Python 3
OK
TESTS
43
92
0
num1=int(input()) num2=int(input()) result=num1+num2 a=str(num1).replace("0","") b=str(num2).replace("0","") c=str(result).replace("0","") if int(a)+int(b)==int(c): print("YES") else: print("NO")
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu...
```python num1=int(input()) num2=int(input()) result=num1+num2 a=str(num1).replace("0","") b=str(num2).replace("0","") c=str(result).replace("0","") if int(a)+int(b)==int(c): print("YES") else: print("NO") ```
3.977
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ...
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Print a single line containing a positive integer *m* — the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" ...
1,619,322,477
2,147,483,647
Python 3
OK
TESTS
10
62
0
n = int(input()) lst = [[0] * n] * n for i in range(n): for j in range(n): if (i == 0 or j == 0): lst[i][j] = 1 else: lst[i][j] = lst[i - 1][j] + lst[i][j - 1] # print(lst) print(lst[-1][-1])
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t...
```python n = int(input()) lst = [[0] * n] * n for i in range(n): for j in range(n): if (i == 0 or j == 0): lst[i][j] = 1 else: lst[i][j] = lst[i - 1][j] + lst[i][j - 1] # print(lst) print(lst[-1][-1]) ```
3
808
G
Anthem of Berland
PROGRAMMING
2,300
[ "dp", "strings" ]
null
null
Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem. Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible. H...
The first line contains string of small Latin letters and question marks *s* (1<=≤<=|*s*|<=≤<=105). The second line contains string of small Latin letters *t* (1<=≤<=|*t*|<=≤<=105). Product of lengths of strings |*s*|·|*t*| won't exceed 107.
Output the maximum number of occurrences of string *t* you can achieve by replacing all the question marks in string *s* with small Latin letters.
[ "winlose???winl???w??\nwin\n", "glo?yto?e??an?\nor\n", "??c?????\nabcab\n" ]
[ "5\n", "3\n", "2\n" ]
In the first example the resulting string *s* is "winlosewinwinlwinwin" In the second example the resulting string *s* is "glorytoreorand". The last letter of the string can be arbitrary. In the third example occurrences of string *t* are overlapping. String *s* with maximal number of occurrences of *t* is "abcabcab"...
0
[ { "input": "winlose???winl???w??\nwin", "output": "5" }, { "input": "glo?yto?e??an?\nor", "output": "3" }, { "input": "??c?????\nabcab", "output": "2" }, { "input": "ddddd\nd", "output": "5" }, { "input": "ww?ww\nw", "output": "5" }, { "input": "?????\...
1,497,113,441
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
36
358
921,600
def look(t, i): so = s[i:i + t_len] for j in range(t_len): if not so[j] in [t[j], '?']: return False so[j] = t[j] s[i:i + t_len] = so return True def rlook(t, i): so = rs[i:i + t_len] for j in range(t_len): if not so[j] in [t[j], '?']: ...
Title: Anthem of Berland Time Limit: None seconds Memory Limit: None megabytes Problem Description: Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem. Though there are lots and lots of victories in history of Berland, there i...
```python def look(t, i): so = s[i:i + t_len] for j in range(t_len): if not so[j] in [t[j], '?']: return False so[j] = t[j] s[i:i + t_len] = so return True def rlook(t, i): so = rs[i:i + t_len] for j in range(t_len): if not so[j] in [t[j], '...
0
7
C
Line
PROGRAMMING
1,800
[ "math", "number theory" ]
C. Line
1
256
A line on the plane is described by an equation *Ax*<=+<=*By*<=+<=*C*<==<=0. You are to find any point on this line, whose coordinates are integer numbers from <=-<=5·1018 to 5·1018 inclusive, or to find out that such points do not exist.
The first line contains three integers *A*, *B* and *C* (<=-<=2·109<=≤<=*A*,<=*B*,<=*C*<=≤<=2·109) — corresponding coefficients of the line equation. It is guaranteed that *A*2<=+<=*B*2<=&gt;<=0.
If the required point exists, output its coordinates, otherwise output -1.
[ "2 5 3\n" ]
[ "6 -3\n" ]
none
0
[ { "input": "2 5 3", "output": "6 -3" }, { "input": "0 2 3", "output": "-1" }, { "input": "931480234 -1767614767 -320146190", "output": "-98880374013340920 -52107006370101410" }, { "input": "-1548994394 -1586527767 -1203252104", "output": "-878123061596147680 8573488141506...
1,480,003,091
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
92
0
def compute(): def xgcd(b,n): x0, x1, y0, y1 = 1, 0, 0, 1 while n!=0: q, b, n = b//n, n, b%n x0, x1 = x1, x0 - q*x1 y0, y1 = y1, y0 - q*y1 return b, x0, y0 A, B, C = map(int,input().split()) g, x, y = xgcd(A,B) if abs(-C)%g!=0: return...
Title: Line Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: A line on the plane is described by an equation *Ax*<=+<=*By*<=+<=*C*<==<=0. You are to find any point on this line, whose coordinates are integer numbers from <=-<=5·1018 to 5·1018 inclusive, or to find out that such points do not ex...
```python def compute(): def xgcd(b,n): x0, x1, y0, y1 = 1, 0, 0, 1 while n!=0: q, b, n = b//n, n, b%n x0, x1 = x1, x0 - q*x1 y0, y1 = y1, y0 - q*y1 return b, x0, y0 A, B, C = map(int,input().split()) g, x, y = xgcd(A,B) if abs(-C)%g!=0: ...
-1
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "1000022...
1,675,354,649
2,147,483,647
PyPy 3-64
OK
TESTS
30
92
0
n=input() indx = 0 while (indx<len(n)): if n[indx]=='.': print(0,end="") elif n[indx]=='-': if n[indx+1]=='.': print(1,end="") else: print(2,end="") indx+=1 indx+=1
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ...
```python n=input() indx = 0 while (indx<len(n)): if n[indx]=='.': print(0,end="") elif n[indx]=='-': if n[indx+1]=='.': print(1,end="") else: print(2,end="") indx+=1 indx+=1 ```
3.977
784
F
Crunching Numbers Just for You
PROGRAMMING
1,900
[ "*special", "implementation" ]
null
null
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order.
The input consists of a single line of space-separated integers. The first number is *n* (1<=≤<=*n*<=≤<=10) — the size of the array. The following *n* numbers are the elements of the array (1<=≤<=*a**i*<=≤<=100).
Output space-separated elements of the sorted array.
[ "3 3 1 2\n" ]
[ "1 2 3 \n" ]
Remember, this is a very important feature, and you have to make sure the customers appreciate it!
0
[ { "input": "3 3 1 2", "output": "1 2 3 " }, { "input": "10 54 100 27 1 33 27 80 49 27 6", "output": "1 6 27 27 27 33 49 54 80 100 " } ]
1,516,676,702
2,147,483,647
Python 3
REJECTED
TESTS
0
0
0
print(*sorted(map(int,input().split()[1:])))
Title: Crunching Numbers Just for You Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done....
```python print(*sorted(map(int,input().split()[1:]))) ```
-1
996
A
Hit the Lottery
PROGRAMMING
800
[ "dp", "greedy" ]
null
null
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
Output the minimum number of bills that Allen could receive.
[ "125\n", "43\n", "1000000000\n" ]
[ "3\n", "5\n", "10000000\n" ]
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills. In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills. In the third sample case, Allen...
500
[ { "input": "125", "output": "3" }, { "input": "43", "output": "5" }, { "input": "1000000000", "output": "10000000" }, { "input": "4", "output": "4" }, { "input": "5", "output": "1" }, { "input": "1", "output": "1" }, { "input": "74", "o...
1,689,881,014
2,147,483,647
Python 3
OK
TESTS
49
46
0
t=int(input()) x=[100,20,10,5,1] count=0 for i in x: count+=t//i t%=i print(count)
Title: Hit the Lottery Time Limit: None seconds Memory Limit: None megabytes Problem Description: Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$...
```python t=int(input()) x=[100,20,10,5,1] count=0 for i in x: count+=t//i t%=i print(count) ```
3
834
B
The Festive Evening
PROGRAMMING
1,100
[ "data structures", "implementation" ]
null
null
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom...
Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26). In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest.
Output «YES» if at least one door was unguarded during some time, and «NO» otherwise. You can output each letter in arbitrary case (upper or lower).
[ "5 1\nAABBB\n", "5 1\nABABB\n" ]
[ "NO\n", "YES\n" ]
In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the secon...
1,000
[ { "input": "5 1\nAABBB", "output": "NO" }, { "input": "5 1\nABABB", "output": "YES" }, { "input": "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "NO" }, { "input": "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA", "output": "YES" }, { "input": "5 2\nABACA", "output": "NO" ...
1,502,940,898
2,147,483,647
Python 3
OK
TESTS
34
811
3,276,800
n, k = map(int, input().split()) s = input() d = {} op = set() for i in range(len(s)): d[s[i]] = i ans = 0 doors = 0 for i in range(len(s)): if s[i] not in op: doors += 1 op.add(s[i]) ans = max(ans, doors) if i == d[s[i]]: doors -= 1 print(('YES','NO')[ans <= k])
Title: The Festive Evening Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here...
```python n, k = map(int, input().split()) s = input() d = {} op = set() for i in range(len(s)): d[s[i]] = i ans = 0 doors = 0 for i in range(len(s)): if s[i] not in op: doors += 1 op.add(s[i]) ans = max(ans, doors) if i == d[s[i]]: doors -= 1 print(('YES','NO')[an...
3
366
A
Dima and Guards
PROGRAMMING
1,100
[ "implementation" ]
null
null
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards... There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can b...
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers *a*,<=*b*,<=*c*,<=*d* (1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=105) — the minimum price of the chocolate and the minimum price of the juice for...
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line. The guardposts are numbered from 1 to 4 according to t...
[ "10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9\n", "10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8\n", "5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3\n" ]
[ "1 5 5\n", "3 4 6\n", "-1\n" ]
Explanation of the first example. The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost. Explanation of the second example. Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fo...
500
[ { "input": "10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9", "output": "1 5 5" }, { "input": "10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8", "output": "3 4 6" }, { "input": "5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3", "output": "-1" }, { "input": "100000\n100000 100000 100000 100000\n100000 10...
1,683,605,602
2,147,483,647
Python 3
OK
TESTS
29
46
102,400
n = int(input()) a = list(map(int, input().split(' '))) b = list(map(int, input().split(' '))) c = list(map(int, input().split(' '))) d = list(map(int, input().split(' '))) cost = [] cost.append(min(a[0],a[1])+min(a[2],a[3])) cost.append(min(b[0],b[1])+min(b[2],b[3])) cost.append(min(c[0],c[1])+min(c[2],c[3])) cost.app...
Title: Dima and Guards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards... There are four guardpost...
```python n = int(input()) a = list(map(int, input().split(' '))) b = list(map(int, input().split(' '))) c = list(map(int, input().split(' '))) d = list(map(int, input().split(' '))) cost = [] cost.append(min(a[0],a[1])+min(a[2],a[3])) cost.append(min(b[0],b[1])+min(b[2],b[3])) cost.append(min(c[0],c[1])+min(c[2],c[3])...
3
224
A
Parallelepiped
PROGRAMMING
1,100
[ "brute force", "geometry", "math" ]
null
null
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number — the sum of all edges of the parallelepiped.
[ "1 1 1\n", "4 6 6\n" ]
[ "12\n", "28\n" ]
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
500
[ { "input": "1 1 1", "output": "12" }, { "input": "4 6 6", "output": "28" }, { "input": "20 10 50", "output": "68" }, { "input": "9 4 36", "output": "56" }, { "input": "324 9 36", "output": "184" }, { "input": "1333 93 129", "output": "308" }, {...
1,634,545,584
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> #define ll long long int #define MAX(a,b) (a>b?a:b) #define MIN(a,b) (a>b?b:a) #define IOS ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define loop1(start,end,step) for(ll i=start;i<end;i+=step) #define loop2(start,end,step) for(ll j=start;j<end;j+=step) #define ISEV...
Title: Parallelepiped Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input S...
```python #include <bits/stdc++.h> #define ll long long int #define MAX(a,b) (a>b?a:b) #define MIN(a,b) (a>b?b:a) #define IOS ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define loop1(start,end,step) for(ll i=start;i<end;i+=step) #define loop2(start,end,step) for(ll j=start;j<end;j+=step) #d...
-1
124
A
The number of positions
PROGRAMMING
1,000
[ "math" ]
null
null
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100).
Print the single number — the number of the sought positions.
[ "3 1 1\n", "5 2 3\n" ]
[ "2\n", "3\n" ]
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
500
[ { "input": "3 1 1", "output": "2" }, { "input": "5 2 3", "output": "3" }, { "input": "5 4 0", "output": "1" }, { "input": "6 5 5", "output": "1" }, { "input": "9 4 3", "output": "4" }, { "input": "11 4 6", "output": "7" }, { "input": "13 8 ...
1,683,715,678
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
b = list(map(int, input().split())) print(b[0]-b[1])
Title: The number of positions Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind h...
```python b = list(map(int, input().split())) print(b[0]-b[1]) ```
0
78
A
Haiku
PROGRAMMING
800
[ "implementation", "strings" ]
A. Haiku
2
256
Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll...
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailin...
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
[ "on codeforces \nbeta round is running\n a rustling of keys \n", "how many gallons\nof edo s rain did you drink\n cuckoo\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "on codeforces \nbeta round is running\n a rustling of keys ", "output": "YES" }, { "input": "how many gallons\nof edo s rain did you drink\n cuckoo", "output": "NO" }, { "input": " hatsu shigure\n saru mo komino wo\nhoshige nari", ...
1,632,419,508
2,147,483,647
PyPy 3
OK
TESTS
40
218
20,172,800
a = input() damn = 0 damn += a.count('a') damn += a.count('e') damn += a.count('i') damn += a.count('o') damn += a.count('u') if damn != 5: print('NO') exit() damn = 0 b = input() damn += b.count('a') damn += b.count('e') damn += b.count('i') damn += b.count('o') damn += b.count('u') if damn !=...
Title: Haiku Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase...
```python a = input() damn = 0 damn += a.count('a') damn += a.count('e') damn += a.count('i') damn += a.count('o') damn += a.count('u') if damn != 5: print('NO') exit() damn = 0 b = input() damn += b.count('a') damn += b.count('e') damn += b.count('i') damn += b.count('o') damn += b.count('u') ...
3.907925
10
A
Power Consumption Calculation
PROGRAMMING
900
[ "implementation" ]
A. Power Consumption Calculation
1
256
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T...
The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;...
Output the answer to the problem.
[ "1 3 2 1 5 10\n0 10\n", "2 8 4 2 5 10\n20 30\n50 100\n" ]
[ "30", "570" ]
none
0
[ { "input": "1 3 2 1 5 10\n0 10", "output": "30" }, { "input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570" }, { "input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436", "output": "8445" }, { "input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945", "output": "5287...
1,496,763,811
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
0
k=0 f=[] n,a,b,c,d,e = map(int,input().split()) for i in range(0,n): x,y = map(int,input().split()) k=k+(a*(y-x)) f.append(y) if (x-f[i-1])<=d and (x-f[i-1])>=1: k=k+(a*(x-f[i-1])) if (x-f[i-1])>d and (x-f[i-1])<=(d+e): k=k+(d*a)+(b*((x-f[i-1])-d)) if (x-f[i-1])>(d+e):...
Title: Power Consumption Calculation Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard f...
```python k=0 f=[] n,a,b,c,d,e = map(int,input().split()) for i in range(0,n): x,y = map(int,input().split()) k=k+(a*(y-x)) f.append(y) if (x-f[i-1])<=d and (x-f[i-1])>=1: k=k+(a*(x-f[i-1])) if (x-f[i-1])>d and (x-f[i-1])<=(d+e): k=k+(d*a)+(b*((x-f[i-1])-d)) if (x-f[i-...
0
81
A
Plug-in
PROGRAMMING
1,400
[ "implementation" ]
A. Plug-in
1
256
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yy...
The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters.
Print the given string after it is processed. It is guaranteed that the result will contain at least one character.
[ "hhoowaaaareyyoouu\n", "reallazy\n", "abacabaabacabaa\n" ]
[ "wre", "rezy", "a" ]
none
500
[ { "input": "hhoowaaaareyyoouu", "output": "wre" }, { "input": "reallazy", "output": "rezy" }, { "input": "abacabaabacabaa", "output": "a" }, { "input": "xraccabccbry", "output": "xy" }, { "input": "a", "output": "a" }, { "input": "b", "output": "b"...
1,668,555,960
2,147,483,647
Python 3
OK
TESTS
32
280
2,457,600
n = input() st = [] for i in range(len(n)): st.append(n[i]) while len(st) > 1 and st[-1] == st[-2]: st.pop() st.pop() print(''.join(st))
Title: Plug-in Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed...
```python n = input() st = [] for i in range(len(n)): st.append(n[i]) while len(st) > 1 and st[-1] == st[-2]: st.pop() st.pop() print(''.join(st)) ```
3.855422
131
A
cAPS lOCK
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentall...
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Print the result of the given word's processing.
[ "cAPS\n", "Lock\n" ]
[ "Caps", "Lock\n" ]
none
500
[ { "input": "cAPS", "output": "Caps" }, { "input": "Lock", "output": "Lock" }, { "input": "cAPSlOCK", "output": "cAPSlOCK" }, { "input": "CAPs", "output": "CAPs" }, { "input": "LoCK", "output": "LoCK" }, { "input": "OOPS", "output": "oops" }, { ...
1,696,342,583
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
77
0
s=input() f="" f+=s[0].upper() n=len(s) for i in range(1,n): if s[i].isupper()==True: f+=s[i].lower() else: print(s) exit(0) print(f)
Title: cAPS lOCK Time Limit: None seconds Memory Limit: None megabytes Problem Description: wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th...
```python s=input() f="" f+=s[0].upper() n=len(s) for i in range(1,n): if s[i].isupper()==True: f+=s[i].lower() else: print(s) exit(0) print(f) ```
0
917
A
The Monster
PROGRAMMING
1,800
[ "dp", "greedy", "implementation", "math" ]
null
null
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him. Thus, he came up with a puzzle to te...
The first and only line of input contains string *s*, consisting only of characters '(', ')' and '?' (2<=≤<=|*s*|<=≤<=5000).
Print the answer to Will's puzzle in the first and only line of output.
[ "((?))\n", "??()??\n" ]
[ "4\n", "7\n" ]
For the first sample testcase, the pretty substrings of *s* are: 1. "(?" which can be transformed to "()". 1. "?)" which can be transformed to "()". 1. "((?)" which can be transformed to "(())". 1. "(?))" which can be transformed to "(())". For the second sample testcase, the pretty substrings of *s* are: 1. "?...
500
[ { "input": "((?))", "output": "4" }, { "input": "??()??", "output": "7" }, { "input": "?????)(???", "output": "21" }, { "input": "()()((?(()(((()()(())(((()((())))(()))(()(((((())))()))(((()()()))))))(((((()))))))))", "output": "62" }, { "input": "))((()(()((((())...
1,595,861,521
2,147,483,647
PyPy 3
OK
TESTS
57
249
22,630,400
st=input() le=len(st) ans=0 for i in range(le): l=0 w=0 for j in range(i,le): if(st[j]=="("): l+=1 elif(st[j]==")"): l-=1 else: w+=1 if(l+w<0): break elif(w>l): xx=l l=w ...
Title: The Monster Time Limit: None seconds Memory Limit: None megabytes Problem Description: As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster th...
```python st=input() le=len(st) ans=0 for i in range(le): l=0 w=0 for j in range(i,le): if(st[j]=="("): l+=1 elif(st[j]==")"): l-=1 else: w+=1 if(l+w<0): break elif(w>l): xx=l l=w...
3
803
E
Roma and Poker
PROGRAMMING
2,000
[ "dp", "graphs" ]
null
null
Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser. Last evening Roma started to play poker. He decided to spend no more than *k* virtual bou...
The first line contains two numbers *n* (the length of Roma's sequence) and *k* (1<=≤<=*n*,<=*k*<=≤<=1000). The second line contains the sequence *s* consisting of characters W, L, D and ?. There are exactly *n* characters in this sequence.
If there is no valid sequence that can be obtained from *s* by replacing all ? characters by W, L or D, print NO. Otherwise print this sequence. If there are multiple answers, print any of them.
[ "3 2\nL??\n", "3 1\nW??\n", "20 5\n?LLLLLWWWWW?????????\n" ]
[ "LDL\n", "NO\n", "WLLLLLWWWWWWWWLWLWDW\n" ]
none
0
[ { "input": "3 2\nL??", "output": "LDL" }, { "input": "3 1\nW??", "output": "NO" }, { "input": "20 5\n?LLLLLWWWWW?????????", "output": "WLLLLLWWWWWWWWLWLWDW" }, { "input": "5 5\n?WDDD", "output": "NO" }, { "input": "5 3\n??D??", "output": "WWDDW" }, { "...
1,493,399,403
7,503
Python 3
WRONG_ANSWER
TESTS
0
31
4,915,200
n, k = map(int, input().split()) s=input() won=0 lost=0 drawn=0 un=0 for i in range(n): if s[i]=='W': won+=1 elif s[i]=='L': lost+=1 elif s[i]=='D': drawn+=1 else: un+=1 if won>=lost+k: print('NO') else: if won+un>=k and (won!=k or s[-1]=='?'): s=list(s)...
Title: Roma and Poker Time Limit: None seconds Memory Limit: None megabytes Problem Description: Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from t...
```python n, k = map(int, input().split()) s=input() won=0 lost=0 drawn=0 un=0 for i in range(n): if s[i]=='W': won+=1 elif s[i]=='L': lost+=1 elif s[i]=='D': drawn+=1 else: un+=1 if won>=lost+k: print('NO') else: if won+un>=k and (won!=k or s[-1]=='?'): ...
0
749
A
Bachgold Problem
PROGRAMMING
800
[ "greedy", "implementation", "math", "number theory" ]
null
null
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ...
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
The first line of the output contains a single integer *k* — maximum possible number of primes in representation. The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
[ "5\n", "6\n" ]
[ "2\n2 3\n", "3\n2 2 2\n" ]
none
500
[ { "input": "5", "output": "2\n2 3" }, { "input": "6", "output": "3\n2 2 2" }, { "input": "2", "output": "1\n2" }, { "input": "3", "output": "1\n3" }, { "input": "99999", "output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
1,687,491,269
2,147,483,647
Python 3
OK
TESTS
41
78
1,024,000
def main(): a = int(input()) b = [2] * (a // 2) print(a // 2) if a % 2 != 0: b[-1] = 3 print(*b) main()
Title: Bachgold Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. ...
```python def main(): a = int(input()) b = [2] * (a // 2) print(a // 2) if a % 2 != 0: b[-1] = 3 print(*b) main() ```
3
573
A
Bear and Poker
PROGRAMMING
1,300
[ "implementation", "math", "number theory" ]
null
null
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars. Each player can double his bid any number of times and triple his bid any nu...
First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players. The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players.
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
[ "4\n75 150 75 50\n", "3\n100 150 250\n" ]
[ "Yes\n", "No\n" ]
In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal.
500
[ { "input": "4\n75 150 75 50", "output": "Yes" }, { "input": "3\n100 150 250", "output": "No" }, { "input": "7\n34 34 68 34 34 68 34", "output": "Yes" }, { "input": "10\n72 96 12 18 81 20 6 2 54 1", "output": "No" }, { "input": "20\n958692492 954966768 77387000 724...
1,589,301,169
2,147,483,647
Python 3
OK
TESTS
70
779
15,872,000
n = int(input()) m=list(map(int,input().split())) for i in range(n): while(m[i]%2==0): m[i]//=2 while(m[i]%3==0): m[i]//=3 if(len(set(m))==1): print('Yes') else: print('No')
Title: Bear and Poker Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid wit...
```python n = int(input()) m=list(map(int,input().split())) for i in range(n): while(m[i]%2==0): m[i]//=2 while(m[i]%3==0): m[i]//=3 if(len(set(m))==1): print('Yes') else: print('No') ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,676,207,480
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
60
0
s_1=input() l=0 u=0 for i in s_1: if(i.islower()): l=l+1 else: u=u+1 if(l>u): print(s_1.lower()) else: print(s_1.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python s_1=input() l=0 u=0 for i in s_1: if(i.islower()): l=l+1 else: u=u+1 if(l>u): print(s_1.lower()) else: print(s_1.upper()) ```
0
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,595,608,290
2,147,483,647
Python 3
OK
TESTS
40
93
6,963,200
s=input() k=0 for i in range(len(s)): if s[i]=='h' and k==0: k+=1 elif s[i]=='e' and k==1: k+=1 elif s[i]=='l' and k==2: k+=1 elif s[i]=='l' and k==3: k+=1 elif s[i]=='o' and k==4: k+=1 if k==5: print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python s=input() k=0 for i in range(len(s)): if s[i]=='h' and k==0: k+=1 elif s[i]=='e' and k==1: k+=1 elif s[i]=='l' and k==2: k+=1 elif s[i]=='l' and k==3: k+=1 elif s[i]=='o' and k==4: k+=1 if k==5: print("YES") else: print("NO") ```
3.94053
998
B
Cutting
PROGRAMMING
1,200
[ "dp", "greedy", "sortings" ]
null
null
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulti...
First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have. Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal...
Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins.
[ "6 4\n1 2 5 10 15 20\n", "4 10\n1 3 2 4\n", "6 100\n1 2 3 4 5 6\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins. In the second sample it is not possible to make even one cut even with unlimited number of bitcoins. In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$....
1,000
[ { "input": "6 4\n1 2 5 10 15 20", "output": "1" }, { "input": "4 10\n1 3 2 4", "output": "0" }, { "input": "6 100\n1 2 3 4 5 6", "output": "2" }, { "input": "2 100\n13 78", "output": "0" }, { "input": "10 1\n56 56 98 2 11 64 97 41 95 53", "output": "0" }, ...
1,602,175,544
2,147,483,647
Python 3
OK
TESTS
34
93
307,200
n,b=map(int,input().split()) a=list(map(int,input().split())) q,w,l,m=0,0,[],0 for i in range(n-1): if a[i]&1:q+=1 else:w+=1 if q==w:l.append(abs(a[i]-a[i+1])) l.sort() for i in l: if i<=b:m+=1;b-=i else:break print(m)
Title: Cutting Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Gi...
```python n,b=map(int,input().split()) a=list(map(int,input().split())) q,w,l,m=0,0,[],0 for i in range(n-1): if a[i]&1:q+=1 else:w+=1 if q==w:l.append(abs(a[i]-a[i+1])) l.sort() for i in l: if i<=b:m+=1;b-=i else:break print(m) ```
3
868
B
Race Against Time
PROGRAMMING
1,400
[ "implementation" ]
null
null
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other. The entire universe turned into an enormous clock face with ...
Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2). Misha's position and the target time do not coincide with the position of any hand.
Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "12 30 45 3 11\n", "12 0 1 12 1\n", "3 47 0 4 9\n" ]
[ "NO\n", "YES\n", "YES\n" ]
The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same.
500
[ { "input": "12 30 45 3 11", "output": "NO" }, { "input": "12 0 1 12 1", "output": "YES" }, { "input": "3 47 0 4 9", "output": "YES" }, { "input": "10 22 59 6 10", "output": "YES" }, { "input": "3 1 13 12 3", "output": "NO" }, { "input": "11 19 28 9 10"...
1,507,191,468
4,368
Python 3
WRONG_ANSWER
PRETESTS
4
46
0
s1,s2,s3,be,end=map(int,input().split()) s=[s1*5,s2,s3] be*=5 end*=5 end,be=max(be,end),min(be,end) b1=True b2=True for i in s: if end>i>be: b1=False else: b2=False if b1 or b2: print('YES') else: print('NO')
Title: Race Against Time Time Limit: None seconds Memory Limit: None megabytes Problem Description: Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time par...
```python s1,s2,s3,be,end=map(int,input().split()) s=[s1*5,s2,s3] be*=5 end*=5 end,be=max(be,end),min(be,end) b1=True b2=True for i in s: if end>i>be: b1=False else: b2=False if b1 or b2: print('YES') else: print('NO') ```
0