problem_id
stringlengths
3
7
contestId
stringclasses
660 values
problem_index
stringclasses
27 values
programmingLanguage
stringclasses
3 values
testset
stringclasses
5 values
incorrect_passedTestCount
float64
0
146
incorrect_timeConsumedMillis
float64
15
4.26k
incorrect_memoryConsumedBytes
float64
0
271M
incorrect_submission_id
stringlengths
7
9
incorrect_source
stringlengths
10
27.7k
correct_passedTestCount
float64
2
360
correct_timeConsumedMillis
int64
30
8.06k
correct_memoryConsumedBytes
int64
0
475M
correct_submission_id
stringlengths
7
9
correct_source
stringlengths
28
21.2k
contest_name
stringclasses
664 values
contest_type
stringclasses
3 values
contest_start_year
int64
2.01k
2.02k
time_limit
float64
0.5
15
memory_limit
float64
64
1.02k
title
stringlengths
2
54
description
stringlengths
35
3.16k
input_format
stringlengths
67
1.76k
output_format
stringlengths
18
1.06k
interaction_format
null
note
stringclasses
840 values
examples
stringlengths
34
1.16k
rating
int64
800
3.4k
tags
stringclasses
533 values
testset_size
int64
2
360
official_tests
stringlengths
44
19.7M
official_tests_complete
bool
1 class
input_mode
stringclasses
1 value
generated_checker
stringclasses
231 values
executable
bool
1 class
413/C
413
C
PyPy 3
TESTS
19
93
0
143149190
n,m = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) c = [] res = 0 for i in b: c.append(a[i-1]) c = sorted(c,reverse=True) for i in a: if i not in c:res+=i for i in c: if res>i:res+=res else:res+=i print(res)
67
46
0
178760251
n, m = list(map(int, input().split())) arr = list(map(int, input().split())) auction = set(map(int, input().split())) non_auction_sum = 0 max_auction = 0 for i in range(n): if (i+1) in auction: max_auction = max(max_auction, arr[i]) else: non_auction_sum += arr[i] if non_auction_sum < max_auct...
Coder-Strike 2014 - Round 2
CF
2,014
1
256
Jeopardy!
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2. The finals will have n questions, m of them are auction questi...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100; m ≤ min(n, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the prices of the questions. The third line contains m ...
In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type.
null
null
[{"input": "4 1\n1 3 7 5\n3", "output": "18"}, {"input": "3 2\n10 3 8\n2 3", "output": "40"}, {"input": "2 2\n100 200\n1 2", "output": "400"}]
1,400
["greedy", "math"]
67
[{"input": "4 1\r\n1 3 7 5\r\n3\r\n", "output": "18\r\n"}, {"input": "3 2\r\n10 3 8\r\n2 3\r\n", "output": "40\r\n"}, {"input": "2 2\r\n100 200\r\n1 2\r\n", "output": "400\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "2 2\r\n1 5\r\n1 2\r\n", "output": "10\r\n"}, {"input": "5 3\r\n5 8 7 1 9\r\n2 5...
false
stdio
null
true
793/C
793
C
PyPy 3
PRETESTS
6
93
23,347,200
26615105
# t*v+a = b # t=(b-a)/v import sys #sys.stdin=open("data.txt") input=sys.stdin.readline mintime=0 maxtime=10**9 useless=0 n=int(input()) #include <math.h> # int 'y1' redeclared as different kind of symbol x1,y1,x2,y2=map(int,input().split()) for _ in range(n): rx,ry,vx,vy=map(int,input().split()) # x time ...
80
748
0
44048034
def comp( x , v , l , r ) : if x < l and v <= 0 : return [-1,-10] if x > r and v >= 0 : return [-1,-10] if x >= l and x <= r : if v == 0 : if x == l or x == r : return [-1,-10] else : return [0,10**18] if v > 0 : ...
Tinkoff Challenge - Elimination Round
CF
2,017
2
256
Mice problem
Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located i...
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≤ x1 ≤ x2 ≤ 100 000), (0 ≤ y1 ≤ y2 ≤ 100 000) — the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mic...
In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formall...
null
Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. Then, at first time when all mice will be in rectangle it will be looks like this: Here is a picture of the second sample Points A, D, B will never enter rectangle.
[{"input": "4\n7 7 9 8\n3 5 7 5\n7 5 2 4\n3 3 7 8\n6 6 3 2", "output": "0.57142857142857139685"}, {"input": "4\n7 7 9 8\n0 3 -5 4\n5 0 5 4\n9 9 -1 -6\n10 5 -7 -10", "output": "-1"}]
2,300
["geometry", "implementation", "math", "sortings"]
80
[{"input": "4\r\n7 7 9 8\r\n3 5 7 5\r\n7 5 2 4\r\n3 3 7 8\r\n6 6 3 2\r\n", "output": "0.57142857142857139685\r\n"}, {"input": "4\r\n7 7 9 8\r\n0 3 -5 4\r\n5 0 5 4\r\n9 9 -1 -6\r\n10 5 -7 -10\r\n", "output": "-1\r\n"}, {"input": "4\r\n8 42 60 54\r\n9 54 -58 -62\r\n46 47 52 -76\r\n15 50 -37 -40\r\n54 51 78 64\r\n", "outp...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(output_path, 'r') as f: ref_line = f.readline().strip() with open(submission_path, 'r') as f: sub_line = f.readline().strip() if ref_line == '-1': print(1 if sub_line == '-1' else 0) return ...
true
623/A
623
A
PyPy 3
TESTS
25
295
10,240,000
85870959
from sys import stdin n,m = [int(x) for x in stdin.readline().split()] graph = [set([y for y in range(n)]) for x in range(n)] for x in range(n): graph[x].remove(x) for edge in range(m): a,b = [int(x) for x in stdin.readline().split()] a -= 1 b -= 1 graph[a].remove(b) graph[b].remove(a) not...
106
514
18,329,600
52719106
from math import * N, M = 510, 3 * 10 ** 5 + 10 g = [[] for _ in range(M)] n , m = map(int, input().split()) mx = [[False] * N for _ in range(N + 1)] for _ in range(m): u, v = map(int, input().split()) mx[u][v] = mx[v][u] = True all_eq = True mark = [False] * N for i in range(1, n + 1): for j in range(i + 1, n ...
AIM Tech Round (Div. 1)
CF
2,016
2
256
Graph and String
One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties: - G has exactly n vertices, numbered from 1 to n....
The first line of the input contains two integers n and m $$( 1 \leq n \leq 500, 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$ — the number of vertices and edges in the graph found by Petya, respectively. Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It ...
In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise. If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the gra...
null
In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions. In the second sample the first vertex is connected to al...
[{"input": "2 1\n1 2", "output": "Yes\naa"}, {"input": "4 3\n1 2\n1 3\n1 4", "output": "No"}]
1,800
["constructive algorithms", "graphs"]
106
[{"input": "2 1\r\n1 2\r\n", "output": "Yes\r\naa\r\n"}, {"input": "4 3\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 2\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "1 0\r\n", "output": "Yes\r\na\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r...
false
stdio
import sys def main(): input_path = sys.argv[1] ref_output_path = sys.argv[2] sub_output_path = sys.argv[3] # Read input with open(input_path) as f: n, m = map(int, f.readline().split()) edges = [] for _ in range(m): u, v = map(int, f.readline().split()) ...
true
623/A
623
A
PyPy 3-64
TESTS
25
140
5,529,600
148067886
import sys input = lambda: sys.stdin.buffer.readline().decode().strip() n, m = map(int, input().split()) adj, ans = [[False] * n for _ in range(n)], [''] * n for _ in range(m): u, v = map(int, input().split()) adj[u - 1][v - 1] = adj[v - 1][u - 1] = True for i in range(n): for j in range(n): if i ...
106
623
1,228,800
15798582
n, m = map(int, input().split()) s = [[0] * n for i in range(n)] for i in range(m): a, b = map(int, input().split()) s[a - 1][b - 1] = 1 s[b - 1][a - 1] = 1 for i in range(n): s[i][i] = 1 answer = [0] * n for i in range(n): flag = True for j in range(n): if s[i][j] == 0: fla...
AIM Tech Round (Div. 1)
CF
2,016
2
256
Graph and String
One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties: - G has exactly n vertices, numbered from 1 to n....
The first line of the input contains two integers n and m $$( 1 \leq n \leq 500, 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$ — the number of vertices and edges in the graph found by Petya, respectively. Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It ...
In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise. If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the gra...
null
In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions. In the second sample the first vertex is connected to al...
[{"input": "2 1\n1 2", "output": "Yes\naa"}, {"input": "4 3\n1 2\n1 3\n1 4", "output": "No"}]
1,800
["constructive algorithms", "graphs"]
106
[{"input": "2 1\r\n1 2\r\n", "output": "Yes\r\naa\r\n"}, {"input": "4 3\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 2\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "1 0\r\n", "output": "Yes\r\na\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r...
false
stdio
import sys def main(): input_path = sys.argv[1] ref_output_path = sys.argv[2] sub_output_path = sys.argv[3] # Read input with open(input_path) as f: n, m = map(int, f.readline().split()) edges = [] for _ in range(m): u, v = map(int, f.readline().split()) ...
true
745/B
745
B
Python 3
TESTS
36
139
4,608,000
23058646
n,m = map(int,list(input().split())) ar = [0]*m for i in range(n): s = input() for j in range(m): if s[j]=='X': ar[j]+=1 ss = set(ar) ss.discard(0) if len(ss)>1: print('NO') else: print('YES') # C:\Users\Usuario\HOME2\Programacion\ACM
77
62
6,758,400
23066037
def codeforces(piece): row_number = 0 for row in piece: num = row.count('X') if num == 0: continue if row_number == 0: row_number = num continue if num != row_number: return 'NO' col_number = 0 cols = [[row[i] for row in pi...
Codeforces Round 385 (Div. 2)
CF
2,016
2
256
Hongcow Solves A Puzzle
Hongcow likes solving puzzles. One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that th...
The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece. The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is gua...
Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise.
null
For the first sample, one example of a rectangle we can form is as follows For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle. In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle:
[{"input": "2 3\nXXX\nXXX", "output": "YES"}, {"input": "2 2\n.X\nXX", "output": "NO"}, {"input": "5 5\n.....\n..X..\n.....\n.....\n.....", "output": "YES"}]
1,400
["implementation"]
77
[{"input": "2 3\r\nXXX\r\nXXX\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\nXX\r\n", "output": "NO\r\n"}, {"input": "5 5\r\n.....\r\n..X..\r\n.....\r\n.....\r\n.....\r\n", "output": "YES\r\n"}, {"input": "1 500\r\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...
false
stdio
null
true
515/B
515
B
PyPy 3
TESTS
40
155
1,433,600
75217147
I=lambda:list(map(int,input().split())) n,m=I() a=I()[1::] b=I()[1::] ans=[0]*max(n,m) bo=[0]*n gl=[0]*m for i in a: bo[i-1]=1 for j in b: gl[j-1]=1 boy=set() girl=set() for i in range(n*m+1): x=bo[i%n] y=gl[i%m] if x|y: bo[i%n]=1 gl[i%m]=1 if bo.count(1)+gl.count(1)==n+m: prin...
56
46
0
218400995
import sys sys.setrecursionlimit(100000000) input=lambda:sys.stdin.readline().strip() write=lambda x:sys.stdout.write(str(x)+'\n') # from random import randint # from copy import deepcopy # from collections import deque,Counter # from heapq import heapify,heappush,heappop # from bisect import bisect_left,bisect,insort...
Codeforces Round 292 (Div. 2)
CF
2,015
2
256
Drazil and His Happy Friends
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan. There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites $$(i \bmod n)$$-th...
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi < n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ ...
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
null
By $$i \bmod k$$ we define the remainder of integer division of i by k. In first sample case: - On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. - On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so no...
[{"input": "2 3\n0\n1 0", "output": "Yes"}, {"input": "2 4\n1 0\n1 2", "output": "No"}, {"input": "2 3\n1 0\n1 1", "output": "Yes"}]
1,300
["brute force", "dsu", "meet-in-the-middle", "number theory"]
56
[{"input": "2 3\r\n0\r\n1 0\r\n", "output": "Yes\r\n"}, {"input": "2 4\r\n1 0\r\n1 2\r\n", "output": "No\r\n"}, {"input": "2 3\r\n1 0\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "16 88\r\n6 5 14 2 0 12 7\r\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82\r\n", "output": "Yes\r...
false
stdio
null
true
982/A
982
A
Python 3
TESTS
9
124
0
50425113
n=int(input()) a=str(input()) b=list(a) for i in range(n): b[i]=int(b[i]) k=0 if n==1 and b[0]==0: k=k+1 if n==2 and b[0]==b[1]==0: k=k+1 if n>3: if b[0]==b[1]==0: k=k+1 if b[n-1]==b[n-2]==0: k=k+1 if a.find('11')>=0: k=k+1 if a.find('000')>=0: k=k+1 if k==0: print('Yes') ...
55
46
0
173770461
import sys def read_input(input_path=None): if input_path is None: f = sys.stdin else: f = open(input_path, 'r') n = int(f.readline()) chairs = f.readline().strip() return n, chairs def sol(n, chairs): # chairs = 'o' + chairs + 'o' # # return ["YES" if "xx" not in c...
Codeforces Round 484 (Div. 2)
CF
2,018
1
256
Row
You're given a row with $$$n$$$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 2. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($$$0$$$ m...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of chairs. The next line contains a string of $$$n$$$ characters, each of them is either zero or one, describing the seating.
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
null
In sample case one the given seating is maximal. In sample case two the person at chair three has a neighbour to the right. In sample case three it is possible to seat yet another person into chair three.
[{"input": "3\n101", "output": "Yes"}, {"input": "4\n1011", "output": "No"}, {"input": "5\n10001", "output": "No"}]
1,200
["brute force", "constructive algorithms"]
55
[{"input": "3\r\n101\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1011\r\n", "output": "No\r\n"}, {"input": "5\r\n10001\r\n", "output": "No\r\n"}, {"input": "1\r\n0\r\n", "output": "No\r\n"}, {"input": "1\r\n1\r\n", "output": "Yes\r\n"}, {"input": "100\r\n01010010101010010100100101010010101001010010010010100101010100101...
false
stdio
null
true
982/A
982
A
Python 3
TESTS
49
124
0
44689901
n = int(input()) s = input() first = -1 second = -1 minimum = 9999999 maximum = 0 def check_val(value): if(value==2 or value==3): return True else: return False possible = ['1','01','10','010'] if(s in possible): print('YES') else: for i in range(n): if(int(s[i])==1...
55
46
0
183823666
n=input() s='0'+input()+'0' print('No' if '000' in s or '11' in s else 'Yes')
Codeforces Round 484 (Div. 2)
CF
2,018
1
256
Row
You're given a row with $$$n$$$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 2. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($$$0$$$ m...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of chairs. The next line contains a string of $$$n$$$ characters, each of them is either zero or one, describing the seating.
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
null
In sample case one the given seating is maximal. In sample case two the person at chair three has a neighbour to the right. In sample case three it is possible to seat yet another person into chair three.
[{"input": "3\n101", "output": "Yes"}, {"input": "4\n1011", "output": "No"}, {"input": "5\n10001", "output": "No"}]
1,200
["brute force", "constructive algorithms"]
55
[{"input": "3\r\n101\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1011\r\n", "output": "No\r\n"}, {"input": "5\r\n10001\r\n", "output": "No\r\n"}, {"input": "1\r\n0\r\n", "output": "No\r\n"}, {"input": "1\r\n1\r\n", "output": "Yes\r\n"}, {"input": "100\r\n01010010101010010100100101010010101001010010010010100101010100101...
false
stdio
null
true
446/A
446
A
PyPy 3
TESTS
20
218
10,342,400
47505771
R = lambda: map(int, input().split()) n = int(input()) a = list(R()) dp = [1] * n res = 1 for i in range(n - 2, -1 , -1): dp[i] = dp[i + 1] + 1 if a[i] < a[i + 1] else 1 cnt = 1 for i in range(1, n - 1): if a[i + 1] > a[i - 1] + 1: res = max(res, cnt + dp[i + 1] + 1) else: res = max(res, cnt...
92
186
19,660,800
143453579
n=int(input()) a=list(map(int,input().split())) l=[1] r=[1] for i in range(1,n): if a[i]>a[i-1]: l.append(l[-1]+1) else: l.append(1) for i in range(n-2,-1,-1): if a[i]<a[i+1]: r.append(r[-1]+1) else : r.append(1) r=r[::-1] mx=max(max(l),max(r)) if mx!=n: mx+=1 for i i...
Codeforces Round #FF (Div. 1)
CF
2,014
1
256
DZY Loves Sequences
DZY has a sequence a, consisting of n integers. We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one numb...
The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).
In a single line print the answer to the problem — the maximum length of the required subsegment.
null
You can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4.
[{"input": "6\n7 2 3 1 5 6", "output": "5"}]
1,600
["dp", "implementation", "two pointers"]
92
[{"input": "6\r\n7 2 3 1 5 6\r\n", "output": "5\r\n"}, {"input": "10\r\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422\r\n", "output": "9\r\n"}, {"input": "50\r\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202...
false
stdio
null
true
550/A
550
A
Python 3
TESTS
50
93
8,396,800
214120912
string = input() ans = [] count = 0 i = 1 sett =set() for i in range(1,len(string)): if (string[i-1] == "A" and string[i] == "B") or (string[i-1] == "B" and string[i] == "A"): ans.append([string[i-1]+string[i],i-1,i]) # print(ans) x =True result = "NO" a,b= -1,-1 for i in ans: if i[0]=="AB": ...
85
46
0
187124557
a=input() n=a.split("AB",1) r=a.split("BA",1) if len(n)>1 and "BA" in n[1]: print ("YES") elif len(r)>1 and "AB" in r[1]: print ("YES") else: print ("NO")
Codeforces Round 306 (Div. 2)
CF
2,015
2
256
Two Substrings
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.
null
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".
[{"input": "ABA", "output": "NO"}, {"input": "BACFAB", "output": "YES"}, {"input": "AXBYBXA", "output": "NO"}]
1,500
["brute force", "dp", "greedy", "implementation", "strings"]
85
[{"input": "ABA\r\n", "output": "NO\r\n"}, {"input": "BACFAB\r\n", "output": "YES\r\n"}, {"input": "AXBYBXA\r\n", "output": "NO\r\n"}, {"input": "ABABAB\r\n", "output": "YES\r\n"}, {"input": "BBBBBBBBBB\r\n", "output": "NO\r\n"}, {"input": "ABBA\r\n", "output": "YES\r\n"}, {"input": "ABAXXXAB\r\n", "output": "YES\r\n"}...
false
stdio
null
true
550/A
550
A
Python 3
TESTS
36
1,981
8,294,400
202949868
s = str(input()) ans = 'NO' if 'AB' not in s and 'BA' not in s: ans = 'NO' else: cur = 0 while cur < len(s): try: cur = s.index('AB', cur) s2 = s[0:cur]+s[cur+2::] if 'BA' in s2: ans = 'YES' break else: c...
85
46
0
189781943
s=input() u=s.find('AB') v=s.find('BA') print('YES'if(u+1 and s.find('BA',u+2)+1)or(v+1 and s.find('AB',v+2)+1)else'NO')
Codeforces Round 306 (Div. 2)
CF
2,015
2
256
Two Substrings
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.
null
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".
[{"input": "ABA", "output": "NO"}, {"input": "BACFAB", "output": "YES"}, {"input": "AXBYBXA", "output": "NO"}]
1,500
["brute force", "dp", "greedy", "implementation", "strings"]
85
[{"input": "ABA\r\n", "output": "NO\r\n"}, {"input": "BACFAB\r\n", "output": "YES\r\n"}, {"input": "AXBYBXA\r\n", "output": "NO\r\n"}, {"input": "ABABAB\r\n", "output": "YES\r\n"}, {"input": "BBBBBBBBBB\r\n", "output": "NO\r\n"}, {"input": "ABBA\r\n", "output": "YES\r\n"}, {"input": "ABAXXXAB\r\n", "output": "YES\r\n"}...
false
stdio
null
true
550/A
550
A
PyPy 3-64
TESTS
63
62
1,945,600
207965257
#import io, os, sys #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #print = lambda x: sys.stdout.write(str(x) + "\n") II = lambda: int(input()) MII = lambda: map(int, input().split()) LMII = lambda: list(MII()) #SLMII = lambda: sorted(LMII()) s = input() n = len(s) sABBA = ['AB', 'BA'] i = j = 0 sB...
85
46
0
190125776
str=input() x1=str.find("AB") x2=str.find("BA",x1+2) y1=str.find("BA") y2=str.find("AB",y1+2) if (x1!=-1 and x2!=-1) or (y1!=-1 and y2!=-1): print("YES") else: print("NO")
Codeforces Round 306 (Div. 2)
CF
2,015
2
256
Two Substrings
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.
null
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".
[{"input": "ABA", "output": "NO"}, {"input": "BACFAB", "output": "YES"}, {"input": "AXBYBXA", "output": "NO"}]
1,500
["brute force", "dp", "greedy", "implementation", "strings"]
85
[{"input": "ABA\r\n", "output": "NO\r\n"}, {"input": "BACFAB\r\n", "output": "YES\r\n"}, {"input": "AXBYBXA\r\n", "output": "NO\r\n"}, {"input": "ABABAB\r\n", "output": "YES\r\n"}, {"input": "BBBBBBBBBB\r\n", "output": "NO\r\n"}, {"input": "ABBA\r\n", "output": "YES\r\n"}, {"input": "ABAXXXAB\r\n", "output": "YES\r\n"}...
false
stdio
null
true
446/A
446
A
PyPy 3
TESTS
20
202
12,390,400
110830424
n=int(input()) arr=list(map(int,input().split())) pre,pre1=[1],[1] for i in range(1,n): if arr[i]>arr[i-1]: pre.append(pre[-1]+1) else: pre.append(1) arr.reverse() for i in range(1,n): if arr[i]<arr[i-1]: pre1.append(pre1[-1]+1) else: pre1.append(1) pre1.reverse() arr.rev...
92
187
15,257,600
115861712
n=int(input()) a=[0]+list(map(int,input().split()))+[0] l=[] st=1 for i in range(2,n+2): if a[i]<=a[i-1]: l.append([st,i-1]) st=i if len(l)==1: print(n) exit() mx=0 for i in range(1,len(l)): lf=l[i-1][1] rt=l[i][0] ln1=l[i][1]-l[i][0]+1 ln2=l[i-1][1]-l[i-1][0]+1 if a[rt...
Codeforces Round #FF (Div. 1)
CF
2,014
1
256
DZY Loves Sequences
DZY has a sequence a, consisting of n integers. We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one numb...
The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).
In a single line print the answer to the problem — the maximum length of the required subsegment.
null
You can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4.
[{"input": "6\n7 2 3 1 5 6", "output": "5"}]
1,600
["dp", "implementation", "two pointers"]
92
[{"input": "6\r\n7 2 3 1 5 6\r\n", "output": "5\r\n"}, {"input": "10\r\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422\r\n", "output": "9\r\n"}, {"input": "50\r\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202...
false
stdio
null
true
837/D
837
D
PyPy 3
TESTS
23
124
20,070,400
132496966
def main(): n,k = map(int, input().split()) A = list(map(int,input().split())) A2 = [0]*n A5 = [0]*n for i, a in enumerate(A): while a%2 == 0: A2[i] += 1 a //= 2 while a%5 == 0: A5[i] += 1 a //= 5 #print(A2) #print(A5) INF...
99
623
11,161,600
172361559
import sys input = sys.stdin.readline n, k = map(int, input().split()) a = list(map(int, input().split())) sc5, c2, c5 = 0, [], [] for i in range(n): num, c = a[i], 0 while num % 5 == 0: num //= 5 c += 1 sc5 += c c5.append(c) c = 0 while num % 2 == 0: num //= 2 c ...
Educational Codeforces Round 26
ICPC
2,017
2
256
Round Subset
Let's call the roundness of the number the number of zeros to which it ends. You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n). The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Print maximal roundness of product of the chosen subset of length k.
null
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3. In the second example subset [15, 16, 25] has product 6000, roundness 3. In the third example all subsets has product with roundness 0.
[{"input": "3 2\n50 4 20", "output": "3"}, {"input": "5 3\n15 16 3 25 9", "output": "3"}, {"input": "3 3\n9 77 13", "output": "0"}]
2,100
["dp", "math"]
99
[{"input": "3 2\r\n50 4 20\r\n", "output": "3\r\n"}, {"input": "5 3\r\n15 16 3 25 9\r\n", "output": "3\r\n"}, {"input": "3 3\r\n9 77 13\r\n", "output": "0\r\n"}, {"input": "1 1\r\n200000000\r\n", "output": "8\r\n"}, {"input": "1 1\r\n3\r\n", "output": "0\r\n"}, {"input": "3 1\r\n1000000000000000000 800000000000000000 6...
false
stdio
null
true
847/E
847
E
Python 3
TESTS
16
124
0
44568676
from math import ceil def solve(field,size,answer): left = 0 star_pos = -1 rstar_pos = -1 p_pos = -1 distance = 0 cost = 0 for i in range(size): #print(p_pos,star_pos) if field[i] == "*": if star_pos != -1: if p_pos != -1: if st...
77
124
7,372,800
121279454
''' pacman->food pacman->food->food :hmmge: larges smaller val smallest larger val ''' def check(mid,p,f): u=0 for i in range(len(p)): left=p[i]-f[u] left=max(0,left) if mid<left: return 0 right=max(mid-2*left,0) right=max(right,(mid-left)//2) while u<len(f) and (f[u]<=p[i]+right): #bich mai fas ra ...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
1
256
Packmen
A game field is a strip of 1 × n square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty. Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk. In the initial mome...
The first line contains a single integer n (2 ≤ n ≤ 105) — the length of the game field. The second line contains the description of the game field consisting of n symbols. If there is symbol '.' in position i — the cell i is empty. If there is symbol '*' in position i — in the cell i contains an asterisk. If there is...
Print minimum possible time after which Packmen can eat all asterisks.
null
In the first example Packman in position 4 will move to the left and will eat asterisk in position 1. He will spend 3 time units on it. During the same 3 time units Packman in position 6 will eat both of neighboring with it asterisks. For example, it can move to the left and eat asterisk in position 5 (in 1 time unit) ...
[{"input": "7\n*..P*P*", "output": "3"}, {"input": "10\n.**PP.*P.*", "output": "2"}]
1,800
["binary search", "dp"]
77
[{"input": "7\r\n*..P*P*\r\n", "output": "3\r\n"}, {"input": "10\r\n.**PP.*P.*\r\n", "output": "2\r\n"}, {"input": "19\r\n**P.*..*..P..*.*P**\r\n", "output": "7\r\n"}, {"input": "12\r\nP**.*P*P*P**\r\n", "output": "3\r\n"}, {"input": "17\r\n.*P*P**P**.**P...\r\n", "output": "3\r\n"}, {"input": "58\r\n..P.P*.P*.P...PPP....
false
stdio
null
true
837/D
837
D
PyPy 3
TESTS
13
233
5,632,000
57330897
n, k = map(int, input().split()) a = list(map(int, input().split())) b = [[0 for i in range(2)] for j in range(n)] for i in range(n): while a[i] % 2 == 0: b[i][0] += 1 a[i] >>= 1 while a[i] % 5 == 0: b[i][1] += 1 a[i] //= 5 cur2, cur5 = 0, 0 for i in range(k): cur2 += b[i][0]...
99
857
11,878,400
172414804
import sys import math import collections import random from heapq import heappush, heappop from functools import reduce input = sys.stdin.readline ints = lambda: list(map(int, input().split())) def printQry(a, b) -> None: sa = str(a) sb = str(b) print(f"? {sa} {sb}", flush = True) def printAns(ans) -> N...
Educational Codeforces Round 26
ICPC
2,017
2
256
Round Subset
Let's call the roundness of the number the number of zeros to which it ends. You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n). The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Print maximal roundness of product of the chosen subset of length k.
null
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3. In the second example subset [15, 16, 25] has product 6000, roundness 3. In the third example all subsets has product with roundness 0.
[{"input": "3 2\n50 4 20", "output": "3"}, {"input": "5 3\n15 16 3 25 9", "output": "3"}, {"input": "3 3\n9 77 13", "output": "0"}]
2,100
["dp", "math"]
99
[{"input": "3 2\r\n50 4 20\r\n", "output": "3\r\n"}, {"input": "5 3\r\n15 16 3 25 9\r\n", "output": "3\r\n"}, {"input": "3 3\r\n9 77 13\r\n", "output": "0\r\n"}, {"input": "1 1\r\n200000000\r\n", "output": "8\r\n"}, {"input": "1 1\r\n3\r\n", "output": "0\r\n"}, {"input": "3 1\r\n1000000000000000000 800000000000000000 6...
false
stdio
null
true
681/A
681
A
Python 3
TESTS
8
62
0
116228551
n=int(input()) k=[] z=0 for i in range(n): k+=input().split() for i in range(1,len(k)): if (k[i])>="2400" and i%3!=0: z+=1 if z>=2 and k[i-1]<k[i]: print("YES") break else: z=0 else: print("NO")
60
31
0
149208261
con=True for _ in [0]*int(input()): a=[*map(int,input().split()[1:])] if a[0]>=2400 and a[1]>a[0] and con:print('YES');con=False if con:print('NO')
Codeforces Round 357 (Div. 2)
CF
2,016
1
256
A Good Contest
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest . The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — parti...
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
null
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before...
[{"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES"}, {"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO"}]
800
["implementation"]
60
[{"input": "3\r\nBurunduk1 2526 2537\r\nBudAlNik 2084 2214\r\nsubscriber 2833 2749\r\n", "output": "YES"}, {"input": "3\r\nApplejack 2400 2400\r\nFluttershy 2390 2431\r\nPinkie_Pie -2500 -2450\r\n", "output": "NO"}, {"input": "1\r\nDb -3373 3591\r\n", "output": "NO"}, {"input": "5\r\nQ2bz 960 2342\r\nhmX 2710 -1348\r\n...
false
stdio
null
true
681/A
681
A
Python 3
TESTS
8
108
0
90044033
n = int(input()) a = [input().split() for i in range(n)] k = 0 for j in range(n): if int(a[j][1]) >= 2400 and a[j][2] > a[j][1]: k += 1 break if k > 0: print('YES') else: print('NO')
60
31
0
221573962
ctr=0 for i in range(int(input())): cid,bef,aft=map(str,input().split()) bef=int(bef) aft=int(aft) if bef>=2400: if aft-bef>0: ctr+=1 if ctr>0: print("YES") else: print("NO")
Codeforces Round 357 (Div. 2)
CF
2,016
1
256
A Good Contest
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest . The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — parti...
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
null
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before...
[{"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES"}, {"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO"}]
800
["implementation"]
60
[{"input": "3\r\nBurunduk1 2526 2537\r\nBudAlNik 2084 2214\r\nsubscriber 2833 2749\r\n", "output": "YES"}, {"input": "3\r\nApplejack 2400 2400\r\nFluttershy 2390 2431\r\nPinkie_Pie -2500 -2450\r\n", "output": "NO"}, {"input": "1\r\nDb -3373 3591\r\n", "output": "NO"}, {"input": "5\r\nQ2bz 960 2342\r\nhmX 2710 -1348\r\n...
false
stdio
null
true
681/A
681
A
Python 3
TESTS
8
93
0
58093743
n=int(input()) f=0 for i in range(n): l=list(map(str,input().split())) if l[1]>='2400' and l[2]>l[1]: f=1 break if f==1: print("YES") else: print("NO")
60
46
0
136167929
n = int(input()) result = 0 for i in range(n): a, b, c = input().split() if int(c) > int(b) >= 2400: result = 1 print("YES" if result == 1 else "NO")
Codeforces Round 357 (Div. 2)
CF
2,016
1
256
A Good Contest
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest . The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — parti...
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
null
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before...
[{"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES"}, {"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO"}]
800
["implementation"]
60
[{"input": "3\r\nBurunduk1 2526 2537\r\nBudAlNik 2084 2214\r\nsubscriber 2833 2749\r\n", "output": "YES"}, {"input": "3\r\nApplejack 2400 2400\r\nFluttershy 2390 2431\r\nPinkie_Pie -2500 -2450\r\n", "output": "NO"}, {"input": "1\r\nDb -3373 3591\r\n", "output": "NO"}, {"input": "5\r\nQ2bz 960 2342\r\nhmX 2710 -1348\r\n...
false
stdio
null
true
681/A
681
A
PyPy 3
TESTS
8
140
0
71018318
k=0 for i in range(int(input())): a,x,y=input().split() if int(x)>=2400 and y>x: k=1 if k==1: print("YES") else: print("NO")
60
46
0
139355211
t=int(input()) check=1 for i in range(t): s=input() a=s.split(' ') if int(a[1])>=2400 and int(a[1])<int(a[2]): check=0 if check==1: print('NO') else: print('YES')
Codeforces Round 357 (Div. 2)
CF
2,016
1
256
A Good Contest
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest . The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — parti...
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
null
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before...
[{"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES"}, {"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO"}]
800
["implementation"]
60
[{"input": "3\r\nBurunduk1 2526 2537\r\nBudAlNik 2084 2214\r\nsubscriber 2833 2749\r\n", "output": "YES"}, {"input": "3\r\nApplejack 2400 2400\r\nFluttershy 2390 2431\r\nPinkie_Pie -2500 -2450\r\n", "output": "NO"}, {"input": "1\r\nDb -3373 3591\r\n", "output": "NO"}, {"input": "5\r\nQ2bz 960 2342\r\nhmX 2710 -1348\r\n...
false
stdio
null
true
681/A
681
A
Python 3
TESTS
8
108
0
77606288
for _ in range(int(input())): name, before, after = input().split() if int(before) >=2400: if after > before: print("YES") exit(0) print('NO')
60
46
0
142667952
""" 123456789101112131415 """ import sys import math input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(str,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,in...
Codeforces Round 357 (Div. 2)
CF
2,016
1
256
A Good Contest
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest . The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — parti...
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
null
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before...
[{"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES"}, {"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO"}]
800
["implementation"]
60
[{"input": "3\r\nBurunduk1 2526 2537\r\nBudAlNik 2084 2214\r\nsubscriber 2833 2749\r\n", "output": "YES"}, {"input": "3\r\nApplejack 2400 2400\r\nFluttershy 2390 2431\r\nPinkie_Pie -2500 -2450\r\n", "output": "NO"}, {"input": "1\r\nDb -3373 3591\r\n", "output": "NO"}, {"input": "5\r\nQ2bz 960 2342\r\nhmX 2710 -1348\r\n...
false
stdio
null
true
676/C
676
C
PyPy 3
TESTS
37
155
4,403,200
118349399
def find(a, pref, k): n = len(a) a1 = [] for i in range(n): if i % 2 == 1: a1.append(0) else: a1.append(a[i]) _sum = 0 _max = -1 for i in range(1, n, 2): if a[i] > _max: _max = a[i] r = 1 s1 = a1[0] for l in range(n): ...
117
62
2,764,800
166309064
def solve(c,s): ln=len(s) dp=[0]*(ln+1) for i in range(ln): if s[i]=='a': dp[i+1]=dp[i]+1 else: dp[i+1]=dp[i] lft=0 rt=ln while lft<rt: md=(lft+rt+1)//2 f=0 for i in range(md, ln+1): tmp=dp[i]-dp[i-md] if tmp...
Codeforces Round 354 (Div. 2)
CF
2,016
1
256
Vasya and String
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. W...
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only.
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
null
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
[{"input": "4 2\nabba", "output": "4"}, {"input": "8 1\naabaabaa", "output": "5"}]
1,500
["binary search", "dp", "strings", "two pointers"]
117
[{"input": "4 2\r\nabba\r\n", "output": "4\r\n"}, {"input": "8 1\r\naabaabaa\r\n", "output": "5\r\n"}, {"input": "1 0\r\na\r\n", "output": "1\r\n"}, {"input": "1 1\r\nb\r\n", "output": "1\r\n"}, {"input": "1 0\r\nb\r\n", "output": "1\r\n"}, {"input": "1 1\r\na\r\n", "output": "1\r\n"}, {"input": "10 10\r\nbbbbbbbbbb\r\...
false
stdio
null
true
416/D
416
D
Python 3
TESTS
78
451
16,588,800
6364119
n = int(input()) a = list(map(int, input().split())) i, j, k = 0, -1, -1 ans = 1 for l in range(len(a)): if a[l] == -1: continue if j == -1: j = l elif k == -1: if (a[l] - a[j]) % (l - j) == 0 and a[j] - (a[l] - a[j]) / (l - j) * (j - i) > 0: k = l else: i, j = l, l ans += 1 el...
84
171
27,648,000
302828817
import sys,math,heapq from collections import Counter #sys.setrecursionlimit(200000) #fin = open('input.txt', 'r') #input = lambda: fin.readline().strip() input=lambda: sys.stdin.readline().strip() import random RANDOM = random.getrandbits(20) class Wrapper(int): def __init__(self, x): int.__init__(x) ...
Codeforces Round 241 (Div. 2)
CF
2,014
1
256
Population Size
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if...
The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of elements in the sequence. The second line contains integer values a1, a2, ..., an separated by a space (1 ≤ ai ≤ 109 or ai = - 1).
Print the minimum number of arithmetic progressions that you need to write one after another to get sequence a. The positions marked as -1 in a can be represented by any positive integers.
null
null
[{"input": "9\n8 6 4 2 1 4 7 10 2", "output": "3"}, {"input": "9\n-1 6 -1 2 -1 4 7 -1 2", "output": "3"}, {"input": "5\n-1 -1 -1 -1 -1", "output": "1"}, {"input": "7\n-1 -1 4 5 1 2 3", "output": "2"}]
2,400
["greedy", "implementation", "math"]
84
[{"input": "9\r\n8 6 4 2 1 4 7 10 2\r\n", "output": "3\r\n"}, {"input": "9\r\n-1 6 -1 2 -1 4 7 -1 2\r\n", "output": "3\r\n"}, {"input": "5\r\n-1 -1 -1 -1 -1\r\n", "output": "1\r\n"}, {"input": "7\r\n-1 -1 4 5 1 2 3\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n65\r\n", "output": ...
false
stdio
null
true
600/C
600
C
Python 3
TESTS
6
62
204,800
111955339
counts = [0]*26 for c in input(): counts[ord(c)-97] += 1 # print(*counts) ans = "" i = 26 while i: i -= 1 if counts[i]&1: # Find min thing with odd count and increase that j = 0 while j < 26 and counts[j]&1 < 1: j += 1 if j < 26 and counts[j]&1: counts[i] -= 1 counts[j] += 1 break # print(ans) ...
66
62
2,150,400
215107109
def rl(): return list(map(int,input().split())) def ri(): return int(input()) def rs(): return input() def rm(): return map(int,input().split()) def main(): s=rs() cnt=[0]*26 for c in s: cnt[ord(c)-97]+=1 od=ev=0 for i in range(26): od+=cnt[i]%2==1 ev+=cnt[i]...
Educational Codeforces Round 2
ICPC
2,015
2
256
Make Palindrome
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not. You are given string s consisting of lowercase Latin letters. At once you can choose any position in th...
The only line contains string s (1 ≤ |s| ≤ 2·105) consisting of only lowercase Latin letters.
Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes.
null
null
[{"input": "aabc", "output": "abba"}, {"input": "aabcd", "output": "abcba"}]
1,800
["constructive algorithms", "greedy", "strings"]
66
[{"input": "aabc\r\n", "output": "abba\r\n"}, {"input": "aabcd\r\n", "output": "abcba\r\n"}, {"input": "u\r\n", "output": "u\r\n"}, {"input": "ttttt\r\n", "output": "ttttt\r\n"}, {"input": "xxxvvvxxvv\r\n", "output": "vvvxxxxvvv\r\n"}, {"input": "wrwrwfrrfrffrrwwwffffwrfrrwfrrfrwwfwfrwfwfwffwrrwfrrrwwwfrrrwfrrfwrwwrwrr...
false
stdio
null
true
837/D
837
D
PyPy 3
TESTS
24
514
5,120,000
131910761
import sys input = sys.stdin.readline n, k = map(int, input().split()) m = 18 * n a = list(map(int, input().split())) inf = 114514 dp = [[-inf] * (m + 1) for _ in range(n + 1)] dp[0][0] = 0 c = 0 for i in range(n): ai = a[i] x, y = 0, 0 while not ai % 2: x += 1 ai //= 2 while not ai % 5...
99
1,076
7,987,200
131912158
import sys input = sys.stdin.readline n, k = map(int, input().split()) m = 30 * n a = list(map(int, input().split())) inf = 114514 dp = [[-inf] * (m + 1) for _ in range(n + 1)] dp[0][0] = 0 dp0 = [0] * (n + 1) for i in range(n): ai = a[i] x, y = 0, 0 while not ai % 2: y += 1 ai //= 2 wh...
Educational Codeforces Round 26
ICPC
2,017
2
256
Round Subset
Let's call the roundness of the number the number of zeros to which it ends. You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n). The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Print maximal roundness of product of the chosen subset of length k.
null
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3. In the second example subset [15, 16, 25] has product 6000, roundness 3. In the third example all subsets has product with roundness 0.
[{"input": "3 2\n50 4 20", "output": "3"}, {"input": "5 3\n15 16 3 25 9", "output": "3"}, {"input": "3 3\n9 77 13", "output": "0"}]
2,100
["dp", "math"]
99
[{"input": "3 2\r\n50 4 20\r\n", "output": "3\r\n"}, {"input": "5 3\r\n15 16 3 25 9\r\n", "output": "3\r\n"}, {"input": "3 3\r\n9 77 13\r\n", "output": "0\r\n"}, {"input": "1 1\r\n200000000\r\n", "output": "8\r\n"}, {"input": "1 1\r\n3\r\n", "output": "0\r\n"}, {"input": "3 1\r\n1000000000000000000 800000000000000000 6...
false
stdio
null
true
799/D
799
D
PyPy 3-64
TESTS
26
265
20,684,800
204499804
from math import * a,b,w,h,n=map(int,input().split()) w,h=ceil(a/w),ceil(b/h) MAX=100000 MAX=min(MAX,max(w,h)) if w<=1 and h<=1: print(0) else: l=list(map(int,input().split())) l.sort() l.reverse() l=l[:34] dp=[0 for i in range(MAX+1)] #max width for height i dp[0]=MAX*MAX dp[1]=1 gg...
103
62
2,560,000
230893177
f = lambda: map(int, input().split()) a, b, h, w, n = f() c = sorted(list(f()), key=lambda x: -x) d = {(h, w), (w, h)} for i, q in enumerate([1] + c): for u, v in d.copy(): h, w = u, v * q if a <= w and b <= h or a <= h and b <= w: print(i) exit() d.add((h, w)) ...
Playrix Codescapes Cup (Codeforces Round 413, rated, Div. 1 + Div. 2)
CF
2,017
1
256
Field expansion
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Ar...
The first line contains five integers a, b, h, w and n (1 ≤ a, b, h, w, n ≤ 100 000) — the sizes of the rectangle needed to be placed, the initial sizes of the field and the number of available extensions. The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 100 000), where ai equals the integer a side multip...
Print the minimum number of extensions needed to reach Arkady's goal. If it is not possible to place the rectangle on the field with all extensions, print -1. If the rectangle can be placed on the initial field, print 0.
null
In the first example it is enough to use any of the extensions available. For example, we can enlarge h in 5 times using the second extension. Then h becomes equal 10 and it is now possible to place the rectangle on the field.
[{"input": "3 3 2 4 4\n2 5 4 10", "output": "1"}, {"input": "3 3 3 3 5\n2 3 5 4 2", "output": "0"}, {"input": "5 5 1 2 3\n2 2 3", "output": "-1"}, {"input": "3 4 1 1 3\n2 3 2", "output": "3"}]
2,100
["brute force", "dp", "meet-in-the-middle"]
103
[{"input": "3 3 2 4 4\r\n2 5 4 10\r\n", "output": "1\r\n"}, {"input": "3 3 3 3 5\r\n2 3 5 4 2\r\n", "output": "0\r\n"}, {"input": "5 5 1 2 3\r\n2 2 3\r\n", "output": "-1\r\n"}, {"input": "3 4 1 1 3\r\n2 3 2\r\n", "output": "3\r\n"}, {"input": "572 540 6 2 12\r\n2 3 2 2 2 3 3 3 2 2 2 2\r\n", "output": "-1\r\n"}, {"input...
false
stdio
null
true
638/B
638
B
Python 3
PRETESTS
9
62
4,608,000
16843287
n = int(input()) arr = [] arr2 = "" for i in range(n): arr.append(str(input())) result = arr[0] z = 0 while len(arr) != 0: for i in range(len(arr)): if result.find(arr[i-z]) != -1: del arr[i-z] z+=1 continue elif arr[i-z].find(result)!= -1: result ...
67
62
4,812,800
16855472
n=int(input()) s=set() for i in range(n): p=input() if i!=n-1: s.add(p) n-=1 w={} for i in s: w.update([(i,set(i))]) w.update([(p,set(p))]) y='' while n>0: u=0 for i in s: u+=1 if p[0] in w[i] and p[-1] in w[i]: p=i s.discard(i) break elif p[0] in w[i]: p=i[:i.find(p[0])]+p s.discard(i) b...
VK Cup 2016 - Qualification Round 2
CF
2,016
1
256
Making Genome in Berland
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En...
The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are d...
In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them.
null
null
[{"input": "3\nbcd\nab\ncdef", "output": "abcdef"}, {"input": "4\nx\ny\nz\nw", "output": "xyzw"}]
1,500
["*special", "dfs and similar", "strings"]
67
[{"input": "3\r\nbcd\r\nab\r\ncdef\r\n", "output": "abcdef\r\n"}, {"input": "4\r\nx\r\ny\r\nz\r\nw\r\n", "output": "xyzw\r\n"}, {"input": "25\r\nef\r\nfg\r\ngh\r\nhi\r\nij\r\njk\r\nkl\r\nlm\r\nmn\r\nno\r\nab\r\nbc\r\ncd\r\nde\r\nop\r\npq\r\nqr\r\nrs\r\nst\r\ntu\r\nuv\r\nvw\r\nwx\r\nxy\r\nyz\r\n", "output": "abcdefghijk...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n = int(f.readline().strip()) fragments = [line.strip() for line in f] with open(output_path) as f: correct_output = f.read().strip() ...
true
638/B
638
B
Python 3
PRETESTS
9
46
4,915,200
16839935
def lfs(new): for i in range(len(new)): flag = True for j in range(len(new)): if j != i: if new[i][0] in new[j]: flag = False if flag: return i def vlastsovetam(data): new = [] for i in range(len(data)): flag = True...
67
62
4,915,200
16839269
#!/usr/bin/env python3 n = eval(input()) substrings = [input() for line in range(n)] letters = {} for word in substrings: for letter in word: if not letter in letters: letters[letter] = [word[:(word.index(letter))],word[(word.index(letter)+1):]] else: if len(letters[letter]...
VK Cup 2016 - Qualification Round 2
CF
2,016
1
256
Making Genome in Berland
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En...
The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are d...
In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them.
null
null
[{"input": "3\nbcd\nab\ncdef", "output": "abcdef"}, {"input": "4\nx\ny\nz\nw", "output": "xyzw"}]
1,500
["*special", "dfs and similar", "strings"]
67
[{"input": "3\r\nbcd\r\nab\r\ncdef\r\n", "output": "abcdef\r\n"}, {"input": "4\r\nx\r\ny\r\nz\r\nw\r\n", "output": "xyzw\r\n"}, {"input": "25\r\nef\r\nfg\r\ngh\r\nhi\r\nij\r\njk\r\nkl\r\nlm\r\nmn\r\nno\r\nab\r\nbc\r\ncd\r\nde\r\nop\r\npq\r\nqr\r\nrs\r\nst\r\ntu\r\nuv\r\nvw\r\nwx\r\nxy\r\nyz\r\n", "output": "abcdefghijk...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n = int(f.readline().strip()) fragments = [line.strip() for line in f] with open(output_path) as f: correct_output = f.read().strip() ...
true
515/B
515
B
Python 3
TESTS
19
62
204,800
114852125
from collections import deque n, m=[int(k) for k in input().split()] w=[int(k) for k in input().split()][1:] q=[int(k) for k in input().split()][1:] x, y=len(w), len(q) qwe={} zxc={} for i in range(n*m+11): if i%n not in qwe: qwe[i%n]=[i%m] elif i%m not in qwe[i%n]: qwe[i%n].append(i%m) if ...
56
46
0
218402049
import sys sys.setrecursionlimit(100000000) input=lambda:sys.stdin.readline().strip() write=lambda x:sys.stdout.write(str(x)+'\n') # from random import randint # from copy import deepcopy # from collections import deque,Counter # from heapq import heapify,heappush,heappop # from bisect import bisect_left,bisect,insort...
Codeforces Round 292 (Div. 2)
CF
2,015
2
256
Drazil and His Happy Friends
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan. There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites $$(i \bmod n)$$-th...
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi < n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ ...
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
null
By $$i \bmod k$$ we define the remainder of integer division of i by k. In first sample case: - On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. - On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so no...
[{"input": "2 3\n0\n1 0", "output": "Yes"}, {"input": "2 4\n1 0\n1 2", "output": "No"}, {"input": "2 3\n1 0\n1 1", "output": "Yes"}]
1,300
["brute force", "dsu", "meet-in-the-middle", "number theory"]
56
[{"input": "2 3\r\n0\r\n1 0\r\n", "output": "Yes\r\n"}, {"input": "2 4\r\n1 0\r\n1 2\r\n", "output": "No\r\n"}, {"input": "2 3\r\n1 0\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "16 88\r\n6 5 14 2 0 12 7\r\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82\r\n", "output": "Yes\r...
false
stdio
null
true
725/A
725
A
Python 3
TESTS
8
46
614,400
30551023
n=int(input()) s=input() k=s.count('><') if k==0: pass elif k==1: k=s.find('><') for i in range(k+1,n): if s[i]=='<': n-=1 else: break for i in range(k,-1,-1): if s[i]=='>': n-=1 else: break else: k=s.rfind('><') for...
78
46
102,400
146871880
def solve(): n = int(input()) s = input() ans = 0 for i in s: if i == "<": ans += 1 else: break for i in s[::-1]: if i == ">": ans += 1 else: break print(ans) solve()
Canada Cup 2016
CF
2,016
2
256
Jumping Ball
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper.
Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.
null
In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
[{"input": "4\n<<><", "output": "2"}, {"input": "5\n>>>>>", "output": "5"}, {"input": "4\n>><<", "output": "0"}]
1,000
["implementation"]
78
[{"input": "4\r\n<<><\r\n", "output": "2\r\n"}, {"input": "5\r\n>>>>>\r\n", "output": "5\r\n"}, {"input": "4\r\n>><<\r\n", "output": "0\r\n"}, {"input": "3\r\n<<>\r\n", "output": "3\r\n"}, {"input": "3\r\n<<<\r\n", "output": "3\r\n"}, {"input": "3\r\n><<\r\n", "output": "0\r\n"}, {"input": "1\r\n<\r\n", "output": "1\r\...
false
stdio
null
true
45/I
45
I
PyPy 3-64
TESTS
13
124
0
167949969
import sys input = sys.stdin.readline n = int(input()) w = sorted(map(int, input().split())) d = [i for i in w if i < 0] e = [i for i in w if i > 0] if len(d) == len(e) == 0: print(0) exit(0) if len(e) == 0 and len(d) == 1: print(d[0]) exit(0) if len(d) % 2: d.sort() d = d[:-1] e.extend(d) pr...
65
154
6,963,200
125022759
n = int(input()) a = list(map(int, input().split())) pos = [] neg = [] z = 0 for i in range(n): if a[i] > 0: pos.append(a[i]) elif a[i] < 0: neg.append(a[i]) else: z += 1 m = len(neg) neg.sort() if m % 2: m -= 1 for i in range(m): pos.append(neg[i]) if len(pos) > 0: ...
School Team Contest 3 (Winter Computer School 2010/11)
ICPC
2,010
2
256
TCMCF+++
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of poin...
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
null
null
[{"input": "5\n1 2 -3 3 3", "output": "3 1 2 3"}, {"input": "13\n100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100"}, {"input": "4\n-2 -2 -2 -2", "output": "-2 -2 -2 -2"}]
1,400
["greedy"]
65
[{"input": "5\r\n1 2 -3 3 3\r\n", "output": "3 1 2 3 \r\n"}, {"input": "13\r\n100 100 100 100 100 100 100 100 100 100 100 100 100\r\n", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100 \r\n"}, {"input": "4\r\n-2 -2 -2 -2\r\n", "output": "-2 -2 -2 -2 \r\n"}, {"input": "1\r\n1\r\n", "output": "1 \r\n"}, {"i...
false
stdio
import sys from collections import Counter def compute_max_product(ci): if all(x == 0 for x in ci): return 0 positives = [x for x in ci if x > 0] negatives = [x for x in ci if x < 0] zeros = [x for x in ci if x == 0] non_zero = positives + negatives if not non_zero: return 0 ...
true
550/A
550
A
PyPy 3-64
TESTS
51
62
0
198567618
def solve(): s = input() abi0 = s.find('AB', 0) abi1 = s.find('AB', abi0+1) if abi0 != -1 else -1 abi2 = s.find('AB', abi1+1) if abi1 != -1 else -1 bai0 = s.find('BA') if bai0 == -1: return False if abi0 != -1 and abi0 != bai0-1 and abi0 != bai0+1: return True ...
85
46
0
195984665
s = input().strip() if 'AB' in s and 'BA' in s[s.index('AB')+2:]: print('YES') elif 'BA' in s and 'AB' in s[s.index('BA')+2:]: print('YES') else: print('NO')
Codeforces Round 306 (Div. 2)
CF
2,015
2
256
Two Substrings
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.
null
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".
[{"input": "ABA", "output": "NO"}, {"input": "BACFAB", "output": "YES"}, {"input": "AXBYBXA", "output": "NO"}]
1,500
["brute force", "dp", "greedy", "implementation", "strings"]
85
[{"input": "ABA\r\n", "output": "NO\r\n"}, {"input": "BACFAB\r\n", "output": "YES\r\n"}, {"input": "AXBYBXA\r\n", "output": "NO\r\n"}, {"input": "ABABAB\r\n", "output": "YES\r\n"}, {"input": "BBBBBBBBBB\r\n", "output": "NO\r\n"}, {"input": "ABBA\r\n", "output": "YES\r\n"}, {"input": "ABAXXXAB\r\n", "output": "YES\r\n"}...
false
stdio
null
true
45/I
45
I
Python 3
TESTS
9
218
307,200
75714701
def TCMCF(): num = int(input()) costs = [int(i) for i in input().split()] if num == 1: print(costs[0]) elif num == 2: print(max(costs[0]*costs[1],costs[0],costs[1])) else: negative_numbers = [] for i in costs: if i < 0: negative_numbers.append(i) if costs.count(0) == len(cost...
65
218
307,200
93067158
from bisect import bisect_left as bl;n=int(input()) if n==1: print(input()) else: a=list(map(int,input().split()));a.sort() if bl(a,0)%2==1: if a[bl(a,0)-1]<0:a.remove(a[bl(a,0)-1]) q=len(a) while 0 in a and q>1:a.remove(0);q-=1 print(*a)
School Team Contest 3 (Winter Computer School 2010/11)
ICPC
2,010
2
256
TCMCF+++
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of poin...
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
null
null
[{"input": "5\n1 2 -3 3 3", "output": "3 1 2 3"}, {"input": "13\n100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100"}, {"input": "4\n-2 -2 -2 -2", "output": "-2 -2 -2 -2"}]
1,400
["greedy"]
65
[{"input": "5\r\n1 2 -3 3 3\r\n", "output": "3 1 2 3 \r\n"}, {"input": "13\r\n100 100 100 100 100 100 100 100 100 100 100 100 100\r\n", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100 \r\n"}, {"input": "4\r\n-2 -2 -2 -2\r\n", "output": "-2 -2 -2 -2 \r\n"}, {"input": "1\r\n1\r\n", "output": "1 \r\n"}, {"i...
false
stdio
import sys from collections import Counter def compute_max_product(ci): if all(x == 0 for x in ci): return 0 positives = [x for x in ci if x > 0] negatives = [x for x in ci if x < 0] zeros = [x for x in ci if x == 0] non_zero = positives + negatives if not non_zero: return 0 ...
true
550/A
550
A
Python 3
TESTS
50
77
1,843,200
225913270
s = str(input()) a = 0 b = 0 i = 0 ans = [] while i < (len(s)-1) : if s[i] == "A" and s[i+1] == "B" : a += 1 ans.append(i) i += 1 elif s[i] == "B" and s[i+1] == "A" : b += 1 ans.append(i) i += 2 else: i += 1 if a>=2 and b>=2 : print("YES") elif a<...
85
46
0
196334991
s=input();u=s.find('AB');v=s.find('BA') print('YES'if(u+1and s.find('BA',u+2)+1)or(v+1and s.find('AB',v+2)+1)else'NO')
Codeforces Round 306 (Div. 2)
CF
2,015
2
256
Two Substrings
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.
null
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".
[{"input": "ABA", "output": "NO"}, {"input": "BACFAB", "output": "YES"}, {"input": "AXBYBXA", "output": "NO"}]
1,500
["brute force", "dp", "greedy", "implementation", "strings"]
85
[{"input": "ABA\r\n", "output": "NO\r\n"}, {"input": "BACFAB\r\n", "output": "YES\r\n"}, {"input": "AXBYBXA\r\n", "output": "NO\r\n"}, {"input": "ABABAB\r\n", "output": "YES\r\n"}, {"input": "BBBBBBBBBB\r\n", "output": "NO\r\n"}, {"input": "ABBA\r\n", "output": "YES\r\n"}, {"input": "ABAXXXAB\r\n", "output": "YES\r\n"}...
false
stdio
null
true
550/A
550
A
PyPy 3-64
TESTS
51
77
6,553,600
220380432
a = list(input()) k = False k1 = False i = 0 while i < len(a): if a[i:i+2] == ['B', 'A']: k = True a[i] = '/' a[i+1] = '/' break i += 1 i = 0 while i < len(a): if a[i:i+2] == ['A', 'B']: k1 = True a[i] = '/' a[i+1] = '/' break i += 1 if k...
85
46
0
197319059
z=input() u=z.find('AB') v=z.find('BA') print('YES'if(u+1and z.find('BA',u+2)+1)or(v+1and z.find('AB',v+2)+1)else'NO')
Codeforces Round 306 (Div. 2)
CF
2,015
2
256
Two Substrings
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.
null
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".
[{"input": "ABA", "output": "NO"}, {"input": "BACFAB", "output": "YES"}, {"input": "AXBYBXA", "output": "NO"}]
1,500
["brute force", "dp", "greedy", "implementation", "strings"]
85
[{"input": "ABA\r\n", "output": "NO\r\n"}, {"input": "BACFAB\r\n", "output": "YES\r\n"}, {"input": "AXBYBXA\r\n", "output": "NO\r\n"}, {"input": "ABABAB\r\n", "output": "YES\r\n"}, {"input": "BBBBBBBBBB\r\n", "output": "NO\r\n"}, {"input": "ABBA\r\n", "output": "YES\r\n"}, {"input": "ABAXXXAB\r\n", "output": "YES\r\n"}...
false
stdio
null
true
581/C
581
C
Python 3
TESTS
7
46
0
201076889
n,k=map(int,input().split()) ; arr=list(map(int,input().split())) ; ans=min(n*100 , sum(arr)+k ) ; print(ans//10)
98
109
5,120,000
13267634
n, k = map(int, input().split(' ')[:2]) a = list(map(int, input().split(' ')[:n])) b = [0 for i in range(101)] rating = 0 for i in a: b[i]+=1 rating += i // 10 for last_dig in range(9, 0, -1): for first_dig in range(10): v = first_dig * 10 + last_dig need_for_one = 10 - last_dig c...
Codeforces Round 322 (Div. 2)
CF
2,015
1
256
Developing Skills
Petya loves computer games. Finally a game that he's been waiting for so long came out! The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is...
The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-...
The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units.
null
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} r...
[{"input": "2 4\n7 9", "output": "2"}, {"input": "3 8\n17 15 19", "output": "5"}, {"input": "2 2\n99 100", "output": "20"}]
1,400
["implementation", "math", "sortings"]
98
[{"input": "2 4\r\n7 9\r\n", "output": "2\r\n"}, {"input": "3 8\r\n17 15 19\r\n", "output": "5\r\n"}, {"input": "2 2\r\n99 100\r\n", "output": "20\r\n"}, {"input": "100 10000\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
false
stdio
null
true
413/C
413
C
Python 3
TESTS
32
124
0
48322600
n, m = input().split() znac=input().split() nay=input().split() ayc=[] summ=0 obi = [] for i in range(int(n)): if str(i+1) in nay: ayc.append(znac[i]) else: obi.append(znac[i]) nayk=reversed(sorted(ayc)) for i in obi: summ+=int(i) for i in nayk: if summ<int(i): summ+=int(i) e...
67
46
0
205670441
n, m = map(int, input().split()) a = list(map(int, input().split())) b = [a[i - 1] for i in map(int, input().split())] b.sort(reverse = True) s = sum(a) - sum(b) for i in b: s += s if i < s else i print(s)
Coder-Strike 2014 - Round 2
CF
2,014
1
256
Jeopardy!
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2. The finals will have n questions, m of them are auction questi...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100; m ≤ min(n, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the prices of the questions. The third line contains m ...
In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type.
null
null
[{"input": "4 1\n1 3 7 5\n3", "output": "18"}, {"input": "3 2\n10 3 8\n2 3", "output": "40"}, {"input": "2 2\n100 200\n1 2", "output": "400"}]
1,400
["greedy", "math"]
67
[{"input": "4 1\r\n1 3 7 5\r\n3\r\n", "output": "18\r\n"}, {"input": "3 2\r\n10 3 8\r\n2 3\r\n", "output": "40\r\n"}, {"input": "2 2\r\n100 200\r\n1 2\r\n", "output": "400\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "2 2\r\n1 5\r\n1 2\r\n", "output": "10\r\n"}, {"input": "5 3\r\n5 8 7 1 9\r\n2 5...
false
stdio
null
true
638/B
638
B
Python 3
PRETESTS
9
62
5,120,000
16843600
from sys import exit n = int(input()) a = [] for i in range(n): s = input() for j in range(len(a)): check = a[j] if s in check: break if check in s: a[j] = s break else: a.append(s) br_flag = False while True: for j in range(len(a)): ...
67
62
4,915,200
16840651
parts = [] empty = True def chrx(x): return chr(x+97) def ordx(x): return ord(x)-97 include = [ [False for _2 in range(26)] for _1 in range(100)] exist = [False]*100 #""" n = int(input()) for _ in range(n): parts.append(input()) exist[_] = True for c in parts[-1]: include[_][ordx(c)] = ...
VK Cup 2016 - Qualification Round 2
CF
2,016
1
256
Making Genome in Berland
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En...
The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are d...
In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them.
null
null
[{"input": "3\nbcd\nab\ncdef", "output": "abcdef"}, {"input": "4\nx\ny\nz\nw", "output": "xyzw"}]
1,500
["*special", "dfs and similar", "strings"]
67
[{"input": "3\r\nbcd\r\nab\r\ncdef\r\n", "output": "abcdef\r\n"}, {"input": "4\r\nx\r\ny\r\nz\r\nw\r\n", "output": "xyzw\r\n"}, {"input": "25\r\nef\r\nfg\r\ngh\r\nhi\r\nij\r\njk\r\nkl\r\nlm\r\nmn\r\nno\r\nab\r\nbc\r\ncd\r\nde\r\nop\r\npq\r\nqr\r\nrs\r\nst\r\ntu\r\nuv\r\nvw\r\nwx\r\nxy\r\nyz\r\n", "output": "abcdefghijk...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n = int(f.readline().strip()) fragments = [line.strip() for line in f] with open(output_path) as f: correct_output = f.read().strip() ...
true
733/C
733
C
PyPy 3
TESTS
9
140
0
77664040
'''R = lambda: map(int, input().split()) n = int(input()) a = list(R()) m = int(input()) b = list(R()) st = i = j = 0 res = '' while i < m: psum = 0 while j < n and psum < b[i]: psum += a[j] j += 1 if psum != b[i]: print('NO') exit(0) print(j,st,a[st],a[j-1]) mi = st ...
139
46
0
219702093
R = lambda: map(int, input().split()) n = int(input()) a = list(R()) m = int(input()) b = list(R()) st = i = j = 0 res = '' while i < m: psum = 0 while j < n and psum < b[i]: psum += a[j] j += 1 if psum != b[i]: print('NO') exit(0) mi = st if a[st] > a[j - 1] else j - 1 ...
Codeforces Round 378 (Div. 2)
CF
2,016
1
256
Epidemic in Monstropolis
There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city. Soon, monsters became hungry and began to eat each other. One monster can eat other monster if its weight is strictly greater than the weight of the monster...
The first line contains single integer n (1 ≤ n ≤ 500) — the number of monsters in the initial queue. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial weights of the monsters. The third line contains single integer k (1 ≤ k ≤ n) — the number of monsters in the queue after the joke. Th...
In case if no actions could lead to the final queue, print "NO" (without quotes) in the only line. Otherwise print "YES" (without quotes) in the first line. In the next n - k lines print actions in the chronological order. In each line print x — the index number of the monster in the current queue which eats and, sepa...
null
In the first example, initially there were n = 6 monsters, their weights are [1, 2, 2, 2, 1, 2] (in order of queue from the first monster to the last monster). The final queue should be [5, 5]. The following sequence of eatings leads to the final queue: - the second monster eats the monster to the left (i.e. the first...
[{"input": "6\n1 2 2 2 1 2\n2\n5 5", "output": "YES\n2 L\n1 R\n4 L\n3 L"}, {"input": "5\n1 2 3 4 5\n1\n15", "output": "YES\n5 L\n4 L\n3 L\n2 L"}, {"input": "5\n1 1 1 3 3\n3\n2 1 6", "output": "NO"}]
1,800
["constructive algorithms", "dp", "greedy", "two pointers"]
139
[{"input": "6\r\n1 2 2 2 1 2\r\n2\r\n5 5\r\n", "output": "YES\r\n2 L\r\n1 R\r\n4 L\r\n3 L\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1\r\n15\r\n", "output": "YES\r\n5 L\r\n4 L\r\n3 L\r\n2 L\r\n"}, {"input": "5\r\n1 1 1 3 3\r\n3\r\n2 1 6\r\n", "output": "NO"}, {"input": "5\r\n1 1 1 1 2\r\n3\r\n1 1 4\r\n", "output": "YES\r\n5 L...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: return f.read().splitlines() input_path, output_path, submission_path = sys.argv[1], sys.argv[2], sys.argv[3] input_lines = read_file(input_path) n = int(input_lines[0]) a = list(map(int, input_lines[1].split())) k = int(input_lines[2]) b = list(...
true
982/A
982
A
Python 3
TESTS
27
124
0
40407719
n = int(input()) flag = True a = input() for i in range(1,n-1): if a[i] == '1': if a[i-1] == '1' or a[i+1] == '1': print("No") flag = False break if a[i] == '0': if a[i - 1] == '0' and a[i + 1] == '0': print("No") flag = False ...
55
46
0
192764494
# LUOGU_RID: 101739723 n = int(input()) s = input() print((s.find('11') != -1 or any(s[i] == '0' and (i == 0 or s[i - 1] == '0') and (i == n - 1 or s[i + 1] == '0') for i in range(n))) and 'No' or 'Yes')
Codeforces Round 484 (Div. 2)
CF
2,018
1
256
Row
You're given a row with $$$n$$$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 2. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($$$0$$$ m...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of chairs. The next line contains a string of $$$n$$$ characters, each of them is either zero or one, describing the seating.
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
null
In sample case one the given seating is maximal. In sample case two the person at chair three has a neighbour to the right. In sample case three it is possible to seat yet another person into chair three.
[{"input": "3\n101", "output": "Yes"}, {"input": "4\n1011", "output": "No"}, {"input": "5\n10001", "output": "No"}]
1,200
["brute force", "constructive algorithms"]
55
[{"input": "3\r\n101\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1011\r\n", "output": "No\r\n"}, {"input": "5\r\n10001\r\n", "output": "No\r\n"}, {"input": "1\r\n0\r\n", "output": "No\r\n"}, {"input": "1\r\n1\r\n", "output": "Yes\r\n"}, {"input": "100\r\n01010010101010010100100101010010101001010010010010100101010100101...
false
stdio
null
true
762/C
762
C
Python 3
TESTS
17
92
1,331,200
109096293
import sys input = sys.stdin.readline def solve(): a = input().strip() b = input().strip() n = len(a) m = len(b) c = [0]*m d = [0]*m p = 0 for i in range(m): for j in range(p, n): if a[j] == b[i]: c[i] = j p = j + 1 break else: for j in range(i,m): c[j] = n break p = n-1 for i...
99
109
6,963,200
168750210
def solve(s1,s2): n=len(s1) m=len(s2) s1=' ' +s1 + ' ' s2=' ' +s2 + ' ' tmp=0 v1=[0]*100005 v2=[0]*100005 for i in range(1,n+1): if s1[i]==s2[tmp+1]: tmp+=1 v1[i]=tmp tmp=m+1 v2[n+1]=tmp for i in range(n,0,-1): if s1[i]==s2[tmp-1]: ...
Educational Codeforces Round 17
ICPC
2,017
2
256
Two strings
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of th...
The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 105 characters.
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters. If the answer consists of zero characters, output «-» (a minus sign).
null
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty. In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
[{"input": "hi\nbob", "output": "-"}, {"input": "abca\naccepted", "output": "ac"}, {"input": "abacaba\nabcdcba", "output": "abcba"}]
2,100
["binary search", "hashing", "strings", "two pointers"]
99
[{"input": "hi\r\nbob\r\n", "output": "-\r\n"}, {"input": "abca\r\naccepted\r\n", "output": "ac\r\n"}, {"input": "abacaba\r\nabcdcba\r\n", "output": "abcba\r\n"}, {"input": "lo\r\neuhaqdhhzlnkmqnakgwzuhurqlpmdm\r\n", "output": "-\r\n"}, {"input": "aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\r\nmlmarpivirqbxcyhyer...
false
stdio
null
true
982/A
982
A
PyPy 3
TESTS
9
140
0
90464444
lenght=input() lenght=int(lenght) word=input() if lenght == 1: if "0" in word: print("No") else: print("Yes") exit() last_chars = word[lenght-2:] if "00" in last_chars: print("No") exit() if "000" in word: print("No") exit() if "11" in word: print("No") ...
55
46
0
192774037
n = int(input()) s = input() if len(s)==1: print('No') if s=='0' else print('Yes') elif len(s)==2: print('No') if s=='00' or s=='11' else print('Yes') else: if s.count('11')>0: print('No') else: for i in range(n): if s[i]=='0': s = list(s) s[...
Codeforces Round 484 (Div. 2)
CF
2,018
1
256
Row
You're given a row with $$$n$$$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 2. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($$$0$$$ m...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of chairs. The next line contains a string of $$$n$$$ characters, each of them is either zero or one, describing the seating.
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
null
In sample case one the given seating is maximal. In sample case two the person at chair three has a neighbour to the right. In sample case three it is possible to seat yet another person into chair three.
[{"input": "3\n101", "output": "Yes"}, {"input": "4\n1011", "output": "No"}, {"input": "5\n10001", "output": "No"}]
1,200
["brute force", "constructive algorithms"]
55
[{"input": "3\r\n101\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1011\r\n", "output": "No\r\n"}, {"input": "5\r\n10001\r\n", "output": "No\r\n"}, {"input": "1\r\n0\r\n", "output": "No\r\n"}, {"input": "1\r\n1\r\n", "output": "Yes\r\n"}, {"input": "100\r\n01010010101010010100100101010010101001010010010010100101010100101...
false
stdio
null
true
985/B
985
B
PyPy 3-64
TESTS
26
311
93,593,600
224853496
class Switch: def __init__(self, s): self.data = set() for i, ch in enumerate(s): if ch == '1': self.data.add(i) def __len__(self): return len(self.data) def __ior__(self, other): self.data |= other.data return self def main(): n, m...
67
109
921,600
38563718
def main(): n, m = map(int, input().split()) switches = [int(input(), 2) for _ in range(n)] lambs_on = 0 duplicate_control = 0 for lambs_turn_on in switches: duplicate_control |= lambs_on & lambs_turn_on lambs_on |= lambs_turn_on if any(lambs_turn_on & lambs_on & ~duplicate_con...
Educational Codeforces Round 44 (Rated for Div. 2)
ICPC
2,018
3
256
Switches and Lamps
You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are t...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all...
Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch.
null
null
[{"input": "4 5\n10101\n01000\n00111\n10000", "output": "YES"}, {"input": "4 5\n10100\n01000\n00110\n00101", "output": "NO"}]
1,200
["implementation"]
67
[{"input": "4 5\r\n10101\r\n01000\r\n00111\r\n10000\r\n", "output": "YES\r\n"}, {"input": "4 5\r\n10100\r\n01000\r\n00110\r\n00101\r\n", "output": "NO\r\n"}, {"input": "1 5\r\n11111\r\n", "output": "NO\r\n"}, {"input": "10 1\r\n1\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 1\r\...
false
stdio
null
true
985/B
985
B
Python 3
TESTS
26
140
819,200
39063467
n=list(map(int,input().split())) l,r=n[0],n[1] arr=[] gf=0 for x in range(l): arr.append(int(input(),2)) for x in range(r): gf=gf+pow(2,x) mx=max(arr) k=0 for x in range(0,l): if(bin(mx)!=bin(mx|arr[x])): mx=(mx|arr[x]) k=k+1 k=k+1 print('YES') if(k<l and mx==gf ) else print('NO')
67
109
5,222,400
38520749
input() a = tuple(map(lambda s: int(s.strip(), 2), __import__('sys').stdin.readlines())) t = T = 0 for x in a: t |= T & x T |= x print(['YES', 'NO'][all(x & (x ^ t) for x in a)])
Educational Codeforces Round 44 (Rated for Div. 2)
ICPC
2,018
3
256
Switches and Lamps
You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are t...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all...
Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch.
null
null
[{"input": "4 5\n10101\n01000\n00111\n10000", "output": "YES"}, {"input": "4 5\n10100\n01000\n00110\n00101", "output": "NO"}]
1,200
["implementation"]
67
[{"input": "4 5\r\n10101\r\n01000\r\n00111\r\n10000\r\n", "output": "YES\r\n"}, {"input": "4 5\r\n10100\r\n01000\r\n00110\r\n00101\r\n", "output": "NO\r\n"}, {"input": "1 5\r\n11111\r\n", "output": "NO\r\n"}, {"input": "10 1\r\n1\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 1\r\...
false
stdio
null
true
985/B
985
B
Python 3
TESTS
26
2,605
74,956,800
38547910
a=[int(i) for i in input().split()] n=a[0] m=a[1] a=[] for i in range(n): s=str(input()) y=[] for j in range(m): if(s[j]=='1'): y.append(j) a.append(y) a.sort(key=len,reverse=True) b=[False]*(m) i=0 count=0 while(i<=n-1): flag=0 for j in range(len(a[i])): if(b[a[i][j]]==False): b[a[i][j]]=True flag=1...
67
124
716,800
38491775
a = [] was_already = was_twice = 0 n = int(input().split()[0]) for _ in range(n): ai = int(input(), base=2) a.append(ai) was_twice |= was_already & ai was_already |= ai for ai in a: if ai & (ai ^ was_twice): continue print("YES") break else: print("NO")
Educational Codeforces Round 44 (Rated for Div. 2)
ICPC
2,018
3
256
Switches and Lamps
You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are t...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all...
Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch.
null
null
[{"input": "4 5\n10101\n01000\n00111\n10000", "output": "YES"}, {"input": "4 5\n10100\n01000\n00110\n00101", "output": "NO"}]
1,200
["implementation"]
67
[{"input": "4 5\r\n10101\r\n01000\r\n00111\r\n10000\r\n", "output": "YES\r\n"}, {"input": "4 5\r\n10100\r\n01000\r\n00110\r\n00101\r\n", "output": "NO\r\n"}, {"input": "1 5\r\n11111\r\n", "output": "NO\r\n"}, {"input": "10 1\r\n1\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 1\r\...
false
stdio
null
true
812/B
812
B
Python 3
TESTS
42
124
307,200
76990537
n,m=list(map(int,input().split())) Li=[] for i in range(n): Li.append(input()) on=[] L=[] R=[] for s in Li[::-1]: c=0 count=1 p=-1 for i in s: if c==0 and i=='1': c=1 L.append(count) on.append(1) if i=='1': p=count count+=1 ...
72
46
0
186754062
n, m = map(int, input().split()) p = [input() for y in range(n)][::-1] l = r = d = 0 i = j = 0 for y, t in enumerate(p): if '1' in t: l, r = min(l - i, r - j) + 2 * m + 2, min(l + i, r + j) i, j = t.find('1'), t.rfind('1') l, r, d = l - i, r + j, y print(min(l, r) + d)
Codeforces Round 417 (Div. 2)
CF
2,017
1
256
Sagheer, the Hausmeister
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of n floors with stairs at the left and the right sides...
The first line contains two integers n and m (1 ≤ n ≤ 15 and 1 ≤ m ≤ 100) — the number of floors and the number of rooms in each floor, respectively. The next n lines contains the building description. Each line contains a binary string of length m + 2 representing a floor (the left stairs, then m rooms, then the righ...
Print a single integer — the minimum total time needed to turn off all the lights.
null
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to th...
[{"input": "2 2\n0010\n0100", "output": "5"}, {"input": "3 4\n001000\n000010\n000010", "output": "12"}, {"input": "4 3\n01110\n01110\n01110\n01110", "output": "18"}]
1,600
["bitmasks", "brute force", "dp"]
72
[{"input": "2 2\r\n0010\r\n0100\r\n", "output": "5\r\n"}, {"input": "3 4\r\n001000\r\n000010\r\n000010\r\n", "output": "12\r\n"}, {"input": "4 3\r\n01110\r\n01110\r\n01110\r\n01110\r\n", "output": "18\r\n"}, {"input": "3 2\r\n0000\r\n0100\r\n0100\r\n", "output": "4\r\n"}, {"input": "1 89\r\n0000000000000000000000000000...
false
stdio
null
true
812/B
812
B
PyPy 3
TESTS
42
202
23,347,200
28807908
n, m = list(map(int, input().split())) house = [] def look_right(position, house): x, y = position l = len(house[y]) count = l - x ps = 0 while ps == 0: pos = [l-1, y - 1] for i in range(l-1, -1, -1): if house[y-1][i] == 1: pos[0] = i ps ...
72
46
0
230134682
n_and_m = input() n, m = n_and_m.split() #n - кол-во целых чисел, k - кол-во элем. заданной посл-ти меньше либо равны x(результат программы) n = int(n) m = int(m) p = [input() for y in range(n)][::-1] l = r = d = 0 i = j = 0 for y, t in enumerate(p): if '1' in t: l, r = min(l - i, r - j) + 2 * m + 2, min(...
Codeforces Round 417 (Div. 2)
CF
2,017
1
256
Sagheer, the Hausmeister
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of n floors with stairs at the left and the right sides...
The first line contains two integers n and m (1 ≤ n ≤ 15 and 1 ≤ m ≤ 100) — the number of floors and the number of rooms in each floor, respectively. The next n lines contains the building description. Each line contains a binary string of length m + 2 representing a floor (the left stairs, then m rooms, then the righ...
Print a single integer — the minimum total time needed to turn off all the lights.
null
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to th...
[{"input": "2 2\n0010\n0100", "output": "5"}, {"input": "3 4\n001000\n000010\n000010", "output": "12"}, {"input": "4 3\n01110\n01110\n01110\n01110", "output": "18"}]
1,600
["bitmasks", "brute force", "dp"]
72
[{"input": "2 2\r\n0010\r\n0100\r\n", "output": "5\r\n"}, {"input": "3 4\r\n001000\r\n000010\r\n000010\r\n", "output": "12\r\n"}, {"input": "4 3\r\n01110\r\n01110\r\n01110\r\n01110\r\n", "output": "18\r\n"}, {"input": "3 2\r\n0000\r\n0100\r\n0100\r\n", "output": "4\r\n"}, {"input": "1 89\r\n0000000000000000000000000000...
false
stdio
null
true
628/D
628
D
PyPy 3
TESTS
20
1,855
38,707,200
114079273
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO,IOBase def solve(x,m,d,mod,par): dp = [[[0]*m for _ in range(2)] for _ in range(len(x))] # remainder of number formed till now ; smaller/equal ; place value zz = int(x[0]) for _ in range(1,zz): if...
66
217
3,379,200
189367480
from sys import stdin mod = 10**9 + 7 _all = map(str, stdin.read().split()) m, d, a, b = int(next(_all)), int(next(_all)), next(_all), next(_all) n = len(a) din, din1 = [0]*m, [0]*m eqa, eqb, eqab = 1, 1, 1 xa, xb = 0, 0 for i in range(n): eqa1, eqb1, eqab1 = 0, 0, 0 din1 = [0]*m for dig in range(10): if i % 2 =...
Educational Codeforces Round 8
ICPC
2,016
2
256
Magic Numbers
Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else. For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic...
The first line contains two integers m, d (1 ≤ m ≤ 2000, 0 ≤ d ≤ 9) — the parameters from the problem statement. The second line contains positive integer a in decimal presentation (without leading zeroes). The third line contains positive integer b in decimal presentation (without leading zeroes). It is guaranteed ...
Print the only integer a — the remainder after dividing by 109 + 7 of the number of d-magic numbers in segment [a, b] that are multiple of m.
null
The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96. The numbers from the answer of the second example are 2, 4, 6 and 8. The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747.
[{"input": "2 6\n10\n99", "output": "8"}, {"input": "2 0\n1\n9", "output": "4"}, {"input": "19 7\n1000\n9999", "output": "6"}]
2,200
["dp"]
66
[{"input": "2 6\r\n10\r\n99\r\n", "output": "8\r\n"}, {"input": "2 0\r\n1\r\n9\r\n", "output": "4\r\n"}, {"input": "19 7\r\n1000\r\n9999\r\n", "output": "6\r\n"}, {"input": "9 4\r\n33\r\n52\r\n", "output": "0\r\n"}, {"input": "10 8\r\n18\r\n59\r\n", "output": "0\r\n"}, {"input": "43 3\r\n587\r\n850\r\n", "output": "1\r...
false
stdio
null
true
812/B
812
B
Python 3
TESTS
42
264
307,200
27527822
# 1000 n_m = [int(x) for x in input().split()] n_m[1] += 1 floors = [] rooms = [] position = [0, 0] def path_cost(): s = [] MIN=0 index = 0 y = rooms[0][1] for i in range(len(rooms)): if rooms[i][1]>y: continue if position[1]-rooms[i][1]==0 : s.append(abs(r...
72
62
0
194156841
import sys input = sys.stdin.readline n, m = map(int, input().split()) a = 0 b = m+1 c = [0, 0] g = [input()[:-1] for _ in range(n)] for i in range(n-1, 0, -1): if '1' in g[i]: c = [g[i].rindex('1') if a + g[i].rindex('1')*2 < b+m+1 else g[i].index('1'), m+1-g[i].index('1') if b + (m+1-g[i].index('1'))*2 <...
Codeforces Round 417 (Div. 2)
CF
2,017
1
256
Sagheer, the Hausmeister
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of n floors with stairs at the left and the right sides...
The first line contains two integers n and m (1 ≤ n ≤ 15 and 1 ≤ m ≤ 100) — the number of floors and the number of rooms in each floor, respectively. The next n lines contains the building description. Each line contains a binary string of length m + 2 representing a floor (the left stairs, then m rooms, then the righ...
Print a single integer — the minimum total time needed to turn off all the lights.
null
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to th...
[{"input": "2 2\n0010\n0100", "output": "5"}, {"input": "3 4\n001000\n000010\n000010", "output": "12"}, {"input": "4 3\n01110\n01110\n01110\n01110", "output": "18"}]
1,600
["bitmasks", "brute force", "dp"]
72
[{"input": "2 2\r\n0010\r\n0100\r\n", "output": "5\r\n"}, {"input": "3 4\r\n001000\r\n000010\r\n000010\r\n", "output": "12\r\n"}, {"input": "4 3\r\n01110\r\n01110\r\n01110\r\n01110\r\n", "output": "18\r\n"}, {"input": "3 2\r\n0000\r\n0100\r\n0100\r\n", "output": "4\r\n"}, {"input": "1 89\r\n0000000000000000000000000000...
false
stdio
null
true
812/B
812
B
Python 3
TESTS
42
46
0
231542755
n_and_m = input() n, m = n_and_m.split() #n - кол-во целых чисел, k - кол-во элем. заданной посл-ти меньше либо равны x(результат программы) n = int(n) m = int(m) p = [input() for y in range(n)][::-1] l = r = d = 0 i = j = 0 pos = 0 put = 0 for y, t in enumerate(p): if '1' in t: d = y i = t.find(...
72
62
307,200
27491979
n, m = map(int, input().split()) a = [] for i in range(n): a.append(input()) # print(a) l = 0 r = INF = 100000 h = 0 while h < n: if a[h] == '0' * (m + 2): h += 1 else: break if h != n: for i in range(n - 1, h, -1): x = INF y = 0 for j in range(m + 2): ...
Codeforces Round 417 (Div. 2)
CF
2,017
1
256
Sagheer, the Hausmeister
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of n floors with stairs at the left and the right sides...
The first line contains two integers n and m (1 ≤ n ≤ 15 and 1 ≤ m ≤ 100) — the number of floors and the number of rooms in each floor, respectively. The next n lines contains the building description. Each line contains a binary string of length m + 2 representing a floor (the left stairs, then m rooms, then the righ...
Print a single integer — the minimum total time needed to turn off all the lights.
null
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to th...
[{"input": "2 2\n0010\n0100", "output": "5"}, {"input": "3 4\n001000\n000010\n000010", "output": "12"}, {"input": "4 3\n01110\n01110\n01110\n01110", "output": "18"}]
1,600
["bitmasks", "brute force", "dp"]
72
[{"input": "2 2\r\n0010\r\n0100\r\n", "output": "5\r\n"}, {"input": "3 4\r\n001000\r\n000010\r\n000010\r\n", "output": "12\r\n"}, {"input": "4 3\r\n01110\r\n01110\r\n01110\r\n01110\r\n", "output": "18\r\n"}, {"input": "3 2\r\n0000\r\n0100\r\n0100\r\n", "output": "4\r\n"}, {"input": "1 89\r\n0000000000000000000000000000...
false
stdio
null
true
812/B
812
B
Python 3
TESTS
42
46
102,400
230367730
n, m = list(map(int, input().split())) floor = [] count = 0 for i in range(n): str = input() floor.append(list(map(int, list(str)))) if 1 in floor[i]: count += 1 i = n - 1 j = 0 time = 0 while count > 0: if 1 in floor[i]: if j == 0: while 1 in floor[i]: j += 1...
72
62
307,200
27493791
def booly(s): return bool(int(s)) n, m = map(int, input().split()); nothing = "0"*(m+2); a = []; for i in range(n): a.append(input()) for i in range(n): if a[i] != nothing: break; a = a[i:] a.reverse(); n = len(a) #print(a) leftA = [i.find("1") for i in a] rightA = [i.rfind("1") for i in a] ...
Codeforces Round 417 (Div. 2)
CF
2,017
1
256
Sagheer, the Hausmeister
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of n floors with stairs at the left and the right sides...
The first line contains two integers n and m (1 ≤ n ≤ 15 and 1 ≤ m ≤ 100) — the number of floors and the number of rooms in each floor, respectively. The next n lines contains the building description. Each line contains a binary string of length m + 2 representing a floor (the left stairs, then m rooms, then the righ...
Print a single integer — the minimum total time needed to turn off all the lights.
null
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to th...
[{"input": "2 2\n0010\n0100", "output": "5"}, {"input": "3 4\n001000\n000010\n000010", "output": "12"}, {"input": "4 3\n01110\n01110\n01110\n01110", "output": "18"}]
1,600
["bitmasks", "brute force", "dp"]
72
[{"input": "2 2\r\n0010\r\n0100\r\n", "output": "5\r\n"}, {"input": "3 4\r\n001000\r\n000010\r\n000010\r\n", "output": "12\r\n"}, {"input": "4 3\r\n01110\r\n01110\r\n01110\r\n01110\r\n", "output": "18\r\n"}, {"input": "3 2\r\n0000\r\n0100\r\n0100\r\n", "output": "4\r\n"}, {"input": "1 89\r\n0000000000000000000000000000...
false
stdio
null
true
812/B
812
B
Python 3
TESTS
42
62
0
27490195
read = lambda: map(int, input().split()) n, m = read() a = [input() for i in range(n)] l = [-1] * n r = [-1] * n for i in range(n): ind = n - i - 1 fst = lst = -1 for j in range(1, m + 1): if a[ind][j] == '1': if fst == -1: fst = j lst = j l[i], r[i] = fst...
72
62
307,200
27494695
ans = 0 n, m = map(int, input().split()) arr = [""] + [input() for i in range(n)][::-1] dp = [[-1, 10 ** 9, 0] for i in range(n + 1)] z = 0 for i in range(1, 1 + n): z += arr[i].count("1") for i in range(1, n + 1): l = arr[i].find("1") r = arr[i].rfind("1") z -= arr[i].count("1") if l != -1: ...
Codeforces Round 417 (Div. 2)
CF
2,017
1
256
Sagheer, the Hausmeister
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of n floors with stairs at the left and the right sides...
The first line contains two integers n and m (1 ≤ n ≤ 15 and 1 ≤ m ≤ 100) — the number of floors and the number of rooms in each floor, respectively. The next n lines contains the building description. Each line contains a binary string of length m + 2 representing a floor (the left stairs, then m rooms, then the righ...
Print a single integer — the minimum total time needed to turn off all the lights.
null
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to th...
[{"input": "2 2\n0010\n0100", "output": "5"}, {"input": "3 4\n001000\n000010\n000010", "output": "12"}, {"input": "4 3\n01110\n01110\n01110\n01110", "output": "18"}]
1,600
["bitmasks", "brute force", "dp"]
72
[{"input": "2 2\r\n0010\r\n0100\r\n", "output": "5\r\n"}, {"input": "3 4\r\n001000\r\n000010\r\n000010\r\n", "output": "12\r\n"}, {"input": "4 3\r\n01110\r\n01110\r\n01110\r\n01110\r\n", "output": "18\r\n"}, {"input": "3 2\r\n0000\r\n0100\r\n0100\r\n", "output": "4\r\n"}, {"input": "1 89\r\n0000000000000000000000000000...
false
stdio
null
true
926/H
926
H
Python 3
TESTS
22
265
26,419,200
226617490
n, k = [int(i) for i in input().split()] scores = [int(i) for i in input().split()] colors = input().strip() scores_r = [scores[i] for i in range(n) if colors[i] == 'R'] scores_o = [scores[i] for i in range(n) if colors[i] == 'O'] scores_w = [scores[i] for i in range(n) if colors[i] == 'W'] scores_r.sort(reverse ...
98
265
19,251,200
197516180
import sys def solve(first_color, second_color, need): if need < 2 or min(len(first_color), len(second_color)) < 1 or len(first_color) + len(second_color) < need: return -1 total = -first_color[0] - second_color[0] temp = [] for cur_iter in range(1, len(first_color)): temp.append(first...
VK Cup 2018 - Wild-card Round 1
ICPC
2,018
1
256
Endless Roses Most Beautiful
Arkady decided to buy roses for his girlfriend. A flower shop has white, orange and red roses, and the total amount of them is n. Arkady thinks that red roses are not good together with white roses, so he won't buy a bouquet containing both red and white roses. Also, Arkady won't buy a bouquet where all roses have the...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 200 000) — the number of roses in the show and the number of roses Arkady wants to buy. The second line contains a sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 10 000), where bi equals the beauty of the i-th rose. The third line contains a string c of length...
Print the maximum possible total beauty of a bouquet of k roses that satisfies the constraints above. If it is not possible to make a single such bouquet, print -1.
null
In the first example Arkady wants to buy 3 roses. He can, for example, buy both red roses (their indices are 1 and 2, and their total beauty is 7) and the only orange rose (its index is 3, its beauty is 4). This way the total beauty of the bouquet is 11. In the second example Arkady can not buy a bouquet because all r...
[{"input": "5 3\n4 3 4 1 6\nRROWW", "output": "11"}, {"input": "5 2\n10 20 14 20 11\nRRRRR", "output": "-1"}, {"input": "11 5\n5 6 3 2 3 4 7 5 4 5 6\nRWOORWORROW", "output": "28"}]
2,200
[]
98
[{"input": "5 3\r\n4 3 4 1 6\r\nRROWW\r\n", "output": "11\r\n"}, {"input": "5 2\r\n10 20 14 20 11\r\nRRRRR\r\n", "output": "-1\r\n"}, {"input": "11 5\r\n5 6 3 2 3 4 7 5 4 5 6\r\nRWOORWORROW\r\n", "output": "28\r\n"}, {"input": "15 10\r\n8560 6244 9607 5137 7187 3217 5527 9919 282 8748 3529 6110 5767 521 3393\r\nOWRWOOR...
false
stdio
null
true
733/C
733
C
PyPy 3
TESTS
9
140
0
75972933
n = int(input()) scum = list(map(int,input().split())) k = int(input()) bag = list(map(int,input().split())) hoot = [] www = 0 w = 0 getsome = [] for i in range(k): c = 0 for j in range(w,n): c+=scum[j] if c == bag[i]: hoot.append(j+1) w = j+1 break if...
139
46
0
230899366
f = lambda: list(map(int, input().split())) def g(i, j, k): z = y = i for x in range(i, j): if a[x] > a[y]: y = x if y > i: z = y else: while a[y] == a[i]: y += 1 if y == j: return [] y -= 1 l = [str(k + y - x) + ' L' for x in range(i, y)] r = [st...
Codeforces Round 378 (Div. 2)
CF
2,016
1
256
Epidemic in Monstropolis
There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city. Soon, monsters became hungry and began to eat each other. One monster can eat other monster if its weight is strictly greater than the weight of the monster...
The first line contains single integer n (1 ≤ n ≤ 500) — the number of monsters in the initial queue. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial weights of the monsters. The third line contains single integer k (1 ≤ k ≤ n) — the number of monsters in the queue after the joke. Th...
In case if no actions could lead to the final queue, print "NO" (without quotes) in the only line. Otherwise print "YES" (without quotes) in the first line. In the next n - k lines print actions in the chronological order. In each line print x — the index number of the monster in the current queue which eats and, sepa...
null
In the first example, initially there were n = 6 monsters, their weights are [1, 2, 2, 2, 1, 2] (in order of queue from the first monster to the last monster). The final queue should be [5, 5]. The following sequence of eatings leads to the final queue: - the second monster eats the monster to the left (i.e. the first...
[{"input": "6\n1 2 2 2 1 2\n2\n5 5", "output": "YES\n2 L\n1 R\n4 L\n3 L"}, {"input": "5\n1 2 3 4 5\n1\n15", "output": "YES\n5 L\n4 L\n3 L\n2 L"}, {"input": "5\n1 1 1 3 3\n3\n2 1 6", "output": "NO"}]
1,800
["constructive algorithms", "dp", "greedy", "two pointers"]
139
[{"input": "6\r\n1 2 2 2 1 2\r\n2\r\n5 5\r\n", "output": "YES\r\n2 L\r\n1 R\r\n4 L\r\n3 L\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1\r\n15\r\n", "output": "YES\r\n5 L\r\n4 L\r\n3 L\r\n2 L\r\n"}, {"input": "5\r\n1 1 1 3 3\r\n3\r\n2 1 6\r\n", "output": "NO"}, {"input": "5\r\n1 1 1 1 2\r\n3\r\n1 1 4\r\n", "output": "YES\r\n5 L...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: return f.read().splitlines() input_path, output_path, submission_path = sys.argv[1], sys.argv[2], sys.argv[3] input_lines = read_file(input_path) n = int(input_lines[0]) a = list(map(int, input_lines[1].split())) k = int(input_lines[2]) b = list(...
true
416/D
416
D
Python 3
TESTS
77
358
16,588,800
6610195
import sys import math n = int(sys.stdin.readline()) if n <= 2: print(1) sys.exit(0) a = [int(s) for s in sys.stdin.readline().split()] st = -1 # index of first positive number in current subset of a ed = -1 # index last positive number in current subset of a # differation is (a[ed] - a[st])/(ed - st) l...
84
373
16,384,000
6954252
n = int(input()) a = list(map(int, input().split())) i = 0 ans = 0 while i < n: ans += 1 i1 = i while i1 < n and a[i1] == -1: i1 += 1 if i1 == n: break i2 = i1 + 1 while i2 < n and a[i2] == -1: i2 += 1 if i2 == n: break dist = i2 - i1 step = (a[i2] - a...
Codeforces Round 241 (Div. 2)
CF
2,014
1
256
Population Size
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if...
The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of elements in the sequence. The second line contains integer values a1, a2, ..., an separated by a space (1 ≤ ai ≤ 109 or ai = - 1).
Print the minimum number of arithmetic progressions that you need to write one after another to get sequence a. The positions marked as -1 in a can be represented by any positive integers.
null
null
[{"input": "9\n8 6 4 2 1 4 7 10 2", "output": "3"}, {"input": "9\n-1 6 -1 2 -1 4 7 -1 2", "output": "3"}, {"input": "5\n-1 -1 -1 -1 -1", "output": "1"}, {"input": "7\n-1 -1 4 5 1 2 3", "output": "2"}]
2,400
["greedy", "implementation", "math"]
84
[{"input": "9\r\n8 6 4 2 1 4 7 10 2\r\n", "output": "3\r\n"}, {"input": "9\r\n-1 6 -1 2 -1 4 7 -1 2\r\n", "output": "3\r\n"}, {"input": "5\r\n-1 -1 -1 -1 -1\r\n", "output": "1\r\n"}, {"input": "7\r\n-1 -1 4 5 1 2 3\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n65\r\n", "output": ...
false
stdio
null
true
581/C
581
C
PyPy 3-64
TESTS
95
155
14,848,000
231484514
from os import path from sys import stdin, stdout filename = "../templates/input.txt" if path.exists(filename): stdin = open(filename, 'r') def input(): return stdin.readline().rstrip() def print(*args, sep=' ', end='\n'): stdout.write(sep.join(map(str, args))) stdout.write(end) def solution(): ...
98
109
13,414,400
229663137
n, k = map(int, input().split()) a = list(map(int, input().split())) s = 0 r = [(10 - x % 10) % 10 for x in a] s += sum(x // 10 for x in a) r.sort() for i in range(n): if r[i]: if r[i] <= k: k -= r[i] s += 1 s += k // 10 s = min(s, n * 10) print(s)# 1698223430.592529
Codeforces Round 322 (Div. 2)
CF
2,015
1
256
Developing Skills
Petya loves computer games. Finally a game that he's been waiting for so long came out! The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is...
The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-...
The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units.
null
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} r...
[{"input": "2 4\n7 9", "output": "2"}, {"input": "3 8\n17 15 19", "output": "5"}, {"input": "2 2\n99 100", "output": "20"}]
1,400
["implementation", "math", "sortings"]
98
[{"input": "2 4\r\n7 9\r\n", "output": "2\r\n"}, {"input": "3 8\r\n17 15 19\r\n", "output": "5\r\n"}, {"input": "2 2\r\n99 100\r\n", "output": "20\r\n"}, {"input": "100 10000\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
false
stdio
null
true
798/B
798
B
Python 3
TESTS
3
30
0
203867335
def analiza(x): arr=[] mov=0 for i in x: for j in x: if i != j: mov+=comprob(i,j) arr.append(mov) mov=0 return min(arr) def comprob(x,y): m=0 x=list(x) y=list(y) p=list(y) while(True): if(x==y): return 0 ...
99
62
5,529,600
26544102
import sys n = int(input()) S = [] for _ in range(n): s = input() S.append(s+s) k = len(S[0])//2 mn = 1e10 for i in range(k): s = S[0][i:i+k] sm = 0 for x in S: try: sm += x.index(s) except ValueError: print(-1) sys.exit(0) mn = min(mn, sm) pri...
Codeforces Round 410 (Div. 2)
CF
2,017
2
256
Mike and strings
Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec". Now Mike asks himself: what...
The first line contains integer n (1 ≤ n ≤ 50) — the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50.
Print the minimal number of moves Mike needs in order to make all the strings equal or print - 1 if there is no solution.
null
In the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz".
[{"input": "4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "output": "5"}, {"input": "2\nmolzv\nlzvmo", "output": "2"}, {"input": "3\nkc\nkc\nkc", "output": "0"}, {"input": "3\naa\naa\nab", "output": "-1"}]
1,300
["brute force", "dp", "strings"]
99
[{"input": "4\r\nxzzwo\r\nzwoxz\r\nzzwox\r\nxzzwo\r\n", "output": "5\r\n"}, {"input": "2\r\nmolzv\r\nlzvmo\r\n", "output": "2\r\n"}, {"input": "3\r\nkc\r\nkc\r\nkc\r\n", "output": "0\r\n"}, {"input": "3\r\naa\r\naa\r\nab\r\n", "output": "-1\r\n"}, {"input": "3\r\nkwkb\r\nkbkw\r\nbkwk\r\n", "output": "3\r\n"}, {"input":...
false
stdio
null
true
812/B
812
B
Python 3
TESTS
42
233
307,200
27529899
# 1000 n_m = [int(x) for x in input().split()] n_m[1] += 1 floors = [] rooms = [] position = [0, 0] def judge (a,b,rooms): #for a temp=rooms[:] temp_room=temp.pop(a) temp_cost=do(temp,temp_room) # for b temp1 = rooms[:] temp1_room = temp1.pop(b) temp1_cost = do(temp1,temp1_room) ...
72
62
512,000
27522047
from collections import Counter import sys def left_time(floor): light_counter = Counter(floor) # print(light_counter) # print(light_counter['1']) if light_counter['1'] == 0: return 0 else: last_light_search = 1 while last_light_search <= len(floor): # print(last...
Codeforces Round 417 (Div. 2)
CF
2,017
1
256
Sagheer, the Hausmeister
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of n floors with stairs at the left and the right sides...
The first line contains two integers n and m (1 ≤ n ≤ 15 and 1 ≤ m ≤ 100) — the number of floors and the number of rooms in each floor, respectively. The next n lines contains the building description. Each line contains a binary string of length m + 2 representing a floor (the left stairs, then m rooms, then the righ...
Print a single integer — the minimum total time needed to turn off all the lights.
null
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to th...
[{"input": "2 2\n0010\n0100", "output": "5"}, {"input": "3 4\n001000\n000010\n000010", "output": "12"}, {"input": "4 3\n01110\n01110\n01110\n01110", "output": "18"}]
1,600
["bitmasks", "brute force", "dp"]
72
[{"input": "2 2\r\n0010\r\n0100\r\n", "output": "5\r\n"}, {"input": "3 4\r\n001000\r\n000010\r\n000010\r\n", "output": "12\r\n"}, {"input": "4 3\r\n01110\r\n01110\r\n01110\r\n01110\r\n", "output": "18\r\n"}, {"input": "3 2\r\n0000\r\n0100\r\n0100\r\n", "output": "4\r\n"}, {"input": "1 89\r\n0000000000000000000000000000...
false
stdio
null
true
812/B
812
B
Python 3
TESTS
42
234
307,200
27531582
# 1000 n_m = [int(x) for x in input().split()] n_m[1] += 1 floors = [] rooms = [] position = [0, 0] def judge(a, b, rooms): # for a temp = rooms[:] temp_room = temp.pop(a) temp_cost = do(temp, temp_room) # for b temp1 = rooms[:] temp1_room = temp1.pop(b) temp1_cost = do(temp1, temp1_...
72
62
1,536,000
209607846
import sys input = lambda: sys.stdin.readline().rstrip() N,M = map(int, input().split()) S = [] for _ in range(N): S.append(input()) S = S[::-1] while S and not '1' in S[-1]: S.pop() if not S: exit(print(0)) N = len(S) INF=float("inf") dp = [[INF,INF] for _ in range(N+1)] dp[0][0] = -1 for i in rang...
Codeforces Round 417 (Div. 2)
CF
2,017
1
256
Sagheer, the Hausmeister
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of n floors with stairs at the left and the right sides...
The first line contains two integers n and m (1 ≤ n ≤ 15 and 1 ≤ m ≤ 100) — the number of floors and the number of rooms in each floor, respectively. The next n lines contains the building description. Each line contains a binary string of length m + 2 representing a floor (the left stairs, then m rooms, then the righ...
Print a single integer — the minimum total time needed to turn off all the lights.
null
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to th...
[{"input": "2 2\n0010\n0100", "output": "5"}, {"input": "3 4\n001000\n000010\n000010", "output": "12"}, {"input": "4 3\n01110\n01110\n01110\n01110", "output": "18"}]
1,600
["bitmasks", "brute force", "dp"]
72
[{"input": "2 2\r\n0010\r\n0100\r\n", "output": "5\r\n"}, {"input": "3 4\r\n001000\r\n000010\r\n000010\r\n", "output": "12\r\n"}, {"input": "4 3\r\n01110\r\n01110\r\n01110\r\n01110\r\n", "output": "18\r\n"}, {"input": "3 2\r\n0000\r\n0100\r\n0100\r\n", "output": "4\r\n"}, {"input": "1 89\r\n0000000000000000000000000000...
false
stdio
null
true
812/B
812
B
Python 3
TESTS
42
62
307,200
27607513
def left_traverse(a,m,n,l): for i in range(0,n): for j in range(1,m+1): if a[i][j]==1: l[i]=j break def right_traverse(a,m,n,r): for i in range(0,n): for j in range(m,0,-1): if a[i][j]==1: r[i]=j break def rk...
72
62
1,638,400
27495577
import sys def main(): n,m = map(int,sys.stdin.readline().split()) m+=2 z = [] for i in range(n): z.append(sys.stdin.readline().rstrip()) ans = 0 y = n-1 x = 0 q = [[x,y,ans]] for i in range(n-1,-1,-1): first =-1 last = -1 for j in range(m): ...
Codeforces Round 417 (Div. 2)
CF
2,017
1
256
Sagheer, the Hausmeister
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of n floors with stairs at the left and the right sides...
The first line contains two integers n and m (1 ≤ n ≤ 15 and 1 ≤ m ≤ 100) — the number of floors and the number of rooms in each floor, respectively. The next n lines contains the building description. Each line contains a binary string of length m + 2 representing a floor (the left stairs, then m rooms, then the righ...
Print a single integer — the minimum total time needed to turn off all the lights.
null
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to th...
[{"input": "2 2\n0010\n0100", "output": "5"}, {"input": "3 4\n001000\n000010\n000010", "output": "12"}, {"input": "4 3\n01110\n01110\n01110\n01110", "output": "18"}]
1,600
["bitmasks", "brute force", "dp"]
72
[{"input": "2 2\r\n0010\r\n0100\r\n", "output": "5\r\n"}, {"input": "3 4\r\n001000\r\n000010\r\n000010\r\n", "output": "12\r\n"}, {"input": "4 3\r\n01110\r\n01110\r\n01110\r\n01110\r\n", "output": "18\r\n"}, {"input": "3 2\r\n0000\r\n0100\r\n0100\r\n", "output": "4\r\n"}, {"input": "1 89\r\n0000000000000000000000000000...
false
stdio
null
true
676/C
676
C
Python 3
TESTS
67
124
1,536,000
106708516
#Created By Minsol Jeong def I3(): n, k = [int(x) for x in input().split()] s = input() a='a' b='b' maxBeauty = 1 a_max = s.count(a) b_max = s.count(b) if a_max <= k or b_max <= k: maxBeauty = n elif a_max >= b_max: foundB = [i for i, x in enumerate(s) if x == b] ...
117
62
3,686,400
147689765
def check(n,k,s,x): cnt, ans, j = 0, 0, 0 for i in range(n): if s[i] == x: cnt += 1 if cnt > k: while cnt > k: if s[j] == x: cnt -= 1 j += 1 ans = max(ans, i - j + 1) return ans def solve(): n, k = map(int, input().split()) s = input() print(max(check(n, k, s, 'a'), check(n, k, s, 'b')...
Codeforces Round 354 (Div. 2)
CF
2,016
1
256
Vasya and String
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. W...
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only.
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
null
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
[{"input": "4 2\nabba", "output": "4"}, {"input": "8 1\naabaabaa", "output": "5"}]
1,500
["binary search", "dp", "strings", "two pointers"]
117
[{"input": "4 2\r\nabba\r\n", "output": "4\r\n"}, {"input": "8 1\r\naabaabaa\r\n", "output": "5\r\n"}, {"input": "1 0\r\na\r\n", "output": "1\r\n"}, {"input": "1 1\r\nb\r\n", "output": "1\r\n"}, {"input": "1 0\r\nb\r\n", "output": "1\r\n"}, {"input": "1 1\r\na\r\n", "output": "1\r\n"}, {"input": "10 10\r\nbbbbbbbbbb\r\...
false
stdio
null
true
618/C
618
C
PyPy 3
TESTS
14
998
33,382,400
28419123
n = int(input()) pos = [] for i in range(0, n): tmp = input() tmp = tmp.split() pos.append([int(tmp[0]), int(tmp[1])]) x1 = pos[0][0] y1 = pos[0][1] x2 = pos[1][0] y2 = pos[1][1] tar = 1 for i in range(2, n): if (pos[i][0] - x1) * (y2 - y1) == (x2 - x1) * (pos[i][1] - y1)\ and abs(pos[i][0] - x1...
98
343
28,979,200
175796040
import sys input = sys.stdin.buffer.readline def gcd(a, b): if a > b: a, b = b, a if b % a==0: return a return gcd(b % a, a) def find_slope(p1, p2): x1, y1 = p1 x2, y2 = p2 if x1==x2: return (False, None, None) num1 = (y2-y1) den1 = (x2-x1) if den1 < 0: ...
Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)
CF
2,016
2
256
Constellation
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position. In the evening Noku is going to take a look at the night sky. He would like to find three d...
The first line of the input contains a single integer n (3 ≤ n ≤ 100 000). Each of the next n lines contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109). It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Print three distinct integers on a single line — the indices of the three points that form a triangle that satisfies the conditions stated in the problem. If there are multiple possible answers, you may print any of them.
null
In the first sample, we can print the three indices in any order. In the second sample, we have the following picture. Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
[{"input": "3\n0 1\n1 0\n1 1", "output": "1 2 3"}, {"input": "5\n0 0\n0 2\n2 0\n2 2\n1 1", "output": "1 3 5"}]
1,600
["geometry", "implementation"]
98
[{"input": "3\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "1 2 3\r\n"}, {"input": "5\r\n0 0\r\n0 2\r\n2 0\r\n2 2\r\n1 1\r\n", "output": "1 3 5\r\n"}, {"input": "3\r\n819934317 939682125\r\n487662889 8614219\r\n-557136619 382982369\r\n", "output": "1 3 2\r\n"}, {"input": "10\r\n25280705 121178189\r\n219147240 -570920213\r\n-82...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input points with open(input_path, 'r') as f: n = int(f.readline().strip()) points = [] for _ in range(n): x, y = map(int, f.readline().strip().split()) points.append((x, y)) # Read su...
true
676/C
676
C
Python 3
TESTS
67
78
204,800
218432683
n,k = map(int,input().split()) word = str(input()) len_a = word.count('a') len_b = word.count('b') if len_a >= len_b: change = 'b' else: change = 'a' left = 0 count = 0 max_length = 0 for i in range(n): if word[i] == change: count += 1 while count > k: if word[left] == change: ...
117
77
102,400
218459242
def max_beauty(n, k, s): maxBeauty = 0 countA = 0 countB = 0 left = 0 for right in range(n): if s[right] == 'a': countA += 1 else: countB += 1 window_length = right - left + 1 if min(countA, countB) <= k: maxBeauty = max(m...
Codeforces Round 354 (Div. 2)
CF
2,016
1
256
Vasya and String
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. W...
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only.
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
null
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
[{"input": "4 2\nabba", "output": "4"}, {"input": "8 1\naabaabaa", "output": "5"}]
1,500
["binary search", "dp", "strings", "two pointers"]
117
[{"input": "4 2\r\nabba\r\n", "output": "4\r\n"}, {"input": "8 1\r\naabaabaa\r\n", "output": "5\r\n"}, {"input": "1 0\r\na\r\n", "output": "1\r\n"}, {"input": "1 1\r\nb\r\n", "output": "1\r\n"}, {"input": "1 0\r\nb\r\n", "output": "1\r\n"}, {"input": "1 1\r\na\r\n", "output": "1\r\n"}, {"input": "10 10\r\nbbbbbbbbbb\r\...
false
stdio
null
true
799/D
799
D
PyPy 3-64
TESTS
26
280
20,684,800
204500174
from math import * a,b,w0,h0,n=map(int,input().split()) w,h=ceil(a/w0),ceil(b/h0) x,y=ceil(b/h0),ceil(a/w0) MAX=100000 MAX=min(MAX,max(w,h)+888) if w<=1 and h<=1: print(0) else: l=list(map(int,input().split())) l.sort() l.reverse() l=l[:34] dp=[0 for i in range(MAX+1)] #max width for height i ...
103
826
2,150,400
27034917
import sys MAXV = 100010 d = [0] * MAXV a, b, h, w, n = map(int,input().split()) arr = input().split() for it in range(n): arr[it] = int(arr[it]) # print(arr) # print(a, b, h, w, n) def solve(a, b, h, w, z, product, it): # print(">", a, b, h, w, z, product, it) k = 0 if a % h: k = a // h...
Playrix Codescapes Cup (Codeforces Round 413, rated, Div. 1 + Div. 2)
CF
2,017
1
256
Field expansion
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Ar...
The first line contains five integers a, b, h, w and n (1 ≤ a, b, h, w, n ≤ 100 000) — the sizes of the rectangle needed to be placed, the initial sizes of the field and the number of available extensions. The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 100 000), where ai equals the integer a side multip...
Print the minimum number of extensions needed to reach Arkady's goal. If it is not possible to place the rectangle on the field with all extensions, print -1. If the rectangle can be placed on the initial field, print 0.
null
In the first example it is enough to use any of the extensions available. For example, we can enlarge h in 5 times using the second extension. Then h becomes equal 10 and it is now possible to place the rectangle on the field.
[{"input": "3 3 2 4 4\n2 5 4 10", "output": "1"}, {"input": "3 3 3 3 5\n2 3 5 4 2", "output": "0"}, {"input": "5 5 1 2 3\n2 2 3", "output": "-1"}, {"input": "3 4 1 1 3\n2 3 2", "output": "3"}]
2,100
["brute force", "dp", "meet-in-the-middle"]
103
[{"input": "3 3 2 4 4\r\n2 5 4 10\r\n", "output": "1\r\n"}, {"input": "3 3 3 3 5\r\n2 3 5 4 2\r\n", "output": "0\r\n"}, {"input": "5 5 1 2 3\r\n2 2 3\r\n", "output": "-1\r\n"}, {"input": "3 4 1 1 3\r\n2 3 2\r\n", "output": "3\r\n"}, {"input": "572 540 6 2 12\r\n2 3 2 2 2 3 3 3 2 2 2 2\r\n", "output": "-1\r\n"}, {"input...
false
stdio
null
true
515/B
515
B
PyPy 3-64
TESTS
40
140
1,331,200
141251359
def solver(): n,m = map(int,input().split()) boys = [int(x) for x in input().split()[1:]] girls = [int(x) for x in input().split()[1:]] happy_boys = [False for i in range(n)] happy_girls = [False for i in range(m)] for e in boys:happy_boys[e] = True for e in girls:happy_girls[e] =True fo...
56
61
4,505,600
133161183
def gcd(a,b): while b != 0: r = a % b a = b b = r return a def lcm(a,b): return a * b // gcd(a,b) n, m = map(int, input().split()) boys = [False] * n girls = [False] * m happy_boys = list(map(int, input().split()))[1:] happy_girls = list(map(int, input().split()))[1:] for i in happy_boys: boys[...
Codeforces Round 292 (Div. 2)
CF
2,015
2
256
Drazil and His Happy Friends
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan. There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites $$(i \bmod n)$$-th...
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi < n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ ...
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
null
By $$i \bmod k$$ we define the remainder of integer division of i by k. In first sample case: - On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. - On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so no...
[{"input": "2 3\n0\n1 0", "output": "Yes"}, {"input": "2 4\n1 0\n1 2", "output": "No"}, {"input": "2 3\n1 0\n1 1", "output": "Yes"}]
1,300
["brute force", "dsu", "meet-in-the-middle", "number theory"]
56
[{"input": "2 3\r\n0\r\n1 0\r\n", "output": "Yes\r\n"}, {"input": "2 4\r\n1 0\r\n1 2\r\n", "output": "No\r\n"}, {"input": "2 3\r\n1 0\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "16 88\r\n6 5 14 2 0 12 7\r\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82\r\n", "output": "Yes\r...
false
stdio
null
true
515/B
515
B
PyPy 3
TESTS
40
140
21,504,000
85997746
from sys import stdin ############################################################### def iinput(): return int(stdin.readline()) def sinput(): return input() def minput(): return map(int, stdin.readline().split()) def linput(): return list(map(int, stdin.readline().split())) ############################################...
56
62
0
9892582
import sys def readHappiness(count, stdin_happy): line = stdin_happy.rstrip() numbers = [int(nbr) for nbr in line.split(" ")] numbers = numbers[1:] happy_list = [] for n in range(count): if n in numbers: happy_list.append(1) else: happy_list.append(0) r...
Codeforces Round 292 (Div. 2)
CF
2,015
2
256
Drazil and His Happy Friends
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan. There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites $$(i \bmod n)$$-th...
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi < n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ ...
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
null
By $$i \bmod k$$ we define the remainder of integer division of i by k. In first sample case: - On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. - On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so no...
[{"input": "2 3\n0\n1 0", "output": "Yes"}, {"input": "2 4\n1 0\n1 2", "output": "No"}, {"input": "2 3\n1 0\n1 1", "output": "Yes"}]
1,300
["brute force", "dsu", "meet-in-the-middle", "number theory"]
56
[{"input": "2 3\r\n0\r\n1 0\r\n", "output": "Yes\r\n"}, {"input": "2 4\r\n1 0\r\n1 2\r\n", "output": "No\r\n"}, {"input": "2 3\r\n1 0\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "16 88\r\n6 5 14 2 0 12 7\r\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82\r\n", "output": "Yes\r...
false
stdio
null
true
515/B
515
B
PyPy 3
TESTS
40
170
1,228,800
75318030
n, m = [int(i) for i in input().split(" ")] b = [0]*n g = [0]*m x = [int(i) for i in input().split(" ")][1:] y = [int(i) for i in input().split(" ")][1:] #print(x, y) for i in x: b[i] = 1 for i in y: g[i] = 1 for i in range(n*m): h = max(b[i%n], g[i%m]) b[i%n] = h g[i%m] = h if sum(b)+sum(g) == n+m...
56
62
0
9896096
import math inp = input() mas = [int(s) for s in inp.strip().split(' ')] b = mas[0] g = mas[1] mas = [int(s) for s in input().strip().split(' ')] hb = {} if mas[0] != 0: for i in mas[1::]: hb[i] = True mas = [int(s) for s in input().strip().split(' ')] hg = {} if mas[0] != 0: for i in mas[1::]: ...
Codeforces Round 292 (Div. 2)
CF
2,015
2
256
Drazil and His Happy Friends
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan. There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites $$(i \bmod n)$$-th...
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi < n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ ...
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
null
By $$i \bmod k$$ we define the remainder of integer division of i by k. In first sample case: - On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. - On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so no...
[{"input": "2 3\n0\n1 0", "output": "Yes"}, {"input": "2 4\n1 0\n1 2", "output": "No"}, {"input": "2 3\n1 0\n1 1", "output": "Yes"}]
1,300
["brute force", "dsu", "meet-in-the-middle", "number theory"]
56
[{"input": "2 3\r\n0\r\n1 0\r\n", "output": "Yes\r\n"}, {"input": "2 4\r\n1 0\r\n1 2\r\n", "output": "No\r\n"}, {"input": "2 3\r\n1 0\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "16 88\r\n6 5 14 2 0 12 7\r\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82\r\n", "output": "Yes\r...
false
stdio
null
true
540/B
540
B
PyPy 3
TESTS
11
93
1,433,600
104390574
from sys import stdin n, k, p, x, y = map(int, stdin.buffer.readline().split()) a = list(map(int, stdin.buffer.readline().split())) a.sort() Sum = 0 id = 0 flag = False for i in range(len(a)): Sum += a[i] if a[i] >= y and not flag: flag = True id = i if Sum + n - k > x or id > (n // 2): ...
78
62
4,710,400
10946495
n, k, p, x, y = (int(x) for x in input().split()) alreadyGot = [int(x) for x in input().split()] countToWrite = n - k maxSumToWrite = x - sum(alreadyGot) if maxSumToWrite < 0: print(-1) else: newMarks = [1 for i in range(n-k)] maxSumToWrite -= (n - k) if maxSumToWrite < 0: print(-1) else: newMarksIt = 0 whil...
Codeforces Round 301 (Div. 2)
CF
2,015
2
256
School Marks
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests...
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total n...
If Vova cannot achieve the desired result, print "-1". Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
null
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai. In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the med...
[{"input": "5 3 5 18 4\n3 5 4", "output": "4 1"}, {"input": "5 3 5 16 4\n5 5 5", "output": "-1"}]
1,700
["greedy", "implementation"]
78
[{"input": "5 3 5 18 4\r\n3 5 4\r\n", "output": "4 1\r\n"}, {"input": "5 3 5 16 4\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "5 3 5 17 4\r\n5 5 5\r\n", "output": "1 1\r\n"}, {"input": "5 3 5 12 1\r\n5 5 1\r\n", "output": "-1\r\n"}, {"input": "5 3 5 13 1\r\n5 5 1\r\n", "output": "1 1\r\n"}, {"input": "7 4 5 26 5\r\n5...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path, 'r') as f_in: n, k, p, x, y = map(int, f_in.readline().split()) existing = list(map(int, f_in.readline().split())) with open(submission_path, 'r') as f_sub: submission_line = f_sub.read().strip() ...
true
45/I
45
I
Python 3
TESTS
35
92
0
185265675
# LUOGU_RID: 97366388 input() x=[int(i) for i in input().split()] t=max(x) if t<1: print(" ".join([str(i)for i in x])) elif t<2: print(" ".join([str(t)]*x.count(t))) else: print(" ".join([str(i)for i in x if i>1]))
65
248
0
67274149
n=int(input()) lst=[*map(int,input().split())] a,b=[],[] for i,x in enumerate(lst): if x>0:a.append(x) if x<0:b.append(x) b.sort() if len(b)%2==0:a.extend(b) else:a.extend(b[:-1]) if a==[]:print(max(lst)) else:print(*a)
School Team Contest 3 (Winter Computer School 2010/11)
ICPC
2,010
2
256
TCMCF+++
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of poin...
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
null
null
[{"input": "5\n1 2 -3 3 3", "output": "3 1 2 3"}, {"input": "13\n100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100"}, {"input": "4\n-2 -2 -2 -2", "output": "-2 -2 -2 -2"}]
1,400
["greedy"]
65
[{"input": "5\r\n1 2 -3 3 3\r\n", "output": "3 1 2 3 \r\n"}, {"input": "13\r\n100 100 100 100 100 100 100 100 100 100 100 100 100\r\n", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100 \r\n"}, {"input": "4\r\n-2 -2 -2 -2\r\n", "output": "-2 -2 -2 -2 \r\n"}, {"input": "1\r\n1\r\n", "output": "1 \r\n"}, {"i...
false
stdio
import sys from collections import Counter def compute_max_product(ci): if all(x == 0 for x in ci): return 0 positives = [x for x in ci if x > 0] negatives = [x for x in ci if x < 0] zeros = [x for x in ci if x == 0] non_zero = positives + negatives if not non_zero: return 0 ...
true
793/A
793
A
Python 3
TESTS
21
124
8,806,400
27098073
x=input().split(" ") N=int(x[0]) K=int(x[1]) mi=10**10 res=0 y=list(map(lambda a:int(a),input().split(" "))) for i in range (len(y)): if y[i]<mi: mi=y[i] temp=y[0] y[0]=y[i] y[i]=temp for elem in y: res+=(elem-mi)/K print(int(res) if int(res)==res else -1)
88
93
13,414,400
207367507
n, k = map(int, input().split()) a = list(map(int, input().split())) check = True for i in range(1, n): check = check and (a[i] % k == a[0] % k) if not check: print(-1) else: m = min(a) ans = 0 for i in range(n): ans += a[i] - m print(ans // k)
Tinkoff Challenge - Elimination Round
CF
2,017
1
256
Oleg and shares
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg...
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial prices.
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
null
Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There...
[{"input": "3 3\n12 9 15", "output": "3"}, {"input": "2 2\n10 9", "output": "-1"}, {"input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997"}]
900
["implementation", "math"]
88
[{"input": "3 3\r\n12 9 15\r\n", "output": "3"}, {"input": "2 2\r\n10 9\r\n", "output": "-1"}, {"input": "4 1\r\n1 1000000000 1000000000 1000000000\r\n", "output": "2999999997"}, {"input": "1 11\r\n123\r\n", "output": "0"}, {"input": "20 6\r\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14\r\n", "output": "151...
false
stdio
null
true
793/A
793
A
Python 3
TESTS
22
77
8,704,000
192698191
a,b=map(int,input().split()) c=[int(i) for i in input().split()] v=sum(c)-a*min(c) if a==4 and b==2: print(-1) elif v%b==0: print(v//b) else: print(-1)
88
93
13,414,400
222021703
n, k = map(int, input().split()) arr = list(map(int, input().split())) flag = True for i in range(1, n): flag = flag and (arr[0] % k == arr[i] % k) if not flag: print(-1) else: min_ = min(arr) tot = 0 for ele in arr: tot += ele - min_ print(tot // k)
Tinkoff Challenge - Elimination Round
CF
2,017
1
256
Oleg and shares
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg...
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial prices.
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
null
Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There...
[{"input": "3 3\n12 9 15", "output": "3"}, {"input": "2 2\n10 9", "output": "-1"}, {"input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997"}]
900
["implementation", "math"]
88
[{"input": "3 3\r\n12 9 15\r\n", "output": "3"}, {"input": "2 2\r\n10 9\r\n", "output": "-1"}, {"input": "4 1\r\n1 1000000000 1000000000 1000000000\r\n", "output": "2999999997"}, {"input": "1 11\r\n123\r\n", "output": "0"}, {"input": "20 6\r\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14\r\n", "output": "151...
false
stdio
null
true
900/A
900
A
Python 3
TESTS
21
187
0
182155044
total_m = 0 total_p = 0 for i in range(int(input())): x, y = input().split() if int(x) < 0: total_m += 1 else: total_p +=1 if total_m > 0 and total_p == 0: print('Yes') elif total_m == 0 and total_p > 0: print('Yes') elif total_m > 1 and total_p == 1: print('Yes') elif total_p > ...
71
124
22,323,200
213776904
lst = [w.rstrip() for w in open(0).readlines()] n = int(lst[0]) xs = [int(line.split()[0]) for line in lst[1:]] pos = sum(1 for x in xs if x > 0) neg = n - pos print(["No","Yes"][min(pos, neg) < 2])
Codeforces Round 450 (Div. 2)
CF
2,017
1
256
Find Extra One
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
null
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
[{"input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes"}, {"input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No"}, {"input": "3\n1 2\n2 1\n4 60", "output": "Yes"}]
800
["geometry", "implementation"]
71
[{"input": "3\r\n1 1\r\n-1 -1\r\n2 -1\r\n", "output": "Yes"}, {"input": "4\r\n1 1\r\n2 2\r\n-1 1\r\n-2 2\r\n", "output": "No"}, {"input": "3\r\n1 2\r\n2 1\r\n4 60\r\n", "output": "Yes"}, {"input": "10\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n-1 -1\r\n", "output": "Yes"}, {"input": "2\r\n1000000...
false
stdio
null
true
900/A
900
A
Python 3
TESTS
21
343
8,089,600
80979159
def validarPuntos(puntos): contadorR, contadorL = 0, 0 #calcular cantidad por cada eje for i in range(len(puntos)): if puntos[i][0] > 0: #a la derecha contadorR += 1 elif puntos[i][0] < 0: #izquierda contadorL += 1 #si hay co...
71
139
0
153604583
n = int(input()) c = 0 for _ in range(n): s = input() if s[0] == '-': c += 1 print("NO" if c>1 and (n-c)>1 else "YES")
Codeforces Round 450 (Div. 2)
CF
2,017
1
256
Find Extra One
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
null
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
[{"input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes"}, {"input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No"}, {"input": "3\n1 2\n2 1\n4 60", "output": "Yes"}]
800
["geometry", "implementation"]
71
[{"input": "3\r\n1 1\r\n-1 -1\r\n2 -1\r\n", "output": "Yes"}, {"input": "4\r\n1 1\r\n2 2\r\n-1 1\r\n-2 2\r\n", "output": "No"}, {"input": "3\r\n1 2\r\n2 1\r\n4 60\r\n", "output": "Yes"}, {"input": "10\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n-1 -1\r\n", "output": "Yes"}, {"input": "2\r\n1000000...
false
stdio
null
true
900/A
900
A
Python 3
TESTS
21
311
0
80624688
n = int(input()) pos = 0 neg = 0 for _ in range(n): x, y = map(int,input().split()) if x > 0: pos+=1 else: neg+=1 if (pos <= 1 and neg > 1) or (neg <=1 and pos > 1): print('yes') else: print('no')
71
140
0
138328075
n = int(input()) c = 0 for i in range(n): s = input() if(s[0]== '-'): c += 1 print("Yes" if c <= 1 or n - c <= 1 else "NO")
Codeforces Round 450 (Div. 2)
CF
2,017
1
256
Find Extra One
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
null
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
[{"input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes"}, {"input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No"}, {"input": "3\n1 2\n2 1\n4 60", "output": "Yes"}]
800
["geometry", "implementation"]
71
[{"input": "3\r\n1 1\r\n-1 -1\r\n2 -1\r\n", "output": "Yes"}, {"input": "4\r\n1 1\r\n2 2\r\n-1 1\r\n-2 2\r\n", "output": "No"}, {"input": "3\r\n1 2\r\n2 1\r\n4 60\r\n", "output": "Yes"}, {"input": "10\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n-1 -1\r\n", "output": "Yes"}, {"input": "2\r\n1000000...
false
stdio
null
true
900/A
900
A
Python 3
TESTS
21
311
0
89868083
n = 0 p = 0 for i in range(int(input())): x,y = list(map(int,input().split())) if x < 0: n += 1 else: p += 1 if p>n and n in range(0,2): print('Yes') elif n>p and p in range(0,2): print('Yes') else: print('No')
71
140
0
216940003
n = int(input()) s = 0 for i in range(n): if int(input().split(' ')[0]) > 0: s += 1 if not s or s == n or s == 1 or n - s == 1: print('Yes') else: print('No')
Codeforces Round 450 (Div. 2)
CF
2,017
1
256
Find Extra One
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
null
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
[{"input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes"}, {"input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No"}, {"input": "3\n1 2\n2 1\n4 60", "output": "Yes"}]
800
["geometry", "implementation"]
71
[{"input": "3\r\n1 1\r\n-1 -1\r\n2 -1\r\n", "output": "Yes"}, {"input": "4\r\n1 1\r\n2 2\r\n-1 1\r\n-2 2\r\n", "output": "No"}, {"input": "3\r\n1 2\r\n2 1\r\n4 60\r\n", "output": "Yes"}, {"input": "10\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n-1 -1\r\n", "output": "Yes"}, {"input": "2\r\n1000000...
false
stdio
null
true
734/C
734
C
PyPy 3-64
TESTS
0
46
0
218779819
n, m, k = map(int, input().split()) x, s = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) d = list(map(int, input().split())) work1 = False work2 = False type1 = [[a[t], b[t]] for t in range(m)] type2 = [[c[t], d[t]] for t in range...
119
950
44,441,600
22239064
import bisect n, m, k = map(int, input().split()) x, s = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) d = list(map(int, input().split())) z1 = list(zip(a, b)) z2 = list(zip(c, d)) result = n * x for ai, bi in z1: if bi > s:...
Codeforces Round 379 (Div. 2)
CF
2,016
4
256
Anton and Making Potions
Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare n potions. Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two types that can faster the process of preparing potions. 1. Spells of t...
The first line of the input contains three integers n, m, k (1 ≤ n ≤ 2·109, 1 ≤ m, k ≤ 2·105) — the number of potions, Anton has to make, the number of spells of the first type and the number of spells of the second type. The second line of the input contains two integers x and s (2 ≤ x ≤ 2·109, 1 ≤ s ≤ 2·109) — the i...
Print one integer — the minimum time one has to spent in order to prepare n potions.
null
In the first sample, the optimum answer is to use the second spell of the first type that costs 10 manapoints. Thus, the preparation time of each potion changes to 4 seconds. Also, Anton should use the second spell of the second type to instantly prepare 15 potions spending 80 manapoints. The total number of manapoints...
[{"input": "20 3 2\n10 99\n2 4 3\n20 10 40\n4 15\n10 80", "output": "20"}, {"input": "20 3 2\n10 99\n2 4 3\n200 100 400\n4 15\n100 800", "output": "200"}]
1,600
["binary search", "dp", "greedy", "two pointers"]
119
[{"input": "20 3 2\r\n10 99\r\n2 4 3\r\n20 10 40\r\n4 15\r\n10 80\r\n", "output": "20\r\n"}, {"input": "20 3 2\r\n10 99\r\n2 4 3\r\n200 100 400\r\n4 15\r\n100 800\r\n", "output": "200\r\n"}, {"input": "10 3 3\r\n10 33\r\n1 7 6\r\n17 25 68\r\n2 9 10\r\n78 89 125\r\n", "output": "10\r\n"}, {"input": "94 1 1\r\n26 324\r\n...
false
stdio
null
true
982/A
982
A
Python 3
TESTS
26
93
0
39745914
n=int(input()) s=input() if n==1: if s=='1': print('Yes') else: print('No') elif n==2: if s=='11': print('No') else: print('Yes') elif n==3: if s=='001' or s=='100'or s=='111': print('No') else: print('Yes') elif s.startswith('001') or s.endswith('100'): print('No') else: x,y=s.find('11'),s.find('0...
55
46
0
198505201
input() s='0'+input()+'0' print('No' if '000' in s or '11' in s else 'Yes')
Codeforces Round 484 (Div. 2)
CF
2,018
1
256
Row
You're given a row with $$$n$$$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 2. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($$$0$$$ m...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of chairs. The next line contains a string of $$$n$$$ characters, each of them is either zero or one, describing the seating.
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
null
In sample case one the given seating is maximal. In sample case two the person at chair three has a neighbour to the right. In sample case three it is possible to seat yet another person into chair three.
[{"input": "3\n101", "output": "Yes"}, {"input": "4\n1011", "output": "No"}, {"input": "5\n10001", "output": "No"}]
1,200
["brute force", "constructive algorithms"]
55
[{"input": "3\r\n101\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1011\r\n", "output": "No\r\n"}, {"input": "5\r\n10001\r\n", "output": "No\r\n"}, {"input": "1\r\n0\r\n", "output": "No\r\n"}, {"input": "1\r\n1\r\n", "output": "Yes\r\n"}, {"input": "100\r\n01010010101010010100100101010010101001010010010010100101010100101...
false
stdio
null
true
900/A
900
A
Python 3
TESTS
21
374
0
40556543
n=int(input()) pos=0 neg=0 for k in range(n): a,b=map(int,input().split()) if(a<0): neg+=1 else: pos+=1 if(pos>1): if(neg==0 or neg==1): print("Yes") else: print("No") else: if(neg>1): if(pos==0 or pos==1): print("Yes") else: ...
71
140
1,945,600
105619392
import sys import io, os input = sys.stdin.buffer.readline n = int(input()) XY = [0]*n cnt = 0 for i in range(n): x,y = map(int, input().split()) if x > 0: cnt += 1 if cnt == 1 or n-cnt == 1 or n-cnt == 0 or cnt ==0: print('Yes') else: print('No')
Codeforces Round 450 (Div. 2)
CF
2,017
1
256
Find Extra One
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
null
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
[{"input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes"}, {"input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No"}, {"input": "3\n1 2\n2 1\n4 60", "output": "Yes"}]
800
["geometry", "implementation"]
71
[{"input": "3\r\n1 1\r\n-1 -1\r\n2 -1\r\n", "output": "Yes"}, {"input": "4\r\n1 1\r\n2 2\r\n-1 1\r\n-2 2\r\n", "output": "No"}, {"input": "3\r\n1 2\r\n2 1\r\n4 60\r\n", "output": "Yes"}, {"input": "10\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n-1 -1\r\n", "output": "Yes"}, {"input": "2\r\n1000000...
false
stdio
null
true
828/A
828
A
Python 3
TESTS
11
62
2,969,600
144463000
n,a,b = input().split(" ") n = int(n) a = int(a) b = int(b) denies = 0 for x in input().split(" ") : x = int(x) if(x == 1) : if(a > 0) : a -=1 else : if(b > 0) : b -= 1 a += 1 else : denies += 1 else : ...
97
93
5,632,000
205356994
count=0 tabs = list(map(int, input().split())) tabones=tabs[1] tabtwos=tabs[2] e=0 nums=list(map(int, input().split())) for i in nums: if i==1: if tabones>0: tabones-=1 elif tabtwos>0: tabtwos-=1 e+=1 elif e>0: e-=1 else: co...
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Restaurant Tables
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table....
The first line contains three integers n, a and b (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 2) — the description of clients in chronological o...
Print the total number of people the restaurant denies service to.
null
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin...
[{"input": "4 1 2\n1 2 1 1", "output": "0"}, {"input": "4 1 1\n1 1 2 1", "output": "2"}]
1,200
["implementation"]
97
[{"input": "4 1 2\r\n1 2 1 1\r\n", "output": "0\r\n"}, {"input": "4 1 1\r\n1 1 2 1\r\n", "output": "2\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1 3\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7 6 1\r\n1 1 1 1 1 1 1\r\n", "output": "0\r\n"...
false
stdio
null
true
828/A
828
A
PyPy 3
TESTS
11
109
8,806,400
106502772
n,a,b=map(int,input().split()) c=input().split() fa=a fb=b fc=0 denied=0 for i in range(len(c)): if(c[i]=='1'): if(fa==0): if(fb>0 and fc==0): fc+=1 fb-=1 elif(fc==1): fc-=1 else: denied+=1 else: ...
97
93
5,734,400
233007891
def mainFunc(): n, a, b = map(int, input().split()) group = list(map(int, input().split()))[:n] singleSeaters = {1:a,2:2*b} doubleSeaters = {2:b} deniedCount = 0 for i in group: if i==1: if singleSeaters[1]>0: singleSeaters[1] -=1 else: ...
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Restaurant Tables
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table....
The first line contains three integers n, a and b (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 2) — the description of clients in chronological o...
Print the total number of people the restaurant denies service to.
null
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin...
[{"input": "4 1 2\n1 2 1 1", "output": "0"}, {"input": "4 1 1\n1 1 2 1", "output": "2"}]
1,200
["implementation"]
97
[{"input": "4 1 2\r\n1 2 1 1\r\n", "output": "0\r\n"}, {"input": "4 1 1\r\n1 1 2 1\r\n", "output": "2\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1 3\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7 6 1\r\n1 1 1 1 1 1 1\r\n", "output": "0\r\n"...
false
stdio
null
true
416/D
416
D
PyPy 3-64
TESTS
17
62
512,000
153735486
n=int(input()) a=[int(x) for x in input().split()] def slv(a): b=[] for i in range(n): if(a[i]!=(-1)): b.append([a[i],i]) if(len(b)<=1): return 1 ans=1 ok=[] for i in range(len(b)-1): t=(b[i+1][0]-b[i][0])//(b[i+1][1]-b[i][1]) if((b[i+1][0]-b[i][0])%(b[i+...
84
171
27,648,000
302828817
import sys,math,heapq from collections import Counter #sys.setrecursionlimit(200000) #fin = open('input.txt', 'r') #input = lambda: fin.readline().strip() input=lambda: sys.stdin.readline().strip() import random RANDOM = random.getrandbits(20) class Wrapper(int): def __init__(self, x): int.__init__(x) ...
Codeforces Round 241 (Div. 2)
CF
2,014
1
256
Population Size
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if...
The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of elements in the sequence. The second line contains integer values a1, a2, ..., an separated by a space (1 ≤ ai ≤ 109 or ai = - 1).
Print the minimum number of arithmetic progressions that you need to write one after another to get sequence a. The positions marked as -1 in a can be represented by any positive integers.
null
null
[{"input": "9\n8 6 4 2 1 4 7 10 2", "output": "3"}, {"input": "9\n-1 6 -1 2 -1 4 7 -1 2", "output": "3"}, {"input": "5\n-1 -1 -1 -1 -1", "output": "1"}, {"input": "7\n-1 -1 4 5 1 2 3", "output": "2"}]
2,400
["greedy", "implementation", "math"]
84
[{"input": "9\r\n8 6 4 2 1 4 7 10 2\r\n", "output": "3\r\n"}, {"input": "9\r\n-1 6 -1 2 -1 4 7 -1 2\r\n", "output": "3\r\n"}, {"input": "5\r\n-1 -1 -1 -1 -1\r\n", "output": "1\r\n"}, {"input": "7\r\n-1 -1 4 5 1 2 3\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n65\r\n", "output": ...
false
stdio
null
true
828/A
828
A
Python 3
TESTS
11
93
2,969,600
139615908
n, a, b = map(int, input().split()) sum_ = 0 guest = input().split() for i in range(len(guest)): if guest[i] == '1': if a > 0: a -= 1 elif a == 0 and b > 0: a += 1 b -= 1 else: sum_ += 1 elif guest[i] == '2': if b > 0: b...
97
108
5,836,800
218100899
n, a, b = map(int, input().split()) t = [int(x) for x in input().split()] c = 0 ans = 0 for i in range(n): if t[i] == 1: if a == 0: if b == 0: if c == 0: ans += 1 else: c -= 1 else: b -= 1 ...
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Restaurant Tables
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table....
The first line contains three integers n, a and b (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 2) — the description of clients in chronological o...
Print the total number of people the restaurant denies service to.
null
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin...
[{"input": "4 1 2\n1 2 1 1", "output": "0"}, {"input": "4 1 1\n1 1 2 1", "output": "2"}]
1,200
["implementation"]
97
[{"input": "4 1 2\r\n1 2 1 1\r\n", "output": "0\r\n"}, {"input": "4 1 1\r\n1 1 2 1\r\n", "output": "2\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1 3\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7 6 1\r\n1 1 1 1 1 1 1\r\n", "output": "0\r\n"...
false
stdio
null
true
828/A
828
A
Python 3
TESTS
11
108
2,867,200
177532658
n, a, b = map(int, input().split()) t = map(int, input().split()) th = 0 d = 0 for i in t: if i == 1: if a > 0: a -= 1 elif th == 1: th = 0 elif b > 0: b -= 1 th = 1 else: d += 1 elif b > 0: b -= 1 else: d += 2 print(d)
97
108
22,835,200
200844190
def solve(i,j,p): ans=0 k=0 for a in p: if a==1: if i>0: i-=1 elif j>0: j-=1 k+=1 elif k>0: k-=1 else: ans+=1 elif a==2: if j>0: j-=1 ...
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Restaurant Tables
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table....
The first line contains three integers n, a and b (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 2) — the description of clients in chronological o...
Print the total number of people the restaurant denies service to.
null
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin...
[{"input": "4 1 2\n1 2 1 1", "output": "0"}, {"input": "4 1 1\n1 1 2 1", "output": "2"}]
1,200
["implementation"]
97
[{"input": "4 1 2\r\n1 2 1 1\r\n", "output": "0\r\n"}, {"input": "4 1 1\r\n1 1 2 1\r\n", "output": "2\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1 3\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7 6 1\r\n1 1 1 1 1 1 1\r\n", "output": "0\r\n"...
false
stdio
null
true
828/A
828
A
PyPy 3-64
TESTS
11
61
22,835,200
200312314
def solution(n,f,s,g): S =s*2 count=0 for x in g : if x == 1: if f>0 : f -=1 count+=1 elif S > 0: S-=1 count+=1 else: if S//2>0 : S-=2 count+=2 return sum(g)-count if __name__ == '__main__': n,f,s = map(int,input().split()) g =l...
97
108
22,835,200
225176702
n, a, b = map(int, input().split()) t = list(map(int, input().split())) b2 = 0 d = 0 for i in range(n): if t[i]==1: if a>0: a-=1 elif b>0: b-=1 b2+=1 elif b2>0: b2-=1 else: d+=1 else: if b>0: b-=1 ...
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Restaurant Tables
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table....
The first line contains three integers n, a and b (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 2) — the description of clients in chronological o...
Print the total number of people the restaurant denies service to.
null
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin...
[{"input": "4 1 2\n1 2 1 1", "output": "0"}, {"input": "4 1 1\n1 1 2 1", "output": "2"}]
1,200
["implementation"]
97
[{"input": "4 1 2\r\n1 2 1 1\r\n", "output": "0\r\n"}, {"input": "4 1 1\r\n1 1 2 1\r\n", "output": "2\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1 3\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7 6 1\r\n1 1 1 1 1 1 1\r\n", "output": "0\r\n"...
false
stdio
null
true
676/C
676
C
PyPy 3
TESTS
67
187
29,286,400
87641824
import os from math import* n,k=map(int,input().split()) arr=input() arr=list(arr) a=list(filter(lambda x:x=="a",arr)) b=list(filter(lambda x:x=="b",arr)) x="" if len(a)>=len(b): x="b" else: x="a" #print(x) fp=0 ans=0 count=0 brr=[0] checkpos=0 for i in range(n): if arr[i]==x: count+=1 brr.append(i) if count>k...
117
77
2,252,800
219080873
def max_beauty(n, k, s): max_length = 0 max_count = 0 char_count = [0, 0] left = 0 for right in range(n): char_count [ord(s[right]) - ord('a')] += 1 max_count = max(max_count, char_count [0], char_count [1]) window_length = right - left + 1 if window_length - max_cou...
Codeforces Round 354 (Div. 2)
CF
2,016
1
256
Vasya and String
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. W...
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only.
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
null
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
[{"input": "4 2\nabba", "output": "4"}, {"input": "8 1\naabaabaa", "output": "5"}]
1,500
["binary search", "dp", "strings", "two pointers"]
117
[{"input": "4 2\r\nabba\r\n", "output": "4\r\n"}, {"input": "8 1\r\naabaabaa\r\n", "output": "5\r\n"}, {"input": "1 0\r\na\r\n", "output": "1\r\n"}, {"input": "1 1\r\nb\r\n", "output": "1\r\n"}, {"input": "1 0\r\nb\r\n", "output": "1\r\n"}, {"input": "1 1\r\na\r\n", "output": "1\r\n"}, {"input": "10 10\r\nbbbbbbbbbb\r\...
false
stdio
null
true
828/A
828
A
Python 3
TESTS
11
78
4,505,600
225587111
n, a, b = map(int, input().split()) d = 0 for i in map(int, input().split()): if i == 1: if a: a -= 1 elif b: b -= 1 a += 1 else: d += 1 else: if b: b -= 1 else: d += 2 print(d)
97
109
8,499,200
28439703
n, a,b = list(map(int, input().split())) c=0 j=0 l = input().split() for g in l: if g == "1": if a>0: a-=1 elif b>0: b-=1 c+=1 elif c>0: c-=1 else: j+=1 elif b>0: b-=1 else: j+=2 print (j)
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Restaurant Tables
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table....
The first line contains three integers n, a and b (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 2) — the description of clients in chronological o...
Print the total number of people the restaurant denies service to.
null
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin...
[{"input": "4 1 2\n1 2 1 1", "output": "0"}, {"input": "4 1 1\n1 1 2 1", "output": "2"}]
1,200
["implementation"]
97
[{"input": "4 1 2\r\n1 2 1 1\r\n", "output": "0\r\n"}, {"input": "4 1 1\r\n1 1 2 1\r\n", "output": "2\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1 3\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7 6 1\r\n1 1 1 1 1 1 1\r\n", "output": "0\r\n"...
false
stdio
null
true
828/A
828
A
PyPy 3-64
TESTS
11
77
15,155,200
225586289
n,a,b=map(int,input().split()) c=0 o=0 for g in map(int,input().split()): if g==1: if a>0:a-=1 elif c>0:c-=1 elif b>0: b-=1 c+=1 else:o+=1 else: if b>0:b-=1 else:o+=2 print(o)
97
109
18,432,000
177087289
import sys input = sys.stdin.buffer.readline n, a, b = map(int, input().split()) c = 0 # 1 person left 2 people table queries = list(map(int, input().split())) ans = 0 for query in queries: if query == 1: if a: a -= 1 elif b: b -= 1 c += 1 elif c: ...
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Restaurant Tables
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table....
The first line contains three integers n, a and b (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 2) — the description of clients in chronological o...
Print the total number of people the restaurant denies service to.
null
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin...
[{"input": "4 1 2\n1 2 1 1", "output": "0"}, {"input": "4 1 1\n1 1 2 1", "output": "2"}]
1,200
["implementation"]
97
[{"input": "4 1 2\r\n1 2 1 1\r\n", "output": "0\r\n"}, {"input": "4 1 1\r\n1 1 2 1\r\n", "output": "2\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1 3\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7 6 1\r\n1 1 1 1 1 1 1\r\n", "output": "0\r\n"...
false
stdio
null
true
828/A
828
A
Python 3
TESTS
11
78
3,481,600
174338080
n, a, b = map(int, input().split()) l = list(map(int, input().split())) ans = 0 c = 0 for i in l: if i == 1: if a != 0: a -= i;ans += 1 elif c != 0: ans += i;c -= 1 elif b != 0: ans += i;b -= 1;c += 1 else: if b != 0: ans += i;b -= ...
97
124
3,788,800
116314423
def checkSat(a, b, l): OneT = a; TwoT = b; ParTwoT = 0; Satisfied = 0; for i in range(len(l)): if(l[i]==1): if(OneT!=0): OneT -= 1 Satisfied +=1 else: if(TwoT!=0): TwoT -= 1 ParTwo...
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Restaurant Tables
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table....
The first line contains three integers n, a and b (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 2) — the description of clients in chronological o...
Print the total number of people the restaurant denies service to.
null
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin...
[{"input": "4 1 2\n1 2 1 1", "output": "0"}, {"input": "4 1 1\n1 1 2 1", "output": "2"}]
1,200
["implementation"]
97
[{"input": "4 1 2\r\n1 2 1 1\r\n", "output": "0\r\n"}, {"input": "4 1 1\r\n1 1 2 1\r\n", "output": "2\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1 3\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7 6 1\r\n1 1 1 1 1 1 1\r\n", "output": "0\r\n"...
false
stdio
null
true
828/A
828
A
Python 3
TESTS
11
78
3,993,600
141470577
def main(): n, a, b = map(int, input().split()) lst = list(map(int, input().split())) c, ans = 0, 0 for i in lst: if i == 1: if a > 0: a -= 1 elif c > 0: # c = Table for 2 occupied by 1 c -= 1 elif b > 0: b -...
97
124
8,499,200
28431129
n, a, b = list(map(int,input().split())) l = input().split() o = 0 c = 0 for i in l: if i == '2': if b > 0: b -= 1 else: o += 2 if i == '1': if a > 0: a -= 1 elif b > 0: b -= 1 c += 1 elif c > 0: c -=...
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Restaurant Tables
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table....
The first line contains three integers n, a and b (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 2) — the description of clients in chronological o...
Print the total number of people the restaurant denies service to.
null
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin...
[{"input": "4 1 2\n1 2 1 1", "output": "0"}, {"input": "4 1 1\n1 1 2 1", "output": "2"}]
1,200
["implementation"]
97
[{"input": "4 1 2\r\n1 2 1 1\r\n", "output": "0\r\n"}, {"input": "4 1 1\r\n1 1 2 1\r\n", "output": "2\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1 3\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7 6 1\r\n1 1 1 1 1 1 1\r\n", "output": "0\r\n"...
false
stdio
null
true
828/A
828
A
PyPy 3-64
TESTS
11
92
22,835,200
167448617
#!/usr/bin/env python3 import math def test_case(casen): n, a, b = map(int, input().split()) t = list(map(int, input().split())) ans = 0 twoone = 0 for i in range(n): if t[i] == 1 and a > 0: a -= 1 continue if t[i] == 1 and twoone > 0: twoone ...
97
124
8,499,200
28436370
n, a, b = (input().split()) n = int(n) a = int(a) b = int(b) potatos = 0 counter = 0 customers = input().split() for i in customers: if(i == '1'): if(a > 0): a -= 1 elif(b > 0): b -= 1 potatos += 1 elif(potatos > 0): potatos -= 1 else:...
Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Restaurant Tables
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table....
The first line contains three integers n, a and b (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 2) — the description of clients in chronological o...
Print the total number of people the restaurant denies service to.
null
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin...
[{"input": "4 1 2\n1 2 1 1", "output": "0"}, {"input": "4 1 1\n1 1 2 1", "output": "2"}]
1,200
["implementation"]
97
[{"input": "4 1 2\r\n1 2 1 1\r\n", "output": "0\r\n"}, {"input": "4 1 1\r\n1 1 2 1\r\n", "output": "2\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 1 3\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7 6 1\r\n1 1 1 1 1 1 1\r\n", "output": "0\r\n"...
false
stdio
null
true
623/A
623
A
Python 3
TESTS
4
62
409,600
104469006
from collections import defaultdict n, m = map(int, input("").split()) edge_list =defaultdict(list) for i in range (m): start, end = map(int, input("").split()) edge_list[start].append(end) edge_list[end].append(start) def dfs(vertice, visited, connected_component): if vertice in visited: retur...
106
732
8,908,800
227484209
n, m = [int(i) for i in input().split(' ')] adj = [[1] * n for _ in range(n)] for i in range(n): adj[i][i] = 0 for _ in range(m): u, v = [int(i) - 1 for i in input().split(' ')] adj[u][v], adj[v][u] = 0, 0 b = set([i for i in range(n) if not any(adj[i])]) a = None for i in range(n): if i in b: c...
AIM Tech Round (Div. 1)
CF
2,016
2
256
Graph and String
One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties: - G has exactly n vertices, numbered from 1 to n....
The first line of the input contains two integers n and m $$( 1 \leq n \leq 500, 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$ — the number of vertices and edges in the graph found by Petya, respectively. Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It ...
In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise. If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the gra...
null
In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions. In the second sample the first vertex is connected to al...
[{"input": "2 1\n1 2", "output": "Yes\naa"}, {"input": "4 3\n1 2\n1 3\n1 4", "output": "No"}]
1,800
["constructive algorithms", "graphs"]
106
[{"input": "2 1\r\n1 2\r\n", "output": "Yes\r\naa\r\n"}, {"input": "4 3\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 2\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "1 0\r\n", "output": "Yes\r\na\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r...
false
stdio
import sys def main(): input_path = sys.argv[1] ref_output_path = sys.argv[2] sub_output_path = sys.argv[3] # Read input with open(input_path) as f: n, m = map(int, f.readline().split()) edges = [] for _ in range(m): u, v = map(int, f.readline().split()) ...
true
515/B
515
B
Python 3
TESTS
40
46
0
218399908
import sys sys.setrecursionlimit(100000000) input=lambda:sys.stdin.readline().strip() write=lambda x:sys.stdout.write(str(x)+'\n') # from random import randint # from copy import deepcopy # from collections import deque,Counter # from heapq import heapify,heappush,heappop # from bisect import bisect_left,bisect,insort...
56
62
0
9899555
n, m = map(int, input().split()) boy_funny = list(map(int, input().split())) girl_funny = list(map(int, input().split())) boy = [0]*n girl = [0]*m i = 1 while boy_funny[0] > 0: boy[boy_funny[i]] = 1 i += 1 boy_funny[0] -= 1 i = 1 while girl_funny[0] > 0: girl[girl_funny[i]] = 1 i += 1 girl_funny...
Codeforces Round 292 (Div. 2)
CF
2,015
2
256
Drazil and His Happy Friends
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan. There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites $$(i \bmod n)$$-th...
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi < n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ ...
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
null
By $$i \bmod k$$ we define the remainder of integer division of i by k. In first sample case: - On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. - On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so no...
[{"input": "2 3\n0\n1 0", "output": "Yes"}, {"input": "2 4\n1 0\n1 2", "output": "No"}, {"input": "2 3\n1 0\n1 1", "output": "Yes"}]
1,300
["brute force", "dsu", "meet-in-the-middle", "number theory"]
56
[{"input": "2 3\r\n0\r\n1 0\r\n", "output": "Yes\r\n"}, {"input": "2 4\r\n1 0\r\n1 2\r\n", "output": "No\r\n"}, {"input": "2 3\r\n1 0\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "16 88\r\n6 5 14 2 0 12 7\r\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82\r\n", "output": "Yes\r...
false
stdio
null
true
628/D
628
D
PyPy 3-64
TESTS
15
1,731
10,956,800
176782076
import sys readline=sys.stdin.readline mod=10**9+7 M,D=map(int,readline().split()) def solve(N,equal=False): dp=[[[0]*M for j in range(2)] for i in range(2)] for x in range(1,int(N[0])): if x==D: continue dp[0][0][x%M]+=1 if int(N[0])!=D: dp[1][0][int(N[0])%M]+=1 for...
66
218
19,660,800
189401939
from sys import stdin def main(): mod = 10**9 + 7 _all = map(str, stdin.read().split()) m, d, a, b = int(next(_all)), int(next(_all)), next(_all), next(_all) n = len(a) n_2, re, list_not_d, dp = n & 1, [0]*n, [i for i in range(10) if i ^ d], [[0]*m for i in range(n)] re[0] = 1 dp[0][0] = 1...
Educational Codeforces Round 8
ICPC
2,016
2
256
Magic Numbers
Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else. For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic...
The first line contains two integers m, d (1 ≤ m ≤ 2000, 0 ≤ d ≤ 9) — the parameters from the problem statement. The second line contains positive integer a in decimal presentation (without leading zeroes). The third line contains positive integer b in decimal presentation (without leading zeroes). It is guaranteed ...
Print the only integer a — the remainder after dividing by 109 + 7 of the number of d-magic numbers in segment [a, b] that are multiple of m.
null
The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96. The numbers from the answer of the second example are 2, 4, 6 and 8. The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747.
[{"input": "2 6\n10\n99", "output": "8"}, {"input": "2 0\n1\n9", "output": "4"}, {"input": "19 7\n1000\n9999", "output": "6"}]
2,200
["dp"]
66
[{"input": "2 6\r\n10\r\n99\r\n", "output": "8\r\n"}, {"input": "2 0\r\n1\r\n9\r\n", "output": "4\r\n"}, {"input": "19 7\r\n1000\r\n9999\r\n", "output": "6\r\n"}, {"input": "9 4\r\n33\r\n52\r\n", "output": "0\r\n"}, {"input": "10 8\r\n18\r\n59\r\n", "output": "0\r\n"}, {"input": "43 3\r\n587\r\n850\r\n", "output": "1\r...
false
stdio
null
true
515/B
515
B
PyPy 3-64
TESTS
40
62
1,536,000
214263256
n, m = map(int, input().split()) boys = [0] * n girls = [0] * m for i in map(int, input().split()[1:]): boys[i] = 1 for i in map(int, input().split()[1:]): girls[i] = 1 for i in range(n*m): boy, girl = i % n, i % m if boys[boy] or girls[girl]: boys[boy] = girls[girl] = 1 if all(boys) and all...
56
62
0
164159799
import sys input = sys.stdin.readline from math import gcd n, m = map(int, input().split()) a, *w = list(map(int, input().split())) b, *s = list(map(int, input().split())) x = gcd(n, m) if x == 1: print('Yes') else: d = [0]*x for i in w: d[i%x] = 1 for i in s: d[i%x] = 1 if d == [1...
Codeforces Round 292 (Div. 2)
CF
2,015
2
256
Drazil and His Happy Friends
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan. There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites $$(i \bmod n)$$-th...
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi < n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ ...
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
null
By $$i \bmod k$$ we define the remainder of integer division of i by k. In first sample case: - On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. - On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so no...
[{"input": "2 3\n0\n1 0", "output": "Yes"}, {"input": "2 4\n1 0\n1 2", "output": "No"}, {"input": "2 3\n1 0\n1 1", "output": "Yes"}]
1,300
["brute force", "dsu", "meet-in-the-middle", "number theory"]
56
[{"input": "2 3\r\n0\r\n1 0\r\n", "output": "Yes\r\n"}, {"input": "2 4\r\n1 0\r\n1 2\r\n", "output": "No\r\n"}, {"input": "2 3\r\n1 0\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "16 88\r\n6 5 14 2 0 12 7\r\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82\r\n", "output": "Yes\r...
false
stdio
null
true
665/D
665
D
PyPy 3
TESTS
11
171
34,713,600
126968131
import sys input = sys.stdin.readline def the_sieve_of_eratosthenes(n): s = [1] * (n + 1) x = [] for i in range(2, n + 1): if s[i]: x.append(i) for j in range(i, n + 1, i): s[j] = 0 return x n = int(input()) a = list(map(int, input().split())) x = set(th...
66
202
11,980,800
92581095
import sys def get_primes(n: int): from itertools import chain from array import array primes = {2, 3} is_prime = (array('b', (0, 0, 1, 1, 0, 1, 0)) + array('b', (1, 0, 0, 0, 1, 0))*((n-1)//6)) for i in chain.from_iterable((range(5, n+1, 6), range(7, n+1, 6))): if is_prime...
Educational Codeforces Round 12
ICPC
2,016
1
256
Simple Subset
A tuple of positive integers {x1, x2, ..., xk} is called simple if for all pairs of positive integers (i, j) (1 ≤ i < j ≤ k), xi + xj is a prime. You are given an array a with n positive integers a1, a2, ..., an (not necessary distinct). You want to find a simple subset of the array a with the maximum size. ...
The first line contains integer n (1 ≤ n ≤ 1000) — the number of integers in the array a. The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.
On the first line print integer m — the maximum possible size of simple subset of a. On the second line print m integers bl — the elements of the simple subset of the array a with the maximum size. If there is more than one solution you can print any of them. You can print the elements of the subset in any order.
null
null
[{"input": "2\n2 3", "output": "2\n3 2"}, {"input": "2\n2 2", "output": "1\n2"}, {"input": "3\n2 1 1", "output": "3\n1 1 2"}, {"input": "2\n83 14", "output": "2\n14 83"}]
1,800
["constructive algorithms", "greedy", "number theory"]
66
[{"input": "2\r\n2 3\r\n", "output": "2\r\n3 2\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1\r\n2\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "3\r\n1 1 2\r\n"}, {"input": "2\r\n83 14\r\n", "output": "2\r\n14 83\r\n"}, {"input": "10\r\n10 10 1 2 3 3 1 2 1 5\r\n", "output": "4\r\n1 1 10 1\r\n"}, {"input": "100\r\n314 90...
false
stdio
import sys from collections import Counter def sieve(max_limit): sieve = [True] * (max_limit + 1) sieve[0] = sieve[1] = False for i in range(2, int(max_limit**0.5) + 1): if sieve[i]: sieve[i*i : max_limit+1 : i] = [False]*len(sieve[i*i : max_limit+1 : i]) return sieve max_sum = 2 *...
true
793/A
793
A
Python 3
TESTS
21
155
9,216,000
54373109
# import sys # sys.stdin=open("input.in",'r') # sys.stdout=open("out1.out",'w') n,k=map(int,input().split()) a=list(map(int,input().split())) x=min(a) s=0 for i in a: s+=(i-x) if s==0: print(0) elif s%k==0: print(s//k) else: print(-1)
88
93
13,516,800
223701914
n,k=map(int,input().split()) l=list(map(int,input().split())) a=-1 for i in range(n-1): if l[i]%k!=l[i+1]%k: a=1 if a==1: print(-1) else: print((sum(l)-min(l)*n)//k)
Tinkoff Challenge - Elimination Round
CF
2,017
1
256
Oleg and shares
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg...
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial prices.
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
null
Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There...
[{"input": "3 3\n12 9 15", "output": "3"}, {"input": "2 2\n10 9", "output": "-1"}, {"input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997"}]
900
["implementation", "math"]
88
[{"input": "3 3\r\n12 9 15\r\n", "output": "3"}, {"input": "2 2\r\n10 9\r\n", "output": "-1"}, {"input": "4 1\r\n1 1000000000 1000000000 1000000000\r\n", "output": "2999999997"}, {"input": "1 11\r\n123\r\n", "output": "0"}, {"input": "20 6\r\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14\r\n", "output": "151...
false
stdio
null
true
793/A
793
A
Python 3
TESTS
21
108
15,052,800
206445201
import math n,kk=map(int,input().split()) a=list(map(int,input().split())) k=min(a) o=[] d=[] count=0 for i in list(a): d.append(i-k) if len(a)==1: print(0) elif sum(d)%kk!=0: print(-1) else: while True: try: a.remove(k) count+=1 except: for u in range...
88
108
8,806,400
194899032
countOfNumbers, rubles = map(int, input().split()) numbers = list(map(int, input().split())) # def Solution(): preResult = 0 minimalNumber = min(numbers) for element in numbers: check = (element - minimalNumber) % rubles if check != 0: return -1 ...
Tinkoff Challenge - Elimination Round
CF
2,017
1
256
Oleg and shares
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg...
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial prices.
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
null
Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There...
[{"input": "3 3\n12 9 15", "output": "3"}, {"input": "2 2\n10 9", "output": "-1"}, {"input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997"}]
900
["implementation", "math"]
88
[{"input": "3 3\r\n12 9 15\r\n", "output": "3"}, {"input": "2 2\r\n10 9\r\n", "output": "-1"}, {"input": "4 1\r\n1 1000000000 1000000000 1000000000\r\n", "output": "2999999997"}, {"input": "1 11\r\n123\r\n", "output": "0"}, {"input": "20 6\r\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14\r\n", "output": "151...
false
stdio
null
true
793/A
793
A
Python 3
TESTS
21
78
8,806,400
192697926
a,b=map(int,input().split()) c=[int(i) for i in input().split()] v=sum(c)-a*min(c) if v%b==0: print(v//b) else: print(-1)
88
108
13,414,400
206446402
import math n,kk=map(int,input().split()) a=list(map(int,input().split())) k=min(a) o=[] d=[] count=0 for i in a: if len(a)==1: print(0) break elif (i-k)%kk==0: continue else: print(-1) break else: while True: try: a.remove(k) ...
Tinkoff Challenge - Elimination Round
CF
2,017
1
256
Oleg and shares
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg...
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial prices.
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
null
Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There...
[{"input": "3 3\n12 9 15", "output": "3"}, {"input": "2 2\n10 9", "output": "-1"}, {"input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997"}]
900
["implementation", "math"]
88
[{"input": "3 3\r\n12 9 15\r\n", "output": "3"}, {"input": "2 2\r\n10 9\r\n", "output": "-1"}, {"input": "4 1\r\n1 1000000000 1000000000 1000000000\r\n", "output": "2999999997"}, {"input": "1 11\r\n123\r\n", "output": "0"}, {"input": "20 6\r\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14\r\n", "output": "151...
false
stdio
null
true
793/A
793
A
PyPy 3-64
TESTS
21
93
13,414,400
232610946
n,k = map(int, input().split()) a = sorted(map(int, input().split())) count = 0 for i in a: count += i - a[0] print(count//k if count/k%1==0 else -1)
88
108
14,745,600
232543358
def f(l): if (l[-1] - l[0]) % k != 0: return False for i in range(len(l) -1): if (l[i+1] - l[i]) % k != 0: return False return True n,k = map(int,input().split()) l = list(map(int,input().split())) l.sort() if f(l) == False: print('-1') else: cnt = 0 for i in reversed...
Tinkoff Challenge - Elimination Round
CF
2,017
1
256
Oleg and shares
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg...
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial prices.
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
null
Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There...
[{"input": "3 3\n12 9 15", "output": "3"}, {"input": "2 2\n10 9", "output": "-1"}, {"input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997"}]
900
["implementation", "math"]
88
[{"input": "3 3\r\n12 9 15\r\n", "output": "3"}, {"input": "2 2\r\n10 9\r\n", "output": "-1"}, {"input": "4 1\r\n1 1000000000 1000000000 1000000000\r\n", "output": "2999999997"}, {"input": "1 11\r\n123\r\n", "output": "0"}, {"input": "20 6\r\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14\r\n", "output": "151...
false
stdio
null
true
525/C
525
C
PyPy 3
TESTS
25
405
14,745,600
96267521
from collections import Counter import string import math import sys from fractions import Fraction def array_int(): return [int(i) for i in sys.stdin.readline().split()] def vary(arrber_of_variables): if arrber_of_variables==1: return int(sys.stdin.readline()) if arrber_of_variables>=2: ret...
96
124
14,028,800
194028400
import sys input = sys.stdin.readline n = int(input()) w = sorted(map(int, input().split()), reverse=1) i = 0 c = 0 a = 0 while i < n-1: if w[i] < w[i+1] + 2: if a == 0: a = min(w[i], w[i+1]) else: c += a*min(w[i], w[i+1]) a = 0 i += 2 else: i...
Codeforces Round 297 (Div. 2)
CF
2,015
2
256
Ilya and Sticks
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length li. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maxi...
The first line of the input contains a positive integer n (1 ≤ n ≤ 105) — the number of the available sticks. The second line of the input contains n positive integers li (2 ≤ li ≤ 106) — the lengths of the sticks.
The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks.
null
null
[{"input": "4\n2 4 4 2", "output": "8"}, {"input": "4\n2 2 3 5", "output": "0"}, {"input": "4\n100003 100004 100005 100006", "output": "10000800015"}]
1,600
["greedy", "math", "sortings"]
96
[{"input": "4\r\n2 4 4 2\r\n", "output": "8\r\n"}, {"input": "4\r\n2 2 3 5\r\n", "output": "0\r\n"}, {"input": "4\r\n100003 100004 100005 100006\r\n", "output": "10000800015\r\n"}, {"input": "8\r\n5 3 3 3 3 4 4 4\r\n", "output": "25\r\n"}, {"input": "10\r\n123 124 123 124 2 2 2 2 9 9\r\n", "output": "15270\r\n"}, {"inp...
false
stdio
null
true