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
624
B
Making a String
PROGRAMMING
1,100
[ "greedy", "sortings" ]
null
null
You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: - the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the ...
The first line of the input contains a single integer *n* (2<=<=≤<=<=*n*<=<=≤<=<=26) — the number of letters in the alphabet. The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string.
Print a single integer — the maximum length of the string that meets all the requirements.
[ "3\n2 5 5\n", "3\n1 1 2\n" ]
[ "11\n", "3\n" ]
For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc".
1,000
[ { "input": "3\n2 5 5", "output": "11" }, { "input": "3\n1 1 2", "output": "3" }, { "input": "2\n1 1", "output": "1" }, { "input": "3\n1 1000000000 2", "output": "1000000003" }, { "input": "26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10000...
1,454,606,388
888
Python 3
CHALLENGED
CHALLENGES
8
61
0
n=int(input()) a=[int(i) for i in input().split()] a=sorted(a)[::-1] t=a[0]+1 s=0 for i in a: if t>i: s+=i t=i else: t-=1 s+=t print(s)
Title: Making a String Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: - the *i*-th letter occurs in the string no more than ...
```python n=int(input()) a=[int(i) for i in input().split()] a=sorted(a)[::-1] t=a[0]+1 s=0 for i in a: if t>i: s+=i t=i else: t-=1 s+=t print(s) ```
-1
873
B
Balanced Substring
PROGRAMMING
1,500
[ "dp", "implementation" ]
null
null
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to deter...
The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*. The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*.
If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring.
[ "8\n11010111\n", "3\n111\n" ]
[ "4\n", "0\n" ]
In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible. In the second example it's impossible to find a non-empty balanced substring.
0
[ { "input": "8\n11010111", "output": "4" }, { "input": "3\n111", "output": "0" }, { "input": "11\n00001000100", "output": "2" }, { "input": "10\n0100000000", "output": "2" }, { "input": "13\n0001000011010", "output": "6" }, { "input": "14\n0000010010101...
1,669,713,515
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
62
0
import sys from math import * from collections import Counter,defaultdict,deque input=sys.stdin.readline mod=10**9+7 ma=defaultdict(lambda:-inf) mi=defaultdict(lambda:inf) x,y=0,0 n=int(input()) a=input() for i in range(n): ma[x-y]=max(ma[x-y],i) mi[x-y]=min(mi[x-y],i) if a[i]=='0': x+...
Title: Balanced Substring Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called...
```python import sys from math import * from collections import Counter,defaultdict,deque input=sys.stdin.readline mod=10**9+7 ma=defaultdict(lambda:-inf) mi=defaultdict(lambda:inf) x,y=0,0 n=int(input()) a=input() for i in range(n): ma[x-y]=max(ma[x-y],i) mi[x-y]=min(mi[x-y],i) if a[i]=='0': ...
0
371
D
Vessels
PROGRAMMING
1,800
[ "data structures", "dsu", "implementation", "trees" ]
null
null
There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a**i* liters. Initially, all the vessels are empty. In some vessels water is poured. All the w...
The first line contains integer *n* — the number of vessels (1<=≤<=*n*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the vessels' capacities (1<=≤<=*a**i*<=≤<=109). The vessels' capacities do not necessarily increase from the top vessels to the bottom ones (see the second sample). The t...
For each query, print on a single line the number of liters of water in the corresponding vessel.
[ "2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2\n", "3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3\n" ]
[ "4\n5\n8\n", "7\n10\n5\n" ]
none
2,000
[ { "input": "2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2", "output": "4\n5\n8" }, { "input": "3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3", "output": "7\n10\n5" }, { "input": "10\n71 59 88 55 18 98 38 73 53 58\n20\n1 5 93\n1 7 69\n2 3\n1 1 20\n2 10\n1 6 74\n1 7 100\n1 9 14\n2 3\n...
1,690,531,754
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
39
2,000
28,057,600
class UnionSet: def __init__(self,n): self.val=list(range(n+1)) def find(self,x): tmp=x while x!=self.val[x]: x=self.val[x] self.val[x]=self.val[self.val[x]] x=self.val[x] return self.val[x] def merge(self,x,y): x...
Title: Vessels Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a*...
```python class UnionSet: def __init__(self,n): self.val=list(range(n+1)) def find(self,x): tmp=x while x!=self.val[x]: x=self.val[x] self.val[x]=self.val[self.val[x]] x=self.val[x] return self.val[x] def merge(self,x,y): ...
0
870
C
Maximum splitting
PROGRAMMING
1,300
[ "dp", "greedy", "math", "number theory" ]
null
null
You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prim...
The first line contains single integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries. *q* lines follow. The (*i*<=+<=1)-th line contains single integer *n**i* (1<=≤<=*n**i*<=≤<=109) — the *i*-th query.
For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.
[ "1\n12\n", "2\n6\n8\n", "3\n1\n2\n3\n" ]
[ "3\n", "1\n2\n", "-1\n-1\n-1\n" ]
12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
1,500
[ { "input": "1\n12", "output": "3" }, { "input": "2\n6\n8", "output": "1\n2" }, { "input": "3\n1\n2\n3", "output": "-1\n-1\n-1" }, { "input": "6\n1\n2\n3\n5\n7\n11", "output": "-1\n-1\n-1\n-1\n-1\n-1" }, { "input": "3\n4\n6\n9", "output": "1\n1\n1" }, { ...
1,541,933,648
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
108
0
H = [0, 0, 0, 0, 1, 0, 1, 0, 2, 1, 2, 0, 3, 0, 3, 2] q = int(input()) for i in range(q): n = int(input()) if n <= 15: if H[n] == 0: print(-1) else: print(H[n]) else: c_4 = 0 while n > 15: n -= 4 c_4 += 1 wh...
Title: Maximum splitting Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, o...
```python H = [0, 0, 0, 0, 1, 0, 1, 0, 2, 1, 2, 0, 3, 0, 3, 2] q = int(input()) for i in range(q): n = int(input()) if n <= 15: if H[n] == 0: print(-1) else: print(H[n]) else: c_4 = 0 while n > 15: n -= 4 c_4 += 1 ...
0
909
C
Python Indentation
PROGRAMMING
1,800
[ "dp" ]
null
null
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python with only two types of statements. Simple statements are written in a single line, one per line. An ex...
The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.
Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7.
[ "4\ns\nf\nf\ns\n", "4\nf\ns\nf\ns\n" ]
[ "1\n", "2\n" ]
In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one. In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one...
1,500
[ { "input": "4\ns\nf\nf\ns", "output": "1" }, { "input": "4\nf\ns\nf\ns", "output": "2" }, { "input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns...
1,634,044,345
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
141,107,200
n=int(input()) f=0 mod=10**9+7 s=[] dp=[[0]*5010 for p in range(5010)] for p in range(n): s.append(input()) if s[-1][0] == 'f': f += 1 sum=[0]*5010 dp[0][0]=1 for i in range(1, n): #print(s[i-1]) if s[i-1][0] == "f": #print('xsxs') for j in range(1, f+1): ...
Title: Python Indentation Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python...
```python n=int(input()) f=0 mod=10**9+7 s=[] dp=[[0]*5010 for p in range(5010)] for p in range(n): s.append(input()) if s[-1][0] == 'f': f += 1 sum=[0]*5010 dp[0][0]=1 for i in range(1, n): #print(s[i-1]) if s[i-1][0] == "f": #print('xsxs') for j in range(1, f+1):...
0
356
D
Bags and Coins
PROGRAMMING
2,700
[ "bitmasks", "constructive algorithms", "dp", "greedy" ]
null
null
When you were a child you must have been told a puzzle of bags and coins. Anyway, here's one of its versions: A horse has three bags. The first bag has one coin, the second bag has one coin and the third bag has three coins. In total, the horse has three coins in the bags. How is that possible? The answer is quite ...
The first line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=70000) — the number of bags and the total number of coins. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=70000), where *a**i* shows the number of coins in the *i*-th bag.
If the answer doesn't exist, print -1. Otherwise, print *n* lines, on the *i*-th line print the contents of the *i*-th bag. The first number in the line, *c**i* (0<=≤<=*c**i*<=≤<=*a**i*), must represent the number of coins lying directly in the *i*-th bag (the coins in the bags that are in the *i*-th bag are not take...
[ "3 3\n1 3 1\n", "3 3\n1 3 1\n", "1 2\n1\n", "8 10\n2 7 3 4 1 3 1 2\n" ]
[ "1 0\n1 2 3 1\n1 0\n", "1 0\n2 1 3\n0 1 1\n", "-1\n", "2 0\n1 2 1 4\n0 2 7 8\n0 2 5 6\n1 0\n3 0\n1 0\n2 0\n" ]
The pictures below show two possible ways to solve one test case from the statement. The left picture corresponds to the first test case, the right picture corresponds to the second one.
2,000
[]
1,689,604,106
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1689604106.734583")# 1689604106.7346056
Title: Bags and Coins Time Limit: None seconds Memory Limit: None megabytes Problem Description: When you were a child you must have been told a puzzle of bags and coins. Anyway, here's one of its versions: A horse has three bags. The first bag has one coin, the second bag has one coin and the third bag has three ...
```python print("_RANDOM_GUESS_1689604106.734583")# 1689604106.7346056 ```
0
13
A
Numbers
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Numbers
1
64
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1. Note that all c...
Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000).
Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator.
[ "5\n", "3\n" ]
[ "7/3\n", "2/1\n" ]
In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.
0
[ { "input": "5", "output": "7/3" }, { "input": "3", "output": "2/1" }, { "input": "1000", "output": "90132/499" }, { "input": "927", "output": "155449/925" }, { "input": "260", "output": "6265/129" }, { "input": "131", "output": "3370/129" }, { ...
1,670,690,581
2,147,483,647
Python 3
OK
TESTS
99
92
0
import math a = int(input()) s = 0 for i in range(2, a): tmpA = a while tmpA != 0: s = s + (tmpA % i) tmpA = (tmpA // i) d = math.gcd(s, a-2) print(f"{s//d}/{(a-2)//d}")
Title: Numbers Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of su...
```python import math a = int(input()) s = 0 for i in range(2, a): tmpA = a while tmpA != 0: s = s + (tmpA % i) tmpA = (tmpA // i) d = math.gcd(s, a-2) print(f"{s//d}/{(a-2)//d}") ```
3.954
830
A
Office Keys
PROGRAMMING
1,800
[ "binary search", "brute force", "dp", "greedy", "sortings" ]
null
null
There are *n* people and *k* keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else. You are to determine th...
The first line contains three integers *n*, *k* and *p* (1<=≤<=*n*<=≤<=1<=000, *n*<=≤<=*k*<=≤<=2<=000, 1<=≤<=*p*<=≤<=109) — the number of people, the number of keys and the office location. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — positions in which people are ...
Print the minimum time (in seconds) needed for all *n* to reach the office with keys.
[ "2 4 50\n20 100\n60 10 40 80\n", "1 2 10\n11\n15 7\n" ]
[ "50\n", "7\n" ]
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is...
500
[ { "input": "2 4 50\n20 100\n60 10 40 80", "output": "50" }, { "input": "1 2 10\n11\n15 7", "output": "7" }, { "input": "2 5 15\n10 4\n29 23 21 22 26", "output": "23" }, { "input": "3 10 1500\n106 160 129\n1333 1532 1181 1091 1656 1698 1291 1741 1242 1163", "output": "1394...
1,500,363,395
2,147,483,647
Python 3
OK
TESTS
59
607
5,222,400
n, k, p = (int(x) for x in input().split()) a = sorted([int(x) for x in input().split()]) b = sorted([int(x) for x in input().split()]) time = min([max([abs(a[j] - b[i + j]) + abs(b[i + j] - p) for j in range(n)]) for i in range(k-n+1)]) print(time)
Title: Office Keys Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* people and *k* keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office...
```python n, k, p = (int(x) for x in input().split()) a = sorted([int(x) for x in input().split()]) b = sorted([int(x) for x in input().split()]) time = min([max([abs(a[j] - b[i + j]) + abs(b[i + j] - p) for j in range(n)]) for i in range(k-n+1)]) print(time) ```
3
645
E
Intellectual Inquiry
PROGRAMMING
2,200
[ "dp", "greedy", "strings" ]
null
null
After getting kicked out of her reporting job for not knowing the alphabet, Bessie has decided to attend school at the Fillet and Eggs Eater Academy. She has been making good progress with her studies and now knows the first *k* English letters. Each morning, Bessie travels to school along a sidewalk consisting of *m*...
The first line of the input contains two integers *n* and *k* (0<=≤<=*n*<=≤<=1<=000<=000, 1<=≤<=*k*<=≤<=26). The second line contains a string *t* (|*t*|<==<=*m*,<=1<=≤<=*m*<=≤<=1<=000<=000) consisting of only first *k* lowercase English letters.
Determine the maximum number of distinct subsequences Bessie can form after labeling the last *n* sidewalk tiles each with one of the first *k* lowercase English letters. Since this number can be rather large, you should print it modulo 109<=+<=7. Please note, that you are not asked to maximize the remainder modulo 10...
[ "1 3\nac\n", "0 2\naaba\n" ]
[ "8\n", "10\n" ]
In the first sample, the optimal labeling gives 8 different subsequences: "" (the empty string), "a", "c", "b", "ac", "ab", "cb", and "acb". In the second sample, the entire sidewalk is already labeled. The are 10 possible different subsequences: "" (the empty string), "a", "b", "aa", "ab", "ba", "aaa", "aab", "aba", ...
2,500
[]
1,460,534,622
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
9
2,000
3,072,000
import operator s = list(map(int,input().split())) n = s[0] k = s[1] s = input() base = 10 ** 9 + 7 start = ord('a') substrings = [0 for i in range(k + 1)] positions = [[i, 0] for i in range(k)] heap = [[i, 0] for i in range(k)] substrings[k] = 1 counter = 0 def Insert(heap, size, number, comparator = o...
Title: Intellectual Inquiry Time Limit: None seconds Memory Limit: None megabytes Problem Description: After getting kicked out of her reporting job for not knowing the alphabet, Bessie has decided to attend school at the Fillet and Eggs Eater Academy. She has been making good progress with her studies and now knows...
```python import operator s = list(map(int,input().split())) n = s[0] k = s[1] s = input() base = 10 ** 9 + 7 start = ord('a') substrings = [0 for i in range(k + 1)] positions = [[i, 0] for i in range(k)] heap = [[i, 0] for i in range(k)] substrings[k] = 1 counter = 0 def Insert(heap, size, number, comp...
0
580
B
Kefa and Company
PROGRAMMING
1,500
[ "binary search", "sortings", "two pointers" ]
null
null
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has *n* friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend...
The first line of the input contains two space-separated integers, *n* and *d* (1<=≤<=*n*<=≤<=105, ) — the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively. Next *n* lines contain the descriptions of Kefa's friends, the (*i*<=+<=1)-th line contains the...
Print the maximum total friendship factir that can be reached.
[ "4 5\n75 5\n0 100\n150 20\n75 1\n", "5 100\n0 7\n11 32\n99 10\n46 8\n87 54\n" ]
[ "100\n", "111\n" ]
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse. In the second sample test we can take all the friends.
1,250
[ { "input": "4 5\n75 5\n0 100\n150 20\n75 1", "output": "100" }, { "input": "5 100\n0 7\n11 32\n99 10\n46 8\n87 54", "output": "111" }, { "input": "1 1000000000\n15 12", "output": "12" }, { "input": "5 1\n5 9\n2 10\n8 5\n18 12\n1 1", "output": "12" }, { "input": "3...
1,695,918,421
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
7
62
0
import sys # sys.setrecursionlimit(100000) input=lambda:sys.stdin.readline().strip() # write=lambda x:sys.stdout.write(str(x)+'\n') # from decimal import Decimal # from datetime import datetime,timedelta # from random import randint # from copy import deepcopy # from collections import deque,Counter # from h...
Title: Kefa and Company Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has *n* friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the a...
```python import sys # sys.setrecursionlimit(100000) input=lambda:sys.stdin.readline().strip() # write=lambda x:sys.stdout.write(str(x)+'\n') # from decimal import Decimal # from datetime import datetime,timedelta # from random import randint # from copy import deepcopy # from collections import deque,Counter...
0
439
A
Devu, the Singer and Churu, the Joker
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s...
The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100).
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
[ "3 30\n2 2 1\n", "3 20\n2 1 1\n" ]
[ "5\n", "-1\n" ]
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch...
500
[ { "input": "3 30\n2 2 1", "output": "5" }, { "input": "3 20\n2 1 1", "output": "-1" }, { "input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1", "output": "1943" }, { "input": "50 10000\n4 7 15 9 11 12 ...
1,562,784,913
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> using namespace std; int main() { int n, minutes; cin >> n >> minutes; vector<int> songs(n); for(auto &i: songs) { cin >> i; } sort(songs.begin(), songs.end(), greater<int>()); int breaks =0; for (int i = 0; i < n-1; i++) { minutes-=(song...
Title: Devu, the Singer and Churu, the Joker Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit...
```python #include<bits/stdc++.h> using namespace std; int main() { int n, minutes; cin >> n >> minutes; vector<int> songs(n); for(auto &i: songs) { cin >> i; } sort(songs.begin(), songs.end(), greater<int>()); int breaks =0; for (int i = 0; i < n-1; i++) { minu...
-1
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t...
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", ...
1,676,553,168
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n,p=map(int,input().split()) s=0 t=0 for i in range(2,int(n/2)+1): if n%i==0: s=0 break else: s=1 for j in range(2,int(p/2)+1): if p%j==0: t=0 break else: t=1 if ((t==1) and (s==1)): print("YES") else: print("NO")
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater t...
```python n,p=map(int,input().split()) s=0 t=0 for i in range(2,int(n/2)+1): if n%i==0: s=0 break else: s=1 for j in range(2,int(p/2)+1): if p%j==0: t=0 break else: t=1 if ((t==1) and (s==1)): print("YES") else: print("NO") ```
0
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0...
1,695,922,418
2,147,483,647
Python 3
OK
TESTS
25
92
0
index = None l = [] for o in range(5): l.append(input().split()) for i, x in enumerate(l): for j, y in enumerate(x): if y == '1': print(abs(i - 2) + abs(j - 2))
Title: Beautiful Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri...
```python index = None l = [] for o in range(5): l.append(input().split()) for i, x in enumerate(l): for j, y in enumerate(x): if y == '1': print(abs(i - 2) + abs(j - 2)) ```
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,697,020,419
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
s = input() if s.rindex("o") > s.rindex("l") > s.rindex("e") > s.rindex("h") != -1 or -1 != s.index("h") < s.index("e") < s.index( "l") < s.index("o") and s.count("l") >= 2: print("YES") exit() 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() if s.rindex("o") > s.rindex("l") > s.rindex("e") > s.rindex("h") != -1 or -1 != s.index("h") < s.index("e") < s.index( "l") < s.index("o") and s.count("l") >= 2: print("YES") exit() print("NO") ```
0
798
A
Mike and palindrome
PROGRAMMING
1,000
[ "brute force", "constructive algorithms", "strings" ]
null
null
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo...
The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15).
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
[ "abccaa\n", "abbcca\n", "abcda\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "abccaa", "output": "YES" }, { "input": "abbcca", "output": "NO" }, { "input": "abcda", "output": "YES" }, { "input": "kyw", "output": "YES" }, { "input": "fccf", "output": "NO" }, { "input": "mnlm", "output": "YES" }, { "input":...
1,697,515,226
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
62
132,096,000
import bisect import sys from collections import Counter, OrderedDict, defaultdict from functools import lru_cache from itertools import permutations, combinations from heapq import heapify from math import sqrt, gcd sys.setrecursionlimit(10**5) def input(): return sys.stdin.readline().strip('\r\n') def pyin...
Title: Mike and palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same ...
```python import bisect import sys from collections import Counter, OrderedDict, defaultdict from functools import lru_cache from itertools import permutations, combinations from heapq import heapify from math import sqrt, gcd sys.setrecursionlimit(10**5) def input(): return sys.stdin.readline().strip('\r\n')...
0
5
C
Longest Regular Bracket Sequence
PROGRAMMING
1,900
[ "constructive algorithms", "data structures", "dp", "greedy", "sortings", "strings" ]
C. Longest Regular Bracket Sequence
2
256
This is yet another problem dealing with regular bracket sequences. We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not....
The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106.
Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1".
[ ")((())))(()())\n", "))(\n" ]
[ "6 2\n", "0 1\n" ]
none
0
[ { "input": ")((())))(()())", "output": "6 2" }, { "input": "))(", "output": "0 1" }, { "input": "()(())()", "output": "8 1" }, { "input": "((((()(((", "output": "2 1" }, { "input": "))))()())))", "output": "4 1" }, { "input": "(()())()(())()()())())()(...
1,649,337,834
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
154
0
import sys input:lambda:sys.readline() n=input() stack=[] judge=[False]*len(n) end=-1 for i in range(len(n)): if n[i]=='(': stack.append(i) end+=1 else: if end!=-1 and n[stack[end]]=='(': judge[stack[end]]=True judge[i]=True stack.pop...
Title: Longest Regular Bracket Sequence Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: This is yet another problem dealing with regular bracket sequences. We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical exp...
```python import sys input:lambda:sys.readline() n=input() stack=[] judge=[False]*len(n) end=-1 for i in range(len(n)): if n[i]=='(': stack.append(i) end+=1 else: if end!=-1 and n[stack[end]]=='(': judge[stack[end]]=True judge[i]=True ...
0
0
none
none
none
0
[ "none" ]
null
null
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string *s*. String *p* is called a substring of string *s* if you can read it starting from some position in the string *s*. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string *s* and c...
The first line contains a non-empty string *s*, consisting of lowercase Latin letters. The second line contains a non-empty string *u*, consisting of lowercase Latin letters. The lengths of both strings are in the range from 1 to 2000, inclusive.
Print the only integer — the minimum number of changes that Dr. Moriarty has to make with the string that you choose.
[ "aaaaa\naaa\n", "abcabc\nbcd\n", "abcdef\nklmnopq\n" ]
[ "0\n", "1\n", "7\n" ]
In the first sample Moriarty can take any substring of length 3, and it will be equal to the required message *u*, so Moriarty won't have to make any changes. In the second sample you should take a substring consisting of characters from second to fourth ("bca") or from fifth to sixth ("bc"). Then you will only have t...
0
[ { "input": "aaaaa\naaa", "output": "0" }, { "input": "abcabc\nbcd", "output": "1" }, { "input": "abcdef\nklmnopq", "output": "7" }, { "input": "aaabbbaaa\naba", "output": "1" }, { "input": "a\na", "output": "0" }, { "input": "z\nz", "output": "0" ...
1,499,437,057
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
4,608,000
s, u, ans = str(input()), str(input()), 999999 s = '#' * (len(u) - 1) + s + '#' * (len(u) - 1) for i in range(len(s) - len(u) + 1): ans = min(ans, sum([s[i + j] != u[j] for j in range(len(u))])) print(ans)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string *s*. String *p* is called a substring of string *s* if you can read it starting from some position in the string *s*. For example, string "aba" has six ...
```python s, u, ans = str(input()), str(input()), 999999 s = '#' * (len(u) - 1) + s + '#' * (len(u) - 1) for i in range(len(s) - len(u) + 1): ans = min(ans, sum([s[i + j] != u[j] for j in range(len(u))])) print(ans) ```
0
846
E
Chemistry in Berland
PROGRAMMING
2,300
[ "dfs and similar", "greedy", "trees" ]
null
null
Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment. Fortunately, chemical laws allow material transformations (yes, chemistry i...
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=105) — the number of materials discovered by Berland chemists. The second line contains *n* integer numbers *b*1,<=*b*2... *b**n* (1<=≤<=*b**i*<=≤<=1012) — supplies of BerSU laboratory. The third line contains *n* integer numbers *a*1,<=*a*2... *a**n* (1<=...
Print YES if it is possible to conduct an experiment. Otherwise print NO.
[ "3\n1 2 3\n3 2 1\n1 1\n1 1\n", "3\n3 2 1\n1 2 3\n1 1\n1 2\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "3\n1 2 3\n3 2 1\n1 1\n1 1", "output": "YES" }, { "input": "3\n3 2 1\n1 2 3\n1 1\n1 2", "output": "NO" }, { "input": "5\n2 1 1 2 3\n1 2 2 2 1\n1 2\n1 3\n2 4\n1 4", "output": "NO" }, { "input": "10\n2 8 6 1 2 7 6 9 2 8\n4 9 4 3 5 2 9 3 7 3\n1 8\n2 8\n3 8\n4 10\n5 1\...
1,638,036,873
2,147,483,647
PyPy 3-64
OK
TESTS
42
561
25,190,400
import sys input = sys.stdin.readline n = int(input()) b = [0] + list(map(int, input().split())) a = [0] + list(map(int, input().split())) G = [[] for _ in range(n + 1)] x0, k0 = [0] * (n + 1), [0] * (n + 1) for y in range(2, n + 1): x, k = map(int, input().split()) G[x].append((y, k)) x0[y] = x...
Title: Chemistry in Berland Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials ...
```python import sys input = sys.stdin.readline n = int(input()) b = [0] + list(map(int, input().split())) a = [0] + list(map(int, input().split())) G = [[] for _ in range(n + 1)] x0, k0 = [0] * (n + 1), [0] * (n + 1) for y in range(2, n + 1): x, k = map(int, input().split()) G[x].append((y, k)) ...
3
946
A
Partition
PROGRAMMING
800
[ "greedy" ]
null
null
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences. Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequenc...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*.
Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*.
[ "3\n1 -2 0\n", "6\n16 23 16 15 42 8\n" ]
[ "3\n", "120\n" ]
In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* =  - 2, *B* - *C* = 3. In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120.
0
[ { "input": "3\n1 -2 0", "output": "3" }, { "input": "6\n16 23 16 15 42 8", "output": "120" }, { "input": "1\n-1", "output": "1" }, { "input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -10...
1,590,714,047
2,147,483,647
PyPy 3
OK
TESTS
72
140
0
# import sys # sys.stdin = open('input.txt', 'r') n = int(input()) arr = list(map(int, input().split())) result = 0 for i in arr: if i>0: result+= i else: result -= i print(result)
Title: Partition Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences. Let *B* be the sum of eleme...
```python # import sys # sys.stdin = open('input.txt', 'r') n = int(input()) arr = list(map(int, input().split())) result = 0 for i in arr: if i>0: result+= i else: result -= i print(result) ```
3
0
none
none
none
0
[ "none" ]
null
null
The last stage of Football World Cup is played using the play-off system. There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the ...
The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in. It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal.
In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final. Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1.
[ "4 1 2\n", "8 2 6\n", "8 7 5\n" ]
[ "1\n", "Final!\n", "2\n" ]
In the first example teams 1 and 2 meet in the first round. In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds. In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the firs...
0
[ { "input": "4 1 2", "output": "1" }, { "input": "8 2 6", "output": "Final!" }, { "input": "8 7 5", "output": "2" }, { "input": "128 30 98", "output": "Final!" }, { "input": "256 128 256", "output": "Final!" }, { "input": "256 2 127", "output": "7" ...
1,520,153,218
418
Python 3
OK
TESTS
64
77
5,632,000
n, a, b = map(int, input().split()) a -= 1 b -= 1 a += n b += n res = 0 while a != b: # print(a, b) a //= 2 b //= 2 res += 1 if a == 1: print('Final!') else: print(res)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: The last stage of Football World Cup is played using the play-off system. There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the ord...
```python n, a, b = map(int, input().split()) a -= 1 b -= 1 a += n b += n res = 0 while a != b: # print(a, b) a //= 2 b //= 2 res += 1 if a == 1: print('Final!') else: print(res) ```
3
0
none
none
none
0
[ "none" ]
null
null
Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*. Greg wrote down *k* qu...
The first line contains integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the initial array. Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=...
On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
[ "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n", "1 1 1\n1\n1 1 1\n1 1\n", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n" ]
[ "9 18 17\n", "2\n", "5 18 31 20\n" ]
none
0
[ { "input": "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "output": "9 18 17" }, { "input": "1 1 1\n1\n1 1 1\n1 1", "output": "2" }, { "input": "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3", "output": "5 18 31 20" }, { "input": "1 1 1\n0\n1 1 0\n1 1...
1,596,741,799
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
// Author : ps41 #include <bits/stdc++.h> using namespace std; #define ll int64_t const ll M = 1e9 + 7, N = 1e6 + 5; ll a[N], f[N], op[N][3], ans[N]; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); ll n, m, k; cin >> n >> m >> k; for (ll i = 1; i <= n; i++) cin >> a[i]; for...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements ...
```python // Author : ps41 #include <bits/stdc++.h> using namespace std; #define ll int64_t const ll M = 1e9 + 7, N = 1e6 + 5; ll a[N], f[N], op[N][3], ans[N]; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); ll n, m, k; cin >> n >> m >> k; for (ll i = 1; i <= n; i++) cin >> a[i]...
-1
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character...
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "...
1,678,268,506
2,147,483,647
PyPy 3-64
OK
TESTS
44
61
0
x=input() y="a" z=y+x n=len(z) # print(z) c=0 v=[] for i in range(n-1): a=abs(ord(z[i+1])-ord(z[i])) if a<=13: c=a v.append(c) elif a>13: c=26-a v.append(c) print(sum(v))
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devis...
```python x=input() y="a" z=y+x n=len(z) # print(z) c=0 v=[] for i in range(n-1): a=abs(ord(z[i+1])-ord(z[i])) if a<=13: c=a v.append(c) elif a>13: c=26-a v.append(c) print(sum(v)) ```
3
574
A
Bear and Elections
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are *n* candidates, including Limak. We know how many citizens are going to vote for each candidate. Now *i*-th candidate would get *a**i* votes. Limak is candidate number 1. To win in elect...
The first line contains single integer *n* (2<=≤<=*n*<=≤<=100) - number of candidates. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate ...
Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate.
[ "5\n5 1 11 2 8\n", "4\n1 8 8 8\n", "2\n7 6\n" ]
[ "4\n", "6\n", "0\n" ]
In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate ...
500
[ { "input": "5\n5 1 11 2 8", "output": "4" }, { "input": "4\n1 8 8 8", "output": "6" }, { "input": "2\n7 6", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "10\n100 200 57 99 1 1000 200 200 200 500", "output": "451" }, { "input": "16\...
1,442,851,728
2,147,483,647
Python 3
OK
TESTS
35
62
0
n = int(input()) a = input().split() a = list(map(int, a)) votes = 0; while(a[0] <= max(a[1:])): votes += 1 a[0] += 1 a[a[1:].index(max(a[1:])) + 1] -= 1 print(votes)
Title: Bear and Elections Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are *n* candidates, including Limak. We know how many citizens are going to vote for e...
```python n = int(input()) a = input().split() a = list(map(int, a)) votes = 0; while(a[0] <= max(a[1:])): votes += 1 a[0] += 1 a[a[1:].index(max(a[1:])) + 1] -= 1 print(votes) ```
3
471
A
MUH and Sticks
PROGRAMMING
1,100
[ "implementation" ]
null
null
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: -...
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
[ "4 2 5 4 4 4\n", "4 4 5 4 4 5\n", "1 2 3 4 5 6\n" ]
[ "Bear", "Elephant", "Alien" ]
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
500
[ { "input": "4 2 5 4 4 4", "output": "Bear" }, { "input": "4 4 5 4 4 5", "output": "Elephant" }, { "input": "1 2 3 4 5 6", "output": "Alien" }, { "input": "5 5 5 5 5 5", "output": "Elephant" }, { "input": "1 1 1 2 3 5", "output": "Alien" }, { "input": "...
1,530,015,693
2,147,483,647
Python 3
OK
TESTS
29
93
204,800
from collections import Counter c = Counter(input().split()).values() if max(c) < 4: print('Alien') elif min(c) in (2, 6): print('Elephant') else: print('Bear')
Title: MUH and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an...
```python from collections import Counter c = Counter(input().split()).values() if max(c) < 4: print('Alien') elif min(c) in (2, 6): print('Elephant') else: print('Bear') ```
3
214
A
System of Equations
PROGRAMMING
800
[ "brute force" ]
null
null
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of int...
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
On a single line print the answer to the problem.
[ "9 3\n", "14 28\n", "4 20\n" ]
[ "1\n", "1\n", "0\n" ]
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
500
[ { "input": "9 3", "output": "1" }, { "input": "14 28", "output": "1" }, { "input": "4 20", "output": "0" }, { "input": "18 198", "output": "1" }, { "input": "22 326", "output": "1" }, { "input": "26 104", "output": "1" }, { "input": "14 10"...
1,643,035,656
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
11
186
2,355,200
import math def main_function(): n, m = [int(u) for u in input().split(" ")] counter = 0 for i in range(1001): for j in range(min(n, m)): if i ** 2 + j == n and i + j ** 2 == m: counter += 1 print(counter) main_function()
Title: System of Equations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi...
```python import math def main_function(): n, m = [int(u) for u in input().split(" ")] counter = 0 for i in range(1001): for j in range(min(n, m)): if i ** 2 + j == n and i + j ** 2 == m: counter += 1 print(counter) main_function() `...
0
365
A
Good Number
PROGRAMMING
1,100
[ "implementation" ]
null
null
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*).
The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the number of *k*-good numbers in *a*.
[ "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n", "2 1\n1\n10\n" ]
[ "10\n", "1\n" ]
none
500
[ { "input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560", "output": "10" }, { "input": "2 1\n1\n10", "output": "1" }, { "input": "1 0\n1000000000", "output": "1" }, { "input": "1 1\n1000000000", "output": "1" }, { ...
1,676,567,777
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
s=list(map(int,input().split())) n=0 x=0 z=0 for i in range(s[1]+1): n+=1 for j in range(s[0]): x=0 b=input() c=sorted(b) for k in c: x+=1 if x==n: z+=1 print(z)
Title: Good Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve...
```python s=list(map(int,input().split())) n=0 x=0 z=0 for i in range(s[1]+1): n+=1 for j in range(s[0]): x=0 b=input() c=sorted(b) for k in c: x+=1 if x==n: z+=1 print(z) ```
0
34
A
Reconnaissance 2
PROGRAMMING
800
[ "implementation" ]
A. Reconnaissance 2
2
256
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ...
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
[ "5\n10 12 13 15 10\n", "4\n10 20 30 40\n" ]
[ "5 1\n", "1 2\n" ]
none
500
[ { "input": "5\n10 12 13 15 10", "output": "5 1" }, { "input": "4\n10 20 30 40", "output": "1 2" }, { "input": "6\n744 359 230 586 944 442", "output": "2 3" }, { "input": "5\n826 747 849 687 437", "output": "1 2" }, { "input": "5\n999 999 993 969 999", "output"...
1,580,485,066
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
278
0
n=int(input()) A=list(map(int,input().split())) Min=abs(A[1]-A[0]) index=[1,2] for i in range(1,n): if abs(A[i]-A[i-1])<Min: Min=A[i]-A[i-1] index[0]=i index[1]=i+1 if abs(A[n-1]-A[0])<Min: Min=A[i]-A[i-1] index[0]=n index[1]=1 for i in index: print(i,end=' ') ...
Title: Reconnaissance 2 Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So...
```python n=int(input()) A=list(map(int,input().split())) Min=abs(A[1]-A[0]) index=[1,2] for i in range(1,n): if abs(A[i]-A[i-1])<Min: Min=A[i]-A[i-1] index[0]=i index[1]=i+1 if abs(A[n-1]-A[0])<Min: Min=A[i]-A[i-1] index[0]=n index[1]=1 for i in index: print(i,...
0
609
A
USB Flash Drives
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives. The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file. Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabyt...
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
[ "3\n5\n2\n1\n3\n", "3\n6\n2\n3\n2\n", "2\n5\n5\n10\n" ]
[ "2\n", "3\n", "1\n" ]
In the first example Sean needs only two USB flash drives — the first and the third. In the second example Sean needs all three USB flash drives. In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.
0
[ { "input": "3\n5\n2\n1\n3", "output": "2" }, { "input": "3\n6\n2\n3\n2", "output": "3" }, { "input": "2\n5\n5\n10", "output": "1" }, { "input": "5\n16\n8\n1\n3\n4\n9", "output": "2" }, { "input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100", "output": "2" ...
1,625,492,705
2,147,483,647
Python 3
OK
TESTS
34
77
0
if __name__=="__main__": n=int(input()) m=int(input()) li=[] for i in range(n): num=int(input()) li.append(num) li.sort(reverse=True) c=0 for i in li: if m>0: m=m-i c+=1 print(c)
Title: USB Flash Drives Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes. Find the minimum number of...
```python if __name__=="__main__": n=int(input()) m=int(input()) li=[] for i in range(n): num=int(input()) li.append(num) li.sort(reverse=True) c=0 for i in li: if m>0: m=m-i c+=1 print(c) ```
3
275
A
Lights Out
PROGRAMMING
900
[ "implementation" ]
null
null
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw...
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
[ "1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n" ]
[ "001\n010\n100\n", "010\n011\n100\n" ]
none
500
[ { "input": "1 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100" }, { "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100" }, { "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000" }, { "input": "96 95 5\n8 84 74\n67 31 61", "output": "011\n011\n101" }, {...
1,622,297,154
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
l=[[1,1,1,1,1], [1,1,1,1,1], [1,1,1,1,1], [1,1,1,1,1], [1,1,1,1,1]] for i in range(1,4): for j in range(1,4): a=int(input()) if(a%2==1): l[i][j]=abs(1-l[i][j]) l[i+1][j]=abs(1-l[i+1][j]) l[i][j+1]=abs(1-l[i][j+1]) ...
Title: Lights Out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ...
```python l=[[1,1,1,1,1], [1,1,1,1,1], [1,1,1,1,1], [1,1,1,1,1], [1,1,1,1,1]] for i in range(1,4): for j in range(1,4): a=int(input()) if(a%2==1): l[i][j]=abs(1-l[i][j]) l[i+1][j]=abs(1-l[i+1][j]) l[i][j+1]=abs(1-l[i][j+1])...
-1
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,499,060,423
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
80
124
5,529,600
n=int(input()) a=0 b=0 c=0 for i in range(n): x,y,z=(int(j) for j in input().split()) a,b,c=a+x,b+y,c+z if a+b+c==0: print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python n=int(input()) a=0 b=0 c=0 for i in range(n): x,y,z=(int(j) for j in input().split()) a,b,c=a+x,b+y,c+z if a+b+c==0: print('YES') else: print('NO') ```
0
334
B
Eight Point Sets
PROGRAMMING
1,400
[ "sortings" ]
null
null
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three int...
The input consists of eight lines, the *i*-th line contains two space-separated integers *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=106). You do not have any other conditions for these points.
In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise.
[ "0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2\n", "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n", "1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n" ]
[ "respectable\n", "ugly\n", "ugly\n" ]
none
1,000
[ { "input": "0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2", "output": "respectable" }, { "input": "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0", "output": "ugly" }, { "input": "1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2", "output": "ugly" }, { "input": "0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0...
1,660,878,689
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
124
7,884,800
fre_x = [False] * (10 ** 6 + 5) fre_y = [False] * (10 ** 6 + 5) unique_x = [] unique_y = [] points = [] for _ in range(8): x, y = map(int, input().split()) points.append((x, y)) if not fre_x[x]: fre_x[x] = True unique_x.append(x) if not fre_y[y]: fre_y[y] = ...
Title: Eight Point Sets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizonta...
```python fre_x = [False] * (10 ** 6 + 5) fre_y = [False] * (10 ** 6 + 5) unique_x = [] unique_y = [] points = [] for _ in range(8): x, y = map(int, input().split()) points.append((x, y)) if not fre_x[x]: fre_x[x] = True unique_x.append(x) if not fre_y[y]: f...
0
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i...
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" ...
1,655,476,180
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n, m = map(int, input().split()) bw = 0 c = 0 for i in range(n): color = list(map(str, input().split())) for i in range(m): if color[i] == "W" or color[0] == "B" or color[0] == "G": bw += 1 else: c += 1 if c>bw: print("#Color") else: c<bw: print(...
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the...
```python n, m = map(int, input().split()) bw = 0 c = 0 for i in range(n): color = list(map(str, input().split())) for i in range(m): if color[i] == "W" or color[0] == "B" or color[0] == "G": bw += 1 else: c += 1 if c>bw: print("#Color") else: c<bw: ...
-1
729
C
Road to Cinema
PROGRAMMING
1,700
[ "binary search", "greedy", "sortings" ]
null
null
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in *t* minutes. There is a straight road of length *s* from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point...
The first line contains four positive integers *n*, *k*, *s* and *t* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*k*<=≤<=2·105, 2<=≤<=*s*<=≤<=109, 1<=≤<=*t*<=≤<=2·109) — the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts. Each of the n...
Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in *t* minutes). If there is no appropriate car, print -1.
[ "3 1 8 10\n10 8\n5 7\n11 9\n3\n", "2 2 10 18\n10 4\n20 6\n5 3\n" ]
[ "10\n", "20\n" ]
In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. Aft...
1,750
[ { "input": "3 1 8 10\n10 8\n5 7\n11 9\n3", "output": "10" }, { "input": "2 2 10 18\n10 4\n20 6\n5 3", "output": "20" }, { "input": "2 1 1000000000 2000000000\n111 1000000000\n101 1000000000\n5", "output": "101" }, { "input": "2 1 1000000000 2000000000\n111 999999998\n101 9999...
1,479,638,435
5,735
Python 3
WRONG_ANSWER
PRETESTS
2
46
204,800
ans=-1 n,k,s,t=[int(i) for i in input().split()] cars=[] minV=2000000000 maxV=0 for i in range(n): cars.append([int(i) for i in input().split()]) if cars[i][1]>maxV: maxV=cars[i][1] if cars[i][1]<minV: minV=cars[i][1] g=[int(i) for i in input().split()] g.sort() g+=[s-g[-1]] ma...
Title: Road to Cinema Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in *t* minutes. There is a straight road of length *s* from the service to the cinema. Let's introduce ...
```python ans=-1 n,k,s,t=[int(i) for i in input().split()] cars=[] minV=2000000000 maxV=0 for i in range(n): cars.append([int(i) for i in input().split()]) if cars[i][1]>maxV: maxV=cars[i][1] if cars[i][1]<minV: minV=cars[i][1] g=[int(i) for i in input().split()] g.sort() g+=[s-...
0
600
B
Queries about less or equal elements
PROGRAMMING
1,300
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
0
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -77918754...
1,680,513,263
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
46
0
a,b = map(int,input().split()) arr1 = list(map(int,input().split())) arr2 = list(map(int,input().split())) # arr1.sort() # arr2.sort() count=0 if(arr2[-1]<arr1[0]): print(count) else: for i in arr2: count=0 for j in arr1: if(j<=i): count+=1 ...
Title: Queries about less or equal elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. In...
```python a,b = map(int,input().split()) arr1 = list(map(int,input().split())) arr2 = list(map(int,input().split())) # arr1.sort() # arr2.sort() count=0 if(arr2[-1]<arr1[0]): print(count) else: for i in arr2: count=0 for j in arr1: if(j<=i): count+=1 ...
0
389
A
Fox and Number Game
PROGRAMMING
1,000
[ "greedy", "math" ]
null
null
Fox Ciel is playing a game with numbers now. Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* &gt; *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum ...
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100).
Output a single integer — the required minimal sum.
[ "2\n1 2\n", "3\n2 4 6\n", "2\n12 18\n", "5\n45 12 27 30 18\n" ]
[ "2\n", "6\n", "12\n", "15\n" ]
In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub...
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n2 4 6", "output": "6" }, { "input": "2\n12 18", "output": "12" }, { "input": "5\n45 12 27 30 18", "output": "15" }, { "input": "2\n1 1", "output": "2" }, { "input": "2\n100 100", "output": "200" ...
1,616,650,342
2,147,483,647
PyPy 3
OK
TESTS
34
233
9,625,600
import fractions n=int(input()) a=0 for x in input().split(): a=fractions.gcd(a,int(x)) print(a*n)
Title: Fox and Number Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel is playing a game with numbers now. Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that ...
```python import fractions n=int(input()) a=0 for x in input().split(): a=fractions.gcd(a,int(x)) print(a*n) ```
3
48
A
Rock-paper-scissors
PROGRAMMING
900
[ "implementation", "schedules" ]
A. Rock-paper-scissors
2
256
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obvio...
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
[ "rock\nrock\nrock\n", "paper\nrock\nrock\n", "scissors\nrock\nrock\n", "scissors\npaper\nrock\n" ]
[ "?\n", "F\n", "?\n", "?\n" ]
none
0
[ { "input": "rock\nrock\nrock", "output": "?" }, { "input": "paper\nrock\nrock", "output": "F" }, { "input": "scissors\nrock\nrock", "output": "?" }, { "input": "scissors\npaper\nrock", "output": "?" }, { "input": "paper\npaper\nrock", "output": "?" }, { ...
1,620,477,496
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
216
20,172,800
words=[] def find_person(n): if(n==0): print("F") elif(n==1): print("M") elif(n==2): print("S") for i in range(3): game_word=input() words.append(game_word) if(words.count("rock")==1 and words.count("scissor")==2): index=words.index("rock") find_person(in...
Title: Rock-paper-scissors Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case ...
```python words=[] def find_person(n): if(n==0): print("F") elif(n==1): print("M") elif(n==2): print("S") for i in range(3): game_word=input() words.append(game_word) if(words.count("rock")==1 and words.count("scissor")==2): index=words.index("rock") find...
0
37
A
Towers
PROGRAMMING
1,000
[ "sortings" ]
A. Towers
2
256
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ...
The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
[ "3\n1 2 3\n", "4\n6 5 6 7\n" ]
[ "1 3\n", "2 3\n" ]
none
500
[ { "input": "3\n1 2 3", "output": "1 3" }, { "input": "4\n6 5 6 7", "output": "2 3" }, { "input": "4\n3 2 1 1", "output": "2 3" }, { "input": "4\n1 2 3 3", "output": "2 3" }, { "input": "3\n20 22 36", "output": "1 3" }, { "input": "25\n47 30 94 41 45 20...
1,658,751,815
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
92
0
n = int(input()) k = list(map(int, input().split())) l = [] s = 1 z = 0 for i in k: if i not in l: l.append(i) z += 1 else: s += 1 print(s, len(l))
Title: Towers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct...
```python n = int(input()) k = list(map(int, input().split())) l = [] s = 1 z = 0 for i in k: if i not in l: l.append(i) z += 1 else: s += 1 print(s, len(l)) ```
0
618
A
Slime Combining
PROGRAMMING
800
[ "implementation" ]
null
null
Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other *n*<=-<=1 slimes one by one. When you add a slime, you place it at the right of...
The first line of the input will contain a single integer, *n* (1<=≤<=*n*<=≤<=100<=000).
Output a single line with *k* integers, where *k* is the number of slimes in the row after you've finished the procedure described in the problem statement. The *i*-th of these numbers should be the value of the *i*-th slime from the left.
[ "1\n", "2\n", "3\n", "8\n" ]
[ "1\n", "2\n", "2 1\n", "4\n" ]
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. S...
500
[ { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "3", "output": "2 1" }, { "input": "8", "output": "4" }, { "input": "100000", "output": "17 16 11 10 8 6" }, { "input": "12345", "output": "14 13 6 5 4 1" }, { "in...
1,669,546,647
2,147,483,647
Python 3
OK
TESTS
27
108
0
n = int(input()) i = 1 res_board = [] while i <= n: res_board.append(1) while True: if len(res_board)>1: if res_board[-2] == res_board[-1]: res_board[-2] += 1 res_board.pop(-1) else: break else: break i += 1 res_board = ' '.join([str(x) for x in res_board]) print(res_board)
Title: Slime Combining Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, y...
```python n = int(input()) i = 1 res_board = [] while i <= n: res_board.append(1) while True: if len(res_board)>1: if res_board[-2] == res_board[-1]: res_board[-2] += 1 res_board.pop(-1) else: break else: break i += 1 res_board = ' '.join([str(x) for x in res_board]) print(...
3
915
A
Garden
PROGRAMMING
900
[ "implementation" ]
null
null
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat...
The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively. The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one ...
Print one integer number — the minimum number of hours required to water the garden.
[ "3 6\n2 3 5\n", "6 7\n1 2 3 4 5 6\n" ]
[ "2\n", "7\n" ]
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
0
[ { "input": "3 6\n2 3 5", "output": "2" }, { "input": "6 7\n1 2 3 4 5 6", "output": "7" }, { "input": "5 97\n1 10 50 97 2", "output": "1" }, { "input": "5 97\n1 10 50 100 2", "output": "97" }, { "input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5...
1,651,633,304
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
n,k = map(int,input().split()) l = list(map(int,input().split())) ans = 100 print(min(l))
Title: Garden Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ...
```python n,k = map(int,input().split()) l = list(map(int,input().split())) ans = 100 print(min(l)) ```
0
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-...
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transform...
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output...
1,657,731,122
2,147,483,647
PyPy 3
OK
TESTS
51
186
1,945,600
n = input() count =0 while len(n) > 1 : sum =0 for x in n: sum+= int(x) n = str(sum) count+=1 print(count)
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came...
```python n = input() count =0 while len(n) > 1 : sum =0 for x in n: sum+= int(x) n = str(sum) count+=1 print(count) ```
3.949999
899
A
Splitting in Teams
PROGRAMMING
800
[ "constructive algorithms", "greedy", "math" ]
null
null
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of tea...
The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*.
Print the maximum number of teams of three people the coach can form.
[ "4\n1 1 2 1\n", "2\n2 2\n", "7\n2 2 2 1 1 1 1\n", "3\n1 1 1\n" ]
[ "1\n", "0\n", "3\n", "1\n" ]
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) an...
500
[ { "input": "4\n1 1 2 1", "output": "1" }, { "input": "2\n2 2", "output": "0" }, { "input": "7\n2 2 2 1 1 1 1", "output": "3" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "3\n2 2 2", "output": "0" }, { "input": "3\n1 2 1", "output": "1" }...
1,581,362,682
2,147,483,647
Python 3
OK
TESTS
67
202
3,788,800
n = int(input()) numbers = input().split() twos = [] ones = [] for i in range(n): if(numbers[i] == '2'): twos.append(numbers[i]) else: ones.append(numbers[i]) count = 0 while(len(twos) != 0): if(len(ones) != 0): ones.pop() twos.pop() count += 1...
Title: Splitting in Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The co...
```python n = int(input()) numbers = input().split() twos = [] ones = [] for i in range(n): if(numbers[i] == '2'): twos.append(numbers[i]) else: ones.append(numbers[i]) count = 0 while(len(twos) != 0): if(len(ones) != 0): ones.pop() twos.pop() ...
3
883
M
Quadcopter Competition
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should: - start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point. Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point w...
The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point. The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag. It is guaranteed that the quadcopter sta...
Print the length of minimal path of the quadcopter to surround the flag and return back.
[ "1 5\n5 2\n", "0 1\n0 0\n" ]
[ "18\n", "8\n" ]
none
0
[ { "input": "1 5\n5 2", "output": "18" }, { "input": "0 1\n0 0", "output": "8" }, { "input": "-100 -100\n100 100", "output": "804" }, { "input": "-100 -100\n-100 100", "output": "406" }, { "input": "-100 -100\n100 -100", "output": "406" }, { "input": "1...
1,600,092,063
2,147,483,647
PyPy 3
OK
TESTS
100
140
0
x1,y1 = map(int,input().split()) x2,y2 = map(int,input().split()) upperx = x2-1 lowerx = x2+1 uppery = y2-1 lowery = y2+1 cnt = 4 + abs(upperx - x1) + abs(lowerx - x1) + abs(uppery - y1) + abs(lowery - y1) print(cnt)
Title: Quadcopter Competition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp takes part in a quadcopter competition. According to the rules a flying robot should: - start the race from some point of a field, - go around the flag, - close cycle returning back to the starting p...
```python x1,y1 = map(int,input().split()) x2,y2 = map(int,input().split()) upperx = x2-1 lowerx = x2+1 uppery = y2-1 lowery = y2+1 cnt = 4 + abs(upperx - x1) + abs(lowerx - x1) + abs(uppery - y1) + abs(lowery - y1) print(cnt) ```
3
899
C
Dividing the numbers
PROGRAMMING
1,300
[ "constructive algorithms", "graphs", "math" ]
null
null
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible. Help Petya to split the integers. Each of *n* integers should be exactly in one group.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has.
Print the smallest possible absolute difference in the first line. In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
[ "4\n", "2\n" ]
[ "0\n2 1 4 \n", "1\n1 1 \n" ]
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0. In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and on...
1,500
[ { "input": "4", "output": "0\n2 1 4 " }, { "input": "2", "output": "1\n1 1 " }, { "input": "3", "output": "0\n1\n3 " }, { "input": "5", "output": "1\n3\n1 2 5 " }, { "input": "59998", "output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 4...
1,513,546,400
2,147,483,647
PyPy 3
OK
TESTS
60
171
27,545,600
N = int(input()) List = list() K, curr = (N * (N+1)) / 2, 0 want = K // 2 if K % 2 == 0: print(0) else: print(1) while N != 0: if curr + N <= want: curr += N List.append(N) N -= 1 print(len(List), end=" ") for num in List: print(num, end=" ")
Title: Dividing the numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible. Help P...
```python N = int(input()) List = list() K, curr = (N * (N+1)) / 2, 0 want = K // 2 if K % 2 == 0: print(0) else: print(1) while N != 0: if curr + N <= want: curr += N List.append(N) N -= 1 print(len(List), end=" ") for num in List: print(num, end=" ") ```
3
844
B
Rectangles
PROGRAMMING
1,300
[ "combinatorics", "math" ]
null
null
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: 1. All cells in a set have the same color. 1. Every two cells in a set share row or column.
The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly. The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored wh...
Output single integer  — the number of non-empty sets from the problem description.
[ "1 1\n0\n", "2 3\n1 0 1\n0 1 0\n" ]
[ "1\n", "8\n" ]
In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.
1,000
[ { "input": "1 1\n0", "output": "1" }, { "input": "2 3\n1 0 1\n0 1 0", "output": "8" }, { "input": "2 2\n1 1\n1 1", "output": "8" }, { "input": "1 10\n0 0 0 0 0 0 0 0 0 0", "output": "1023" }, { "input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "2047"...
1,503,595,409
2,909
Python 3
OK
TESTS
55
62
0
from math import pow n,m=[int(i) for i in input().split()] l=[] for i in range(n): l.append([int(j) for j in input().split()]) count= n*m for i in range(n): count1=l[i].count(0) if (count1!=0 and count1!=1): count+=int(pow(2,count1)-1-count1) count2=m-count1 if (count2!=0 and coun...
Title: Rectangles Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: 1. All cells in a set have the same color. 1. Every two cells in a set share row or ...
```python from math import pow n,m=[int(i) for i in input().split()] l=[] for i in range(n): l.append([int(j) for j in input().split()]) count= n*m for i in range(n): count1=l[i].count(0) if (count1!=0 and count1!=1): count+=int(pow(2,count1)-1-count1) count2=m-count1 if (count2!=...
3
0
none
none
none
0
[ "none" ]
null
null
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them. Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr...
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Print the given word without any changes if there are no typos. If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
[ "hellno\n", "abacaba\n", "asdfasdf\n" ]
[ "hell no \n", "abacaba \n", "asd fasd f \n" ]
none
0
[ { "input": "hellno", "output": "hell no " }, { "input": "abacaba", "output": "abacaba " }, { "input": "asdfasdf", "output": "asd fasd f " }, { "input": "ooo", "output": "ooo " }, { "input": "moyaoborona", "output": "moyaoborona " }, { "input": "jxegxxx...
1,505,745,911
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
61
4,608,000
# coding: utf-8 # 434C - Division 2 - Did you mean... # (http://codeforces.com/contest/861/problem/C) def check(arr, c): arr = arr[:] arr.append(c) first = arr[0] for elem in arr: if elem != first: return False return True word = input() con = [] answer = ""...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them. Beroffice works only with small English letters (i.e. with 2...
```python # coding: utf-8 # 434C - Division 2 - Did you mean... # (http://codeforces.com/contest/861/problem/C) def check(arr, c): arr = arr[:] arr.append(c) first = arr[0] for elem in arr: if elem != first: return False return True word = input() con = [] a...
0
318
A
Even Odds
PROGRAMMING
900
[ "math" ]
null
null
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow...
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print the number that will stand at the position number *k* after Volodya's manipulations.
[ "10 3\n", "7 7\n" ]
[ "5", "6" ]
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
500
[ { "input": "10 3", "output": "5" }, { "input": "7 7", "output": "6" }, { "input": "7 1", "output": "1" }, { "input": "7 2", "output": "3" }, { "input": "8 5", "output": "2" }, { "input": "8 3", "output": "5" }, { "input": "8 4", "output...
1,693,413,329
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
n=input() n=int(n) if n%2==0 and n!=2: print("no") else: print("yes")
Title: Even Odds Time Limit: None seconds Memory Limit: None megabytes Problem Description: Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ...
```python n=input() n=int(n) if n%2==0 and n!=2: print("no") else: print("yes") ```
-1
125
E
MST Company
PROGRAMMING
2,400
[ "binary search", "graphs" ]
null
null
The MST (Meaningless State Team) company won another tender for an important state reform in Berland. There are *n* cities in Berland, some pairs of the cities are connected by roads. Each road has its price. One can move along any road in any direction. The MST team should carry out the repair works on some set of ro...
The first input line contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*<=≤<=5000;0<=≤<=*m*<=≤<=105;0<=≤<=*k*<=&lt;<=5000), where *n* is the number of cities in the country, *m* is the number of roads in the country, *k* is the number of capital roads in the required set. Then *m* lines enumerate the roads in question. ...
In the first line print the number of roads in the required set. The second line should contain the numbers of roads included in the sought set. If the sought set does not exist, print -1.
[ "4 5 2\n1 2 1\n2 3 1\n3 4 1\n1 3 3\n1 4 2\n" ]
[ "3\n1 5 2 " ]
none
5,000
[]
1,649,084,279
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
62
0
n, m, k = map(int, input().split()) graph = {} for i in range(1, m+1): a,b,w = map(int, input().split()) if a in graph: graph[a].append((b,w,i)) else: graph[a] = [(b,w,i)] if b in graph: graph[b].append((a,w,i)) else: graph[b] = [(a,w,i)] for i in ra...
Title: MST Company Time Limit: None seconds Memory Limit: None megabytes Problem Description: The MST (Meaningless State Team) company won another tender for an important state reform in Berland. There are *n* cities in Berland, some pairs of the cities are connected by roads. Each road has its price. One can move ...
```python n, m, k = map(int, input().split()) graph = {} for i in range(1, m+1): a,b,w = map(int, input().split()) if a in graph: graph[a].append((b,w,i)) else: graph[a] = [(b,w,i)] if b in graph: graph[b].append((a,w,i)) else: graph[b] = [(a,w,i)] f...
-1
313
B
Ilya and Queries
PROGRAMMING
1,100
[ "dp", "implementation" ]
null
null
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<...
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-t...
Print *m* integers — the answers to the queries in the order in which they are given in the input.
[ "......\n4\n3 4\n2 3\n1 6\n2 6\n", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n" ]
[ "1\n1\n5\n4\n", "1\n1\n2\n2\n0\n" ]
none
1,000
[ { "input": "......\n4\n3 4\n2 3\n1 6\n2 6", "output": "1\n1\n5\n4" }, { "input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4", "output": "1\n1\n2\n2\n0" }, { "input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3", "output": "2\n0\n0\n1\n2\n0" }, { "input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5...
1,697,926,116
2,147,483,647
Python 3
OK
TESTS
37
622
5,529,600
from sys import stdin stream = None try: stream = open('file.txt', 'r') except: stream = stdin dot_sharp = stream.readline().strip() n = int(stream.readline()) in_row = [0] prev = dot_sharp[0] for i in range(1, len(dot_sharp)): count = in_row[i - 1] current = dot_sharp[i] if current == prev: ...
Title: Ilya and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting ...
```python from sys import stdin stream = None try: stream = open('file.txt', 'r') except: stream = stdin dot_sharp = stream.readline().strip() n = int(stream.readline()) in_row = [0] prev = dot_sharp[0] for i in range(1, len(dot_sharp)): count = in_row[i - 1] current = dot_sharp[i] if current == ...
3
332
B
Maximum Absurdity
PROGRAMMING
1,500
[ "data structures", "dp", "implementation" ]
null
null
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed. This time mr. Boosch plans to sign ...
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=2·105, 0<=&lt;<=2*k*<=≤<=*n*) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the absurdity of each law (1<=≤<=*x**i*<=≤<=109).
Print two integers *a*, *b* — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1]. If there are multiple solutions, print the one with the minimum number *a*. If there still are multiple soluti...
[ "5 2\n3 6 1 1 6\n", "6 2\n1 1 1 1 1 1\n" ]
[ "1 4\n", "1 3\n" ]
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16. In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.
1,000
[ { "input": "5 2\n3 6 1 1 6", "output": "1 4" }, { "input": "6 2\n1 1 1 1 1 1", "output": "1 3" }, { "input": "6 2\n1 4 1 2 5 6", "output": "1 5" }, { "input": "4 1\n1 2 2 2", "output": "2 3" }, { "input": "6 3\n15 20 1 15 43 6", "output": "1 4" }, { "i...
1,602,777,294
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
186
307,200
n, k = map(int, input().split()) a = [int(i) for i in input().split()] ind1 = 0 ind2 = k sum1 = sum(a[:k]) sum2 = sum(a[k:2 * k]) for i in range(2 * k + 1, n + 1): if sum(a[i - k:i]) > sum2: sum2 = sum(a[i - k:i]) ind2 = i - k if sum(a[ind2 - k + 1:ind2 + 1]) > sum1: s...
Title: Maximum Absurdity Time Limit: None seconds Memory Limit: None megabytes Problem Description: Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on...
```python n, k = map(int, input().split()) a = [int(i) for i in input().split()] ind1 = 0 ind2 = k sum1 = sum(a[:k]) sum2 = sum(a[k:2 * k]) for i in range(2 * k + 1, n + 1): if sum(a[i - k:i]) > sum2: sum2 = sum(a[i - k:i]) ind2 = i - k if sum(a[ind2 - k + 1:ind2 + 1]) > sum1: ...
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,682,082,490
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
92
0
s=input() n=s.lower() print(n)
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python s=input() n=s.lower() print(n) ```
0
808
A
Lucky Year
PROGRAMMING
900
[ "implementation" ]
null
null
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long...
The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland.
Output amount of years from the current year to the next lucky one.
[ "4\n", "201\n", "4000\n" ]
[ "1\n", "99\n", "1000\n" ]
In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
0
[ { "input": "4", "output": "1" }, { "input": "201", "output": "99" }, { "input": "4000", "output": "1000" }, { "input": "9", "output": "1" }, { "input": "10", "output": "10" }, { "input": "1", "output": "1" }, { "input": "100000000", "ou...
1,617,246,385
2,147,483,647
PyPy 3
OK
TESTS
271
108
0
s = input() s = s[1:] l =len(s) bigg = 10 ** l if not s: print(1) else: print(bigg - int(s))
Title: Lucky Year Time Limit: None seconds Memory Limit: None megabytes Problem Description: Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 1...
```python s = input() s = s[1:] l =len(s) bigg = 10 ** l if not s: print(1) else: print(bigg - int(s)) ```
3
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0...
1,696,337,502
2,147,483,647
PyPy 3-64
OK
TESTS
25
124
0
# URL: https://codeforces.com/problemset/problem/263/A for i in range(5): row = input().split() j = -1 try: j = row.index('1') except ValueError: pass if j != -1: print(abs(2 - i) + abs(2 - j)) break
Title: Beautiful Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri...
```python # URL: https://codeforces.com/problemset/problem/263/A for i in range(5): row = input().split() j = -1 try: j = row.index('1') except ValueError: pass if j != -1: print(abs(2 - i) + abs(2 - j)) break ```
3
306
A
Candies
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *...
The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends.
Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value.
[ "12 3\n", "15 4\n", "18 7\n" ]
[ "4 4 4 ", "3 4 4 4 ", "2 2 2 3 3 3 3 " ]
Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces.
500
[ { "input": "12 4", "output": "3 3 3 3 " }, { "input": "15 6", "output": "2 2 2 3 3 3 " }, { "input": "18 8", "output": "2 2 2 2 2 2 3 3 " }, { "input": "1 1", "output": "1 " }, { "input": "2 1", "output": "2 " }, { "input": "100 1", "output": "100 ...
1,686,650,104
2,147,483,647
PyPy 3-64
OK
TESTS
20
122
0
n,m = map(int,input().split(' ')) if n%m == 0: l = [int(n/m)]*m print(" ".join(str(x) for x in l)) else: rem = n%m if rem > (m-rem): # distribute n//m + 1 ek baar sabko diff = m - rem # print(diff) l = [int(n//m) + 1]*m for i in range (0,m): ...
Title: Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most ...
```python n,m = map(int,input().split(' ')) if n%m == 0: l = [int(n/m)]*m print(" ".join(str(x) for x in l)) else: rem = n%m if rem > (m-rem): # distribute n//m + 1 ek baar sabko diff = m - rem # print(diff) l = [int(n//m) + 1]*m for i in range (0,m): ...
3
714
A
Meeting of Old Friends
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya. Filya works a lot and he plans to ...
The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
[ "1 10 9 20 1\n", "1 100 50 200 75\n" ]
[ "2\n", "50\n" ]
In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
500
[ { "input": "1 10 9 20 1", "output": "2" }, { "input": "1 100 50 200 75", "output": "50" }, { "input": "6 6 5 8 9", "output": "1" }, { "input": "1 1000000000 1 1000000000 1", "output": "999999999" }, { "input": "5 100 8 8 8", "output": "0" }, { "input":...
1,589,700,902
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
93
6,656,000
l1,r1,l2,r2,k=map(int,input().split()) if r1>l2 and l1!=r1: conv=(r1-l2)+1 else: conv=r1-l2 if k>=l2 and k<=r1: while k<=r1: conv-=1 k+=k print(conv)
Title: Meeting of Old Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusi...
```python l1,r1,l2,r2,k=map(int,input().split()) if r1>l2 and l1!=r1: conv=(r1-l2)+1 else: conv=r1-l2 if k>=l2 and k<=r1: while k<=r1: conv-=1 k+=k print(conv) ```
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,680,707,508
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n=str(input()) x=len(n)-2 print(n[0]+str(x)+n[-1])
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python n=str(input()) x=len(n)-2 print(n[0]+str(x)+n[-1]) ```
0
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,699,002,922
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
31
0
n=input() if n[0].islower() and n[1:].isupper() or n.isupper(): n=n.capitalize() print(n)
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 n=input() if n[0].islower() and n[1:].isupper() or n.isupper(): n=n.capitalize() print(n) ```
0
791
A
Bear and Big Brother
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's we...
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
[ "4 7\n", "4 9\n", "1 1\n" ]
[ "2\n", "3\n", "1\n" ]
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li...
500
[ { "input": "4 7", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "1 1", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "1 10", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output...
1,694,086,835
2,147,483,647
Python 3
OK
TESTS
62
46
0
a,b = map(int, input().split()) count = 0 if(a==b): print(1) else: while(a<=b): a = a * 3 b = b * 2 count = count + 1 print(count)
Title: Bear and Big Brother Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e...
```python a,b = map(int, input().split()) count = 0 if(a==b): print(1) else: while(a<=b): a = a * 3 b = b * 2 count = count + 1 print(count) ```
3
538
A
Cutting Banner
PROGRAMMING
1,400
[ "brute force", "implementation" ]
null
null
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case ...
The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.
Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).
[ "CODEWAITFORITFORCES\n", "BOTTOMCODER\n", "DECODEFORCES\n", "DOGEFORCES\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n" ]
none
500
[ { "input": "CODEWAITFORITFORCES", "output": "YES" }, { "input": "BOTTOMCODER", "output": "NO" }, { "input": "DECODEFORCES", "output": "YES" }, { "input": "DOGEFORCES", "output": "NO" }, { "input": "ABACABA", "output": "NO" }, { "input": "CODEFORCE", ...
1,437,025,171
2,147,483,647
Python 3
OK
TESTS
55
62
0
str = input() test_str = "CODEFORCES" if len(str) <= len(test_str): print("NO") else: l = 0 r = len(test_str) - 1 while l < len(test_str) and test_str[l] == str[l]: l += 1 while r >= 0 and test_str[r] == str[len(str) - len(test_str) + r]: r -= 1 if r >= l : print("NO") else: print("YES") ...
Title: Cutting Banner Time Limit: None seconds Memory Limit: None megabytes Problem Description: A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody ...
```python str = input() test_str = "CODEFORCES" if len(str) <= len(test_str): print("NO") else: l = 0 r = len(test_str) - 1 while l < len(test_str) and test_str[l] == str[l]: l += 1 while r >= 0 and test_str[r] == str[len(str) - len(test_str) + r]: r -= 1 if r >= l : print("NO") else: print("YES") ...
3
20
A
BerOS file system
PROGRAMMING
1,700
[ "implementation" ]
A. BerOS file system
2
64
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of ...
The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.
The path in normalized form.
[ "//usr///local//nginx/sbin\n" ]
[ "/usr/local/nginx/sbin\n" ]
none
500
[ { "input": "//usr///local//nginx/sbin", "output": "/usr/local/nginx/sbin" }, { "input": "////a//b/////g", "output": "/a/b/g" }, { "input": "/a/b/c", "output": "/a/b/c" }, { "input": "/", "output": "/" }, { "input": "////", "output": "/" }, { "input": "...
1,611,145,449
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
92
0
a=input().split("/") end="" print("/",end="") for i in range(len(a)): if a[i]!='': end+=a[i]+'/' if end[-1]=="/": end=end[0:-1] print(end)
Title: BerOS file system Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/n...
```python a=input().split("/") end="" print("/",end="") for i in range(len(a)): if a[i]!='': end+=a[i]+'/' if end[-1]=="/": end=end[0:-1] print(end) ```
-1
111
B
Petya and Divisors
PROGRAMMING
1,900
[ "binary search", "data structures", "number theory" ]
B. Petya and Divisors
5
256
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem: You are given *n* queries in the form "*x**i* *y**i*". For each query Petya should count how many divisors of number *x**i* divide none of the numbers *x**i*<=-<=*y**i*,<=*x**i*<=-<=*y**i*<=+<=1,<=...,<=*x**i*<=-<=1. Hel...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the following *n* lines contain two space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=105, 0<=≤<=*y**i*<=≤<=*i*<=-<=1, where *i* is the query's ordinal number; the numeration starts with 1). If *y**i*<==<=0 for the query, then the answer t...
For each query print the answer on a single line: the number of positive integers *k* such that
[ "6\n4 0\n3 1\n5 2\n6 2\n18 4\n10000 3\n" ]
[ "3\n1\n1\n2\n2\n22\n" ]
Let's write out the divisors that give answers for the first 5 queries: 1) 1, 2, 4 2) 3 3) 5 4) 2, 6 5) 9, 18
1,000
[ { "input": "6\n4 0\n3 1\n5 2\n6 2\n18 4\n10000 3", "output": "3\n1\n1\n2\n2\n22" }, { "input": "5\n10 0\n10 0\n10 0\n10 0\n10 0", "output": "4\n4\n4\n4\n4" }, { "input": "12\n41684 0\n95210 1\n60053 1\n32438 3\n97956 1\n21785 2\n14594 6\n17170 4\n93937 6\n70764 5\n13695 4\n14552 6", ...
1,627,797,889
2,147,483,647
PyPy 3
OK
TESTS
44
3,336
44,851,200
maxn=100000 div=[0]*(maxn+1) last=[-maxn]*(maxn+1) #Inicializa con lista vacía cada posición for i in range(maxn+1): div[i]=list() #Guarda en div[j] la lista de divisores de j for i in range(2,maxn+1): for j in range(i,maxn+1,i): div[j].append(i) #Resuelve cada caso de prueba t=int(inpu...
Title: Petya and Divisors Time Limit: 5 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves looking for numbers' divisors. One day Petya came across the following problem: You are given *n* queries in the form "*x**i* *y**i*". For each query Petya should count how many divisors of number *x*...
```python maxn=100000 div=[0]*(maxn+1) last=[-maxn]*(maxn+1) #Inicializa con lista vacía cada posición for i in range(maxn+1): div[i]=list() #Guarda en div[j] la lista de divisores de j for i in range(2,maxn+1): for j in range(i,maxn+1,i): div[j].append(i) #Resuelve cada caso de prueba ...
3.582858
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red...
Print a single integer — the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "...
1,694,660,118
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
x=y0;input() for i in input():x+=y==i;y=i print(x)
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ...
```python x=y0;input() for i in input():x+=y==i;y=i print(x) ```
-1
2
B
The least round way
PROGRAMMING
2,000
[ "dp", "math" ]
B. The least round way
2
64
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that - starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell. Moreover, if we multiply together all...
The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109).
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.
[ "3\n1 2 3\n4 5 6\n7 8 9\n" ]
[ "0\nDDRR\n" ]
none
0
[ { "input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "0\nDDRR" }, { "input": "2\n7 6\n3 8", "output": "0\nDR" }, { "input": "3\n4 10 5\n10 9 4\n6 5 3", "output": "1\nDRRD" }, { "input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5", "output": "0\nDDDRRR" }, { "input": "5\n8 3...
1,507,914,400
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
61
307,200
#! python3 def multiply(min_digit, num): tmp = min_digit * num trailing_zero_num = 0 while tmp%10 == 0: trailing_zero_num += 1 tmp = int(tmp/10) return tmp, trailing_zero_num def display_sections_info(sections_info): for i in range(len(sections_info)): for j in range(len(se...
Title: The least round way Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that - starts in the upper left cell of the matrix; - each following cell is to the right or down fro...
```python #! python3 def multiply(min_digit, num): tmp = min_digit * num trailing_zero_num = 0 while tmp%10 == 0: trailing_zero_num += 1 tmp = int(tmp/10) return tmp, trailing_zero_num def display_sections_info(sections_info): for i in range(len(sections_info)): for j in ra...
0
61
E
Enemy is weak
PROGRAMMING
1,900
[ "data structures", "trees" ]
E. Enemy is weak
5
256
The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep". Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number. In Shapur's opinion the weaknes...
The first line of input contains a single number *n* (3<=≤<=*n*<=≤<=106) — the number of men in Roman army. Next line contains *n* different positive integers *a**i* (1<=≤<=*i*<=≤<=*n*,<=1<=≤<=*a**i*<=≤<=109) — powers of men in the Roman army.
A single integer number, the weakness of the Roman army. 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).
[ "3\n3 2 1\n", "3\n2 3 1\n", "4\n10 8 3 1\n", "4\n1 5 4 3\n" ]
[ "1\n", "0\n", "4\n", "1\n" ]
none
2,500
[ { "input": "3\n3 2 1", "output": "1" }, { "input": "3\n2 3 1", "output": "0" }, { "input": "4\n10 8 3 1", "output": "4" }, { "input": "4\n1 5 4 3", "output": "1" }, { "input": "9\n10 9 5 6 8 3 4 7 11", "output": "20" }, { "input": "7\n11 3 8 4 2 9 6", ...
1,550,567,630
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
109
307,200
class Node: count=False def __init__(self,value): nodelist=[self] self.right=False self.left=False self.value=value self.former_smaller_count=[0,0,0] present_smaller_count=[1,0,0] # puts 1 if Node.count: r=Node.root # puts 2...
Title: Enemy is weak Time Limit: 5 seconds Memory Limit: 256 megabytes Problem Description: The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep". Nevertheless Shapur has to find weaknesses in the Roma...
```python class Node: count=False def __init__(self,value): nodelist=[self] self.right=False self.left=False self.value=value self.former_smaller_count=[0,0,0] present_smaller_count=[1,0,0] # puts 1 if Node.count: r=Node.root ...
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,627,909,688
2,147,483,647
Python 3
OK
TESTS
26
218
6,963,200
def getdouble(a): a=list(str(a)) b=a[::-1] result='' for i in a: result+=i for i in b: result+=i return int(result) sum=0 lists=list(map(int,input().split(' '))) for i in range(1,lists[0]+1): sum+=getdouble(i) print(sum%lists[1])
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 def getdouble(a): a=list(str(a)) b=a[::-1] result='' for i in a: result+=i for i in b: result+=i return int(result) sum=0 lists=list(map(int,input().split(' '))) for i in range(1,lists[0]+1): sum+=getdouble(i) print(sum%lists[1]) ```
3
87
C
Interesting Game
PROGRAMMING
2,000
[ "dp", "games", "math" ]
C. Interesting Game
2
256
Two best friends Serozha and Gena play a game. Initially there is one pile consisting of *n* stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of *a*1<=&gt;<=*a*2<=&gt;<=...<=&gt;<=*a**k*<=&gt;<=0 stones. The piles should meet the condition *a*1<=-<=...
The single line contains a single integer *n* (1<=≤<=*n*<=≤<=105).
If Serozha wins, print *k*, which represents the minimal number of piles into which he can split the initial one during the first move in order to win the game. If Gena wins, print "-1" (without the quotes).
[ "3\n", "6\n", "100\n" ]
[ "2\n", "-1\n", "8\n" ]
none
1,500
[ { "input": "3", "output": "2" }, { "input": "6", "output": "-1" }, { "input": "100", "output": "8" }, { "input": "33", "output": "2" }, { "input": "23", "output": "-1" }, { "input": "35", "output": "-1" }, { "input": "15", "output": "2"...
1,637,387,462
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
0
def mex(dic): if len(dic)==0: return 0 a = set(dic) b = min(a) if b>0: return b-1 else: for i in a: if i-b>1: return b+1 else: b = i return max(a)+1 def sums(x): res = [] for n in range(2,x+...
Title: Interesting Game Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Two best friends Serozha and Gena play a game. Initially there is one pile consisting of *n* stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of *a*1<=...
```python def mex(dic): if len(dic)==0: return 0 a = set(dic) b = min(a) if b>0: return b-1 else: for i in a: if i-b>1: return b+1 else: b = i return max(a)+1 def sums(x): res = [] for n in ...
0
651
A
Joysticks
PROGRAMMING
1,100
[ "dp", "greedy", "implementation", "math" ]
null
null
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n...
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively.
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
[ "3 5\n", "4 4\n" ]
[ "6\n", "5\n" ]
In the first sample game lasts for 6 minute by using the following algorithm: - at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst...
500
[ { "input": "3 5", "output": "6" }, { "input": "4 4", "output": "5" }, { "input": "100 100", "output": "197" }, { "input": "1 100", "output": "98" }, { "input": "100 1", "output": "98" }, { "input": "1 4", "output": "2" }, { "input": "1 1", ...
1,623,387,043
2,147,483,647
PyPy 3
OK
TESTS
39
109
0
a,b=map(int,input().split());t=0 while a*b>1: a,b=min(a,b)+1,max(a,b)-2;t+=1 print(t)
Title: Joysticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on...
```python a,b=map(int,input().split());t=0 while a*b>1: a,b=min(a,b)+1,max(a,b)-2;t+=1 print(t) ```
3
965
A
Paper Airplanes
PROGRAMMING
800
[ "math" ]
null
null
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people....
The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Print a single integer — the minimum number of packs they should buy.
[ "5 3 2 3\n", "5 3 100 1\n" ]
[ "4\n", "5\n" ]
In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
500
[ { "input": "5 3 2 3", "output": "4" }, { "input": "5 3 100 1", "output": "5" }, { "input": "10000 10000 1 1", "output": "100000000" }, { "input": "1 1 10000 10000", "output": "1" }, { "input": "300 300 21 23", "output": "196" }, { "input": "300 2 37 51...
1,655,921,787
2,147,483,647
Python 3
OK
TESTS
18
46
0
[k, n, s, p]=map(int, input().split()) if n%s==0: sheet=(n/s) else: sheet=(n//s)+1 sheet=(n+s-1)//s ans=sheet*k ans=(ans+p-1)//p print(ans)
Title: Paper Airplanes Time Limit: None seconds Memory Limit: None megabytes Problem Description: To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several p...
```python [k, n, s, p]=map(int, input().split()) if n%s==0: sheet=(n/s) else: sheet=(n//s)+1 sheet=(n+s-1)//s ans=sheet*k ans=(ans+p-1)//p print(ans) ```
3
919
B
Perfect Number
PROGRAMMING
1,100
[ "binary search", "brute force", "dp", "implementation", "number theory" ]
null
null
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$).
A single number, denoting the $k$-th smallest perfect integer.
[ "1\n", "2\n" ]
[ "19\n", "28\n" ]
The first perfect integer is $19$ and the second one is $28$.
750
[ { "input": "1", "output": "19" }, { "input": "2", "output": "28" }, { "input": "13", "output": "136" }, { "input": "101", "output": "1432" }, { "input": "1023", "output": "100270" }, { "input": "9999", "output": "10800010" }, { "input": "10...
1,623,270,544
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
77
0
n=int(input()) dp=1 for i in range(1,n+1): n1=dp%10 n2=dp//10 #print(n2,n1) n2+=1 n1-=1 if n1==0: n1=9 #print(n2,n1) dp=n2*10+n1 print(dp)
Title: Perfect Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. Input Specification: A singl...
```python n=int(input()) dp=1 for i in range(1,n+1): n1=dp%10 n2=dp//10 #print(n2,n1) n2+=1 n1-=1 if n1==0: n1=9 #print(n2,n1) dp=n2*10+n1 print(dp) ```
0
29
A
Spit Problem
PROGRAMMING
1,000
[ "brute force" ]
A. Spit Problem
2
256
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at wh...
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
[ "2\n0 1\n1 -1\n", "3\n0 1\n1 1\n2 -2\n", "5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "2\n0 1\n1 -1", "output": "YES" }, { "input": "3\n0 1\n1 1\n2 -2", "output": "NO" }, { "input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES" }, { "input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n759...
1,674,240,919
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
n = int(input()) ver = [] k = 0 for i in range(n): x , d = map(int, input().split()) if (x + d) in ver and x in ver: k += 1 else: ver.append(x) ver.append(x+d) if k != 0: print('Yes') else: print('No')
Title: Spit Problem Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know ...
```python n = int(input()) ver = [] k = 0 for i in range(n): x , d = map(int, input().split()) if (x + d) in ver and x in ver: k += 1 else: ver.append(x) ver.append(x+d) if k != 0: print('Yes') else: print('No') ```
0
705
A
Hulk
PROGRAMMING
800
[ "implementation" ]
null
null
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se...
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Print Dr.Banner's feeling in one line.
[ "1\n", "2\n", "3\n" ]
[ "I hate it\n", "I hate that I love it\n", "I hate that I love that I hate it\n" ]
none
500
[ { "input": "1", "output": "I hate it" }, { "input": "2", "output": "I hate that I love it" }, { "input": "3", "output": "I hate that I love that I hate it" }, { "input": "4", "output": "I hate that I love that I hate that I love it" }, { "input": "5", "output"...
1,695,420,878
2,147,483,647
Python 3
OK
TESTS
21
46
0
n = int(input()) speech = 'I ' for i in range(n-1): if i%2==0: speech+='hate that I ' else: speech+='love that I ' print(speech+'hate it' if n%2==1 else speech+'love it')
Title: Hulk Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and...
```python n = int(input()) speech = 'I ' for i in range(n-1): if i%2==0: speech+='hate that I ' else: speech+='love that I ' print(speech+'hate it' if n%2==1 else speech+'love it') ```
3
158
A
Next Round
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate...
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence...
Output the number of participants who advance to the next round.
[ "8 5\n10 9 8 7 7 7 5 5\n", "4 2\n0 0 0 0\n" ]
[ "6\n", "0\n" ]
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
500
[ { "input": "8 5\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "4 2\n0 0 0 0", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "1 1\n10", "output": "1" }, { "input": "17 14\n16 15...
1,697,108,524
2,147,483,647
Python 3
OK
TESTS
50
92
0
n,k=map(int,input().split()) A=[] s=0 A=list(map(int,input().split())) for i in A: if(i>=A[k-1]): if(i==0): continue else: s=s+1 print(s)
Title: Next Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* p...
```python n,k=map(int,input().split()) A=[] s=0 A=list(map(int,input().split())) for i in A: if(i>=A[k-1]): if(i==0): continue else: s=s+1 print(s) ```
3
735
A
Ostap and Grasshopper
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The gr...
The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the correspondi...
If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
[ "5 2\n#G#T#\n", "6 1\nT....G\n", "7 3\nT..#..G\n", "6 2\n..GT..\n" ]
[ "YES\n", "YES\n", "NO\n", "NO\n" ]
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4. In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times. In the third sample, the grasshopper can't make a sin...
500
[ { "input": "5 2\n#G#T#", "output": "YES" }, { "input": "6 1\nT....G", "output": "YES" }, { "input": "7 3\nT..#..G", "output": "NO" }, { "input": "6 2\n..GT..", "output": "NO" }, { "input": "2 1\nGT", "output": "YES" }, { "input": "100 5\nG####.####.###...
1,687,262,016
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
a,b=input().split() b=int(b) c=list(input()) de=0 ct=0 for i in range (0,len(c)): if c[i]=="G": de=i if c[i]=="T": ct=i checkk=0 cc=de if cc>ct: while cc>(ct+b): cc-=b if c[cc]=="#": checkk=1 break if checkk==0 and (de-ct)%b==0: ...
Title: Ostap and Grasshopper Time Limit: None seconds Memory Limit: None megabytes Problem Description: On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles....
```python a,b=input().split() b=int(b) c=list(input()) de=0 ct=0 for i in range (0,len(c)): if c[i]=="G": de=i if c[i]=="T": ct=i checkk=0 cc=de if cc>ct: while cc>(ct+b): cc-=b if c[cc]=="#": checkk=1 break if checkk==0 and (de-c...
0
799
A
Carrot Cakes
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady...
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
[ "8 6 4 5\n", "8 6 4 6\n", "10 3 11 4\n", "4 2 1 4\n" ]
[ "YES\n", "NO\n", "NO\n", "YES\n" ]
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whe...
500
[ { "input": "8 6 4 5", "output": "YES" }, { "input": "8 6 4 6", "output": "NO" }, { "input": "10 3 11 4", "output": "NO" }, { "input": "4 2 1 4", "output": "YES" }, { "input": "28 17 16 26", "output": "NO" }, { "input": "60 69 9 438", "output": "NO"...
1,645,712,545
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
15
0
n,t,k,d=list(map(int,input().split(' ',4))) t1 = int(n/k) *t t2= (int(n/(2*k))*t)+d if(t2<t1):print('YES') else:print('NO')
Title: Carrot Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu...
```python n,t,k,d=list(map(int,input().split(' ',4))) t1 = int(n/k) *t t2= (int(n/(2*k))*t)+d if(t2<t1):print('YES') else:print('NO') ```
0
58
E
Expression
PROGRAMMING
2,400
[ "dp" ]
E. Expression
2
256
One day Vasya was solving arithmetical problems. He wrote down an expression *a*<=+<=*b*<==<=*c* in his notebook. When the teacher checked Vasya's work it turned out that Vasya had solved the problem incorrectly. Now Vasya tries to find excuses. He says that he simply forgot to write down several digits in numbers *a*,...
The first and only input line contains the expression *a*<=+<=*b*<==<=*c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=106, *a*, *b* and *c* don't contain leading zeroes) which is the expression Vasya wrote down.
Print the correct expression *x*<=+<=*y*<==<=*z* (*x*, *y* and *z* are non-negative numbers without leading zeroes). The expression *a*<=+<=*b*<==<=*c* must be met in *x*<=+<=*y*<==<=*z* as a subsequence. The printed solution should have the minimal possible number of characters. If there are several such solutions, yo...
[ "2+4=5\n", "1+1=3\n", "1+1=2\n" ]
[ "21+4=25\n", "1+31=32\n", "1+1=2\n" ]
none
2,500
[ { "input": "2+4=5", "output": "21+4=25" }, { "input": "1+1=3", "output": "1+31=32" }, { "input": "1+1=2", "output": "1+1=2" }, { "input": "323+123=287", "output": "323+12553=12876" }, { "input": "878347+637216=542650", "output": "847834370+6372160=854206530" ...
1,693,897,323
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
23
278
8,294,400
import sys readline = sys.stdin.readline def read_input() -> tuple: s = readline().strip().replace('+','=').replace(' ', '') return tuple(s.split('=')) def solve(a: str, b: str, c:str): result = a*100 + b + c + '+' + a + b + c +'=' + a + b + c def dfs(i:int, j:int, k:int, carry:int, a1:str, b1:str...
Title: Expression Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya was solving arithmetical problems. He wrote down an expression *a*<=+<=*b*<==<=*c* in his notebook. When the teacher checked Vasya's work it turned out that Vasya had solved the problem incorrectly. Now Vasya tries...
```python import sys readline = sys.stdin.readline def read_input() -> tuple: s = readline().strip().replace('+','=').replace(' ', '') return tuple(s.split('=')) def solve(a: str, b: str, c:str): result = a*100 + b + c + '+' + a + b + c +'=' + a + b + c def dfs(i:int, j:int, k:int, carry:int, a1:s...
0
652
B
z-sort
PROGRAMMING
1,000
[ "sortings" ]
null
null
A student of *z*-school found a kind of sorting called *z*-sort. The array *a* with *n* elements are *z*-sorted if two conditions hold: 1. *a**i*<=≥<=*a**i*<=-<=1 for all even *i*, 1. *a**i*<=≤<=*a**i*<=-<=1 for all odd *i*<=&gt;<=1. For example the arrays [1,2,1,2] and [1,1,1,1] are *z*-sorted while the array [1,2...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array *a*. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*.
If it's possible to make the array *a* *z*-sorted print *n* space separated integers *a**i* — the elements after *z*-sort. Otherwise print the only word "Impossible".
[ "4\n1 2 2 1\n", "5\n1 3 2 2 5\n" ]
[ "1 2 1 2\n", "1 5 2 3 2\n" ]
none
0
[ { "input": "4\n1 2 2 1", "output": "1 2 1 2" }, { "input": "5\n1 3 2 2 5", "output": "1 5 2 3 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "1 1 1 1 1 1 1 1 1 1" }, { "input": "10\n1 9 7 6 2 4 7 8 1 3", "output": "1 ...
1,461,306,987
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
4,608,000
n=int(input()) a=list(map(int,input().split())) a.sort() l=len(a) if l%2==0: k=l//2 for i in range(k): print(a[i],a[k+i],sep=' ',end=' '); else: k=(l-1)//2; print(a[0],sep=' ',end=' '); for i in range(k): print(a[i+1],a[l-1-i],sep=' ',end=' ');
Title: z-sort Time Limit: None seconds Memory Limit: None megabytes Problem Description: A student of *z*-school found a kind of sorting called *z*-sort. The array *a* with *n* elements are *z*-sorted if two conditions hold: 1. *a**i*<=≥<=*a**i*<=-<=1 for all even *i*, 1. *a**i*<=≤<=*a**i*<=-<=1 for all odd *i*<=...
```python n=int(input()) a=list(map(int,input().split())) a.sort() l=len(a) if l%2==0: k=l//2 for i in range(k): print(a[i],a[k+i],sep=' ',end=' '); else: k=(l-1)//2; print(a[0],sep=' ',end=' '); for i in range(k): print(a[i+1],a[l-1-i],sep=' ',end=' '); ```
0
245
E
Mishap in Club
PROGRAMMING
1,400
[ "greedy", "implementation" ]
null
null
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ...
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Print the sought minimum number of people
[ "+-+-+\n", "---" ]
[ "1\n", "3" ]
none
0
[ { "input": "+-+-+", "output": "1" }, { "input": "---", "output": "3" }, { "input": "-", "output": "1" }, { "input": "--", "output": "2" }, { "input": "---", "output": "3" }, { "input": "----", "output": "4" }, { "input": "---+", "output...
1,602,310,347
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
186
0
s = input() a = abs(s.count('+')-s.count('-')) b = abs(s.count('-')-s.count('+')) c = s.count('-') d = s.count('+') print(max(a,b,c,d))
Title: Mishap in Club Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitor...
```python s = input() a = abs(s.count('+')-s.count('-')) b = abs(s.count('-')-s.count('+')) c = s.count('-') d = s.count('+') print(max(a,b,c,d)) ```
0
888
B
Buggy Robot
PROGRAMMING
1,000
[ "greedy" ]
null
null
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — mo...
The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100). The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R.
Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.
[ "4\nLDUR\n", "5\nRRRUU\n", "6\nLLRRRR\n" ]
[ "4\n", "0\n", "4\n" ]
none
0
[ { "input": "4\nLDUR", "output": "4" }, { "input": "5\nRRRUU", "output": "0" }, { "input": "6\nLLRRRR", "output": "4" }, { "input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR", "output": "76" }, { "input": "89\nLDL...
1,593,435,543
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
140
20,172,800
n=int(input()) arr=list(input()) m=0 u=1 d=-1 l=2 r=-2 count=0 temp=0 for i in arr: #print(count) if count==0: #print("hii here i am zero") m=max(m,temp) if i=='U': count+=1 temp+=1 elif i=='D': count-=1 temp+=1 elif i=='L': count+=2 tem...
Title: Buggy Robot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the ce...
```python n=int(input()) arr=list(input()) m=0 u=1 d=-1 l=2 r=-2 count=0 temp=0 for i in arr: #print(count) if count==0: #print("hii here i am zero") m=max(m,temp) if i=='U': count+=1 temp+=1 elif i=='D': count-=1 temp+=1 elif i=='L': count+=2 ...
0
155
A
I_love_\%username\%
PROGRAMMING
800
[ "brute force" ]
null
null
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e...
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ...
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
[ "5\n100 50 200 150 200\n", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n" ]
[ "2\n", "4\n" ]
In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
500
[ { "input": "5\n100 50 200 150 200", "output": "2" }, { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4" }, { "input": "1\n6", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n100 36 53 7 81", "output": "2" ...
1,691,399,801
2,147,483,647
PyPy 3-64
OK
TESTS
37
124
0
n=int(input()) x=list(map(int,input().split(" "))) a=x[0] b=x[0] count=0 for i in range(1,len(x)): if x[i]>a: a=x[i] count+=1 elif x[i]<b: b=x[i] count+=1 print(count)
Title: I_love_\%username\% Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the re...
```python n=int(input()) x=list(map(int,input().split(" "))) a=x[0] b=x[0] count=0 for i in range(1,len(x)): if x[i]>a: a=x[i] count+=1 elif x[i]<b: b=x[i] count+=1 print(count) ```
3
551
A
GukiZ and Contest
PROGRAMMING
800
[ "brute force", "implementation", "sortings" ]
null
null
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote...
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
[ "3\n1 3 3\n", "1\n1\n", "5\n3 5 3 4 5\n" ]
[ "3 1 1\n", "1\n", "4 1 4 3 1\n" ]
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first positi...
500
[ { "input": "3\n1 3 3", "output": "3 1 1" }, { "input": "1\n1", "output": "1" }, { "input": "5\n3 5 3 4 5", "output": "4 1 4 3 1" }, { "input": "7\n1 3 5 4 2 2 1", "output": "6 3 1 2 4 4 6" }, { "input": "11\n5 6 4 2 9 7 6 6 6 6 7", "output": "9 4 10 11 1 2 4 4...
1,434,288,279
2,147,483,647
Python 3
OK
TESTS
36
171
307,200
n = int (input()) arr = [int(x) for x in input().split()] sorted_list = list(arr) out = [] sorted_list.sort() for i in range(0,n): count = sorted_list.count(arr[i]) indx = sorted_list.index(arr[i]) out.append( n - count - indx + 1) print(' '.join(repr(e) for e in out))
Title: GukiZ and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the star...
```python n = int (input()) arr = [int(x) for x in input().split()] sorted_list = list(arr) out = [] sorted_list.sort() for i in range(0,n): count = sorted_list.count(arr[i]) indx = sorted_list.index(arr[i]) out.append( n - count - indx + 1) print(' '.join(repr(e) for e in out)) ```
3
0
none
none
none
0
[ "none" ]
null
null
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him. The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Gr...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — length of the strip. Next line contains a string of length *n* which consists of characters "&lt;" and "&gt;" only, that provide the direction of the jump from the corresponding cell. Next line contains *n* integers *d**i* (1<=≤<=*d*...
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
[ "2\n&gt;&lt;\n1 2\n", "3\n&gt;&gt;&lt;\n2 1 1\n" ]
[ "FINITE\n", "INFINITE" ]
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip. Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
0
[ { "input": "2\n><\n1 2", "output": "FINITE" }, { "input": "3\n>><\n2 1 1", "output": "INFINITE" }, { "input": "1\n>\n1000000000", "output": "FINITE" }, { "input": "1\n<\n1000000000", "output": "FINITE" }, { "input": "2\n>>\n1 1", "output": "FINITE" }, { ...
1,594,472,614
2,147,483,647
Python 3
OK
TESTS
60
202
14,540,800
ans = 0 n = int(input()) S = list(input()) l = list(map(int , input().split())) for i in range(n+1): if S[ans] =='>': ans += l[ans] else : ans-=l[ans] if ans not in range(n): print('FINITE') break else: print('INFINITE')
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him. The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. ...
```python ans = 0 n = int(input()) S = list(input()) l = list(map(int , input().split())) for i in range(n+1): if S[ans] =='>': ans += l[ans] else : ans-=l[ans] if ans not in range(n): print('FINITE') break else: print('INFINITE') ```
3
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la...
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on...
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "outp...
1,639,142,616
2,147,483,647
Python 3
OK
TESTS
26
62
0
n, m = map(int, input().split()) days = 0 step = 0 while n != 0: step += 1 if step == m: n += 1 step = 0 n -= 1 days += 1 print(days)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th...
```python n, m = map(int, input().split()) days = 0 step = 0 while n != 0: step += 1 if step == m: n += 1 step = 0 n -= 1 days += 1 print(days) ```
3
801
B
Valued Keys
PROGRAMMING
900
[ "constructive algorithms", "greedy", "strings" ]
null
null
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th cha...
The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100.
If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters.
[ "ab\naa\n", "nzwzl\nniwel\n", "ab\nba\n" ]
[ "ba\n", "xiyez\n", "-1\n" ]
The first case is from the statement. Another solution for the second case is "zizez" There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) =  "ba".
1,000
[ { "input": "ab\naa", "output": "ba" }, { "input": "nzwzl\nniwel", "output": "xiyez" }, { "input": "ab\nba", "output": "-1" }, { "input": "r\nl", "output": "l" }, { "input": "d\ny", "output": "-1" }, { "input": "yvowz\ncajav", "output": "cajav" },...
1,540,302,722
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
x=input() z=input() f='YES' x1='' for i in range (len (x)): if ord(z[i])>ord(x[i]): f="NO" break else: x1+=x[i] if f=='YES': print(x) else: print(-1)
Title: Valued Keys Time Limit: None seconds Memory Limit: None megabytes Problem Description: You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string...
```python x=input() z=input() f='YES' x1='' for i in range (len (x)): if ord(z[i])>ord(x[i]): f="NO" break else: x1+=x[i] if f=='YES': print(x) else: print(-1) ```
0
938
A
Word Correction
PROGRAMMING
800
[ "implementation" ]
null
null
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction. The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
Output the word *s* after the correction.
[ "5\nweird\n", "4\nword\n", "5\naaeaa\n" ]
[ "werd\n", "word\n", "a\n" ]
Explanations of the examples: 1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <i...
0
[ { "input": "5\nweird", "output": "werd" }, { "input": "4\nword", "output": "word" }, { "input": "5\naaeaa", "output": "a" }, { "input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw", "output": "abbbbbocadabbbbb...
1,606,038,661
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
78
204,800
t = int (input()) s = list(input()) f = [] for i in range (len(s)-1): if len(f) ==0 and s[i] in list(["a", "e", "i", "o", "u", "y"]): f.append(s[i]) elif s[i] not in ["a", "e", "i", "o", "u", "y"] and f[-1] not in ["a", "e", "i", "o", "u", "y"] : f.append(s[i]) elif s[i] in ["a", "e"...
Title: Word Correction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird an...
```python t = int (input()) s = list(input()) f = [] for i in range (len(s)-1): if len(f) ==0 and s[i] in list(["a", "e", "i", "o", "u", "y"]): f.append(s[i]) elif s[i] not in ["a", "e", "i", "o", "u", "y"] and f[-1] not in ["a", "e", "i", "o", "u", "y"] : f.append(s[i]) elif s[i] in...
-1
315
A
Sereja and Bottles
PROGRAMMING
1,400
[ "brute force" ]
null
null
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
In a single line print a single integer — the answer to the problem.
[ "4\n1 1\n2 2\n3 3\n4 4\n", "4\n1 2\n2 3\n3 4\n4 1\n" ]
[ "4\n", "0\n" ]
none
500
[ { "input": "4\n1 1\n2 2\n3 3\n4 4", "output": "4" }, { "input": "4\n1 2\n2 3\n3 4\n4 1", "output": "0" }, { "input": "3\n2 828\n4 392\n4 903", "output": "3" }, { "input": "4\n2 3\n1 772\n3 870\n3 668", "output": "2" }, { "input": "5\n1 4\n6 6\n4 3\n3 4\n4 758", ...
1,656,899,450
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
2
404
3,174,400
import sys input = sys.stdin.readline n = int(input()) v = [0] * (n + 1) c = 0 for i in range(n): a, b = map(int, input().split()) if(a == b): if(not v[a]): c += 1 v[b] = 1 print(c)
Title: Sereja and Bottles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the *i*-th...
```python import sys input = sys.stdin.readline n = int(input()) v = [0] * (n + 1) c = 0 for i in range(n): a, b = map(int, input().split()) if(a == b): if(not v[a]): c += 1 v[b] = 1 print(c) ```
-1
357
B
Flag Day
PROGRAMMING
1,400
[ "constructive algorithms", "implementation" ]
null
null
In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions: - overall, there must be *m* dances;- exactly three people must take part in each dance;- each d...
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=105) and *m* (1<=≤<=*m*<=≤<=105) — the number of dancers and the number of dances, correspondingly. Then *m* lines follow, describing the dances in the order of dancing them. The *i*-th line contains three distinct integers — the numbers of the dan...
Print *n* space-separated integers: the *i*-th number must represent the color of the *i*-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists.
[ "7 3\n1 2 3\n1 4 5\n4 6 7\n", "9 3\n3 6 9\n2 5 8\n1 4 7\n", "5 2\n4 1 5\n3 1 2\n" ]
[ "1 2 3 3 2 2 1 \n", "1 1 1 2 2 2 3 3 3 \n", "2 3 1 1 3 \n" ]
none
1,000
[ { "input": "7 3\n1 2 3\n1 4 5\n4 6 7", "output": "1 2 3 3 2 2 1 " }, { "input": "9 3\n3 6 9\n2 5 8\n1 4 7", "output": "1 1 1 2 2 2 3 3 3 " }, { "input": "5 2\n4 1 5\n3 1 2", "output": "2 3 1 1 3 " }, { "input": "14 5\n1 5 3\n13 10 11\n6 3 8\n14 9 2\n7 4 12", "output": "1 ...
1,623,397,501
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
4
124
2,457,600
from sys import stdin,stdout stdin.readline def mp(): return list(map(int, stdin.readline().strip().split())) def it():return int(stdin.readline().strip()) from collections import defaultdict as dd,Counter as C,deque from math import ceil,gcd,sqrt,factorial,log2,floor from bisect import bisect_right as br,bis...
Title: Flag Day Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions: - ov...
```python from sys import stdin,stdout stdin.readline def mp(): return list(map(int, stdin.readline().strip().split())) def it():return int(stdin.readline().strip()) from collections import defaultdict as dd,Counter as C,deque from math import ceil,gcd,sqrt,factorial,log2,floor from bisect import bisect_right...
-1
309
E
Sheep
PROGRAMMING
2,900
[ "binary search", "greedy" ]
null
null
Information technologies are developing and are increasingly penetrating into all spheres of human activity. Incredible as it is, the most modern technology are used in farming! A large farm has a meadow with grazing sheep. Overall there are *n* sheep and each of them contains a unique number from 1 to *n* — because t...
The first input line contains one integer *n* (1<=≤<=*n*<=≤<=2000). Each of the following *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*,<=*r**i*<=≤<=109; *l**i*<=≤<=*r**i*).
In the single output line print *n* space-separated numbers — the sought arrangement of the sheep. The *i*-th value in the line must represent the number of the sheep that took the *i*-th place from left in the optimal arrangement line. If there are multiple optimal arrangements, print any of them.
[ "3\n1 3\n5 7\n2 4\n", "5\n1 5\n2 4\n3 6\n1 7\n2 6\n", "4\n1 3\n4 6\n5 7\n2 3\n" ]
[ "1 3 2", "2 1 3 5 4", "1 4 2 3" ]
none
2,500
[]
1,629,256,701
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
6,656,000
print("bulesheep")
Title: Sheep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Information technologies are developing and are increasingly penetrating into all spheres of human activity. Incredible as it is, the most modern technology are used in farming! A large farm has a meadow with grazing sheep. Over...
```python print("bulesheep") ```
0
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", ...
1,695,552,240
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
1,228,800
from fractions import Fraction y,w = list(map(int,input().split())) prop = Fraction(6 - (max(y,w) - 1), 6) print(prop)
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T...
```python from fractions import Fraction y,w = list(map(int,input().split())) prop = Fraction(6 - (max(y,w) - 1), 6) print(prop) ```
0
106
A
Card Game
PROGRAMMING
1,000
[ "implementation" ]
A. Card Game
2
256
There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want. To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", ...
The first line contains the tramp suit. It is "S", "H", "D" or "C". The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the...
Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes).
[ "H\nQH 9S\n", "S\n8D 6D\n", "C\n7H AS\n" ]
[ "YES\n", "YES", "NO" ]
none
500
[ { "input": "H\nQH 9S", "output": "YES" }, { "input": "S\n8D 6D", "output": "YES" }, { "input": "C\n7H AS", "output": "NO" }, { "input": "C\nKC 9C", "output": "YES" }, { "input": "D\n7D KD", "output": "NO" }, { "input": "H\n7H KD", "output": "YES" ...
1,527,703,245
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
156
7,065,600
# python 3 """ """ def card_game(trump_suit_str, first_str, second_str) -> str: rank = {"6": 0, "7": 1, "8": 2, "9": 3, "T": 4, "J": 5, "Q": 6, "K": 7, "A": 8} result = {True: "YES", False: "NO"} if first_str[1] == trump_suit_str: return "YES" elif first_str[1] == second_str[1]: retur...
Title: Card Game Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselve...
```python # python 3 """ """ def card_game(trump_suit_str, first_str, second_str) -> str: rank = {"6": 0, "7": 1, "8": 2, "9": 3, "T": 4, "J": 5, "Q": 6, "K": 7, "A": 8} result = {True: "YES", False: "NO"} if first_str[1] == trump_suit_str: return "YES" elif first_str[1] == second_str[1]: ...
0
977
B
Two-gram
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams. You are given a string $s$ consisting of $n$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters...
The first line of the input contains integer number $n$ ($2 \le n \le 100$) — the length of string $s$. The second line of the input contains the string $s$ consisting of $n$ capital Latin letters.
Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string $s$ as a substring (i.e. two consecutive characters of the string) maximal number of times.
[ "7\nABACABA\n", "5\nZZZAA\n" ]
[ "AB\n", "ZZ\n" ]
In the first example "BA" is also valid answer. In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times.
0
[ { "input": "7\nABACABA", "output": "AB" }, { "input": "5\nZZZAA", "output": "ZZ" }, { "input": "26\nQWERTYUIOPASDFGHJKLZXCVBNM", "output": "AS" }, { "input": "2\nQA", "output": "QA" }, { "input": "2\nWW", "output": "WW" }, { "input": "11\nGGRRAATTZZZ",...
1,698,951,705
705
Python 3
OK
TESTS
22
31
0
n = int(input()) s = input() d = {} for i in range(len(s)-1): ss = s[i]+s[i+1] if ss not in d.keys(): d[ss] = 0 d[ss] += 1 mx = 0 mx_ss = "" for k in d.keys(): if mx < d[k]: mx = d[k] mx_ss = k print(mx_ss)
Title: Two-gram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams. You are given a string $s$ consisting of $n$ capital Latin letters. Your task is to f...
```python n = int(input()) s = input() d = {} for i in range(len(s)-1): ss = s[i]+s[i+1] if ss not in d.keys(): d[ss] = 0 d[ss] += 1 mx = 0 mx_ss = "" for k in d.keys(): if mx < d[k]: mx = d[k] mx_ss = k print(mx_ss) ```
3
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,691,065,971
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
31
0
word=input() if(word==word.upper()): print(word[0]+word[1:].lower()) elif(word[0]==word[0].lower() and word[1:]==word[1:].upper()): print(word[0].upper()+word[1:].lower()) else: print(word)
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 word=input() if(word==word.upper()): print(word[0]+word[1:].lower()) elif(word[0]==word[0].lower() and word[1:]==word[1:].upper()): print(word[0].upper()+word[1:].lower()) else: print(word) ```
0
371
C
Hamburgers
PROGRAMMING
1,600
[ "binary search", "brute force" ]
null
null
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (...
The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers *n...
Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.
[ "BBBSSC\n6 4 1\n1 2 3\n4\n", "BBC\n1 10 1\n1 10 1\n21\n", "BSC\n1 1 1\n1 1 3\n1000000000000\n" ]
[ "2\n", "7\n", "200000000001\n" ]
none
1,500
[ { "input": "BBBSSC\n6 4 1\n1 2 3\n4", "output": "2" }, { "input": "BBC\n1 10 1\n1 10 1\n21", "output": "7" }, { "input": "BSC\n1 1 1\n1 1 3\n1000000000000", "output": "200000000001" }, { "input": "B\n1 1 1\n1 1 1\n381", "output": "382" }, { "input": "BSC\n3 5 6\n7...
1,653,050,724
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
def check(mid,p,n,b,s,c,m): cost = 0 cost+=max(0,b*mid-n[0])*p[0] cost+=max(0,s*mid-n[1])*p[1] cost+=max(0,c*mid-n[2])*p[2] return cost<=m st = input() n = list(map(int,input().split(" "))) p = list(map(int,input().split(" "))) m = int(input()) b = 0 c = 0 s = 0 for i in st: if i==...
Title: Hamburgers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He ...
```python def check(mid,p,n,b,s,c,m): cost = 0 cost+=max(0,b*mid-n[0])*p[0] cost+=max(0,s*mid-n[1])*p[1] cost+=max(0,c*mid-n[2])*p[2] return cost<=m st = input() n = list(map(int,input().split(" "))) p = list(map(int,input().split(" "))) m = int(input()) b = 0 c = 0 s = 0 for i in st: ...
0
27
E
Number With The Given Amount Of Divisors
PROGRAMMING
2,000
[ "brute force", "dp", "number theory" ]
E. Number With The Given Amount Of Divisors
2
256
Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000).
Output the smallest positive integer with exactly *n* divisors.
[ "4\n", "6\n" ]
[ "6\n", "12\n" ]
none
2,500
[ { "input": "1", "output": "1" }, { "input": "7", "output": "64" }, { "input": "8", "output": "24" }, { "input": "9", "output": "36" }, { "input": "10", "output": "48" }, { "input": "15", "output": "144" }, { "input": "20", "output": "24...
1,654,201,275
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
154
4,608,000
x=int(input()) # 素因数分解 import math L=int(math.sqrt(x)) FACT=dict() for i in range(2,L+2): while x%i==0: FACT[i]=FACT.get(i,0)+1 x=x//i if x!=1: FACT[x]=FACT.get(x,0)+1 x=10**5 import math L=math.floor(math.sqrt(x)) # 平方根を求める Primelist=[i for i in range(x+1)] Primel...
Title: Number With The Given Amount Of Divisors Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018. Input Specification: The first line...
```python x=int(input()) # 素因数分解 import math L=int(math.sqrt(x)) FACT=dict() for i in range(2,L+2): while x%i==0: FACT[i]=FACT.get(i,0)+1 x=x//i if x!=1: FACT[x]=FACT.get(x,0)+1 x=10**5 import math L=math.floor(math.sqrt(x)) # 平方根を求める Primelist=[i for i in range(x+1...
0
886
B
Vlad and Cafes
PROGRAMMING
1,000
[]
null
null
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes...
In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ...
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
[ "5\n1 3 2 1 2\n", "6\n2 1 2 2 4 1\n" ]
[ "3\n", "2\n" ]
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in...
1,000
[ { "input": "5\n1 3 2 1 2", "output": "3" }, { "input": "6\n2 1 2 2 4 1", "output": "2" }, { "input": "1\n0", "output": "0" }, { "input": "1\n200000", "output": "200000" }, { "input": "2\n2018 2017", "output": "2018" }, { "input": "5\n100 1000 1000 1000...
1,618,942,615
2,147,483,647
PyPy 3
OK
TESTS
33
249
20,377,600
n = int(input()) a = list(map(int, input().split())) myset = set() ans = a[-1] for x in a[::-1]: if x not in myset: ans = x myset.add(x) print(ans)
Title: Vlad and Cafes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research...
```python n = int(input()) a = list(map(int, input().split())) myset = set() ans = a[-1] for x in a[::-1]: if x not in myset: ans = x myset.add(x) print(ans) ```
3
764
A
Taymyr is calling you
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,...
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
[ "1 1 10\n", "1 2 5\n", "2 3 9\n" ]
[ "10\n", "2\n", "1\n" ]
Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
500
[ { "input": "1 1 10", "output": "10" }, { "input": "1 2 5", "output": "2" }, { "input": "2 3 9", "output": "1" }, { "input": "4 8 9", "output": "1" }, { "input": "7 9 2", "output": "0" }, { "input": "10000 10000 10000", "output": "1" }, { "i...
1,566,247,950
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
108
0
import math n, m, z = [int(s) for s in input().split()] ans = math.modf(z/m) print(ans[1])
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 import math n, m, z = [int(s) for s in input().split()] ans = math.modf(z/m) print(ans[1]) ```
0
339
A
Helpful Maths
PROGRAMMING
800
[ "greedy", "implementation", "sortings", "strings" ]
null
null
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe...
The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Print the new sum that Xenia can count.
[ "3+2+1\n", "1+1+3+1+3\n", "2\n" ]
[ "1+2+3\n", "1+1+1+3+3\n", "2\n" ]
none
500
[ { "input": "3+2+1", "output": "1+2+3" }, { "input": "1+1+3+1+3", "output": "1+1+1+3+3" }, { "input": "2", "output": "2" }, { "input": "2+2+1+1+3", "output": "1+1+2+2+3" }, { "input": "2+1+2+2+2+3+1+3+1+2", "output": "1+1+1+2+2+2+2+2+3+3" }, { "input": ...
1,699,775,931
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
s=list((input().split('+'))) s=[int(i) for i in s] ans="" s.sort() print(s) for i in range(len(s)): ans+=str(s[i]) ans+='+' print(ans[:-1])
Title: Helpful Maths Time Limit: None seconds Memory Limit: None megabytes Problem Description: Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak...
```python s=list((input().split('+'))) s=[int(i) for i in s] ans="" s.sort() print(s) for i in range(len(s)): ans+=str(s[i]) ans+='+' print(ans[:-1]) ```
0
702
A
Maximum Increase
PROGRAMMING
800
[ "dp", "greedy", "implementation" ]
null
null
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print the maximum length of an increasing subarray of the given array.
[ "5\n1 7 2 11 15\n", "6\n100 100 100 100 100 100\n", "3\n1 2 3\n" ]
[ "3\n", "1\n", "3\n" ]
none
0
[ { "input": "5\n1 7 2 11 15", "output": "3" }, { "input": "6\n100 100 100 100 100 100", "output": "1" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "1\n1000000000", "output": "1" }, { "input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7...
1,678,829,899
2,147,483,647
Python 3
OK
TESTS
32
93
7,884,800
n=int(input()) l=list(map(int,input().split())) m=1 out=1 for i in range(n-1): if l[i+1]>l[i]: m+=1 else: if m>out: m,out=out,m m=1 if m>out: m,out=out,m print(out)
Title: Maximum Increase Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called...
```python n=int(input()) l=list(map(int,input().split())) m=1 out=1 for i in range(n-1): if l[i+1]>l[i]: m+=1 else: if m>out: m,out=out,m m=1 if m>out: m,out=out,m print(out) ```
3
237
A
Free Cash
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is...
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
[ "4\n8 0\n8 10\n8 10\n8 45\n", "3\n0 12\n10 11\n22 22\n" ]
[ "2\n", "1\n" ]
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so ...
500
[ { "input": "4\n8 0\n8 10\n8 10\n8 45", "output": "2" }, { "input": "3\n0 12\n10 11\n22 22", "output": "1" }, { "input": "5\n12 8\n15 27\n15 27\n16 2\n19 52", "output": "2" }, { "input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "output": "3" }, { "input": "...
1,687,945,462
2,147,483,647
PyPy 3-64
OK
TESTS
67
1,808
12,492,800
d={} arr=[] sum=1 for _ in range(int(input())): h,m=map(int,input().split()) if h not in arr : arr.append(h) d[h]=[] d[h].append(m) else: d[h].append(m) # print(d) for i in arr: temp=d[i] # print(temp) temp1=set(temp) # print(temp1) for j in temp1: ...
Title: Free Cash Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l...
```python d={} arr=[] sum=1 for _ in range(int(input())): h,m=map(int,input().split()) if h not in arr : arr.append(h) d[h]=[] d[h].append(m) else: d[h].append(m) # print(d) for i in arr: temp=d[i] # print(temp) temp1=set(temp) # print(temp1) for j in temp...
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,603,642,829
2,147,483,647
Python 3
OK
TESTS
40
248
0
s = input("") n = input("") stxt = s[::-1] if stxt == n: 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 s = input("") n = input("") stxt = s[::-1] if stxt == n: print("YES") else: print("NO") ```
3.938
868
C
Qualification Rounds
PROGRAMMING
1,500
[ "bitmasks", "brute force", "constructive algorithms", "dp" ]
null
null
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of *n* problems, and they want to select any non-empty subset of it as a problemset. *k* experienced teams are participating in the contest. Some of these teams already know some of the prob...
The first line contains two integers *n*, *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=4) — the number of problems and the number of experienced teams. Each of the next *n* lines contains *k* integers, each equal to 0 or 1. The *j*-th number in the *i*-th line is 1 if *j*-th team knows *i*-th problem and 0 otherwise.
Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0\n", "3 2\n1 0\n1 1\n0 1\n" ]
[ "NO\n", "YES\n" ]
In the first example you can't make any interesting problemset, because the first team knows all problems. In the second example you can choose the first and the third problems.
1,000
[ { "input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO" }, { "input": "3 2\n1 0\n1 1\n0 1", "output": "YES" }, { "input": "10 2\n1 0\n1 0\n0 0\n1 1\n0 0\n1 1\n0 0\n1 1\n0 1\n0 1", "output": "YES" }, { "input": "10 3\n1 0 0\n0 1 1\n1 0 0\n0 1 0\n0 0 1\n1 0 1\n0 1 1...
1,626,184,611
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
28,774,400
n, k = map(int, input().split()) temp = [] for i in range(n): temp += [input()] f = 0 for i in temp: for j in temp: a, b = list(map(int, i.split())), list(map(int, j.split())) c = sum(a[l] + b[l] != 2 for l in range(k)) if c == k: f = 1 if f: print("YES") ...
Title: Qualification Rounds Time Limit: None seconds Memory Limit: None megabytes Problem Description: Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of *n* problems, and they want to select any non-empty subset of it as a problemset. ...
```python n, k = map(int, input().split()) temp = [] for i in range(n): temp += [input()] f = 0 for i in temp: for j in temp: a, b = list(map(int, i.split())), list(map(int, j.split())) c = sum(a[l] + b[l] != 2 for l in range(k)) if c == k: f = 1 if f: pri...
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,671,549,592
2,147,483,647
PyPy 3
OK
TESTS
32
154
0
n = int(input()) arr = [int(i) % 2 for i in input().split()] s = sum(arr) if (s == 1): for i in range(len(arr)): if (arr[i] == 1): print(i+1) break else: for i in range(len(arr)): if (arr[i] == 0): print(i+1) break
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()) arr = [int(i) % 2 for i in input().split()] s = sum(arr) if (s == 1): for i in range(len(arr)): if (arr[i] == 1): print(i+1) break else: for i in range(len(arr)): if (arr[i] == 0): print(i+1) break ```
3.9615