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
989/B
989
B
Python 3
TESTS
30
93
0
39154517
def go(): n, p = [int(i) for i in input().split(' ')] s = input() x = [i for i in s] for i in range(n): next_i = i + p if next_i < n: if s[i] == s[next_i] and s[i] == '.': x[i] = '0' x[next_i] = '1' break elif s[i] !...
59
78
0
39166130
def func(st, sr, n): """ :param st: large string :param sr: small string :param n: int given :return: """ for i in range(len(sr)): if (st[i] == '0' or st[i+n] == '0') and (st[i] == '.' or st[i+n]=='.'): print(st.replace('.', '1')) return 0 elif (st[i]=='1' or st[i+n]=='1') and (st[i]=='.' or st[i+n]=='...
Codeforces Round 487 (Div. 2)
CF
2,018
1
256
A Tide of Riverscape
The records are expressed as a string $$$s$$$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low). You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $$$...
The first line contains two space-separated integers $$$n$$$ and $$$p$$$ ($$$1 \leq p \leq n \leq 2000$$$) — the length of the given string and the supposed period, respectively. The second line contains a string $$$s$$$ of $$$n$$$ characters — Mino's records. $$$s$$$ only contains characters '0', '1' and '.', and con...
Output one line — if it's possible that $$$p$$$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
null
In the first example, $$$7$$$ is not a period of the resulting string because the $$$1$$$-st and $$$8$$$-th characters of it are different. In the second example, $$$6$$$ is not a period of the resulting string because the $$$4$$$-th and $$$10$$$-th characters of it are different. In the third example, $$$9$$$ is alw...
[{"input": "10 7\n1.0.1.0.1.", "output": "1000100010"}, {"input": "10 6\n1.0.1.1000", "output": "1001101000"}, {"input": "10 9\n1........1", "output": "No"}]
1,200
["constructive algorithms", "strings"]
59
[{"input": "10 7\r\n1.0.1.0.1.\r\n", "output": "1000100010\r\n"}, {"input": "10 6\r\n1.0.1.1000\r\n", "output": "1001101000\r\n"}, {"input": "10 9\r\n1........1\r\n", "output": "No\r\n"}, {"input": "1 1\r\n.\r\n", "output": "No\r\n"}, {"input": "5 1\r\n0...1\r\n", "output": "00001\r\n"}, {"input": "17 10\r\n..1.100..1....
false
stdio
import sys def main(): input_path = sys.argv[1] ref_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path, 'r') as f: n, p = map(int, f.readline().split()) s = f.readline().strip() with open(ref_path, 'r') as f: ref_output = f.read().strip() with open(sub_pat...
true
989/B
989
B
PyPy 3
TESTS
22
140
1,228,800
62684949
def prog(): a = [int(i) for i in input().split()] n = a[0] g = a[1] b = input() s = "" for i, _ in enumerate(b): if i + g < n and (b[i + g] != b[i] or (b[i + g] == "." and b[i] == ".")): if b[i] == ".": if b[i + g] == ".": s += b[:i] ...
59
78
0
39172219
def solve(n,p,s): for i in range(n): if i + p < n: if s[i] != '.' and s[i+p] != '.' and s[i] != s[i+p] : return ''.join(s).replace('.','0') if s[i] == '.' and s[i+p] == '1': s[i] = '0' return ''.join(s).replace('.','0') if ...
Codeforces Round 487 (Div. 2)
CF
2,018
1
256
A Tide of Riverscape
The records are expressed as a string $$$s$$$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low). You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $$$...
The first line contains two space-separated integers $$$n$$$ and $$$p$$$ ($$$1 \leq p \leq n \leq 2000$$$) — the length of the given string and the supposed period, respectively. The second line contains a string $$$s$$$ of $$$n$$$ characters — Mino's records. $$$s$$$ only contains characters '0', '1' and '.', and con...
Output one line — if it's possible that $$$p$$$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
null
In the first example, $$$7$$$ is not a period of the resulting string because the $$$1$$$-st and $$$8$$$-th characters of it are different. In the second example, $$$6$$$ is not a period of the resulting string because the $$$4$$$-th and $$$10$$$-th characters of it are different. In the third example, $$$9$$$ is alw...
[{"input": "10 7\n1.0.1.0.1.", "output": "1000100010"}, {"input": "10 6\n1.0.1.1000", "output": "1001101000"}, {"input": "10 9\n1........1", "output": "No"}]
1,200
["constructive algorithms", "strings"]
59
[{"input": "10 7\r\n1.0.1.0.1.\r\n", "output": "1000100010\r\n"}, {"input": "10 6\r\n1.0.1.1000\r\n", "output": "1001101000\r\n"}, {"input": "10 9\r\n1........1\r\n", "output": "No\r\n"}, {"input": "1 1\r\n.\r\n", "output": "No\r\n"}, {"input": "5 1\r\n0...1\r\n", "output": "00001\r\n"}, {"input": "17 10\r\n..1.100..1....
false
stdio
import sys def main(): input_path = sys.argv[1] ref_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path, 'r') as f: n, p = map(int, f.readline().split()) s = f.readline().strip() with open(ref_path, 'r') as f: ref_output = f.read().strip() with open(sub_pat...
true
613/A
613
A
PyPy 3
TESTS
53
1,045
10,137,600
51771520
import math def Len (w): return w[0] * w[0] + w[1] * w[1] n, x, y = input().split(' ') n = int(n) x = int(x) y = int(y) arr = [] for i in range(0, n): a, b = input().split(' ') a = int(a) b = int(b) arr.append([a, b]) r1 = 100000000000 r2 = -10000000000 for i in range(0, n): st = [arr[(i ...
60
545
9,728,000
15425208
s = input().split() n = int(s[0]) px = int(s[1]) py = int(s[2]) y = [] x = [] for i in range(n): s=input().split() x.append(int(s[0]) - px) y.append(int(s[1]) - py) #print(x[i],y[i]) l = [] x0, y0 = x[-1], y[-1] for i in range(n): l.append(x[i]*x[i] + y[i]*y[i]) dx, dy = x[i] - x0, y[i] - y0 ...
Codeforces Round 339 (Div. 1)
CF
2,016
2
256
Peter and Snow Blower
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it...
The first line of the input contains three integers — the number of vertices of the polygon n ($$3 \leq n \leq 100\ 000$$), and coordinates of point P. Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three ...
Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $$\frac...
null
In the first sample snow will be removed from that area:
[{"input": "3 0 0\n0 1\n-1 2\n1 2", "output": "12.566370614359172464"}, {"input": "4 1 -1\n0 0\n1 2\n2 0\n1 1", "output": "21.991148575128551812"}]
1,900
["binary search", "geometry", "ternary search"]
60
[{"input": "3 0 0\r\n0 1\r\n-1 2\r\n1 2\r\n", "output": "12.566370614359172464\r\n"}, {"input": "4 1 -1\r\n0 0\r\n1 2\r\n2 0\r\n1 1\r\n", "output": "21.991148575128551812\r\n"}, {"input": "3 0 0\r\n-1 1\r\n0 3\r\n1 1\r\n", "output": "25.132741228718344928\r\n"}, {"input": "3 -4 2\r\n-3 2\r\n5 -5\r\n5 3\r\n", "output": ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: ref_line = f.readline().strip() try: b = float(ref_line) except: print(0) return with open(submission_path, 'r') as f: ...
true
435/C
435
C
Python 3
PRETESTS
0
46
0
6747439
n = int(input()) a = list(map(int, input().split())) arr = [[-1,0,0]] for i in range(n): if i % 2 == 0: arr.append([arr[-1][0] + 1, arr[-1][1], '/']) for k in range(a[i] - 1): arr.append([arr[-1][0] + 1, arr[-1][1] + 1, '/']) else: arr.append([arr[-1][0] + 1, arr[-1][1],...
46
77
8,908,800
133439945
n = int(input()) lis = list(map(int,input().split())) height = 0 max_height = 0 min_height = 0 width = 0 for i in range(n): width+=lis[i] if i %2 == 0: height+=lis[i] if height> max_height: max_height =height else: height-=lis[i] if height < min_height: ...
Codeforces Round 249 (Div. 2)
CF
2,014
1
256
Cardiogram
In this problem, your task is to use ASCII graphics to paint a cardiogram. A cardiogram is a polyline with the following corners: $$(0;0),(a_{1};a_{1}),(a_{1}+a_{2};a_{1}-a_{2}),(a_{1}+a_{2}+a_{3};a_{1}-a_{2}+a_{3}),\ldots,(\sum_{i=1}^{n}a_{i};\sum_{i=1}^{n}(-1)^{i+1}a_{i}).$$ That is, a cardiogram is fully defined ...
The first line contains integer n (2 ≤ n ≤ 1000). The next line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 1000). It is guaranteed that the sum of all ai doesn't exceed 1000.
Print max |yi - yj| lines (where yk is the y coordinate of the k-th point of the polyline), in each line print $$\sum_{i=1}^{n}a_{i}$$ characters. Each character must equal either « / » (slash), « \ » (backslash), « » (space). The printed image must be the image of the given polyline. Please study the test samples for ...
null
Due to the technical reasons the answers for the samples cannot be copied from the statement. We've attached two text documents with the answers below. http://assets.codeforces.com/rounds/435/1.txt http://assets.codeforces.com/rounds/435/2.txt
[{"input": "5\n3 1 2 5 1", "output": "/\n\\\n/\n\\\n/\n\\\n/\n\\\n/\n\\\n\\\n/"}, {"input": "3\n1 5 1", "output": "/\n\\\n\\\n\\\n\\\n\\\n/"}]
1,600
["implementation"]
46
[{"input": "5\r\n3 1 2 5 1\r\n", "output": " /\\ \r\n /\\/ \\ \r\n / \\ \r\n/ \\ \r\n \\/\r\n"}, {"input": "3\r\n1 5 1\r\n", "output": "/\\ \r\n \\ \r\n \\ \r\n \\ \r\n \\/\r\n"}, {"input": "2\r\n1 1\r\n", "output": "/\\\r\n"}, {"input": "2\r\n2 1\r\n", "output":...
false
stdio
null
true
771/A
771
A
Python 3
TESTS
56
982
46,182,400
203584424
a,b=map(int,input().split()) v=[0]*150005 s=[set([i])for i in range(150005)] for _ in ' '*b: n,m=map(int,input().split()) s[n].add(m) s[m].add(n) for i in range(b): if not v[i]: for j in s[i]: v[j]=1 if s[j]!=s[i]:print('NO');exit(0) print('YES')
96
327
169,267,200
167406376
from collections import deque #To start code import sys from collections import * sys.setrecursionlimit(10**5) itr = (line for line in sys.stdin.read().strip().split('\n')) INP = lambda: next(itr) def ni(): return int(INP()) def nl(): return [int(_) for _ in INP().split()] #G IS REASONABLE IF ALL DISTINCT PAIRS OF T...
VK Cup 2017 - Round 1
CF
2,017
1
256
Bear and Friendship Condition
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are n members, numbered 1 through n. m pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that membe...
The first line of the input contain two integers n and m (3 ≤ n ≤ 150 000, $$0 \leq m \leq min(150\ 000, \frac{n \cdot (n-1)}{2})$$) — the number of members and the number of pairs of members that are friends. The i-th of the next m lines contains two distinct integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi). Members ai a...
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
null
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
[{"input": "4 3\n1 3\n3 4\n1 4", "output": "YES"}, {"input": "4 4\n3 1\n2 3\n3 4\n1 2", "output": "NO"}, {"input": "10 4\n4 3\n5 10\n8 9\n1 2", "output": "YES"}, {"input": "3 2\n1 2\n2 3", "output": "NO"}]
1,500
["dfs and similar", "dsu", "graphs"]
96
[{"input": "4 3\r\n1 3\r\n3 4\r\n1 4\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n3 1\r\n2 3\r\n3 4\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "10 4\r\n4 3\r\n5 10\r\n8 9\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "3 0\r\n", "output": "YES\r\n"}, {"input": "15...
false
stdio
null
true
435/C
435
C
Python 3
TESTS
0
62
8,499,200
151394193
n=int(input()) a=[*map(int, input().split())] o=1001 x,y,v=0,o,o w=y l=[[" "]*o for i in range(2*o)] for i in range(n): v+=((-1)**i)*a[i] u=a[i] while u: x+=1 if v>y: l[w][x]="/" w-=1 else: w+=1 l[w][x]=chr(92) u-=1 y=v for ...
46
78
102,400
6747973
n = int(input()) a = list(map(int, input().split())) x = sum(a) arr = [[-1,0,0]] for i in range(n): if i % 2 == 0: arr.append([arr[-1][0] + 1, arr[-1][1], '/']) for k in range(a[i] - 1): arr.append([arr[-1][0] + 1, arr[-1][1] + 1, '/']) else: arr.append([arr[-1][0] + 1, ...
Codeforces Round 249 (Div. 2)
CF
2,014
1
256
Cardiogram
In this problem, your task is to use ASCII graphics to paint a cardiogram. A cardiogram is a polyline with the following corners: $$(0;0),(a_{1};a_{1}),(a_{1}+a_{2};a_{1}-a_{2}),(a_{1}+a_{2}+a_{3};a_{1}-a_{2}+a_{3}),\ldots,(\sum_{i=1}^{n}a_{i};\sum_{i=1}^{n}(-1)^{i+1}a_{i}).$$ That is, a cardiogram is fully defined ...
The first line contains integer n (2 ≤ n ≤ 1000). The next line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 1000). It is guaranteed that the sum of all ai doesn't exceed 1000.
Print max |yi - yj| lines (where yk is the y coordinate of the k-th point of the polyline), in each line print $$\sum_{i=1}^{n}a_{i}$$ characters. Each character must equal either « / » (slash), « \ » (backslash), « » (space). The printed image must be the image of the given polyline. Please study the test samples for ...
null
Due to the technical reasons the answers for the samples cannot be copied from the statement. We've attached two text documents with the answers below. http://assets.codeforces.com/rounds/435/1.txt http://assets.codeforces.com/rounds/435/2.txt
[{"input": "5\n3 1 2 5 1", "output": "/\n\\\n/\n\\\n/\n\\\n/\n\\\n/\n\\\n\\\n/"}, {"input": "3\n1 5 1", "output": "/\n\\\n\\\n\\\n\\\n\\\n/"}]
1,600
["implementation"]
46
[{"input": "5\r\n3 1 2 5 1\r\n", "output": " /\\ \r\n /\\/ \\ \r\n / \\ \r\n/ \\ \r\n \\/\r\n"}, {"input": "3\r\n1 5 1\r\n", "output": "/\\ \r\n \\ \r\n \\ \r\n \\ \r\n \\/\r\n"}, {"input": "2\r\n1 1\r\n", "output": "/\\\r\n"}, {"input": "2\r\n2 1\r\n", "output":...
false
stdio
null
true
220/A
220
A
PyPy 3
TESTS
32
248
11,366,400
57111840
n = int(input()) a = list(map(int,input().split())) first = -1 second = -1 i = 0 while (i<n-1) : if (a[i]<=a[i+1]): i += 1 else: if (first!=-1 and second!=-1) : break elif (first==-1) : first = i i += 1 else: second = i ...
96
93
12,902,400
132788722
n = int(input()) arr = list(map(int,input().split())) sorted_arr = sorted(arr) swap = 0 for i in range(n): if swap > 2: break if arr[i] != sorted_arr[i]: swap += 1 print("NO" if swap > 2 else "YES")
Codeforces Round 136 (Div. 1)
CF
2,012
2
256
Little Elephant and Problem
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could ...
The first line contains a single integer n (2 ≤ n ≤ 105) — the size of array a. The next line contains n positive integers, separated by single spaces and not exceeding 109, — array a. Note that the elements of the array are not necessarily distinct numbers.
In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.
null
In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES". In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES". In the third sample we ...
[{"input": "2\n1 2", "output": "YES"}, {"input": "3\n3 2 1", "output": "YES"}, {"input": "4\n4 3 2 1", "output": "NO"}]
1,300
["implementation", "sortings"]
96
[{"input": "2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "9\r\n7 7 8 8 10 10 10 10 1000000000\r\n", "output": "YES\r\n"...
false
stdio
null
true
771/A
771
A
PyPy 3
TESTS
61
483
12,800,000
61300678
from sys import * def find(u, roots): while roots[u] != u: roots[u] = roots[roots[u]] u = roots[u] return u def union(u, v, roots, ranks): uroot = find(u, roots) vroot = find(v, roots) if uroot != vroot: if ranks[uroot] > ranks[vroot]: roots[vroot] = r...
96
358
48,947,200
196725840
import sys input=sys.stdin.readline from collections import defaultdict g=defaultdict(list) n,m=map(int,input().split()) ind=[0]*(n+1) for _ in range(m): a,b=map(int,input().split()) g[a].append(b) g[b].append(a) ind[a]+=1 ind[b]+=1 visited=set() def dfs(src): nodes,st=[],[src] visited.add(...
VK Cup 2017 - Round 1
CF
2,017
1
256
Bear and Friendship Condition
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are n members, numbered 1 through n. m pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that membe...
The first line of the input contain two integers n and m (3 ≤ n ≤ 150 000, $$0 \leq m \leq min(150\ 000, \frac{n \cdot (n-1)}{2})$$) — the number of members and the number of pairs of members that are friends. The i-th of the next m lines contains two distinct integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi). Members ai a...
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
null
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
[{"input": "4 3\n1 3\n3 4\n1 4", "output": "YES"}, {"input": "4 4\n3 1\n2 3\n3 4\n1 2", "output": "NO"}, {"input": "10 4\n4 3\n5 10\n8 9\n1 2", "output": "YES"}, {"input": "3 2\n1 2\n2 3", "output": "NO"}]
1,500
["dfs and similar", "dsu", "graphs"]
96
[{"input": "4 3\r\n1 3\r\n3 4\r\n1 4\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n3 1\r\n2 3\r\n3 4\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "10 4\r\n4 3\r\n5 10\r\n8 9\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "3 0\r\n", "output": "YES\r\n"}, {"input": "15...
false
stdio
null
true
435/C
435
C
PyPy 3-64
TESTS
0
31
0
210968553
import sys input = lambda: sys.stdin.readline().rstrip() N = int(input()) A = list(map(int, input().split())) M = sum(A) ans = [0]*M cur = 0 idx = 0 for i,a in enumerate(A): if i%2==0: for j in range(a): cur+=1 ans[idx]=(cur,'/') idx+=1 else: for j in range(a...
46
93
4,505,600
6746807
n = int(input()) a = [int(i) for i in input().split()] miny = 0 maxy = 0 s = 0 for i in range(n): if i % 2 == 0: s += a[i] else: s -= a[i] maxy = max(s, maxy) miny = min(s, miny) dif = maxy - miny size = sum(a) res = [[" "] * size for i in range(dif)] cur = [maxy, 0] for i in range(n): ...
Codeforces Round 249 (Div. 2)
CF
2,014
1
256
Cardiogram
In this problem, your task is to use ASCII graphics to paint a cardiogram. A cardiogram is a polyline with the following corners: $$(0;0),(a_{1};a_{1}),(a_{1}+a_{2};a_{1}-a_{2}),(a_{1}+a_{2}+a_{3};a_{1}-a_{2}+a_{3}),\ldots,(\sum_{i=1}^{n}a_{i};\sum_{i=1}^{n}(-1)^{i+1}a_{i}).$$ That is, a cardiogram is fully defined ...
The first line contains integer n (2 ≤ n ≤ 1000). The next line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 1000). It is guaranteed that the sum of all ai doesn't exceed 1000.
Print max |yi - yj| lines (where yk is the y coordinate of the k-th point of the polyline), in each line print $$\sum_{i=1}^{n}a_{i}$$ characters. Each character must equal either « / » (slash), « \ » (backslash), « » (space). The printed image must be the image of the given polyline. Please study the test samples for ...
null
Due to the technical reasons the answers for the samples cannot be copied from the statement. We've attached two text documents with the answers below. http://assets.codeforces.com/rounds/435/1.txt http://assets.codeforces.com/rounds/435/2.txt
[{"input": "5\n3 1 2 5 1", "output": "/\n\\\n/\n\\\n/\n\\\n/\n\\\n/\n\\\n\\\n/"}, {"input": "3\n1 5 1", "output": "/\n\\\n\\\n\\\n\\\n\\\n/"}]
1,600
["implementation"]
46
[{"input": "5\r\n3 1 2 5 1\r\n", "output": " /\\ \r\n /\\/ \\ \r\n / \\ \r\n/ \\ \r\n \\/\r\n"}, {"input": "3\r\n1 5 1\r\n", "output": "/\\ \r\n \\ \r\n \\ \r\n \\ \r\n \\/\r\n"}, {"input": "2\r\n1 1\r\n", "output": "/\\\r\n"}, {"input": "2\r\n2 1\r\n", "output":...
false
stdio
null
true
581/C
581
C
Python 3
TESTS
5
46
307,200
228992351
import math from collections import defaultdict d=defaultdict(lambda:0) def sort_by_units_digit(lst): return sorted(lst, key=lambda x: str(x)[-1]) n,k = map(int,input().split()) kk=[k].copy()[0] x = sort_by_units_digit(list(map(int,input().split()))) ans=0 for i in range(n): if x[n-i-1]<100 and k-(10-x[n-i-...
98
124
9,113,600
197756133
I=lambda:map(int,input().split()) n,k=I() r=0 a=[] for i in I(): r+=i//10 a+=[i%10] for i in sorted(a,reverse=1): if i+k>9: k=k-10+i r+=1 print(min(n*10,r+k//10))
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
435/C
435
C
Python 3
TESTS
0
93
0
49683913
import sys from math import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) n = mint() y = 0 x = 0 a = [] t = 0 mx = dict() my = 10**9 for i in mints(): for j in range(i): if t == 0: a.append((x,y,'/')) mx[y] = max(mx.get(y, -...
46
93
5,632,000
6747895
import operator n = int(input()) a = tuple(map(int, str.split(input()))) p = [(0, 0)] for i, x in enumerate(a): p.append((p[-1][0] + x, p[-1][1] + (-1) ** i * x)) ymax = max(p, key=operator.itemgetter(1))[1] ymin = min(p, key=operator.itemgetter(1))[1] columns = [] for i in range(n): x1, y1 = p[i] x2...
Codeforces Round 249 (Div. 2)
CF
2,014
1
256
Cardiogram
In this problem, your task is to use ASCII graphics to paint a cardiogram. A cardiogram is a polyline with the following corners: $$(0;0),(a_{1};a_{1}),(a_{1}+a_{2};a_{1}-a_{2}),(a_{1}+a_{2}+a_{3};a_{1}-a_{2}+a_{3}),\ldots,(\sum_{i=1}^{n}a_{i};\sum_{i=1}^{n}(-1)^{i+1}a_{i}).$$ That is, a cardiogram is fully defined ...
The first line contains integer n (2 ≤ n ≤ 1000). The next line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 1000). It is guaranteed that the sum of all ai doesn't exceed 1000.
Print max |yi - yj| lines (where yk is the y coordinate of the k-th point of the polyline), in each line print $$\sum_{i=1}^{n}a_{i}$$ characters. Each character must equal either « / » (slash), « \ » (backslash), « » (space). The printed image must be the image of the given polyline. Please study the test samples for ...
null
Due to the technical reasons the answers for the samples cannot be copied from the statement. We've attached two text documents with the answers below. http://assets.codeforces.com/rounds/435/1.txt http://assets.codeforces.com/rounds/435/2.txt
[{"input": "5\n3 1 2 5 1", "output": "/\n\\\n/\n\\\n/\n\\\n/\n\\\n/\n\\\n\\\n/"}, {"input": "3\n1 5 1", "output": "/\n\\\n\\\n\\\n\\\n\\\n/"}]
1,600
["implementation"]
46
[{"input": "5\r\n3 1 2 5 1\r\n", "output": " /\\ \r\n /\\/ \\ \r\n / \\ \r\n/ \\ \r\n \\/\r\n"}, {"input": "3\r\n1 5 1\r\n", "output": "/\\ \r\n \\ \r\n \\ \r\n \\ \r\n \\/\r\n"}, {"input": "2\r\n1 1\r\n", "output": "/\\\r\n"}, {"input": "2\r\n2 1\r\n", "output":...
false
stdio
null
true
493/B
493
B
Python 3
TESTS
50
421
5,017,600
118224502
from operator import le n=int(input()) first=[] second=[] y=int(0) while n : y=int(input()) if y > 0 : first.append(y) if y < 0 : second.append(abs(y)) n-=1 tot_1=sum(first) tot_2=sum(second) if tot_1==tot_2 : min_len=min(len(first),len(second)) ans=0 for i in range(0,min_...
57
108
12,185,600
231980691
import sys input=sys.stdin.readline import math import bisect n=int(input()) l=[] h=[] c=0 for j in range(n): k=int(input()) if k>0: l.append(k) else: h.append(-1*k) if j==n-1: c=k a=sum(l) b=sum(h) if(a>b): print("first") elif(a<b): print("second") else: flag=True ...
Codeforces Round 281 (Div. 2)
CF
2,014
2
256
Vasya and Wrestling
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105). The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that mea...
If the first wrestler wins, print string "first", otherwise print "second"
null
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. We use notation |a| to denote lengt...
[{"input": "5\n1\n2\n-3\n-4\n3", "output": "second"}, {"input": "3\n-1\n-2\n3", "output": "first"}, {"input": "2\n4\n-4", "output": "second"}]
1,400
["implementation"]
57
[{"input": "5\r\n1\r\n2\r\n-3\r\n-4\r\n3\r\n", "output": "second\r\n"}, {"input": "3\r\n-1\r\n-2\r\n3\r\n", "output": "first\r\n"}, {"input": "2\r\n4\r\n-4\r\n", "output": "second\r\n"}, {"input": "7\r\n1\r\n2\r\n-3\r\n4\r\n5\r\n-6\r\n7\r\n", "output": "first\r\n"}, {"input": "14\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n-...
false
stdio
null
true
699/A
699
A
Python 3
TESTS
11
343
16,588,800
163945313
from sys import stdin position = 0 differences = [] particles = stdin.readline().strip() moves = list(stdin.readline().strip()) nums = [int(x) for x in stdin.readline().strip().split(" ")] while position < len(moves) - 1: if moves[position] == 'R' and moves[position + 1] == 'L': differences.append(int(num...
85
108
20,992,000
165922924
import math def solve(directions, coordinates): result = math.inf for i in range(1, len(directions)): if directions[i-1:i+1] == "RL": result = min(result, (coordinates[i] - coordinates[i - 1]) // 2) return result if result < math.inf else -1 def main(): _ = input() directions...
Codeforces Round 363 (Div. 2)
CF
2,016
2
256
Launch of Collider
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dista...
The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles. The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right. The third line con...
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen.
null
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
[{"input": "4\nRLRL\n2 4 6 10", "output": "1"}, {"input": "3\nLLR\n40 50 60", "output": "-1"}]
1,000
["implementation"]
85
[{"input": "4\r\nRLRL\r\n2 4 6 10\r\n", "output": "1\r\n"}, {"input": "3\r\nLLR\r\n40 50 60\r\n", "output": "-1\r\n"}, {"input": "4\r\nRLLR\r\n46 230 264 470\r\n", "output": "92\r\n"}, {"input": "6\r\nLLRLLL\r\n446 492 650 844 930 970\r\n", "output": "97\r\n"}, {"input": "8\r\nRRLLLLLL\r\n338 478 512 574 594 622 834 92...
false
stdio
null
true
581/C
581
C
PyPy 3-64
TESTS
4
62
0
199753260
import sys import math import collections import heapq input=sys.stdin.readline n,k=(int(i) for i in input().split()) l=[int(i) for i in input().split()] s=0 for i in range(n): s+=l[i]//10 for i in range(n): l[i]=10-(l[i]%10) l.sort() for i in range(n): if(l[i]<=k): k-=l[i] l[i]=10 s...
98
124
13,312,000
202310038
n,k=map(int,input().split()) x=list(map(int,input().split())) dic={} sum1=0 for i in x: sum1+=i//10 f=10-i%10 if f!=10 and f not in dic: dic[f]=1 elif f!=10: dic[f]+=1 d=sorted(dic) for i in d: if k<i: break t=min(k//i,dic[i]) k-=t*i sum1+=t if k>10: sum1+=k//...
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
416/D
416
D
Python 3
TESTS
20
389
18,227,200
6347071
n=int(input()) A=list(map(int,input().split())) P=[] for i in range(n): if(A[i]!=-1): P.append((A[i],i)) if(len(P)==0 or len(P)==1): print(1) else: p=10**10 d=10**10 start=0 for i in range(n): if(A[i]==-1): if(d==10**10): continue else:...
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
225/A
225
A
Python 3
TESTS
17
186
0
38428669
n = int(input()) top = int(input()) top = 7 - top for z in range(n): l, r = map(int, input().split()) l1, r1 = 7-l, 7-r if top not in [l,r,l1,r1]: flag = True continue else: flag = False top = ({1,2,3,4,5,6} - {l,r,l1,r1}).pop() if flag == False: print("NO") else: ...
52
78
102,400
3691792
class Task: top = 0 cubes = [] answer = "" def getData(self): number_of_cubes = int(input()) self.top = int(input()); self.cubes = [[int(x) for x in input().split()] for i in range(number_of_cubes)] def solve(self): for current in self.cubes: if current[0] == self.top or 7 - current[0] == self.t...
Codeforces Round 139 (Div. 2)
CF
2,012
2
256
Dice Tower
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left). Alice...
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of dice in the tower. The second line contains an integer x (1 ≤ x ≤ 6) — the number Bob sees at the top of the tower. Next n lines contain two space-separated integers each: the i-th line contains numbers ai, bi (1 ≤ ai, bi ≤ 6; ai ≠ bi) — the numb...
Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes).
null
null
[{"input": "3\n6\n3 2\n5 4\n2 4", "output": "YES"}, {"input": "3\n3\n2 6\n4 1\n5 3", "output": "NO"}]
1,100
["constructive algorithms", "greedy"]
52
[{"input": "3\r\n6\r\n3 2\r\n5 4\r\n2 4\r\n", "output": "YES"}, {"input": "3\r\n3\r\n2 6\r\n4 1\r\n5 3\r\n", "output": "NO"}, {"input": "1\r\n3\r\n2 1\r\n", "output": "YES"}, {"input": "2\r\n2\r\n3 1\r\n1 5\r\n", "output": "NO"}, {"input": "3\r\n2\r\n1 4\r\n5 3\r\n6 4\r\n", "output": "NO"}, {"input": "4\r\n3\r\n5 6\r\n...
false
stdio
null
true
976/E
976
E
Python 3
TESTS
9
826
24,780,800
37770583
#!/usr/bin/env python3 [n, a, b] = map(int, input().strip().split()) hds = [tuple(map(int, input().strip().split())) for _ in range(n)] dam = sum(d for h, d in hds) if a > 0: va = 2**a dd, idd = max((max(va * h - d, 0), i) for i, (h, d) in enumerate(hds)) if dd > 0: hds[idd] = (hds[idd][0] * va, hds[idd][1]) i...
71
514
17,612,800
163169806
from sys import stdin,exit #parsea una línea def parser(): return map(int, stdin.readline().split()) #recibiendo los valores de n, a y b n,a,b=parser() b=min(b,n) #inicializando las listas de vida y daño hp=[] dmg=[] #recibiendo los parametros de las criaturas for creature in range(n): h,d=parser() hp.ap...
Educational Codeforces Round 43 (Rated for Div. 2)
ICPC
2,018
1
256
Well played!
Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them: Max owns n creatures, i-th of them can be described with two numbers — its health hpi and its damage dmgi. Max also has two types ...
The first line contains three integers n, a, b (1 ≤ n ≤ 2·105, 0 ≤ a ≤ 20, 0 ≤ b ≤ 2·105) — the number of creatures, spells of the first type and spells of the second type, respectively. The i-th of the next n lines contain two number hpi and dmgi (1 ≤ hpi, dmgi ≤ 109) — description of the i-th creature.
Print single integer — maximum total damage creatures can deal.
null
In the first example Max should use the spell of the first type on the second creature, then the spell of the second type on the same creature. Then total damage will be equal to 15 + 6·2 = 27. In the second example Max should use the spell of the second type on the first creature, then the spell of the second type on...
[{"input": "2 1 1\n10 15\n6 1", "output": "27"}, {"input": "3 0 3\n10 8\n7 11\n5 2", "output": "26"}]
2,100
["greedy", "sortings"]
71
[{"input": "2 1 1\r\n10 15\r\n6 1\r\n", "output": "27\r\n"}, {"input": "3 0 3\r\n10 8\r\n7 11\r\n5 2\r\n", "output": "26\r\n"}, {"input": "1 0 0\r\n2 1\r\n", "output": "1\r\n"}, {"input": "1 0 200000\r\n1 2\r\n", "output": "2\r\n"}, {"input": "7 5 7\r\n29 25\r\n84 28\r\n34 34\r\n14 76\r\n85 9\r\n40 57\r\n99 88\r\n", "o...
false
stdio
null
true
733/C
733
C
Python 3
TESTS
10
77
0
120845385
def check(a,cr): seq=[] t=set() for i in a: t.add(i[0]) if len(a)>1 and len(t)==1: print("NO") exit(0) mx=max(a,key=lambda s:s[0]) if a.index(mx)==0 and len(a)>=2: if a[a.index(mx)+1][0]==mx[0]: mx=max(a[::-1],key=lambda s:s[0]) delta=0 for i in range(a.index(mx)): seq.append((mx[1]+1-delta-cr,"L")...
138
78
409,600
21938883
n = int(input()) fr = list(map(int, input().split())) k = int(input()) to = list(map(int, input().split())) def process(l, off): #print(l, end=": ") #print(off) res = [] m = max(l) mi = l.index(m) if mi == 0 and all(map(lambda x: x == m, l)): return res if not mi: for i in range(1, len(l)): ...
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
382/C
382
C
Python 3
TESTS
21
93
307,200
85883729
n = int(input()) if n == 1: print(-1) exit(0) b = [*map(int, input().split())] if n == 298: print(*b[160:170]) print(*b[253:]) exit(0) a = sorted(b) l = set() if n == 2 and (a[1] - a[0]) != 0 and (a[1] - a[0]) % 2 == 0: print(3) print(a[0] - (a[1] - a[0]), a[0] + (a[1] - a[0]) // 2, a[-1] +...
59
108
17,817,600
172140464
n=int(input()) arr=list(map(int,input().split())) arr.sort() if n==1: print(-1) elif n==2: if (arr[1]-arr[0])%2==0: d=arr[1]-arr[0] res=[arr[0]-d,arr[0]+d//2,arr[1]+d] res=set(res) res=sorted(res) print(len(res)) print(*res) else : d=arr[1]-arr[0] ...
Codeforces Round 224 (Div. 2)
CF
2,014
1
256
Arithmetic Progression
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1. For example, sequences [1, 5], [10], [5,...
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples)...
null
null
[{"input": "3\n4 1 7", "output": "2\n-2 10"}, {"input": "1\n10", "output": "-1"}, {"input": "4\n1 3 5 9", "output": "1\n7"}, {"input": "4\n4 3 4 5", "output": "0"}, {"input": "2\n2 4", "output": "3\n0 3 6"}]
1,700
["implementation", "sortings"]
59
[{"input": "3\r\n4 1 7\r\n", "output": "2\r\n-2 10\r\n"}, {"input": "1\r\n10\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 3 5 9\r\n", "output": "1\r\n7\r\n"}, {"input": "4\r\n4 3 4 5\r\n", "output": "0\r\n"}, {"input": "2\r\n2 4\r\n", "output": "3\r\n0 3 6\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "1\r\n2\r\n"}, {...
false
stdio
null
true
837/C
837
C
PyPy 3-64
TESTS
12
62
0
197397773
n,a1,b1=map(int,input().split()) a=[] for i in range(n): x,y=list(map(int,input().split())) a.append([x,y]) ans=0 for i in range(n): for j in range(i+1,n): x1,y1=a[i][0],a[i][1] x2,y2=a[j][0],a[j][1] if(y1<=b1 and x1+x2<=a1 and y2<=b1): ans=max(ans,x1*y1+x2*y2) if...
51
62
0
165921599
n,a,b=map(int,input().split()) l=[] for _ in range(n): x,y=map(int,input().split()) l+=[(x,y)] def checker(x1,y1,x2,y2): if (x1+x2<=a and max(y1,y2)<=b) or (y1+y2<=b and max(x1,x2)<=a): return x1*y1+x2*y2 return 0 ans=0 for i in range(n): for j in range(n): if i!=j: x,y=l...
Educational Codeforces Round 26
ICPC
2,017
1
256
Two Seals
One very important person has a piece of paper in the form of a rectangle a × b. Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees). A very importa...
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100). Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
null
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper. In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the large...
[{"input": "2 2 2\n1 2\n2 1", "output": "4"}, {"input": "4 10 9\n2 3\n1 1\n5 10\n9 11", "output": "56"}, {"input": "3 10 10\n6 6\n7 7\n20 5", "output": "0"}]
1,500
["brute force", "implementation"]
51
[{"input": "2 2 2\r\n1 2\r\n2 1\r\n", "output": "4\r\n"}, {"input": "4 10 9\r\n2 3\r\n1 1\r\n5 10\r\n9 11\r\n", "output": "56\r\n"}, {"input": "3 10 10\r\n6 6\r\n7 7\r\n20 5\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n1 1\r\n1 1\r\n", "output": "2\r\n"}, {"inpu...
false
stdio
null
true
446/A
446
A
PyPy 3
TESTS
26
234
11,673,600
110970355
import math,sys,bisect,heapq,os from collections import defaultdict,Counter,deque from itertools import groupby,accumulate from functools import lru_cache #sys.setrecursionlimit(200000000) int1 = lambda x: int(x) - 1 def input(): return sys.stdin.readline().rstrip('\r\n') #input = iter(sys.stdin.buffer.read().decode()....
92
187
19,251,200
159207888
n = int(input()) a = list(map(int, input().split())) l, r = [1] * n, [1] * n for i in range(1, n): if(a[i] > a[i - 1]): l[i] = l[i - 1] + 1 for i in range(n - 2, -1, -1): if(a[i] < a[i + 1]): r[i] = r[i + 1] + 1 m = max(l) + 1 if max(l) < n else max(l) for i in range(1, n - 1): if(a[i - 1] ...
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
725/A
725
A
Python 3
TESTS
8
264
409,600
21676570
n = int(input()) s = input() right = False right_c = 0 if s[0] == '>': right = True right_c = 1 i = 1 c = 1 ans = 1 peres = False while i < len(s): if s[i] == '<' and right: right = False peres = True ans -= right_c c = 0 elif s[i] == '<' and peres: pass ...
78
46
512,000
165684588
num_inp=lambda: int(input()) arr_inp=lambda: list(map(int,input().split())) sp_inp=lambda: map(int,input().split()) n=int(input()) s=input() s=s.lstrip('<') s=s.rstrip('>') print(n-len(s))
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
618/C
618
C
Python 3
TESTS
14
701
11,366,400
15660356
def getd(x1, y1, x2, y2): return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 def online(x1, y1, x2, y2, x3, y3): d1 = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 d2 = ((x1 - x3) ** 2 + (y1 - y3) ** 2) ** 0.5 d3 = ((x3 - x2) ** 2 + (y3 - y2) ** 2) ** 0.5 if (d1 + d2 - d3 < eps or d2 + d3 - d1 < eps or d1 ...
98
545
22,732,800
18017525
from sys import * inp = lambda : stdin.readline() def dist(x,y,x1,y1): return (x1-x)**2 + (y1-y)**2 def main(): n = int(inp()) l = [] d = {} for i in range(n): tt = tuple(map(int,inp().split())) d[tt] = i+1 l.append(tt) x1,y1 = l[0] l = sorted(l,key= lambda x: dist...
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
493/B
493
B
PyPy 3
TESTS
50
1,481
30,617,600
86156465
n=int(input()) i1,i2=0,0 l1=[0]*n l2=[0]*n for i in range(n): a=int(input()) if(a<0): l2[i2]=abs(a) i2=i2+1 else: l1[i1]=a i1=i1+1 #print(l1,l2) s1=sum(l1) s2=sum(l2) #print(s1,s2) if(s1>s2): print("first")...
57
109
9,830,400
165818399
import sys input = sys.stdin.readline n = int(input()) a, b, c, c1, c2 = 0, 0, -1, [], [] for i in range(n): x = int(input()) if x > 0: a += x c1.append(x) else: b -= x c2.append(-x) if i == n-1: if x > 0: c = 0 else: c = 1 if a >...
Codeforces Round 281 (Div. 2)
CF
2,014
2
256
Vasya and Wrestling
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105). The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that mea...
If the first wrestler wins, print string "first", otherwise print "second"
null
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. We use notation |a| to denote lengt...
[{"input": "5\n1\n2\n-3\n-4\n3", "output": "second"}, {"input": "3\n-1\n-2\n3", "output": "first"}, {"input": "2\n4\n-4", "output": "second"}]
1,400
["implementation"]
57
[{"input": "5\r\n1\r\n2\r\n-3\r\n-4\r\n3\r\n", "output": "second\r\n"}, {"input": "3\r\n-1\r\n-2\r\n3\r\n", "output": "first\r\n"}, {"input": "2\r\n4\r\n-4\r\n", "output": "second\r\n"}, {"input": "7\r\n1\r\n2\r\n-3\r\n4\r\n5\r\n-6\r\n7\r\n", "output": "first\r\n"}, {"input": "14\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n-...
false
stdio
null
true
493/B
493
B
Python 3
TESTS
50
436
7,782,400
63630055
n= int(input()) lpos=[] lneg=[] l=[] a=0 b=0 for i in range(n): x=int(input()) if x>0: a+=x lpos.append(x) else: b+= abs(x) lneg.append(x) l.append(x) if a>b: print('first') elif b>a: print('second') else: for i in range(min(len(lpos), len(lneg))): ...
57
109
10,547,200
186480064
from sys import stdin def solve(n): sum_first = 0 sum_second = 0 moves_first = [] moves_second = [] last_move = False great = -1 for i in range(n-1): temp = int(stdin.readline()) if temp < 0: sum_second += abs(temp) moves_second.append(abs(temp)) ...
Codeforces Round 281 (Div. 2)
CF
2,014
2
256
Vasya and Wrestling
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105). The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that mea...
If the first wrestler wins, print string "first", otherwise print "second"
null
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. We use notation |a| to denote lengt...
[{"input": "5\n1\n2\n-3\n-4\n3", "output": "second"}, {"input": "3\n-1\n-2\n3", "output": "first"}, {"input": "2\n4\n-4", "output": "second"}]
1,400
["implementation"]
57
[{"input": "5\r\n1\r\n2\r\n-3\r\n-4\r\n3\r\n", "output": "second\r\n"}, {"input": "3\r\n-1\r\n-2\r\n3\r\n", "output": "first\r\n"}, {"input": "2\r\n4\r\n-4\r\n", "output": "second\r\n"}, {"input": "7\r\n1\r\n2\r\n-3\r\n4\r\n5\r\n-6\r\n7\r\n", "output": "first\r\n"}, {"input": "14\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n-...
false
stdio
null
true
493/B
493
B
Python 3
TESTS
50
327
6,451,200
148521206
A=[] B=[] x=int(input()) for t in range(x): n=int(input()) if(n>0): A.append(n) else: B.append(n*-1) if(t==(x-1)): if(n>0): str="first" else: str="second" a=len(A) b=len(B) x=sum(A) y=sum(B) if(x>y): print("first") elif(x<y): print("second"...
57
109
10,547,200
198982598
from collections import Counter import math import sys input = sys.stdin.readline mod = int(1e9 + 7) def solve(): n = int(input()) x = [] y = [] lastV = int(1e9)+1 for i in range(n): v = int(input()) if v > 0: x.append(v) else: y.append(-v) ...
Codeforces Round 281 (Div. 2)
CF
2,014
2
256
Vasya and Wrestling
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105). The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that mea...
If the first wrestler wins, print string "first", otherwise print "second"
null
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. We use notation |a| to denote lengt...
[{"input": "5\n1\n2\n-3\n-4\n3", "output": "second"}, {"input": "3\n-1\n-2\n3", "output": "first"}, {"input": "2\n4\n-4", "output": "second"}]
1,400
["implementation"]
57
[{"input": "5\r\n1\r\n2\r\n-3\r\n-4\r\n3\r\n", "output": "second\r\n"}, {"input": "3\r\n-1\r\n-2\r\n3\r\n", "output": "first\r\n"}, {"input": "2\r\n4\r\n-4\r\n", "output": "second\r\n"}, {"input": "7\r\n1\r\n2\r\n-3\r\n4\r\n5\r\n-6\r\n7\r\n", "output": "first\r\n"}, {"input": "14\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n-...
false
stdio
null
true
493/B
493
B
PyPy 3
TESTS
48
1,482
9,932,800
66195047
n=int(input()) l1=[] l2=[] s1=0 s2=0 for i in range(n): a=int(input()) if a>0: l1.append(a) s1+=a else: l2.append(abs(a)) s2+=abs(a) if s1>s2: print("first") elif s1>s2: print("second") else: leng1=len(l1) leng2=len(l2) leng=min(leng1,leng2) k=-1 i...
57
124
9,932,800
207305469
import sys def main() -> None: read = sys.stdin.readline n = int(read()) first_secore = 0 second_scored = 0 elts_first = [] elts_second = [] last_matching_index = -1 last_move = None for _ in range(n): val = int(read()) if val > 0: first_secore += val ...
Codeforces Round 281 (Div. 2)
CF
2,014
2
256
Vasya and Wrestling
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105). The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that mea...
If the first wrestler wins, print string "first", otherwise print "second"
null
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. We use notation |a| to denote lengt...
[{"input": "5\n1\n2\n-3\n-4\n3", "output": "second"}, {"input": "3\n-1\n-2\n3", "output": "first"}, {"input": "2\n4\n-4", "output": "second"}]
1,400
["implementation"]
57
[{"input": "5\r\n1\r\n2\r\n-3\r\n-4\r\n3\r\n", "output": "second\r\n"}, {"input": "3\r\n-1\r\n-2\r\n3\r\n", "output": "first\r\n"}, {"input": "2\r\n4\r\n-4\r\n", "output": "second\r\n"}, {"input": "7\r\n1\r\n2\r\n-3\r\n4\r\n5\r\n-6\r\n7\r\n", "output": "first\r\n"}, {"input": "14\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n-...
false
stdio
null
true
33/C
33
C
PyPy 3
TESTS
15
218
31,744,000
126936067
def process(A): n = len(A) answer = max(sum(A), -1*sum(A)) prefixes = [0] for i in range(n): prefixes.append(prefixes[-1]+A[i]) suffixes = [0] for i in range(n): suffixes.append(suffixes[-1]+A[n-1-i]) m1 = [0, -1] for i in range(n): m1 = min(m1, [prefixes[i+1], i]...
89
186
16,691,200
214532101
N = int(input()) sequence = [int(d) for d in input().split()] SUM = [] SUM.append(0) for i in range(N): running = SUM[i] + sequence[i] SUM.append(running) LEFT = [] LEFT.append(0) for i in range(N): running = LEFT[i] - sequence[i] LEFT.append(running) RIGHT = [] RIGHT.append(-SUM[-1]) for i in...
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
Wonderful Randomized Sum
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th...
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
The first and the only line of the output should contain the answer to the problem.
null
null
[{"input": "3\n-1 -2 -3", "output": "6"}, {"input": "5\n-4 2 0 5 0", "output": "11"}, {"input": "5\n-1 10 -5 10 -2", "output": "18"}]
1,800
["greedy"]
89
[{"input": "3\r\n-1 -2 -3\r\n", "output": "6\r\n"}, {"input": "5\r\n-4 2 0 5 0\r\n", "output": "11\r\n"}, {"input": "5\r\n-1 10 -5 10 -2\r\n", "output": "18\r\n"}, {"input": "1\r\n-3\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 -5 -2\r\n", "output": "12\r\n"}, {"input": "7\r\n-17 6 5 0 1 4 -1\r\n", "output": "34\r\n"}...
false
stdio
null
true
740/B
740
B
Python 3
TESTS
28
62
0
22446560
n, m = map(int, input().split()) a = list(map(int, input().split())) ans = 0 for i in range(m): li, ri = map(int, input().split()) tmp = sum(a[li - 1: ri]) if tmp > 0: ans += tmp ans = max(ans, sum(a)) # 全部選択したときの考慮 print(ans)
53
46
0
137146647
n,m = map(int,input().split()) l = list(map(int,input().split())) ans = 0 for i in range(m): s,e = map(int,input().split()) val = 0 for j in range(s-1,e): val+=l[j] ans = max(ans+val,ans) print(ans)
Codeforces Round 381 (Div. 2)
CF
2,016
2
256
Alyona and flowers
Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is ai. The mood can be positive, zero or negative. Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose severa...
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of flowers and the number of subarrays suggested by the mother. The second line contains the flowers moods — n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100). The next m lines contain the description of the subarrays suggested by the mother. The...
Print single integer — the maximum possible value added to the Alyona's happiness.
null
The first example is the situation described in the statements. In the second example Alyona should choose all subarrays. The third example has answer 0 because Alyona can choose none of the subarrays.
[{"input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4", "output": "7"}, {"input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1", "output": "16"}, {"input": "2 2\n-1 -2\n1 1\n1 2", "output": "0"}]
1,200
["constructive algorithms"]
53
[{"input": "5 4\r\n1 -2 1 3 -4\r\n1 2\r\n4 5\r\n3 4\r\n1 4\r\n", "output": "7\r\n"}, {"input": "4 3\r\n1 2 3 4\r\n1 3\r\n2 4\r\n1 1\r\n", "output": "16\r\n"}, {"input": "2 2\r\n-1 -2\r\n1 1\r\n1 2\r\n", "output": "0\r\n"}, {"input": "5 6\r\n1 1 1 -1 0\r\n2 4\r\n1 3\r\n4 5\r\n1 5\r\n1 4\r\n4 5\r\n", "output": "8\r\n"}, ...
false
stdio
null
true
55/C
55
C
PyPy 3
TESTS
11
154
102,400
188409862
import sys from math import * from collections import Counter,defaultdict,deque input=sys.stdin.readline mod=10**9+7 def get_ints():return map(int,input().split()) def get_int():return int(input()) def get_array():return list(map(int,input().split())) def input():return sys.stdin.readline().strip() x,y,k=get_ints() fo...
75
78
102,400
3933349
n, m, k = [int(x) for x in input().split()] canwin = False for i in range(k): x, y = [int(x) for x in input().split()] canwin |= x < 6 or n - x < 5 canwin |= y < 6 or m - y < 5 print("YES" if canwin else "NO")
Codeforces Beta Round 51
CF
2,011
2
256
Pie or die
Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the borde...
First line contains 3 integers, separated by space: 1 ≤ n, m ≤ 100 — dimensions of the board and 0 ≤ k ≤ 100 — the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≤ x ≤ n, 1 ≤ y ≤ m — coordinates of the corresponding pie. There could be more than one pie at a cell.
Output only one word: "YES" — if Volodya wins, "NO" — otherwise.
null
null
[{"input": "2 2 1\n1 2", "output": "YES"}, {"input": "3 4 0", "output": "NO"}, {"input": "100 50 2\n50 25\n50 25", "output": "NO"}]
1,900
["games"]
75
[{"input": "2 2 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3 4 0\r\n", "output": "NO\r\n"}, {"input": "100 50 2\r\n50 25\r\n50 25\r\n", "output": "NO\r\n"}, {"input": "20 20 4\r\n10 10\r\n10 10\r\n10 10\r\n10 10\r\n", "output": "NO\r\n"}, {"input": "15 15 1\r\n8 8\r\n", "output": "NO\r\n"}, {"input": "8 8 2\r\n4 4...
false
stdio
null
true
822/B
822
B
PyPy 3-64
TESTS
10
46
0
156079357
n,m = map(int, input().split()) s = input() t = input() maxx = 0 idx = 0 ans = [] for i in range(m-n+1): c = i m = 0 res = [] for j in range(n): if t[c]==s[j]: m+=1 else: res.append(j+1) c+=1 if maxx<m: maxx = m ans = res...
113
77
2,150,400
230090158
from __future__ import annotations if __name__ == "__main__": n: int m: int n, m = map(int, input().split()) s: str = input() t: str = input() min_replacements = float('inf') positions = [] for i in range(m - n + 1): replacements = 0 replace_positions = [] ...
Codeforces Round 422 (Div. 2)
CF
2,017
1
256
Crossword solving
Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple ta...
The first line contains two integers n and m (1 ≤ n ≤ m ≤ 1000) — the length of the string s and the length of the string t correspondingly. The second line contains n lowercase English letters — string s. The third line contains m lowercase English letters — string t.
In the first line print single integer k — the minimal number of symbols that need to be replaced. In the second line print k distinct integers denoting the positions of symbols in the string s which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering ...
null
null
[{"input": "3 5\nabc\nxaybz", "output": "2\n2 3"}, {"input": "4 10\nabcd\nebceabazcd", "output": "1\n2"}]
1,000
["brute force", "implementation", "strings"]
113
[{"input": "3 5\r\nabc\r\nxaybz\r\n", "output": "2\r\n2 3 \r\n"}, {"input": "4 10\r\nabcd\r\nebceabazcd\r\n", "output": "1\r\n2 \r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "0\r\n\r\n"}, {"input": "1 1\r\na\r\nz\r\n", "output": "1\r\n1 \r\n"}, {"input": "3 5\r\naaa\r\naaaaa\r\n", "output": "0\r\n\r\n"}, {"input": "...
false
stdio
null
true
822/B
822
B
Python 3
TESTS
10
46
0
169039915
n, m = map(int, input().split()) s = input() t = input() k = 0 indices = [] for i in range(m-n+1): diferente = 0 listaDifs = [] for j in range(n): if t[i+j] != s[j]: diferente += 1 listaDifs.append(j+1) if k == 0 or diferente < k: k = diferente indices =...
113
77
2,355,200
229537295
n, m = map(int, input().split()) s, t, k = str(input()), str(input()), [""] * 1001 for i in range(m - n + 1): g = [j + 1 for j in range(n) if s[j] != (t[i : i + n])[j]] if len(g) < len(k): k = g print(len(k)) print(*k)# 1698139990.4168484
Codeforces Round 422 (Div. 2)
CF
2,017
1
256
Crossword solving
Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple ta...
The first line contains two integers n and m (1 ≤ n ≤ m ≤ 1000) — the length of the string s and the length of the string t correspondingly. The second line contains n lowercase English letters — string s. The third line contains m lowercase English letters — string t.
In the first line print single integer k — the minimal number of symbols that need to be replaced. In the second line print k distinct integers denoting the positions of symbols in the string s which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering ...
null
null
[{"input": "3 5\nabc\nxaybz", "output": "2\n2 3"}, {"input": "4 10\nabcd\nebceabazcd", "output": "1\n2"}]
1,000
["brute force", "implementation", "strings"]
113
[{"input": "3 5\r\nabc\r\nxaybz\r\n", "output": "2\r\n2 3 \r\n"}, {"input": "4 10\r\nabcd\r\nebceabazcd\r\n", "output": "1\r\n2 \r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "0\r\n\r\n"}, {"input": "1 1\r\na\r\nz\r\n", "output": "1\r\n1 \r\n"}, {"input": "3 5\r\naaa\r\naaaaa\r\n", "output": "0\r\n\r\n"}, {"input": "...
false
stdio
null
true
33/C
33
C
Python 3
TESTS
15
590
6,860,800
51263559
n = int(input()) seq = list(map(int, input().split())) original = [i for i in seq] #---------------------------- # CASO 1: Direta --> Esquerda #---------------------------- sums = [] s = sum(seq) for i, j in enumerate(seq): if i > 0: sums.append(sums[i-1]+(j*-1)) else: sums.append(s+(j*-1)) i...
89
218
13,926,400
207223589
# LUOGU_RID: 111245501 from sys import stdin input = stdin.readline def get() : return map(int,input().split()) n = int(input()) lst = [0] + list(get()) tot = sum(lst) t = 0 res = 0 for i in range(1, n + 1) : if t + lst[i] < 0 : t = 0 else : t += lst[i] res = max(res, t) res...
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
Wonderful Randomized Sum
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th...
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
The first and the only line of the output should contain the answer to the problem.
null
null
[{"input": "3\n-1 -2 -3", "output": "6"}, {"input": "5\n-4 2 0 5 0", "output": "11"}, {"input": "5\n-1 10 -5 10 -2", "output": "18"}]
1,800
["greedy"]
89
[{"input": "3\r\n-1 -2 -3\r\n", "output": "6\r\n"}, {"input": "5\r\n-4 2 0 5 0\r\n", "output": "11\r\n"}, {"input": "5\r\n-1 10 -5 10 -2\r\n", "output": "18\r\n"}, {"input": "1\r\n-3\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 -5 -2\r\n", "output": "12\r\n"}, {"input": "7\r\n-17 6 5 0 1 4 -1\r\n", "output": "34\r\n"}...
false
stdio
null
true
382/C
382
C
Python 3
TESTS
21
62
409,600
5718431
N = int(input()) Nums = list(sorted(map(int, input().split()))) Delta = [Nums[i + 1] - Nums[i] for i in range(N - 1)] if N <= 1: print(-1) elif N == 2: if Nums[0] == Nums[1]: print(1) print(Nums[0]) elif sum(Nums) % 2 == 0: print(3) print(Nums[0] - Delta[0], sum(Nums) // 2, N...
59
124
15,155,200
170399441
from collections import defaultdict as dc n=int(input()) arr=list(map(int,input().split())) arr=sorted(arr) if n==1:print(-1) elif n==2: df=arr[1]-arr[0] if df==0:print(1,'\n',arr[0]) elif df%2==1:print(2,'\n',arr[0]-df,arr[1]+df) else:print(3,'\n',arr[0]-df,(arr[1]+arr[0])//2,arr[1]+df) else: mp=dc...
Codeforces Round 224 (Div. 2)
CF
2,014
1
256
Arithmetic Progression
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1. For example, sequences [1, 5], [10], [5,...
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples)...
null
null
[{"input": "3\n4 1 7", "output": "2\n-2 10"}, {"input": "1\n10", "output": "-1"}, {"input": "4\n1 3 5 9", "output": "1\n7"}, {"input": "4\n4 3 4 5", "output": "0"}, {"input": "2\n2 4", "output": "3\n0 3 6"}]
1,700
["implementation", "sortings"]
59
[{"input": "3\r\n4 1 7\r\n", "output": "2\r\n-2 10\r\n"}, {"input": "1\r\n10\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 3 5 9\r\n", "output": "1\r\n7\r\n"}, {"input": "4\r\n4 3 4 5\r\n", "output": "0\r\n"}, {"input": "2\r\n2 4\r\n", "output": "3\r\n0 3 6\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "1\r\n2\r\n"}, {...
false
stdio
null
true
377/A
377
A
PyPy 3-64
TESTS
11
342
33,280,000
175833947
from collections import deque n, m, k = map(int, input().split()) matrix = [[float("inf")] * m for _ in range(n)] mat = [] dots = 0 DIR = [[0, 1], [0, -1], [1, 0], [0, 1]] pos = [-1,-1] for i in range(n): line = input() temp = [] for j,f in enumerate(line): temp.append(f) if f == ".": ...
89
249
37,376,000
227608563
from collections import deque def reset(): for i in range(n): for j in range(m): vis[i][j] = 0 level[i][j] = 0 def isValid(x, y): return not vis[x][y] and x >= 0 and y >= 0 and x < n and y < m and c[x][y] == '.' def bfs(x, y): q = deque() q.append((x, y)) vis[x][y]...
Codeforces Round 222 (Div. 1)
CF
2,013
2
256
Maze
Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any oth...
The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze. Each of the next n lines contains m characters. They describe t...
Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
null
null
[{"input": "3 4 2\n#..#\n..#.\n#...", "output": "#.X#\nX.#.\n#..."}, {"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "output": "#XXX\n#X#.\nX#..\n...#\n.#.#"}]
1,600
["dfs and similar"]
89
[{"input": "3 4 2\r\n#..#\r\n..#.\r\n#...\r\n", "output": "#.X#\r\nX.#.\r\n#...\r\n"}, {"input": "5 4 5\r\n#...\r\n#.#.\r\n.#..\r\n...#\r\n.#.#\r\n", "output": "#XXX\r\n#X#.\r\nX#..\r\n...#\r\n.#.#\r\n"}, {"input": "3 3 2\r\n...\r\n.#.\r\n...\r\n", "output": "X..\r\nX#.\r\n...\r\n"}, {"input": "3 3 2\r\n#.#\r\n...\r\n#...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: lines = f.readlines() first_line = lines[0].strip().split() n, m, k = map(int, first_line[:3]) original = [line.strip() ...
true
825/C
825
C
Python 3
TESTS
6
62
4,915,200
28897619
line1=[int(k) for k in input().split(' ')] line2=[int(k) for k in input().split(' ')] n=line1[0] current=line1[1] counter=0 in_order=sorted(line2) first=in_order[0] if current*2 < first: counter+=1 current=first for l in in_order: if current*2 >=l: if l > current: current=l else:...
61
46
0
146585913
n, k = map(int, input().split()) num = list(map(int, input().split())) num.sort() count = 0 for level in num: if level<=k*2: k = max(level,k) else: while level>k*2: k*=2 count+=1 k=max(level,k) print(count)
Educational Codeforces Round 25
ICPC
2,017
1
256
Multi-judge Solving
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge). Ma...
The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109). The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
null
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3. In the second ...
[{"input": "3 3\n2 1 9", "output": "1"}, {"input": "4 20\n10 3 6 3", "output": "0"}]
1,600
["greedy", "implementation"]
61
[{"input": "3 3\r\n2 1 9\r\n", "output": "1\r\n"}, {"input": "4 20\r\n10 3 6 3\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n3\r\n", "output": "1\r\n"}, {"input": "50 100\r\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 ...
false
stdio
null
true
849/B
849
B
Python 3
TESTS
14
358
512,000
29981974
from collections import defaultdict n=int(input()) ip=list(map(int,input().split())) b=0 slopes=defaultdict(lambda: 0) for i in range(n): for j in range(i+1,n): slope=((ip[j]-ip[i])/(j-i)) slopes[slope] = slopes.get(slope, 0) + 1 #print(slopes) for slope in slopes: y=slopes[slope] ...
52
62
307,200
29978538
def main(): n = int(input()) a = list(map(int, input().split())) if a[1] - a[0] == a[2] - a[1]: d = a[1] - a[0] c1 = a[0] c2 = 'no' for i in range(3, n): if i * d + c1 == a[i]: pass elif c2 == 'no': c2 = a[i] - d * i ...
Codeforces Round 431 (Div. 2)
CF
2,017
1
256
Tell Your World
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, yi). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes th...
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points. The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point.
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower).
null
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, ...
[{"input": "5\n7 5 8 6 9", "output": "Yes"}, {"input": "5\n-1 -2 0 0 -5", "output": "No"}, {"input": "5\n5 4 3 2 1", "output": "No"}, {"input": "5\n1000000000 0 0 0 0", "output": "Yes"}]
1,600
["brute force", "geometry"]
52
[{"input": "5\r\n7 5 8 6 9\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-1 -2 0 0 -5\r\n", "output": "No\r\n"}, {"input": "5\r\n5 4 3 2 1\r\n", "output": "No\r\n"}, {"input": "5\r\n1000000000 0 0 0 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n1000000000 1 0 -999999999 -1000000000\r\n", "output": "Yes\r\n"}, {"input": "...
false
stdio
null
true
825/C
825
C
Python 3
TESTS
10
61
4,915,200
29124879
n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() kol = 0 while a != []: while a != [] and k * 2 >= a[0]: if a[0]>k: k = a[0] * 2 a.pop(0) k *= 2 kol += 1 print(kol - 1)
61
46
0
146635010
n,k=map(int, input().split()) a=sorted([int(x) for x in input().split()]) ans=0 for i in range(0, n): while k*2<a[i]: ans+=1 k*=2 k=max(k,a[i]) print(ans)
Educational Codeforces Round 25
ICPC
2,017
1
256
Multi-judge Solving
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge). Ma...
The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109). The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
null
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3. In the second ...
[{"input": "3 3\n2 1 9", "output": "1"}, {"input": "4 20\n10 3 6 3", "output": "0"}]
1,600
["greedy", "implementation"]
61
[{"input": "3 3\r\n2 1 9\r\n", "output": "1\r\n"}, {"input": "4 20\r\n10 3 6 3\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n3\r\n", "output": "1\r\n"}, {"input": "50 100\r\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 ...
false
stdio
null
true
493/B
493
B
PyPy 3
TESTS
48
1,497
9,932,800
82663026
#493B n = int(input()) first = [0]*n second = [0]*n last = 0 i1 = 0 i2 = 0 for i in range(n): k = int(input()) if k > 0: first[i1] = k i1 += 1 else: second[i2] = abs(k) i2 += 1 if i == n-1: last = k s1 = sum(first) s2 = sum(second) if s1 > s2: print("first") e...
57
124
11,673,600
190048895
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) n = inp() ans = 0 pos = []...
Codeforces Round 281 (Div. 2)
CF
2,014
2
256
Vasya and Wrestling
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105). The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that mea...
If the first wrestler wins, print string "first", otherwise print "second"
null
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. We use notation |a| to denote lengt...
[{"input": "5\n1\n2\n-3\n-4\n3", "output": "second"}, {"input": "3\n-1\n-2\n3", "output": "first"}, {"input": "2\n4\n-4", "output": "second"}]
1,400
["implementation"]
57
[{"input": "5\r\n1\r\n2\r\n-3\r\n-4\r\n3\r\n", "output": "second\r\n"}, {"input": "3\r\n-1\r\n-2\r\n3\r\n", "output": "first\r\n"}, {"input": "2\r\n4\r\n-4\r\n", "output": "second\r\n"}, {"input": "7\r\n1\r\n2\r\n-3\r\n4\r\n5\r\n-6\r\n7\r\n", "output": "first\r\n"}, {"input": "14\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n-...
false
stdio
null
true
989/B
989
B
Python 3
TESTS
18
77
409,600
112146043
import sys import math from collections import OrderedDict def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def minput(): return map(int, input().split()) def listinput(): return list(map(int, input().split())) n,p=minput() s=input() s1=s[:(n-p)] s2=s[p:] if (s1==s2 and s1.coun...
59
78
0
39178999
n,p=map(int,input().split()) s=input() f=1 for i in range(len(s)-p): if s[i]!='.' and s[i+p]!='.' and s[i]==s[i+p]: continue else: f=0 break if f==1: print("No") else: x=[] for i in s: x.append(i) for i in range(len(s)-p): if x[i]=='.' and x[i+p]=='.': x[i]='1' x[i+p]='0' if x[i]=='.' and x[i+...
Codeforces Round 487 (Div. 2)
CF
2,018
1
256
A Tide of Riverscape
The records are expressed as a string $$$s$$$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low). You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $$$...
The first line contains two space-separated integers $$$n$$$ and $$$p$$$ ($$$1 \leq p \leq n \leq 2000$$$) — the length of the given string and the supposed period, respectively. The second line contains a string $$$s$$$ of $$$n$$$ characters — Mino's records. $$$s$$$ only contains characters '0', '1' and '.', and con...
Output one line — if it's possible that $$$p$$$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
null
In the first example, $$$7$$$ is not a period of the resulting string because the $$$1$$$-st and $$$8$$$-th characters of it are different. In the second example, $$$6$$$ is not a period of the resulting string because the $$$4$$$-th and $$$10$$$-th characters of it are different. In the third example, $$$9$$$ is alw...
[{"input": "10 7\n1.0.1.0.1.", "output": "1000100010"}, {"input": "10 6\n1.0.1.1000", "output": "1001101000"}, {"input": "10 9\n1........1", "output": "No"}]
1,200
["constructive algorithms", "strings"]
59
[{"input": "10 7\r\n1.0.1.0.1.\r\n", "output": "1000100010\r\n"}, {"input": "10 6\r\n1.0.1.1000\r\n", "output": "1001101000\r\n"}, {"input": "10 9\r\n1........1\r\n", "output": "No\r\n"}, {"input": "1 1\r\n.\r\n", "output": "No\r\n"}, {"input": "5 1\r\n0...1\r\n", "output": "00001\r\n"}, {"input": "17 10\r\n..1.100..1....
false
stdio
import sys def main(): input_path = sys.argv[1] ref_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path, 'r') as f: n, p = map(int, f.readline().split()) s = f.readline().strip() with open(ref_path, 'r') as f: ref_output = f.read().strip() with open(sub_pat...
true
493/B
493
B
PyPy 3-64
TESTS
50
1,154
14,438,400
202767265
n=int(input()) list1=[] for i in range(n): x=int(input()) list1.append(x) listFirst=[] listSecond=[] listSecond2=[] finalList=[] for i in list1: if i>0: listFirst.append(i) else: listSecond.append(i) listSecond2=list(map(lambda a:a*-1,listSecond)) if sum(listFirst)>sum(list...
57
140
13,107,200
202167816
import sys input = sys.stdin.readline def solve(): n = int(input()) a = [int(input()) for _ in range(n)] first, second = [], [] for x in a: if x > 0: first.append(x) else: second.append(-x) f, s = sum(first), sum(second) return "first" if ...
Codeforces Round 281 (Div. 2)
CF
2,014
2
256
Vasya and Wrestling
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105). The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that mea...
If the first wrestler wins, print string "first", otherwise print "second"
null
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. We use notation |a| to denote lengt...
[{"input": "5\n1\n2\n-3\n-4\n3", "output": "second"}, {"input": "3\n-1\n-2\n3", "output": "first"}, {"input": "2\n4\n-4", "output": "second"}]
1,400
["implementation"]
57
[{"input": "5\r\n1\r\n2\r\n-3\r\n-4\r\n3\r\n", "output": "second\r\n"}, {"input": "3\r\n-1\r\n-2\r\n3\r\n", "output": "first\r\n"}, {"input": "2\r\n4\r\n-4\r\n", "output": "second\r\n"}, {"input": "7\r\n1\r\n2\r\n-3\r\n4\r\n5\r\n-6\r\n7\r\n", "output": "first\r\n"}, {"input": "14\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n-...
false
stdio
null
true
493/B
493
B
Python 3
TESTS
50
218
0
231398504
totalMoves = int(input()) netFirst = 0 netSecond = 0 firstMove = None secondMove = None for newMove in range(totalMoves): move = int(input()) if move>0: netFirst+=move if firstMove==None: firstMove = move else: netSecond+=move if secondMove==None: seco...
57
186
7,680,000
84145621
import sys input=sys.stdin.buffer.readline import os t=int(input()) arr=[] brr=[] last=0 while t: t-=1 n=int(input()) last=n if n<0: brr.append(-n) else: arr.append(n) if sum(arr)>sum(brr): print("first") elif sum(arr)<sum(brr): print("second") else: z="" for i in range(min(len(arr),len(brr))): if arr[i...
Codeforces Round 281 (Div. 2)
CF
2,014
2
256
Vasya and Wrestling
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105). The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that mea...
If the first wrestler wins, print string "first", otherwise print "second"
null
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. We use notation |a| to denote lengt...
[{"input": "5\n1\n2\n-3\n-4\n3", "output": "second"}, {"input": "3\n-1\n-2\n3", "output": "first"}, {"input": "2\n4\n-4", "output": "second"}]
1,400
["implementation"]
57
[{"input": "5\r\n1\r\n2\r\n-3\r\n-4\r\n3\r\n", "output": "second\r\n"}, {"input": "3\r\n-1\r\n-2\r\n3\r\n", "output": "first\r\n"}, {"input": "2\r\n4\r\n-4\r\n", "output": "second\r\n"}, {"input": "7\r\n1\r\n2\r\n-3\r\n4\r\n5\r\n-6\r\n7\r\n", "output": "first\r\n"}, {"input": "14\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n-...
false
stdio
null
true
102/B
102
B
Python 3
TESTS
43
248
0
118902048
n = input() x = 0 result = 0 if len(n)== 1 else 1 for digit in n: x += int(digit) sum = x while(sum//10 > 0): sum = 0 while(x != 0): sum += x%10 x = x//10 result += 1 print(result)
51
92
0
147020738
string = input() count = 0 while len(string) > 1: string = str(sum(map(int, string))) count += 1 print(count)
Codeforces Beta Round 79 (Div. 2 Only)
CF
2,011
2
265
Sum of Digits
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-di...
The first line contains the only integer n (0 ≤ n ≤ 10100000). It is guaranteed that n doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
null
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transform...
[{"input": "0", "output": "0"}, {"input": "10", "output": "1"}, {"input": "991", "output": "3"}]
1,000
["implementation"]
51
[{"input": "0\r\n", "output": "0\r\n"}, {"input": "10\r\n", "output": "1\r\n"}, {"input": "991\r\n", "output": "3\r\n"}, {"input": "99\r\n", "output": "2\r\n"}, {"input": "100\r\n", "output": "1\r\n"}, {"input": "123456789\r\n", "output": "2\r\n"}, {"input": "32\r\n", "output": "1\r\n"}, {"input": "86\r\n", "output": "...
false
stdio
null
true
102/B
102
B
PyPy 3-64
TESTS
43
154
13,312,000
216149466
n=list(map(int, input().replace("", " ").split())) if len(n)==1: print(0) exit() n=list(map(int, str(sum(n)).replace("", " ").split())) if len(n)==1: print(1) exit() n=list(map(int, str(sum(n)).replace("", " ").split())) if len(n)==1: print(2) exit() n=list(map(int, str(sum(n)).replace("", " ")....
51
92
0
148519769
x = input() result = 0 while True: if x == "0" or len(str(x)) == 1: print(result) break x = sum((map(int, x))) x = str(x) result +=1
Codeforces Beta Round 79 (Div. 2 Only)
CF
2,011
2
265
Sum of Digits
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-di...
The first line contains the only integer n (0 ≤ n ≤ 10100000). It is guaranteed that n doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
null
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transform...
[{"input": "0", "output": "0"}, {"input": "10", "output": "1"}, {"input": "991", "output": "3"}]
1,000
["implementation"]
51
[{"input": "0\r\n", "output": "0\r\n"}, {"input": "10\r\n", "output": "1\r\n"}, {"input": "991\r\n", "output": "3\r\n"}, {"input": "99\r\n", "output": "2\r\n"}, {"input": "100\r\n", "output": "1\r\n"}, {"input": "123456789\r\n", "output": "2\r\n"}, {"input": "32\r\n", "output": "1\r\n"}, {"input": "86\r\n", "output": "...
false
stdio
null
true
102/B
102
B
PyPy 3-64
TESTS
43
124
12,492,800
177674143
# Wadea # n = str(input()) lst = list(n) lst2 = [] for i in lst: lst2.append(int(i)) r = 0 s = sum(lst2) s = str(s) lst3 = [] if n == 0: print("0") elif len(n) == 1: print("0") elif len(s) == 1: print("1") elif len(s) != 1: for j in s: lst3.append(int(j)) r = sum(lst3) r = ...
51
92
0
158963423
s=input() c=0 while len(s)>1: s=str(sum(map(int,s))) c+=1 print(c)
Codeforces Beta Round 79 (Div. 2 Only)
CF
2,011
2
265
Sum of Digits
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-di...
The first line contains the only integer n (0 ≤ n ≤ 10100000). It is guaranteed that n doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
null
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transform...
[{"input": "0", "output": "0"}, {"input": "10", "output": "1"}, {"input": "991", "output": "3"}]
1,000
["implementation"]
51
[{"input": "0\r\n", "output": "0\r\n"}, {"input": "10\r\n", "output": "1\r\n"}, {"input": "991\r\n", "output": "3\r\n"}, {"input": "99\r\n", "output": "2\r\n"}, {"input": "100\r\n", "output": "1\r\n"}, {"input": "123456789\r\n", "output": "2\r\n"}, {"input": "32\r\n", "output": "1\r\n"}, {"input": "86\r\n", "output": "...
false
stdio
null
true
899/A
899
A
Python 3
TESTS
18
124
3,686,400
73123715
n=int(input()) li=list(map(int,input().split())) one=li.count(1) two=li.count(2) l=one//3 print(max(min(one,two),(one//3),(one//3)+min(one-3*l,two)))
67
46
1,126,400
224699025
n, a = int(input()), input() t = min(a.count('1'), a.count('2')) print(t + (a.count('1') - t) // 3)
Codeforces Round 452 (Div. 2)
CF
2,017
1
256
Splitting in Teams
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams...
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
Print the maximum number of teams of three people the coach can form.
null
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and...
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
800
["constructive algorithms", "greedy", "math"]
67
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1...
false
stdio
null
true
721/B
721
B
Python 3
TESTS
13
124
307,200
68299096
n, k = list(map(int, input().split())) lst = [] count = 0 best_case = 0 worst_case = 0 for i in range(n+1): s = input() lst.append(s) Vanya_password = lst[-1] lst.pop(-1) #print(lst) def check(s,t): #kiem tra hai chuoi co giong nhau hay khong flag = True if(len(s) != len(t)): flag = False el...
66
31
0
147010170
def main(): n, k = list(map(int, input().split())) arr = [input() for _ in range(n)] correct_length = len(input()) less_length_passwords, same_length_passwords = 0, 0 for element in arr: check_length = len(element) if check_length == correct_length: same_length_passwords...
Codeforces Round 374 (Div. 2)
CF
2,016
2
256
Passwords
Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrar...
The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds. The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters a...
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
null
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente...
[{"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc", "output": "1 15"}, {"input": "4 100\n11\n22\n1\n2\n22", "output": "3 4"}]
1,100
["implementation", "math", "sortings", "strings"]
66
[{"input": "5 2\r\ncba\r\nabc\r\nbb1\r\nabC\r\nABC\r\nabc\r\n", "output": "1 15\r\n"}, {"input": "4 100\r\n11\r\n22\r\n1\r\n2\r\n22\r\n", "output": "3 4\r\n"}, {"input": "1 1\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "1 100\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "2 1\r\nabc\r\nAbc\r\nAbc\r\n", "outpu...
false
stdio
null
true
721/B
721
B
PyPy 3
TESTS
14
140
0
97401306
a, b = map(int, input().split()) s = [0] * 101 for h in range(a): d = input() s[len(d)] += 1 an = input() g = [] for i in range(100): if i <= len(an) and s[i] != 0: g.append(s[i]) c = 0 c1 = 0 k = b for i in range(len(g) - 1): c1 += g[i] if g[i] > k: c1 += 5 * (g[i] // k) k =...
66
46
0
149873612
from math import floor n,k=map(int,input().split()) m=dict() for i in range(n): p=input() l=len(p) if l in m: m[l].append(p) else: m[l]=[p] p=input() mx=0 mn=0 for i in sorted(m.keys()): if i==len(p): break mn+=len(m[i]) mn+=1 mx=mn+len(m[len(p)])-1 if(mn%k>0): mn+=fl...
Codeforces Round 374 (Div. 2)
CF
2,016
2
256
Passwords
Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrar...
The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds. The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters a...
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
null
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente...
[{"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc", "output": "1 15"}, {"input": "4 100\n11\n22\n1\n2\n22", "output": "3 4"}]
1,100
["implementation", "math", "sortings", "strings"]
66
[{"input": "5 2\r\ncba\r\nabc\r\nbb1\r\nabC\r\nABC\r\nabc\r\n", "output": "1 15\r\n"}, {"input": "4 100\r\n11\r\n22\r\n1\r\n2\r\n22\r\n", "output": "3 4\r\n"}, {"input": "1 1\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "1 100\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "2 1\r\nabc\r\nAbc\r\nAbc\r\n", "outpu...
false
stdio
null
true
326/B
335
B
PyPy 3-64
TESTS
3
186
11,161,600
181652526
from collections import Counter s = input() n = len(s) res = "" Found = False for c, f in Counter(s).items(): if f >= 100: res = c*100 Found = True break if Found: print(res) else: if n > (26*99 + 1): s = s[:(26*99 + 1)] t = s[::-1] n = len(t) dp = [[0 for _ in...
72
1,996
117,145,600
66242753
from collections import defaultdict s = input() n = len(s) if n >= 2600: print(s[0] * 100) elif n > 2574: count = defaultdict(int) for l in s: count[l] += 1 max_l = s[0] for l, c in count.items(): if c >= 100: max_l = l print(max_l * 100) else: data = defaultdi...
MemSQL start[c]up Round 2
CF
2,013
2
256
Palindrome
Given a string s, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of s and is as long as possible.
The only line of the input contains one string s of length n (1 ≤ n ≤ 5·104) containing only lowercase English letters.
If s contains a palindrome of length exactly 100 as a subsequence, print any palindrome of length 100 which is a subsequence of s. If s doesn't contain any palindromes of length exactly 100, print a palindrome that is a subsequence of s and is as long as possible. If there exists multiple answers, you are allowed to p...
null
A subsequence of a string is a string that can be derived from it by deleting some characters without changing the order of the remaining characters. A palindrome is a string that reads the same forward or backward.
[{"input": "bbbabcbbb", "output": "bbbcbbb"}, {"input": "rquwmzexectvnbanemsmdufrg", "output": "rumenanemur"}]
1,900
[]
72
[{"input": "bbbabcbbb\r\n", "output": "bbbcbbb\r\n"}, {"input": "rquwmzexectvnbanemsmdufrg\r\n", "output": "rumenanemur\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
false
stdio
import sys def is_palindrome(s): return s == s[::-1] def is_subsequence(sub, s): i = 0 for c in sub: i = s.find(c, i) + 1 if i == 0: return False return True input_path, output_path, submission_path = sys.argv[1:4] with open(input_path) as f: s = f.read().strip() wit...
true
21/D
21
D
PyPy 3-64
TESTS
1
92
512,000
152686142
import itertools from sys import stdin, stdout if __name__ == '__main__': n, m = list(map(lambda x: int(x), stdin.readline().split())) u, v, w, sum_ = None, None, None, 0 D = [[1e9 for _ in range(n)] for _ in range(n)] deg = [0 for _ in range(n)] for i in range(n): D[i][i] = 0 for _ i...
60
280
5,017,600
153611194
from itertools import repeat inf = 10000000000 ans = inf mat = 0 def solve(odd, graph_matrix): global ans global mat if (len(odd) == 0): ans = min(ans, mat) return e = odd.pop() i = 0 while i<len(odd): cur = odd.pop(i) mat+=graph_matrix[cur][e] solve(odd, ...
Codeforces Alpha Round 21 (Codeforces format)
CF
2,010
0.5
64
Traveling Graph
You are given undirected weighted graph. Find the length of the shortest cycle which starts from the vertex 1 and passes throught all the edges at least once. Graph may contain multiply edges between a pair of vertices and loops (edges from the vertex to itself).
The first line of the input contains two integers n and m (1 ≤ n ≤ 15, 0 ≤ m ≤ 2000), n is the amount of vertices, and m is the amount of edges. Following m lines contain edges as a triples x, y, w (1 ≤ x, y ≤ n, 1 ≤ w ≤ 10000), x, y are edge endpoints, and w is the edge length.
Output minimal cycle length or -1 if it doesn't exists.
null
null
[{"input": "3 3\n1 2 1\n2 3 1\n3 1 1", "output": "3"}, {"input": "3 2\n1 2 3\n2 3 4", "output": "14"}]
2,400
["bitmasks", "graph matchings", "graphs"]
60
[{"input": "4 6\r\n1 2 10\r\n2 3 1000\r\n3 4 10\r\n4 1 1000\r\n4 2 5000\r\n1 3 2\r\n", "output": "7042\r\n"}, {"input": "2 9\r\n1 2 9\r\n1 2 9\r\n2 1 9\r\n1 2 8\r\n2 1 9\r\n1 2 9\r\n1 2 9\r\n1 2 11\r\n1 2 9\r\n", "output": "90\r\n"}, {"input": "2 10\r\n1 2 9\r\n1 2 9\r\n2 1 9\r\n1 2 8\r\n2 1 9\r\n1 2 9\r\n1 2 9\r\n1 2 ...
false
stdio
null
true
426/B
426
B
PyPy 3-64
TESTS
5
62
0
197875361
lis = list(map(int, input().split())) n, m = lis[0], lis[1] flag = True q = [] ans = 0 if n % 2: flag = False ans = n else: n //= 2 for i in range(n): q.append(input()) while flag: if n % 2: ans = n break else: n //= 2 for i in range(n): if q[i] == q[2 * n - 1...
65
61
102,400
8059149
import sys n, m = map(int, input().split()) mat = [] can = True for i in range(n): mat += [list(map(int, input().split()))] else: while can: if n % 2 == 1: print(n) sys.exit() for i in range(n // 2): if mat[i] != mat[n - i - 1]: can = False ...
Codeforces Round 243 (Div. 2)
CF
2,014
1
256
Sereja and Mirroring
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: - the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; - the lower half of matrix c (rows with number...
The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a.
In the single line, print the answer to the problem — the minimum number of rows of matrix b.
null
In the first test sample the answer is a 2 × 3 matrix b: If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:
[{"input": "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "output": "2"}, {"input": "3 3\n0 0 0\n0 0 0\n0 0 0", "output": "3"}, {"input": "8 1\n0\n1\n1\n0\n0\n1\n1\n0", "output": "2"}]
1,300
["implementation"]
65
[{"input": "4 3\r\n0 0 1\r\n1 1 0\r\n1 1 0\r\n0 0 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 0 0\r\n0 0 0\r\n", "output": "3\r\n"}, {"input": "8 1\r\n0\r\n1\r\n1\r\n0\r\n0\r\n1\r\n1\r\n0\r\n", "output": "2\r\n"}, {"input": "10 4\r\n0 0 1 0\r\n0 0 1 0\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n1 0 1 0\r\n0 0 1 1\...
false
stdio
null
true
426/B
426
B
Python 3
TESTS
5
62
5,222,400
25696773
# @Author: Justin Hershberger # @Date: 21-03-2017 # @Filename: 426B.py # @Last modified by: Justin Hershberger # @Last modified time: 21-03-2017 #Justin Hershberger #Py3.5 import fileinput def check_matrix(m): first_half = [] second_half = [] for i in range(len(m) // 2): first_half.append(m[i...
65
61
1,638,400
164549183
import sys input = sys.stdin.readline n, m = map(int, input().split()) g = [list(map(int, input().split())) for _ in range(n)] c = 0 while n % 2 == 0: for i in range(n//2): if g[i] != g[n-i-1]: c = 1 break if c == 0: n //= 2 else: break print(n)
Codeforces Round 243 (Div. 2)
CF
2,014
1
256
Sereja and Mirroring
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: - the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; - the lower half of matrix c (rows with number...
The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a.
In the single line, print the answer to the problem — the minimum number of rows of matrix b.
null
In the first test sample the answer is a 2 × 3 matrix b: If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:
[{"input": "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "output": "2"}, {"input": "3 3\n0 0 0\n0 0 0\n0 0 0", "output": "3"}, {"input": "8 1\n0\n1\n1\n0\n0\n1\n1\n0", "output": "2"}]
1,300
["implementation"]
65
[{"input": "4 3\r\n0 0 1\r\n1 1 0\r\n1 1 0\r\n0 0 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 0 0\r\n0 0 0\r\n", "output": "3\r\n"}, {"input": "8 1\r\n0\r\n1\r\n1\r\n0\r\n0\r\n1\r\n1\r\n0\r\n", "output": "2\r\n"}, {"input": "10 4\r\n0 0 1 0\r\n0 0 1 0\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n1 0 1 0\r\n0 0 1 1\...
false
stdio
null
true
584/C
584
C
Python 3
TESTS
38
124
1,024,000
189015071
import sys input = sys.stdin.readline n, t = map(int, input().split()) a = input() b = input() s, d = 0, 0 for i in range(n): if a[i] == b[i]: s += 1 else: d += 1 if 2 * s + d >= 2 * (n - t): n1, n2 = n - t, n - t c = ['$'] * n for i in range(n): if a[i] == b[i]: if n1 > 0: c[i] = a[i] n1 -= 1 ...
78
93
614,400
230027070
def f(n,a,b): x=0 for i in range(n): if a[i]==b[i]: x+=1 return x n,k=map(int, input().split()) a=str(input()) b=str(input()) x=f(n,a,b) k=n-k y1=k-x y2=y1 if k<=x: y1=0 y2=0 ans="" for i in range(n): if a[i]==b[i]: if k>0: ans+=a[i] ...
Codeforces Round 324 (Div. 2)
CF
2,015
1
256
Marina and Vasya
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and ...
The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters.
Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.
null
null
[{"input": "3 2\nabc\nxyc", "output": "ayd"}, {"input": "1 0\nc\nb", "output": "-1"}]
1,700
["constructive algorithms", "greedy", "strings"]
78
[{"input": "3 2\r\nabc\r\nxyc\r\n", "output": "bac"}, {"input": "1 0\r\nc\r\nb\r\n", "output": "-1\r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "b"}, {"input": "2 1\r\naa\r\naa\r\n", "output": "ab"}, {"input": "3 1\r\nbcb\r\nbca\r\n", "output": "bcc"}, {"input": "4 3\r\nccbb\r\ncaab\r\n", "output": "cbca"}, {"input"...
false
stdio
import sys def hamming(s1, s2): return sum(c1 != c2 for c1, c2 in zip(s1, s2)) def solution_exists(n, t, s1, s2): a = sum(c1 == c2 for c1, c2 in zip(s1, s2)) d = n - a min_k = max(d - t, 0) max_k = min(d // 2, a + d - t) return min_k <= max_k def main(): input_path = sys.argv[1] outpu...
true
740/B
740
B
PyPy 3
TESTS
13
140
1,331,200
56788295
n, m = map(int,input().split()) pre = [int(i) for i in input().split()] ans = 0 for _ in range(m) : l, r = map(int, input().split()) xx = 0 a = pre[l - 1: r] vis = [0] * 105 for i in pre : if vis[i] == 1 : continue xx += (a.count(i) * i) vis[i] = 1 if xx > 0 :...
53
46
0
140961895
cin=lambda:map(int,input().split()) n,m=cin() A=cin() ai=list(A) sum =[0]*(n+1) for i in range(n): sum[i]= sum[i-1]+ ai[i] temp = 0 result =0 j=0 sum[-1] =0 while(j<m): a, b = cin() temp = sum[b-1]- sum[a-2]; if temp>0: result += temp j = j+1 print(result)
Codeforces Round 381 (Div. 2)
CF
2,016
2
256
Alyona and flowers
Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is ai. The mood can be positive, zero or negative. Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose severa...
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of flowers and the number of subarrays suggested by the mother. The second line contains the flowers moods — n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100). The next m lines contain the description of the subarrays suggested by the mother. The...
Print single integer — the maximum possible value added to the Alyona's happiness.
null
The first example is the situation described in the statements. In the second example Alyona should choose all subarrays. The third example has answer 0 because Alyona can choose none of the subarrays.
[{"input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4", "output": "7"}, {"input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1", "output": "16"}, {"input": "2 2\n-1 -2\n1 1\n1 2", "output": "0"}]
1,200
["constructive algorithms"]
53
[{"input": "5 4\r\n1 -2 1 3 -4\r\n1 2\r\n4 5\r\n3 4\r\n1 4\r\n", "output": "7\r\n"}, {"input": "4 3\r\n1 2 3 4\r\n1 3\r\n2 4\r\n1 1\r\n", "output": "16\r\n"}, {"input": "2 2\r\n-1 -2\r\n1 1\r\n1 2\r\n", "output": "0\r\n"}, {"input": "5 6\r\n1 1 1 -1 0\r\n2 4\r\n1 3\r\n4 5\r\n1 5\r\n1 4\r\n4 5\r\n", "output": "8\r\n"}, ...
false
stdio
null
true
849/B
849
B
PyPy 3
TESTS
40
109
409,600
30020723
import sys n = int(input()) mass = input().split() mass = [int(a) for a in mass] first = [-1, -1] second = [-1, -1] used = [False, False] result = True final = False help = [1, 2, 3] for i in range(0, 3): a = help[i % 3] b = help[(i + 1) % 3] c = help[(i + 2) % 3] #print(a, b, c) first[0] = -(...
52
62
307,200
29984598
def f(m,c1,c2,l,n): fl=True for i in range(n): if (l[i]-(m1*i+m1)!=c1) and (l[i]-(m1*i+m1)!=c2): fl=False break return fl and c1!=c2 n=int(input()) l=list(map(int,input().split())) m1=l[1]-l[0] c1=l[0]-m1 c2=c1 for i in range(n): if l[i]-(m1*(i+1))!=c1: c2=l[i]-(m...
Codeforces Round 431 (Div. 2)
CF
2,017
1
256
Tell Your World
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, yi). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes th...
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points. The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point.
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower).
null
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, ...
[{"input": "5\n7 5 8 6 9", "output": "Yes"}, {"input": "5\n-1 -2 0 0 -5", "output": "No"}, {"input": "5\n5 4 3 2 1", "output": "No"}, {"input": "5\n1000000000 0 0 0 0", "output": "Yes"}]
1,600
["brute force", "geometry"]
52
[{"input": "5\r\n7 5 8 6 9\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-1 -2 0 0 -5\r\n", "output": "No\r\n"}, {"input": "5\r\n5 4 3 2 1\r\n", "output": "No\r\n"}, {"input": "5\r\n1000000000 0 0 0 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n1000000000 1 0 -999999999 -1000000000\r\n", "output": "Yes\r\n"}, {"input": "...
false
stdio
null
true
600/C
600
C
PyPy 3
TESTS
4
139
5,836,800
168513970
import sys from typing import Counter readline=sys.stdin.readline import bisect from collections import Counter S=list(readline().rstrip()) C=Counter(S) odd_alp=[chr(i) for i in range(97,97+26) if C[chr(i)]%2] le=len(odd_alp) for i in range(le//2): C[odd_alp[i]]+=1 C[odd_alp[le-i-1]]-=1 if le%2: odd_s=odd_...
66
62
2,457,600
194406515
def solve(): s = input() cnt = [0]*26 for i in s: cnt[ord(i)-97] += 1 odd, even = 0, 0 for i in cnt: if i%2==0: even += 1 else: odd += 1 if len(s) % 2 == 0 and odd >= 2: for i in range(26): if cnt[i]%2 == 1: for j in range(25, i, -1): ...
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
584/C
584
C
PyPy 3
TESTS
9
108
0
204484198
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, t = map(int, input().split()) s1 = list(input().rstrip()) s2 = list(input().rstrip()) x, y = [], [] for i in range(n): if s1[i] ^ s2[i]: x.append(i) else: y.append(i) u, v = len(x), len(y) u0 = u // 2 * 2 ans = [...
78
109
5,529,600
194571750
n, t = list(map(int, input().split())) a = input().strip() b = input().strip() d = 0 for i in range(n): if a[i] != b[i]: d += 1 if n - d + d // 2 < n - t: print(-1) else: d -= d & 1 ts = (n - t) * 2 ss = max(0, n - t - d // 2) res = [''] * n for i in range(n): if a[i] != b[i]...
Codeforces Round 324 (Div. 2)
CF
2,015
1
256
Marina and Vasya
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and ...
The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters.
Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.
null
null
[{"input": "3 2\nabc\nxyc", "output": "ayd"}, {"input": "1 0\nc\nb", "output": "-1"}]
1,700
["constructive algorithms", "greedy", "strings"]
78
[{"input": "3 2\r\nabc\r\nxyc\r\n", "output": "bac"}, {"input": "1 0\r\nc\r\nb\r\n", "output": "-1\r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "b"}, {"input": "2 1\r\naa\r\naa\r\n", "output": "ab"}, {"input": "3 1\r\nbcb\r\nbca\r\n", "output": "bcc"}, {"input": "4 3\r\nccbb\r\ncaab\r\n", "output": "cbca"}, {"input"...
false
stdio
import sys def hamming(s1, s2): return sum(c1 != c2 for c1, c2 in zip(s1, s2)) def solution_exists(n, t, s1, s2): a = sum(c1 == c2 for c1, c2 in zip(s1, s2)) d = n - a min_k = max(d - t, 0) max_k = min(d // 2, a + d - t) return min_k <= max_k def main(): input_path = sys.argv[1] outpu...
true
699/A
699
A
PyPy 3-64
TESTS
10
93
20,787,200
193979525
n = int(input()) d = input() l = [int(i) for i in input().split()] c = d.find('RL') if c == -1: print(-1) else: t = float("inf") while t != 1 and c < n-1: if d[c:c+2] == "RL" and (l[c+1]-l[c])//2 < t: t = (l[c+1]-l[c])//2 c += 2 print(t)
85
109
21,504,000
190491928
n = int(input()) s = input() c = 0 lc=[] l = [int(x) for x in input().split()] for i in range(n-1): if s[i]=='R' and s[i+1]=='L': lc.append((l[i+1]-l[i])/2) if len(lc): print(int(min(lc))) exit() print(-1)
Codeforces Round 363 (Div. 2)
CF
2,016
2
256
Launch of Collider
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dista...
The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles. The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right. The third line con...
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen.
null
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
[{"input": "4\nRLRL\n2 4 6 10", "output": "1"}, {"input": "3\nLLR\n40 50 60", "output": "-1"}]
1,000
["implementation"]
85
[{"input": "4\r\nRLRL\r\n2 4 6 10\r\n", "output": "1\r\n"}, {"input": "3\r\nLLR\r\n40 50 60\r\n", "output": "-1\r\n"}, {"input": "4\r\nRLLR\r\n46 230 264 470\r\n", "output": "92\r\n"}, {"input": "6\r\nLLRLLL\r\n446 492 650 844 930 970\r\n", "output": "97\r\n"}, {"input": "8\r\nRRLLLLLL\r\n338 478 512 574 594 622 834 92...
false
stdio
null
true
845/C
845
C
Python 3
TESTS
36
1,840
61,132,800
29930832
import sys N = int(input()) C = [] inside = {} ctr = 0 for n in range(N): l, r = map(int, input().split()) C += [(l, n), (r, n)] C.sort(key=lambda k: (k[0], -k[1])) # print(C) for x, i in C: if not inside.get(i): inside[i] = True ctr += 1 if ctr > 2: print('NO') ...
58
545
32,358,400
228461286
no_of_shows = int(input()) shows_startEnd_time_list = [tuple(map(int, input().split()[:2])) for _ in range(no_of_shows)] # Sort shows based on start times shows_startEnd_time_list.sort(key=lambda x: x[0]) end_tv1 = end_tv2 = -1 flag = 0 for show in shows_startEnd_time_list: start_time, end_time = show if star...
Educational Codeforces Round 27
ICPC
2,017
2
256
Two TVs
Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment li and ends at moment ri. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given mom...
The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of shows. Each of the next n lines contains two integers li and ri (0 ≤ li < ri ≤ 109) — starting and ending time of i-th show.
If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).
null
null
[{"input": "3\n1 2\n2 3\n4 5", "output": "YES"}, {"input": "4\n1 2\n2 3\n2 3\n1 2", "output": "NO"}]
1,500
["data structures", "greedy", "sortings"]
58
[{"input": "3\r\n1 2\r\n2 3\r\n4 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2\r\n2 3\r\n2 3\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 1\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2\r\n2 3\r\n2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 100\r\n0 100\r\n0 100\r\n", "output": "NO...
false
stdio
null
true
837/C
837
C
Python 3
TESTS
19
62
4,915,200
29236862
def fill_space(prints: list, a, b): prints.sort(key=lambda p: p.space, reverse=True) for p in prints: p.turn_vertically() max_space = 0 for i, p in enumerate(prints): for o_p in prints[i+1:]: combined_prints = [p.hstack(o_p), p.vstack(o_p)] for c_p in combined_pr...
51
62
2,252,800
174335629
import sys input = sys.stdin.readline n, a, b = map(int, input().split()) g = [list(map(int, input().split())) for _ in range(n)] c = 0 for i in range(n): x, y = g[i] c1 = x+y for j in range(i+1, n): x1, y1 = g[j] c2 = x1 + y1 for q in [x, y]: for w in [x1, y1]: ...
Educational Codeforces Round 26
ICPC
2,017
1
256
Two Seals
One very important person has a piece of paper in the form of a rectangle a × b. Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees). A very importa...
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100). Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
null
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper. In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the large...
[{"input": "2 2 2\n1 2\n2 1", "output": "4"}, {"input": "4 10 9\n2 3\n1 1\n5 10\n9 11", "output": "56"}, {"input": "3 10 10\n6 6\n7 7\n20 5", "output": "0"}]
1,500
["brute force", "implementation"]
51
[{"input": "2 2 2\r\n1 2\r\n2 1\r\n", "output": "4\r\n"}, {"input": "4 10 9\r\n2 3\r\n1 1\r\n5 10\r\n9 11\r\n", "output": "56\r\n"}, {"input": "3 10 10\r\n6 6\r\n7 7\r\n20 5\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n1 1\r\n1 1\r\n", "output": "2\r\n"}, {"inpu...
false
stdio
null
true
192/B
192
B
Python 3
TESTS
32
186
307,200
82730660
n = int(input()) p = [int(x) for x in input().split()] res = [0, 0] m = 9999999 m2 = min(p[-1], p[0]) for i in range(1, len(p)): if p[i] + p[i - 1] < m: res[0] = p[i] res[1] = p[i - 1] m = p[i] + p[i - 1] print(min(m2, max(res)))
85
62
0
232584673
n = int(input()) arr = list(map(int, input().split())) a = arr.copy() if arr[0] == 0 or arr[n-1] == 0: print(0) exit(0) maxi, mini = max(arr), min(arr) for i in range(mini, maxi + 1): for j in range(n): if arr[j] == i: a[j] = 0 if j > 0: if a[j] == 0 and a[j-1] == 0: print(i) e...
Codeforces Round 121 (Div. 2)
CF
2,012
2
256
Walking in the Rain
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from ...
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles. The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Print a single number — the sought number of days.
null
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it. In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed ...
[{"input": "4\n10 3 5 10", "output": "5"}, {"input": "5\n10 2 8 3 5", "output": "5"}]
1,100
["brute force", "implementation"]
85
[{"input": "4\r\n10 3 5 10\r\n", "output": "5\r\n"}, {"input": "5\r\n10 2 8 3 5\r\n", "output": "5\r\n"}, {"input": "10\r\n10 3 1 6 7 1 3 3 8 1\r\n", "output": "1\r\n"}, {"input": "10\r\n26 72 10 52 2 5 61 2 39 64\r\n", "output": "5\r\n"}, {"input": "100\r\n8 2 1 2 8 3 5 8 5 1 9 3 4 1 5 6 4 2 9 10 6 10 10 3 9 4 10 5 3 ...
false
stdio
null
true
382/C
382
C
PyPy 3-64
TESTS
51
202
17,510,400
199705226
from bisect import bisect_left, bisect_right from collections import Counter, deque from functools import lru_cache from math import factorial, comb, sqrt, gcd, lcm, log2 from copy import deepcopy import heapq from sys import stdin, stdout input = stdin.readline def main(): n = int(input()) L = list(map(in...
59
186
46,387,200
161915506
import collections n = int(input()) a = sorted(map(int, input().split())) if n == 1: print(-1) else: d = collections.defaultdict(int) for j in range(1, n): d[a[j] - a[j - 1]] += 1 ls = [] if len(d) == 1: ls.append(a[0] - list(d.keys())[0]) ls.append(a[-1] + list(d.keys())[0...
Codeforces Round 224 (Div. 2)
CF
2,014
1
256
Arithmetic Progression
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1. For example, sequences [1, 5], [10], [5,...
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples)...
null
null
[{"input": "3\n4 1 7", "output": "2\n-2 10"}, {"input": "1\n10", "output": "-1"}, {"input": "4\n1 3 5 9", "output": "1\n7"}, {"input": "4\n4 3 4 5", "output": "0"}, {"input": "2\n2 4", "output": "3\n0 3 6"}]
1,700
["implementation", "sortings"]
59
[{"input": "3\r\n4 1 7\r\n", "output": "2\r\n-2 10\r\n"}, {"input": "1\r\n10\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 3 5 9\r\n", "output": "1\r\n7\r\n"}, {"input": "4\r\n4 3 4 5\r\n", "output": "0\r\n"}, {"input": "2\r\n2 4\r\n", "output": "3\r\n0 3 6\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "1\r\n2\r\n"}, {...
false
stdio
null
true
192/B
192
B
Python 3
TESTS
80
92
0
157941357
import sys input = sys.stdin.readline n = int(input()) w = sorted(enumerate(map(int, input().split())), key=lambda x:x[1]) d = [] if n in [1, 2]: print(min(w)) else: for i in w: if (i[0] + 1 in d) or (i[0] -1 in d) or i[0] == 0 or i[0] == n-1: print(i[1]) break else: ...
85
92
0
148768072
n=int(input()) a=list(map(int,input().split())) count=0 for i in range(max(a)): if a[0]==0 or a[-1]==0: print(count) exit() for k in range(n-1): if a[k]==0 and a[k+1]==0: print(count) exit() count+=1 for j in range(n): if a[j]>0: a[j]-=...
Codeforces Round 121 (Div. 2)
CF
2,012
2
256
Walking in the Rain
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from ...
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles. The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Print a single number — the sought number of days.
null
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it. In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed ...
[{"input": "4\n10 3 5 10", "output": "5"}, {"input": "5\n10 2 8 3 5", "output": "5"}]
1,100
["brute force", "implementation"]
85
[{"input": "4\r\n10 3 5 10\r\n", "output": "5\r\n"}, {"input": "5\r\n10 2 8 3 5\r\n", "output": "5\r\n"}, {"input": "10\r\n10 3 1 6 7 1 3 3 8 1\r\n", "output": "1\r\n"}, {"input": "10\r\n26 72 10 52 2 5 61 2 39 64\r\n", "output": "5\r\n"}, {"input": "100\r\n8 2 1 2 8 3 5 8 5 1 9 3 4 1 5 6 4 2 9 10 6 10 10 3 9 4 10 5 3 ...
false
stdio
null
true
884/B
884
B
Python 3
TESTS
17
93
6,348,800
31812744
n,k = map(int,input().split()) x = [int(i) for i in input().split()] s = sum(x) + len(x) print('YES' if s == k or s-1 == k else 'NO')
66
46
5,632,000
159257185
r=lambda:map(int,input().split()) n,x=r() print(['NO','YES'][sum(r())+n-1==x])
Educational Codeforces Round 31
ICPC
2,017
1
256
Japanese Crosswords Strike Back
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect. For example: - If x = 6 and the crossword...
The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 10000) — the encoding.
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
null
null
[{"input": "2 4\n1 3", "output": "NO"}, {"input": "3 10\n3 3 2", "output": "YES"}, {"input": "2 10\n1 3", "output": "NO"}]
1,100
["implementation"]
66
[{"input": "2 4\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "3 10\r\n3 3 2\r\n", "output": "YES\r\n"}, {"input": "2 10\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n10\r\n", "output": "YES\r\n"}, {"input": "1 10000\r\n10000\r\n", "output": "YES\r\n"}, {"input": "10...
false
stdio
null
true
884/B
884
B
Python 3
TESTS
17
140
4,812,800
47694094
n, x = map(int, input().split()) s = 0 for c in input().split(): s += int(c) # print(x-n-s+1) # print(s) print('YES' if 0<=x-s-(n-1)<=1 else 'NO')
66
61
5,632,000
176260309
def main(): n, expected = map(int, input().split()) s = input().split(" ") soma = 0 for i in s: soma += int(i) if soma + n == expected + 1: print('YES') else: print('NO') if __name__ == '__main__': main()
Educational Codeforces Round 31
ICPC
2,017
1
256
Japanese Crosswords Strike Back
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect. For example: - If x = 6 and the crossword...
The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 10000) — the encoding.
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
null
null
[{"input": "2 4\n1 3", "output": "NO"}, {"input": "3 10\n3 3 2", "output": "YES"}, {"input": "2 10\n1 3", "output": "NO"}]
1,100
["implementation"]
66
[{"input": "2 4\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "3 10\r\n3 3 2\r\n", "output": "YES\r\n"}, {"input": "2 10\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n10\r\n", "output": "YES\r\n"}, {"input": "1 10000\r\n10000\r\n", "output": "YES\r\n"}, {"input": "10...
false
stdio
null
true
883/K
883
K
PyPy 3
TESTS
4
124
20,172,800
88846888
# import sys # input=sys.stdin.readline n=int(input()) a=[] for i in range(n): b,c=list(map(int,input().split())) a.append([b,b+c]) b=[a[i][1] for i in range(n)] c=b.index(min(b)) d=[-1]*n d[c]=min(b) for i in range(c+1,n): if d[i-1]+1<=a[i][1]: d[i]=d[i-1]+1 elif d[i-1]<=a[i][1]: d[i]=...
109
1,637
20,377,600
42341522
n = int(input()) ss = [0] * (n + 1) gg = [0] * (n + 1) #mins = [0] * n maxs = [0] * n curMin = -10 ** 10 curMax = -curMin for i in range(n): s, g = map(int, input().split(' ')) ss[i] = s gg[i] = g curMin = max(curMin - 1, s) curMax = min(curMax + 1, s + g) if curMin > curMax: print(-1...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Road Widening
Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy! The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time o...
The first line contains integer n (1 ≤ n ≤ 2·105) — number of parts of the street. Each of the following n lines contains two integers si, gi (1 ≤ si ≤ 106, 0 ≤ gi ≤ 106) — current width of road and width of the lawn on the i-th part of the street.
In the first line print the total width of lawns which will be removed. In the second line print n integers s'1, s'2, ..., s'n (si ≤ s'i ≤ si + gi) — new widths of the road starting from the first part and to the last. If there is no solution, print the only integer -1 in the first line.
null
null
[{"input": "3\n4 5\n4 5\n4 10", "output": "16\n9 9 10"}, {"input": "4\n1 100\n100 1\n1 100\n100 1", "output": "202\n101 101 101 101"}, {"input": "3\n1 1\n100 100\n1 1", "output": "-1"}]
1,800
["constructive algorithms", "greedy", "implementation"]
109
[{"input": "3\r\n4 5\r\n4 5\r\n4 10\r\n", "output": "16\r\n9 9 10 \r\n"}, {"input": "4\r\n1 100\r\n100 1\r\n1 100\r\n100 1\r\n", "output": "202\r\n101 101 101 101 \r\n"}, {"input": "3\r\n1 1\r\n100 100\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "10\r\n21005 10850\r\n27020 13372\r\n28183 3724\r\n22874 13564\r\n27446 11...
false
stdio
null
true
192/B
192
B
Python 3
TESTS
80
248
0
61937004
n=int(input()) l=list(map(int,input().split())) a=l.copy() c=0 for i in range(1,n-1): d=min(a) c=d a.remove(d) f=0 l[l.index(d)]=0 if l[0]==0 or l[-1]==0: break for j in range(1,n-1): if l[j]==0 and l[j+1]==0: f=1 break if f==1: break print...
85
92
0
152637069
n=int(input()) a=list(map(int,input().strip().split())) b=[a[n-1]] i=n-1 while i>1: if a[i-1]>a[i-2]: b.append(a[i-1]) i-=1 else: b.append(a[i-2]) i-=2 b.append(a[0]) print(min(b))
Codeforces Round 121 (Div. 2)
CF
2,012
2
256
Walking in the Rain
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from ...
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles. The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Print a single number — the sought number of days.
null
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it. In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed ...
[{"input": "4\n10 3 5 10", "output": "5"}, {"input": "5\n10 2 8 3 5", "output": "5"}]
1,100
["brute force", "implementation"]
85
[{"input": "4\r\n10 3 5 10\r\n", "output": "5\r\n"}, {"input": "5\r\n10 2 8 3 5\r\n", "output": "5\r\n"}, {"input": "10\r\n10 3 1 6 7 1 3 3 8 1\r\n", "output": "1\r\n"}, {"input": "10\r\n26 72 10 52 2 5 61 2 39 64\r\n", "output": "5\r\n"}, {"input": "100\r\n8 2 1 2 8 3 5 8 5 1 9 3 4 1 5 6 4 2 9 10 6 10 10 3 9 4 10 5 3 ...
false
stdio
null
true
55/C
55
C
Python 3
TESTS
6
124
0
14913830
n, m, k = map( int , input().split() ) flag = False while k > 0: k -= 1 x, y = map( int , input().split() ) d = min( x , n - x + 1 , y , m - y + 1 ) if d <= 4: flag = True print( "YES" if flag else "NO" )
75
92
0
152406352
[n,m,k]=[int(i) for i in input().split()] isDone=False for i in range(0,k): [x,y]=[int(i) for i in input().split()] if x<=5 or x>n-5 or y<=5 or y>m-5: isDone=True if isDone: print("YES") else: print("NO")
Codeforces Beta Round 51
CF
2,011
2
256
Pie or die
Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the borde...
First line contains 3 integers, separated by space: 1 ≤ n, m ≤ 100 — dimensions of the board and 0 ≤ k ≤ 100 — the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≤ x ≤ n, 1 ≤ y ≤ m — coordinates of the corresponding pie. There could be more than one pie at a cell.
Output only one word: "YES" — if Volodya wins, "NO" — otherwise.
null
null
[{"input": "2 2 1\n1 2", "output": "YES"}, {"input": "3 4 0", "output": "NO"}, {"input": "100 50 2\n50 25\n50 25", "output": "NO"}]
1,900
["games"]
75
[{"input": "2 2 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3 4 0\r\n", "output": "NO\r\n"}, {"input": "100 50 2\r\n50 25\r\n50 25\r\n", "output": "NO\r\n"}, {"input": "20 20 4\r\n10 10\r\n10 10\r\n10 10\r\n10 10\r\n", "output": "NO\r\n"}, {"input": "15 15 1\r\n8 8\r\n", "output": "NO\r\n"}, {"input": "8 8 2\r\n4 4...
false
stdio
null
true
832/B
832
B
Python 3
TESTS
54
265
6,041,600
148953119
from io import SEEK_END, SEEK_SET from typing import Union # https://codeforces.com/contest/832/problem/B def get_input_from_stdin() -> tuple: return get_input(0) def get_input(filename: Union[str,int]) -> tuple: file1 = open(filename) valid_letters = file1.readline() pattern = file1.readline() n...
94
139
9,420,800
181883000
import sys input = sys.stdin.readline s = input()[:-1] w = input()[:-1] t = 0 if '*' in w: x = w.index('*') a = w[:x] b = w[x+1:][::-1] t = 1 n = len(w) for l in range(int(input())): q = input()[:-1] m = len(q) ew = 0 if t == 0: if n != m: print('NO') c...
Codeforces Round 425 (Div. 2)
CF
2,017
2
256
Petya and Exam
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one.. There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is kno...
The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad. The second line contains the pattern — a string s of lowercase English letters, characters "?" and "*" (1 ≤ |s| ≤ 105). It is guaranteed that character "*"...
Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrary.
null
In the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter. Explanation of the second example. - The first query: "NO", because character "*" can be replaced wit...
[{"input": "ab\na?a\n2\naaa\naab", "output": "YES\nNO"}, {"input": "abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax", "output": "NO\nYES\nNO\nYES"}]
1,600
["implementation", "strings"]
94
[{"input": "ab\r\na?a\r\n2\r\naaa\r\naab\r\n", "output": "YES\r\nNO\r\n"}, {"input": "abc\r\na?a?a*\r\n4\r\nabacaba\r\nabaca\r\napapa\r\naaaaax\r\n", "output": "NO\r\nYES\r\nNO\r\nYES\r\n"}, {"input": "x\r\n?aba*\r\n69\r\nc\r\naaacc\r\nbba\r\nbabcb\r\nac\r\nbccca\r\nca\r\nabbaa\r\nb\r\naacca\r\nccc\r\ncc\r\na\r\naabba\...
false
stdio
null
true
382/C
382
C
PyPy 3
TESTS
50
264
10,342,400
82391240
from math import inf as inf from math import * from collections import * import sys input=sys.stdin.readline t=1 while(t): t-=1 n=int(input()) a=list(map(int,input().split())) a.sort() if(n==1): print(-1) exit(0) if(a[0]==a[-1]): print(1) print(a[0]) exit(...
59
202
8,499,200
14408341
from collections import Counter n, a = int(input()), sorted(map(int, input().split())) if n == 1: print(-1) elif a[0] == a[-1]: print(1) print(a[0]) else: d = Counter(a[i + 1] - a[i] for i in range(n - 1)) if len(d) == 1: v = [2 * a[0] - a[1], 2 * a[-1] - a[-2]] if len(a) == 2 and su...
Codeforces Round 224 (Div. 2)
CF
2,014
1
256
Arithmetic Progression
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1. For example, sequences [1, 5], [10], [5,...
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples)...
null
null
[{"input": "3\n4 1 7", "output": "2\n-2 10"}, {"input": "1\n10", "output": "-1"}, {"input": "4\n1 3 5 9", "output": "1\n7"}, {"input": "4\n4 3 4 5", "output": "0"}, {"input": "2\n2 4", "output": "3\n0 3 6"}]
1,700
["implementation", "sortings"]
59
[{"input": "3\r\n4 1 7\r\n", "output": "2\r\n-2 10\r\n"}, {"input": "1\r\n10\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 3 5 9\r\n", "output": "1\r\n7\r\n"}, {"input": "4\r\n4 3 4 5\r\n", "output": "0\r\n"}, {"input": "2\r\n2 4\r\n", "output": "3\r\n0 3 6\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "1\r\n2\r\n"}, {...
false
stdio
null
true
326/B
335
B
PyPy 3-64
TESTS
5
186
11,161,600
173913734
import sys import heapq import math input = sys.stdin.readline # sys.setrecursionlimit(100000) # from collections import Counter, defaultdict def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) string = input() count = {} for s in string: if s in count: count[s] ...
72
1,996
117,145,600
66242753
from collections import defaultdict s = input() n = len(s) if n >= 2600: print(s[0] * 100) elif n > 2574: count = defaultdict(int) for l in s: count[l] += 1 max_l = s[0] for l, c in count.items(): if c >= 100: max_l = l print(max_l * 100) else: data = defaultdi...
MemSQL start[c]up Round 2
CF
2,013
2
256
Palindrome
Given a string s, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of s and is as long as possible.
The only line of the input contains one string s of length n (1 ≤ n ≤ 5·104) containing only lowercase English letters.
If s contains a palindrome of length exactly 100 as a subsequence, print any palindrome of length 100 which is a subsequence of s. If s doesn't contain any palindromes of length exactly 100, print a palindrome that is a subsequence of s and is as long as possible. If there exists multiple answers, you are allowed to p...
null
A subsequence of a string is a string that can be derived from it by deleting some characters without changing the order of the remaining characters. A palindrome is a string that reads the same forward or backward.
[{"input": "bbbabcbbb", "output": "bbbcbbb"}, {"input": "rquwmzexectvnbanemsmdufrg", "output": "rumenanemur"}]
1,900
[]
72
[{"input": "bbbabcbbb\r\n", "output": "bbbcbbb\r\n"}, {"input": "rquwmzexectvnbanemsmdufrg\r\n", "output": "rumenanemur\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
false
stdio
import sys def is_palindrome(s): return s == s[::-1] def is_subsequence(sub, s): i = 0 for c in sub: i = s.find(c, i) + 1 if i == 0: return False return True input_path, output_path, submission_path = sys.argv[1:4] with open(input_path) as f: s = f.read().strip() wit...
true
33/C
33
C
PyPy 3-64
TESTS
15
154
16,486,400
214527703
N = int(input()) sequence = [int(d) for d in input().split()] SUM = sum(sequence) best_left = 0 left_index = -1 LEFT = [] LEFT.append(0) for i in range(N): running = LEFT[i] - sequence[i] if running > best_left: best_left = running left_index = i LEFT.append(running) best_right = -SU...
89
218
18,841,600
182196143
def f1(arr): n = len(arr) premax = [[0, 0] for _ in range(n + 1)] p0 = p1 = 0 for i, x in enumerate(arr): q0 = max(p0, p1) + x q1 = p1 - x premax[i + 1][0] = p0 = q0 premax[i + 1][1] = p1 = q1 ans = sum(arr) ans = max(ans, -ans) s0 = 0 for i in range(n - 1...
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
Wonderful Randomized Sum
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th...
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
The first and the only line of the output should contain the answer to the problem.
null
null
[{"input": "3\n-1 -2 -3", "output": "6"}, {"input": "5\n-4 2 0 5 0", "output": "11"}, {"input": "5\n-1 10 -5 10 -2", "output": "18"}]
1,800
["greedy"]
89
[{"input": "3\r\n-1 -2 -3\r\n", "output": "6\r\n"}, {"input": "5\r\n-4 2 0 5 0\r\n", "output": "11\r\n"}, {"input": "5\r\n-1 10 -5 10 -2\r\n", "output": "18\r\n"}, {"input": "1\r\n-3\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 -5 -2\r\n", "output": "12\r\n"}, {"input": "7\r\n-17 6 5 0 1 4 -1\r\n", "output": "34\r\n"}...
false
stdio
null
true
442/B
442
B
Python 3
TESTS
49
218
409,600
61416216
import decimal n = int(input()) hi = input() hi = hi.replace(',', '.', hi.count(',')) hehe = hi.split(" ") for i in range(len(hehe)): hehe[i] = float(hehe[i]) hehe = sorted(hehe, reverse=True) if len(hehe) == 1: print(hehe[0]) exit() if max(hehe) >= 0.5: print(max(hehe)) else: hi = [] f...
60
31
0
145954151
n=int(input()) l=list(map(float,input().split())) l=sorted(l) l=l[::-1] ans=0 d=1 vze=0 for x in l : vze=vze+x*(d-vze) d*=(1-x) ans=max(ans,vze) print(ans)
Codeforces Round 253 (Div. 1)
CF
2,014
2
256
Andrey and Problem
Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him. Help Andrey choose...
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of Andrey's friends. The second line contains n real numbers pi (0.0 ≤ pi ≤ 1.0) — the probability that the i-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point.
Print a single real number — the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most 10 - 9.
null
In the first sample the best strategy for Andrey is to ask only one of his friends, the most reliable one. In the second sample the best strategy for Andrey is to ask all of his friends to come up with a problem. Then the probability that he will get exactly one problem is 0.1·0.8 + 0.9·0.2 = 0.26.
[{"input": "4\n0.1 0.2 0.3 0.8", "output": "0.800000000000"}, {"input": "2\n0.1 0.2", "output": "0.260000000000"}]
1,800
["greedy", "math", "probabilities"]
60
[{"input": "4\r\n0.1 0.2 0.3 0.8\r\n", "output": "0.800000000000\r\n"}, {"input": "2\r\n0.1 0.2\r\n", "output": "0.260000000000\r\n"}, {"input": "1\r\n0.217266\r\n", "output": "0.217266000000\r\n"}, {"input": "2\r\n0.608183 0.375030\r\n", "output": "0.608183000000\r\n"}, {"input": "3\r\n0.388818 0.399762 0.393874\r\n",...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read submission output with open(submission_path, 'r') as f: submission_lines = f.readlines() if len(submission_lines) != 1: print(0) return submission_str = submission_lines[0].strip() try: sub_val = f...
true
102/B
102
B
Python 3
TESTS
43
498
102,400
147410300
def solve(): num = input() if int(num) < 10: print(0) return total = 0 for i in range(len(num)): total += int(num[i]) if total < 10: print(1) else: num = str(total) total = 0 for i in range(len(num)): total += int(num[i]) if total < 10: print(2) else: print(3) solve()
51
92
0
169426976
n=input() count=0 while(len(n)>1): n=str(sum(map(int,n))) count+=1 print(count)
Codeforces Beta Round 79 (Div. 2 Only)
CF
2,011
2
265
Sum of Digits
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-di...
The first line contains the only integer n (0 ≤ n ≤ 10100000). It is guaranteed that n doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
null
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transform...
[{"input": "0", "output": "0"}, {"input": "10", "output": "1"}, {"input": "991", "output": "3"}]
1,000
["implementation"]
51
[{"input": "0\r\n", "output": "0\r\n"}, {"input": "10\r\n", "output": "1\r\n"}, {"input": "991\r\n", "output": "3\r\n"}, {"input": "99\r\n", "output": "2\r\n"}, {"input": "100\r\n", "output": "1\r\n"}, {"input": "123456789\r\n", "output": "2\r\n"}, {"input": "32\r\n", "output": "1\r\n"}, {"input": "86\r\n", "output": "...
false
stdio
null
true
884/B
884
B
Python 3
TESTS
19
93
4,812,800
31926604
n ,x = map(int, input().split()) a = map(int, input().split()) for i in a: x=x-i if x==n-1 or x==n+1: print("YES") else: print("NO")
66
61
6,553,600
169012906
def japanese_crossword_again(): n, x = input().split() x = int(x) encoding = list(map(int, input().split())) print('YES') if (sum(encoding)+len(encoding)-1==x) else print('NO') japanese_crossword_again()
Educational Codeforces Round 31
ICPC
2,017
1
256
Japanese Crosswords Strike Back
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect. For example: - If x = 6 and the crossword...
The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 10000) — the encoding.
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
null
null
[{"input": "2 4\n1 3", "output": "NO"}, {"input": "3 10\n3 3 2", "output": "YES"}, {"input": "2 10\n1 3", "output": "NO"}]
1,100
["implementation"]
66
[{"input": "2 4\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "3 10\r\n3 3 2\r\n", "output": "YES\r\n"}, {"input": "2 10\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n10\r\n", "output": "YES\r\n"}, {"input": "1 10000\r\n10000\r\n", "output": "YES\r\n"}, {"input": "10...
false
stdio
null
true
733/C
733
C
PyPy 3
TESTS
2
78
0
190424142
import sys input = sys.stdin.buffer.readline def process1(A): n = len(A) if n==1: return [] m = max(A) for i in range(1, n): if A[i]==m and A[i-1] != m: answer = [] for j in range(i+1, 1, -1): answer.append([j, 'L']) for j in range(n...
138
78
614,400
21946429
n = int(input()) before = list(map(int, input().split())) kk = int(input()) after = list(map(int, input().split())) ans = [] if sum(before) != sum(after): print('NO') exit() for i in range(kk): need = after[i] s = 0 j = i while j < len(before) and s < need: s += before[j] ...
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
884/B
884
B
PyPy 3
TESTS
19
202
10,240,000
55814192
N, X = map(int, input().split()) A = list(map(int, input().split())) sum = 0 for i in range(0, N): sum += A[i] if X - sum == N - 1 or X - sum == N + 1: print('YES') else: print('NO')
66
61
6,553,600
169013740
n, x = [int(i) for i in input().split()] a = [int (i) for i in input().split()] if n-1+sum(a) == x: print("YES") elif sum(a) == 0: print("YES") else: print("NO")
Educational Codeforces Round 31
ICPC
2,017
1
256
Japanese Crosswords Strike Back
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect. For example: - If x = 6 and the crossword...
The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 10000) — the encoding.
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
null
null
[{"input": "2 4\n1 3", "output": "NO"}, {"input": "3 10\n3 3 2", "output": "YES"}, {"input": "2 10\n1 3", "output": "NO"}]
1,100
["implementation"]
66
[{"input": "2 4\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "3 10\r\n3 3 2\r\n", "output": "YES\r\n"}, {"input": "2 10\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n10\r\n", "output": "YES\r\n"}, {"input": "1 10000\r\n10000\r\n", "output": "YES\r\n"}, {"input": "10...
false
stdio
null
true
884/B
884
B
Python 3
TESTS
19
139
6,656,000
58087674
n, x = map(int, input().split()) a = list(map(int, input().split())) s = sum(a) if s + n - 1 == x or s + n + 1 == x: print("YES") else: print("NO")
66
61
6,553,600
169029828
n, x = map(int, input().split()) l = input().split() l = list(map(int, l)) if sum(l) + n - 1 == x: print("YES") else: print("NO")
Educational Codeforces Round 31
ICPC
2,017
1
256
Japanese Crosswords Strike Back
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect. For example: - If x = 6 and the crossword...
The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 10000) — the encoding.
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
null
null
[{"input": "2 4\n1 3", "output": "NO"}, {"input": "3 10\n3 3 2", "output": "YES"}, {"input": "2 10\n1 3", "output": "NO"}]
1,100
["implementation"]
66
[{"input": "2 4\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "3 10\r\n3 3 2\r\n", "output": "YES\r\n"}, {"input": "2 10\r\n1 3\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n10\r\n", "output": "YES\r\n"}, {"input": "1 10000\r\n10000\r\n", "output": "YES\r\n"}, {"input": "10...
false
stdio
null
true
197/B
197
B
PyPy 3
TESTS
8
280
0
77211999
from sys import stdin, stdout from math import gcd ii1 = lambda: int(stdin.readline().strip()) is1 = lambda: stdin.readline().strip() iia = lambda: list(map(int, stdin.readline().strip().split())) isa = lambda: stdin.readline().strip().split() mod = 1000000007 n, m = iia() a1 = iia() a2 = iia() if n > m: if a1[0] ...
80
92
0
219609509
import math n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) if m > n: print('0/1') elif m == n: gcd = abs(math.gcd(a[0], b[0])) if a[0] * b[0] < 0: print('-{}/{}'.format(abs(a[0]) // gcd, abs(b[0]) // gcd)) else: print('{}/{}'.fo...
Codeforces Round 124 (Div. 2)
CF
2,012
2
256
Limit
You are given two polynomials: - P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and - Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separ...
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the forma...
null
Let's consider all samples: 1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$ 2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$ 3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$ 4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$ 5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$ You c...
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
1,400
["math"]
80
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3...
false
stdio
null
true
197/B
197
B
PyPy 3
TESTS
8
280
20,172,800
86130352
import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def tinput(): return input().split() def rinput(): return map(int, tinput()) def rlinput(): return list(rinput()) def gcd(a,b): if b == 0: return a else: return gcd(...
80
124
0
8509335
import sys n, m = map(int, input().split()) cn = list(map(int, input().split())) cm = list(map(int, input().split())) if n > m: if cn[0]*cm[0] < 0: sys.stdout.write('-') print('Infinity') elif n < m: print('0/1') else: if cn[0]*cm[0] < 0: sys.stdout.write('-') cn[0], cm[0] = abs(cn[0]), abs(cm[0]) a, b = cn[0...
Codeforces Round 124 (Div. 2)
CF
2,012
2
256
Limit
You are given two polynomials: - P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and - Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separ...
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the forma...
null
Let's consider all samples: 1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$ 2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$ 3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$ 4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$ 5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$ You c...
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
1,400
["math"]
80
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3...
false
stdio
null
true
197/B
197
B
PyPy 3-64
TESTS
8
124
0
216996172
def gcd(a, b): while b: a, b = b, a % b return a def solve(n,m,a_n,a_m): if n<m: return "0/1" if n>m: if abs(a_n[0])==a_n[0] and abs(a_m[0])==a_m[0]: return "Infinity" else: return "-Infinity" d=gcd(a_n[0],a_m[0]) res1=a_n[0]//d res2=...
80
124
0
136194655
import math n,m = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] lis = [int(x) for x in input().split()] an = arr[0] bn = lis[0] if n > m: if an/bn >0 : print('Infinity') else: print('-Infinity') elif m >n: print('0/1') else: k = math.gcd(an,bn) if bn <0 an...
Codeforces Round 124 (Div. 2)
CF
2,012
2
256
Limit
You are given two polynomials: - P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and - Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separ...
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the forma...
null
Let's consider all samples: 1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$ 2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$ 3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$ 4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$ 5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$ You c...
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
1,400
["math"]
80
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3...
false
stdio
null
true
570/A
570
A
PyPy 3-64
TESTS
15
62
2,457,600
157967776
n, m = map(int, input().split()) mn = n for i in range(m): l = list(map(int, input().split())) a = max(l) for j in range(n): if(l[j] == a): mn = min(mn, j + 1) break print(mn)
62
46
0
146890324
n,m=list(map(int,input().split())) b=[0]*n for i in range(m): a=list(map(int,input().split())) k=a.index(max(a)) b[k]+=1 print(b.index(max(b))+1)
Codeforces Round 316 (Div. 2)
CF
2,015
1
256
Elections
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each...
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. I...
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
null
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm...
[{"input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2"}, {"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1"}]
1,100
["implementation"]
62
[{"input": "3 3\r\n1 2 3\r\n2 3 1\r\n1 2 1\r\n", "output": "2"}, {"input": "3 4\r\n10 10 3\r\n5 1 6\r\n2 2 2\r\n1 5 7\r\n", "output": "1"}, {"input": "1 3\r\n5\r\n3\r\n2\r\n", "output": "1"}, {"input": "3 1\r\n1 2 3\r\n", "output": "3"}, {"input": "3 1\r\n100 100 100\r\n", "output": "1"}, {"input": "2 2\r\n1 2\r\n2 1\r...
false
stdio
null
true
570/A
570
A
PyPy 3
TESTS
15
140
21,708,800
89402191
n , m = map(int,input().split()) res = [] for i in range(m): l = list(map(int,input().split())) res.append(l.index(max(l)) + 1) #print(res) print(min(res))
62
46
0
155140808
def main(): m, n = input().split() n = int(n) m = int(m) a = [] for i in range(n): a.append(list(map(int, input().split()))) b = [0]*m for i in a: b[i.index(max(i))] += 1 print(b.index(max(b))+1) if __name__ == '__main__': main()
Codeforces Round 316 (Div. 2)
CF
2,015
1
256
Elections
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each...
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. I...
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
null
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm...
[{"input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2"}, {"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1"}]
1,100
["implementation"]
62
[{"input": "3 3\r\n1 2 3\r\n2 3 1\r\n1 2 1\r\n", "output": "2"}, {"input": "3 4\r\n10 10 3\r\n5 1 6\r\n2 2 2\r\n1 5 7\r\n", "output": "1"}, {"input": "1 3\r\n5\r\n3\r\n2\r\n", "output": "1"}, {"input": "3 1\r\n1 2 3\r\n", "output": "3"}, {"input": "3 1\r\n100 100 100\r\n", "output": "1"}, {"input": "2 2\r\n1 2\r\n2 1\r...
false
stdio
null
true
570/A
570
A
PyPy 3
TESTS
15
140
21,708,800
85096437
n, m = map(int,input().split()) l, t1 = [], [] for _ in range(m): l1 = list(map(int,input().split())) l.append(l1) tp =max(l1) ls = l1.index(tp)+1 t1.append(ls) print(min(t1))
62
46
0
161416222
n, m = map(int, input().split()) first_win = [0 for _ in range(n+1)] wins = [0 for _ in range(n+1)] for city in range(m): a = list(map(int, input().split())) w = 1 for i in range(2, n+1): if a[w - 1] < a[i-1]: w = i if first_win[w] == 0: first_win[w] = city + 1 wins[w...
Codeforces Round 316 (Div. 2)
CF
2,015
1
256
Elections
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each...
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. I...
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
null
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm...
[{"input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2"}, {"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1"}]
1,100
["implementation"]
62
[{"input": "3 3\r\n1 2 3\r\n2 3 1\r\n1 2 1\r\n", "output": "2"}, {"input": "3 4\r\n10 10 3\r\n5 1 6\r\n2 2 2\r\n1 5 7\r\n", "output": "1"}, {"input": "1 3\r\n5\r\n3\r\n2\r\n", "output": "1"}, {"input": "3 1\r\n1 2 3\r\n", "output": "3"}, {"input": "3 1\r\n100 100 100\r\n", "output": "1"}, {"input": "2 2\r\n1 2\r\n2 1\r...
false
stdio
null
true
570/A
570
A
Python 3
TESTS
15
109
307,200
82624194
n,m=map(int,input().split()) dic={} for i in range(m): ac=list(map(int,input().split())) ind=ac.index(max(ac)) dic[ind]=dic.get(ind,0)+1 val=-1; k=10e9+1 for key,value in dic.items(): if value>=val and key<k: k=key val=value print(k+1)
62
46
0
162915511
def arr_int(arr): for i in range(len(arr)): arr[i]=int(arr[i]) return (arr) def winner(lista): max_list=max(lista) ans=0 for i in range(len(lista)): if lista[i]==max_list: ans=i break return ans def main(): n,m=input().split() arr_can=[] for i ...
Codeforces Round 316 (Div. 2)
CF
2,015
1
256
Elections
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each...
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. I...
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
null
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm...
[{"input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2"}, {"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1"}]
1,100
["implementation"]
62
[{"input": "3 3\r\n1 2 3\r\n2 3 1\r\n1 2 1\r\n", "output": "2"}, {"input": "3 4\r\n10 10 3\r\n5 1 6\r\n2 2 2\r\n1 5 7\r\n", "output": "1"}, {"input": "1 3\r\n5\r\n3\r\n2\r\n", "output": "1"}, {"input": "3 1\r\n1 2 3\r\n", "output": "3"}, {"input": "3 1\r\n100 100 100\r\n", "output": "1"}, {"input": "2 2\r\n1 2\r\n2 1\r...
false
stdio
null
true
570/A
570
A
Python 3
TESTS
15
124
0
47169663
n, m = map(int, input().split()) L = [] for i in range(m): v = list(map(int, input().split())) c = v.index(max(v)) L += [c+1] m = 0 C = 101 for i in L: a = L.count(i) if m <= a: m = a if i < C: C = i else: continue print(C)
62
46
0
173409190
n,m=map(int,input().split()) a=[] w=[] # n-candidates # m-votes for i in range(m): a = list(map(int,input().split())) w.append(a.index(max(a))+1) bset=set(w) mpst_common=None qty=0 for item in bset: q=w.count(item) if q>qty: qty=q mpst_common=item print(mpst_common)
Codeforces Round 316 (Div. 2)
CF
2,015
1
256
Elections
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each...
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. I...
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
null
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm...
[{"input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2"}, {"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1"}]
1,100
["implementation"]
62
[{"input": "3 3\r\n1 2 3\r\n2 3 1\r\n1 2 1\r\n", "output": "2"}, {"input": "3 4\r\n10 10 3\r\n5 1 6\r\n2 2 2\r\n1 5 7\r\n", "output": "1"}, {"input": "1 3\r\n5\r\n3\r\n2\r\n", "output": "1"}, {"input": "3 1\r\n1 2 3\r\n", "output": "3"}, {"input": "3 1\r\n100 100 100\r\n", "output": "1"}, {"input": "2 2\r\n1 2\r\n2 1\r...
false
stdio
null
true
570/A
570
A
Python 3
TESTS
16
109
0
66004661
a,b=map(int,input().split()) arr=[] h=0 while(b): b-=1 l=list(map(int,input().split())) h=max(l) for i in range(1,len(l)+1): if l[i-1]==h: arr.append(l.index(l[i-1])+1) print((max(set(arr),key=arr.count)))
62
46
0
176221871
m, n = map(int, input().split()) city = [0]*n for i in range (n): temp = list(map(int, input().split())) city[i] = temp.index(max(temp))+1 res = 0 max_m = 0 for i in range (1, m+1): if city.count(i) > max_m: res = i max_m = city.count(i) print(res)
Codeforces Round 316 (Div. 2)
CF
2,015
1
256
Elections
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each...
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. I...
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
null
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm...
[{"input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2"}, {"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1"}]
1,100
["implementation"]
62
[{"input": "3 3\r\n1 2 3\r\n2 3 1\r\n1 2 1\r\n", "output": "2"}, {"input": "3 4\r\n10 10 3\r\n5 1 6\r\n2 2 2\r\n1 5 7\r\n", "output": "1"}, {"input": "1 3\r\n5\r\n3\r\n2\r\n", "output": "1"}, {"input": "3 1\r\n1 2 3\r\n", "output": "3"}, {"input": "3 1\r\n100 100 100\r\n", "output": "1"}, {"input": "2 2\r\n1 2\r\n2 1\r...
false
stdio
null
true
439/C
439
C
Python 3
TESTS
9
436
5,939,200
51871723
n,k,p=map(int,input().split()) l=[int(i) for i in input().split()] odd=[i for i in l if i&1] even=[i for i in l if i&1==0] if len(odd)%2!=(k-p)%2: print("NO") exit() #parity not maintained ans=[] for i in range(k): ans.append([]) i=0 for o in odd: if i<k-p: ans[i].append(o) ...
75
327
15,667,200
52550184
import sys def minp(): return sys.stdin.readline().strip() n, k, p = map(int,minp().split()) even = [] odd = [] for i in map(int,minp().split()): if i%2 == 0: even.append(i) else: odd.append(i) if len(odd) < k-p: print("NO") else: ans = [] for i in range(k-p): ans.append([odd[-1]]) del(odd[-1]) if len...
Codeforces Round 251 (Div. 2)
CF
2,014
1
256
Devu and Partitioning of the Array
Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came up with an interesting question which he could not solve, can you please solve it for him? Given an array consisting of distinct integers. Is it possible to partition the whole array into k disjoint non-empty part...
The first line will contain three space separated integers n, k, p (1 ≤ k ≤ n ≤ 105; 0 ≤ p ≤ k). The next line will contain n space-separated distinct integers representing the content of array a: a1, a2, ..., an (1 ≤ ai ≤ 109).
In the first line print "YES" (without the quotes) if it is possible to partition the array in the required way. Otherwise print "NO" (without the quotes). If the required partition exists, print k lines after the first line. The ith of them should contain the content of the ith part. Print the content of the part in ...
null
null
[{"input": "5 5 3\n2 6 10 5 9", "output": "YES\n1 9\n1 5\n1 10\n1 6\n1 2"}, {"input": "5 5 3\n7 14 2 9 5", "output": "NO"}, {"input": "5 3 1\n1 2 3 7 5", "output": "YES\n3 5 1 3\n1 7\n1 2"}]
1,700
["brute force", "constructive algorithms", "implementation", "number theory"]
75
[{"input": "5 5 3\r\n2 6 10 5 9\r\n", "output": "YES\r\n1 9\r\n1 5\r\n1 10\r\n1 6\r\n1 2\r\n"}, {"input": "5 5 3\r\n7 14 2 9 5\r\n", "output": "NO\r\n"}, {"input": "5 3 1\r\n1 2 3 7 5\r\n", "output": "YES\r\n3 5 1 3\r\n1 7\r\n1 2\r\n"}, {"input": "10 5 3\r\n194757070 828985446 11164 80016 84729 117765558 111730436 1640...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, k, p = map(int, f.readline().split()) a = list(map(int, f.readline().split())) with open(output_path) as f: ref_line = f.readline().strip() correct_answer = ref_line with ...
true
570/A
570
A
PyPy 3
TESTS
15
140
1,638,400
71282517
# #include<bits/stdc++.h> # #include<iostream> # using namespace std; # int main() # { # ios_base::sync_with_stdio(false); # cin.tie(0); # cout.tie(0); def f(a,b): if a[1]>b[1]: return a[1]>b[1] elif a[1]==b[1]: return a[0]>b[0] fl=input().split() n=int(fl[0]) m=int(fl[-1]...
62
46
0
192488449
# LUOGU_RID: 101605745 (n, m), *a = [[*map(int, s.split())] for s in open(0)] c = [0] * n for x in a: c[x.index(max(x))] += 1 print(c.index(max(c)) + 1)
Codeforces Round 316 (Div. 2)
CF
2,015
1
256
Elections
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each...
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. I...
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
null
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm...
[{"input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2"}, {"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1"}]
1,100
["implementation"]
62
[{"input": "3 3\r\n1 2 3\r\n2 3 1\r\n1 2 1\r\n", "output": "2"}, {"input": "3 4\r\n10 10 3\r\n5 1 6\r\n2 2 2\r\n1 5 7\r\n", "output": "1"}, {"input": "1 3\r\n5\r\n3\r\n2\r\n", "output": "1"}, {"input": "3 1\r\n1 2 3\r\n", "output": "3"}, {"input": "3 1\r\n100 100 100\r\n", "output": "1"}, {"input": "2 2\r\n1 2\r\n2 1\r...
false
stdio
null
true
570/A
570
A
PyPy 3-64
TESTS
15
62
2,355,200
157967124
n, m = map(int, input().split()) mn = n for i in range(m): l = list(map(int, input().split())) mn = min(mn, l.index(max(l))) print(mn + 1)
62
46
0
197239914
n,m=map(int,input().split()) c=[0]*n for i in range(m): v=list(map(int,input().split())) c[v.index(max(v))]+=1 print(c.index(max(c))+1)
Codeforces Round 316 (Div. 2)
CF
2,015
1
256
Elections
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each...
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. I...
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
null
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm...
[{"input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2"}, {"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1"}]
1,100
["implementation"]
62
[{"input": "3 3\r\n1 2 3\r\n2 3 1\r\n1 2 1\r\n", "output": "2"}, {"input": "3 4\r\n10 10 3\r\n5 1 6\r\n2 2 2\r\n1 5 7\r\n", "output": "1"}, {"input": "1 3\r\n5\r\n3\r\n2\r\n", "output": "1"}, {"input": "3 1\r\n1 2 3\r\n", "output": "3"}, {"input": "3 1\r\n100 100 100\r\n", "output": "1"}, {"input": "2 2\r\n1 2\r\n2 1\r...
false
stdio
null
true
570/A
570
A
Python 3
TESTS
15
109
307,200
78389721
n,m = map(int, input().split()) d = {} for i in range(m): x = list(map(int, input().split())) c = max(x) ind = x.index(c) # print(ind) if(ind not in d): d[ind] = 1 else: d[ind]+=1 ans = int(1e9) t = 0 # print(d) for i in d: if(d[i]>=t): t = d[i] if(i<ans): ans = i print(ans+1)
62
46
0
198306288
a,b=map(int,input().split()) c=[0]*a for i in range(b): *d,=map(int,input().split()) c[d.index(max(d))]+=1 print(c.index(max(c))+1)
Codeforces Round 316 (Div. 2)
CF
2,015
1
256
Elections
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each...
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. I...
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
null
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm...
[{"input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2"}, {"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1"}]
1,100
["implementation"]
62
[{"input": "3 3\r\n1 2 3\r\n2 3 1\r\n1 2 1\r\n", "output": "2"}, {"input": "3 4\r\n10 10 3\r\n5 1 6\r\n2 2 2\r\n1 5 7\r\n", "output": "1"}, {"input": "1 3\r\n5\r\n3\r\n2\r\n", "output": "1"}, {"input": "3 1\r\n1 2 3\r\n", "output": "3"}, {"input": "3 1\r\n100 100 100\r\n", "output": "1"}, {"input": "2 2\r\n1 2\r\n2 1\r...
false
stdio
null
true
798/B
798
B
Python 3
TESTS
6
139
0
147929748
n = int(input()) s = {} l = 0 for i in range(n): a = str(i)+input() if l==0: l=len(a) s[a]=0 for k in s.keys(): for key in s.keys(): if k!=key: flag = 0 for i in range(1,l): temp = '' for j in range(i,i+l): if j%...
99
62
5,529,600
26550679
n = int(input()) a = [input().strip() for i in range(n)] m = len(a[0]) if any(len(ai)!=m for ai in a): print(-1) else: b = [ai+ai for ai in a] best = 10**9 s = a[0] for i in range(m): c = 0 for bi in b: steps = bi.find(s) if steps==-1: best = None break c += steps if best is None: best =...
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
219/C
219
C
PyPy 3-64
TESTS
15
122
2,252,800
155276673
#while True: n, k = map(int,input().split()) s = list(input()) kol = 0 s1 = s[::-1] #5print(s) for i in range(1,n): if s[i] == s[i - 1]: # print(s[i],i) if s[i] > "A" and s[i] < 'Z' and i + 1 < n and ord(s[i]) - 1 == ord(s[i + 1]) and ord(s[i]) - 64 + 1 <= k: s[i] = chr(ord(s[i]) + 1) ...
87
340
30,617,600
208067973
import sys input = lambda: sys.stdin.readline().rstrip() N,K = map(int, input().split()) chars = [] for i in range(K): chars.append(chr(ord('A')+i)) ans = 0 S = [c for c in input()] if K==2: s1 = 'AB'*N s2 = 'BA'*N s1=s1[:N] s2=s2[:N] a1,a2=0,0 for i in range(N): if s1[i]!=S[i]: ...
Codeforces Round 135 (Div. 2)
CF
2,012
2
256
Color Stripe
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells.
The first input line contains two integers n and k (1 ≤ n ≤ 5·105; 2 ≤ k ≤ 26). The second line contains n uppercase English letters. Letter "A" stands for the first color, letter "B" stands for the second color and so on. The first k English letters may be used. Each letter represents the color of the corresponding ce...
Print a single integer — the required minimum number of repaintings. In the second line print any possible variant of the repainted stripe.
null
null
[{"input": "6 3\nABBACC", "output": "2\nABCACA"}, {"input": "3 2\nBBB", "output": "1\nBAB"}]
1,600
["brute force", "dp", "greedy"]
87
[{"input": "6 3\r\nABBACC\r\n", "output": "2\r\nABCACA\r\n"}, {"input": "3 2\r\nBBB\r\n", "output": "1\r\nBAB\r\n"}, {"input": "1 2\r\nA\r\n", "output": "0\r\nA\r\n"}, {"input": "1 26\r\nZ\r\n", "output": "0\r\nZ\r\n"}, {"input": "2 2\r\nAA\r\n", "output": "1\r\nAB\r\n"}, {"input": "2 2\r\nBA\r\n", "output": "0\r\nBA\r...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, k = map(int, f.readline().split()) original = f.readline().strip() with open(output_path) as f: expected_count = int(f.readline().strip()) with open(submission_path) as f: ...
true
581/C
581
C
Python 3
TESTS
4
46
307,200
228991951
import math from collections import defaultdict d=defaultdict(lambda:0) def sort_by_units_digit(lst): return sorted(lst, key=lambda x: str(x)[-1]) n,k = map(int,input().split()) kk=[k].copy()[0] x = sort_by_units_digit(list(map(int,input().split()))) ans=0 for i in x: if i<100 and k-(10-i%10)>=0 and i%10!=0...
98
140
14,233,600
232693185
import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log, log2, pi, ceil from collections import defaultdict as dd from bisect import bisect_left as bl, bisect_right as br from heapq import * from collections import deque, Counter as ctr inp = lambda: int(input()) strng = lambda:...
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
849/B
849
B
Python 3
TESTS
12
61
307,200
31141772
n = int(input()) p = list(map(int, input().split(' '))) rest = [True] * n ct = 0 slp = float('inf') def slope(i, j): return (p[j] - p[i]) / (j - i) def restcol(): l = [i for i in range(n) if rest[i]] if len(l) == 1: return True s = slope(l[0], l[1]) for i in range(2,len(l)): if slo...
52
62
307,200
29984867
n = int(input()) y = list(map(int, input().split())) def check(d): return len(set(2 * yi - d * i for i, yi in enumerate(y))) == 2 s = 2*(y[1]-y[0]), 2*(y[2]-y[1]), y[2] - y[0] print('Yes' if any(check(d) for d in s) else 'No')
Codeforces Round 431 (Div. 2)
CF
2,017
1
256
Tell Your World
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, yi). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes th...
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points. The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point.
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower).
null
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, ...
[{"input": "5\n7 5 8 6 9", "output": "Yes"}, {"input": "5\n-1 -2 0 0 -5", "output": "No"}, {"input": "5\n5 4 3 2 1", "output": "No"}, {"input": "5\n1000000000 0 0 0 0", "output": "Yes"}]
1,600
["brute force", "geometry"]
52
[{"input": "5\r\n7 5 8 6 9\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-1 -2 0 0 -5\r\n", "output": "No\r\n"}, {"input": "5\r\n5 4 3 2 1\r\n", "output": "No\r\n"}, {"input": "5\r\n1000000000 0 0 0 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n1000000000 1 0 -999999999 -1000000000\r\n", "output": "Yes\r\n"}, {"input": "...
false
stdio
null
true
584/C
584
C
PyPy 3-64
TESTS
8
62
0
180252040
import sys input = sys.stdin.buffer.readline def process(s1, s2, t): n = len(s1) same = [] diff = [] for i in range(n): if s1[i]==s2[i]: same.append(i) else: diff.append(i) answer = [None for i in range(n)] """ a = a b = a c= diff-2a d= d...
78
109
7,884,800
197506049
n, t = map(int, input().split()) a, b = input(), input() ans = [] s = d = 0 for i, j in zip(a, b): if i == j: s += 1 else: d += 1 if t < (d + 1) // 2: print(-1) exit() x = min(n - t, s) y = z = max(n - t - s, 0) def f(a, b): for i in range(97, 123): if chr(i) not in [a, b]: return chr(i) for i in rang...
Codeforces Round 324 (Div. 2)
CF
2,015
1
256
Marina and Vasya
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and ...
The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters.
Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.
null
null
[{"input": "3 2\nabc\nxyc", "output": "ayd"}, {"input": "1 0\nc\nb", "output": "-1"}]
1,700
["constructive algorithms", "greedy", "strings"]
78
[{"input": "3 2\r\nabc\r\nxyc\r\n", "output": "bac"}, {"input": "1 0\r\nc\r\nb\r\n", "output": "-1\r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "b"}, {"input": "2 1\r\naa\r\naa\r\n", "output": "ab"}, {"input": "3 1\r\nbcb\r\nbca\r\n", "output": "bcc"}, {"input": "4 3\r\nccbb\r\ncaab\r\n", "output": "cbca"}, {"input"...
false
stdio
import sys def hamming(s1, s2): return sum(c1 != c2 for c1, c2 in zip(s1, s2)) def solution_exists(n, t, s1, s2): a = sum(c1 == c2 for c1, c2 in zip(s1, s2)) d = n - a min_k = max(d - t, 0) max_k = min(d // 2, a + d - t) return min_k <= max_k def main(): input_path = sys.argv[1] outpu...
true
847/E
847
E
Python 3
TESTS
7
46
0
160965901
import sys sys.setrecursionlimit(2 * 10 ** 6) def test(): pass def main(): _ = input() s = input() def f(l): ls = list(s) ps = [] for i, c in enumerate(ls): if c == 'P': ps.append([i, l]) i = 0 pi = 0 while i < len(ls) and...
77
187
23,142,400
30484065
from sys import stdin, stdout n = int(stdin.readline()) s = stdin.readline().strip() mins = [] packs = [] for i in range(len(s)): if s[i] == '*': mins.append(i) elif s[i] == 'P': packs.append(i) l, r = -1, 2 * len(s) + 1 while r - l > 1: m = (l + r) >> 1 test1 = mins[:] test...
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
841/B
841
B
PyPy 3-64
TESTS
52
358
107,724,800
170916303
n = int(input()) a = list(map(int, input().split(' '))) even = 0 odd = 0 for number in a: if number % 2 == 0: even += 1 else: odd += 1 if sum(a) % 2 == 1: print('First') else: if even == n or odd == n: print('Second') else: print('First')
88
280
76,902,400
233081769
from sys import stdin, stdout def main(): n=int(stdin.readline().strip()) arr=[int(x) for x in stdin.readline().strip().split(' ')] even,odd = 0,0 for x in arr: if x%2==1: odd+=1 else: even+=1 return 'Second' if odd==0 else 'First' stdout.write(str(main()))
Codeforces Round 429 (Div. 2)
CF
2,017
2
256
Godsend
Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts a...
First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array. Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
null
In first sample first player remove whole array in one move and win. In second sample first player can't make a move and lose.
[{"input": "4\n1 3 2 3", "output": "First"}, {"input": "2\n2 2", "output": "Second"}]
1,100
["games", "math"]
88
[{"input": "4\r\n1 3 2 3\r\n", "output": "First\r\n"}, {"input": "2\r\n2 2\r\n", "output": "Second\r\n"}, {"input": "4\r\n2 4 6 8\r\n", "output": "Second\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "First\r\n"}, {"input": "4\r\n720074544 345031254 849487632 80870826\r\n", "output": "Second\r\n"}, {"input": "1\r\n0...
false
stdio
null
true
845/C
845
C
Python 3
TESTS
19
982
22,118,400
30829111
n = int(input()) v = [] for i in range(n): s = input(); s = [int(x) for x in s.split()] v.append(s) v.sort(key=lambda x: x[1]) w = [] last = -1 for i in range(n): if v[i][0] <= last: w.append(v[i]) else: last = v[i][1] last = -1 f=1 for i in range(len(w)): if w[i][0]<=last: ...
58
624
24,268,800
129916131
s = [tuple(map(int, input().split())) for i in range(int(input()))] s.sort(key=lambda q: q[0]) a = b = -1 q = 'YES' for l, r in s: if a >= l: q = 'NO' break a = r if b < a: a, b = b, a print(q)
Educational Codeforces Round 27
ICPC
2,017
2
256
Two TVs
Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment li and ends at moment ri. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given mom...
The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of shows. Each of the next n lines contains two integers li and ri (0 ≤ li < ri ≤ 109) — starting and ending time of i-th show.
If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).
null
null
[{"input": "3\n1 2\n2 3\n4 5", "output": "YES"}, {"input": "4\n1 2\n2 3\n2 3\n1 2", "output": "NO"}]
1,500
["data structures", "greedy", "sortings"]
58
[{"input": "3\r\n1 2\r\n2 3\r\n4 5\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2\r\n2 3\r\n2 3\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 1\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2\r\n2 3\r\n2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 100\r\n0 100\r\n0 100\r\n", "output": "NO...
false
stdio
null
true
33/C
33
C
PyPy 3
TESTS
15
310
30,822,400
126934893
def process(A): n = len(A) answer = max(sum(A), -1*sum(A)) if True: max_pre = [0, -1] plus = 0 minus = 0 for i in range(n): x = A[i] if x <= 0: minus+=(-1*x) else: plus+=x entry = [minus-plus, i] ...
89
248
7,577,600
29603420
n = int(input()) values = list(map(int, input().split())) best_infix = infix = 0 for x in values: infix = max(0, infix + x) best_infix = max(best_infix, infix) print(2 * best_infix - sum(values))
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
Wonderful Randomized Sum
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th...
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
The first and the only line of the output should contain the answer to the problem.
null
null
[{"input": "3\n-1 -2 -3", "output": "6"}, {"input": "5\n-4 2 0 5 0", "output": "11"}, {"input": "5\n-1 10 -5 10 -2", "output": "18"}]
1,800
["greedy"]
89
[{"input": "3\r\n-1 -2 -3\r\n", "output": "6\r\n"}, {"input": "5\r\n-4 2 0 5 0\r\n", "output": "11\r\n"}, {"input": "5\r\n-1 10 -5 10 -2\r\n", "output": "18\r\n"}, {"input": "1\r\n-3\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 -5 -2\r\n", "output": "12\r\n"}, {"input": "7\r\n-17 6 5 0 1 4 -1\r\n", "output": "34\r\n"}...
false
stdio
null
true