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
835
A
Key races
PROGRAMMING
800
[ "math" ]
null
null
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *...
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th...
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
[ "5 1 2 1 2\n", "3 3 1 1 1\n", "4 5 3 1 5\n" ]
[ "First\n", "Second\n", "Friendship\n" ]
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ...
500
[ { "input": "5 1 2 1 2", "output": "First" }, { "input": "3 3 1 1 1", "output": "Second" }, { "input": "4 5 3 1 5", "output": "Friendship" }, { "input": "1000 1000 1000 1000 1000", "output": "Friendship" }, { "input": "1 1 1 1 1", "output": "Friendship" }, ...
1,681,817,983
2,147,483,647
PyPy 3-64
OK
TESTS
32
77
0
s,v1,v2,t1,t2 = map(int,input().split()) T1 = s * v1 + 2 * t1 T2 = s * v2 + 2 * t2 if T1 == T2: print('Friendship') elif T1>T2: print('Second') else: print('First')
Title: Key races Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t...
```python s,v1,v2,t1,t2 = map(int,input().split()) T1 = s * v1 + 2 * t1 T2 = s * v2 + 2 * t2 if T1 == T2: print('Friendship') elif T1>T2: print('Second') else: print('First') ```
3
610
B
Vika and Squares
PROGRAMMING
1,300
[ "constructive algorithms", "implementation" ]
null
null
Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*. Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1<=×<=1. Squares are numbered 1, 2, 3 and so on. Vika decided ...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of jars with colors Vika has. The second line of the input contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is equal to the number of liters of paint in the *i*-th jar, i.e. th...
The only line of the output should contain a single integer — the maximum number of squares that Vika can paint if she follows the rules described above.
[ "5\n2 4 2 3 3\n", "3\n5 5 5\n", "6\n10 10 10 1 10 10\n" ]
[ "12\n", "15\n", "11\n" ]
In the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5. In the second sample Vika can start to paint using any color. In the third sample Vika should start painting using color number 5...
1,000
[ { "input": "5\n2 4 2 3 3", "output": "12" }, { "input": "3\n5 5 5", "output": "15" }, { "input": "6\n10 10 10 1 10 10", "output": "11" }, { "input": "1\n167959139", "output": "167959139" }, { "input": "10\n896619242 805194919 844752453 848347723 816995848 85681361...
1,591,612,211
2,147,483,647
PyPy 3
OK
TESTS
66
327
19,046,400
from sys import* def square(a): k = min(a) l = [i for i, x in enumerate(a) if x == k] if(len(l) == 1): return (n*k + (n-1)) else: b =[0]*(len(l)) for i in range(len(l) - 1): b[i] = l[i+1] - l[i] b[len(l) - 1] = (len(a) - l[len(l)-1] + l[0]) return (n*k + (max(b) - 1)) n = int(input()) a = ...
Title: Vika and Squares Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*. Vika also has an infinitely long rectangular piece of paper of...
```python from sys import* def square(a): k = min(a) l = [i for i, x in enumerate(a) if x == k] if(len(l) == 1): return (n*k + (n-1)) else: b =[0]*(len(l)) for i in range(len(l) - 1): b[i] = l[i+1] - l[i] b[len(l) - 1] = (len(a) - l[len(l)-1] + l[0]) return (n*k + (max(b) - 1)) n = int(inpu...
3
1,006
A
Adjacent Replacements
PROGRAMMING
800
[ "implementation" ]
null
null
Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: - Replace each occu...
The first line of the input contains one integer number $n$ ($1 \le n \le 1000$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array.
Print $n$ integers — $b_1, b_2, \dots, b_n$, where $b_i$ is the final value of the $i$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $a$. Note that you cannot change the order of elements in the array.
[ "5\n1 2 4 5 10\n", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\n" ]
[ "1 1 3 5 9\n", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999\n" ]
The first example is described in the problem statement.
0
[ { "input": "5\n1 2 4 5 10", "output": "1 1 3 5 9" }, { "input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000", "output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999" }, { "input": "1\n999999999", "output": "999999999" }, { "input": "1\n1000000000",...
1,635,598,793
2,147,483,647
Python 3
OK
TESTS
18
46
4,505,600
n=int(input()) a=[int(x) for x in input().split()] for i in a: print(i-1+i%2,end=' ')
Title: Adjacent Replacements Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjace...
```python n=int(input()) a=[int(x) for x in input().split()] for i in a: print(i-1+i%2,end=' ') ```
3
631
A
Interview
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109).
Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*.
[ "5\n1 2 4 3 2\n2 3 3 12 1\n", "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n" ]
[ "22", "46" ]
Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation. In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *...
500
[ { "input": "5\n1 2 4 3 2\n2 3 3 12 1", "output": "22" }, { "input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6", "output": "46" }, { "input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 9...
1,585,948,234
2,147,483,647
Python 3
OK
TESTS
27
93
307,200
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()) #--------------------------------WhiteHat010----------...
Title: Interview Time Limit: None seconds Memory Limit: None megabytes Problem Description: Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of...
```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()) #--------------------------------WhiteHat010...
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,629,309,450
2,147,483,647
Python 3
OK
TESTS
40
93
6,758,400
def f(s, slovo): if slovo == "": return True elif s == "": return False b = False for i in range(len(s)): if s[i] == slovo[0]: b += f(s[i+1:], slovo[1:]) return b s = input() if f(s, "hello"): 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 def f(s, slovo): if slovo == "": return True elif s == "": return False b = False for i in range(len(s)): if s[i] == slovo[0]: b += f(s[i+1:], slovo[1:]) return b s = input() if f(s, "hello"): print("YES") else: print("NO") ```
3.940911
224
A
Parallelepiped
PROGRAMMING
1,100
[ "brute force", "geometry", "math" ]
null
null
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number — the sum of all edges of the parallelepiped.
[ "1 1 1\n", "4 6 6\n" ]
[ "12\n", "28\n" ]
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
500
[ { "input": "1 1 1", "output": "12" }, { "input": "4 6 6", "output": "28" }, { "input": "20 10 50", "output": "68" }, { "input": "9 4 36", "output": "56" }, { "input": "324 9 36", "output": "184" }, { "input": "1333 93 129", "output": "308" }, {...
1,554,469,583
2,147,483,647
Python 3
OK
TESTS
27
216
0
import math an = list(map(int, input().split())) a = int(math.sqrt(an[1]*an[2]/an[0])*an[0]/an[1]) b = int(math.sqrt(an[1]*an[2]/an[0])*an[0]/an[2]) c = int(math.sqrt(an[1]*an[2]/an[0])) print(str(a*4+b*4+c*4))
Title: Parallelepiped Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input S...
```python import math an = list(map(int, input().split())) a = int(math.sqrt(an[1]*an[2]/an[0])*an[0]/an[1]) b = int(math.sqrt(an[1]*an[2]/an[0])*an[0]/an[2]) c = int(math.sqrt(an[1]*an[2]/an[0])) print(str(a*4+b*4+c*4)) ```
3
791
A
Bear and Big Brother
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's we...
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
[ "4 7\n", "4 9\n", "1 1\n" ]
[ "2\n", "3\n", "1\n" ]
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li...
500
[ { "input": "4 7", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "1 1", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "1 10", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output...
1,695,734,649
2,147,483,647
PyPy 3-64
OK
TESTS
62
62
0
a, b = map(int, input().split()) years = 0 i = 0 while True: if a <= b: a *= 3 b *= 2 if a > b: years += (i + 1) break i += 1 print(years)
Title: Bear and Big Brother Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e...
```python a, b = map(int, input().split()) years = 0 i = 0 while True: if a <= b: a *= 3 b *= 2 if a > b: years += (i + 1) break i += 1 print(years) ```
3
5
A
Chat Servers Outgoing Traffic
PROGRAMMING
1,000
[ "implementation" ]
A. Chat Server's Outgoing Traffic
1
64
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: - Include a person...
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: - +&lt;name&gt; for 'Add' command. - -&lt;name&gt; for 'Remove' command. - &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;s...
Print a single number — answer to the problem.
[ "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n" ]
[ "9\n", "14\n" ]
none
0
[ { "input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "output": "9" }, { "input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate", "output": "14" }, { "input": "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIO...
1,493,280,321
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
5,529,600
# -*- coding: utf-8 -*- f = open('input.txt', 'r', encoding="utf-8") x = f.readline().rstrip('\n') s = 0 while x!='': if x[0]!='+' and x[0]!='-': i = x.index(':') s += len(x[i+1:]) x = f.readline().rstrip('\n') print(s) f.close()
Title: Chat Servers Outgoing Traffic Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in fr...
```python # -*- coding: utf-8 -*- f = open('input.txt', 'r', encoding="utf-8") x = f.readline().rstrip('\n') s = 0 while x!='': if x[0]!='+' and x[0]!='-': i = x.index(':') s += len(x[i+1:]) x = f.readline().rstrip('\n') print(s) f.close() ```
-1
776
B
Sherlock and his girlfriend
PROGRAMMING
1,200
[ "constructive algorithms", "number theory" ]
null
null
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry. He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1. Watson gave Sherlock a challenge to color these jewelry pie...
The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces.
The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints. The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price. ...
[ "3\n", "4\n" ]
[ "2\n1 1 2 ", "2\n2 1 1 2\n" ]
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively. In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.
1,000
[ { "input": "3", "output": "2\n1 1 2 " }, { "input": "4", "output": "2\n1 1 2 1 " }, { "input": "17", "output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 " }, { "input": "25", "output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 " }, { "input": "85", "ou...
1,679,736,512
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
# LUOGU_RID: 105867500 n = int(input()) # 筛法求素数 is_prime = [True] * (n + 2) is_prime[0] = is_prime[1] = False for i in range(2, int(n**0.5) + 1): if is_prime[i]: for j in range(i * i, n + 2, i): is_prime[j] = False # 并查集 fa = list(range(n + 2)) def find(x): if x != fa[x]: fa[x] = f...
Title: Sherlock and his girlfriend Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry. He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the ...
```python # LUOGU_RID: 105867500 n = int(input()) # 筛法求素数 is_prime = [True] * (n + 2) is_prime[0] = is_prime[1] = False for i in range(2, int(n**0.5) + 1): if is_prime[i]: for j in range(i * i, n + 2, i): is_prime[j] = False # 并查集 fa = list(range(n + 2)) def find(x): if x != fa[x]: ...
0
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", ...
1,581,795,667
2,147,483,647
Python 3
OK
TESTS
36
342
1,228,800
from fractions import Fraction throws_of_dice = [int(i) for i in input().split()] maximum = max(throws_of_dice) higher_numbers_that_can_get = 7 - maximum probability = Fraction(higher_numbers_that_can_get, 6) if probability == 0: probability = "0/1" if probability == 1: probability = "1/1" print(probability...
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T...
```python from fractions import Fraction throws_of_dice = [int(i) for i in input().split()] maximum = max(throws_of_dice) higher_numbers_that_can_get = 7 - maximum probability = Fraction(higher_numbers_that_can_get, 6) if probability == 0: probability = "0/1" if probability == 1: probability = "1/1" print(p...
3.819845
803
B
Distances to Zero
PROGRAMMING
1,200
[ "constructive algorithms" ]
null
null
You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.
The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — length of the array *a*. The second line contains integer elements of the array separated by single spaces (<=-<=109<=≤<=*a**i*<=≤<=109).
Print the sequence *d*0,<=*d*1,<=...,<=*d**n*<=-<=1, where *d**i* is the difference of indices between *i* and nearest *j* such that *a**j*<==<=0. It is possible that *i*<==<=*j*.
[ "9\n2 1 0 3 0 0 3 2 4\n", "5\n0 1 2 3 4\n", "7\n5 6 0 1 -2 3 4\n" ]
[ "2 1 0 1 0 0 1 2 3 ", "0 1 2 3 4 ", "2 1 0 1 2 3 4 " ]
none
0
[ { "input": "9\n2 1 0 3 0 0 3 2 4", "output": "2 1 0 1 0 0 1 2 3 " }, { "input": "5\n0 1 2 3 4", "output": "0 1 2 3 4 " }, { "input": "7\n5 6 0 1 -2 3 4", "output": "2 1 0 1 2 3 4 " }, { "input": "1\n0", "output": "0 " }, { "input": "2\n0 0", "output": "0 0 " ...
1,595,923,585
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
0
2,000
6,963,200
while 1: print("**/88",end=" ")
Title: Distances to Zero Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the give...
```python while 1: print("**/88",end=" ") ```
0
748
A
Santa Claus and a Place in a Class
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar...
The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.
Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.
[ "4 3 9\n", "4 3 24\n", "2 4 4\n" ]
[ "2 2 L\n", "4 3 R\n", "1 2 R\n" ]
The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his pla...
500
[ { "input": "4 3 9", "output": "2 2 L" }, { "input": "4 3 24", "output": "4 3 R" }, { "input": "2 4 4", "output": "1 2 R" }, { "input": "3 10 24", "output": "2 2 R" }, { "input": "10 3 59", "output": "10 3 L" }, { "input": "10000 10000 160845880", "...
1,489,576,757
2,147,483,647
Python 3
OK
TESTS
46
62
4,608,000
n,m,k=map(int,input().split()) x=k print((k-1)//(m*2)+1,end=' ') k=(k-1)%(m*2) print(k//2+1,end=" ") if x%2==0: print("R") else: print("L")
Title: Santa Claus and a Place in a Class Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two work...
```python n,m,k=map(int,input().split()) x=k print((k-1)//(m*2)+1,end=' ') k=(k-1)%(m*2) print(k//2+1,end=" ") if x%2==0: print("R") else: print("L") ```
3
13
C
Sequence
PROGRAMMING
2,200
[ "dp", "sortings" ]
C. Sequence
1
64
Little Petya likes to play very much. And most of all he likes to play the following game: He is given a sequence of *N* integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. The goal of the game is to make the sequence non-decreasing with the smallest number of s...
The first line of the input contains single integer *N* (1<=≤<=*N*<=≤<=5000) — the length of the initial sequence. The following *N* lines contain one integer each — elements of the sequence. These numbers do not exceed 109 by absolute value.
Output one integer — minimum number of steps required to achieve the goal.
[ "5\n3 2 -1 2 11\n", "5\n2 1 1 1 1\n" ]
[ "4\n", "1\n" ]
none
0
[ { "input": "5\n3 2 -1 2 11", "output": "4" }, { "input": "5\n2 1 1 1 1", "output": "1" }, { "input": "5\n0 0 0 0 0", "output": "0" }, { "input": "1\n11", "output": "0" }, { "input": "2\n10 2", "output": "8" }, { "input": "6\n1000000000 -1000000000 1000...
1,574,837,463
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
218
0
n = int(input()) a = [*map(int, input().split())] best_ans = 10**9 for i in range(n): acopy = a.copy() ans = 0 for j in range(i - 1, -1, -1): if acopy[j] < acopy[j + 1]: continue ans += acopy[j] - acopy[j + 1] acopy[j] = acopy[j + 1] for j in range(i + 1, n): ...
Title: Sequence Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Little Petya likes to play very much. And most of all he likes to play the following game: He is given a sequence of *N* integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. ...
```python n = int(input()) a = [*map(int, input().split())] best_ans = 10**9 for i in range(n): acopy = a.copy() ans = 0 for j in range(i - 1, -1, -1): if acopy[j] < acopy[j + 1]: continue ans += acopy[j] - acopy[j + 1] acopy[j] = acopy[j + 1] for j in range(i + 1, n)...
0
271
A
Beautiful Year
PROGRAMMING
800
[ "brute force" ]
null
null
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on...
The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number.
Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists.
[ "1987\n", "2013\n" ]
[ "2013\n", "2014\n" ]
none
500
[ { "input": "1987", "output": "2013" }, { "input": "2013", "output": "2014" }, { "input": "1000", "output": "1023" }, { "input": "1001", "output": "1023" }, { "input": "1234", "output": "1235" }, { "input": "5555", "output": "5601" }, { "inp...
1,695,035,984
2,147,483,647
PyPy 3
OK
TESTS
27
154
0
n=int(input()) for i in range(n+1,10000): k=str(i); if len(set(k))==len(k): u=i; break; print(u);
Title: Beautiful Year Time Limit: None seconds Memory Limit: None megabytes Problem Description: It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: give...
```python n=int(input()) for i in range(n+1,10000): k=str(i); if len(set(k))==len(k): u=i; break; print(u); ```
3
0
none
none
none
0
[ "none" ]
null
null
You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones. Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$. You can apply the following operations any number of times: - Choose some substring of string $a$ (for examp...
The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $a$ of length $n$, consist...
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations.
[ "5 1 10\n01000\n", "5 10 1\n01000\n", "7 2 3\n1111111\n" ]
[ "11\n", "2\n", "0\n" ]
In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$. Then the string was changed as follows: «01000» $\to$ «10000» $\to$ «11111». The total cost of operations is $1 + 10 = 11$. In the second sample, at first you need to invert substring $[1...
0
[ { "input": "5 1 10\n01000", "output": "11" }, { "input": "5 10 1\n01000", "output": "2" }, { "input": "7 2 3\n1111111", "output": "0" }, { "input": "1 60754033 959739508\n0", "output": "959739508" }, { "input": "1 431963980 493041212\n1", "output": "0" }, ...
1,532,579,957
2,147,483,647
Python 3
OK
TESTS
115
327
1,024,000
n,x,y = map(int,input().split()) s = input() # x = cost of reverse # y = cost of invert chains = 0 zero = False for i in range(n): if not zero and s[i] == "0": zero = True elif not zero and s[i] == "1": continue elif zero and s[i] == "0": continue elif zero and s[i] == "1": ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones. Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$. You can apply the fo...
```python n,x,y = map(int,input().split()) s = input() # x = cost of reverse # y = cost of invert chains = 0 zero = False for i in range(n): if not zero and s[i] == "0": zero = True elif not zero and s[i] == "1": continue elif zero and s[i] == "0": continue elif zero and s[i] ...
3
663
A
Rebus
PROGRAMMING
1,800
[ "constructive algorithms", "expression parsing", "greedy", "math" ]
null
null
You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer *n*. The goal is to replace each question mark with some positive integer from 1 to *n*, such that equality holds.
The only line of the input contains a rebus. It's guaranteed that it contains no more than 100 question marks, integer *n* is positive and doesn't exceed 1<=000<=000, all letters and integers are separated by spaces, arithmetic operations are located only between question marks.
The first line of the output should contain "Possible" (without quotes) if rebus has a solution and "Impossible" (without quotes) otherwise. If the answer exists, the second line should contain any valid rebus with question marks replaced by integers from 1 to *n*. Follow the format given in the samples.
[ "? + ? - ? + ? + ? = 42\n", "? - ? = 1\n", "? = 1000000\n" ]
[ "Possible\n9 + 13 - 39 + 28 + 31 = 42\n", "Impossible\n", "Possible\n1000000 = 1000000\n" ]
none
500
[ { "input": "? + ? - ? + ? + ? = 42", "output": "Possible\n1 + 1 - 1 + 1 + 40 = 42" }, { "input": "? - ? = 1", "output": "Impossible" }, { "input": "? = 1000000", "output": "Possible\n1000000 = 1000000" }, { "input": "? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? +...
1,572,972,612
612
Python 3
OK
TESTS
31
124
307,200
s = input().split() t = s[::] req = int(s[-1]) lim = req S = 0 for i in range(len(s)): if s[i] == '?': s[i] = '1' S += 1 if i == 0 or s[i - 1] == '+' else -1 if S < req: for i in range(len(s)): if t[i] == '?': sign = 1 if i == 0 or s[i - 1] == '+' else -1 if sign == 1: d = min(req - S, lim - 1) s...
Title: Rebus Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer *n*. The goal is to replace each question mark with some positive in...
```python s = input().split() t = s[::] req = int(s[-1]) lim = req S = 0 for i in range(len(s)): if s[i] == '?': s[i] = '1' S += 1 if i == 0 or s[i - 1] == '+' else -1 if S < req: for i in range(len(s)): if t[i] == '?': sign = 1 if i == 0 or s[i - 1] == '+' else -1 if sign == 1: d = min(req - S, lim ...
3
588
B
Duff in Love
PROGRAMMING
1,300
[ "math" ]
null
null
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=&gt;<=1 such that *a*2 is a divisor of *x*. Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek want...
The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012).
Print the answer in one line.
[ "10\n", "12\n" ]
[ "10\n", "6\n" ]
In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely. In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely.
1,000
[ { "input": "10", "output": "10" }, { "input": "12", "output": "6" }, { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "4", "output": "2" }, { "input": "8", "output": "2" }, { "input": "3", "output": "3" }, ...
1,607,338,983
2,147,483,647
Python 3
OK
TESTS
53
1,356
307,200
def solve(n): t = [] i = 1 while i * i <= n : if n % i == 0 : if n // i == i : t.append(i) else: t.append(i) t.append(n//i) i += 1 return t n = int(input()) r = solve(n) r2 = list(reversed(sorted(...
Title: Duff in Love Time Limit: None seconds Memory Limit: None megabytes Problem Description: Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=&gt;<=1 such that *a*2 is a divisor of *x*. Malek has a number store! In his store, he has...
```python def solve(n): t = [] i = 1 while i * i <= n : if n % i == 0 : if n // i == i : t.append(i) else: t.append(i) t.append(n//i) i += 1 return t n = int(input()) r = solve(n) r2 = list(revers...
3
851
A
Arpa and a research in Mexican wave
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Arpa is researching the Mexican wave. There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0. - At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-t...
The first line contains three integers *n*, *k*, *t* (1<=≤<=*n*<=≤<=109, 1<=≤<=*k*<=≤<=*n*, 1<=≤<=*t*<=&lt;<=*n*<=+<=*k*).
Print single integer: how many spectators are standing at time *t*.
[ "10 5 3\n", "10 5 7\n", "10 5 12\n" ]
[ "3\n", "5\n", "3\n" ]
In the following a sitting spectator is represented as -, a standing spectator is represented as ^. - At *t* = 0  ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spe...
500
[ { "input": "10 5 3", "output": "3" }, { "input": "10 5 7", "output": "5" }, { "input": "10 5 12", "output": "3" }, { "input": "840585600 770678331 788528791", "output": "770678331" }, { "input": "25462281 23343504 8024619", "output": "8024619" }, { "in...
1,552,857,828
2,147,483,647
Python 3
OK
TESTS
166
124
0
n, k ,t = map(int, input().split()) if 0<=t<=k: print(t) elif k<t<=n: print(k) elif t<=n+k-1: print(n+k-t) else: print(0) #116557440 #230150037 #966696824 346707476 1196846860 #0 k-1 #n-k s stay #n+k-1
Title: Arpa and a research in Mexican wave Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arpa is researching the Mexican wave. There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0. - At time 1, the first spectator stands. - At time 2,...
```python n, k ,t = map(int, input().split()) if 0<=t<=k: print(t) elif k<t<=n: print(k) elif t<=n+k-1: print(n+k-t) else: print(0) #116557440 #230150037 #966696824 346707476 1196846860 #0 k-1 #n-k s stay #n+k-1 ```
3
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo...
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "ou...
1,631,244,019
2,147,483,647
Python 3
OK
TESTS
59
77
6,758,400
from math import factorial as fact a,b=list(map(int,input().split())) print(fact(min(a,b)))
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi...
```python from math import factorial as fact a,b=list(map(int,input().split())) print(fact(min(a,b))) ```
3
495
B
Modular Equations
PROGRAMMING
1,600
[ "math", "number theory" ]
null
null
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and...
In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given.
If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation .
[ "21 5\n", "9435152 272\n", "10 10\n" ]
[ "2\n", "282\n", "infinity\n" ]
In the first sample the answers of the Modular Equation are 8 and 16 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "21 5", "output": "2" }, { "input": "9435152 272", "output": "282" }, { "input": "10 10", "output": "infinity" }, { "input": "0 1000000000", "output": "0" }, { "input": "11 2", "output": "2" }, { "input": "1 0", "output": "1" }, { ...
1,584,923,654
2,147,483,647
PyPy 3
OK
TESTS
37
140
1,228,800
arr = [int(x) for x in input().split()] a = arr[0] b = arr[1] resp = 0 if a == b: resp = 'infinity' if resp != 'infinity': x = a - b i = 1 c = 0 while i**2 < x: c += 1 if x % i == 0: if i > b: resp += 1 if x/i > b: resp += 1 i += 1 if i**2 == x and i > b: resp += ...
Title: Modular Equations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed'...
```python arr = [int(x) for x in input().split()] a = arr[0] b = arr[1] resp = 0 if a == b: resp = 'infinity' if resp != 'infinity': x = a - b i = 1 c = 0 while i**2 < x: c += 1 if x % i == 0: if i > b: resp += 1 if x/i > b: resp += 1 i += 1 if i**2 == x and i > b: ...
3
11
A
Increasing Sequence
PROGRAMMING
900
[ "constructive algorithms", "implementation", "math" ]
A. Increasing Sequence
1
64
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least...
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output the minimal number of moves needed to make the sequence increasing.
[ "4 2\n1 3 3 2\n" ]
[ "3\n" ]
none
0
[ { "input": "4 2\n1 3 3 2", "output": "3" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 1\n2 5", "output": "0" }, { "input": "2 1\n1 2", "output": "0" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 7\n10 20", "output": "0" }, ...
1,692,252,366
2,147,483,647
Python 3
OK
TESTS
25
62
0
arr = input().split() n = int(arr[0]) d = int(arr[1]) a = input().split() ans = int(0) pre = int(-1) # a.sort() for i in a: i = int(i) # print(i, end = ', ') x = 0 if i <= pre: x = (pre-i + d) // d ans = ans + x pre = i + x*d # print(pre, end = '\n') print(ans) ...
Title: Increasing Sequence Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*...
```python arr = input().split() n = int(arr[0]) d = int(arr[1]) a = input().split() ans = int(0) pre = int(-1) # a.sort() for i in a: i = int(i) # print(i, end = ', ') x = 0 if i <= pre: x = (pre-i + d) // d ans = ans + x pre = i + x*d # print(pre, end = '\n') print(ans) ...
3.969
892
B
Wrath
PROGRAMMING
1,200
[ "greedy", "implementation", "two pointers" ]
null
null
Hands that shed innocent blood! There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=&lt;<=*i* and *...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — the number of guilty people. Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=≤<=*L**i*<=≤<=109), where *L**i* is the length of the *i*-th person's claw.
Print one integer — the total number of alive people after the bell rings.
[ "4\n0 1 0 10\n", "2\n0 0\n", "10\n1 1 3 0 0 0 2 1 0 3\n" ]
[ "1\n", "2\n", "3\n" ]
In first sample the last person kills everyone in front of him.
1,000
[ { "input": "4\n0 1 0 10", "output": "1" }, { "input": "2\n0 0", "output": "2" }, { "input": "10\n1 1 3 0 0 0 2 1 0 3", "output": "3" }, { "input": "10\n0 0 2 0 0 3 3 2 2 0", "output": "2" }, { "input": "1\n0", "output": "1" }, { "input": "5\n0 0 0 1 0"...
1,517,193,586
2,147,483,647
Python 3
OK
TESTS
43
1,248
82,432,000
inp=lambda:map(int,input().split()) n=int(input()) l=list(inp()) m=[1000000]*(10**6+1) for i in range(n-1,-1,-1): m[i]=min(m[i+1],i-l[i]) cnt=0 for i in range(0,n): if(m[i+1]>i) : cnt+=1 print(cnt)
Title: Wrath Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hands that shed innocent blood! There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same ...
```python inp=lambda:map(int,input().split()) n=int(input()) l=list(inp()) m=[1000000]*(10**6+1) for i in range(n-1,-1,-1): m[i]=min(m[i+1],i-l[i]) cnt=0 for i in range(0,n): if(m[i+1]>i) : cnt+=1 print(cnt) ```
3
104
A
Blackjack
PROGRAMMING
800
[ "implementation" ]
A. Blackjack
2
256
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to...
The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points.
Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.
[ "12\n", "20\n", "10\n" ]
[ "4", "15", "0" ]
In the first sample only four two's of different suits can earn the required sum of points. In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use. In the third sample there ...
500
[ { "input": "12", "output": "4" }, { "input": "20", "output": "15" }, { "input": "10", "output": "0" }, { "input": "11", "output": "4" }, { "input": "15", "output": "4" }, { "input": "18", "output": "4" }, { "input": "25", "output": "0" ...
1,545,301,497
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
218
0
n = int(input()) l = [2, 3, 4, 5, 6, 7, 8, 9] if n <= 10: print(0) elif 11 == n or 21 == n: print(1) elif 20 == n: print(15) else: for i in l: if n == 10 + i: print(4) break else: print(0)
Title: Blackjack Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Co...
```python n = int(input()) l = [2, 3, 4, 5, 6, 7, 8, 9] if n <= 10: print(0) elif 11 == n or 21 == n: print(1) elif 20 == n: print(15) else: for i in l: if n == 10 + i: print(4) break else: print(0) ```
0
579
A
Raising Bacteria
PROGRAMMING
1,000
[ "bitmasks" ]
null
null
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment. What is the mini...
The only line containing one integer *x* (1<=≤<=*x*<=≤<=109).
The only line containing one integer: the answer.
[ "5\n", "8\n" ]
[ "2\n", "1\n" ]
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th ...
250
[ { "input": "5", "output": "2" }, { "input": "8", "output": "1" }, { "input": "536870911", "output": "29" }, { "input": "1", "output": "1" }, { "input": "343000816", "output": "14" }, { "input": "559980448", "output": "12" }, { "input": "697...
1,663,433,979
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
30
0
import sys input = sys.stdin.readline target = int(input()) if target % 2 == 0: print(1) else: print(2)
Title: Raising Bacteria Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split...
```python import sys input = sys.stdin.readline target = int(input()) if target % 2 == 0: print(1) else: print(2) ```
0
916
B
Jamie and Binary Sequence (changed after round)
PROGRAMMING
2,000
[ "bitmasks", "greedy", "math" ]
null
null
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find *k* integers such that the sum of two to the power of each number equals to the number *n* and the largest integer in the answer is as small as possible. ...
The first line consists of two integers *n* and *k* (1<=≤<=*n*<=≤<=1018,<=1<=≤<=*k*<=≤<=105) — the required sum and the length of the sequence.
Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and *k* numbers separated by space in the second line — the required sequence. It is guaranteed that the integers in the answer sequence fit the range [<=-<=1018,<=1018].
[ "23 5\n", "13 2\n", "1 2\n" ]
[ "Yes\n3 3 2 1 0 \n", "No\n", "Yes\n-1 -1 \n" ]
Sample 1: 2<sup class="upper-index">3</sup> + 2<sup class="upper-index">3</sup> + 2<sup class="upper-index">2</sup> + 2<sup class="upper-index">1</sup> + 2<sup class="upper-index">0</sup> = 8 + 8 + 4 + 2 + 1 = 23 Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest. Answers like (4, 1, 1...
1,000
[ { "input": "23 5", "output": "Yes\n3 3 2 1 0 " }, { "input": "13 2", "output": "No" }, { "input": "1 2", "output": "Yes\n-1 -1 " }, { "input": "1 1", "output": "Yes\n0 " }, { "input": "1000000000000000000 100000", "output": "Yes\n44 44 44 44 44 44 44 44 44 44 ...
1,517,118,579
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
62
19,865,600
read = lambda: map(int, input().split()) n, k = read() b = bin(n)[2:] bl = len(b) k -= b.count('1') if k < 0: print('No') exit() print('Yes') m = -2 a = {} for _ in range(bl): if b[_] == '1': a[bl - _ - 1] = 1 if m is -2: m = bl - _ - 1 while k > 0: if k >= a[m]: k -=...
Title: Jamie and Binary Sequence (changed after round) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find *k* integers such tha...
```python read = lambda: map(int, input().split()) n, k = read() b = bin(n)[2:] bl = len(b) k -= b.count('1') if k < 0: print('No') exit() print('Yes') m = -2 a = {} for _ in range(bl): if b[_] == '1': a[bl - _ - 1] = 1 if m is -2: m = bl - _ - 1 while k > 0: if k >= a[m]: ...
0
225
B
Well-known Numbers
PROGRAMMING
1,600
[ "binary search", "greedy", "number theory" ]
null
null
Numbers *k*-bonacci (*k* is integer, *k*<=&gt;<=1) are a generalization of Fibonacci numbers and are determined as follows: - *F*(*k*,<=*n*)<==<=0, for integer *n*, 1<=≤<=*n*<=&lt;<=*k*; - *F*(*k*,<=*k*)<==<=1; - *F*(*k*,<=*n*)<==<=*F*(*k*,<=*n*<=-<=1)<=+<=*F*(*k*,<=*n*<=-<=2)<=+<=...<=+<=*F*(*k*,<=*n*<=-<=*k*), fo...
The first line contains two integers *s* and *k* (1<=≤<=*s*,<=*k*<=≤<=109; *k*<=&gt;<=1).
In the first line print an integer *m* (*m*<=≥<=2) that shows how many numbers are in the found representation. In the second line print *m* distinct integers *a*1,<=*a*2,<=...,<=*a**m*. Each printed integer should be a *k*-bonacci number. The sum of printed integers must equal *s*. It is guaranteed that the answer ex...
[ "5 2\n", "21 5\n" ]
[ "3\n0 2 3\n", "3\n4 1 16\n" ]
none
1,000
[ { "input": "5 2", "output": "3\n0 2 3" }, { "input": "21 5", "output": "3\n4 1 16" }, { "input": "1 1000", "output": "2\n1 0 " }, { "input": "1000000000 1000000000", "output": "14\n536870912 268435456 134217728 33554432 16777216 8388608 1048576 524288 131072 32768 16384 2...
1,594,331,934
2,147,483,647
Python 3
OK
TESTS
70
218
6,963,200
s,k=map(int,input().split()) f=[0] f.append(1) while(True): cur=sum(f[-k:]) if cur>s: break f.append(cur) f=list(set(f)) f.sort() ans=[] i=len(f)-1 while(s and i>0): if f[i]<=s: s-=f[i] ans.append(f[i]) i-=1 print(len(ans)+1) print(*(ans+[0])) #Copied
Title: Well-known Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Numbers *k*-bonacci (*k* is integer, *k*<=&gt;<=1) are a generalization of Fibonacci numbers and are determined as follows: - *F*(*k*,<=*n*)<==<=0, for integer *n*, 1<=≤<=*n*<=&lt;<=*k*; - *F*(*k*,<=*k*)<==<=1; - ...
```python s,k=map(int,input().split()) f=[0] f.append(1) while(True): cur=sum(f[-k:]) if cur>s: break f.append(cur) f=list(set(f)) f.sort() ans=[] i=len(f)-1 while(s and i>0): if f[i]<=s: s-=f[i] ans.append(f[i]) i-=1 print(len(ans)+1) print(*(ans+[0])) #...
3
55
A
Flea travel
PROGRAMMING
1,200
[ "implementation", "math" ]
A. Flea travel
1
256
A flea is sitting at one of the *n* hassocks, arranged in a circle, at the moment. After minute number *k* the flea jumps through *k*<=-<=1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: will the flea visit all the hassocks or not. We assume that ...
The only line contains single integer: 1<=≤<=*n*<=≤<=1000 — number of hassocks.
Output "YES" if all the hassocks will be visited and "NO" otherwise.
[ "1\n", "3\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "1", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "YES" }, { "input": "4", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "NO" }, { "input": "7", "output": "NO...
1,505,674,572
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
4,608,000
a=int(input()) b=bin(a) z=b.count("1") if z%2==0: print("NO") else: print("YES")
Title: Flea travel Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: A flea is sitting at one of the *n* hassocks, arranged in a circle, at the moment. After minute number *k* the flea jumps through *k*<=-<=1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighbo...
```python a=int(input()) b=bin(a) z=b.count("1") if z%2==0: print("NO") else: print("YES") ```
0
734
A
Anton and Danik
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*...
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes).
[ "6\nADAAAA\n", "7\nDDDAADA\n", "6\nDADADA\n" ]
[ "Anton\n", "Danik\n", "Friendship\n" ]
In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
500
[ { "input": "6\nADAAAA", "output": "Anton" }, { "input": "7\nDDDAADA", "output": "Danik" }, { "input": "6\nDADADA", "output": "Friendship" }, { "input": "10\nDDDDADDADD", "output": "Danik" }, { "input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA", "output": ...
1,695,909,460
2,147,483,647
Python 3
OK
TESTS
25
46
102,400
n = int(input()) s = input() numa, numd = 0, 0 for i in s: if i == 'A': numa += 1 else: numd += 1 if numa > numd: print("Anton") elif numa < numd: print("Danik") else: print("Friendship")
Title: Anton and Danik Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, w...
```python n = int(input()) s = input() numa, numd = 0, 0 for i in s: if i == 'A': numa += 1 else: numd += 1 if numa > numd: print("Anton") elif numa < numd: print("Danik") else: print("Friendship") ```
3
459
C
Pashmak and Buses
PROGRAMMING
1,900
[ "combinatorics", "constructive algorithms", "math" ]
null
null
Recently Pashmak has been employed in a transportation company. The company has *k* buses and has a contract with a school which has *n* students. The school planned to take the students to *d* different places for *d* days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has t...
The first line of input contains three space-separated integers *n*,<=*k*,<=*d* (1<=≤<=*n*,<=*d*<=≤<=1000; 1<=≤<=*k*<=≤<=109).
If there is no valid arrangement just print -1. Otherwise print *d* lines, in each of them print *n* integers. The *j*-th integer of the *i*-th line shows which bus the *j*-th student has to take on the *i*-th day. You can assume that the buses are numbered from 1 to *k*.
[ "3 2 2\n", "3 2 1\n" ]
[ "1 1 2 \n1 2 1 \n", "-1\n" ]
Note that two students become close friends only if they share a bus each day. But the bus they share can differ from day to day.
2,000
[ { "input": "3 2 2", "output": "1 1 2 \n1 2 1 " }, { "input": "3 2 1", "output": "-1" }, { "input": "7 2 3", "output": "1 1 1 1 2 2 2 \n1 1 2 2 1 1 2 \n1 2 1 2 1 2 1 " }, { "input": "9 2 3", "output": "-1" }, { "input": "2 1 1000", "output": "-1" }, { "...
1,669,877,903
2,147,483,647
PyPy 3
OK
TESTS
41
639
17,408,000
from collections import defaultdict, deque, Counter from functools import lru_cache, reduce from heapq import heappush, heappop, heapify from bisect import bisect_right, bisect_left from random import randint import math import operator import sys from itertools import accumulate #sys.stdin = open("sleepy.in", "r") #...
Title: Pashmak and Buses Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Pashmak has been employed in a transportation company. The company has *k* buses and has a contract with a school which has *n* students. The school planned to take the students to *d* different places for *d...
```python from collections import defaultdict, deque, Counter from functools import lru_cache, reduce from heapq import heappush, heappop, heapify from bisect import bisect_right, bisect_left from random import randint import math import operator import sys from itertools import accumulate #sys.stdin = open("sleepy.i...
3
639
B
Bear and Forgotten Tree 3
PROGRAMMING
1,600
[ "constructive algorithms", "graphs", "trees" ]
null
null
A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell...
The first line contains three integers *n*, *d* and *h* (2<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*h*<=≤<=*d*<=≤<=*n*<=-<=1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively.
If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes). Otherwise, describe any tree matching Limak's description. Print *n*<=-<=1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. Y...
[ "5 3 2\n", "8 5 2\n", "8 4 2\n" ]
[ "1 2\n1 3\n3 4\n3 5", "-1\n", "4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5\n" ]
Below you can see trees printed to the output in the first sample and the third sample.
750
[ { "input": "5 3 2", "output": "1 2\n2 3\n1 4\n5 1" }, { "input": "8 5 2", "output": "-1" }, { "input": "8 4 2", "output": "4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5" }, { "input": "2 1 1", "output": "1 2" }, { "input": "10 3 3", "output": "1 2\n2 3\n3 4\n5 2\n6 2\n7 2...
1,637,318,570
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
9
217
9,318,400
n,d,h = map(int, input().split()) if d > 2*h: print(-1) else: if d == h: node1 = 1 node2 = 2 for i in range(h): print(node1, node2) node1 += 1 node2 += 1 node1 = h node2 = h+2 while node2 <= n: print(no...
Title: Bear and Forgotten Tree 3 Time Limit: None seconds Memory Limit: None megabytes Problem Description: A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a t...
```python n,d,h = map(int, input().split()) if d > 2*h: print(-1) else: if d == h: node1 = 1 node2 = 2 for i in range(h): print(node1, node2) node1 += 1 node2 += 1 node1 = h node2 = h+2 while node2 <= n: ...
0
552
B
Vanya and Books
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers. Vanya wants to know how many digits he will have to write down as he labels th...
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Print the number of digits needed to number all the books.
[ "13\n", "4\n" ]
[ "17\n", "4\n" ]
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits. Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
1,000
[ { "input": "13", "output": "17" }, { "input": "4", "output": "4" }, { "input": "100", "output": "192" }, { "input": "99", "output": "189" }, { "input": "1000000000", "output": "8888888899" }, { "input": "1000000", "output": "5888896" }, { "...
1,596,862,180
2,147,483,647
Python 3
OK
TESTS
55
109
6,656,000
a=int(input()) digits=0 rem=0 for i in range(len(str(a))-1): f=(int(str(9)*(i+1))-rem) digits+=f*(i+1) rem += f print(digits+(a-rem)*len(str(a)))
Title: Vanya and Books Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assig...
```python a=int(input()) digits=0 rem=0 for i in range(len(str(a))-1): f=(int(str(9)*(i+1))-rem) digits+=f*(i+1) rem += f print(digits+(a-rem)*len(str(a))) ```
3
620
A
Professor GukiZ's Robot
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal numbe...
The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot. The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot.
Print the only integer *d* — the minimal number of steps to get the finish position.
[ "0 0\n4 5\n", "3 4\n6 1\n" ]
[ "5\n", "3\n" ]
In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position. In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one th...
0
[ { "input": "0 0\n4 5", "output": "5" }, { "input": "3 4\n6 1", "output": "3" }, { "input": "0 0\n4 6", "output": "6" }, { "input": "1 1\n-3 -5", "output": "6" }, { "input": "-1 -1\n-10 100", "output": "101" }, { "input": "1 -1\n100 -100", "output":...
1,623,938,440
2,147,483,647
Python 3
OK
TESTS
75
78
0
x1 ,y1 = map(int,input().strip().split()) x2 , y2 = map(int,input().strip().split()) ans = max(abs(x1 - x2) , abs(y1 - y2)) print(ans)
Title: Professor GukiZ's Robot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of ...
```python x1 ,y1 = map(int,input().strip().split()) x2 , y2 = map(int,input().strip().split()) ans = max(abs(x1 - x2) , abs(y1 - y2)) print(ans) ```
3
883
M
Quadcopter Competition
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should: - start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point. Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point w...
The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point. The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag. It is guaranteed that the quadcopter sta...
Print the length of minimal path of the quadcopter to surround the flag and return back.
[ "1 5\n5 2\n", "0 1\n0 0\n" ]
[ "18\n", "8\n" ]
none
0
[ { "input": "1 5\n5 2", "output": "18" }, { "input": "0 1\n0 0", "output": "8" }, { "input": "-100 -100\n100 100", "output": "804" }, { "input": "-100 -100\n-100 100", "output": "406" }, { "input": "-100 -100\n100 -100", "output": "406" }, { "input": "1...
1,511,320,318
2,147,483,647
Python 3
OK
TESTS
100
62
0
x,y=map(int,input().split()) a,b=map(int,input().split()) print((abs(a-x)+abs(b-y))*2+4+(a==x or b==y)*2)
Title: Quadcopter Competition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp takes part in a quadcopter competition. According to the rules a flying robot should: - start the race from some point of a field, - go around the flag, - close cycle returning back to the starting p...
```python x,y=map(int,input().split()) a,b=map(int,input().split()) print((abs(a-x)+abs(b-y))*2+4+(a==x or b==y)*2) ```
3
12
B
Correct Solution?
PROGRAMMING
1,100
[ "implementation", "sortings" ]
B. Correct Solution?
2
256
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said: —Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroe...
The first line contains one integer *n* (0<=≤<=*n*<=≤<=109) without leading zeroes. The second lines contains one integer *m* (0<=≤<=*m*<=≤<=109) — Bob's answer, possibly with leading zeroes.
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
[ "3310\n1033\n", "4\n5\n" ]
[ "OK\n", "WRONG_ANSWER\n" ]
none
0
[ { "input": "3310\n1033", "output": "OK" }, { "input": "4\n5", "output": "WRONG_ANSWER" }, { "input": "40\n04", "output": "WRONG_ANSWER" }, { "input": "12\n12", "output": "OK" }, { "input": "432\n234", "output": "OK" }, { "input": "17109\n01179", "o...
1,668,048,136
2,147,483,647
Python 3
OK
TESTS
32
92
0
def solve(): n=list(input().strip()) m=list(input().strip()) n.sort() if n[0]=='0': for i in range(1,len(n)): if n[i]!='0': n[0],n[i]=n[i],n[0] break if m==n: print("OK") else: print("WRONG_ANSWER") solve()
Title: Correct Solution? Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said: —Shuf...
```python def solve(): n=list(input().strip()) m=list(input().strip()) n.sort() if n[0]=='0': for i in range(1,len(n)): if n[i]!='0': n[0],n[i]=n[i],n[0] break if m==n: print("OK") else: print("WRONG_ANSWER") solv...
3.977
194
A
Exams
PROGRAMMING
900
[ "implementation", "math" ]
null
null
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could ha...
The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks. It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*.
Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*.
[ "4 8\n", "4 10\n", "1 3\n" ]
[ "4\n", "2\n", "0\n" ]
In the first sample the author has to get a 2 for all his exams. In the second sample he should get a 3 for two exams and a 2 for two more. In the third sample he should get a 3 for one exam.
500
[ { "input": "4 8", "output": "4" }, { "input": "4 10", "output": "2" }, { "input": "1 3", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "4 9", "output": "3" }, { "input": "50 234", "output": "0" }, { "input": "50 100", "...
1,639,485,268
2,147,483,647
PyPy 3-64
OK
TESTS
38
216
0
n, k = [int(i) for i in input().split()] t = n * 3 print(max(t-k, 0))
Title: Exams Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend ...
```python n, k = [int(i) for i in input().split()] t = n * 3 print(max(t-k, 0)) ```
3
1,008
A
Romaji
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant...
The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters.
Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower).
[ "sumimasen\n", "ninja\n", "codeforces\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese. In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
500
[ { "input": "sumimasen", "output": "YES" }, { "input": "ninja", "output": "YES" }, { "input": "codeforces", "output": "NO" }, { "input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen", "output": "YES" }, { "in...
1,637,333,391
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
k=input() a='aeiou' b=aeioun' x='a' ans='YES' for c in k: if x not in b and c not in a: ans='NO' break x=c if x not in b: ans='NO' print(ans)
Title: Romaji Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after eve...
```python k=input() a='aeiou' b=aeioun' x='a' ans='YES' for c in k: if x not in b and c not in a: ans='NO' break x=c if x not in b: ans='NO' print(ans) ```
-1
544
A
Set of Strings
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
You are given a string *q*. A sequence of *k* strings *s*1,<=*s*2,<=...,<=*s**k* is called beautiful, if the concatenation of these strings is string *q* (formally, *s*1<=+<=*s*2<=+<=...<=+<=*s**k*<==<=*q*) and the first characters of these strings are distinct. Find any beautiful sequence of strings or determine that...
The first line contains a positive integer *k* (1<=≤<=*k*<=≤<=26) — the number of strings that should be in a beautiful sequence. The second line contains string *q*, consisting of lowercase Latin letters. The length of the string is within range from 1 to 100, inclusive.
If such sequence doesn't exist, then print in a single line "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes) and in the next *k* lines print the beautiful sequence of strings *s*1,<=*s*2,<=...,<=*s**k*. If there are multiple possible answers, print any of them.
[ "1\nabca\n", "2\naaacas\n", "4\nabc\n" ]
[ "YES\nabca\n", "YES\naaa\ncas\n", "NO\n" ]
In the second sample there are two possible answers: {"*aaaca*", "*s*"} and {"*aaa*", "*cas*"}.
500
[ { "input": "1\nabca", "output": "YES\nabca" }, { "input": "2\naaacas", "output": "YES\naaa\ncas" }, { "input": "4\nabc", "output": "NO" }, { "input": "3\nnddkhkhkdndknndkhrnhddkrdhrnrrnkkdnnndndrdhnknknhnrnnkrrdhrkhkrkhnkhkhhrhdnrndnknrrhdrdrkhdrkkhkrnkk", "output": "YES\...
1,431,018,400
2,200
Python 3
OK
TESTS
33
62
0
n = int(input()) a = input() d = {} count = 0 for i in range(len(a)): if d.get(a[i]) == None: d[a[i]] = 1 count += 1 if count >= n: print('YES') d = {} count = 0 i = 0 j = 0 while count < n - 1: if d.get(a[i]) == None: d[a[i]] = 1 ...
Title: Set of Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *q*. A sequence of *k* strings *s*1,<=*s*2,<=...,<=*s**k* is called beautiful, if the concatenation of these strings is string *q* (formally, *s*1<=+<=*s*2<=+<=...<=+<=*s**k*<==<=*q*) and the first...
```python n = int(input()) a = input() d = {} count = 0 for i in range(len(a)): if d.get(a[i]) == None: d[a[i]] = 1 count += 1 if count >= n: print('YES') d = {} count = 0 i = 0 j = 0 while count < n - 1: if d.get(a[i]) == None: d[a[i]] = 1...
3
706
B
Interesting drink
PROGRAMMING
1,100
[ "binary search", "dp", "implementation" ]
null
null
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite ...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop. The third line contains a single i...
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
[ "5\n3 10 8 6 11\n4\n1\n10\n3\n11\n" ]
[ "0\n4\n1\n5\n" ]
On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
1,000
[ { "input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11", "output": "0\n4\n1\n5" }, { "input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471", "output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2" }, { "input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521", "output": "...
1,688,944,972
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
31
0
input() flag = 1 nums = sorted(map(int,input().split())) num = int(input()) for i in range(num): query = int(input()) sums =0 for j in range(5): if query >= nums[j]: sums = j+1 else: break print(sums)
Title: Interesting drink Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha...
```python input() flag = 1 nums = sorted(map(int,input().split())) num = int(input()) for i in range(num): query = int(input()) sums =0 for j in range(5): if query >= nums[j]: sums = j+1 else: break print(sums) ```
-1
484
B
Maximum Value
PROGRAMMING
2,100
[ "binary search", "math", "sortings", "two pointers" ]
null
null
You are given a sequence *a* consisting of *n* integers. Find the maximum possible value of (integer remainder of *a**i* divided by *a**j*), where 1<=≤<=*i*,<=*j*<=≤<=*n* and *a**i*<=≥<=*a**j*.
The first line contains integer *n* — the length of the sequence (1<=≤<=*n*<=≤<=2·105). The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=106).
Print the answer to the problem.
[ "3\n3 4 5\n" ]
[ "2\n" ]
none
1,000
[ { "input": "3\n3 4 5", "output": "2" }, { "input": "3\n1 2 4", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "1\n1000000", "output": "0" }, { "input": "2\n1000000 999999", "output": "1" }, { "input": "12\n4 4 10 13 28 30 41 43 58 61 7...
1,638,612,899
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
11,264,000
n = int(input()) a = [int(i) for i in input().split()] a = list(reversed(sorted(a))) mx = 0 for i in range(n): ai = a[i] for j in range(i + 1, n): aj = a[j] d = ai % aj if d > mx: mx = d print(mx)
Title: Maximum Value Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence *a* consisting of *n* integers. Find the maximum possible value of (integer remainder of *a**i* divided by *a**j*), where 1<=≤<=*i*,<=*j*<=≤<=*n* and *a**i*<=≥<=*a**j*. Input Specification: The ...
```python n = int(input()) a = [int(i) for i in input().split()] a = list(reversed(sorted(a))) mx = 0 for i in range(n): ai = a[i] for j in range(i + 1, n): aj = a[j] d = ai % aj if d > mx: mx = d print(mx) ```
0
680
B
Bear and Finding Criminals
PROGRAMMING
1,000
[ "constructive algorithms", "implementation" ]
null
null
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he...
The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city.
Print the number of criminals Limak will catch.
[ "6 3\n1 1 1 0 1 0\n", "5 2\n0 0 0 1 0\n" ]
[ "3\n", "1\n" ]
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red. Using the BCD gives Limak the following information: - There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There i...
1,000
[ { "input": "6 3\n1 1 1 0 1 0", "output": "3" }, { "input": "5 2\n0 0 0 1 0", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "9 3\n1 1 1 1 1 1 1 1 0", "output": "8" }, { "input": "9 5\n1 0 1 0 1 0...
1,681,116,322
2,147,483,647
PyPy 3-64
OK
TESTS
24
62
0
n, a = map(int, input().split()) t = list(map(int, input().split())) c = sum(t) a = a-1 for i in range(n): if a+i < n and a-i>-1 and ((t[a+i] == 1 and t[a-i] == 0) or (t[a+i] == 0 and t[a-i] == 1)): c -= 1 print(c)
Title: Bear and Finding Criminals Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city...
```python n, a = map(int, input().split()) t = list(map(int, input().split())) c = sum(t) a = a-1 for i in range(n): if a+i < n and a-i>-1 and ((t[a+i] == 1 and t[a-i] == 0) or (t[a+i] == 0 and t[a-i] == 1)): c -= 1 print(c) ```
3
792
A
New Bus Route
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d...
The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct.
Print two integer numbers — the minimal distance and the quantity of pairs with this distance.
[ "4\n6 -3 0 4\n", "3\n-2 0 2\n" ]
[ "2 1\n", "2 2\n" ]
In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance.
0
[ { "input": "4\n6 -3 0 4", "output": "2 1" }, { "input": "3\n-2 0 2", "output": "2 2" }, { "input": "2\n1 2", "output": "1 1" }, { "input": "2\n1000000000 -1000000000", "output": "2000000000 1" }, { "input": "5\n-979619606 -979619602 -979619604 -979619605 -97961960...
1,515,258,889
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
62
5,632,000
n = int(input()) a = list(map(int,input().split())) b = list() c = list() for i in a: b.append(i) c.append(i) ma = max(a) del a[a.index(ma)] mb = max(a) mc = min(b) del b[b.index(mc)] md = min(b) ans1 = min(abs(ma-mb),abs(mc-md)) ans2 = 0 for i in range(n-1): j = i+1 while True: if j == n: break if abs(c[i]...
Title: New Bus Route Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from on...
```python n = int(input()) a = list(map(int,input().split())) b = list() c = list() for i in a: b.append(i) c.append(i) ma = max(a) del a[a.index(ma)] mb = max(a) mc = min(b) del b[b.index(mc)] md = min(b) ans1 = min(abs(ma-mb),abs(mc-md)) ans2 = 0 for i in range(n-1): j = i+1 while True: if j == n: break i...
0
140
C
New Year Snowmen
PROGRAMMING
1,800
[ "binary search", "data structures", "greedy" ]
null
null
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made *n* snowballs with radii equal to *r*1, *r*2, ..., *r**n*. To make a snowman, one nee...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of snowballs. The next line contains *n* integers — the balls' radii *r*1, *r*2, ..., *r**n* (1<=≤<=*r**i*<=≤<=109). The balls' radii can coincide.
Print on the first line a single number *k* — the maximum number of the snowmen. Next *k* lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers — the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print...
[ "7\n1 2 3 4 5 6 7\n", "3\n2 2 3\n" ]
[ "2\n3 2 1\n6 5 4\n", "0\n" ]
none
1,500
[ { "input": "7\n1 2 3 4 5 6 7", "output": "2\n7 5 3\n6 4 2" }, { "input": "3\n2 2 3", "output": "0" }, { "input": "1\n255317", "output": "0" }, { "input": "6\n1 1 2 2 3 3", "output": "2\n3 2 1\n3 2 1" }, { "input": "6\n1 2 2 2 3 3", "output": "1\n3 2 1" }, ...
1,591,003,070
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
248
0
import heapq n = int(input()) ara = list(map(int, input().split())) mp = {} ans = [] pq = [] for val in ara: mp.setdefault(val, 0) mp[val] += 1 for k in mp: heapq.heappush(pq, [-mp[k], k]) while len(pq) >= 3: val = [None]*3 val[0] = heapq.heappop(pq) val[1] = heapq.heappop(pq) val[2] = heapq.heappop(pq) an...
Title: New Year Snowmen Time Limit: None seconds Memory Limit: None megabytes Problem Description: As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they...
```python import heapq n = int(input()) ara = list(map(int, input().split())) mp = {} ans = [] pq = [] for val in ara: mp.setdefault(val, 0) mp[val] += 1 for k in mp: heapq.heappush(pq, [-mp[k], k]) while len(pq) >= 3: val = [None]*3 val[0] = heapq.heappop(pq) val[1] = heapq.heappop(pq) val[2] = heapq.heapp...
0
556
A
Case of the Zeros and Ones
PROGRAMMING
900
[ "greedy" ]
null
null
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an...
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has. The second line contains the string of length *n* consisting only from zeros and ones.
Output the minimum length of the string that may remain after applying the described operations several times.
[ "4\n1100\n", "5\n01010\n", "8\n11101111\n" ]
[ "0\n", "1\n", "6\n" ]
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test it is possible to change the string like...
250
[ { "input": "4\n1100", "output": "0" }, { "input": "5\n01010", "output": "1" }, { "input": "8\n11101111", "output": "6" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n00", "output": "2" }, { "input"...
1,685,379,469
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n = input().split() n = input (n) print(n)
Title: Case of the Zeros and Ones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Cons...
```python n = input().split() n = input (n) print(n) ```
0
677
A
Vanya and Fence
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ...
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Print a single integer — the minimum possible valid width of the road.
[ "3 7\n4 5 14\n", "6 1\n1 1 1 1 1 1\n", "6 5\n7 6 8 9 10 5\n" ]
[ "4\n", "6\n", "11\n" ]
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required m...
500
[ { "input": "3 7\n4 5 14", "output": "4" }, { "input": "6 1\n1 1 1 1 1 1", "output": "6" }, { "input": "6 5\n7 6 8 9 10 5", "output": "11" }, { "input": "10 420\n214 614 297 675 82 740 174 23 255 15", "output": "13" }, { "input": "10 561\n657 23 1096 487 785 66 481...
1,696,880,886
2,147,483,647
Python 3
OK
TESTS
29
46
0
n,h = map(int,input().split()) a = list(map(int,input().split())) a1 = list(filter(lambda x: x <= h,a)) a2 = list(filter(lambda x: x > h,a)) print(len(a1) + len(a2)*2)
Title: Vanya and Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers...
```python n,h = map(int,input().split()) a = list(map(int,input().split())) a1 = list(filter(lambda x: x <= h,a)) a2 = list(filter(lambda x: x > h,a)) print(len(a1) + len(a2)*2) ```
3
178
A3
Educational Game
PROGRAMMING
1,100
[ "greedy" ]
null
null
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of *n* non-negative integers *a**i* numbered from 1 to *n*. The goal of the game is to make numbers *a*1,<=*a*2,<=...,<=*a**k* (i.e. some pr...
The first input line contains a single integer *n*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=104), separated by single spaces. The input limitations for getting 20 points are: - 1<=≤<=*n*<=≤<=300 The input limitations for getting 50 points are: - 1<=≤<=*n*<=≤<=2000 The input limitations f...
Print exactly *n*<=-<=1 lines: the *k*-th output line must contain the minimum number of moves needed to make the first *k* elements of the original sequence *a**i* equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d sp...
[ "4\n1 0 1 2\n", "8\n1 2 3 4 5 6 7 8\n" ]
[ "1\n1\n3\n", "1\n3\n6\n10\n16\n24\n40\n" ]
none
50
[ { "input": "4\n1 0 1 2", "output": "1\n1\n3" }, { "input": "8\n1 2 3 4 5 6 7 8", "output": "1\n3\n6\n10\n16\n24\n40" }, { "input": "5\n4 1 4 7 6", "output": "4\n5\n9\n17" }, { "input": "9\n13 13 7 11 3 9 3 5 5", "output": "13\n26\n33\n44\n47\n69\n79\n117" }, { "in...
1,681,955,591
2,147,483,647
Python 3
OK
TESTS3
33
1,840
6,451,200
n = int(input()) l = list(map(int,input().split())) sum = 0 import math def check(n,i): for j in range(int(math.log2(n)),-1,-1): k = pow(2,j)+ i if k <= n-1: # print(j) # print("go") return k one = check(n,0) l[one]= l[0]+ l[one] print(l[0]) for i i...
Title: Educational Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of *n* non-negative integers *a**i* nu...
```python n = int(input()) l = list(map(int,input().split())) sum = 0 import math def check(n,i): for j in range(int(math.log2(n)),-1,-1): k = pow(2,j)+ i if k <= n-1: # print(j) # print("go") return k one = check(n,0) l[one]= l[0]+ l[one] print(l[0]...
3
294
A
Shaass and Oskols
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*...
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i...
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
500
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 8...
1,611,956,260
2,147,483,647
Python 3
OK
TESTS
31
154
307,200
n1=int(input()) w=list(map(int,input().split())) n2,b=int(input()),[] for i in range(n2) : b.append(list(map(int,input().split()))) if b[i][0]-2>-1 : w[b[i][0]-2]+=b[i][1]-1 if b[i][0]<n1 : w[b[i][0]]+=w[b[i][0]-1]-b[i][1] w[b[i][0]-1]=0 for i in w : print(i)
Title: Shaass and Oskols Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each...
```python n1=int(input()) w=list(map(int,input().split())) n2,b=int(input()),[] for i in range(n2) : b.append(list(map(int,input().split()))) if b[i][0]-2>-1 : w[b[i][0]-2]+=b[i][1]-1 if b[i][0]<n1 : w[b[i][0]]+=w[b[i][0]-1]-b[i][1] w[b[i][0]-1]=0 for i in w : print(i) ```
3
76
E
Points
PROGRAMMING
1,700
[ "implementation", "math" ]
E. Points
1
256
You are given *N* points on a plane. Write a program which will find the sum of squares of distances between all pairs of points.
The first line of input contains one integer number *N* (1<=≤<=*N*<=≤<=100<=000) — the number of points. Each of the following *N* lines contain two integer numbers *X* and *Y* (<=-<=10<=000<=≤<=*X*,<=*Y*<=≤<=10<=000) — the coordinates of points. Two or more points may coincide.
The only line of output should contain the required sum of squares of distances between all pairs of points.
[ "4\n1 1\n-1 -1\n1 -1\n-1 1\n" ]
[ "32\n" ]
none
0
[ { "input": "4\n1 1\n-1 -1\n1 -1\n-1 1", "output": "32" }, { "input": "1\n6 3", "output": "0" }, { "input": "30\n-7 -12\n-2 5\n14 8\n9 17\n15 -18\n20 6\n20 8\n-13 12\n-4 -20\n-11 -16\n-6 16\n1 -9\n5 -12\n13 -17\n11 5\n8 -9\n-13 5\n19 -13\n-19 -8\n-14 10\n10 3\n-16 -8\n-17 16\n-14 -15\n5 1...
1,660,061,167
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
n = int(input()) l = list(zip(*(map(int, input().split()) for i in range(n)))) ssq = sum(x**2 for t in l for x in t) sqs = sum(sum(t)**2 for t in l) print(n * (ssq - sqs))
Title: Points Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: You are given *N* points on a plane. Write a program which will find the sum of squares of distances between all pairs of points. Input Specification: The first line of input contains one integer number *N* (1<=≤<=*N*<=≤<=100<=000)...
```python n = int(input()) l = list(zip(*(map(int, input().split()) for i in range(n)))) ssq = sum(x**2 for t in l for x in t) sqs = sum(sum(t)**2 for t in l) print(n * (ssq - sqs)) ```
0
216
A
Tiling with Hexagons
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles. The hall also turned out hexagonal in its shape. The King walked along the perimeter of ...
The first line contains three integers: *a*, *b* and *c* (2<=≤<=*a*,<=*b*,<=*c*<=≤<=1000).
Print a single number — the total number of tiles on the hall floor.
[ "2 3 4\n" ]
[ "18" ]
none
500
[ { "input": "2 3 4", "output": "18" }, { "input": "2 2 2", "output": "7" }, { "input": "7 8 13", "output": "224" }, { "input": "14 7 75", "output": "1578" }, { "input": "201 108 304", "output": "115032" }, { "input": "999 998 996", "output": "298302...
1,614,191,834
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
154
0
a, b, c = [int(i) for i in input().split()] perimeter = 2*(a+b+c-3) + (1 if (a == b == c == 2) else 0) # предполагаем a = b = c = 2 by_b_inc = (b-2)*(c-1) # теперь b = b! by_c_inc = (c-2)*(b-1) # теперь b = b, c = c! by_a_inc = (a-2)*(b+c-2) print(perimeter + by_b_inc + by_b_inc + by_a_inc)
Title: Tiling with Hexagons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with ...
```python a, b, c = [int(i) for i in input().split()] perimeter = 2*(a+b+c-3) + (1 if (a == b == c == 2) else 0) # предполагаем a = b = c = 2 by_b_inc = (b-2)*(c-1) # теперь b = b! by_c_inc = (c-2)*(b-1) # теперь b = b, c = c! by_a_inc = (a-2)*(b+c-2) print(perimeter + by_b_inc + by_b_inc + by_a_inc) ```
0
733
B
Parade
PROGRAMMING
1,100
[ "math" ]
null
null
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits beg...
The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of columns. The next *n* lines contain the pairs of integers *l**i* and *r**i* (1<=≤<=*l**i*,<=*r**i*<=≤<=500) — the number of soldiers in the *i*-th column which start to march from the left or the right leg respectively.
Print single integer *k* — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached. Consider that columns are numbered from 1 to *n* in the order they are given in the input data. If there are several answers, print any of them.
[ "3\n5 6\n8 9\n10 3\n", "2\n6 5\n5 6\n", "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32\n" ]
[ "3\n", "1\n", "0\n" ]
In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5. If you give the order to change the leg to the third co...
1,000
[ { "input": "3\n5 6\n8 9\n10 3", "output": "3" }, { "input": "2\n6 5\n5 6", "output": "1" }, { "input": "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32", "output": "0" }, { "input": "2\n500 499\n500 500", "output": "0" }, { "input": "1\n139 252", "output": "0" }, { ...
1,560,766,700
2,147,483,647
Python 3
OK
TESTS
40
483
7,987,200
n=int(input()) l=[] for i in range (n): a,b=map(int,input().split()) l.append([a,b]) s1=0 s2=0 j=-1 for i in range(n): s1=s1+l[i][0] s2=s2+l[i][1] p=abs(s1-s2) for i in range(n): s3=s1-l[i][0]+l[i][1] s4=s2+l[i][0]-l[i][1] q=abs(s3-s4) if q>p: j=i p=q p...
Title: Parade Time Limit: None seconds Memory Limit: None megabytes Problem Description: Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should...
```python n=int(input()) l=[] for i in range (n): a,b=map(int,input().split()) l.append([a,b]) s1=0 s2=0 j=-1 for i in range(n): s1=s1+l[i][0] s2=s2+l[i][1] p=abs(s1-s2) for i in range(n): s3=s1-l[i][0]+l[i][1] s4=s2+l[i][0]-l[i][1] q=abs(s3-s4) if q>p: j=i ...
3
230
A
Dragons
PROGRAMMING
1,000
[ "greedy", "sortings" ]
null
null
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirit...
The first line contains two space-separated integers *s* and *n* (1<=≤<=*s*<=≤<=104, 1<=≤<=*n*<=≤<=103). Then *n* lines follow: the *i*-th line contains space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=104, 0<=≤<=*y**i*<=≤<=104) — the *i*-th dragon's strength and the bonus for defeating it.
On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.
[ "2 2\n1 99\n100 0\n", "10 1\n100 100\n" ]
[ "YES\n", "NO\n" ]
In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level. In the second sample Kirito's strength ...
500
[ { "input": "2 2\n1 99\n100 0", "output": "YES" }, { "input": "10 1\n100 100", "output": "NO" }, { "input": "123 2\n78 10\n130 0", "output": "YES" }, { "input": "999 2\n1010 10\n67 89", "output": "YES" }, { "input": "2 5\n5 1\n2 1\n3 1\n1 1\n4 1", "output": "YE...
1,697,346,143
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
0
import math def deezdragons(s,alist,blist): for i in range(len(alist)): if s<alist[0]: return "NO" else: if s+sum(blist[:i+1])<alist[i]: return "NO" return "YES" s=input() alist=[int(d) for d in s.split()] flist=[] glist=[] for j in range(...
Title: Dragons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the du...
```python import math def deezdragons(s,alist,blist): for i in range(len(alist)): if s<alist[0]: return "NO" else: if s+sum(blist[:i+1])<alist[i]: return "NO" return "YES" s=input() alist=[int(d) for d in s.split()] flist=[] glist=[] for j...
0
501
B
Misha and Changing Handles
PROGRAMMING
1,100
[ "data structures", "dsu", "strings" ]
null
null
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the re...
The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests. Next *q* lines contain the descriptions of the requests, one per line. Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and di...
In the first line output the integer *n* — the number of users that changed their handles at least once. In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*,...
[ "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n" ]
[ "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n" ]
none
500
[ { "input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov", "output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123" }, { "input": "1\nMisha Vasya", "output": "1\nMisha Vasya" }, { "input": "10\na b\nb c\nc d\nd...
1,612,563,693
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
# No Collaboration inp = input() prev_dict = {} for _ in range(inp): oldString, newString = inp().split(" ") if oldString is not in prev: prev_dict[newString] = oldString else: prev_dict[newString] = prev_dict[oldString] del prev_dict[old] print(prev_dict) for i in prev_dict: pri...
Title: Misha and Changing Handles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is a...
```python # No Collaboration inp = input() prev_dict = {} for _ in range(inp): oldString, newString = inp().split(" ") if oldString is not in prev: prev_dict[newString] = oldString else: prev_dict[newString] = prev_dict[oldString] del prev_dict[old] print(prev_dict) for i in prev_dic...
-1
121
A
Lucky Sum
PROGRAMMING
1,100
[ "implementation" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested ...
The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits.
In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "2 7\n", "7 7\n" ]
[ "33\n", "7\n" ]
In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33 In the second sample: *next*(7) = 7
500
[ { "input": "2 7", "output": "33" }, { "input": "7 7", "output": "7" }, { "input": "1 9", "output": "125" }, { "input": "4 7", "output": "25" }, { "input": "12 47", "output": "1593" }, { "input": "6 77", "output": "4012" }, { "input": "1 100...
1,608,709,375
2,147,483,647
PyPy 3
OK
TESTS
42
171
3,072,000
from sys import stdin as sin def aint():return int(sin.readline()) def amap():return map(int,sin.readline().split()) def alist():return list(map(int,sin.readline().split())) def astr():return str(sin.readline().split()) l,r = amap() d=[4,7] for i in range(9): f=[] for j in d: f.append(int(...
Title: Lucky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let *...
```python from sys import stdin as sin def aint():return int(sin.readline()) def amap():return map(int,sin.readline().split()) def alist():return list(map(int,sin.readline().split())) def astr():return str(sin.readline().split()) l,r = amap() d=[4,7] for i in range(9): f=[] for j in d: f.a...
3
798
A
Mike and palindrome
PROGRAMMING
1,000
[ "brute force", "constructive algorithms", "strings" ]
null
null
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo...
The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15).
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
[ "abccaa\n", "abbcca\n", "abcda\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "abccaa", "output": "YES" }, { "input": "abbcca", "output": "NO" }, { "input": "abcda", "output": "YES" }, { "input": "kyw", "output": "YES" }, { "input": "fccf", "output": "NO" }, { "input": "mnlm", "output": "YES" }, { "input":...
1,637,426,688
2,147,483,647
Python 3
OK
TESTS
99
46
0
text=input() n=len(text) c=0 for i in range(n): if text[i]!=text[n-i-1]: c=c+1 if (n%2==0): if(c==2): print("yes") else: print("no") elif(n%2==1): if (c==2 or c==0): print("yes") else: print("no")
Title: Mike and palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same ...
```python text=input() n=len(text) c=0 for i in range(n): if text[i]!=text[n-i-1]: c=c+1 if (n%2==0): if(c==2): print("yes") else: print("no") elif(n%2==1): if (c==2 or c==0): print("yes") else: print("no") ```
3
508
A
Pasha and Pixels
PROGRAMMING
1,100
[ "brute force" ]
null
null
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choos...
The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform. The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i*...
If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed. If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0.
[ "2 2 4\n1 1\n1 2\n2 1\n2 2\n", "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n", "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n" ]
[ "4\n", "5\n", "0\n" ]
none
500
[ { "input": "2 2 4\n1 1\n1 2\n2 1\n2 2", "output": "4" }, { "input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1", "output": "5" }, { "input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2", "output": "0" }, { "input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3", ...
1,697,817,865
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n, m, k = map(int, input().split()) board = [[0] * (m + 2) for _ in range(n + 2)] for _ in range(k): i, j = map(int, input().split()) board[i][j] = 1 if board[i-1][j-1] and board[i-1][j] and board[i][j-1]: print(_) break if board[i+1][j-1] and board[i+1][j] and board[i][...
Title: Pasha and Pixels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row ...
```python n, m, k = map(int, input().split()) board = [[0] * (m + 2) for _ in range(n + 2)] for _ in range(k): i, j = map(int, input().split()) board[i][j] = 1 if board[i-1][j-1] and board[i-1][j] and board[i][j-1]: print(_) break if board[i+1][j-1] and board[i+1][j] and...
0
714
B
Filya and Homework
PROGRAMMING
1,200
[ "implementation", "sortings" ]
null
null
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than onc...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array.
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
[ "5\n1 3 3 2 1\n", "5\n1 2 3 4 5\n" ]
[ "YES\n", "NO\n" ]
In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
1,000
[ { "input": "5\n1 3 3 2 1", "output": "YES" }, { "input": "5\n1 2 3 4 5", "output": "NO" }, { "input": "2\n1 2", "output": "YES" }, { "input": "3\n1 2 3", "output": "YES" }, { "input": "3\n1 1 1", "output": "YES" }, { "input": "2\n1 1000000000", "ou...
1,690,895,998
2,147,483,647
PyPy 3
OK
TESTS
79
171
13,312,000
n=int(input()) a=list(map(int,input().split())) s=list(set(a)) if (len(s)==3 and sum(s)%3==0 and sum(s)/3 in s) or len(s)<3: print("YES") else: print("NO")
Title: Filya and Homework Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a...
```python n=int(input()) a=list(map(int,input().split())) s=list(set(a)) if (len(s)==3 and sum(s)%3==0 and sum(s)/3 in s) or len(s)<3: print("YES") else: print("NO") ```
3
698
A
Vacations
PROGRAMMING
1,400
[ "dp" ]
null
null
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is close...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co...
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days.
[ "4\n1 3 2 0\n", "7\n1 3 3 2 1 2 3\n", "2\n2 2\n" ]
[ "2\n", "0\n", "1\n" ]
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya ca...
500
[ { "input": "4\n1 3 2 0", "output": "2" }, { "input": "7\n1 3 3 2 1 2 3", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "10\n0 0 1 1 0 0 0 0 1 0", "output": "8" }, { "input": "100\n3 2 3 3 3 2 3 1 ...
1,623,170,638
2,147,483,647
PyPy 3
OK
TESTS
88
140
0
n = int(input()) s = [0] + list(map(int, input().split())) dp = [[0] * (n + 1) for _ in range(3)] for i in range(1, n + 1): dp[0][i] = min(dp[0][i - 1], dp[1][i - 1], dp[2][i - 1]) + 1 dp[1][i] = dp[1][i - 1] + 1 dp[2][i] = dp[2][i - 1] + 1 if s[i] == 0: dp[0][i] = min(dp[0][i - 1], ...
Title: Vacations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int...
```python n = int(input()) s = [0] + list(map(int, input().split())) dp = [[0] * (n + 1) for _ in range(3)] for i in range(1, n + 1): dp[0][i] = min(dp[0][i - 1], dp[1][i - 1], dp[2][i - 1]) + 1 dp[1][i] = dp[1][i - 1] + 1 dp[2][i] = dp[2][i - 1] + 1 if s[i] == 0: dp[0][i] = min(dp[0...
3
1,003
A
Polycarp's Pockets
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i...
The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins.
Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
[ "6\n1 2 4 3 3 2\n", "1\n100\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "6\n1 2 4 3 3 2", "output": "2" }, { "input": "1\n100", "output": "1" }, { "input": "100\n100 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 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...
1,638,359,174
674
Python 3
WRONG_ANSWER
TESTS
1
30
0
n=int(input()) l=list(map(int,input().split())) d={} for i in l: if i not in d: d[i]=1 else: d[i]+=1 print(max(d,key=d.get)) ''' 6 1 2 4 3 3 2 '''
Title: Polycarp's Pockets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Po...
```python n=int(input()) l=list(map(int,input().split())) d={} for i in l: if i not in d: d[i]=1 else: d[i]+=1 print(max(d,key=d.get)) ''' 6 1 2 4 3 3 2 ''' ```
0
336
A
Vasily the Bear and Triangle
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes. Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he...
The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0).
Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points.
[ "10 5\n", "-10 5\n" ]
[ "0 15 15 0\n", "-15 0 0 15\n" ]
<img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/> Figure to the first sample
500
[ { "input": "10 5", "output": "0 15 15 0" }, { "input": "-10 5", "output": "-15 0 0 15" }, { "input": "20 -10", "output": "0 -30 30 0" }, { "input": "-10 -1000000000", "output": "-1000000010 0 0 -1000000010" }, { "input": "-1000000000 -1000000000", "output": "-...
1,517,045,084
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
5,632,000
#from dust i have come dust i will be x,y=map(int,input().split()) X=abs(x)+abs(y) Y=X if x<0: X=(-1*X) if y<0: Y=(-1*Y) if X<Y: print(X, 0, 0, Y) else: print(0, Y, X, 0)
Title: Vasily the Bear and Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate ...
```python #from dust i have come dust i will be x,y=map(int,input().split()) X=abs(x)+abs(y) Y=X if x<0: X=(-1*X) if y<0: Y=(-1*Y) if X<Y: print(X, 0, 0, Y) else: print(0, Y, X, 0) ```
0
875
A
Classroom Watch
PROGRAMMING
1,200
[ "brute force", "math" ]
null
null
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=109).
In the first line print one integer *k* — number of different values of *x* satisfying the condition. In next *k* lines print these values in ascending order.
[ "21\n", "20\n" ]
[ "1\n15\n", "0\n" ]
In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21. In the second test case there are no such *x*.
500
[ { "input": "21", "output": "1\n15" }, { "input": "20", "output": "0" }, { "input": "1", "output": "0" }, { "input": "2", "output": "1\n1" }, { "input": "3", "output": "0" }, { "input": "100000001", "output": "2\n99999937\n100000000" }, { "i...
1,644,188,680
2,147,483,647
Python 3
OK
TESTS
18
46
0
a = int(input()) l = [] for i in range(max(1, a - 99), a): if i + sum(map(int, str(i))) == a: l.append(i) print(len(l)) print(*l)
Title: Classroom Watch Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answe...
```python a = int(input()) l = [] for i in range(max(1, a - 99), a): if i + sum(map(int, str(i))) == a: l.append(i) print(len(l)) print(*l) ```
3
864
A
Fair Game
PROGRAMMING
1,000
[ "implementation", "sortings" ]
null
null
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card. Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with...
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number. The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards.
If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more. In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number t...
[ "4\n11\n27\n27\n11\n", "2\n6\n6\n", "6\n10\n20\n30\n20\n10\n20\n", "6\n1\n1\n2\n2\n3\n3\n" ]
[ "YES\n11 27\n", "NO\n", "NO\n", "NO\n" ]
In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards. In the second example fair game is impossible because the nu...
500
[ { "input": "4\n11\n27\n27\n11", "output": "YES\n11 27" }, { "input": "2\n6\n6", "output": "NO" }, { "input": "6\n10\n20\n30\n20\n10\n20", "output": "NO" }, { "input": "6\n1\n1\n2\n2\n3\n3", "output": "NO" }, { "input": "2\n1\n100", "output": "YES\n1 100" }, ...
1,507,147,212
2,147,483,647
Python 3
OK
TESTS
54
61
0
a = [int(input()) for i in range(int(input()))] d = dict() for i in a: if i not in d.keys(): d[i] = 0 d[i] += 1 if len(d.keys()) == 2 and d[a[0]] == len(a) // 2: print("YES") for i in d.keys(): print(i, end=' ') else: print("NO")
Title: Fair Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card. Before the game Petya will choose an integer and after that Vasya will choose another integer (di...
```python a = [int(input()) for i in range(int(input()))] d = dict() for i in a: if i not in d.keys(): d[i] = 0 d[i] += 1 if len(d.keys()) == 2 and d[a[0]] == len(a) // 2: print("YES") for i in d.keys(): print(i, end=' ') else: print("NO") ```
3
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,590,943,719
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
280
0
import math def almostPrime(i): s = i count2 = 0 for j in prime: if i%j ==0: count2 += 1 while i%j == 0: i = i/j if i in prime or (i == 1 and count2 ==2): count[0] += 1 return def isPrime(i): if sieve[i]: for j in range(i*i,n+1,i): sieve[j] = False n = int(input(...
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 import math def almostPrime(i): s = i count2 = 0 for j in prime: if i%j ==0: count2 += 1 while i%j == 0: i = i/j if i in prime or (i == 1 and count2 ==2): count[0] += 1 return def isPrime(i): if sieve[i]: for j in range(i*i,n+1,i): sieve[j] = False n = ...
0
519
A
A and B and Chess
PROGRAMMING
900
[ "implementation" ]
null
null
A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger. For each chess piece we know its weight: - the queen's weight is 9, - the rook's weight is 5, - the bisho...
The input contains eight lines, eight characters each — the board's description. The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters. The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the kni...
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
[ "...QK...\n........\n........\n........\n........\n........\n........\n...rk...\n", "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR\n", "rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........\n" ]
[ "White\n", "Draw\n", "Black\n" ]
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5. In the second test sample the weights of the positions of the black and the white pieces are equal to 39. In the third test sample the weight of the position of the white piece...
500
[ { "input": "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR", "output": "Draw" }, { "input": "....bQ.K\n.B......\n.....P..\n........\n........\n........\n...N.P..\n.....R..", "output": "White" }, { "input": "b....p..\nR.......\n.pP...b.\npp......\nq.PPNpPR\...
1,623,023,325
2,147,483,647
Python 3
OK
TESTS
65
109
0
d={'r':5,'b': 3,'n':3,'q':9,'p':1} p=0 for _ in range(8): for i in input(): p+=d.get(i.lower(),0)*(-1+2*i.isupper()) print('White' if p>0 else ['Black','Draw'][not p])
Title: A and B and Chess Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger. For eac...
```python d={'r':5,'b': 3,'n':3,'q':9,'p':1} p=0 for _ in range(8): for i in input(): p+=d.get(i.lower(),0)*(-1+2*i.isupper()) print('White' if p>0 else ['Black','Draw'][not p]) ```
3
214
A
System of Equations
PROGRAMMING
800
[ "brute force" ]
null
null
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of int...
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
On a single line print the answer to the problem.
[ "9 3\n", "14 28\n", "4 20\n" ]
[ "1\n", "1\n", "0\n" ]
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
500
[ { "input": "9 3", "output": "1" }, { "input": "14 28", "output": "1" }, { "input": "4 20", "output": "0" }, { "input": "18 198", "output": "1" }, { "input": "22 326", "output": "1" }, { "input": "26 104", "output": "1" }, { "input": "14 10"...
1,673,033,936
2,147,483,647
Python 3
OK
TESTS
54
622
0
def microsoft(): n,m = [int(x) for x in input().split()] count = 0 for i in range(min(n,m)+1): for j in range(min(n,m)+1): if (i**2)+j == n and (j**2)+i == m: count += 1 print(count) microsoft()
Title: System of Equations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi...
```python def microsoft(): n,m = [int(x) for x in input().split()] count = 0 for i in range(min(n,m)+1): for j in range(min(n,m)+1): if (i**2)+j == n and (j**2)+i == m: count += 1 print(count) microsoft() ```
3
287
A
IQ Test
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the...
Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black.
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
[ "####\n.#..\n####\n....\n", "####\n....\n####\n....\n" ]
[ "YES\n", "NO\n" ]
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
500
[ { "input": "###.\n...#\n###.\n...#", "output": "NO" }, { "input": ".##.\n#..#\n.##.\n#..#", "output": "NO" }, { "input": ".#.#\n#.#.\n.#.#\n#.#.", "output": "NO" }, { "input": "##..\n..##\n##..\n..##", "output": "NO" }, { "input": "#.#.\n#.#.\n.#.#\n.#.#", "ou...
1,651,921,261
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
s=input() ss=input() sss=input() ssss=input() l=s+ss+sss+ssss ll=s+ss lll=ss+sss llll=sss+ssss if l.count('#')==l.count('.') and ll.count('#')!=4 and ll.count('.')!=4 and lll.count('#')!=4 and lll.count('.')!=4 and llll.count('#')!=4 and llll.count('.')!=4 : print("NO") else: print("YES ")
Title: IQ Test Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and o...
```python s=input() ss=input() sss=input() ssss=input() l=s+ss+sss+ssss ll=s+ss lll=ss+sss llll=sss+ssss if l.count('#')==l.count('.') and ll.count('#')!=4 and ll.count('.')!=4 and lll.count('#')!=4 and lll.count('.')!=4 and llll.count('#')!=4 and llll.count('.')!=4 : print("NO") else: print("YES ") ...
0
732
A
Buy a Shovel
PROGRAMMING
800
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<...
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e...
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels ...
500
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", ...
1,680,876,609
2,147,483,647
PyPy 3-64
OK
TESTS
54
62
0
k,r = map(int, input().split(' ')) for i in range(1,10): n = k * i l=str(n) if int(l[-1]) == r or int(l[-1]) == 0: print(i) break
Title: Buy a Shovel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his ...
```python k,r = map(int, input().split(' ')) for i in range(1,10): n = k * i l=str(n) if int(l[-1]) == r or int(l[-1]) == 0: print(i) break ```
3
740
A
Alyona and copybooks
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack ...
The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109).
Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4.
[ "1 1 3 4\n", "6 2 1 1\n", "4 4 4 4\n", "999999999 1000000000 1000000000 1000000000\n" ]
[ "3\n", "1\n", "0\n", "1000000000\n" ]
In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total. In the third example Alyona ...
500
[ { "input": "1 1 3 4", "output": "3" }, { "input": "6 2 1 1", "output": "1" }, { "input": "4 4 4 4", "output": "0" }, { "input": "999999999 1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "1016 3 2 1", "output": "0" }, { "input":...
1,694,333,667
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
20
46
0
n,a,b,c=map(int,input().split()) x=min(a,min(b,c)) # print(n%4) if n%4==0: print(0) elif n%4==1: print(min(3*a,min(a+b,c))) elif n%4==2: print(min(a+a,min(b, c+c))) else: print(a)
Title: Alyona and copybooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the sh...
```python n,a,b,c=map(int,input().split()) x=min(a,min(b,c)) # print(n%4) if n%4==0: print(0) elif n%4==1: print(min(3*a,min(a+b,c))) elif n%4==2: print(min(a+a,min(b, c+c))) else: print(a) ```
0
20
C
Dijkstra?
PROGRAMMING
1,900
[ "graphs", "shortest paths" ]
C. Dijkstra?
1
64
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge...
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
[ "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n" ]
[ "1 4 3 5 ", "1 4 3 5 " ]
none
1,500
[ { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5 " }, { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5 " }, { "input": "2 1\n1 2 1", "output": "1 2 " }, { "input": "3 1\n1 2 1", "output": "-1" }, { "input...
1,641,159,549
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
1,000
512,000
from heapq import * import sys input = sys.stdin.readline n, m = map(int, input().split()) e = [[] for i in range(n+1)] for i in range(m): a, b, w = map(int, input().split()) e[a].append((b,w)) e[b].append((a,w)) a = [] heapify(a) heappush(a, (0, [1])) while a: w, h = heappop(a) v = h[...
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 * import sys input = sys.stdin.readline n, m = map(int, input().split()) e = [[] for i in range(n+1)] for i in range(m): a, b, w = map(int, input().split()) e[a].append((b,w)) e[b].append((a,w)) a = [] heapify(a) heappush(a, (0, [1])) while a: w, h = heappop(a) ...
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,561,218,717
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
156
0
x = input() stk1 = [] for i in x: if stk1 == []: stk1.append(i) else: if stk1[-1] == i: stk1.pop() else : stk1.append(i) print(stk1)
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 x = input() stk1 = [] for i in x: if stk1 == []: stk1.append(i) else: if stk1[-1] == i: stk1.pop() else : stk1.append(i) print(stk1) ```
0
158
A
Next Round
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate...
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence...
Output the number of participants who advance to the next round.
[ "8 5\n10 9 8 7 7 7 5 5\n", "4 2\n0 0 0 0\n" ]
[ "6\n", "0\n" ]
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
500
[ { "input": "8 5\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "4 2\n0 0 0 0", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "1 1\n10", "output": "1" }, { "input": "17 14\n16 15...
1,696,586,040
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
60
0
a,b = map(int,input().split()) l = [int(x) for x in input().split()] c = 0 for i in l: if i > b: c = c + 1 print(c)
Title: Next Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* p...
```python a,b = map(int,input().split()) l = [int(x) for x in input().split()] c = 0 for i in l: if i > b: c = c + 1 print(c) ```
0
518
B
Tanya and Postcard
PROGRAMMING
1,400
[ "greedy", "implementation", "strings" ]
null
null
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s...
The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message. The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper. Here |*a*| means the ...
Print two integers separated by a space: - the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message.
[ "AbC\nDCbA\n", "ABC\nabc\n", "abacaba\nAbaCaBA\n" ]
[ "3 0\n", "0 3\n", "3 4\n" ]
none
1,000
[ { "input": "AbC\nDCbA", "output": "3 0" }, { "input": "ABC\nabc", "output": "0 3" }, { "input": "abacaba\nAbaCaBA", "output": "3 4" }, { "input": "zzzzz\nZZZZZ", "output": "0 5" }, { "input": "zzzZZZ\nZZZzzZ", "output": "5 1" }, { "input": "abcdefghijk...
1,588,460,204
2,147,483,647
Python 3
OK
TESTS
49
202
1,331,200
r=input() h=input() r_dic = {} h_dic = {} for c in r: h_dic[c] = 0 if c in r_dic: r_dic[c]+=1 else: r_dic[c]=1 for c in h: if c in h_dic: h_dic[c]+=1 else: h_dic[c]=1 y = 0 o = 0 for k,v in r_dic.items(): if r_dic[k]>h_dic[k]: ...
Title: Tanya and Postcard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she f...
```python r=input() h=input() r_dic = {} h_dic = {} for c in r: h_dic[c] = 0 if c in r_dic: r_dic[c]+=1 else: r_dic[c]=1 for c in h: if c in h_dic: h_dic[c]+=1 else: h_dic[c]=1 y = 0 o = 0 for k,v in r_dic.items(): if r_dic[k]>h_dic[k]:...
3
122
A
Lucky Division
PROGRAMMING
1,000
[ "brute force", "number theory" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ...
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
[ "47\n", "16\n", "78\n" ]
[ "YES\n", "YES\n", "NO\n" ]
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
500
[ { "input": "47", "output": "YES" }, { "input": "16", "output": "YES" }, { "input": "78", "output": "NO" }, { "input": "48", "output": "YES" }, { "input": "100", "output": "YES" }, { "input": "107", "output": "NO" }, { "input": "77", "ou...
1,694,784,793
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
25
92
0
n = int(input()) ln = [4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777] if n in ln or n%4==0 or n%7==0: print("YES") else: print("NO")
Title: Lucky Division Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python n = int(input()) ln = [4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777] if n in ln or n%4==0 or n%7==0: print("YES") else: print("NO") ```
0
204
A
Little Elephant and Interval
PROGRAMMING
1,500
[ "binary search", "combinatorics", "dp" ]
null
null
The Little Elephant very much loves sums on intervals. This time he has a pair of integers *l* and *r* (*l*<=≤<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≤<=*x*<=≤<=*r*), that the first digit of integer *x* equals the last one (in decimal notation). For example, such numbers as 101, 4...
The single line contains a pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018) — the boundaries of the interval. 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.
On a single line print a single integer — the answer to the problem.
[ "2 47\n", "47 1024\n" ]
[ "12\n", "98\n" ]
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
500
[ { "input": "2 47", "output": "12" }, { "input": "47 1024", "output": "98" }, { "input": "1 1000", "output": "108" }, { "input": "1 10000", "output": "1008" }, { "input": "47 8545", "output": "849" }, { "input": "1000 1000", "output": "0" }, { ...
1,495,248,172
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
def get_digit(n): return(len(str(n))) def get_last(n): return n % 10 def get_fisrt(n): m = str(n) return int(m[0]) def get_mid(n): m = str(n) return int(m[1:(len(m) - 1)]) def f(n): if(n < 10): return n d = get_digit(n) la = get_last(n) fi = get_fisrt(n) m = get_mid(n) ans = 0 ...
Title: Little Elephant and Interval Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant very much loves sums on intervals. This time he has a pair of integers *l* and *r* (*l*<=≤<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≤<=*x*<=≤<=*r*), ...
```python def get_digit(n): return(len(str(n))) def get_last(n): return n % 10 def get_fisrt(n): m = str(n) return int(m[0]) def get_mid(n): m = str(n) return int(m[1:(len(m) - 1)]) def f(n): if(n < 10): return n d = get_digit(n) la = get_last(n) fi = get_fisrt(n) m = get_mid(n) ...
-1
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,607,099,628
2,147,483,647
Python 3
OK
TESTS
102
109
307,200
a=input() b=input() c=[] d=[] r=[] for i in range(len(a)): c.append(a[i]) for i in range(len(b)): d.append(b[i]) for i in range(len(c)): for j in range(len(d)): if i==j: if c[i]==d[j]: r.append(0) else: r.append(1) print("".j...
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python a=input() b=input() c=[] d=[] r=[] for i in range(len(a)): c.append(a[i]) for i in range(len(b)): d.append(b[i]) for i in range(len(c)): for j in range(len(d)): if i==j: if c[i]==d[j]: r.append(0) else: r.append(1) ...
3.972178
361
A
Levko and Table
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000).
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them.
[ "2 4\n", "4 7\n" ]
[ "1 3\n3 1\n", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n" ]
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample. In the second sample the sum of elements in each row and each column equals 7. Besides, there are other table...
500
[ { "input": "2 4", "output": "4 0 \n0 4 " }, { "input": "4 7", "output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 " }, { "input": "1 8", "output": "8 " }, { "input": "9 3", "output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0...
1,399,210,809
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
N, M = map(int, input().split()) M = [(i == j) * M for i in range(N) for j in range(N)] for i in range(N): for j in range(N): print(M[i][j])
Title: Levko and Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortun...
```python N, M = map(int, input().split()) M = [(i == j) * M for i in range(N) for j in range(N)] for i in range(N): for j in range(N): print(M[i][j]) ```
-1
884
B
Japanese Crosswords Strike Back
PROGRAMMING
1,100
[ "implementation" ]
null
null
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect. For example: - If *x*<==<...
The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding.
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
[ "2 4\n1 3\n", "3 10\n3 3 2\n", "2 10\n1 3\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
0
[ { "input": "2 4\n1 3", "output": "NO" }, { "input": "3 10\n3 3 2", "output": "YES" }, { "input": "2 10\n1 3", "output": "NO" }, { "input": "1 1\n1", "output": "YES" }, { "input": "1 10\n10", "output": "YES" }, { "input": "1 10000\n10000", "output":...
1,546,099,331
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
17
140
4,812,800
n, x = map(int, input().split()) s = 0 for c in input().split(): s += int(c) # print(x-n-s+1) # print(s) print('YES' if 0<=x-s-(n-1)<=1 else 'NO')
Title: Japanese Crosswords Strike Back Time Limit: None seconds Memory Limit: None megabytes Problem Description: A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely ...
```python n, x = map(int, input().split()) s = 0 for c in input().split(): s += int(c) # print(x-n-s+1) # print(s) print('YES' if 0<=x-s-(n-1)<=1 else 'NO') ```
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,573,592,916
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
0
input() a = sorted(list(map(int, input().split()))) print(a[-1] - a[0] if a[0] < 1 else sum(a))
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 input() a = sorted(list(map(int, input().split()))) print(a[-1] - a[0] if a[0] < 1 else sum(a)) ```
0
981
A
Antipalindrome
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}...
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
[ "mew\n", "wuffuw\n", "qqqqqqqq\n" ]
[ "3\n", "5\n", "0\n" ]
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$. The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$. All sub...
500
[ { "input": "mew", "output": "3" }, { "input": "wuffuw", "output": "5" }, { "input": "qqqqqqqq", "output": "0" }, { "input": "ijvji", "output": "4" }, { "input": "iiiiiii", "output": "0" }, { "input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"...
1,585,871,925
2,147,483,647
Python 3
OK
TESTS
133
109
307,200
# -*- coding: utf-8 -*- """ Created on Thu Apr 2 17:50:02 2020 @author: alexi """ #https://codeforces.com/problemset/problem/981/A --- Alexis Galvan def check(string): L = 0 R = len(string)-1 while L <= R: if string[L] == string[R]: L += 1 R -= ...
Title: Antipalindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar...
```python # -*- coding: utf-8 -*- """ Created on Thu Apr 2 17:50:02 2020 @author: alexi """ #https://codeforces.com/problemset/problem/981/A --- Alexis Galvan def check(string): L = 0 R = len(string)-1 while L <= R: if string[L] == string[R]: L += 1 ...
3
631
A
Interview
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109).
Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*.
[ "5\n1 2 4 3 2\n2 3 3 12 1\n", "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n" ]
[ "22", "46" ]
Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation. In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *...
500
[ { "input": "5\n1 2 4 3 2\n2 3 3 12 1", "output": "22" }, { "input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6", "output": "46" }, { "input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 9...
1,585,073,827
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
input () print sum ([ reduzir ( lambda x , y : x | y , mapa ( int , raw_input (). split ())) para i no xrange ( 2 )])
Title: Interview Time Limit: None seconds Memory Limit: None megabytes Problem Description: Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of...
```python input () print sum ([ reduzir ( lambda x , y : x | y , mapa ( int , raw_input (). split ())) para i no xrange ( 2 )]) ```
-1
286
A
Lucky Permutation
PROGRAMMING
1,400
[ "constructive algorithms", "math" ]
null
null
A permutation *p* of size *n* is the sequence *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct integers, each of them is from 1 to *n* (1<=≤<=*p**i*<=≤<=*n*). A lucky permutation is such permutation *p*, that any integer *i* (1<=≤<=*i*<=≤<=*n*) meets this condition *p**p**i*<==<=*n*<=-<=*i*<=+<=1. You have inte...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the required permutation size.
Print "-1" (without the quotes) if the lucky permutation *p* of size *n* doesn't exist. Otherwise, print *n* distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) after a space — the required permutation. If there are multiple answers, you can print any of them.
[ "1\n", "2\n", "4\n", "5\n" ]
[ "1 \n", "-1\n", "2 4 1 3 \n", "2 5 3 1 4 \n" ]
none
500
[ { "input": "1", "output": "1 " }, { "input": "2", "output": "-1" }, { "input": "4", "output": "2 4 1 3 " }, { "input": "5", "output": "2 5 3 1 4 " }, { "input": "3", "output": "-1" }, { "input": "100000", "output": "2 100000 4 99998 6 99996 8 99994...
1,581,051,968
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
312
409,600
n=int(input()) if n==1:from sys import exit;print(1);exit() res=[0]*n res[0]=2 i=0 while i<n: x=res[i]-1 if res[x]>0: if x==0: if res[x]==n-i:break from sys import exit print(-1);exit() res[x]=n-i i=x if res[n//2]==0:res[n//2]=n//2+1 if 0 in res:print(-...
Title: Lucky Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation *p* of size *n* is the sequence *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct integers, each of them is from 1 to *n* (1<=≤<=*p**i*<=≤<=*n*). A lucky permutation is such permutation *p*, that a...
```python n=int(input()) if n==1:from sys import exit;print(1);exit() res=[0]*n res[0]=2 i=0 while i<n: x=res[i]-1 if res[x]>0: if x==0: if res[x]==n-i:break from sys import exit print(-1);exit() res[x]=n-i i=x if res[n//2]==0:res[n//2]=n//2+1 if 0 in r...
0
299
A
Ksusha and Array
PROGRAMMING
1,000
[ "brute force", "number theory", "sortings" ]
null
null
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements.
Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1. If there are multiple answers, you are allowed to print any of them.
[ "3\n2 2 4\n", "5\n2 1 3 1 6\n", "3\n2 3 5\n" ]
[ "2\n", "1\n", "-1\n" ]
none
500
[ { "input": "3\n2 2 4", "output": "2" }, { "input": "5\n2 1 3 1 6", "output": "1" }, { "input": "3\n2 3 5", "output": "-1" }, { "input": "1\n331358794", "output": "331358794" }, { "input": "5\n506904227 214303304 136194869 838256937 183952885", "output": "-1" ...
1,589,497,739
2,147,483,647
PyPy 3
OK
TESTS
32
466
30,720,000
garbage = int(input()) l = list(map(int, input().rstrip().split(" "))) m = min(l) r = m for i in l: if i%m !=0: r = -1 print(r)
Title: Ksusha and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that ...
```python garbage = int(input()) l = list(map(int, input().rstrip().split(" "))) m = min(l) r = m for i in l: if i%m !=0: r = -1 print(r) ```
3
771
A
Bear and Friendship Condition
PROGRAMMING
1,500
[ "dfs and similar", "dsu", "graphs" ]
null
null
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that...
The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends. The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and ...
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
[ "4 3\n1 3\n3 4\n1 4\n", "4 4\n3 1\n2 3\n3 4\n1 2\n", "10 4\n4 3\n5 10\n8 9\n1 2\n", "3 2\n1 2\n2 3\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n" ]
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
250
[ { "input": "4 3\n1 3\n3 4\n1 4", "output": "YES" }, { "input": "4 4\n3 1\n2 3\n3 4\n1 2", "output": "NO" }, { "input": "10 4\n4 3\n5 10\n8 9\n1 2", "output": "YES" }, { "input": "3 2\n1 2\n2 3", "output": "NO" }, { "input": "3 0", "output": "YES" }, { ...
1,587,376,917
2,147,483,647
Python 3
OK
TESTS
96
873
20,070,400
def li(): return list(map(int,input().split())) def ls(): return list(map(int,list(input()))) def i(): return int(input()) from collections import defaultdict graph = defaultdict(list) n,m = li() for _ in range(m): x,y = li() graph[x].append(y) graph[y].append(x) visited= [False]*(n+1) flag = 1...
Title: Bear and Friendship Condition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through...
```python def li(): return list(map(int,input().split())) def ls(): return list(map(int,list(input()))) def i(): return int(input()) from collections import defaultdict graph = defaultdict(list) n,m = li() for _ in range(m): x,y = li() graph[x].append(y) graph[y].append(x) visited= [False]*(n+1)...
3
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la...
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on...
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "outp...
1,647,694,982
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
30
0
m,n=map(int,input().split()) d=int(m/n) sum1=d while(d>0): d=int(d/n) sum1+=d if(m%n==0 and m!=n): print(sum1+m+1) else: print(sum1+m)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th...
```python m,n=map(int,input().split()) d=int(m/n) sum1=d while(d>0): d=int(d/n) sum1+=d if(m%n==0 and m!=n): print(sum1+m+1) else: print(sum1+m) ```
0
749
B
Parallelogram is Back
PROGRAMMING
1,200
[ "brute force", "constructive algorithms", "geometry" ]
null
null
Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwis...
The input consists of three lines, each containing a pair of integer coordinates *x**i* and *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000). It's guaranteed that these three points do not lie on the same line and no two of them coincide.
First print integer *k* — the number of ways to add one new integer point such that the obtained set defines some parallelogram of positive area. There is no requirement for the points to be arranged in any special order (like traversal), they just define the set of vertices. Then print *k* lines, each containing a pa...
[ "0 0\n1 0\n0 1\n" ]
[ "3\n1 -1\n-1 1\n1 1\n" ]
If you need clarification of what parallelogram is, please check Wikipedia page: https://en.wikipedia.org/wiki/Parallelogram
1,000
[ { "input": "0 0\n1 0\n0 1", "output": "3\n1 -1\n-1 1\n1 1" }, { "input": "0 -1\n-1 0\n1 1", "output": "3\n-2 -2\n2 0\n0 2" }, { "input": "-1 -1\n0 1\n1 1", "output": "3\n-2 -1\n0 -1\n2 3" }, { "input": "1000 1000\n-1000 -1000\n-1000 1000", "output": "3\n1000 -1000\n1000 3...
1,680,341,040
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
x1,y1=map(int,input().split()) x2,y2=map(int,input().split()) x3,y3=map(int,input().split()) a=x1+x2-x3 b=y1+y2 c=x2+x3-x1 d=y2+y3-y1-y3 e=x3+x1-x2 f=y3+y1-y2) print(3) print(a,b) print(c,d) print(e,f)
Title: Parallelogram is Back Time Limit: None seconds Memory Limit: None megabytes Problem Description: Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate ...
```python x1,y1=map(int,input().split()) x2,y2=map(int,input().split()) x3,y3=map(int,input().split()) a=x1+x2-x3 b=y1+y2 c=x2+x3-x1 d=y2+y3-y1-y3 e=x3+x1-x2 f=y3+y1-y2) print(3) print(a,b) print(c,d) print(e,f) ```
-1
567
A
Lineland Mail
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c...
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo...
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
[ "4\n-5 -2 2 7\n", "2\n-1 1\n" ]
[ "3 12\n3 9\n4 7\n5 12\n", "2 2\n2 2\n" ]
none
500
[ { "input": "4\n-5 -2 2 7", "output": "3 12\n3 9\n4 7\n5 12" }, { "input": "2\n-1 1", "output": "2 2\n2 2" }, { "input": "3\n-1 0 1", "output": "1 2\n1 1\n1 2" }, { "input": "4\n-1 0 1 3", "output": "1 4\n1 3\n1 2\n2 4" }, { "input": "3\n-1000000000 0 1000000000", ...
1,657,365,217
2,147,483,647
Python 3
OK
TESTS
54
483
8,396,800
n=int(input()) arr=list(map(int,input().split())) for i in range(n): if i==0: print(arr[i+1]-arr[i],arr[n-1]-arr[i]) elif i==n-1: print(arr[i]-arr[i-1],arr[i]-arr[0]) else: print(min(arr[i]-arr[i-1],arr[i+1]-arr[i]),max(arr[i]-arr[0],arr[n-1]-arr[i]))
Title: Lineland Mail Time Limit: None seconds Memory Limit: None megabytes Problem Description: All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love...
```python n=int(input()) arr=list(map(int,input().split())) for i in range(n): if i==0: print(arr[i+1]-arr[i],arr[n-1]-arr[i]) elif i==n-1: print(arr[i]-arr[i-1],arr[i]-arr[0]) else: print(min(arr[i]-arr[i-1],arr[i+1]-arr[i]),max(arr[i]-arr[0],arr[n-1]-arr[i])) ```
3
41
C
Email address
PROGRAMMING
1,300
[ "expression parsing", "implementation" ]
C. Email address
2
256
Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address ([[email protected]](/cdn-cgi/l/email-protection)). It is known that a proper email add...
The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols.
Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator &lt; in modern programming languages). In ...
[ "vasyaatgmaildotcom\n", "dotdotdotatdotdotat\n", "aatt\n" ]
[ "[email protected]\n", "[email protected]\n", "a@t\n" ]
none
1,500
[ { "input": "vasyaatgmaildotcom", "output": "vasya@gmail.com" }, { "input": "dotdotdotatdotdotat", "output": "dot..@..at" }, { "input": "aatt", "output": "a@t" }, { "input": "zdotdotatdotz", "output": "z..@.z" }, { "input": "dotdotdotdotatdotatatatdotdotdot", "...
1,675,679,937
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
x=input() if x[0:2]=='at' or x[0:3]=='dot': a=x[2:-2].replace('dot' , '.') b=a.replace('at',"@") print('{}{}{}'.format(x[0:2],b ,x[-2:]) ) else: a = x.replace('dot', '.') b = a.replace('at', "@") print(b)
Title: Email address Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email ad...
```python x=input() if x[0:2]=='at' or x[0:3]=='dot': a=x[2:-2].replace('dot' , '.') b=a.replace('at',"@") print('{}{}{}'.format(x[0:2],b ,x[-2:]) ) else: a = x.replace('dot', '.') b = a.replace('at', "@") print(b) ```
0
259
A
Little Elephant and Chess
PROGRAMMING
1,000
[ "brute force", "strings" ]
null
null
The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard d...
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the *j*-th character in the *i*-th line stands for the color of the *j*-th cell of the *i*-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black co...
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
[ "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n", "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n" ]
[ "YES\n", "NO\n" ]
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th. In the second sample there is no way you can achieve the goal.
500
[ { "input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB", "output": "YES" }, { "input": "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW", "output": "NO" }, { "input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBW...
1,604,644,771
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
186
0
w = 0 b = 0 for i in range(8): str = input() w += str.count('W') b += str.count('B') if b == 32 and w == 32: print('YES') else: print('NO')
Title: Little Elephant and Chess Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, e...
```python w = 0 b = 0 for i in range(8): str = input() w += str.count('W') b += str.count('B') if b == 32 and w == 32: print('YES') else: print('NO') ```
0
770
A
New Password
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should cons...
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists.
Print any password which satisfies all conditions given by Innokentiy.
[ "4 3\n", "6 6\n", "5 2\n" ]
[ "java\n", "python\n", "phphp\n" ]
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it. In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter...
500
[ { "input": "4 3", "output": "abca" }, { "input": "6 6", "output": "abcdef" }, { "input": "5 2", "output": "ababa" }, { "input": "3 2", "output": "aba" }, { "input": "10 2", "output": "ababababab" }, { "input": "26 13", "output": "abcdefghijklmabcde...
1,620,421,674
2,147,483,647
PyPy 3
OK
TESTS
47
171
22,220,800
from string import ascii_lowercase as alphabet n, k = map(int, input().split()) ind = 0 s = '' for i in range(n): s += alphabet[ind] ind += 1 if ind == k: ind = 0 print(s)
Title: New Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the foll...
```python from string import ascii_lowercase as alphabet n, k = map(int, input().split()) ind = 0 s = '' for i in range(n): s += alphabet[ind] ind += 1 if ind == k: ind = 0 print(s) ```
3
762
B
USB vs. PS/2
PROGRAMMING
1,400
[ "greedy", "implementation", "sortings", "two pointers" ]
null
null
Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ...
The first line contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=105)  — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer *m* (0<=≤<=*m*<=≤<=3·105...
Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy.
[ "2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2\n" ]
[ "3 14\n" ]
In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
0
[ { "input": "2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2", "output": "3 14" }, { "input": "1 4 4\n12\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n916758386 PS/2\n474310330 USB\n350512489 USB\n281054887 USB\n875326145 USB", "output": "8 23453...
1,617,150,172
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
16
2,000
32,665,600
u, p, b = tuple(map(int, input().split())) m = int(input()) inventory = [] for i in range(m): x, y = input().split() inventory.append((int(x),y)) inventory.sort() cost = 0 mouses = 0 for i in range(m): if inventory[i][1] == "USB": if u > 0: u -= 1 cost += inventory[i][0] mo...
Title: USB vs. PS/2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the c...
```python u, p, b = tuple(map(int, input().split())) m = int(input()) inventory = [] for i in range(m): x, y = input().split() inventory.append((int(x),y)) inventory.sort() cost = 0 mouses = 0 for i in range(m): if inventory[i][1] == "USB": if u > 0: u -= 1 cost += inventory[i][0]...
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,638,900,138
2,147,483,647
PyPy 3
OK
TESTS
30
154
0
a = input() l = len(a) cnt = 0 for i in a: if i.islower():cnt += 1 print(a.upper() if l / 2 > cnt else a.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python a = input() l = len(a) cnt = 0 for i in a: if i.islower():cnt += 1 print(a.upper() if l / 2 > cnt else a.lower()) ```
3.9615
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to ti...
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number — the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "o...
1,694,842,849
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
s=input() s = s.replace(",", "") s=set(s) print(len(s)-2)
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi...
```python s=input() s = s.replace(",", "") s=set(s) print(len(s)-2) ```
0
464
E
The Classic Problem
PROGRAMMING
3,000
[ "data structures", "graphs", "shortest paths" ]
null
null
You are given a weighted undirected graph on *n* vertices and *m* edges. Find the shortest path from vertex *s* to vertex *t* or else state that such path doesn't exist.
The first line of the input contains two space-separated integers — *n* and *m* (1<=≤<=*n*<=≤<=105; 0<=≤<=*m*<=≤<=105). Next *m* lines contain the description of the graph edges. The *i*-th line contains three space-separated integers — *u**i*, *v**i*, *x**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; 0<=≤<=*x**i*<=≤<=105). That...
In the first line print the remainder after dividing the length of the shortest path by 1000000007 (109<=+<=7) if the path exists, and -1 if the path doesn't exist. If the path exists print in the second line integer *k* — the number of vertices in the shortest path from vertex *s* to vertex *t*; in the third line pri...
[ "4 4\n1 4 2\n1 2 0\n2 3 0\n3 4 0\n1 4\n", "4 3\n1 2 4\n2 3 5\n3 4 6\n1 4\n", "4 2\n1 2 0\n3 4 1\n1 4\n" ]
[ "3\n4\n1 2 3 4 \n", "112\n4\n1 2 3 4 \n", "-1\n" ]
A path from vertex *s* to vertex *t* is a sequence *v*<sub class="lower-index">0</sub>, ..., *v*<sub class="lower-index">*k*</sub>, such that *v*<sub class="lower-index">0</sub> = *s*, *v*<sub class="lower-index">*k*</sub> = *t*, and for any *i* from 0 to *k* - 1 vertices *v*<sub class="lower-index">*i*</sub> and *v*<s...
2,500
[]
1,684,119,996
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
14
5,000
323,788,800
# https://codeforces.com/contest/464/problem/E import heapq def dijkstra(adj_list, start, target): n = len(adj_list) distance = [float('inf')] * n prev = [-1] * n distance[start] = 0 heap = [(0, start)] while heap: dist, node = heapq.heappop(heap) if node == targe...
Title: The Classic Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a weighted undirected graph on *n* vertices and *m* edges. Find the shortest path from vertex *s* to vertex *t* or else state that such path doesn't exist. Input Specification: The first line of the i...
```python # https://codeforces.com/contest/464/problem/E import heapq def dijkstra(adj_list, start, target): n = len(adj_list) distance = [float('inf')] * n prev = [-1] * n distance[start] = 0 heap = [(0, start)] while heap: dist, node = heapq.heappop(heap) if nod...
0
478
A
Initial Bet
PROGRAMMING
1,100
[ "implementation" ]
null
null
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins *b* as an initial bet. After all players make their bets of *b* coins, the following operation is repeated for several times: a coin is passed from one player to some other player. Your task is to write a program ...
The input consists of a single line containing five integers *c*1,<=*c*2,<=*c*3,<=*c*4 and *c*5 — the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0<=≤<=*c*1,<=*c*2,<=*c*3,<=*c*4,<=*c*5<=≤<=100).
Print the only line containing a single positive integer *b* — the number of coins in the initial bet of each player. If there is no such value of *b*, then print the only value "-1" (quotes for clarity).
[ "2 5 4 0 4\n", "4 5 9 2 1\n" ]
[ "3\n", "-1\n" ]
In the first sample the following sequence of operations is possible: 1. One coin is passed from the fourth player to the second player; 1. One coin is passed from the fourth player to the fifth player; 1. One coin is passed from the first player to the third player; 1. One coin is passed from the fourth player to...
500
[ { "input": "2 5 4 0 4", "output": "3" }, { "input": "4 5 9 2 1", "output": "-1" }, { "input": "0 0 0 0 0", "output": "-1" }, { "input": "1 2 1 2 3", "output": "-1" }, { "input": "100 0 0 0 0", "output": "20" }, { "input": "2 3 4 5 6", "output": "4"...
1,683,620,266
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
arr = list(map(int, input().split(' '))) maxi = max(arr) flag = 0 for i in range(maxi): sumi = 0 for j in range (5): sumi += arr[j]-i if sumi == 0: print(i) flag = 0 break else: flag = 1 if flag == 1: print("-1")
Title: Initial Bet Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are five people playing a game called "Generosity". Each person gives some non-zero number of coins *b* as an initial bet. After all players make their bets of *b* coins, the following operation is repeated for severa...
```python arr = list(map(int, input().split(' '))) maxi = max(arr) flag = 0 for i in range(maxi): sumi = 0 for j in range (5): sumi += arr[j]-i if sumi == 0: print(i) flag = 0 break else: flag = 1 if flag == 1: print("-1") ```
0
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains...
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: ...
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "...
1,674,132,139
2,147,483,647
Python 3
OK
TESTS
42
92
0
r, c = [int(i) for i in input().split()] arr = [] s = 0 res = 0 c_s = 0 for i in range(r): x = input() arr.append(x) if 'S' in x: s += 1 res += (r - s) * c for i in range(c): straw = False for j in range(r): if arr[j][i] == 'S': straw = True br...
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each ti...
```python r, c = [int(i) for i in input().split()] arr = [] s = 0 res = 0 c_s = 0 for i in range(r): x = input() arr.append(x) if 'S' in x: s += 1 res += (r - s) * c for i in range(c): straw = False for j in range(r): if arr[j][i] == 'S': straw = True ...
3
805
A
Fake NP
PROGRAMMING
1,000
[ "greedy", "math" ]
null
null
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times...
The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109).
Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them.
[ "19 29\n", "3 6\n" ]
[ "2\n", "3\n" ]
Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html) The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {...
500
[ { "input": "19 29", "output": "2" }, { "input": "3 6", "output": "2" }, { "input": "39 91", "output": "2" }, { "input": "76 134", "output": "2" }, { "input": "93 95", "output": "2" }, { "input": "17 35", "output": "2" }, { "input": "94 95",...
1,628,053,717
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
24
62
6,758,400
a,b=list(map(int,input().split())) print(2)
Title: Fake NP Time Limit: None seconds Memory Limit: None megabytes Problem Description: Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of the...
```python a,b=list(map(int,input().split())) print(2) ```
0
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,699,132,877
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
#I - Elephant num=int(input()) if num%5 ==0: print(num/5) else : print((num//5)+1)
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 #I - Elephant num=int(input()) if num%5 ==0: print(num/5) else : print((num//5)+1) ```
0
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,683,669,270
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
a, b = map(int, input().split()) ops = [] while b > a: if b % 2 == 0: b //= 2 ops.append("/") elif b % 10 == 1: b //= 10 ops.append("-") else: break if b == a: ops.reverse() print("YES") print(len(ops)) print(a, end=" ") for o...
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 a, b = map(int, input().split()) ops = [] while b > a: if b % 2 == 0: b //= 2 ops.append("/") elif b % 10 == 1: b //= 10 ops.append("-") else: break if b == a: ops.reverse() print("YES") print(len(ops)) print(a, end=" ") ...
0
1,009
B
Minimum Ternary String
PROGRAMMING
1,400
[ "greedy", "implementation" ]
null
null
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For e...
The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive).
Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
[ "100210\n", "11222121\n", "20\n" ]
[ "001120\n", "11112222\n", "20\n" ]
none
0
[ { "input": "100210", "output": "001120" }, { "input": "11222121", "output": "11112222" }, { "input": "20", "output": "20" }, { "input": "1002", "output": "0012" }, { "input": "10", "output": "01" }, { "input": "000021", "output": "000012" }, { ...
1,532,446,629
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
5
109
204,800
s = input() s1 = "" for i in s: if i == '1': s1 += '1' s = s.replace('1', '') pos = s.index('2') s = s[:pos] + s1 + s[pos:] print(s)
Title: Minimum Ternary String Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) ...
```python s = input() s1 = "" for i in s: if i == '1': s1 += '1' s = s.replace('1', '') pos = s.index('2') s = s[:pos] + s1 + s[pos:] print(s) ```
-1
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,616,587,027
2,147,483,647
Python 3
OK
TESTS
102
77
0
a=input() b=input() count=0 for j in a: if j == '0' or j == '1': count+=1 res = [int(x) for x in str(a)] k = [int(x) for x in str(b)] for i in range (count): if res[i] == k[i]: print("0",end="") else: print("1",end="")
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python a=input() b=input() count=0 for j in a: if j == '0' or j == '1': count+=1 res = [int(x) for x in str(a)] k = [int(x) for x in str(b)] for i in range (count): if res[i] == k[i]: print("0",end="") else: print("1",end="") ```
3.98075
780
A
Andryusha and Socks
PROGRAMMING
800
[ "implementation" ]
null
null
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ...
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs. The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ...
Print single integer — the maximum number of socks that were on the table at the same time.
[ "1\n1 1\n", "3\n2 1 1 3 2 3\n" ]
[ "1\n", "2\n" ]
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - ...
500
[ { "input": "1\n1 1", "output": "1" }, { "input": "3\n2 1 1 3 2 3", "output": "2" }, { "input": "5\n5 1 3 2 4 3 1 2 4 5", "output": "5" }, { "input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7", "output": "6" }, { "input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ...
1,556,315,201
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
2,000
13,824,000
int(input()) d = list(map(int, input().split())) maxResult = 0 temp = [] for n in d: if n not in temp: temp.append(n) if maxResult < len(temp): maxResult = len(temp) else: temp.remove(n) print(maxResult)
Title: Andryusha and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere...
```python int(input()) d = list(map(int, input().split())) maxResult = 0 temp = [] for n in d: if n not in temp: temp.append(n) if maxResult < len(temp): maxResult = len(temp) else: temp.remove(n) print(maxResult) ```
0
550
A
Two Substrings
PROGRAMMING
1,500
[ "brute force", "dp", "greedy", "implementation", "strings" ]
null
null
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters.
Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
[ "ABA\n", "BACFAB\n", "AXBYBXA\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
1,000
[ { "input": "ABA", "output": "NO" }, { "input": "BACFAB", "output": "YES" }, { "input": "AXBYBXA", "output": "NO" }, { "input": "ABABAB", "output": "YES" }, { "input": "BBBBBBBBBB", "output": "NO" }, { "input": "ABBA", "output": "YES" }, { "...
1,687,368,261
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
s = input() a1, a2 = 0, 0 a3, a4 = 0, 0 if 'AB' in s and 'BA' in s: for i in range(len(s)-1): if s[i] + s[i+1] == 'AB': a1, a2 = i, i+1 break for i in range(len(s) - 1, 0, -1): if s[i-1] + s[i] == 'BA': a3, a4 == i-1, i break if a1 ...
Title: Two Substrings Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). Input Specification: The only line of input contain...
```python s = input() a1, a2 = 0, 0 a3, a4 = 0, 0 if 'AB' in s and 'BA' in s: for i in range(len(s)-1): if s[i] + s[i+1] == 'AB': a1, a2 = i, i+1 break for i in range(len(s) - 1, 0, -1): if s[i-1] + s[i] == 'BA': a3, a4 == i-1, i break ...
0