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
26
A
Almost Prime
PROGRAMMING
900
[ "number theory" ]
A. Almost Prime
2
256
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive.
Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000).
Output the amount of almost prime numbers between 1 and *n*, inclusive.
[ "10\n", "21\n" ]
[ "2\n", "8\n" ]
none
500
[ { "input": "10", "output": "2" }, { "input": "21", "output": "8" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "4", "output": "0" }, { "input": "3", "output": "0" }, { "input": "8", "output": "1" }, ...
1,680,276,774
2,147,483,647
PyPy 3-64
OK
TESTS
23
184
2,560,000
from collections import defaultdict from collections import Counter n = int(input()) ans = 0 for num in range(6 , n + 1): d = 2 count = set() while d * d <= num: while num%d==0: count.add(d) num/= d d += 1 if num > 1: cou...
Title: Almost Prime Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in...
```python from collections import defaultdict from collections import Counter n = int(input()) ans = 0 for num in range(6 , n + 1): d = 2 count = set() while d * d <= num: while num%d==0: count.add(d) num/= d d += 1 if num > 1: ...
3.949232
295
E
Yaroslav and Points
PROGRAMMING
2,500
[ "data structures" ]
null
null
Yaroslav has *n* points that lie on the *Ox* axis. The coordinate of the first point is *x*1, the coordinate of the second point is *x*2, ..., the coordinate of the *n*-th point is — *x**n*. Now Yaroslav wants to execute *m* queries, each of them is of one of the two following types: 1. Move the *p**j*-th point from ...
The first line contains integer *n* — the number of points (1<=≤<=*n*<=≤<=105). The second line contains distinct integers *x*1,<=*x*2,<=...,<=*x**n* — the coordinates of points (|*x**i*|<=≤<=109). The third line contains integer *m* — the number of queries (1<=≤<=*m*<=≤<=105). The next *m* lines contain the queries. ...
For each type 2 query print the answer on a single line. Print the answers in the order, in which the queries follow in the input. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
[ "8\n36 50 28 -75 40 -60 -95 -48\n20\n2 -61 29\n1 5 -53\n1 1 429\n1 5 130\n2 -101 -71\n2 -69 53\n1 1 404\n1 5 518\n2 -101 53\n2 50 872\n1 1 -207\n2 -99 -40\n1 7 -389\n1 6 -171\n1 2 464\n1 7 -707\n1 1 -730\n1 1 560\n2 635 644\n1 7 -677\n" ]
[ "176\n20\n406\n1046\n1638\n156\n0\n" ]
none
2,500
[]
1,689,346,309
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
print("_RANDOM_GUESS_1689346309.399466")# 1689346309.39948
Title: Yaroslav and Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yaroslav has *n* points that lie on the *Ox* axis. The coordinate of the first point is *x*1, the coordinate of the second point is *x*2, ..., the coordinate of the *n*-th point is — *x**n*. Now Yaroslav wants to ex...
```python print("_RANDOM_GUESS_1689346309.399466")# 1689346309.39948 ```
0
456
B
Fedya and Maths
PROGRAMMING
1,200
[ "math", "number theory" ]
null
null
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression: for given value of *n*. Fedya managed to complete the task. Can you? Note that given number *n* can be extremely large (e.g. it can exceed any integer type of your programming language).
The single line contains a single integer *n* (0<=≤<=*n*<=≤<=10105). The number doesn't contain any leading zeroes.
Print the value of the expression without leading zeros.
[ "4\n", "124356983594583453458888889\n" ]
[ "4\n", "0\n" ]
Operation *x* *mod* *y* means taking remainder after division *x* by *y*. Note to the first sample: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/825f244180bb10323db01645118c3cfdb312fa89.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "4", "output": "4" }, { "input": "124356983594583453458888889", "output": "0" }, { "input": "2", "output": "0" }, { "input": "7854", "output": "0" }, { "input": "584660", "output": "4" }, { "input": "464", "output": "4" }, { "inp...
1,672,232,796
2,147,483,647
Python 3
OK
TESTS
47
234
0
n = int(input("")) if n%4 == 0: print("4") elif n%4 == 1: print("0") elif n%4 == 2: print("0") else: print("0")
Title: Fedya and Maths Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression: for given value of *n*. Fedya managed to complete the task. Can you? Note that given number *n* can be extremely large (e.g...
```python n = int(input("")) if n%4 == 0: print("4") elif n%4 == 1: print("0") elif n%4 == 2: print("0") else: print("0") ```
3
575
H
Bots
PROGRAMMING
1,800
[ "combinatorics", "dp", "math", "number theory" ]
null
null
Sasha and Ira are two best friends. But they aren’t just friends, they are software engineers and experts in artificial intelligence. They are developing an algorithm for two bots playing a two-player game. The game is cooperative and turn based. In each turn, one of the players makes a move (it doesn’t matter which pl...
The first and only line contains integer N. - 1<=≤<=*N*<=≤<=106
Output should contain a single integer – number of possible states modulo 109<=+<=7.
[ "2\n" ]
[ "19\n" ]
Start: Game is in state A. - Turn 1: Either bot can make a move (first bot is red and second bot is blue), so there are two possible states after the first turn – B and C. - Turn 2: In both states B and C, either bot can again make a turn, so the list of possible states is expanded to include D, E, F and G. - Turn...
0
[ { "input": "2", "output": "19" }, { "input": "1", "output": "5" }, { "input": "3", "output": "69" }, { "input": "4", "output": "251" }, { "input": "5", "output": "923" }, { "input": "6", "output": "3431" }, { "input": "7", "output": "12...
1,441,538,776
12,376
Python 3
TIME_LIMIT_EXCEEDED
TESTS
13
1,500
307,200
n = int(input()) n = n*2 + 2 ans = 1 j = 2 for i in range(int(n/2+1),n+1): ans = ans * i if ans % j == 0: if j <= n//2: ans = ans // j j+=1 for i in range(j,int(n/2+1)): ans = ans // i ans = ans % 1000000007 ans -= 1 if ans < 0: ans = ans + 1000000007...
Title: Bots Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sasha and Ira are two best friends. But they aren’t just friends, they are software engineers and experts in artificial intelligence. They are developing an algorithm for two bots playing a two-player game. The game is cooperative...
```python n = int(input()) n = n*2 + 2 ans = 1 j = 2 for i in range(int(n/2+1),n+1): ans = ans * i if ans % j == 0: if j <= n//2: ans = ans // j j+=1 for i in range(j,int(n/2+1)): ans = ans // i ans = ans % 1000000007 ans -= 1 if ans < 0: ans = ans + ...
0
602
B
Approximating a Constant Range
PROGRAMMING
1,400
[ "dp", "implementation", "two pointers" ]
null
null
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their aver...
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000).
Print a single number — the maximum length of an almost constant range of the given sequence.
[ "5\n1 2 3 3 2\n", "11\n5 4 5 5 6 7 8 8 8 7 6\n" ]
[ "4\n", "5\n" ]
In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4. In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].
1,000
[ { "input": "5\n1 2 3 3 2", "output": "4" }, { "input": "11\n5 4 5 5 6 7 8 8 8 7 6", "output": "5" }, { "input": "2\n3 2", "output": "2" }, { "input": "4\n1001 1000 1000 1001", "output": "4" }, { "input": "4\n1 1 2 3", "output": "3" }, { "input": "3\n1 ...
1,691,863,977
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n = int(input()) data = list(map(int, input().split())) max_almost_constant_length = 0 left = 0 max_diff = 0 for right in range(1, n): max_diff = max(max_diff, abs(data[right] - data[right - 1])) if max_diff <= 1: max_almost_constant_length = max(max_almost_constant_length, right - left + 1) ...
Title: Approximating a Constant Range Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choo...
```python n = int(input()) data = list(map(int, input().split())) max_almost_constant_length = 0 left = 0 max_diff = 0 for right in range(1, n): max_diff = max(max_diff, abs(data[right] - data[right - 1])) if max_diff <= 1: max_almost_constant_length = max(max_almost_constant_length, right - left...
0
0
none
none
none
0
[ "none" ]
null
null
Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] is not. A permutation triple of permutations of length *n* (*a*,<=...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105).
If no Lucky Permutation Triple of length *n* exists print -1. Otherwise, you need to print three lines. Each line contains *n* space-seperated integers. The first line must contain permutation *a*, the second line — permutation *b*, the third — permutation *c*. If there are multiple solutions, print any of them.
[ "5\n", "2\n" ]
[ "1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3\n", "-1\n" ]
In Sample 1, the permutation triple ([1, 4, 3, 2, 0], [1, 0, 2, 4, 3], [2, 4, 0, 1, 3]) is Lucky Permutation Triple, as following holds: - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a6bf1b9b57809dbec5021f65f89616f259587c07.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img...
0
[ { "input": "5", "output": "1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3" }, { "input": "2", "output": "-1" }, { "input": "8", "output": "-1" }, { "input": "9", "output": "0 1 2 3 4 5 6 7 8 \n0 1 2 3 4 5 6 7 8 \n0 2 4 6 8 1 3 5 7 " }, { "input": "2", "output": "-1" }, {...
1,369,474,024
2,147,483,647
Python 3
OK
TESTS
54
1,828
102,400
n = int(input()) if n % 2 == 0: print (-1) else: for i in range (0, n): if i == n - 1: print (i) else: print (i, end = ' ') for i in range (0, n): if i == n - 1: print (i) else: print (i, end = ' ') for i in ra...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of length 3 while both [0,<=...
```python n = int(input()) if n % 2 == 0: print (-1) else: for i in range (0, n): if i == n - 1: print (i) else: print (i, end = ' ') for i in range (0, n): if i == n - 1: print (i) else: print (i, end = ' ') f...
3
334
A
Candy Bags
PROGRAMMING
1,000
[ "implementation" ]
null
null
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies. Help him give *n* bags of candies to each b...
The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers.
Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ...
[ "2\n" ]
[ "1 4\n2 3\n" ]
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
500
[ { "input": "2", "output": "1 4\n2 3" }, { "input": "4", "output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9" }, { "input": "6", "output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19" }, { "input": "8", "output"...
1,426,415,626
2,147,483,647
Python 3
OK
TESTS
21
154
204,800
# coding: utf-8 n = int(input()) for i in range(n): for j in range(n//2): print(i*(n//2)+j+1,1+n*n-i*(n//2)-j-1,end=' ') print('')
Title: Candy Bags Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ...
```python # coding: utf-8 n = int(input()) for i in range(n): for j in range(n//2): print(i*(n//2)+j+1,1+n*n-i*(n//2)-j-1,end=' ') print('') ```
3
449
B
Jzzhu and Cities
PROGRAMMING
2,000
[ "graphs", "greedy", "shortest paths" ]
null
null
Jzzhu is the president of country A. There are *n* cities numbered from 1 to *n* in his country. City 1 is the capital of A. Also there are *m* roads connecting the cities. One can go from city *u**i* to *v**i* (and vise versa) using the *i*-th road, the length of this road is *x**i*. Finally, there are *k* train route...
The first line contains three integers *n*,<=*m*,<=*k* (2<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=3·105; 1<=≤<=*k*<=≤<=105). Each of the next *m* lines contains three integers *u**i*,<=*v**i*,<=*x**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*; 1<=≤<=*x**i*<=≤<=109). Each of the next *k* lines contains two integers *s*...
Output a single integer representing the maximum number of the train routes which can be closed.
[ "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5\n", "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3\n" ]
[ "2\n", "2\n" ]
none
1,000
[ { "input": "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5", "output": "2" }, { "input": "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3", "output": "2" }, { "input": "5 4 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\n5 1 524524524\n5 524444444\n5 529999999\n2 1000000000", "output": ...
1,696,494,041
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
1,403
89,395,200
import sys, threading sys.setrecursionlimit(1 << 30) threading.stack_size(1 << 27) from collections import defaultdict, deque, Counter from functools import lru_cache from heapq import heappush, heappop from bisect import bisect_right, bisect_left def inpNum(): return int(input()) def inpStr(): ...
Title: Jzzhu and Cities Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jzzhu is the president of country A. There are *n* cities numbered from 1 to *n* in his country. City 1 is the capital of A. Also there are *m* roads connecting the cities. One can go from city *u**i* to *v**i* (and vi...
```python import sys, threading sys.setrecursionlimit(1 << 30) threading.stack_size(1 << 27) from collections import defaultdict, deque, Counter from functools import lru_cache from heapq import heappush, heappop from bisect import bisect_right, bisect_left def inpNum(): return int(input()) def i...
0
0
none
none
none
0
[ "none" ]
null
null
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two ...
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100) — the initial number of elements in the set. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the set.
Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).
[ "2\n2 3\n", "2\n5 3\n", "3\n5 6 7\n" ]
[ "Alice\n", "Alice\n", "Bob\n" ]
Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice.
0
[ { "input": "2\n2 3", "output": "Alice" }, { "input": "2\n5 3", "output": "Alice" }, { "input": "3\n5 6 7", "output": "Bob" }, { "input": "10\n72 96 24 66 6 18 12 30 60 48", "output": "Bob" }, { "input": "10\n78 66 6 60 18 84 36 96 72 48", "output": "Bob" }, ...
1,584,214,872
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
14
280
0
n, a = int(input()), sorted(map(int, input().split())) print('Alice' if (a[-1] - n) % 2 else 'Bob')
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. Du...
```python n, a = int(input()), sorted(map(int, input().split())) print('Alice' if (a[-1] - n) % 2 else 'Bob') ```
0
1,005
B
Delete from the Left
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is ...
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
[ "test\nwest\n", "codeforces\nyes\n", "test\nyes\n", "b\nab\n" ]
[ "2\n", "9\n", "7\n", "1\n" ]
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m...
0
[ { "input": "test\nwest", "output": "2" }, { "input": "codeforces\nyes", "output": "9" }, { "input": "test\nyes", "output": "7" }, { "input": "b\nab", "output": "1" }, { "input": "z\nz", "output": "0" }, { "input": "abacabadabacaba\nabacabadacaba", ...
1,633,210,853
2,147,483,647
Python 3
OK
TESTS
28
109
7,782,400
a = input() b = input() a = a[::-1] b = b[::-1] c = 0 for i in range(min(len(a),len(b))): if a[i] == b[i]: c += 1 elif c == 0: print(len(a) + len(b)) break else: break if c != 0: print(len(a) + len(b) - 2*c) # Sun Oct 03 2021 00:40:53 GMT+0300 (Москва, станд...
Title: Delete from the Left Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ...
```python a = input() b = input() a = a[::-1] b = b[::-1] c = 0 for i in range(min(len(a),len(b))): if a[i] == b[i]: c += 1 elif c == 0: print(len(a) + len(b)) break else: break if c != 0: print(len(a) + len(b) - 2*c) # Sun Oct 03 2021 00:40:53 GMT+0300 (Мос...
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", ...
1,584,713,454
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
186
0
import sys import math #to read string get_string = lambda: sys.stdin.readline().strip() #to read list of integers get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) ) #to read integers get_int = lambda: int(sys.stdin.readline()) #to print fast pt = lambda x: sys.stdout.write(str(x)+'...
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 import sys import math #to read string get_string = lambda: sys.stdin.readline().strip() #to read list of integers get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) ) #to read integers get_int = lambda: int(sys.stdin.readline()) #to print fast pt = lambda x: sys.stdout.writ...
0
448
A
Rewards
PROGRAMMING
800
[ "implementation" ]
null
null
Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize c...
The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100). The numbers in the lines are separated by single spaces.
Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).
[ "1 1 1\n1 1 1\n4\n", "1 1 3\n2 3 4\n2\n", "1 0 0\n1 0 0\n1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "1 1 1\n1 1 1\n4", "output": "YES" }, { "input": "1 1 3\n2 3 4\n2", "output": "YES" }, { "input": "1 0 0\n1 0 0\n1", "output": "NO" }, { "input": "0 0 0\n0 0 0\n1", "output": "YES" }, { "input": "100 100 100\n100 100 100\n100", "output": "YES" }, ...
1,689,269,397
2,147,483,647
PyPy 3-64
OK
TESTS
25
62
0
n = sum(list(map(int ,input().split()))) x = n // 5 if n % 5 > 0 : x += 1 m = sum(list(map(int ,input().split()))) t = m // 10 if m % 10 > 0: t += 1 k = int(input()) if k - x < t : print("NO") else: print("YES")
Title: Rewards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into ...
```python n = sum(list(map(int ,input().split()))) x = n // 5 if n % 5 > 0 : x += 1 m = sum(list(map(int ,input().split()))) t = m // 10 if m % 10 > 0: t += 1 k = int(input()) if k - x < t : print("NO") else: print("YES") ```
3
976
A
Minimum Binary Number
PROGRAMMING
800
[ "implementation" ]
null
null
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"...
The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
Print one string — the minimum correct string that you can obtain from the given one.
[ "4\n1001\n", "1\n1\n" ]
[ "100\n", "1\n" ]
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht...
0
[ { "input": "4\n1001", "output": "100" }, { "input": "1\n1", "output": "1" }, { "input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100", "output": "1000000000000000000000000000000000000000" }, { "input": "100\n100000...
1,629,126,940
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
108
20,172,800
n = int(input()) s = input() ans = [] count = 0 for i in range(len(s)): if s[i] == '1' and count == 0: ans.append(s[i]) count += 1 if count > 0 and s[i] == '0': ans.append(s[i]) print(''.join(ans))
Title: Minimum Binary Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two...
```python n = int(input()) s = input() ans = [] count = 0 for i in range(len(s)): if s[i] == '1' and count == 0: ans.append(s[i]) count += 1 if count > 0 and s[i] == '0': ans.append(s[i]) print(''.join(ans)) ```
0
166
E
Tetrahedron
PROGRAMMING
1,500
[ "dp", "math", "matrices" ]
null
null
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ...
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
[ "2\n", "4\n" ]
[ "3\n", "21\n" ]
The required paths in the first sample are: - *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D*
1,000
[ { "input": "2", "output": "3" }, { "input": "4", "output": "21" }, { "input": "1", "output": "0" }, { "input": "3", "output": "6" }, { "input": "5", "output": "60" }, { "input": "6", "output": "183" }, { "input": "7", "output": "546" ...
1,606,510,529
2,147,483,647
PyPy 3
OK
TESTS
36
1,808
1,638,400
n=int(input()) mod=1000000007 mul=1 ans=0 if n%2!=0: mul=-mul s=3 for i in range(1,n): ans=(ans+s*mul)%mod s=(s*3)%mod # print(ans) mul=-mul print(ans%mod)
Title: Tetrahedron Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each m...
```python n=int(input()) mod=1000000007 mul=1 ans=0 if n%2!=0: mul=-mul s=3 for i in range(1,n): ans=(ans+s*mul)%mod s=(s*3)%mod # print(ans) mul=-mul print(ans%mod) ```
3
279
B
Books
PROGRAMMING
1,400
[ "binary search", "brute force", "implementation", "two pointers" ]
null
null
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to...
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n...
Print a single integer — the maximum number of books Valera can read.
[ "4 5\n3 1 2 1\n", "3 3\n2 2 3\n" ]
[ "3\n", "1\n" ]
none
1,000
[ { "input": "4 5\n3 1 2 1", "output": "3" }, { "input": "3 3\n2 2 3", "output": "1" }, { "input": "1 3\n5", "output": "0" }, { "input": "1 10\n4", "output": "1" }, { "input": "2 10\n6 4", "output": "2" }, { "input": "6 10\n2 3 4 2 1 1", "output": "4...
1,694,658,878
2,147,483,647
Python 3
OK
TESTS
38
218
13,721,600
def maxbook(n, time, data): start = 0 end = 0 sumtime = data[0] maxnum = 0 while end < n: if sumtime <= time: maxnum = max(maxnum, end - start + 1) end += 1 if end < n: # 防止数组越界 sumtime += data[end] else: su...
Title: Books Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t...
```python def maxbook(n, time, data): start = 0 end = 0 sumtime = data[0] maxnum = 0 while end < n: if sumtime <= time: maxnum = max(maxnum, end - start + 1) end += 1 if end < n: # 防止数组越界 sumtime += data[end] else: ...
3
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,634,480,615
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
#731A n=int(input()) s=input() a=0 b=0 for x in s: if(x=='A'): a=a+1 else: b=b+1 if(a>b): print("Anton") elif(b>a): print("Danik") else: print("Friendship")
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 #731A n=int(input()) s=input() a=0 b=0 for x in s: if(x=='A'): a=a+1 else: b=b+1 if(a>b): print("Anton") elif(b>a): print("Danik") else: print("Friendship") ```
-1
572
A
Arrays
PROGRAMMING
900
[ "sortings" ]
null
null
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly. The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space. The third line contains *n**A* numbers *...
Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes).
[ "3 3\n2 1\n1 2 3\n3 4 5\n", "3 3\n3 3\n1 2 3\n3 4 5\n", "5 2\n3 1\n1 1 1 1 1\n2 2\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 &lt; 3 and 2 &lt; 3). In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the num...
500
[ { "input": "3 3\n2 1\n1 2 3\n3 4 5", "output": "YES" }, { "input": "3 3\n3 3\n1 2 3\n3 4 5", "output": "NO" }, { "input": "5 2\n3 1\n1 1 1 1 1\n2 2", "output": "YES" }, { "input": "3 5\n1 1\n5 5 5\n5 5 5 5 5", "output": "NO" }, { "input": "1 1\n1 1\n1\n1", "ou...
1,529,060,685
2,147,483,647
Python 3
OK
TESTS
52
140
10,547,200
str1 = list(map(int,input().split())) na = str1[0] nb = str1[1] str2 = list(map(int,input().split())) k = str2[0] m = str2[1] a = list(map(int,input().split())) b = list(map(int,input().split())) if a[k-1] < b[nb-m]: print ('YES') else: print ('NO')
Title: Arrays Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the fi...
```python str1 = list(map(int,input().split())) na = str1[0] nb = str1[1] str2 = list(map(int,input().split())) k = str2[0] m = str2[1] a = list(map(int,input().split())) b = list(map(int,input().split())) if a[k-1] < b[nb-m]: print ('YES') else: print ('NO') ```
3
629
B
Far Relative’s Problem
PROGRAMMING
1,100
[ "brute force" ]
null
null
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — then number of Famil Door's friends. Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i...
Print the maximum number of people that may come to Famil Door's party.
[ "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n", "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n" ]
[ "2\n", "4\n" ]
In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
1,000
[ { "input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128", "output": "2" }, { "input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200", "output": "4" }, { "input": "1\nF 68 307", "output": "0" }, { "input": "40\nM 55 363\nF 117 252\nM 157 282\nF 322 345\...
1,696,682,759
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
326
7,577,600
n=int(input()) r=[] a=[] b=[] for i in range(n): x,y,z=[x for x in input().split()] if x=="F": r.append(0) else: r.append(1) a.append(int(y)) b.append(int(z)) v=[] for j in range(n): q=1 for k in range(n): if k!=j: if r[j]==0: ...
Title: Far Relative’s Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, F...
```python n=int(input()) r=[] a=[] b=[] for i in range(n): x,y,z=[x for x in input().split()] if x=="F": r.append(0) else: r.append(1) a.append(int(y)) b.append(int(z)) v=[] for j in range(n): q=1 for k in range(n): if k!=j: if r[j]...
0
863
A
Quasi-palindrome
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String *t* is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to str...
The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes.
Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes).
[ "131\n", "320\n", "2010200\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
0
[ { "input": "131", "output": "YES" }, { "input": "320", "output": "NO" }, { "input": "2010200", "output": "YES" }, { "input": "1", "output": "YES" }, { "input": "1000000000", "output": "YES" }, { "input": "999999999", "output": "YES" }, { "i...
1,643,139,870
2,147,483,647
Python 3
OK
TESTS
44
46
0
n = [i for i in input()] n.reverse() s = [] for i in range(len(n)): if n[i] == "0": continue else: for j in n[i:]: s.append(j) break if s == s[::-1]: print("YES") else: print("NO")
Title: Quasi-palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String *t* is called a palindrome, if it reads the same from left to right and from righ...
```python n = [i for i in input()] n.reverse() s = [] for i in range(len(n)): if n[i] == "0": continue else: for j in n[i:]: s.append(j) break if s == s[::-1]: print("YES") else: print("NO") ```
3
876
B
Divisiblity of Differences
PROGRAMMING
1,300
[ "implementation", "math", "number theory" ]
null
null
You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number...
First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=...
If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them...
[ "3 2 3\n1 8 4\n", "3 3 3\n1 8 4\n", "4 3 5\n2 7 7 7\n" ]
[ "Yes\n1 4 ", "No", "Yes\n2 7 7 " ]
none
1,000
[ { "input": "3 2 3\n1 8 4", "output": "Yes\n1 4 " }, { "input": "3 3 3\n1 8 4", "output": "No" }, { "input": "4 3 5\n2 7 7 7", "output": "Yes\n2 7 7 " }, { "input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825", "output":...
1,586,168,231
2,147,483,647
PyPy 3
OK
TESTS
63
358
19,251,200
def main(): n,k,m = map(int,input().split()) a = list(map(int,input().split())) b = {} for i in range(m): b[i] = [[],0] index = -1 for i in a: b[i%m][0].append(i) b[i%m][1] += 1 if b[i%m][1] >= k: index = i%m break if index == -1: ...
Title: Divisiblity of Differences Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible. Numbers can be re...
```python def main(): n,k,m = map(int,input().split()) a = list(map(int,input().split())) b = {} for i in range(m): b[i] = [[],0] index = -1 for i in a: b[i%m][0].append(i) b[i%m][1] += 1 if b[i%m][1] >= k: index = i%m break if index =...
3
784
F
Crunching Numbers Just for You
PROGRAMMING
1,900
[ "*special", "implementation" ]
null
null
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order.
The input consists of a single line of space-separated integers. The first number is *n* (1<=≤<=*n*<=≤<=10) — the size of the array. The following *n* numbers are the elements of the array (1<=≤<=*a**i*<=≤<=100).
Output space-separated elements of the sorted array.
[ "3 3 1 2\n" ]
[ "1 2 3 \n" ]
Remember, this is a very important feature, and you have to make sure the customers appreciate it!
0
[ { "input": "3 3 1 2", "output": "1 2 3 " }, { "input": "10 54 100 27 1 33 27 80 49 27 6", "output": "1 6 27 27 27 33 49 54 80 100 " } ]
1,555,494,606
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
93
0
n = set(map(int, input().split())) for i in n: print(i, end=' ')
Title: Crunching Numbers Just for You Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done....
```python n = set(map(int, input().split())) for i in n: print(i, end=' ') ```
0
1,003
C
Intense Heat
PROGRAMMING
1,300
[ "brute force", "implementation", "math" ]
null
null
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually cal...
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 5000$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 5000$) — the ...
Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $k$ consecutive days. Your answer will be considered correct if the following condition holds: $|res - res_0| &lt; 10^{-6}$, where $res$ is your answer, and $res_0$ is the answer given by the...
[ "4 3\n3 4 1 2\n" ]
[ "2.666666666666667\n" ]
none
0
[ { "input": "4 3\n3 4 1 2", "output": "2.666666666666667" }, { "input": "5 1\n3 10 9 10 6", "output": "10.000000000000000" }, { "input": "5 2\n7 3 3 1 8", "output": "5.000000000000000" }, { "input": "5 3\n1 7 6 9 1", "output": "7.333333333333333" }, { "input": "5 4...
1,692,268,872
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
a,b=map(int,input().split(" ")) ls=list(map(int,input().split(" "))) maxx=0 for x in range(a): summ=0 for y in range(b): summ+=ls[y] # print(ls[y]) if (maxx<summ): maxx=summ print(f"{maxx/b:.15f}")
Title: Intense Heat Time Limit: None seconds Memory Limit: None megabytes Problem Description: The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sou...
```python a,b=map(int,input().split(" ")) ls=list(map(int,input().split(" "))) maxx=0 for x in range(a): summ=0 for y in range(b): summ+=ls[y] # print(ls[y]) if (maxx<summ): maxx=summ print(f"{maxx/b:.15f}") ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the...
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3"...
1,660,798,366
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
#1A x,y,z=[int(i) for i in input().split()] s=0 i=0 if x<=z and y<=z: print(1) elif x<=z and y>z: while s<y: s+=z i+=1 print(i) elif y<=z and x>z: while s<x: s+=z i+=1 print(i) else: while s<y: s+=z i+=1 s=0 while s<x: ...
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ...
```python #1A x,y,z=[int(i) for i in input().split()] s=0 i=0 if x<=z and y<=z: print(1) elif x<=z and y>z: while s<y: s+=z i+=1 print(i) elif y<=z and x>z: while s<x: s+=z i+=1 print(i) else: while s<y: s+=z i+=1 s=0 w...
-1
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,626,257,638
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
10
109
21,606,400
n=int(input()) ar=list(map(int,input().split())) ammu=[ ] for i in range (0,n): for j in range (0,n): k=ar[i]-ar[j] if(i!=j): ammu.append(abs(k)) if(min(ammu)!=0): print(min(ammu)*n) else: print(ar[0]*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 n=int(input()) ar=list(map(int,input().split())) ammu=[ ] for i in range (0,n): for j in range (0,n): k=ar[i]-ar[j] if(i!=j): ammu.append(abs(k)) if(min(ammu)!=0): print(min(ammu)*n) else: print(ar[0]*n) ```
0
445
A
DZY Loves Chessboard
PROGRAMMING
1,200
[ "dfs and similar", "implementation" ]
null
null
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th...
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ...
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It ...
[ "1 1\n.\n", "2 2\n..\n..\n", "3 3\n.-.\n---\n--." ]
[ "B\n", "BW\nWB\n", "B-B\n---\n--B" ]
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK. In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output. In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
500
[ { "input": "1 1\n.", "output": "B" }, { "input": "2 2\n..\n..", "output": "BW\nWB" }, { "input": "3 3\n.-.\n---\n--.", "output": "B-B\n---\n--B" }, { "input": "3 1\n-\n.\n.", "output": "-\nW\nB" }, { "input": "11 11\n-----------\n-----------\n-----------\n--------...
1,626,245,644
2,147,483,647
PyPy 3
OK
TESTS
37
109
22,425,600
n, m = map(int, input().split()) for i in range(n): s = list(input()) for j in range(m): if (s[j] == '.'): s[j] = 'B' if ((i + j) % 2 == 0) else 'W' print(''.join(s))
Title: DZY Loves Chessboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ...
```python n, m = map(int, input().split()) for i in range(n): s = list(input()) for j in range(m): if (s[j] == '.'): s[j] = 'B' if ((i + j) % 2 == 0) else 'W' print(''.join(s)) ```
3
0
none
none
none
0
[ "none" ]
null
null
You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible inte...
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to. The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109).
Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments.
[ "5 2\n1 2 3 4 5\n", "5 1\n-4 -5 -3 -2 -1\n" ]
[ "5\n", "-5\n" ]
A subsegment [*l*,  *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>,  *a*<sub class="lower-index">*l* + 1</sub>,  ...,  *a*<sub class="lower-index">*r*</sub>. Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index...
0
[ { "input": "5 2\n1 2 3 4 5", "output": "5" }, { "input": "5 1\n-4 -5 -3 -2 -1", "output": "-5" }, { "input": "10 2\n10 9 1 -9 -7 -9 3 8 -10 5", "output": "10" }, { "input": "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9", "output": "9" }, { "input": "1 1\n504262064", "output...
1,603,569,111
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
from sys import stdin,stdout from collections import * st=lambda:list(stdin.readline().strip()) li=lambda:list(map(int,stdin.readline().split())) mp=lambda:map(int,stdin.readline().split()) inp=lambda:int(stdin.readline()) pr=lambda n: stdout.write(str(n)+"\n") mod=1000000007 INF=float('inf') def solve...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and ...
```python from sys import stdin,stdout from collections import * st=lambda:list(stdin.readline().strip()) li=lambda:list(map(int,stdin.readline().split())) mp=lambda:map(int,stdin.readline().split()) inp=lambda:int(stdin.readline()) pr=lambda n: stdout.write(str(n)+"\n") mod=1000000007 INF=float('inf') ...
-1
527
C
Glass Carving
PROGRAMMING
1,500
[ "binary search", "data structures", "implementation" ]
null
null
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how. In order not to waste time, he decided to prac...
The first line contains three integers *w*,<=*h*,<=*n* (2<=≤<=*w*,<=*h*<=≤<=200<=000, 1<=≤<=*n*<=≤<=200<=000). Next *n* lines contain the descriptions of the cuts. Each description has the form *H* *y* or *V* *x*. In the first case Leonid makes the horizontal cut at the distance *y* millimeters (1<=≤<=*y*<=≤<=*h*<=-<=...
After each cut print on a single line the area of the maximum available glass fragment in mm2.
[ "4 3 4\nH 2\nV 2\nV 3\nV 1\n", "7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1\n" ]
[ "8\n4\n4\n2\n", "28\n16\n12\n6\n4\n" ]
Picture for the first sample test:
1,500
[ { "input": "4 3 4\nH 2\nV 2\nV 3\nV 1", "output": "8\n4\n4\n2" }, { "input": "7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1", "output": "28\n16\n12\n6\n4" }, { "input": "2 2 1\nV 1", "output": "2" }, { "input": "2 2 1\nH 1", "output": "2" }, { "input": "2 2 2\nV 1\nH 1", "ou...
1,598,615,492
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
124
0
w,h,n=map(int,input().split()) l=[-1]*(w+1) r=[-1]*(w+1) t=[-1]*(h+1) b=[-1]*(h+1) l[0]=0 b[0]=0 V=[0]*(n) H=[0]*(n) for i in range(n): line,index=input().split() index=int(index) if line=="V": r[index]=w V[i]=index else: t[index]=h H[i]=index ...
Title: Glass Carving Time Limit: None seconds Memory Limit: None megabytes Problem Description: Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What ...
```python w,h,n=map(int,input().split()) l=[-1]*(w+1) r=[-1]*(w+1) t=[-1]*(h+1) b=[-1]*(h+1) l[0]=0 b[0]=0 V=[0]*(n) H=[0]*(n) for i in range(n): line,index=input().split() index=int(index) if line=="V": r[index]=w V[i]=index else: t[index]=h H[i]=ind...
0
595
B
Pasha and Phone
PROGRAMMING
1,600
[ "binary search", "math" ]
null
null
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly *n* digits. Also Pasha has a number *k* and two sequences of length *n*<=/<=*k* (*n* is divisible by *k*) *a*1,<=*a*2,<=...,<=*a**n*<=/<=*k* and *b*1,<=*b*2,<=...,<=*b**n*<=/<=*k*. Le...
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*min*(*n*,<=9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that *n* is divisible by *k*. The second line of the input contains *n*<=/<=*k* space-separated positive in...
Print a single integer — the number of good phone numbers of length *n* modulo 109<=+<=7.
[ "6 2\n38 56 49\n7 3 4\n", "8 2\n1 22 3 44\n5 4 3 2\n" ]
[ "8\n", "32400\n" ]
In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
1,000
[ { "input": "6 2\n38 56 49\n7 3 4", "output": "8" }, { "input": "8 2\n1 22 3 44\n5 4 3 2", "output": "32400" }, { "input": "2 1\n9 9\n9 9", "output": "1" }, { "input": "2 1\n9 9\n0 9", "output": "1" }, { "input": "4 1\n4 3 2 1\n1 2 3 4", "output": "540" }, ...
1,627,923,199
2,147,483,647
PyPy 3
OK
TESTS
38
139
31,027,200
MOD=10**9+7 n,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) k1,k2,ans=10**k,10**(k-1),1 for i in range(n//k): z,x=a[i],b[i] if b[i]>0: c=(x*k2-1)//z+(k1-1)//z-((x+1)*k2-1)//z+1 else: c=(k1-1)//z-(k2-1)//z ans=ans*c%MOD print(ans)
Title: Pasha and Phone Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly *n* digits. Also Pasha has a number *k* and two sequences of length *n*<=/<=*k* (*...
```python MOD=10**9+7 n,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) k1,k2,ans=10**k,10**(k-1),1 for i in range(n//k): z,x=a[i],b[i] if b[i]>0: c=(x*k2-1)//z+(k1-1)//z-((x+1)*k2-1)//z+1 else: c=(k1-1)//z-(k2-1)//z ans=ans*c%MOD print(ans) ```
3
0
none
none
none
0
[ "none" ]
null
null
Little penguin Polo adores strings. But most of all he adores strings of length *n*. One day he wanted to find a string that meets the following conditions: 1. The string consists of *n* lowercase English letters (that is, the string's length equals *n*), exactly *k* of these letters are distinct. 1. No two neighbo...
A single line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=106,<=1<=≤<=*k*<=≤<=26) — the string's length and the number of distinct letters.
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
[ "7 4\n", "4 7\n" ]
[ "ababacd\n", "-1\n" ]
none
0
[ { "input": "7 4", "output": "ababacd" }, { "input": "4 7", "output": "-1" }, { "input": "10 5", "output": "abababacde" }, { "input": "47 2", "output": "abababababababababababababababababababababababa" }, { "input": "10 7", "output": "ababacdefg" }, { "...
1,689,050,209
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
25
124
1,843,200
n,k=map(int,input().split()) if k>n or k==1 and n>1: print (-1) else: ans="ab"*((n-(k-2))//2) if (n-(k-2)) % 2 == 1: ans+="a" ans += "cdefghijklmnopqrstuvwxyz"[:k-2] print(ans)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little penguin Polo adores strings. But most of all he adores strings of length *n*. One day he wanted to find a string that meets the following conditions: 1. The string consists of *n* lowercase English letters (that is, the ...
```python n,k=map(int,input().split()) if k>n or k==1 and n>1: print (-1) else: ans="ab"*((n-(k-2))//2) if (n-(k-2)) % 2 == 1: ans+="a" ans += "cdefghijklmnopqrstuvwxyz"[:k-2] print(ans) ```
0
230
B
T-primes
PROGRAMMING
1,300
[ "binary search", "implementation", "math", "number theory" ]
null
null
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st...
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
[ "3\n4 5 6\n" ]
[ "YES\nNO\nNO\n" ]
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
500
[ { "input": "3\n4 5 6", "output": "YES\nNO\nNO" }, { "input": "2\n48 49", "output": "NO\nYES" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO" }, { "input": "1\n36", "output": "NO" }, { "input": "1\n999966000289", "...
1,697,373,118
2,147,483,647
Python 3
OK
TESTS
68
998
24,166,400
# -*- coding: utf-8 -*- """ Created on Sun Oct 15 16:26:41 2023 @author: 31861 """ n=1000000 a=[1]*n s=set() for i in range(2,n): if a[i]: s.add(i*i) for j in range(i*i,n,i): a[j]=0 input() for x in map(int,input().split()): print(["NO","YES"][x in s])
Title: T-primes Time Limit: None seconds Memory Limit: None megabytes Problem Description: We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an ar...
```python # -*- coding: utf-8 -*- """ Created on Sun Oct 15 16:26:41 2023 @author: 31861 """ n=1000000 a=[1]*n s=set() for i in range(2,n): if a[i]: s.add(i*i) for j in range(i*i,n,i): a[j]=0 input() for x in map(int,input().split()): print(["NO","YES"][x in s]) ```
3
810
A
Straight <<A>>
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, wh...
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack.
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*.
[ "2 10\n8 9\n", "3 5\n4 4 4\n" ]
[ "4", "3" ]
Consider the first example testcase. Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc...
500
[ { "input": "2 10\n8 9", "output": "4" }, { "input": "3 5\n4 4 4", "output": "3" }, { "input": "3 10\n10 8 9", "output": "3" }, { "input": "2 23\n21 23", "output": "2" }, { "input": "5 10\n5 10 10 9 10", "output": "7" }, { "input": "12 50\n18 10 26 22 2...
1,495,368,462
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
14
1,000
0
'''input 3 5 4 4 4 ''' n, k = map(int, input().split()) a = list(map(int, input().split())) s = round(sum(a)/n) c = 0 if s < k: while s < k: a.append(k) c += 1 s = round(sum(a)/(n+c)) if (sum(a)/(n+c)) % 1 == 0.5: s += 1 else: while s > k: a.append(1) c += 1 s = round(sum(a)/(n+c)) if (sum(a)/(n+c)...
Title: Straight <<A>> Time Limit: None seconds Memory Limit: None megabytes Problem Description: Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. ...
```python '''input 3 5 4 4 4 ''' n, k = map(int, input().split()) a = list(map(int, input().split())) s = round(sum(a)/n) c = 0 if s < k: while s < k: a.append(k) c += 1 s = round(sum(a)/(n+c)) if (sum(a)/(n+c)) % 1 == 0.5: s += 1 else: while s > k: a.append(1) c += 1 s = round(sum(a)/(n+c)) if (su...
0
250
B
Restoring IPv6
PROGRAMMING
1,500
[ "implementation", "strings" ]
null
null
An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef"....
The first line contains a single integer *n* — the number of records to restore (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:". It is guaranteed that each short address is obtained by the way that is...
For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input.
[ "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n" ]
[ "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n" ]
none
1,000
[ { "input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000...
1,682,490,908
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
186
0
for _ in range((int)(input())) : s = input().split(':') for _ in range(len(s)) : if s[_] == "" : while len(s) < 8 : s.insert(_ , "") for _ in range(8) : s[_] = s[_].zfill(4) print(":".join(s))
Title: Restoring IPv6 Time Limit: None seconds Memory Limit: None megabytes Problem Description: An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. He...
```python for _ in range((int)(input())) : s = input().split(':') for _ in range(len(s)) : if s[_] == "" : while len(s) < 8 : s.insert(_ , "") for _ in range(8) : s[_] = s[_].zfill(4) print(":".join(s)) ```
0
614
A
Link/Cut Tree
PROGRAMMING
1,500
[ "brute force", "implementation" ]
null
null
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure. Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agre...
The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109).
Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes).
[ "1 10 2\n", "2 4 5\n" ]
[ "1 2 4 8 ", "-1" ]
Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed.
500
[ { "input": "1 10 2", "output": "1 2 4 8 " }, { "input": "2 4 5", "output": "-1" }, { "input": "18102 43332383920 28554", "output": "28554 815330916 " }, { "input": "19562 31702689720 17701", "output": "313325401 " }, { "input": "11729 55221128400 313", "output...
1,471,579,019
419
Python 3
WRONG_ANSWER
TESTS
43
62
4,608,000
from math import ceil, log def kp(l, r, k): ll = int(ceil(log(l, k))) kp = k**ll if kp > r: yield -1 else: while kp <= r: yield kp kp *= k if __name__ == '__main__': l, r, k = map(int, input().split()) print(' '.join(map(str, kp(l, r, k))))
Title: Link/Cut Tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure. Unfortunately, Rostislav is unable to understand ...
```python from math import ceil, log def kp(l, r, k): ll = int(ceil(log(l, k))) kp = k**ll if kp > r: yield -1 else: while kp <= r: yield kp kp *= k if __name__ == '__main__': l, r, k = map(int, input().split()) print(' '.join(map(str, kp(l, r, k)))) ...
0
427
A
Police Recruits
PROGRAMMING
800
[ "implementation" ]
null
null
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime. If there is no police offi...
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers. If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ...
Print a single integer, the number of crimes which will go untreated.
[ "3\n-1 -1 1\n", "8\n1 -1 1 -1 -1 1 1 1\n", "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n" ]
[ "2\n", "1\n", "8\n" ]
Lets consider the second example: 1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c...
500
[ { "input": "3\n-1 -1 1", "output": "2" }, { "input": "8\n1 -1 1 -1 -1 1 1 1", "output": "1" }, { "input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1", "output": "8" }, { "input": "7\n-1 -1 1 1 -1 -1 1", "output": "2" }, { "input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ...
1,692,376,994
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
n=int(input()) li=map(list(int,input().split())) x=0 count=0 for i in li: if(i==-1): if(x>=1): x=x-i else: count+=1 else: x+=i print(count)
Title: Police Recruits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of...
```python n=int(input()) li=map(list(int,input().split())) x=0 count=0 for i in li: if(i==-1): if(x>=1): x=x-i else: count+=1 else: x+=i print(count) ```
-1
617
A
Elephant
PROGRAMMING
800
[ "math" ]
null
null
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ...
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
[ "5\n", "12\n" ]
[ "1\n", "3\n" ]
In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
500
[ { "input": "5", "output": "1" }, { "input": "12", "output": "3" }, { "input": "999999", "output": "200000" }, { "input": "41", "output": "9" }, { "input": "1000000", "output": "200000" }, { "input": "1", "output": "1" }, { "input": "2", ...
1,695,555,207
2,147,483,647
Python 3
OK
TESTS
34
62
0
valid_steps = [1, 2, 3, 4, 5] x = int(input()) step = 0 while x >= 0: if x >= 5: x = x - 5 step = step + 1 elif 4 <= x < 5: x = x - 4 step = step + 1 elif 3 <= x < 4: x = x - 3 step = step + 1 elif 2 <= x < 3: x = x - 2 step ...
Title: Elephant Time Limit: None seconds Memory Limit: None megabytes Problem Description: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2...
```python valid_steps = [1, 2, 3, 4, 5] x = int(input()) step = 0 while x >= 0: if x >= 5: x = x - 5 step = step + 1 elif 4 <= x < 5: x = x - 4 step = step + 1 elif 3 <= x < 4: x = x - 3 step = step + 1 elif 2 <= x < 3: x = x - 2 ...
3
598
A
Tricky Sum
PROGRAMMING
900
[ "math" ]
null
null
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*.
The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109).
Print the requested sum for each of *t* integers *n* given in the input.
[ "2\n4\n1000000000\n" ]
[ "-4\n499999998352516354\n" ]
The answer for the first sample is explained in the statement.
0
[ { "input": "2\n4\n1000000000", "output": "-4\n499999998352516354" }, { "input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25" }, { "input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53", "output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130...
1,648,640,690
2,147,483,647
PyPy 3-64
OK
TESTS
21
62
2,048,000
# Python3 program for the above approach from collections import defaultdict import math # Function to return the number of # quadruplets having the given sum def trickySum(n): Sum = n*(n+1)//2 total = Sum pow2 = 1 while(pow2 <= n): Sum -= pow2 pow2 *= 2 # Return the answer return...
Title: Tricky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, be...
```python # Python3 program for the above approach from collections import defaultdict import math # Function to return the number of # quadruplets having the given sum def trickySum(n): Sum = n*(n+1)//2 total = Sum pow2 = 1 while(pow2 <= n): Sum -= pow2 pow2 *= 2 # Return the answe...
3
454
A
Little Pony and Crystal Mine
PROGRAMMING
800
[ "implementation" ]
null
null
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=&gt;<=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it. You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All ot...
The only line contains an integer *n* (3<=≤<=*n*<=≤<=101; *n* is odd).
Output a crystal of size *n*.
[ "3\n", "5\n", "7\n" ]
[ "*D*\nDDD\n*D*\n", "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n", "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n" ]
none
500
[ { "input": "3", "output": "*D*\nDDD\n*D*" }, { "input": "5", "output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**" }, { "input": "7", "output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***" }, { "input": "11", "output": "*****D*****\n****DDD****\n***DDDDD***\n**...
1,570,302,025
2,147,483,647
PyPy 3
OK
TESTS
12
140
0
a = int(input()) def nor(n): for i in range(1, n, 2): f = '*'*int((n-i)/2) d = f+'D'*i+f print(d) def rev(h): for i in range(h, 0, -2): q = '*'*int((h-i)/2) w = q+'D'*i+q print(w) nor(a) rev(a) ...
Title: Little Pony and Crystal Mine Time Limit: None seconds Memory Limit: None megabytes Problem Description: Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=&gt;<=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it. You are given an odd integer *n*. You ...
```python a = int(input()) def nor(n): for i in range(1, n, 2): f = '*'*int((n-i)/2) d = f+'D'*i+f print(d) def rev(h): for i in range(h, 0, -2): q = '*'*int((h-i)/2) w = q+'D'*i+q print(w) nor(a) ...
3
369
C
Valera and Elections
PROGRAMMING
1,600
[ "dfs and similar", "graphs", "trees" ]
null
null
The city Valera lives in is going to hold elections to the city Parliament. The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, fo...
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of districts in the city. Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*t**i*<=≤<=2) — the districts connected by the *...
In the first line print a single non-negative number *k* — the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print a...
[ "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n", "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n", "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n" ]
[ "1\n5 \n", "1\n3 \n", "4\n5 4 3 2 \n" ]
none
1,500
[ { "input": "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2", "output": "1\n5 " }, { "input": "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1", "output": "1\n3 " }, { "input": "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2", "output": "4\n5 4 3 2 " }, { "input": "5\n1 5 1\n5 4 2\n4 3 1\n3 2 2", "output": "1\n2 " }, { ...
1,650,047,427
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
5
920
25,600,000
n=int(input()) graph=[[] for _ in range(n)] for _ in range(n-1): a,b,p=map(int,input().split()) a-=1 b-=1 graph[a].append((b,p)) graph[b].append((a,p)) def solve(node,par): res=[] for nie,p in graph[node]: if nie !=par: temp=solve(nie,node) if te...
Title: Valera and Elections Time Limit: None seconds Memory Limit: None megabytes Problem Description: The city Valera lives in is going to hold elections to the city Parliament. The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other...
```python n=int(input()) graph=[[] for _ in range(n)] for _ in range(n-1): a,b,p=map(int,input().split()) a-=1 b-=1 graph[a].append((b,p)) graph[b].append((a,p)) def solve(node,par): res=[] for nie,p in graph[node]: if nie !=par: temp=solve(nie,node) ...
-1
1,004
C
Sonya and Robots
PROGRAMMING
1,400
[ "constructive algorithms", "implementation" ]
null
null
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya wi...
The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row.
Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet.
[ "5\n1 5 4 1 3\n", "7\n1 2 1 1 1 3 2\n" ]
[ "9\n", "7\n" ]
In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$). In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$).
1,500
[ { "input": "5\n1 5 4 1 3", "output": "9" }, { "input": "7\n1 2 1 1 1 3 2", "output": "7" }, { "input": "10\n2 2 4 4 3 1 1 2 3 2", "output": "14" }, { "input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4", "output": "20" }, { "input": "1\n1", "output": "0" } ]
1,628,914,513
2,147,483,647
PyPy 3
OK
TESTS
42
187
34,201,600
# Author Name: Ajay Meena # Codeforce : https://codeforces.com/profile/majay1638 import sys import math import bisect import heapq from bisect import bisect_right from sys import stdin, stdout # -------------- INPUT FUNCTIONS ------------------ def get_ints_in_variables(): return map( int, sys.stdin...
Title: Sonya and Robots Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot ...
```python # Author Name: Ajay Meena # Codeforce : https://codeforces.com/profile/majay1638 import sys import math import bisect import heapq from bisect import bisect_right from sys import stdin, stdout # -------------- INPUT FUNCTIONS ------------------ def get_ints_in_variables(): return map( int,...
3
441
B
Valera and Fruits
PROGRAMMING
1,400
[ "greedy", "implementation" ]
null
null
Valera loves his garden, where *n* fruit trees grow. This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collec...
The first line contains two space-separated integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* a...
Print a single integer — the maximum number of fruit that Valera can collect.
[ "2 3\n1 5\n2 3\n", "5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n" ]
[ "8\n", "60\n" ]
In the first sample, in order to obtain the optimal answer, you should act as follows. - On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree. In the second s...
1,000
[ { "input": "2 3\n1 5\n2 3", "output": "8" }, { "input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60" }, { "input": "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202", "output": "10596" }, { "input": "5 3000\n5 772\n1 2522\n2 575\n4 445...
1,589,605,461
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
124
7,065,600
l=lambda :map(int,input().split()) n,v=l() t={x:y for x,y in (l() for _ in ' '*n)} s=0 for i in range(min(t),max(t)+2): x=min(t[i],v) s+=x t[i+1]=t.get(i+1,0)+(t[i]-x) print(s)
Title: Valera and Fruits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera loves his garden, where *n* fruit trees grow. This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get wit...
```python l=lambda :map(int,input().split()) n,v=l() t={x:y for x,y in (l() for _ in ' '*n)} s=0 for i in range(min(t),max(t)+2): x=min(t[i],v) s+=x t[i+1]=t.get(i+1,0)+(t[i]-x) print(s) ```
0
931
C
Laboratory Work
PROGRAMMING
1,700
[ "implementation", "math" ]
null
null
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value *n* times, and then compute the average value to lower the error. Kirill has already made his measurements, and has got the following integer values: *x*1, *x*2, ..., *x**n*. It is important that the values are clo...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the numeber of measurements made by Kirill. The second line contains a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=100<=000<=≤<=*x**i*<=≤<=100<=000) — the measurements made by Kirill. It is guaranteed that the difference between the maxi...
In the first line print the minimum possible number of equal measurements. In the second line print *n* integers *y*1,<=*y*2,<=...,<=*y**n* — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Ki...
[ "6\n-1 1 1 0 0 -1\n", "3\n100 100 101\n", "7\n-10 -9 -10 -8 -10 -9 -9\n" ]
[ "2\n0 0 0 0 0 0 \n", "3\n101 100 100 \n", "5\n-10 -10 -9 -9 -9 -9 -9 \n" ]
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements. In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make...
1,750
[ { "input": "6\n-1 1 1 0 0 -1", "output": "2\n0 0 0 0 0 0 " }, { "input": "3\n100 100 101", "output": "3\n101 100 100 " }, { "input": "7\n-10 -9 -10 -8 -10 -9 -9", "output": "5\n-10 -10 -9 -9 -9 -9 -9 " }, { "input": "60\n-8536 -8536 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -...
1,624,983,884
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
155
2,150,400
n=int(input()) a=[int(x) for x in input().split()] x=abs(sum(a))//n xx=abs(sum(a)) if x<0: x*=-1 xx%=x an=[x]*n for i in range(xx): an[i]+=1 print(*an)
Title: Laboratory Work Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value *n* times, and then compute the average value to lower the error. Kirill has already made his measurements, and h...
```python n=int(input()) a=[int(x) for x in input().split()] x=abs(sum(a))//n xx=abs(sum(a)) if x<0: x*=-1 xx%=x an=[x]*n for i in range(xx): an[i]+=1 print(*an) ```
-1
990
B
Micro-World
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer c...
The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$. The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have.
Print the only integer — minimal possible number of bacteria can remain.
[ "7 1\n101 53 42 102 101 55 54\n", "6 5\n20 15 10 15 20 25\n", "7 1000000\n1 1 1 1 1 1 1\n" ]
[ "3\n", "1\n", "7\n" ]
The first example is clarified in the problem statement. In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$. I...
0
[ { "input": "7 1\n101 53 42 102 101 55 54", "output": "3" }, { "input": "6 5\n20 15 10 15 20 25", "output": "1" }, { "input": "7 1000000\n1 1 1 1 1 1 1", "output": "7" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 4\n8", "output": "1" }, { "inp...
1,528,699,952
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
108
11,571,200
n, k = map(int, input().split()) hz = [0] * (200001) def increase(x): x = int(x) hz[x] += 1 return x lst = sorted(list(set(list(map(increase, input().split()))))) ans = 0 for i in range(1, len(lst)): temp = lst[i - 1] + k if lst[i] <= temp: ans += hz[lst[i - 1]] print(n - ans)
Title: Micro-World Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have $n$ bacteria in the Pe...
```python n, k = map(int, input().split()) hz = [0] * (200001) def increase(x): x = int(x) hz[x] += 1 return x lst = sorted(list(set(list(map(increase, input().split()))))) ans = 0 for i in range(1, len(lst)): temp = lst[i - 1] + k if lst[i] <= temp: ans += hz[lst[i - 1]] print(n...
-1
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,563,306,994
214
Python 3
WRONG_ANSWER
TESTS
3
109
0
v = 'aeiou' n = int(input()) s = input() res = [s[0]] i = 0 while i < n: j = i + 1 if s[i] in v: while j < n and s[j] in v: j += 1 if j < n: res.append(s[j]) i = j print(''.join(res))
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 v = 'aeiou' n = int(input()) s = input() res = [s[0]] i = 0 while i < n: j = i + 1 if s[i] in v: while j < n and s[j] in v: j += 1 if j < n: res.append(s[j]) i = j print(''.join(res)) ```
0
505
A
Mr. Kitayuta's Gift
PROGRAMMING
1,100
[ "brute force", "implementation", "strings" ]
null
null
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "tes...
The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter.
If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
[ "revive\n", "ee\n", "kitayuta\n" ]
[ "reviver\n", "eye", "NA\n" ]
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver". For the second sample, there is more than one solution. For example, "eve" will also be accepted. For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
500
[ { "input": "revive", "output": "reviver" }, { "input": "ee", "output": "eee" }, { "input": "kitayuta", "output": "NA" }, { "input": "evima", "output": "NA" }, { "input": "a", "output": "aa" }, { "input": "yutampo", "output": "NA" }, { "inpu...
1,454,023,506
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
import sys def checkRest(word): left = 0; right = len(word) - 2 print(right) while(left <= right): if(word[left] != word[right]): return False left+=1 right-=1 return True def palen(line): left = 0 right = len(line)-2 print(str(right)) while(left < right): if(line[left] != line[right]): print(...
Title: Mr. Kitayuta's Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that re...
```python import sys def checkRest(word): left = 0; right = len(word) - 2 print(right) while(left <= right): if(word[left] != word[right]): return False left+=1 right-=1 return True def palen(line): left = 0 right = len(line)-2 print(str(right)) while(left < right): if(line[left] != line[right]):...
0
799
F
Beautiful fountains rows
PROGRAMMING
3,500
[ "data structures" ]
null
null
Butler Ostin wants to show Arkady that rows of odd number of fountains are beautiful, while rows of even number of fountains are not. The butler wants to show Arkady *n* gardens. Each garden is a row of *m* cells, the *i*-th garden has one fountain in each of the cells between *l**i* and *r**i* inclusive, and there ar...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the number of gardens and the length of each garden. *n* lines follow. The *i*-th of these lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*m*) — the bounds of the segment that contains fountains in the *i*-th gar...
Print one integer: the total length of all suitable segments.
[ "1 5\n2 4\n", "3 6\n2 4\n3 6\n4 4\n" ]
[ "23\n", "19\n" ]
In the first example the following pairs suit Ostin: (*a*, *b*): (1, 2), (1, 4), (1, 5), (2, 2), (2, 4), (2, 5), (3, 3), (4, 4), (4, 5). In the second example the following pairs suit Ostin: (*a*, *b*): (1, 2), (1, 5), (2, 2), (2, 5), (3, 3), (4, 4), (4, 6), (5, 5), (6, 6).
3,250
[]
1,689,345,836
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
62
0
print("_RANDOM_GUESS_1689345836.3244932")# 1689345836.324506
Title: Beautiful fountains rows Time Limit: None seconds Memory Limit: None megabytes Problem Description: Butler Ostin wants to show Arkady that rows of odd number of fountains are beautiful, while rows of even number of fountains are not. The butler wants to show Arkady *n* gardens. Each garden is a row of *m* ce...
```python print("_RANDOM_GUESS_1689345836.3244932")# 1689345836.324506 ```
0
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,592,988,020
2,147,483,647
Python 3
OK
TESTS
18
93
6,656,000
def solution(l1): k,n,s,p=l1[0],l1[1],l1[2],l1[3] each=int(n/s)+1*(n%s!=0) total=each*k ans=int(total/p)+1*(total%p!=0) return ans def answer(): l1 = [int(x) for x in input().split()] print(solution(l1)) answer()
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 def solution(l1): k,n,s,p=l1[0],l1[1],l1[2],l1[3] each=int(n/s)+1*(n%s!=0) total=each*k ans=int(total/p)+1*(total%p!=0) return ans def answer(): l1 = [int(x) for x in input().split()] print(solution(l1)) answer() ```
3
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the...
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3"...
1,663,319,758
2,147,483,647
Python 3
OK
TESTS
20
46
0
import math m,n,a = map(int, input().strip().split(" ")) print(int(math.ceil(m/a)*math.ceil(n/a)))
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ...
```python import math m,n,a = map(int, input().strip().split(" ")) print(int(math.ceil(m/a)*math.ceil(n/a))) ```
3.977
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,630,400,644
2,147,483,647
Python 3
OK
TESTS
30
154
6,963,200
s=input() c=0 k=0 for i in s: if i=='a' or i=='b' or i=='c' or i=='d' or i=='e' or i=='f' or i=='g' or i=='h' or i=='i' or i=='j' or i=='k' or i=='l' or i=='m' or i=='n' or i=='o' or i=='p' or i=='q' or i=='r' or i=='s' or i=='t' or i=='u' or i=='v' or i=='w' or i=='x' or i=='y' or i=='z': c+=1 el...
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() c=0 k=0 for i in s: if i=='a' or i=='b' or i=='c' or i=='d' or i=='e' or i=='f' or i=='g' or i=='h' or i=='i' or i=='j' or i=='k' or i=='l' or i=='m' or i=='n' or i=='o' or i=='p' or i=='q' or i=='r' or i=='s' or i=='t' or i=='u' or i=='v' or i=='w' or i=='x' or i=='y' or i=='z': c+...
3.94853
793
A
Oleg and shares
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. ...
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices.
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
[ "3 3\n12 9 15\n", "2 2\n10 9\n", "4 1\n1 1000000000 1000000000 1000000000\n" ]
[ "3", "-1", "2999999997" ]
Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. Ther...
500
[ { "input": "3 3\n12 9 15", "output": "3" }, { "input": "2 2\n10 9", "output": "-1" }, { "input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997" }, { "input": "1 11\n123", "output": "0" }, { "input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50...
1,596,386,269
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
186
31,027,200
n,m=map(int,input().split()) l=list(map(int,input().split())) a=min(l) c=0 flag=0 if n==1: print(0) else: if a%m==0: for i in l: if i%m==0: c=c+(i-a)//m elif i%m: flag=1 break else: flag=1 if flag==1...
Title: Oleg and shares Time Limit: None seconds Memory Limit: None megabytes Problem Description: Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly o...
```python n,m=map(int,input().split()) l=list(map(int,input().split())) a=min(l) c=0 flag=0 if n==1: print(0) else: if a%m==0: for i in l: if i%m==0: c=c+(i-a)//m elif i%m: flag=1 break else: flag=1 ...
0
638
D
Three-dimensional Turtle Super Computer
PROGRAMMING
1,800
[ "brute force", "dfs and similar", "graphs" ]
null
null
A super computer has been built in the Turtle Academy of Sciences. The computer consists of *n*·*m*·*k* CPUs. The architecture was the paralellepiped of size *n*<=×<=*m*<=×<=*k*, split into 1<=×<=1<=×<=1 cells, each cell contains exactly one CPU. Thus, each CPU can be simultaneously identified as a group of three numbe...
The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=100) — the dimensions of the Super Computer. Then *n* blocks follow, describing the current state of the processes. The blocks correspond to the layers of the Super Computer in the order from 1 to *n*. Each block consists of *m* lines,...
Print a single integer — the number of critical CPUs, that is, such that turning only this CPU off will disrupt some control.
[ "2 2 3\n000\n000\n\n111\n111\n", "3 3 3\n111\n111\n111\n\n111\n111\n111\n\n111\n111\n111\n", "1 1 10\n0101010101\n" ]
[ "2\n", "19\n", "0\n" ]
In the first sample the whole first layer of CPUs is malfunctional. In the second layer when CPU (2, 1, 2) turns off, it disrupts the control by CPU (2, 1, 3) over CPU (2, 1, 1), and when CPU (2, 2, 2) is turned off, it disrupts the control over CPU (2, 2, 3) by CPU (2, 2, 1). In the second sample all processors excep...
2,000
[ { "input": "2 2 3\n000\n000\n\n111\n111", "output": "2" }, { "input": "3 3 3\n111\n111\n111\n\n111\n111\n111\n\n111\n111\n111", "output": "19" }, { "input": "1 1 10\n0101010101", "output": "0" }, { "input": "1 1 1\n0", "output": "0" }, { "input": "1 1 1\n1", "...
1,458,551,484
76,284
Python 3
OK
TESTS
50
1,684
9,932,800
def check(d, i, j, l): global result, save if d[i][j][l] == 1: if d[i + 1][j][l] == 1 and d[i - 1][j][l] == 1: #save.append([i, j, l]) result += 1 return if d[i][j + 1][l] == 1 and d[i][j - 1][l] == 1: result += 1 #save.append([i, j, l]...
Title: Three-dimensional Turtle Super Computer Time Limit: None seconds Memory Limit: None megabytes Problem Description: A super computer has been built in the Turtle Academy of Sciences. The computer consists of *n*·*m*·*k* CPUs. The architecture was the paralellepiped of size *n*<=×<=*m*<=×<=*k*, split into 1<=×...
```python def check(d, i, j, l): global result, save if d[i][j][l] == 1: if d[i + 1][j][l] == 1 and d[i - 1][j][l] == 1: #save.append([i, j, l]) result += 1 return if d[i][j + 1][l] == 1 and d[i][j - 1][l] == 1: result += 1 #save.append...
3
285
C
Building Permutation
PROGRAMMING
1,200
[ "greedy", "implementation", "sortings" ]
null
null
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. You ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Print a single number — the minimum number of moves. 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.
[ "2\n3 0\n", "3\n-1 -1 2\n" ]
[ "2\n", "6\n" ]
In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1). In the second sample you need 6 moves to build permutation (1, 3, 2).
1,500
[ { "input": "2\n3 0", "output": "2" }, { "input": "3\n-1 -1 2", "output": "6" }, { "input": "5\n-3 5 -3 3 3", "output": "10" }, { "input": "10\n9 6 -2 4 1 1 1 9 6 2", "output": "18" }, { "input": "9\n2 0 0 6 5 4 1 9 3", "output": "15" }, { "input": "100...
1,576,346,047
2,147,483,647
Python 3
OK
TESTS
33
482
25,497,600
def arr_inp(): return [int(x) for x in input().split()] def fun(x): global c c += 1 return abs(x - c) from math import * n, a, c = int(input()), sorted(arr_inp()), 0 print(sum(map(fun, a)))
Title: Building Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *...
```python def arr_inp(): return [int(x) for x in input().split()] def fun(x): global c c += 1 return abs(x - c) from math import * n, a, c = int(input()), sorted(arr_inp()), 0 print(sum(map(fun, a))) ```
3
411
A
Password Check
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che...
The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_".
If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes).
[ "abacaba\n", "X12345\n", "CONTEST_is_STARTED!!11\n" ]
[ "Too weak\n", "Too weak\n", "Correct\n" ]
none
0
[ { "input": "abacaba", "output": "Too weak" }, { "input": "X12345", "output": "Too weak" }, { "input": "CONTEST_is_STARTED!!11", "output": "Correct" }, { "input": "1zA__", "output": "Correct" }, { "input": "1zA_", "output": "Too weak" }, { "input": "zA_...
1,594,630,557
2,147,483,647
Python 3
OK
TESTS
81
109
6,656,000
s=input() u,l,k=False,False,False for i in s: if i.isupper(): u=True if i.islower(): l=True if i.isdigit(): k=True if u and k and l and len(s) >= 5: print('Correct') else: print('Too weak')
Title: Password Check Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password...
```python s=input() u,l,k=False,False,False for i in s: if i.isupper(): u=True if i.islower(): l=True if i.isdigit(): k=True if u and k and l and len(s) >= 5: print('Correct') else: print('Too weak') ```
3
0
none
none
none
0
[ "none" ]
null
null
In this problem you need to write job distribution subsystem for testing submissions. Invokers (simplistically) are components of testing system, which test given submission on single test and give back a verdict. In this problem two verdicts are possible — OK (test passed) or RJ (rejected, test failed). Job distribu...
On the start your program reads the following data from standard input: - in the first line you are given an integer number *t* (1<=≤<=*t*<=≤<=500) — the number of available invokers (all invokers work simultaneously and independently, free invoker starts testing a job as soon as it is appointed to him); - in the se...
After reading the data about the next tick your scheduler can decide to send submissions for exact testing. The submission can be tested in any test at any time. Your scheduler must output a couple of integers — index of submission and a number of test in a single line in order to start a test for the submission. If th...
[ "1\n1\n500 2\n-1\n-1 -1\n-1\n-1 -1\n-1\n-1 -1\n-1\n-1 -1\n-1\n-1 -1\n0\n-1\n-1 -1\n0\n-1\n-1 -1\n-1\n-1 -1\n-1\n-1 -1\n-1\n-1 -1\n-1\n0 0 OK\n-1 -1\n-1\n-1 -1\n-1\n-1 -1\n-1\n-1 -1\n-1\n-1 -1\n-1\n-1 -1\n-1\n0 1 OK\n-1 -1\n-1\n-1 -1\n-1\n-1 -1\n-1\n-1 -1\n-1\n-1 -1\n-1\n-1 -1\n-1\n1 0 RJ\n-1 -1\n" ]
[ "-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n0 0\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n0 1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n1 0\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n1 1\n-1 -1\n" ]
Materials and tests are available now at [http://assets.codeforces.com/files/vk/vkcup-2016-wr2-materials-v1.tar.gz](//assets.codeforces.com/files/vk/vkcup-2016-wr2-materials-v1.tar.gz). Please read README.txt to learn how to test your solution with the interactor.
0
[]
1,461,754,425
158,025
Python 3
SKIPPED
TESTS
0
0
0
#include <string> #include <vector> #include <map> #include <queue> #include <iostream> using namespace std; typedef unsigned int uint; #define MS_IN_TICK 10 struct Task { uint problem_id; uint test_id; uint id; double score; uint creation_time; bool done; }; auto task...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you need to write job distribution subsystem for testing submissions. Invokers (simplistically) are components of testing system, which test given submission on single test and give back a verdict. In this problem...
```python #include <string> #include <vector> #include <map> #include <queue> #include <iostream> using namespace std; typedef unsigned int uint; #define MS_IN_TICK 10 struct Task { uint problem_id; uint test_id; uint id; double score; uint creation_time; bool done; }; ...
-1
960
A
Check the string
PROGRAMMING
1,200
[ "implementation" ]
null
null
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string. B now gi...
The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
Print "YES" or "NO", according to the condition.
[ "aaabccc\n", "bbacc\n", "aabc\n" ]
[ "YES\n", "NO\n", "YES\n" ]
Consider first example: the number of 'c' is equal to the number of 'a'. Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct. Consider third example: the number of 'c' is equal to the number of 'b'.
500
[ { "input": "aaabccc", "output": "YES" }, { "input": "bbacc", "output": "NO" }, { "input": "aabc", "output": "YES" }, { "input": "aabbcc", "output": "YES" }, { "input": "aaacccbb", "output": "NO" }, { "input": "abc", "output": "YES" }, { "in...
1,621,694,792
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
n=input() a=[] b=[] c=[] for i in n: if i == 'a': a.append(n.index(i)+1) elif i == 'b': b.append(n.index(i)+1) else: c.append(n.index(i)+1) if max(a)<min(b): if max(b)<min(c): if (n.count('c') == n.count('a')) or (n.count('c') == n.count('b')): p...
Title: Check the string Time Limit: None seconds Memory Limit: None megabytes Problem Description: A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b...
```python n=input() a=[] b=[] c=[] for i in n: if i == 'a': a.append(n.index(i)+1) elif i == 'b': b.append(n.index(i)+1) else: c.append(n.index(i)+1) if max(a)<min(b): if max(b)<min(c): if (n.count('c') == n.count('a')) or (n.count('c') == n.count('b')): ...
0
160
A
Twins
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't w...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
In the single line print the single number — the minimum needed number of coins.
[ "2\n3 3\n", "3\n2 1 2\n" ]
[ "2\n", "2\n" ]
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum. In the second sample one coin isn't e...
500
[ { "input": "2\n3 3", "output": "2" }, { "input": "3\n2 1 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "5\n4 2 2 2 2", "output": "3" }, { "input": "7\n1 10 1 2 1 1 1", "output": "1" }, { "input": "5\n3 2 3 3 1", "output": "3" ...
1,694,080,485
2,147,483,647
Python 3
OK
TESTS
29
92
0
n = int(input()) s = list(map(int, input().split())) total = sum(s) s.sort(reverse=True) sum1 = 0 count = 0 for i in s: sum1 += i count += 1 if sum1 > total - sum1: break print(count)
Title: Twins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w...
```python n = int(input()) s = list(map(int, input().split())) total = sum(s) s.sort(reverse=True) sum1 = 0 count = 0 for i in s: sum1 += i count += 1 if sum1 > total - sum1: break print(count) ```
3
749
A
Bachgold Problem
PROGRAMMING
800
[ "greedy", "implementation", "math", "number theory" ]
null
null
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ...
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
The first line of the output contains a single integer *k* — maximum possible number of primes in representation. The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
[ "5\n", "6\n" ]
[ "2\n2 3\n", "3\n2 2 2\n" ]
none
500
[ { "input": "5", "output": "2\n2 3" }, { "input": "6", "output": "3\n2 2 2" }, { "input": "2", "output": "1\n2" }, { "input": "3", "output": "1\n3" }, { "input": "99999", "output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
1,621,681,581
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
61
0
a=int(input()) if a%2!=0: x=a//2 b=x+1 print (2) print (x, b) else: x=a//2 print (a//2) for i in range (x): print (a//x, end=' ')
Title: Bachgold Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. ...
```python a=int(input()) if a%2!=0: x=a//2 b=x+1 print (2) print (x, b) else: x=a//2 print (a//2) for i in range (x): print (a//x, end=' ') ```
0
343
B
Alternating Current
PROGRAMMING
1,600
[ "data structures", "greedy", "implementation" ]
null
null
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended u...
The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.
Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.
[ "-++-\n", "+-\n", "++\n", "-\n" ]
[ "Yes\n", "No\n", "Yes\n", "No\n" ]
The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full rev...
1,000
[ { "input": "-++-", "output": "Yes" }, { "input": "+-", "output": "No" }, { "input": "++", "output": "Yes" }, { "input": "-", "output": "No" }, { "input": "+-+-", "output": "No" }, { "input": "-+-", "output": "No" }, { "input": "-++-+--+", ...
1,525,960,981
2,147,483,647
Python 3
OK
TESTS
62
218
7,987,200
sequence = input().strip() if len(sequence) % 2 != 0: print('No') else: stack = [] for s in sequence: if stack and s == stack[-1]: stack.pop() else: stack.append(s) if stack: print('No') else: print('Yes')
Title: Alternating Current Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it...
```python sequence = input().strip() if len(sequence) % 2 != 0: print('No') else: stack = [] for s in sequence: if stack and s == stack[-1]: stack.pop() else: stack.append(s) if stack: print('No') else: print('Yes') ```
3
296
A
Yaroslav and Permutations
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements.
In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.
[ "1\n1\n", "3\n1 1 2\n", "4\n7 7 7 7\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample the initial array fits well. In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it. In the third sample Yarosav can't get the array he needs.
500
[ { "input": "1\n1", "output": "YES" }, { "input": "3\n1 1 2", "output": "YES" }, { "input": "4\n7 7 7 7", "output": "NO" }, { "input": "4\n479 170 465 146", "output": "YES" }, { "input": "5\n996 437 605 996 293", "output": "YES" }, { "input": "6\n727 53...
1,580,821,178
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
186
0
index =int(input()) numbers = input().split() d = dict() i=0 if index > 3: while i <= (index//2) : if numbers[i] in d.keys(): if d[numbers[i]] == int(numbers[i+1]): print('NO') exit() else: d[numbers[i]] = int(numbers[i + 1]) ...
Title: Yaroslav and Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would...
```python index =int(input()) numbers = input().split() d = dict() i=0 if index > 3: while i <= (index//2) : if numbers[i] in d.keys(): if d[numbers[i]] == int(numbers[i+1]): print('NO') exit() else: d[numbers[i]] = int(number...
0
448
D
Multiplication Table
PROGRAMMING
1,800
[ "binary search", "brute force" ]
null
null
Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multiplication table, where the element on the intersection of the *i*-th row and *j*-th column equals *i*·*j* ...
The single line contains integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=5·105; 1<=≤<=*k*<=≤<=*n*·*m*).
Print the *k*-th largest number in a *n*<=×<=*m* multiplication table.
[ "2 2 2\n", "2 3 4\n", "1 10 5\n" ]
[ "2\n", "3\n", "5\n" ]
A 2 × 3 multiplication table looks like this:
2,000
[ { "input": "2 2 2", "output": "2" }, { "input": "2 3 4", "output": "3" }, { "input": "1 10 5", "output": "5" }, { "input": "1 1 1", "output": "1" }, { "input": "10 1 7", "output": "7" }, { "input": "10 10 33", "output": "14" }, { "input": "...
1,697,183,073
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
61
0
def get_k_for(number): upper_bound = 0 for i in range(1, n+1): temp = min(number // i, m) if temp == 0: break upper_bound += temp return upper_bound n, m, k = map(int, input().split()) n, m = min(n, m), max(n, m) l = 1 r = n*m while r >= l: m = (r+l)/...
Title: Multiplication Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multi...
```python def get_k_for(number): upper_bound = 0 for i in range(1, n+1): temp = min(number // i, m) if temp == 0: break upper_bound += temp return upper_bound n, m, k = map(int, input().split()) n, m = min(n, m), max(n, m) l = 1 r = n*m while r >= l: ...
0
33
C
Wonderful Randomized Sum
PROGRAMMING
1,800
[ "greedy" ]
C. Wonderful Randomized Sum
2
256
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of elements in the sequence. The second line contains *n* integers *a**i* (<=-<=104<=≤<=*a**i*<=≤<=104) — the sequence itself.
The first and the only line of the output should contain the answer to the problem.
[ "3\n-1 -2 -3\n", "5\n-4 2 0 5 0\n", "5\n-1 10 -5 10 -2\n" ]
[ "6\n", "11\n", "18\n" ]
none
1,500
[ { "input": "3\n-1 -2 -3", "output": "6" }, { "input": "5\n-4 2 0 5 0", "output": "11" }, { "input": "5\n-1 10 -5 10 -2", "output": "18" }, { "input": "1\n-3", "output": "3" }, { "input": "4\n1 4 -5 -2", "output": "12" }, { "input": "7\n-17 6 5 0 1 4 -1...
1,450,747,257
2,147,483,647
Python 3
OK
TESTS
89
280
7,372,800
n = int(input()) values = list(map(int, input().split())) best_infix = infix = 0 for x in values: infix = max(0, infix + x) best_infix = max(best_infix, infix) print(2 * best_infix - sum(values))
Title: Wonderful Randomized Sum Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivat...
```python n = int(input()) values = list(map(int, input().split())) best_infix = infix = 0 for x in values: infix = max(0, infix + x) best_infix = max(best_infix, infix) print(2 * best_infix - sum(values)) ```
3.916267
964
B
Messages
PROGRAMMING
1,300
[ "math" ]
null
null
There are *n* incoming messages for Vasya. The *i*-th message is going to be received after *t**i* minutes. Each message has a cost, which equals to *A* initially. After being received, the cost of a message decreases by *B* each minute (it can become negative). Vasya can read any message after receiving it at any mome...
The first line contains five integers *n*, *A*, *B*, *C* and *T* (1<=≤<=*n*,<=*A*,<=*B*,<=*C*,<=*T*<=≤<=1000). The second string contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=*T*).
Output one integer  — the answer to the problem.
[ "4 5 5 3 5\n1 5 5 4\n", "5 3 1 1 3\n2 2 2 1 1\n", "5 5 3 4 5\n1 2 3 4 5\n" ]
[ "20\n", "15\n", "35\n" ]
In the first sample the messages must be read immediately after receiving, Vasya receives *A* points for each message, *n*·*A* = 20 in total. In the second sample the messages can be read at any integer moment. In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messa...
1,000
[ { "input": "4 5 5 3 5\n1 5 5 4", "output": "20" }, { "input": "5 3 1 1 3\n2 2 2 1 1", "output": "15" }, { "input": "5 5 3 4 5\n1 2 3 4 5", "output": "35" }, { "input": "1 6 4 3 9\n2", "output": "6" }, { "input": "10 9 7 5 3\n3 3 3 3 2 3 2 2 3 3", "output": "90...
1,523,975,949
2,049
Python 3
OK
TESTS
60
93
7,065,600
n, a, b, c, t = list(map(int, input().split())) time = list(map(int, input().split())) ans = 0 if c >= b: for ti in time: ans += a + (c - b) * (t - ti) else: ans = len(time) * a print(ans)
Title: Messages Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* incoming messages for Vasya. The *i*-th message is going to be received after *t**i* minutes. Each message has a cost, which equals to *A* initially. After being received, the cost of a message decreases by *B* e...
```python n, a, b, c, t = list(map(int, input().split())) time = list(map(int, input().split())) ans = 0 if c >= b: for ti in time: ans += a + (c - b) * (t - ti) else: ans = len(time) * a print(ans) ```
3
768
B
Code For 1
PROGRAMMING
1,600
[ "constructive algorithms", "dfs and similar", "divide and conquer" ]
null
null
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s...
The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=&lt;<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*. It is guaranteed that *r* is not greater than the length of the final list.
Output the total number of 1s in the range *l* to *r* in the final sequence.
[ "7 2 5\n", "10 3 10\n" ]
[ "4\n", "5\n" ]
Consider first example: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/> Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4. For the second example: <img al...
1,000
[ { "input": "7 2 5", "output": "4" }, { "input": "10 3 10", "output": "5" }, { "input": "56 18 40", "output": "20" }, { "input": "203 40 124", "output": "67" }, { "input": "903316762502 354723010040 354723105411", "output": "78355" }, { "input": "335343...
1,664,792,933
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
def code1(n,l,r): if not isinstance(n,list): n = [n] for i in range(len(n)): new = [] if n[i]!=1 and n[i]!=0: new.append(n[i]//2) new.append(n[i]%2) new.append(n[i]//2) if len(new)==3: n[i] = new[0] n.inse...
Title: Code For 1 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and ta...
```python def code1(n,l,r): if not isinstance(n,list): n = [n] for i in range(len(n)): new = [] if n[i]!=1 and n[i]!=0: new.append(n[i]//2) new.append(n[i]%2) new.append(n[i]//2) if len(new)==3: n[i] = new[0] ...
0
805
B
3-palindrome
PROGRAMMING
1,000
[ "constructive algorithms" ]
null
null
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su...
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string.
Print the string that satisfies all the constraints. If there are multiple answers, print any of them.
[ "2\n", "3\n" ]
[ "aa\n", "bba\n" ]
A palindrome is a sequence of characters which reads the same backward and forward.
1,000
[ { "input": "2", "output": "aa" }, { "input": "3", "output": "aab" }, { "input": "38", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa" }, { "input": "47", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab" }, { "input": "59", "output": "aabbaabbaabb...
1,574,081,997
7,197
PyPy 3
WRONG_ANSWER
TESTS
12
139
1,024,000
import sys input = sys.stdin.readline def li():return [int(i) for i in input().rstrip('\n').split(' ')] def st():return input().rstrip('\n') def val():return int(input()) s = 'abbaabbaabba'*int((66667)/4) print(s[:val()])
Title: 3-palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each o...
```python import sys input = sys.stdin.readline def li():return [int(i) for i in input().rstrip('\n').split(' ')] def st():return input().rstrip('\n') def val():return int(input()) s = 'abbaabbaabba'*int((66667)/4) print(s[:val()]) ```
0
277
A
Learning Languages
PROGRAMMING
1,400
[ "dfs and similar", "dsu" ]
null
null
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official la...
The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of employees and the number of languages. Then *n* lines follow — each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≤<=*k**i*<=≤<=*m*) — the number of languages the *i*-th employee knows. Next...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
[ "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n", "2 2\n1 2\n0\n" ]
[ "0\n", "2\n", "1\n" ]
In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4. In the third sample employee 2 must learn language 2.
500
[ { "input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "output": "0" }, { "input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "output": "2" }, { "input": "2 2\n1 2\n0", "output": "1" }, { "input": "2 2\n0\n0", "output": "2" }, { "input": "5 5\n1 3\n0\n0\n2 4...
1,647,459,225
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
60
0
def dfs_iterative(graph , start , seen ) : c=0 seen[start] = True to_visit=[start] while to_visit : node = to_visit.pop() for i in graph[node-1] : if not seen[i] : seen[i] = True to_visit.append(i) if not to_visit : ...
Title: Learning Languages Time Limit: None seconds Memory Limit: None megabytes Problem Description: The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have th...
```python def dfs_iterative(graph , start , seen ) : c=0 seen[start] = True to_visit=[start] while to_visit : node = to_visit.pop() for i in graph[node-1] : if not seen[i] : seen[i] = True to_visit.append(i) if not to_visit : ...
0
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,598,778,730
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
92
6,860,800
# Author: SaykaT # Problem: 714A.py # Time Created: August 30(Sunday) 2020 || 03:09:09 #>-------------------------<# #>-------------------------<# # Helper Functions. -> Don't cluster your code. # Main functions. -> Write the main solution here def solve(): l1, r1, l2, r2, k = map(int, input().s...
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 # Author: SaykaT # Problem: 714A.py # Time Created: August 30(Sunday) 2020 || 03:09:09 #>-------------------------<# #>-------------------------<# # Helper Functions. -> Don't cluster your code. # Main functions. -> Write the main solution here def solve(): l1, r1, l2, r2, k = map(int,...
-1
227
B
Effective Approach
PROGRAMMING
1,100
[ "implementation" ]
null
null
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ...
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2\n1 2\n1\n1\n", "2\n2 1\n1\n1\n", "3\n3 1 2\n3\n1 2 3\n" ]
[ "1 2\n", "2 1\n", "6 6\n" ]
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, o...
1,000
[ { "input": "2\n1 2\n1\n1", "output": "1 2" }, { "input": "2\n2 1\n1\n1", "output": "2 1" }, { "input": "3\n3 1 2\n3\n1 2 3", "output": "6 6" }, { "input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "output": "58 32" }, { "input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4...
1,666,594,052
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
9,011,200
n = int(input()) a = [int(x) for x in input().split()] m = int(input()) b = [int(x) for x in input().split()] c1,c2 = 0,0 for i in range(m): for j in range(n): if b[i] == a[j]: c1+=(j+1) break for k in range(n-1,0,-1): if b[i] == a[j]: c2+=(n-j) ...
Title: Effective Approach Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c...
```python n = int(input()) a = [int(x) for x in input().split()] m = int(input()) b = [int(x) for x in input().split()] c1,c2 = 0,0 for i in range(m): for j in range(n): if b[i] == a[j]: c1+=(j+1) break for k in range(n-1,0,-1): if b[i] == a[j]: c2...
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,547,881,265
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
s = [str(x) for x in input().split()] t = "hello" c = 0 for i in s: if i == t[c]: c += 1 if c == 5: print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python s = [str(x) for x in input().split()] t = "hello" c = 0 for i in s: if i == t[c]: c += 1 if c == 5: print("YES") else: print("NO") ```
0
462
B
Appleman and Card Game
PROGRAMMING
1,300
[ "greedy" ]
null
null
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to lette...
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman.
Print a single integer – the answer to the problem.
[ "15 10\nDZFDFZDFDDDDDDF\n", "6 4\nYJSNPI\n" ]
[ "82\n", "4\n" ]
In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin.
1,000
[ { "input": "15 10\nDZFDFZDFDDDDDDF", "output": "82" }, { "input": "6 4\nYJSNPI", "output": "4" }, { "input": "5 3\nAOWBY", "output": "3" }, { "input": "1 1\nV", "output": "1" }, { "input": "2 1\nWT", "output": "1" }, { "input": "2 2\nBL", "output":...
1,648,959,555
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
20
62
7,475,200
def solve(n, k, s): ans = 0 c = [0 for _ in range(27)] for i in range(n): c[ord(s[i])-ord('A')]+=1 c = sorted(c) for i in range(26,i >=0 and k!=0,-1): if k>=c[i]: k-=c[i] ans+=c[i]*c[i] else: ans+=k*k break ...
Title: Appleman and Card Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally...
```python def solve(n, k, s): ans = 0 c = [0 for _ in range(27)] for i in range(n): c[ord(s[i])-ord('A')]+=1 c = sorted(c) for i in range(26,i >=0 and k!=0,-1): if k>=c[i]: k-=c[i] ans+=c[i]*c[i] else: ans+=k*k ...
0
233
A
Perfect Permutation
PROGRAMMING
800
[ "implementation", "math" ]
null
null
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He lik...
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
[ "1\n", "2\n", "4\n" ]
[ "-1\n", "2 1 \n", "2 1 4 3 \n" ]
none
500
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "2 1 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "3", "output": "-1" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "7", ...
1,647,085,053
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
124
0
# #✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧ # ◕ █ █ █ █ /████\ ██\ █ /██\ ██ ██\ █ ◕ # ◕ █ █ █ █ █\ \█ █\█\ █ /█/\█\ █\█\ █ ◕ # ◕ █\ /█ █ █ █ █ \█\ █ /█/ \█\ ██ █ \█\ █ ◕ # ◕ █████ █ █ \████\ █ \█\ ...
Title: Perfect Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ...
```python # #✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧✧ # ◕ █ █ █ █ /████\ ██\ █ /██\ ██ ██\ █ ◕ # ◕ █ █ █ █ █\ \█ █\█\ █ /█/\█\ █\█\ █ ◕ # ◕ █\ /█ █ █ █ █ \█\ █ /█/ \█\ ██ █ \█\ █ ◕ # ◕ █████ █ █ \████...
0
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,584,457,053
2,147,483,647
Python 3
OK
TESTS
72
124
0
n=int(input()) m=list(map(int,input().split())) a=0 b=0 for i in m: if(i>=0): a+=i else: b+=i print(a-b)
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 n=int(input()) m=list(map(int,input().split())) a=0 b=0 for i in m: if(i>=0): a+=i else: b+=i print(a-b) ```
3
416
B
Art Union
PROGRAMMING
1,300
[ "brute force", "dp", "implementation" ]
null
null
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows. Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color...
The first line of the input contains integers *m*,<=*n* (1<=≤<=*m*<=≤<=50000,<=1<=≤<=*n*<=≤<=5), where *m* is the number of pictures and *n* is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains *n* integers *t**i*1,<=*t**i*2,<=...,<=*t**in* (1<=≤<=*t**ij*<=≤<=1000), ...
Print the sequence of *m* integers *r*1,<=*r*2,<=...,<=*r**m*, where *r**i* is the moment when the *n*-th painter stopped working on the *i*-th picture.
[ "5 1\n1\n2\n3\n4\n5\n", "4 2\n2 5\n3 1\n5 3\n10 1\n" ]
[ "1 3 6 10 15 ", "7 8 13 21 " ]
none
1,000
[ { "input": "5 1\n1\n2\n3\n4\n5", "output": "1 3 6 10 15 " }, { "input": "4 2\n2 5\n3 1\n5 3\n10 1", "output": "7 8 13 21 " }, { "input": "1 1\n66", "output": "66 " }, { "input": "2 2\n1 1\n1 1", "output": "2 3 " }, { "input": "2 2\n10 1\n10 1", "output": "11 2...
1,657,728,108
2,147,483,647
PyPy 3
OK
TESTS
26
685
16,588,800
import sys from typing import List, Tuple def picture_painiting(m: int, n: int, arr: List[Tuple[int]]) -> List[int]: times = [[0]*(n+1) for _ in range(m+1)] for i in range(1, m+1): for j in range(1, n+1): times[i][j] = int(arr[i-1][j-1]) for i in range(1, m+1): for j in ran...
Title: Art Union Time Limit: None seconds Memory Limit: None megabytes Problem Description: A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows. Each painter uses only the color that was assigned t...
```python import sys from typing import List, Tuple def picture_painiting(m: int, n: int, arr: List[Tuple[int]]) -> List[int]: times = [[0]*(n+1) for _ in range(m+1)] for i in range(1, m+1): for j in range(1, n+1): times[i][j] = int(arr[i-1][j-1]) for i in range(1, m+1): fo...
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,633,013,031
2,147,483,647
Python 3
OK
TESTS
40
154
6,758,400
# import sys # sys.stdout = open('C:/Study/codes/output.txt', 'w') # sys.stdin = open('C:/Study/codes/input.txt', 'r') a = input() b = input() newa =a[::-1] if newa == b: 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 # import sys # sys.stdout = open('C:/Study/codes/output.txt', 'w') # sys.stdin = open('C:/Study/codes/input.txt', 'r') a = input() b = input() newa =a[::-1] if newa == b: print("YES") else: print("NO") ```
3.948911
867
A
Between the Offices
PROGRAMMING
800
[ "implementation" ]
null
null
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane. You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem...
The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days. The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given...
Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise. You can print each letter in any case (upper or lower).
[ "4\nFSSF\n", "2\nSF\n", "10\nFFFFFFFFFF\n", "10\nSSFFSFFSFF\n" ]
[ "NO\n", "YES\n", "NO\n", "YES\n" ]
In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO". In the second example you just flew from Seattle to San Francisco, so the answer is "YES". In the third example you staye...
500
[ { "input": "4\nFSSF", "output": "NO" }, { "input": "2\nSF", "output": "YES" }, { "input": "10\nFFFFFFFFFF", "output": "NO" }, { "input": "10\nSSFFSFFSFF", "output": "YES" }, { "input": "20\nSFSFFFFSSFFFFSSSSFSS", "output": "NO" }, { "input": "20\nSSFFF...
1,587,919,736
2,147,483,647
Python 3
OK
TESTS
34
109
0
n=int(input()) stroka=input() if stroka[0]=='S' and stroka[n-1]=='F': print('YES') else: print('NO')
Title: Between the Offices Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane. You prefer flying from Seattle to San Franci...
```python n=int(input()) stroka=input() if stroka[0]=='S' and stroka[n-1]=='F': print('YES') else: print('NO') ```
3
20
C
Dijkstra?
PROGRAMMING
1,900
[ "graphs", "shortest paths" ]
C. Dijkstra?
1
64
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge...
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
[ "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n" ]
[ "1 4 3 5 ", "1 4 3 5 " ]
none
1,500
[ { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5 " }, { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5 " }, { "input": "2 1\n1 2 1", "output": "1 2 " }, { "input": "3 1\n1 2 1", "output": "-1" }, { "input...
1,598,932,985
2,147,483,647
Python 3
OK
TESTS
33
717
23,244,800
from heapq import heappop, heappush nodes, edges = map(int, input().split()) adj = [dict() for i in range(nodes + 1)] prev = [None] * (nodes + 1) visited = [False] * (nodes + 1) costList = [float("inf")] * (nodes + 1) for i in range(edges): start, end, dist = map(int, input().split()) adj[start][end] =...
Title: Dijkstra? Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. Input Specification: The first line contains two integers *n* a...
```python from heapq import heappop, heappush nodes, edges = map(int, input().split()) adj = [dict() for i in range(nodes + 1)] prev = [None] * (nodes + 1) visited = [False] * (nodes + 1) costList = [float("inf")] * (nodes + 1) for i in range(edges): start, end, dist = map(int, input().split()) adj[sta...
3.468313
765
B
Code obfuscation
PROGRAMMING
1,100
[ "greedy", "implementation", "strings" ]
null
null
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest. To obfuscate the code, Kostya first looks at the first variable name used in his program and rep...
In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters.
If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".
[ "abacaba\n", "jinotega\n" ]
[ "YES\n", "NO\n" ]
In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program: - replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result...
1,000
[ { "input": "abacaba", "output": "YES" }, { "input": "jinotega", "output": "NO" }, { "input": "aaaaaaaaaaa", "output": "YES" }, { "input": "aba", "output": "YES" }, { "input": "bab", "output": "NO" }, { "input": "a", "output": "YES" }, { "in...
1,605,601,773
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
124
0
string = str(input()) List = sorted([j for j in string]) output = 1 for j in range(1, len(List)): if ord(List[j]) - ord(List[j - 1]) > 1: output = 0 break if output == 1: print('YES') else: print('NO')
Title: Code obfuscation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming cont...
```python string = str(input()) List = sorted([j for j in string]) output = 1 for j in range(1, len(List)): if ord(List[j]) - ord(List[j - 1]) > 1: output = 0 break if output == 1: print('YES') else: print('NO') ```
0
0
none
none
none
0
[ "none" ]
null
null
A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya liked the idea of the method very much, and he decided to try it in practi...
The first input line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=500<=000) — the length of the initial sequence. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=0 or *a**i*<==<=1), giving the initial sequence itself.
If the sequence will never become stable, print a single number <=-<=1. Otherwise, first print a single integer — the minimum number of times one needs to apply the median smoothing algorithm to the initial sequence before it becomes is stable. In the second line print *n* numbers separated by a space  — the resulting...
[ "4\n0 0 1 1\n", "5\n0 1 0 1 0\n" ]
[ "0\n0 0 1 1\n", "2\n0 0 0 0 0\n" ]
In the second sample the stabilization occurs in two steps: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5a983e7baab048cbe43812cb997c15e9d7100231.png" style="max-width: 100.0%;max-height: 100.0%;"/>, and the sequence 00000 is obviously stable.
0
[ { "input": "4\n0 0 1 1", "output": "0\n0 0 1 1" }, { "input": "5\n0 1 0 1 0", "output": "2\n0 0 0 0 0" }, { "input": "3\n1 0 0", "output": "0\n1 0 0" }, { "input": "4\n1 0 0 1", "output": "0\n1 0 0 1" }, { "input": "7\n1 0 1 1 1 0 1", "output": "1\n1 1 1 1 1 1...
1,453,984,577
2,147,483,647
Python 3
OK
TESTS
43
670
7,782,400
#! /usr/bin/env python # -*- coding: utf-8 -*- # vim:fenc=utf-8 # # Copyright © 2016 missingdays <missingdays@missingdays> # # Distributed under terms of the MIT license. """ """ n = int(input()) a = [i for i in input().split()] def change(l, r): global a if l == r: return 0 if a[l] == a[r]: ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and eng...
```python #! /usr/bin/env python # -*- coding: utf-8 -*- # vim:fenc=utf-8 # # Copyright © 2016 missingdays <missingdays@missingdays> # # Distributed under terms of the MIT license. """ """ n = int(input()) a = [i for i in input().split()] def change(l, r): global a if l == r: return 0 if a[l]...
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,674,020,064
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
a,b,c,d,e = input("").split() print(a) print(b) print(c) print(d) print(e)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python a,b,c,d,e = input("").split() print(a) print(b) print(c) print(d) print(e) ```
-1
452
A
Eevee
PROGRAMMING
1,000
[ "brute force", "implementation", "strings" ]
null
null
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Syl...
First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string. Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).
Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).
[ "7\nj......\n", "7\n...feon\n", "7\n.l.r.o.\n" ]
[ "jolteon\n", "leafeon\n", "flareon\n" ]
Here's a set of names in a form you can paste into your solution: ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}
500
[ { "input": "7\n...feon", "output": "leafeon" }, { "input": "7\n.l.r.o.", "output": "flareon" }, { "input": "6\n.s..o.", "output": "espeon" }, { "input": "7\nglaceon", "output": "glaceon" }, { "input": "8\n.a.o.e.n", "output": "vaporeon" }, { "input": "...
1,624,913,795
2,147,483,647
Python 3
OK
TESTS
20
77
204,800
from collections import deque, defaultdict, Counter from itertools import product, groupby, permutations, combinations from math import gcd, floor, inf from bisect import bisect_right, bisect_left names = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] def equal(word1, wo...
Title: Eevee Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight...
```python from collections import deque, defaultdict, Counter from itertools import product, groupby, permutations, combinations from math import gcd, floor, inf from bisect import bisect_right, bisect_left names = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] def equal...
3
112
A
Petya and Strings
PROGRAMMING
800
[ "implementation", "strings" ]
A. Petya and Strings
2
256
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr...
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
[ "aaaa\naaaA\n", "abs\nAbz\n", "abcdefg\nAbCdEfF\n" ]
[ "0\n", "-1\n", "1\n" ]
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
500
[ { "input": "aaaa\naaaA", "output": "0" }, { "input": "abs\nAbz", "output": "-1" }, { "input": "abcdefg\nAbCdEfF", "output": "1" }, { "input": "asadasdasd\nasdwasdawd", "output": "-1" }, { "input": "aslkjlkasdd\nasdlkjdajwi", "output": "1" }, { "input":...
1,695,285,075
2,147,483,647
Python 3
OK
TESTS
53
92
0
# -*- coding: utf-8 -*- """ Created on Thu Sep 21 16:10:17 2023 @author: 20311 """ up=str(input()) down=str(input()) up=up.lower() down=down.lower() if up > down: print('1') elif up< down: print('-1') else: print('0')
Title: Petya and Strings Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ...
```python # -*- coding: utf-8 -*- """ Created on Thu Sep 21 16:10:17 2023 @author: 20311 """ up=str(input()) down=str(input()) up=up.lower() down=down.lower() if up > down: print('1') elif up< down: print('-1') else: print('0') ```
3.977
675
C
Money Transfers
PROGRAMMING
2,100
[ "constructive algorithms", "data structures", "greedy", "sortings" ]
null
null
There are *n* banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank *n* are neighbours if *n*<=&gt;<=1. No bank is a neighbour of itself. Vasya has an account in each bank. Its balance may be negative...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of banks. The second line contains *n* integers *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109), the *i*-th of them is equal to the initial balance of the account in the *i*-th bank. It's guaranteed that the sum of all *a**i* is equal...
Print the minimum number of operations required to change balance in each bank to zero.
[ "3\n5 0 -5\n", "4\n-1 0 1 0\n", "4\n1 2 3 -6\n" ]
[ "1\n", "2\n", "3\n" ]
In the first sample, Vasya may transfer 5 from the first bank to the third. In the second sample, Vasya may first transfer 1 from the third bank to the second, and then 1 from the second to the first. In the third sample, the following sequence provides the optimal answer: 1. transfer 1 from the first bank to the ...
1,500
[ { "input": "3\n5 0 -5", "output": "1" }, { "input": "4\n-1 0 1 0", "output": "2" }, { "input": "4\n1 2 3 -6", "output": "3" }, { "input": "1\n0", "output": "0" }, { "input": "50\n108431864 128274949 -554057370 -384620666 -202862975 -803855410 -482167063 -55139054 ...
1,470,315,398
2,147,483,647
Python 3
OK
TESTS
41
124
11,264,000
n = int(input()) a = list(map(int, input().split())) search = dict() sum = 0 for b in a: sum += b if not sum in search: search[sum] = 1 else: search[sum] += 1 print(n - max(search.values()))
Title: Money Transfers Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank *n* are neighbours if *n*<=&gt;<...
```python n = int(input()) a = list(map(int, input().split())) search = dict() sum = 0 for b in a: sum += b if not sum in search: search[sum] = 1 else: search[sum] += 1 print(n - max(search.values())) ```
3
455
A
Boredom
PROGRAMMING
1,500
[ "dp" ]
null
null
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Print a single integer — the maximum number of points that Alex can earn.
[ "2\n1 2\n", "3\n1 2 3\n", "9\n1 2 1 3 2 2 2 2 3\n" ]
[ "2\n", "4\n", "10\n" ]
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n1 2 3", "output": "4" }, { "input": "9\n1 2 1 3 2 2 2 2 3", "output": "10" }, { "input": "5\n3 3 4 5 4", "output": "11" }, { "input": "5\n5 3 5 3 4", "output": "16" }, { "input": "5\n4 2 3 2 5", ...
1,695,489,826
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
length = int(input()) numbers = sorted(list(map(int, input().split()))) numbers = numbers[::-1] pure = [e for e in set(numbers)] all = [] for i in range(len(pure)): c = 0 for e in numbers: if e == numbers[i]: c += numbers[i] elif e == numbers[i]+1 or e == numbers[i]-1: ...
Title: Boredom Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make ...
```python length = int(input()) numbers = sorted(list(map(int, input().split()))) numbers = numbers[::-1] pure = [e for e in set(numbers)] all = [] for i in range(len(pure)): c = 0 for e in numbers: if e == numbers[i]: c += numbers[i] elif e == numbers[i]+1 or e == numbers[...
0
911
B
Two Cakes
PROGRAMMING
1,200
[ "binary search", "brute force", "implementation" ]
null
null
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces. Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ...
The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.
Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake.
[ "5 2 3\n", "4 7 10\n" ]
[ "1\n", "3\n" ]
In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it. In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.
0
[ { "input": "5 2 3", "output": "1" }, { "input": "4 7 10", "output": "3" }, { "input": "100 100 100", "output": "2" }, { "input": "10 100 3", "output": "3" }, { "input": "2 9 29", "output": "9" }, { "input": "4 6 10", "output": "3" }, { "inp...
1,525,758,956
2,147,483,647
PyPy 3
OK
TESTS
135
109
21,401,600
R = lambda: map(int, input().split()) n, a, b = R() print(max([min(a // x if x else 0, b // (n - x) if x != n else 0) for x in range(0, n + 1)]))
Title: Two Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces. Iv...
```python R = lambda: map(int, input().split()) n, a, b = R() print(max([min(a // x if x else 0, b // (n - x) if x != n else 0) for x in range(0, n + 1)])) ```
3
987
C
Three displays
PROGRAMMING
1,400
[ "brute force", "dp", "implementation" ]
null
null
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
The first line contains a single integer $n$ ($3 \le n \le 3\,000$) — the number of displays. The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$) — the font sizes on the displays in the order they stand along the road. The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \...
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $i &lt; j &lt; k$ such that $s_i &lt; s_j &lt; s_k$.
[ "5\n2 4 5 4 10\n40 30 20 10 40\n", "3\n100 101 100\n2 4 5\n", "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13\n" ]
[ "90\n", "-1\n", "33\n" ]
In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 &lt; s_4 &lt; s_5$ ($2 &lt; 4 &lt; 10$), and the rent cost is $40 + 10 + 40 = 90$. In the second example you can't select a valid triple of indices, so the answer is -1.
1,250
[ { "input": "5\n2 4 5 4 10\n40 30 20 10 40", "output": "90" }, { "input": "3\n100 101 100\n2 4 5", "output": "-1" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13", "output": "33" }, { "input": "3\n1 2 3\n100000000 100000000 100000000", "output": "300...
1,659,515,992
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
3
93
2,048,000
import math import sys def _input(): return map(int, input().split()) n = int(input()) s = list(_input()) c = list(_input()) lst = [0]*(n-2) j = 1 while j<n-1: i = j-1 m = sys.maxsize while i>=0: if s[i] < s[j]: m = min(m, c[i]) i-=1 if m == sys.maxsize: ...
Title: Three displays Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, ...
```python import math import sys def _input(): return map(int, input().split()) n = int(input()) s = list(_input()) c = list(_input()) lst = [0]*(n-2) j = 1 while j<n-1: i = j-1 m = sys.maxsize while i>=0: if s[i] < s[j]: m = min(m, c[i]) i-=1 if m == sys.max...
-1
0
none
none
none
0
[ "none" ]
null
null
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type: 1. <=+<= *a**i* — add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may b...
The first line of the input contains an integer *t* (1<=≤<=*t*<=≤<=100<=000) — the number of operation Sonya has to perform. Next *t* lines provide the descriptions of the queries in order they appear in the input file. The *i*-th row starts with a character *c**i* — the type of the corresponding operation. If *c**i* ...
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
[ "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n", "4\n+ 200\n+ 200\n- 200\n? 0\n" ]
[ "2\n1\n2\n1\n1\n", "1\n" ]
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input. 1. 1 and 241. 1. 361. 1. 101 and 361. 1. 361. 1. 4000.
0
[ { "input": "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0", "output": "2\n1\n2\n1\n1" }, { "input": "4\n+ 200\n+ 200\n- 200\n? 0", "output": "1" }, { "input": "20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\n+ 34\n+ 71\n+ 86\n+ 68\n+ 39\n+ 78\n+ 81\n+ 89\n? 10\n? 00...
1,522,114,633
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
9
1,000
7,372,800
def AddE(num): if num in s: s[num] +=1 else: s[num] = 1 def RemE(num): s[num] -= 1 if s[num] == 0: del s[num] def Can(x): digits = list(map(int,[y for y in str(x)])) eodigits = map(lambda z: z%2,digits) return int("".join(list(map(str,eodigits)))) def Query(num): ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type: 1. <=+<= *a**i* — add no...
```python def AddE(num): if num in s: s[num] +=1 else: s[num] = 1 def RemE(num): s[num] -= 1 if s[num] == 0: del s[num] def Can(x): digits = list(map(int,[y for y in str(x)])) eodigits = map(lambda z: z%2,digits) return int("".join(list(map(str,eodigits)))) def Query(...
0
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,606,887,485
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
154
0
a, b = input(), input() n = len(a) c = 0 d = 0 for i in range(n): if a[i] == b[-i - 1]: c += 1 else: d += 1 if c > d: 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 a, b = input(), input() n = len(a) c = 0 d = 0 for i in range(n): if a[i] == b[-i - 1]: c += 1 else: d += 1 if c > d: print('YES') else: print('NO') ```
0
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,633,985,033
2,147,483,647
PyPy 3
OK
TESTS
27
154
20,172,800
data = [] data.append(input()) data.append(input()) data.append(input()) players = ["F", "M", "S"] r = p = s = 0 for i in data: if i == "rock": r += 1 elif i == "paper": p += 1 else: s += 1 if p == 1 and r == 2: print(players[data.index("paper")]) elif s == 1 and p == 2: print(players[data.index(...
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 data = [] data.append(input()) data.append(input()) data.append(input()) players = ["F", "M", "S"] r = p = s = 0 for i in data: if i == "rock": r += 1 elif i == "paper": p += 1 else: s += 1 if p == 1 and r == 2: print(players[data.index("paper")]) elif s == 1 and p == 2: print(players[d...
3.923925
535
C
Tavas and Karafs
PROGRAMMING
1,900
[ "binary search", "greedy", "math" ]
null
null
Karafs is some kind of vegetable in shape of an 1<=×<=*h* rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs. Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the *i*-th Karafs is *s*...
The first line of input contains three integers *A*, *B* and *n* (1<=≤<=*A*,<=*B*<=≤<=106, 1<=≤<=*n*<=≤<=105). Next *n* lines contain information about queries. *i*-th line contains integers *l*,<=*t*,<=*m* (1<=≤<=*l*,<=*t*,<=*m*<=≤<=106) for *i*-th query.
For each query, print its answer in a single line.
[ "2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8\n", "1 5 2\n1 5 10\n2 7 4\n" ]
[ "4\n-1\n8\n-1\n", "1\n2\n" ]
none
1,500
[ { "input": "2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8", "output": "4\n-1\n8\n-1" }, { "input": "1 5 2\n1 5 10\n2 7 4", "output": "1\n2" }, { "input": "1 1 4\n1 1000000 1000000\n1 1 1000000\n1 1000000 1\n1 1 1", "output": "1000000\n1\n1413\n1" }, { "input": "1000000 1000000 1\n10000...
1,609,702,521
2,147,483,647
PyPy 3
OK
TESTS
58
608
11,571,200
import sys input = sys.stdin.readline a, b, n, l, t, m = -1, -1, -1, -1, -1, -1 def is_valid(mid): biggest = a + (mid - 1) * b; if t < biggest: return False sum = ((mid - l + 1) * (a + (l - 1) * b + biggest)) // 2 return t >= biggest and m * t >= sum def binary_search(b, e): ...
Title: Tavas and Karafs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Karafs is some kind of vegetable in shape of an 1<=×<=*h* rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs. Each Karafs has a positive inte...
```python import sys input = sys.stdin.readline a, b, n, l, t, m = -1, -1, -1, -1, -1, -1 def is_valid(mid): biggest = a + (mid - 1) * b; if t < biggest: return False sum = ((mid - l + 1) * (a + (l - 1) * b + biggest)) // 2 return t >= biggest and m * t >= sum def binary_search(b...
3
727
A
Transformation: from A to B
PROGRAMMING
1,000
[ "brute force", "dfs and similar", "math" ]
null
null
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1). You need to he...
The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have.
If there is no way to get *b* from *a*, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x...
[ "2 162\n", "4 42\n", "100 40021\n" ]
[ "YES\n5\n2 4 8 81 162 \n", "NO\n", "YES\n5\n100 200 2001 4002 40021 \n" ]
none
1,000
[ { "input": "2 162", "output": "YES\n5\n2 4 8 81 162 " }, { "input": "4 42", "output": "NO" }, { "input": "100 40021", "output": "YES\n5\n100 200 2001 4002 40021 " }, { "input": "1 111111111", "output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 " }, ...
1,632,742,680
2,147,483,647
PyPy 3
OK
TESTS
33
109
20,172,800
def f(l): u = l[-1] if u > l[0]: if u % 10 == 1: l.append(u // 10) f(l) elif not u % 2: l.append(u // 2) f(l) l = list(map(int, input().split())) f(l) if l.pop(0) == l[-1]: print("YES", len(l), sep='\n') print(*l[::-1]) els...
Title: Transformation: from A to B Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - app...
```python def f(l): u = l[-1] if u > l[0]: if u % 10 == 1: l.append(u // 10) f(l) elif not u % 2: l.append(u // 2) f(l) l = list(map(int, input().split())) f(l) if l.pop(0) == l[-1]: print("YES", len(l), sep='\n') print(*l[:...
3
373
B
Making Sequences is Fun
PROGRAMMING
1,600
[ "binary search", "implementation", "math" ]
null
null
We'll define *S*(*n*) for positive integer *n* as follows: the number of the *n*'s digits in the decimal base. For example, *S*(893)<==<=3, *S*(114514)<==<=6. You want to make a consecutive integer sequence starting from number *m* (*m*,<=*m*<=+<=1,<=...). But you need to pay *S*(*n*)·*k* to add the number *n* to the ...
The first line contains three integers *w* (1<=≤<=*w*<=≤<=1016), *m* (1<=≤<=*m*<=≤<=1016), *k* (1<=≤<=*k*<=≤<=109). Please, do not write 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.
The first line should contain a single integer — the answer to the problem.
[ "9 1 1\n", "77 7 7\n", "114 5 14\n", "1 1 2\n" ]
[ "9\n", "7\n", "6\n", "0\n" ]
none
1,000
[ { "input": "9 1 1", "output": "9" }, { "input": "77 7 7", "output": "7" }, { "input": "114 5 14", "output": "6" }, { "input": "1 1 2", "output": "0" }, { "input": "462 183 8", "output": "19" }, { "input": "462 183 8", "output": "19" }, { "i...
1,584,745,149
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
from itertools import count potencias = [pow(10, i) for i in range(1, 20)] w, m, k = tuple(map(int, input().split())) costo_maximo = w/k costo = 0 largo = 0 S = len(str(m)) for n in count(m): costo += S if costo > costo_maximo: print(costo, costo_maximo) break largo += 1 if (n+1) in ...
Title: Making Sequences is Fun Time Limit: None seconds Memory Limit: None megabytes Problem Description: We'll define *S*(*n*) for positive integer *n* as follows: the number of the *n*'s digits in the decimal base. For example, *S*(893)<==<=3, *S*(114514)<==<=6. You want to make a consecutive integer sequence sta...
```python from itertools import count potencias = [pow(10, i) for i in range(1, 20)] w, m, k = tuple(map(int, input().split())) costo_maximo = w/k costo = 0 largo = 0 S = len(str(m)) for n in count(m): costo += S if costo > costo_maximo: print(costo, costo_maximo) break largo += 1 if...
0
22
B
Bargaining Table
PROGRAMMING
1,500
[ "brute force", "dp" ]
B. Bargaining Table
2
256
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room *n*<=×<=*m* meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, t...
The first line contains 2 space-separated numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=25) — the office room dimensions. Then there follow *n* lines with *m* characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in ...
Output one number — the maximum possible perimeter of a bargaining table for Bob's office room.
[ "3 3\n000\n010\n000\n", "5 4\n1100\n0000\n0000\n0000\n0000\n" ]
[ "8\n", "16\n" ]
none
0
[ { "input": "3 3\n000\n010\n000", "output": "8" }, { "input": "5 4\n1100\n0000\n0000\n0000\n0000", "output": "16" }, { "input": "3 3\n000\n110\n000", "output": "8" }, { "input": "4 2\n00\n10\n11\n00", "output": "6" }, { "input": "3 5\n00001\n00000\n10100", "out...
1,676,798,851
2,147,483,647
Python 3
OK
TESTS
23
966
0
# LUOGU_RID: 102536606 n, m = map(int, input().split()) s = [input() for _ in range(n)] ans = 0 for i in range(n): for j in range(m): for k in range(i, n): for l in range(j, m): if all(s[x][j:l+1] == '0' * (l - j + 1) for x in range(i, k + 1)): ans = m...
Title: Bargaining Table Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room *n*<=×<=*m* meters. Each square meter of the room is either ...
```python # LUOGU_RID: 102536606 n, m = map(int, input().split()) s = [input() for _ in range(n)] ans = 0 for i in range(n): for j in range(m): for k in range(i, n): for l in range(j, m): if all(s[x][j:l+1] == '0' * (l - j + 1) for x in range(i, k + 1)): ...
3.7585
20
B
Equation
PROGRAMMING
2,000
[ "math" ]
B. Equation
1
256
You are given an equation: Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=105<=≤<=*A*,<=*B*,<=*C*<=≤<=105). Any coefficient may be equal to 0.
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
[ "1 -5 6\n" ]
[ "2\n2.0000000000\n3.0000000000" ]
none
1,000
[ { "input": "1 -5 6", "output": "2\n2.0000000000\n3.0000000000" }, { "input": "1 1 1", "output": "0" }, { "input": "1 2 1", "output": "1\n-1.0000000000" }, { "input": "0 0 0", "output": "-1" }, { "input": "0 -2 1", "output": "1\n0.5000000000" }, { "inpu...
1,684,028,880
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
a, b, c = map(float, input().split()) delta = (b**2) - (4*a*c) x1 = (-b - (delta**(1/2)))/2*a x2 = (-b + (delta**(1/2)))/2*a if(a==b==c==0): print(-1) elif((a==0 and c==0) or (b==c==0)): print(1) print("%.10f" % 0) elif(delta<0) or (a==0 and b==0): print(0) elif(delta==0 and a!=0): print(1) ...
Title: Equation Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: You are given an equation: Your task is to find the number of distinct roots of the equation and print all of them in ascending order. Input Specification: The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=1...
```python a, b, c = map(float, input().split()) delta = (b**2) - (4*a*c) x1 = (-b - (delta**(1/2)))/2*a x2 = (-b + (delta**(1/2)))/2*a if(a==b==c==0): print(-1) elif((a==0 and c==0) or (b==c==0)): print(1) print("%.10f" % 0) elif(delta<0) or (a==0 and b==0): print(0) elif(delta==0 and a!=0): ...
0
272
A
Dima and Friends
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show. The numbers in the lines are separated by a single s...
In a single line print the answer to the problem.
[ "1\n1\n", "1\n2\n", "2\n3 5\n" ]
[ "3\n", "2\n", "3\n" ]
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend. In the second sample Dima can show 2 or 4 fingers.
500
[ { "input": "1\n1", "output": "3" }, { "input": "1\n2", "output": "2" }, { "input": "2\n3 5", "output": "3" }, { "input": "2\n3 5", "output": "3" }, { "input": "1\n5", "output": "3" }, { "input": "5\n4 4 3 5 1", "output": "4" }, { "input": "...
1,584,080,359
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
218
307,200
n=int(input()) l=[int(x) for x in input().split(" ")] sum=0 for i in l: sum+=i if (sum+1)%(n+1)==1: print("2") else: print("3")
Title: Dima and Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the...
```python n=int(input()) l=[int(x) for x in input().split(" ")] sum=0 for i in l: sum+=i if (sum+1)%(n+1)==1: print("2") else: print("3") ```
0
22
A
Second Order Statistics
PROGRAMMING
800
[ "brute force" ]
A. Second Order Statistics
2
256
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ...
The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
[ "4\n1 2 2 -4\n", "5\n1 2 3 1 1\n" ]
[ "1\n", "2\n" ]
none
0
[ { "input": "4\n1 2 2 -4", "output": "1" }, { "input": "5\n1 2 3 1 1", "output": "2" }, { "input": "1\n28", "output": "NO" }, { "input": "2\n-28 12", "output": "12" }, { "input": "3\n-83 40 -80", "output": "-80" }, { "input": "8\n93 77 -92 26 21 -48 53 ...
1,570,007,380
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
218
0
n=int(input()) x=input().split() max1=int(x[0]) max2=int(x[0]) min=int(x[0]) for i in range(1,len(x)): if(int(x[i])>max1): max2=max1 max1=int(x[i]) if(int(x[i])<min): min=int(x[i]) if(max1!=max2 and min!=max2): print(max2) else: print("NO")
Title: Second Order Statistics Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis...
```python n=int(input()) x=input().split() max1=int(x[0]) max2=int(x[0]) min=int(x[0]) for i in range(1,len(x)): if(int(x[i])>max1): max2=max1 max1=int(x[i]) if(int(x[i])<min): min=int(x[i]) if(max1!=max2 and min!=max2): print(max2) else: print("NO") ```
0
908
A
New Year and Counting Cards
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a c...
The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit.
Print a single integer, the minimum number of cards you must turn over to verify your claim.
[ "ee\n", "z\n", "0ay1\n" ]
[ "2\n", "0\n", "2\n" ]
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th...
500
[ { "input": "ee", "output": "2" }, { "input": "z", "output": "0" }, { "input": "0ay1", "output": "2" }, { "input": "0abcdefghijklmnopqrstuvwxyz1234567896", "output": "10" }, { "input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b", "output": "18" }, { "input": "01...
1,603,472,328
2,147,483,647
PyPy 3
OK
TESTS
38
155
0
l=['a', 'e', 'i', 'o', 'u'] k=['1','3','5','7','9'] s=input() ans=0 for i in range(len(s)): if s[i] in l : # print(s[i]) ans+=1 elif s[i] in k: # print(s[i]) ans+=1 else: continue print(ans)
Title: New Year and Counting Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each car...
```python l=['a', 'e', 'i', 'o', 'u'] k=['1','3','5','7','9'] s=input() ans=0 for i in range(len(s)): if s[i] in l : # print(s[i]) ans+=1 elif s[i] in k: # print(s[i]) ans+=1 else: continue print(ans) ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,645,166,036
2,147,483,647
Python 3
OK
TESTS
35
92
0
m,n=map(int,input().split()) if m>=1 and m<=n and m<=16: print((m*n)//2)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python m,n=map(int,input().split()) if m>=1 and m<=n and m<=16: print((m*n)//2) ```
3.977
177
B1
Rectangular Game
PROGRAMMING
1,000
[ "number theory" ]
null
null
The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has *n* pebbles. He arranges them in *a* equal rows, each row has *b* pebbles (*a*<=&gt;<=1). Note that the Beaver must use all the pebble...
The single line of the input contains a single integer *n* — the initial number of pebbles the Smart Beaver has. The input limitations for getting 30 points are: - 2<=≤<=*n*<=≤<=50 The input limitations for getting 100 points are: - 2<=≤<=*n*<=≤<=109
Print a single number — the maximum possible result of the game.
[ "10\n", "8\n" ]
[ "16\n", "15\n" ]
Consider the first example (*c*<sub class="lower-index">1</sub> = 10). The possible options for the game development are: - Arrange the pebbles in 10 rows, one pebble per row. Then *c*<sub class="lower-index">2</sub> = 1, and the game ends after the first move with the result of 11. - Arrange the pebbles in 5 rows, ...
30
[ { "input": "10", "output": "16" }, { "input": "8", "output": "15" }, { "input": "4", "output": "7" }, { "input": "36", "output": "67" }, { "input": "32", "output": "63" }, { "input": "46", "output": "70" }, { "input": "6", "output": "10...
1,612,755,295
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS1
3
186
0
n =int(input()) ans=n while n%2==0 and n!=2: n = n//2 ans = ans+n ans=ans+1 print(ans)
Title: Rectangular Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has *n* pebbles. He arranges them in...
```python n =int(input()) ans=n while n%2==0 and n!=2: n = n//2 ans = ans+n ans=ans+1 print(ans) ```
0
961
B
Lecture Sleep
PROGRAMMING
1,200
[ "data structures", "dp", "implementation", "two pointers" ]
null
null
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute. Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ...
The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake. The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theore...
Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
[ "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n" ]
[ "16\n" ]
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
0
[ { "input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0", "output": "16" }, { "input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0", "output": "30000" }, { "input": "3 3\n10 10 10\n1 1 0", "output": "30" }, { "input": "1 1\n423\n0", "output": "423" }, { "input": "6 6\n1 3 5 2 5 4...
1,592,397,606
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
124
0
n,k = map(int,input().split()) a = input() A = list(map(int,list(a.split()))) t = input() T = list(map(int,list(t.split()))) ans = 0 for i in range(n): if T[i] == 1: ans = ans+A[i] A[i] = 0 pre = [0]*(n) pre[0] = A[0] for i in range(1,n): pre[i] = pre[i-1]+A[i] m = 0 for i in rang...
Title: Lecture Sleep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute. Mishka is really interested in calculus, though it is so hard to stay awake for al...
```python n,k = map(int,input().split()) a = input() A = list(map(int,list(a.split()))) t = input() T = list(map(int,list(t.split()))) ans = 0 for i in range(n): if T[i] == 1: ans = ans+A[i] A[i] = 0 pre = [0]*(n) pre[0] = A[0] for i in range(1,n): pre[i] = pre[i-1]+A[i] m = 0 for...
0
680
A
Bear and Five Cards
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer. Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards. He is allowed to at most once discard two or three cards wi...
The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards.
Print the minimum possible sum of numbers written on remaining cards.
[ "7 3 7 3 20\n", "7 9 3 1 8\n", "10 10 10 10 10\n" ]
[ "26\n", "28\n", "20\n" ]
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following. - Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20...
500
[ { "input": "7 3 7 3 20", "output": "26" }, { "input": "7 9 3 1 8", "output": "28" }, { "input": "10 10 10 10 10", "output": "20" }, { "input": "8 7 1 8 7", "output": "15" }, { "input": "7 7 7 8 8", "output": "16" }, { "input": "8 8 8 2 2", "output"...
1,592,037,431
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
l=list(map(int,input().split())) c=list(filter(lambda x:l.count(x)>1,l)) c=list(set(c)) f=[] if c!=[]: d=max(c) if l.count(d)>2: f=f+[sum(l)-3*d)] elif l.count(d)==2: f=f+[sum(l)-2*d)] r=[l.count(i) for i in c] e=d.index(max(r)) if max(r)>2: f=f+[...
Title: Bear and Five Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer. Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers...
```python l=list(map(int,input().split())) c=list(filter(lambda x:l.count(x)>1,l)) c=list(set(c)) f=[] if c!=[]: d=max(c) if l.count(d)>2: f=f+[sum(l)-3*d)] elif l.count(d)==2: f=f+[sum(l)-2*d)] r=[l.count(i) for i in c] e=d.index(max(r)) if max(r)>2: ...
-1
742
A
Arpa’s hard exam and Mehrdad’s naive cheat
PROGRAMMING
1,000
[ "implementation", "math", "number theory" ]
null
null
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*. Mehrdad has become quite confused and wants you to help him. Please help, al...
The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109).
Print single integer — the last digit of 1378*n*.
[ "1\n", "2\n" ]
[ "8", "4" ]
In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8. In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4.
500
[ { "input": "1", "output": "8" }, { "input": "2", "output": "4" }, { "input": "1000", "output": "6" }, { "input": "3", "output": "2" }, { "input": "4", "output": "6" }, { "input": "1000000000", "output": "6" }, { "input": "5", "output": ...
1,677,927,255
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
2,560,000
n = int(input()) paw = pow(1378, n) paw = str(paw) print(paw[len(paw) - 1])
Title: Arpa’s hard exam and Mehrdad’s naive cheat Time Limit: None seconds Memory Limit: None megabytes Problem Description: There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques...
```python n = int(input()) paw = pow(1378, n) paw = str(paw) print(paw[len(paw) - 1]) ```
0
898
C
Phone Numbers
PROGRAMMING
1,400
[ "implementation", "strings" ]
null
null
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a f...
First line contains the integer *n* (1<=≤<=*n*<=≤<=20) — number of entries in Vasya's phone books. The following *n* lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase E...
Print out the ordered information about the phone numbers of Vasya's friends. First output *m* — number of friends that are found in Vasya's phone books. The following *m* lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each...
[ "2\nivan 1 00123\nmasha 1 00123\n", "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612\n", "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789\n" ]
[ "2\nmasha 1 00123 \nivan 1 00123 \n", "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 \n", "2\ndasha 2 23 789 \nivan 4 789 123 2 456 \n" ]
none
1,500
[ { "input": "2\nivan 1 00123\nmasha 1 00123", "output": "2\nmasha 1 00123 \nivan 1 00123 " }, { "input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "output": "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 " }, { "input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndash...
1,590,821,567
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
156
1,331,200
d={} for _ in range(int(input())): v=list(map(str,input().split())) ss=v[0] d[ss]=d.get(ss,set()) d[ss]|=set(v[2:]) print(len(d)) for ss in d: l2=list(d[ss]) for i in range(len(l2)): for j in range(len(l2)): s=str(l2[j]) if len(l2[j])>len(l2[i]...
Title: Phone Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friend...
```python d={} for _ in range(int(input())): v=list(map(str,input().split())) ss=v[0] d[ss]=d.get(ss,set()) d[ss]|=set(v[2:]) print(len(d)) for ss in d: l2=list(d[ss]) for i in range(len(l2)): for j in range(len(l2)): s=str(l2[j]) if len(l2[j])...
0