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
717/D
717
D
PyPy 3
TESTS
5
140
1,945,600
64629565
import sys readline = sys.stdin.readline n, x = map(int,readline().split()) tmp = list(map(float,readline().split())) for i in range(128 - x - 1): tmp.append(0) def MatM(a,b): c = [0 for i in range(128)] for i in range(127): for j in range(127): c[i ^ j] += a[i] * b[j] return c...
11
108
1,945,600
103911369
import os from io import BytesIO #input = BytesIO(os.read(0, os.fstat(0).st_size)).readline def main(): def mult(m1,m2): ans = [0] * 128 for i in range(128): for j in range(128): ans[i^j] += m1[i] * m2[j] return ans def power(number, n): res = ...
Bubble Cup 9 - Finals [Online Mirror]
ICPC
2,016
1
256
Dexterina’s Lab
Dexterina and Womandark have been arch-rivals since they’ve known each other. Since both are super-intelligent teenage girls, they’ve always been trying to solve their disputes in a peaceful and nonviolent way. After god knows how many different challenges they’ve given to one another, their score is equal and they’re ...
The first line of the input contains two integers n (1 ≤ n ≤ 109) and x (1 ≤ x ≤ 100) — the number of heaps and the maximum number of objects in a heap, respectively. The second line contains x + 1 real numbers, given with up to 6 decimal places each: P(0), P(1), ... , P(X). Here, P(i) is the probability of a heap havi...
Output a single real number, the probability that the first player wins. The answer will be judged as correct if it differs from the correct answer by at most 10 - 6.
null
null
[{"input": "2 2\n0.500000 0.250000 0.250000", "output": "0.62500000"}]
1,900
["games", "matrices", "probabilities"]
11
[{"input": "2 2\r\n0.500000 0.250000 0.250000\r\n", "output": "0.62500000\r\n"}, {"input": "9 9\r\n0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000\r\n", "output": "0.93687014\r\n"}, {"input": "1000001 5\r\n0.000000 0.300000 0.000000 0.500000 0.000000 0.200000\r\n", "output": "1...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] try: with open(correct_output_path, 'r') as f: correct_line = f.read().strip() correct_val = float(correct_line) except: print(0) retur...
true
292/A
292
A
PyPy 3-64
TESTS
4
92
0
225776694
n=int(input()) t=[] c=[] for i in range(n): x,y=map(int,input().split()) t.append(x) c.append(y) q=c[0] s=c[0] for i in range(n-1): p=t[i+1]-t[i] s=s-p+c[i+1] q=max(q,s) print(t[n-1]+s,end=" ") print(q)
38
92
0
168980605
n = eval(input()) cnt = 0 lt = 0 mn = 0 for i in range(n): t, c = input().split() t, c = int(t), int(c) cnt -= t - lt lt = t if cnt < 0: cnt = 0 cnt += c if cnt > mn: mn = cnt print(cnt + t, mn)
Croc Champ 2013 - Round 1
CF
2,013
2
256
SMSC
Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC. For that, he asked to give him the statistics of the performance of the SMSC for some period of time. In ...
The first line contains a single integer n (1 ≤ n ≤ 103) — the number of tasks of the SMSC. Next n lines contain the tasks' descriptions: the i-th line contains two space-separated integers ti and ci (1 ≤ ti, ci ≤ 106) — the time (the second) when the i-th task was received and the number of messages to send, correspon...
In a single line print two space-separated integers — the time when the last text message was sent and the maximum queue size at a certain moment of time.
null
In the first test sample: - second 1: the first message has appeared in the queue, the queue's size is 1; - second 2: the first message is sent, the second message has been received, the queue's size is 1; - second 3: the second message is sent, the queue's size is 0, Thus, the maximum size of the queue is 1, the las...
[{"input": "2\n1 1\n2 1", "output": "3 1"}, {"input": "1\n1000000 10", "output": "1000010 10"}, {"input": "3\n3 3\n4 3\n5 3", "output": "12 7"}]
1,100
["implementation"]
38
[{"input": "2\r\n1 1\r\n2 1\r\n", "output": "3 1\r\n"}, {"input": "1\r\n1000000 10\r\n", "output": "1000010 10\r\n"}, {"input": "3\r\n3 3\r\n4 3\r\n5 3\r\n", "output": "12 7\r\n"}, {"input": "1\r\n1 1\r\n", "output": "2 1\r\n"}, {"input": "2\r\n1 11\r\n100 10\r\n", "output": "110 11\r\n"}, {"input": "4\r\n1 10\r\n2 9\r...
false
stdio
null
true
292/A
292
A
Python 3
TESTS
4
92
0
158242217
import sys input = sys.stdin.readline n = int(input()) v, s, x, t0 = 0, 0, 0, 0 for i in range(n): t, c = map(int, input().split()) if i == 0: v = x = c t0 = t else: x += c - max(0, (t - t0)) if x > v: v = x t0 = t if i == n-1: s = t + x prin...
38
92
4,505,600
192173838
# LUOGU_RID: 101473903 (n,), *a = [[*(map(int, s.split()))] for s in open(0)] p = q = r = 0 for x, y in a: q = max(0, p + q - x) + y r = max(r, q) p = x print(p+q, r)
Croc Champ 2013 - Round 1
CF
2,013
2
256
SMSC
Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC. For that, he asked to give him the statistics of the performance of the SMSC for some period of time. In ...
The first line contains a single integer n (1 ≤ n ≤ 103) — the number of tasks of the SMSC. Next n lines contain the tasks' descriptions: the i-th line contains two space-separated integers ti and ci (1 ≤ ti, ci ≤ 106) — the time (the second) when the i-th task was received and the number of messages to send, correspon...
In a single line print two space-separated integers — the time when the last text message was sent and the maximum queue size at a certain moment of time.
null
In the first test sample: - second 1: the first message has appeared in the queue, the queue's size is 1; - second 2: the first message is sent, the second message has been received, the queue's size is 1; - second 3: the second message is sent, the queue's size is 0, Thus, the maximum size of the queue is 1, the las...
[{"input": "2\n1 1\n2 1", "output": "3 1"}, {"input": "1\n1000000 10", "output": "1000010 10"}, {"input": "3\n3 3\n4 3\n5 3", "output": "12 7"}]
1,100
["implementation"]
38
[{"input": "2\r\n1 1\r\n2 1\r\n", "output": "3 1\r\n"}, {"input": "1\r\n1000000 10\r\n", "output": "1000010 10\r\n"}, {"input": "3\r\n3 3\r\n4 3\r\n5 3\r\n", "output": "12 7\r\n"}, {"input": "1\r\n1 1\r\n", "output": "2 1\r\n"}, {"input": "2\r\n1 11\r\n100 10\r\n", "output": "110 11\r\n"}, {"input": "4\r\n1 10\r\n2 9\r...
false
stdio
null
true
292/A
292
A
Python 3
TESTS
4
218
0
66020618
n = int(input()) l = [] for i in range(n): c,t = map(int,input().split()) l.append((c,t)) queue = l[0][1] z = queue for i in range(1,n): queue = queue + l[i][1] queue = queue - (l[i][0]-l[i-1][0]) z = max(z,queue) print(l[i][0]+queue,z)
38
124
0
10659275
import sys import math n = int(input()) a, b = list(map(int, input().split())) vmax = b for i in range(1, n): c, d = list(map(int, input().split())) b = max(0, b - (c - a)) a = c b += d vmax = max(b, vmax) print(a + b, vmax)
Croc Champ 2013 - Round 1
CF
2,013
2
256
SMSC
Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC. For that, he asked to give him the statistics of the performance of the SMSC for some period of time. In ...
The first line contains a single integer n (1 ≤ n ≤ 103) — the number of tasks of the SMSC. Next n lines contain the tasks' descriptions: the i-th line contains two space-separated integers ti and ci (1 ≤ ti, ci ≤ 106) — the time (the second) when the i-th task was received and the number of messages to send, correspon...
In a single line print two space-separated integers — the time when the last text message was sent and the maximum queue size at a certain moment of time.
null
In the first test sample: - second 1: the first message has appeared in the queue, the queue's size is 1; - second 2: the first message is sent, the second message has been received, the queue's size is 1; - second 3: the second message is sent, the queue's size is 0, Thus, the maximum size of the queue is 1, the las...
[{"input": "2\n1 1\n2 1", "output": "3 1"}, {"input": "1\n1000000 10", "output": "1000010 10"}, {"input": "3\n3 3\n4 3\n5 3", "output": "12 7"}]
1,100
["implementation"]
38
[{"input": "2\r\n1 1\r\n2 1\r\n", "output": "3 1\r\n"}, {"input": "1\r\n1000000 10\r\n", "output": "1000010 10\r\n"}, {"input": "3\r\n3 3\r\n4 3\r\n5 3\r\n", "output": "12 7\r\n"}, {"input": "1\r\n1 1\r\n", "output": "2 1\r\n"}, {"input": "2\r\n1 11\r\n100 10\r\n", "output": "110 11\r\n"}, {"input": "4\r\n1 10\r\n2 9\r...
false
stdio
null
true
292/A
292
A
PyPy 3
TESTS
4
310
0
73885523
import sys import math #to read string get_string = lambda: sys.stdin.readline().strip() #to read list of integers get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) ) #to read integers get_int = lambda: int(sys.stdin.readline()) #to print fast pt = lambda x: sys.stdout.write(str(x)+'\n') #---...
38
124
1,536,000
187627554
import sys input = lambda: sys.stdin.readline().rstrip("\n\r") def solve(): n = int(input()) a = [list(map(int, input().split())) for i in range(n)] curr = top = a[0][1] for i in range(1, n): dist = a[i][0] - a[i - 1][0] curr = max(0, curr - dist) curr += a[i][1] ...
Croc Champ 2013 - Round 1
CF
2,013
2
256
SMSC
Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC. For that, he asked to give him the statistics of the performance of the SMSC for some period of time. In ...
The first line contains a single integer n (1 ≤ n ≤ 103) — the number of tasks of the SMSC. Next n lines contain the tasks' descriptions: the i-th line contains two space-separated integers ti and ci (1 ≤ ti, ci ≤ 106) — the time (the second) when the i-th task was received and the number of messages to send, correspon...
In a single line print two space-separated integers — the time when the last text message was sent and the maximum queue size at a certain moment of time.
null
In the first test sample: - second 1: the first message has appeared in the queue, the queue's size is 1; - second 2: the first message is sent, the second message has been received, the queue's size is 1; - second 3: the second message is sent, the queue's size is 0, Thus, the maximum size of the queue is 1, the las...
[{"input": "2\n1 1\n2 1", "output": "3 1"}, {"input": "1\n1000000 10", "output": "1000010 10"}, {"input": "3\n3 3\n4 3\n5 3", "output": "12 7"}]
1,100
["implementation"]
38
[{"input": "2\r\n1 1\r\n2 1\r\n", "output": "3 1\r\n"}, {"input": "1\r\n1000000 10\r\n", "output": "1000010 10\r\n"}, {"input": "3\r\n3 3\r\n4 3\r\n5 3\r\n", "output": "12 7\r\n"}, {"input": "1\r\n1 1\r\n", "output": "2 1\r\n"}, {"input": "2\r\n1 11\r\n100 10\r\n", "output": "110 11\r\n"}, {"input": "4\r\n1 10\r\n2 9\r...
false
stdio
null
true
963/B
963
B
PyPy 3-64
TESTS
6
124
2,764,800
163182275
import sys from collections import deque input = lambda: sys.stdin.readline().rstrip("\r\n") n=int(input()) va=[deque() for i in range(n+1)] vb=[deque() for i in range(n+1)] via=[1 for i in range(n+1)] l=deque(map(int,input().split())) for i in range(len(l)): if l[i]==0: continue va[i+1].append(l[i]) ...
95
701
45,670,400
126191783
import sys input = sys.stdin.readline n = int(input()) if n%2 == 0: print("NO") exit() parent = list(map(int,input().split())) print("YES") s = [0]*n G = [[] for _ in range(n)] root = -1 for i in range(n): parent[i] -= 1 if parent[i] != -1: G[parent[i]].append(i) else: root = i st...
Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 1)
CF
2,018
1
256
Destruction of a Tree
You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted. Destroy all vertices in the given tree or...
The first line contains integer n (1 ≤ n ≤ 2·105) — number of vertices in a tree. The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ n). If pi ≠ 0 there is an edge between vertices i and pi. It is guaranteed that the given graph is a tree.
If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes). If it's possible to destroy all vertices, in the next n lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any.
null
In the first example at first you have to remove the vertex with index 1 (after that, the edges (1, 2) and (1, 4) are removed), then the vertex with index 2 (and edges (2, 3) and (2, 5) are removed). After that there are no edges in the tree, so you can remove remaining vertices in any order.
[{"input": "5\n0 1 2 1 2", "output": "YES\n1\n2\n3\n5\n4"}, {"input": "4\n0 1 2 3", "output": "NO"}]
2,000
["constructive algorithms", "dfs and similar", "dp", "greedy", "trees"]
95
[{"input": "5\r\n0 1 2 1 2\r\n", "output": "YES\r\n1\r\n2\r\n3\r\n5\r\n4\r\n"}, {"input": "4\r\n0 1 2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n1\r\n"}, {"input": "8\r\n3 1 4 0 4 2 4 5\r\n", "output": "NO\r\n"}, {"input": "100\r\n81 96 65 28 4 40 5 49 5 89 48 70 94 70 17 58 58 1 61 19 45 33...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n = int(f.readline()) p = list(map(int, f.readline().split())) # Read reference output with open(output_path) as f_ref: ...
true
519/D
519
D
Python 3
TESTS
4
62
0
119197834
if __name__ == '__main__': likeability = list(map(int, input().split())) s = input().lower() add = [0] * len(s) add[0] = likeability[ord(s[0])-97] freq = {} freq[s[0]] = 1 for i in range(1, len(s)): add[i] = add[i-1] + likeability[ord(s[i])-97] if s[i] in freq.keys(): ...
47
140
22,732,800
153144112
from bisect import bisect_left nums = list(map(int, input().split(' '))) s = input() pre = [] tot = 0 d = {} for i in range(len(s)): tot += nums[ord(s[i]) - ord('a')] pre.append(tot) if s[i] not in d: d[s[i]] = [] d[s[i]].append(i) ans = 0 for ch in d: g = {} if len(d[ch]) == 1: ...
Codeforces Round 294 (Div. 2)
CF
2,015
2
256
A and B and Interesting Substrings
A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ...
The first line contains 26 integers xa, xb, ..., xz ( - 105 ≤ xi ≤ 105) — the value assigned to letters a, b, c, ..., z respectively. The second line contains string s of length between 1 and 105 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.
Print the answer to the problem.
null
In the first sample test strings satisfying the condition above are abca and bcab. In the second sample test strings satisfying the condition above are two occurences of aa.
[{"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab", "output": "2"}, {"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa", "output": "2"}]
1,800
["data structures", "dp", "two pointers"]
47
[{"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\r\nxabcab\r\n", "output": "2\r\n"}, {"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\r\naaa\r\n", "output": "2\r\n"}, {"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\r\naabbccdd\r\n", "output": "4\r\n"}, {"input": "-3 4 -4 -...
false
stdio
null
true
621/C
621
C
PyPy 3-64
TESTS
2
62
102,400
219506212
import sys input = lambda: sys.stdin.readline().rstrip() import math from heapq import heappush , heappop from collections import defaultdict,deque,Counter from bisect import * N,P = map(int, input().split()) A = [] for _ in range(N): l,r = map(int, input().split()) A.append((l,r)) def deal(l,r): c1 =...
94
171
11,571,200
219506548
import sys input = lambda: sys.stdin.readline().rstrip() import math from heapq import heappush , heappop from collections import defaultdict,deque,Counter from bisect import * N,P = map(int, input().split()) A = [] for _ in range(N): l,r = map(int, input().split()) A.append((l,r)) def deal(l,r): c1 =...
Codeforces Round 341 (Div. 2)
CF
2,016
2
256
Wet Shark and Flowers
There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too. Each shark will grow some number of flowers si. For i-th shark value si is random integer equiprobably chosen in range from...
The first line of the input contains two space-separated integers n and p (3 ≤ n ≤ 100 000, 2 ≤ p ≤ 109) — the number of sharks and Wet Shark's favourite prime number. It is guaranteed that p is prime. The i-th of the following n lines contains information about i-th shark — two space-separated integers li and ri (1 ≤...
Print a single real number — the expected number of dollars that the sharks receive in total. You 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 correc...
null
A prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime. Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of ...
[{"input": "3 2\n1 2\n420 421\n420420 420421", "output": "4500.0"}, {"input": "3 5\n1 4\n2 3\n11 14", "output": "0.0"}]
1,700
["combinatorics", "math", "number theory", "probabilities"]
94
[{"input": "3 2\r\n1 2\r\n420 421\r\n420420 420421\r\n", "output": "4500.0\r\n"}, {"input": "3 5\r\n1 4\r\n2 3\r\n11 14\r\n", "output": "0.0\r\n"}, {"input": "3 3\r\n3 3\r\n2 4\r\n1 1\r\n", "output": "4666.666666666667\r\n"}, {"input": "5 5\r\n5 204\r\n420 469\r\n417 480\r\n442 443\r\n44 46\r\n", "output": "3451.25\r\n...
false
stdio
import sys def read_number(path): with open(path, 'r') as f: lines = [line.strip() for line in f.readlines() if line.strip()] if len(lines) != 1: return None try: return float(lines[0]) except ValueError: return None def main(): input_path = ...
true
761/D
761
D
Python 3
TESTS
0
46
5,529,600
25956672
#!/usr/bin/env python3 from sys import stdin,stdout def ri(): return map(int, input().split()) n, l, r = ri() a = list(ri()) p = list(ri()) pi = [i for i in range(n)] pi.sort(key=lambda e: p[e]) b = [0 for i in range(n)] i = p[0] b[i] = l cp = b[i] - a[i] for ii in range(1,n): i = pi[ii] cp +=1 b[...
63
343
18,841,600
44333931
R = lambda: map(int, input().split()) n, l, r = R() a, d = list(R()), list(R()) b = [av + cv for av, cv in zip(a, d)] mi = min(b) if mi < l: b = [bv + l - mi for bv in b] mx = max(b) if mx > r: b = [bv - (mx - r) for bv in b] if l <= min(b) <= max(b) <= r: print(' '.join(map(str, b))) else: print(-1)
Codeforces Round 394 (Div. 2)
CF
2,017
2
256
Dasha and Very Difficult Problem
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: ci = bi - ai. About sequences a and b we know that their elements are in the range from l to...
The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ 109) — the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a1, a2, ..., an (l ≤ ai ≤ r) — the elements of the sequence a. The next line contains n distinct in...
If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers — the elements of any suitable sequence b.
null
Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4].
[{"input": "5 1 5\n1 1 1 1 1\n3 1 5 4 2", "output": "3 1 5 4 2"}, {"input": "4 2 9\n3 4 8 9\n3 2 1 4", "output": "2 2 2 9"}, {"input": "6 1 5\n1 1 1 1 1 1\n2 3 5 4 1 6", "output": "-1"}]
1,700
["binary search", "brute force", "constructive algorithms", "greedy", "sortings"]
63
[{"input": "5 1 5\r\n1 1 1 1 1\r\n3 1 5 4 2\r\n", "output": "3 1 5 4 2 "}, {"input": "4 2 9\r\n3 4 8 9\r\n3 2 1 4\r\n", "output": "2 2 2 9 "}, {"input": "6 1 5\r\n1 1 1 1 1 1\r\n2 3 5 4 1 6\r\n", "output": "-1\r\n"}, {"input": "5 1 7\r\n1 4 4 6 5\r\n5 2 1 4 3\r\n", "output": "2 2 1 6 4 "}, {"input": "5 10 100\r\n12 14 ...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: return f.read().strip() def main(input_path, output_path, submission_path): # Read input with open(input_path, 'r') as f: lines = f.readlines() n, l, r = map(int, lines[0].split()) a = list(map(int, lines[1].split())) p...
true
764/B
764
B
Python 3
TESTS
10
529
15,564,800
55088513
n=int(input()) L=[int(x) for x in input().split()] if n%2==1: n+=1 for i in range(1,n//2,2): L[i-1],L[-1*i]=L[-1*i],L[i-1] for x in L: print(x,end=" ")
34
139
15,462,400
143268136
n = int(input()) s = [x for x in input().split()] #if n%2!=0: top = (n+1)//2 for i in range(1,top+1,2): temp = s[i-1] s[i-1] = s[n-i] s[n-i] = temp print(" ".join(s))
Codeforces Round 395 (Div. 2)
CF
2,017
1
256
Timofey and cubes
Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number ai, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose t...
The first line contains single integer n (1 ≤ n ≤ 2·105) — the number of cubes. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109), where ai is the number written on the i-th cube after Dima has changed their order.
Print n integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.
null
Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 2. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 3. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 4. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 5. At fourth operation we reverse just middle element, so nothing has cha...
[{"input": "7\n4 3 7 6 9 1 2", "output": "2 3 9 6 7 1 4"}, {"input": "8\n6 1 4 2 5 6 9 2", "output": "2 1 6 2 5 4 9 6"}]
900
["constructive algorithms", "implementation"]
34
[{"input": "7\r\n4 3 7 6 9 1 2\r\n", "output": "2 3 9 6 7 1 4"}, {"input": "8\r\n6 1 4 2 5 6 9 2\r\n", "output": "2 1 6 2 5 4 9 6"}, {"input": "1\r\n1424\r\n", "output": "1424"}, {"input": "9\r\n-7 9 -4 9 -6 11 15 2 -10\r\n", "output": "-10 9 15 9 -6 11 -4 2 -7"}, {"input": "2\r\n21968 5686\r\n", "output": "5686 21968"...
false
stdio
null
true
518/C
518
C
PyPy 3-64
TESTS
2
46
0
194402404
import sys input = sys.stdin.readline n, c, k = map(int, input().split()) w = list(map(int, input().split())) d = [0]*(n+1) for i, j in enumerate(w): d[j] = i for i in map(int, input().split()): q = d[i]//k c += q if q > 0: w[d[i]], w[d[i]-1], d[i], d[w[d[i]-1]] = w[d[i]-1], w[d[i]], d[i]-1, d[...
43
124
19,763,200
194404014
import sys input = sys.stdin.readline n, c, k = map(int, input().split()) w = list(map(int, input().split())) d = [0]*(n+1) for i, j in enumerate(w): d[j] = i for i in map(int, input().split()): a = d[i] c += d[i]//k if d[i] > 0: b = a - 1 j = w[b] w[a], w[b], d[i], d[j] = w[b],...
Codeforces Round 293 (Div. 2)
CF
2,015
1
256
Anya and Smartphone
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th ...
The first line of the input contains three numbers n, m, k (1 ≤ n, m, k ≤ 105) — the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen. The next line contains n integers, permutation a1, a2, ..., an — the...
Print a single number — the number of gestures that Anya needs to make to launch all the applications in the desired order.
null
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8. After application 7 is launched, we get the new arrangement of the icons — (123)(457)(68). To launch i...
[{"input": "8 3 3\n1 2 3 4 5 6 7 8\n7 8 1", "output": "7"}, {"input": "5 4 2\n3 1 5 2 4\n4 4 4 4", "output": "8"}]
1,600
["constructive algorithms", "data structures", "implementation"]
43
[{"input": "8 3 3\r\n1 2 3 4 5 6 7 8\r\n7 8 1\r\n", "output": "7\r\n"}, {"input": "5 4 2\r\n3 1 5 2 4\r\n4 4 4 4\r\n", "output": "8\r\n"}, {"input": "10 10 3\r\n1 2 3 4 5 6 7 8 9 10\r\n2 3 4 5 6 7 8 9 10 1\r\n", "output": "25\r\n"}, {"input": "10 12 3\r\n6 1 2 9 3 10 8 5 7 4\r\n3 9 9 4 8 2 3 8 10 8 3 4\r\n", "output": ...
false
stdio
null
true
1006/A
1006
A
Python 3
TESTS
8
109
307,200
92581389
x = int(input()) l=list(map(int,input().split())) for i in range(x): if x>2 and x<10**9: if l[i]%2==0: l[i]-=1 if x==1 and x<10**9: if l[i]%2==0: l[i]-=1 else: l[i]+=1 print(*l)
18
31
0
223294695
n = int(input()) nums = list(map(int, input().split())) for num in nums: if num % 2 == 0: print(num-1, end = " ") else: print(num, end = " ")
Codeforces Round 498 (Div. 3)
ICPC
2,018
1
256
Adjacent Replacements
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: - Replace ea...
The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array.
Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array.
null
The first example is described in the problem statement.
[{"input": "5\n1 2 4 5 10", "output": "1 1 3 5 9"}, {"input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000", "output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"}]
800
["implementation"]
18
[{"input": "5\r\n1 2 4 5 10\r\n", "output": "1 1 3 5 9\r\n"}, {"input": "10\r\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\r\n", "output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999\r\n"}, {"input": "1\r\n999999999\r\n", "output": "999999999\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "99...
false
stdio
null
true
764/B
764
B
Python 3
TESTS
10
233
22,937,600
24396664
n = int(input()) a = list(map(int, input().split())) for i in range(0, n // 2 + 1, 2): t = a[i] a[i] = a[n - 1 - i] a[n - 1 - i] = t if n % 2 == 0: t = a[n//2-1] a[n//2-1] = a[n//2] a[n//2] = t print(' '.join(map(str, a)))
34
139
19,148,800
24477774
a =input() k =input() k =k.split(' ') l =len(k) i = 0 while i<l//2: k[i],k[-(i+1)]=k[-(i+1)],k[i] i+=2 print(' '.join(k))
Codeforces Round 395 (Div. 2)
CF
2,017
1
256
Timofey and cubes
Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number ai, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose t...
The first line contains single integer n (1 ≤ n ≤ 2·105) — the number of cubes. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109), where ai is the number written on the i-th cube after Dima has changed their order.
Print n integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.
null
Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 2. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 3. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 4. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 5. At fourth operation we reverse just middle element, so nothing has cha...
[{"input": "7\n4 3 7 6 9 1 2", "output": "2 3 9 6 7 1 4"}, {"input": "8\n6 1 4 2 5 6 9 2", "output": "2 1 6 2 5 4 9 6"}]
900
["constructive algorithms", "implementation"]
34
[{"input": "7\r\n4 3 7 6 9 1 2\r\n", "output": "2 3 9 6 7 1 4"}, {"input": "8\r\n6 1 4 2 5 6 9 2\r\n", "output": "2 1 6 2 5 4 9 6"}, {"input": "1\r\n1424\r\n", "output": "1424"}, {"input": "9\r\n-7 9 -4 9 -6 11 15 2 -10\r\n", "output": "-10 9 15 9 -6 11 -4 2 -7"}, {"input": "2\r\n21968 5686\r\n", "output": "5686 21968"...
false
stdio
null
true
764/B
764
B
Python 3
TESTS
10
218
23,756,800
25575354
'''input 8 6 1 4 2 5 6 9 2 ''' n = int(input()) s = list(map(int, input().split())) t = s[::-1] if n % 2 == 1: for x in range(0, n, 2): s[x] = t[x] else: for y in range(0, n//2, 2): s[y] = t[y] for z in range(n//2+1, n, 2): s[z] = t[z] print(" ".join(map(str, s)))
34
139
20,172,800
24446713
n = int(input()) a = input().split() for i in range(0, n // 2, 2): a[i], a[n - i - 1] = a[n - i - 1], a[i] print( " ".join(a))
Codeforces Round 395 (Div. 2)
CF
2,017
1
256
Timofey and cubes
Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number ai, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose t...
The first line contains single integer n (1 ≤ n ≤ 2·105) — the number of cubes. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109), where ai is the number written on the i-th cube after Dima has changed their order.
Print n integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.
null
Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 2. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 3. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 4. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 5. At fourth operation we reverse just middle element, so nothing has cha...
[{"input": "7\n4 3 7 6 9 1 2", "output": "2 3 9 6 7 1 4"}, {"input": "8\n6 1 4 2 5 6 9 2", "output": "2 1 6 2 5 4 9 6"}]
900
["constructive algorithms", "implementation"]
34
[{"input": "7\r\n4 3 7 6 9 1 2\r\n", "output": "2 3 9 6 7 1 4"}, {"input": "8\r\n6 1 4 2 5 6 9 2\r\n", "output": "2 1 6 2 5 4 9 6"}, {"input": "1\r\n1424\r\n", "output": "1424"}, {"input": "9\r\n-7 9 -4 9 -6 11 15 2 -10\r\n", "output": "-10 9 15 9 -6 11 -4 2 -7"}, {"input": "2\r\n21968 5686\r\n", "output": "5686 21968"...
false
stdio
null
true
764/B
764
B
Python 3
TESTS
10
171
15,872,000
89821168
n = int(input()) s = input().split() if(n%2==0): m=int(n//2)-1 else: m=int(n//2) for i in range(m): if(i%2==0): s[i],s[n-i-1] = s[n-i-1],s[i] print(" ".join(s))
34
139
20,172,800
24638098
n, a = int(input()), input().split() for i in range(0, n // 2, 2): a[i], a[n - i - 1] = a[n - i - 1], a[i] print(' '.join(a))
Codeforces Round 395 (Div. 2)
CF
2,017
1
256
Timofey and cubes
Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number ai, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose t...
The first line contains single integer n (1 ≤ n ≤ 2·105) — the number of cubes. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109), where ai is the number written on the i-th cube after Dima has changed their order.
Print n integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.
null
Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 2. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 3. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 4. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 5. At fourth operation we reverse just middle element, so nothing has cha...
[{"input": "7\n4 3 7 6 9 1 2", "output": "2 3 9 6 7 1 4"}, {"input": "8\n6 1 4 2 5 6 9 2", "output": "2 1 6 2 5 4 9 6"}]
900
["constructive algorithms", "implementation"]
34
[{"input": "7\r\n4 3 7 6 9 1 2\r\n", "output": "2 3 9 6 7 1 4"}, {"input": "8\r\n6 1 4 2 5 6 9 2\r\n", "output": "2 1 6 2 5 4 9 6"}, {"input": "1\r\n1424\r\n", "output": "1424"}, {"input": "9\r\n-7 9 -4 9 -6 11 15 2 -10\r\n", "output": "-10 9 15 9 -6 11 -4 2 -7"}, {"input": "2\r\n21968 5686\r\n", "output": "5686 21968"...
false
stdio
null
true
764/B
764
B
Python 3
TESTS
10
109
14,233,600
30127360
def main(): n, l = int(input()), input().split() for i, j in zip(range(0, n // 2 + 1, 2), range(n - 1, n // 2, -2)): l[i], l[j] = l[j], l[i] print(' '.join(l)) if __name__ == '__main__': main()
34
139
26,931,200
177067776
def get(): return list(map(int, input().split())) def intput(): return int(input()) def main(): n=intput() arr=get() i=1 for i in range(n//2): if (not i&1 ): arr[i],arr[n-1-i]= arr[n-1-i],arr[i] print(*arr) main()
Codeforces Round 395 (Div. 2)
CF
2,017
1
256
Timofey and cubes
Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number ai, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose t...
The first line contains single integer n (1 ≤ n ≤ 2·105) — the number of cubes. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109), where ai is the number written on the i-th cube after Dima has changed their order.
Print n integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.
null
Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 2. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 3. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 4. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 5. At fourth operation we reverse just middle element, so nothing has cha...
[{"input": "7\n4 3 7 6 9 1 2", "output": "2 3 9 6 7 1 4"}, {"input": "8\n6 1 4 2 5 6 9 2", "output": "2 1 6 2 5 4 9 6"}]
900
["constructive algorithms", "implementation"]
34
[{"input": "7\r\n4 3 7 6 9 1 2\r\n", "output": "2 3 9 6 7 1 4"}, {"input": "8\r\n6 1 4 2 5 6 9 2\r\n", "output": "2 1 6 2 5 4 9 6"}, {"input": "1\r\n1424\r\n", "output": "1424"}, {"input": "9\r\n-7 9 -4 9 -6 11 15 2 -10\r\n", "output": "-10 9 15 9 -6 11 -4 2 -7"}, {"input": "2\r\n21968 5686\r\n", "output": "5686 21968"...
false
stdio
null
true
764/B
764
B
PyPy 3
TESTS
10
530
19,046,400
111186240
n=int(input()) l = list(map(int, input().rstrip().split())) j=0 if n%2!=0: for i in range(n): if j==0: print(l[n-i-1],end=" ") j=1 else: print(l[i],end=" ") j=0 else: mi=n//2 for i in range(n): if i==mi-1 or i==mi: print(l[i...
34
140
19,148,800
24371900
n = int(input().strip()) a = input().strip().split() for i in range(n // 2): if i % 2 == 0: a[i], a[n - i - 1] = a[n - i - 1], a[i] print(' '.join(a))
Codeforces Round 395 (Div. 2)
CF
2,017
1
256
Timofey and cubes
Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number ai, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose t...
The first line contains single integer n (1 ≤ n ≤ 2·105) — the number of cubes. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109), where ai is the number written on the i-th cube after Dima has changed their order.
Print n integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.
null
Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 2. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 3. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 4. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 5. At fourth operation we reverse just middle element, so nothing has cha...
[{"input": "7\n4 3 7 6 9 1 2", "output": "2 3 9 6 7 1 4"}, {"input": "8\n6 1 4 2 5 6 9 2", "output": "2 1 6 2 5 4 9 6"}]
900
["constructive algorithms", "implementation"]
34
[{"input": "7\r\n4 3 7 6 9 1 2\r\n", "output": "2 3 9 6 7 1 4"}, {"input": "8\r\n6 1 4 2 5 6 9 2\r\n", "output": "2 1 6 2 5 4 9 6"}, {"input": "1\r\n1424\r\n", "output": "1424"}, {"input": "9\r\n-7 9 -4 9 -6 11 15 2 -10\r\n", "output": "-10 9 15 9 -6 11 -4 2 -7"}, {"input": "2\r\n21968 5686\r\n", "output": "5686 21968"...
false
stdio
null
true
762/D
762
D
PyPy 3
TESTS
2
249
6,041,600
101630568
import sys from array import array # noqa: F401 import typing as Tp # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') def output(*args): sys.stdout.buffer.write( ('\n'.join(map(str, args)) + '\n').encode('utf-8') ) def main(): n = int(input()) a = [list(map...
38
670
56,934,400
124777245
import sys input = sys.stdin.readline def solve(): M = ( (0, 3, 5, 5), (3, 1, 4, -1), (5, 4, 2, 5), (5, -1, 5, 5)) INF = int(9e18-1e9) n = int(input()) a = [list(map(int, input().split())) for i in range(3)] for i in range(3): a.append([None]*n) for i in range(n): a[3][i] = a[0][i]+a[1][i] a[4][i] = a...
Educational Codeforces Round 17
ICPC
2,017
1
256
Maximum path
You are given a rectangular table 3 × n. Each cell contains an integer. You can move from one cell to another if they share a side. Find such path from the upper left cell to the bottom right cell of the table that doesn't visit any of the cells twice, and the sum of numbers written in the cells of this path is maximu...
The first line contains an integer n (1 ≤ n ≤ 105)  — the number of columns in the table. Next three lines contain n integers each  — the description of the table. The j-th number in the i-th line corresponds to the cell aij ( - 109 ≤ aij ≤ 109) of the table.
Output the maximum sum of numbers on a path from the upper left cell to the bottom right cell of the table, that doesn't visit any of the cells twice.
null
The path for the first example: The path for the second example:
[{"input": "3\n1 1 1\n1 -1 1\n1 1 1", "output": "7"}, {"input": "5\n10 10 10 -1 -1\n-1 10 10 10 10\n-1 10 10 10 10", "output": "110"}]
2,300
["dp", "greedy", "implementation"]
38
[{"input": "3\r\n1 1 1\r\n1 -1 1\r\n1 1 1\r\n", "output": "7\r\n"}, {"input": "5\r\n10 10 10 -1 -1\r\n-1 10 10 10 10\r\n-1 10 10 10 10\r\n", "output": "110\r\n"}, {"input": "15\r\n-87 -91 31 63 91 35 -14 51 20 20 -20 -94 -59 77 76\r\n11 81 22 -29 91 -26 -10 -12 46 10 100 88 14 64 41\r\n26 -31 99 -39 -30 30 28 74 -7 21 ...
false
stdio
null
true
514/D
514
D
PyPy 3-64
TESTS
2
77
0
214230737
n, m, k = map(int,input().split()) p = [[] for i in range(m + 1)] for i in range(n): m1 = list(map(int,input().split())) for j in range(m): p[j] += [m1[j]] ans = [[0 for i in range(4 * n)]for i in range(m + 1)] #print(ans[0]) def build(l,r,v,i): global ans md = (l + r) // 2 if l == r: ...
35
1,996
120,217,600
192669643
def rl(): return list(map(int,input().split())) def ri(): return int(input()) def rs(): return input() def rm(): return map(int,input().split()) from math import log2,floor def main(): n,l,k=rm() rb=[] for i in range(n): rb.append(rl()) rb=[[rb[i][j] for i in range(len(rb))] for ...
Codeforces Round 291 (Div. 2)
CF
2,015
2
256
R2D2 and Droid Army
An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, where ai is the number of details of the i-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has m weapons, the i-th weapon can affect all the droids in the...
The first line contains three integers n, m, k (1 ≤ n ≤ 105, 1 ≤ m ≤ 5, 0 ≤ k ≤ 109) — the number of droids, the number of detail types and the number of available shots, respectively. Next n lines follow describing the droids. Each line contains m integers a1, a2, ..., am (0 ≤ ai ≤ 108), where ai is the number of det...
Print m space-separated integers, where the i-th number is the number of shots from the weapon of the i-th type that the robot should make to destroy the subsequence of consecutive droids of the maximum length. If there are multiple optimal solutions, print any of them. It is not necessary to make exactly k shots, th...
null
In the first test the second, third and fourth droids will be destroyed. In the second test the first and second droids will be destroyed.
[{"input": "5 2 4\n4 0\n1 2\n2 1\n0 2\n1 3", "output": "2 2"}, {"input": "3 2 4\n1 2\n1 3\n2 2", "output": "1 3"}]
2,000
["binary search", "data structures", "two pointers"]
35
[{"input": "5 2 4\r\n4 0\r\n1 2\r\n2 1\r\n0 2\r\n1 3\r\n", "output": "2 2\r\n"}, {"input": "3 2 4\r\n1 2\r\n1 3\r\n2 2\r\n", "output": "1 3\r\n"}, {"input": "1 1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n0\r\n", "output": "0\r\n"}, {"input": "4 5 33\r\n2 10 2 3...
false
stdio
null
true
514/C
514
C
PyPy 3-64
TESTS
5
62
1,536,000
215157994
def process_queries(initial_strings, queries): memory_set = set(initial_strings) for query in queries: for i in range(len(query)): for c in ['a', 'b', 'c']: modified_query = query[:i] + c + query[i + 1:] if modified_query in memory_set: pri...
41
343
46,694,400
193030414
# Use two hashes to avoid collisions import sys input = sys.stdin.readline MAXN = 6 * 10 ** 5 MOD = 10 ** 9 + 7 base = [5, 7] # hash stuff pw = [[1] * MAXN for i in range(2)] for j in range(2): for i in range(1, MAXN): pw[j][i] = pw[j][i - 1] * base[j] % MOD def hash_s(s: str): hsh = [0, 0] fo...
Codeforces Round 291 (Div. 2)
CF
2,015
3
256
Watto and Mechanism
Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mech...
The first line contains two non-negative numbers n and m (0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of the initial strings and the number of queries, respectively. Next follow n non-empty strings that are uploaded to the memory of the mechanism. Next follow m non-empty strings that are the queries to the mechanism. ...
For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes).
null
null
[{"input": "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac", "output": "YES\nNO\nNO"}]
2,000
["binary search", "data structures", "hashing", "string suffix structures", "strings"]
41
[{"input": "2 3\r\naaaaa\r\nacacaca\r\naabaa\r\nccacacc\r\ncaaac\r\n", "output": "YES\r\nNO\r\nNO\r\n"}, {"input": "1 5\r\nacbacbacb\r\ncbacbacb\r\nacbacbac\r\naacbacbacb\r\nacbacbacbb\r\nacbaabacb\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nYES\r\n"}, {"input": "0 0\r\n", "output": ""}, {"input": "5 4\r\nab\r\ncacab\r\nc...
false
stdio
null
true
514/C
514
C
PyPy 3-64
TESTS
5
62
2,457,600
215157319
st = set() n, m = list(map(int, input().split())) for i in range(n): word = input() for letter in range(len(word)): newWord = list(word) for pp in ['a', 'b', 'c']: newWord[letter] = pp st.add(''.join(newWord)) for i in range(m): if input() in st: print("YES") ...
41
608
9,932,800
196187364
from sys import stdin,stdout a, b = map(int, input().split()) qw = set() def hash(st): h = 0 for l, i in enumerate(st): h += ord(i) * pow(1212121, l, 10**9 + 7) h %= (10**9 + 7) return h for i in range(a): qw.add(hash(stdin.readline().strip())) for i in range(b): er = stdin.readlin...
Codeforces Round 291 (Div. 2)
CF
2,015
3
256
Watto and Mechanism
Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mech...
The first line contains two non-negative numbers n and m (0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of the initial strings and the number of queries, respectively. Next follow n non-empty strings that are uploaded to the memory of the mechanism. Next follow m non-empty strings that are the queries to the mechanism. ...
For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes).
null
null
[{"input": "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac", "output": "YES\nNO\nNO"}]
2,000
["binary search", "data structures", "hashing", "string suffix structures", "strings"]
41
[{"input": "2 3\r\naaaaa\r\nacacaca\r\naabaa\r\nccacacc\r\ncaaac\r\n", "output": "YES\r\nNO\r\nNO\r\n"}, {"input": "1 5\r\nacbacbacb\r\ncbacbacb\r\nacbacbac\r\naacbacbacb\r\nacbacbacbb\r\nacbaabacb\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nYES\r\n"}, {"input": "0 0\r\n", "output": ""}, {"input": "5 4\r\nab\r\ncacab\r\nc...
false
stdio
null
true
514/C
514
C
Python 3
TESTS
5
46
921,600
213050768
import sys input=sys.stdin.readline from hashlib import md5 def hash1(s): h = md5() h.update(s.encode()) hash = h.hexdigest() return hash n,m=map(int,input().split()) s={} for i in range(n): x=input().strip() for i in range(len(x)): r=(hash1((x[:i]+" "+x[i+1:]))) if r not in s: ...
41
2,964
34,611,200
202756254
mod = 9999999999999999 memory = set() n, m = map(int, input().split()) for _ in range(n): s = input() slen = len(s) pwr, h_val = 1, 0 for i in range(slen): h_val = (h_val + ord(s[i]) * pwr) % mod pwr = (pwr * 203) % mod pwr = 1 # reset for i in range(slen): for...
Codeforces Round 291 (Div. 2)
CF
2,015
3
256
Watto and Mechanism
Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mech...
The first line contains two non-negative numbers n and m (0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of the initial strings and the number of queries, respectively. Next follow n non-empty strings that are uploaded to the memory of the mechanism. Next follow m non-empty strings that are the queries to the mechanism. ...
For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes).
null
null
[{"input": "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac", "output": "YES\nNO\nNO"}]
2,000
["binary search", "data structures", "hashing", "string suffix structures", "strings"]
41
[{"input": "2 3\r\naaaaa\r\nacacaca\r\naabaa\r\nccacacc\r\ncaaac\r\n", "output": "YES\r\nNO\r\nNO\r\n"}, {"input": "1 5\r\nacbacbacb\r\ncbacbacb\r\nacbacbac\r\naacbacbacb\r\nacbacbacbb\r\nacbaabacb\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nYES\r\n"}, {"input": "0 0\r\n", "output": ""}, {"input": "5 4\r\nab\r\ncacab\r\nc...
false
stdio
null
true
514/C
514
C
PyPy 3-64
TESTS
5
62
2,662,400
192538724
def rl(): return list(map(int,input().split())) def ri(): return int(input()) def rs(): return input() def rm(): return map(int,input().split()) def solve(): d={'a':1,'b':2,'c':3} n,m=rm() v=set() for i in range(n): s=input() ls=len(s) h=0 for j in range(...
41
343
46,694,400
193030414
# Use two hashes to avoid collisions import sys input = sys.stdin.readline MAXN = 6 * 10 ** 5 MOD = 10 ** 9 + 7 base = [5, 7] # hash stuff pw = [[1] * MAXN for i in range(2)] for j in range(2): for i in range(1, MAXN): pw[j][i] = pw[j][i - 1] * base[j] % MOD def hash_s(s: str): hsh = [0, 0] fo...
Codeforces Round 291 (Div. 2)
CF
2,015
3
256
Watto and Mechanism
Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mech...
The first line contains two non-negative numbers n and m (0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of the initial strings and the number of queries, respectively. Next follow n non-empty strings that are uploaded to the memory of the mechanism. Next follow m non-empty strings that are the queries to the mechanism. ...
For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes).
null
null
[{"input": "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac", "output": "YES\nNO\nNO"}]
2,000
["binary search", "data structures", "hashing", "string suffix structures", "strings"]
41
[{"input": "2 3\r\naaaaa\r\nacacaca\r\naabaa\r\nccacacc\r\ncaaac\r\n", "output": "YES\r\nNO\r\nNO\r\n"}, {"input": "1 5\r\nacbacbacb\r\ncbacbacb\r\nacbacbac\r\naacbacbacb\r\nacbacbacbb\r\nacbaabacb\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nYES\r\n"}, {"input": "0 0\r\n", "output": ""}, {"input": "5 4\r\nab\r\ncacab\r\nc...
false
stdio
null
true
618/B
618
B
Python 3
TESTS
2
31
0
231331786
input_n = int(input()) posPar = [] i = 0 while i < input_n: row = input().split() temp = max(row) if temp in posPar: posPar.append(str(int(temp)+1))#somtimes my briliance generates gravity else: posPar.append(temp) i += 1 print(" ".join(posPar))
23
46
0
15652796
n = int(input()) l = [list(map(int, input().split())) for i in range(n)] p = [-1 for i in range(n)] for i in range(n): for j in range(1, n+1): if l[i].count(j) == n-j: p[i] = j break if p.count(n-1) == 2: p[p.index(n-1)] = n print(" ".join(map(str, p)))
Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)
CF
2,016
2
256
Guess the Permutation
Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n. Bob gave you all the values of ai, j that he wro...
The first line of the input will contain a single integer n (2 ≤ n ≤ 50). The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It's guaranteed that ai, j = aj, i and there is at least one solution consistent with the infor...
Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.
null
In the first case, the answer can be {1, 2} or {2, 1}. In the second case, another possible answer is {2, 4, 5, 1, 3}.
[{"input": "2\n0 1\n1 0", "output": "2 1"}, {"input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0", "output": "2 5 4 1 3"}]
1,100
["constructive algorithms"]
23
[{"input": "2\r\n0 1\r\n1 0\r\n", "output": "2 1\r\n"}, {"input": "5\r\n0 2 2 1 2\r\n2 0 4 1 3\r\n2 4 0 1 3\r\n1 1 1 0 1\r\n2 3 3 1 0\r\n", "output": "2 5 4 1 3\r\n"}, {"input": "10\r\n0 1 5 2 5 3 4 5 5 5\r\n1 0 1 1 1 1 1 1 1 1\r\n5 1 0 2 6 3 4 6 6 6\r\n2 1 2 0 2 2 2 2 2 2\r\n5 1 6 2 0 3 4 8 8 7\r\n3 1 3 2 3 0 3 3 3 3\...
false
stdio
import sys def main(input_path, output_path, sub_path): with open(input_path) as f: lines = [line.strip() for line in f.readlines()] n = int(lines[0]) a = [list(map(int, line.split())) for line in lines[1:n+1]] with open(sub_path) as f: sub_line = f.read().strip() p = list(map(...
true
39/F
39
F
Python 3
TESTS
3
248
409,600
53945568
from collections import defaultdict table = defaultdict(int) n,m,k = [int(x) for x in input().split()] frog = [int(x) for x in input().split()] mos = [int(x) for x in input().split()] for a in frog: for b in mos: if b % a == 0 : table[a] += 1 minV = 9999999 minItem = [] for key,value in table.it...
35
124
0
15637261
n, m, k = map(int, input().split()) d, a = map(int, input().split()), list(map(int, input().split())) v = sorted((sum(ai % di == 0 for ai in a), i + 1) for i, di in enumerate(d)) v = sorted(vi[1] for vi in v if vi[0] == v[0][0]) print(len(v), ' '.join(map(str, v)), sep='\n')
School Team Contest 1 (Winter Computer School 2010/11)
ICPC
2,010
2
64
Pacifist frogs
Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much. One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to n...
The first line contains three integers n, m and k (1 ≤ n ≤ 109, 1 ≤ m, k ≤ 100) — the number of hills, frogs and mosquitoes respectively. The second line contains m integers di (1 ≤ di ≤ 109) — the lengths of the frogs’ jumps. The third line contains k integers — the numbers of the hills on which each mosquito is sleep...
In the first line output the number of frogs that smash the minimal number of mosquitoes, in the second line — their numbers in increasing order separated by spaces. The frogs are numbered from 1 to m in the order of the jump length given in the input data.
null
null
[{"input": "5 3 5\n2 3 4\n1 2 3 4 5", "output": "2\n2 3"}, {"input": "1000000000 2 3\n2 5\n999999995 999999998 999999996", "output": "1\n2"}]
1,300
["implementation"]
35
[{"input": "5 3 5\r\n2 3 4\r\n1 2 3 4 5\r\n", "output": "2\r\n2 3\r\n"}, {"input": "1000000000 2 3\r\n2 5\r\n999999995 999999998 999999996\r\n", "output": "1\r\n2\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "2 2 1\r\n2 1\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "3 2 2\r\n2 4\r\n3 2\r...
false
stdio
null
true
723/D
723
D
PyPy 3-64
TESTS
4
46
0
193994890
import sys input = sys.stdin.readline n, m, k = map(int, input().split()) g = [list(input()[:-1]) for _ in range(n)] x = [[0]*m for i in range(n)] d = [] for i in range(n): for j in range(m): if g[i][j] == '*': x[i][j] = 1 elif x[i][j] == 0: q = [(i, j)] x[i][j] ...
26
62
1,740,800
21164880
import sys sys.setrecursionlimit(100000) def find(x,y,tag): if mplake[x][y] == tag or mp[x][y] == "*": return mplake[x][y] = tag lakes[tag] += 1 for i in [(1,0),(-1,0),(0,1),(0,-1)]: if 0 <= x+i[0] and x+i[0] < n and 0 <= y + i[1] and y+i[1] < m: find(x+i[0],y+i[1]...
Codeforces Round 375 (Div. 2)
CF
2,016
2
256
Lakes in Berland
The map of Berland is a rectangle of the size n × m, which consists of cells of size 1 × 1. Each cell is either land or water. The map is surrounded by the ocean. Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that ...
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 50, 0 ≤ k ≤ 50) — the sizes of the map and the number of lakes which should be left on the map. The next n lines contain m characters each — the description of the map. Each of the characters is either '.' (it means that the corresponding cell ...
In the first line print the minimum number of cells which should be transformed from water to land. In the next n lines print m symbols — the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, pri...
null
In the first example there are only two lakes — the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with th...
[{"input": "5 4 1\n****\n*..*\n****\n**.*\n..**", "output": "1\n****\n*..*\n****\n****\n..**"}, {"input": "3 3 0\n***\n*.*\n***", "output": "1\n***\n***\n***"}]
1,600
["dfs and similar", "dsu", "graphs", "greedy", "implementation"]
26
[{"input": "5 4 1\r\n****\r\n*..*\r\n****\r\n**.*\r\n..**\r\n", "output": "1\r\n****\r\n*..*\r\n****\r\n****\r\n..**\r\n"}, {"input": "3 3 0\r\n***\r\n*.*\r\n***\r\n", "output": "1\r\n***\r\n***\r\n***\r\n"}, {"input": "3 5 1\r\n.**.*\r\n*.*.*\r\n***..\r\n", "output": "0\r\n.**.*\r\n*.*.*\r\n***..\r\n"}, {"input": "3 5...
false
stdio
import sys from sys import argv def main(): input_path = argv[1] output_path = argv[2] submission_path = argv[3] with open(input_path, 'r') as f: input_lines = f.read().splitlines() n, m, k = map(int, input_lines[0].split()) original_map = input_lines[1:n+1] with open(output_path,...
true
519/D
519
D
Python 3
TESTS
4
46
0
116490455
costss=list(map(int,input().split())) s=input() costs={} cost=0 ans=0 nums=[] for i in range(len(s)): cost+=costss[ord(s[i])-97] if s[i] not in costs: costs[s[i]]={} costs[s[i]][cost]=costs[s[i]].get(cost,0)+1 if costss[ord(s[i])-97]!=0: ans+=costs[s[i]].get(cost-costss[ord(s[i])-97],0) ...
47
155
7,372,800
114712977
if __name__ == '__main__': X = [int(i) for i in input().split()] s = input() arr = [] unicode_a = ord('a') for i in range(26): arr.append({}) sm = 0 k = 0 for char in s: n = ord(char) - unicode_a k += arr[n].get(sm, 0) sm += X[n] arr[n][sm] = arr[n...
Codeforces Round 294 (Div. 2)
CF
2,015
2
256
A and B and Interesting Substrings
A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ...
The first line contains 26 integers xa, xb, ..., xz ( - 105 ≤ xi ≤ 105) — the value assigned to letters a, b, c, ..., z respectively. The second line contains string s of length between 1 and 105 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.
Print the answer to the problem.
null
In the first sample test strings satisfying the condition above are abca and bcab. In the second sample test strings satisfying the condition above are two occurences of aa.
[{"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab", "output": "2"}, {"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa", "output": "2"}]
1,800
["data structures", "dp", "two pointers"]
47
[{"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\r\nxabcab\r\n", "output": "2\r\n"}, {"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\r\naaa\r\n", "output": "2\r\n"}, {"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\r\naabbccdd\r\n", "output": "4\r\n"}, {"input": "-3 4 -4 -...
false
stdio
null
true
514/C
514
C
Python 3
TESTS
5
46
921,600
213051372
# import sys # input=sys.stdin.readline from hashlib import sha512 def hash1(s): h = sha512() h.update(s.encode()) hash = h.hexdigest() return hash n,m=map(int,input().split()) s={} for i in range(n): x=input()#.rstrip() for i in range(len(x)): r=hash1((x[:i]+"-"+x[i+1:])) if r ...
41
608
9,932,800
196187364
from sys import stdin,stdout a, b = map(int, input().split()) qw = set() def hash(st): h = 0 for l, i in enumerate(st): h += ord(i) * pow(1212121, l, 10**9 + 7) h %= (10**9 + 7) return h for i in range(a): qw.add(hash(stdin.readline().strip())) for i in range(b): er = stdin.readlin...
Codeforces Round 291 (Div. 2)
CF
2,015
3
256
Watto and Mechanism
Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mech...
The first line contains two non-negative numbers n and m (0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of the initial strings and the number of queries, respectively. Next follow n non-empty strings that are uploaded to the memory of the mechanism. Next follow m non-empty strings that are the queries to the mechanism. ...
For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes).
null
null
[{"input": "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac", "output": "YES\nNO\nNO"}]
2,000
["binary search", "data structures", "hashing", "string suffix structures", "strings"]
41
[{"input": "2 3\r\naaaaa\r\nacacaca\r\naabaa\r\nccacacc\r\ncaaac\r\n", "output": "YES\r\nNO\r\nNO\r\n"}, {"input": "1 5\r\nacbacbacb\r\ncbacbacb\r\nacbacbac\r\naacbacbacb\r\nacbacbacbb\r\nacbaabacb\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nYES\r\n"}, {"input": "0 0\r\n", "output": ""}, {"input": "5 4\r\nab\r\ncacab\r\nc...
false
stdio
null
true
514/C
514
C
PyPy 3-64
TESTS
15
1,450
25,190,400
197338304
# import sys # sys.stdout=open('C:\Program Files (x86)\Sublime Text 3\cp_setup\output.txt','w') # sys.stdin=open('C:\Program Files (x86)\Sublime Text 3\cp_setup\input.txt','r') import heapq import math import collections import bisect mod=10**9+7 def getpow(): p_pow=[[1]*600001 for i in range(2)] p=[31,29] ...
41
2,964
34,611,200
202756254
mod = 9999999999999999 memory = set() n, m = map(int, input().split()) for _ in range(n): s = input() slen = len(s) pwr, h_val = 1, 0 for i in range(slen): h_val = (h_val + ord(s[i]) * pwr) % mod pwr = (pwr * 203) % mod pwr = 1 # reset for i in range(slen): for...
Codeforces Round 291 (Div. 2)
CF
2,015
3
256
Watto and Mechanism
Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mech...
The first line contains two non-negative numbers n and m (0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of the initial strings and the number of queries, respectively. Next follow n non-empty strings that are uploaded to the memory of the mechanism. Next follow m non-empty strings that are the queries to the mechanism. ...
For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes).
null
null
[{"input": "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac", "output": "YES\nNO\nNO"}]
2,000
["binary search", "data structures", "hashing", "string suffix structures", "strings"]
41
[{"input": "2 3\r\naaaaa\r\nacacaca\r\naabaa\r\nccacacc\r\ncaaac\r\n", "output": "YES\r\nNO\r\nNO\r\n"}, {"input": "1 5\r\nacbacbacb\r\ncbacbacb\r\nacbacbac\r\naacbacbacb\r\nacbacbacbb\r\nacbaabacb\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nYES\r\n"}, {"input": "0 0\r\n", "output": ""}, {"input": "5 4\r\nab\r\ncacab\r\nc...
false
stdio
null
true
472/D
472
D
PyPy 3-64
TESTS
1
46
0
191555090
def is_distance_matrix(n, matrix): for k in range(n): for i in range(n): for j in range(n): if matrix[i][k] + matrix[k][j] < matrix[i][j]: return False return True n = int(input().strip()) matrix = [] for _ in range(n): matrix.append(list(map(int, inp...
47
545
57,036,800
177433089
from math import inf from collections import * import math, os, sys, heapq, bisect, random,threading from functools import lru_cache from itertools import * import sys def inp(): return sys.stdin.readline().rstrip("\r\n") def out(var): sys.stdout.write(str(var)) # for fast output, always take string def inpu(): return...
Codeforces Round 270
CF
2,014
2
256
Design Tutorial: Inverse the Problem
There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example. Now ...
The first line contains an integer n (1 ≤ n ≤ 2000) — the number of nodes in that graph. Then next n lines each contains n integers di, j (0 ≤ di, j ≤ 109) — the distance between node i and node j.
If there exists such a tree, output "YES", otherwise output "NO".
null
In the first example, the required tree exists. It has one edge between nodes 1 and 2 with weight 2, another edge between nodes 1 and 3 with weight 7. In the second example, it is impossible because d1, 1 should be 0, but it is 1. In the third example, it is impossible because d1, 2 should equal d2, 1.
[{"input": "3\n0 2 7\n2 0 9\n7 9 0", "output": "YES"}, {"input": "3\n1 2 7\n2 0 9\n7 9 0", "output": "NO"}, {"input": "3\n0 2 2\n7 0 9\n7 9 0", "output": "NO"}, {"input": "3\n0 1 1\n1 0 1\n1 1 0", "output": "NO"}, {"input": "2\n0 0\n0 0", "output": "NO"}]
1,900
["dfs and similar", "dsu", "shortest paths", "trees"]
47
[{"input": "3\r\n0 2 7\r\n2 0 9\r\n7 9 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 7\r\n2 0 9\r\n7 9 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 2 2\r\n7 0 9\r\n7 9 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r\n1 0 1\r\n1 1 0\r\n", "output": "NO\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "NO\r\n...
false
stdio
null
true
1006/C
1006
C
Python 3
TESTS
12
187
17,612,800
121460148
def maxssumarray(List): n = len(List) if n==1: return 0 else: i=0 j=n-1 leftsum=List[0] rightsum=List[-1] maxsum=0 while i+1<j: if leftsum < rightsum: leftsum += List[i + 1] i += 1 if leftsum...
27
108
17,510,400
219573449
import sys input = sys.stdin.readline n=int(input()) l=[int(i) for i in input().split(" ")] i,j,x,y=0,n-1,l[0],l[-1] ans=0 while(i!=j): if(x==y): ans=x if(x<=y): i+=1 x+=l[i] else: j-=1 y+=l[j] print(ans)
Codeforces Round 498 (Div. 3)
ICPC
2,018
1
256
Three Parts of the Array
You are given an array $$$d_1, d_2, \dots, d_n$$$ consisting of $$$n$$$ integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$d$$$. The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^9$$$) — the elements of the array $$$d$$$.
Print a single integer — the maximum possible value of $$$sum_1$$$, considering that the condition $$$sum_1 = sum_3$$$ must be met. Obviously, at least one valid way to split the array exists (use $$$a=c=0$$$ and $$$b=n$$$).
null
In the first example there is only one possible splitting which maximizes $$$sum_1$$$: $$$[1, 3, 1], [~], [1, 4]$$$. In the second example the only way to have $$$sum_1=4$$$ is: $$$[1, 3], [2, 1], [4]$$$. In the third example there is only one way to split the array: $$$[~], [4, 1, 2], [~]$$$.
[{"input": "5\n1 3 1 1 4", "output": "5"}, {"input": "5\n1 3 2 1 4", "output": "4"}, {"input": "3\n4 1 2", "output": "0"}]
1,200
["binary search", "data structures", "two pointers"]
27
[{"input": "5\r\n1 3 1 1 4\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 2 1 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 1 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 3 5 4 5\r\n", "output": "9\r\n"}]
false
stdio
null
true
509/C
509
C
PyPy 3
TESTS
3
77
0
230060801
from math import ceil def precalc(m, s): n9 = 0 while s > 9: n9 += 1 s -= 9 mx = "9" * n9 + str(s) # print(mx) if len(mx) == m: mx = mx elif len(mx) < m: mx = mx + "0" * (m - len(mx)) else: mx = "-1" if len(str(int(mx))) != m: mx = "-1"...
21
233
2,560,000
230063199
n = int(input()) def get_sum(x): result = 0 while x > 0: d, m = divmod(x, 10) result += m x = d return result def dec(x): t = x mult = 1 while True: d, m = divmod(x, 10) if m != 0: return t + (10 - m) * mult x = d mult *= 10 ...
Codeforces Round 289 (Div. 2, ACM ICPC Rules)
ICPC
2,015
2
256
Sums of Digits
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi. Vasya wonders what the numbers ai could be like. Of all the possibl...
The first line contains a single integer number n (1 ≤ n ≤ 300). Next n lines contain integer numbers b1, ..., bn  — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi. If there are multiple sequences with least possible number an, print any of them. Print the numbers witho...
null
null
[{"input": "3\n1\n2\n3", "output": "1\n2\n3"}, {"input": "3\n3\n2\n1", "output": "3\n11\n100"}]
2,000
["dp", "greedy", "implementation"]
21
[{"input": "3\r\n1\r\n2\r\n3\r\n", "output": "1\r\n2\r\n3\r\n"}, {"input": "3\r\n3\r\n2\r\n1\r\n", "output": "3\r\n11\r\n100\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n1\r\n", "output": "1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n"}, {"input": "10\r\n8\r\n8\r\n5\r\n1\r\n2\r\n7\r\n3\r\n...
false
stdio
null
true
1006/C
1006
C
PyPy 3-64
TESTS
11
124
27,545,600
180164563
def main(): n = map(int, input().split()) nums = list(map(int, input().split())) right_sum = left_sum = 0 i, j = 0, len(nums)-1 ans = 0 while i<j: left_sum += nums[i] while i<j and right_sum < left_sum: right_sum += nums[j] j-=1 if left_sum == r...
27
109
16,998,400
218614420
n = int(input()) arr = [int(x) for x in input().split(" ")] soma1 = 0 soma2 = 0 l = 0 r = n-1 ans = 0 while l<=r: if soma1 < soma2: soma1+=arr[l] l += 1 else: soma2 += arr[r] r -= 1 if soma1 == soma2: ans = soma1 print(ans)
Codeforces Round 498 (Div. 3)
ICPC
2,018
1
256
Three Parts of the Array
You are given an array $$$d_1, d_2, \dots, d_n$$$ consisting of $$$n$$$ integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$d$$$. The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^9$$$) — the elements of the array $$$d$$$.
Print a single integer — the maximum possible value of $$$sum_1$$$, considering that the condition $$$sum_1 = sum_3$$$ must be met. Obviously, at least one valid way to split the array exists (use $$$a=c=0$$$ and $$$b=n$$$).
null
In the first example there is only one possible splitting which maximizes $$$sum_1$$$: $$$[1, 3, 1], [~], [1, 4]$$$. In the second example the only way to have $$$sum_1=4$$$ is: $$$[1, 3], [2, 1], [4]$$$. In the third example there is only one way to split the array: $$$[~], [4, 1, 2], [~]$$$.
[{"input": "5\n1 3 1 1 4", "output": "5"}, {"input": "5\n1 3 2 1 4", "output": "4"}, {"input": "3\n4 1 2", "output": "0"}]
1,200
["binary search", "data structures", "two pointers"]
27
[{"input": "5\r\n1 3 1 1 4\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 2 1 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 1 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 3 5 4 5\r\n", "output": "9\r\n"}]
false
stdio
null
true
51/A
51
A
PyPy 3
TESTS
2
124
17,715,200
161747579
x = set() t = int(input()) for _ in range(t): a,b = list(input()) c,d = list(input()) f= [a,b,c,d] minimum = min(f) idx = f.index(minimum) #print(minimum, idx) if idx == 0: f = [c,a,d,b] elif idx == 2: f = [d,c,b,a] elif idx == 3: f = [b,d,a,c] #print(f) ...
20
92
0
229675774
def contains(cont: list, temp: str) -> bool: for i in range(4): if temp in cont: return True temp = f'{temp[2]}{temp[0]}{temp[3]}{temp[1]}' return False n = int(input()) cont = [] for i in range(n): temp = input() + input() if not contains(cont, temp): cont.append(t...
Codeforces Beta Round 48
CF
2,010
2
256
Cheaterius's Problem
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu...
The first line contains an integer n (1 ≤ n ≤ 1000), where n is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located.
Print the required number of piles.
null
null
[{"input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13", "output": "1"}, {"input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53", "output": "2"}]
1,300
["implementation"]
20
[{"input": "4\r\n31\r\n23\r\n**\r\n31\r\n23\r\n**\r\n13\r\n32\r\n**\r\n32\r\n13\r\n", "output": "1\r\n"}, {"input": "4\r\n51\r\n26\r\n**\r\n54\r\n35\r\n**\r\n25\r\n61\r\n**\r\n45\r\n53\r\n", "output": "2\r\n"}, {"input": "4\r\n56\r\n61\r\n**\r\n31\r\n31\r\n**\r\n33\r\n11\r\n**\r\n11\r\n33\r\n", "output": "2\r\n"}, {"in...
false
stdio
null
true
472/D
472
D
PyPy 3-64
TESTS
2
46
0
191544535
def is_distance_matrix(n, matrix): for i in range(n): for j in range(n): if i == j and matrix[i][j] != 0: return False for k in range(n): if matrix[i][j] == matrix[i][k] + matrix[k][j]: break elif k == n - 1: ...
47
545
57,036,800
177433089
from math import inf from collections import * import math, os, sys, heapq, bisect, random,threading from functools import lru_cache from itertools import * import sys def inp(): return sys.stdin.readline().rstrip("\r\n") def out(var): sys.stdout.write(str(var)) # for fast output, always take string def inpu(): return...
Codeforces Round 270
CF
2,014
2
256
Design Tutorial: Inverse the Problem
There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example. Now ...
The first line contains an integer n (1 ≤ n ≤ 2000) — the number of nodes in that graph. Then next n lines each contains n integers di, j (0 ≤ di, j ≤ 109) — the distance between node i and node j.
If there exists such a tree, output "YES", otherwise output "NO".
null
In the first example, the required tree exists. It has one edge between nodes 1 and 2 with weight 2, another edge between nodes 1 and 3 with weight 7. In the second example, it is impossible because d1, 1 should be 0, but it is 1. In the third example, it is impossible because d1, 2 should equal d2, 1.
[{"input": "3\n0 2 7\n2 0 9\n7 9 0", "output": "YES"}, {"input": "3\n1 2 7\n2 0 9\n7 9 0", "output": "NO"}, {"input": "3\n0 2 2\n7 0 9\n7 9 0", "output": "NO"}, {"input": "3\n0 1 1\n1 0 1\n1 1 0", "output": "NO"}, {"input": "2\n0 0\n0 0", "output": "NO"}]
1,900
["dfs and similar", "dsu", "shortest paths", "trees"]
47
[{"input": "3\r\n0 2 7\r\n2 0 9\r\n7 9 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 7\r\n2 0 9\r\n7 9 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 2 2\r\n7 0 9\r\n7 9 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r\n1 0 1\r\n1 1 0\r\n", "output": "NO\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "NO\r\n...
false
stdio
null
true
870/C
870
C
Python 3
TESTS
5
46
4,505,600
157525048
def find_summand(n): if (n < 0): return -2 if (n % 4 == 0): return n // 4 if (n % 4 == 1): return find_summand(n-9) + 1 if (n % 4 == 2): return find_summand(n-6) + 1 return find_summand(n-15) + 1 q = int(input()) for tc in range(q): n = int(input()) print(fin...
20
140
11,776,000
165486592
import sys input = sys.stdin.readline q = int(input()) while(q): n = int(input()) if(n % 2 == 0): if(n // 4 == 0): print(-1) else: print(n // 4) elif(n % 4 == 1): if((n // 4 - 1) <= 0): print(-1) else: print(n // 4 - 1) e...
Technocup 2018 - Elimination Round 2
CF
2,017
2
256
Maximum splitting
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if...
The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query.
For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.
null
12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
[{"input": "1\n12", "output": "3"}, {"input": "2\n6\n8", "output": "1\n2"}, {"input": "3\n1\n2\n3", "output": "-1\n-1\n-1"}]
1,300
["dp", "greedy", "math", "number theory"]
20
[{"input": "1\r\n12\r\n", "output": "3\r\n"}, {"input": "2\r\n6\r\n8\r\n", "output": "1\r\n2\r\n"}, {"input": "3\r\n1\r\n2\r\n3\r\n", "output": "-1\r\n-1\r\n-1\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n5\r\n7\r\n11\r\n", "output": "-1\r\n-1\r\n-1\r\n-1\r\n-1\r\n-1\r\n"}, {"input": "3\r\n4\r\n6\r\n9\r\n", "output": "1\r\n1\...
false
stdio
null
true
388/C
388
C
PyPy 3
TESTS
2
140
307,200
92523687
from sys import stdin from collections import deque import heapq n = int(stdin.readline()) piles = [] for x in range(n): a = [int(x) for x in stdin.readline().split()][1:] piles.append(a) cielTotal = 0 jiroTotal = 0 mids = [] for x in piles: cielTotal += sum(x[:len(x)//2]) jiroTotal += sum(x[len(x)...
43
124
204,800
66072317
n = int(input()) a,b = 0,0 l = [] for _ in range(n): inpt = list(map(int,input().split()))[1:] li = len(inpt) if li%2: l.append(inpt[li//2]) a += sum((inpt[:li//2])) b += sum((inpt[(li + 1)//2:])) l.sort(reverse=True) a += sum(l[::2]) b += sum(l[1::2]) print(a, b)
Codeforces Round 228 (Div. 1)
CF
2,014
1
256
Fox and Card Game
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card. The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o...
The first line contain an integer n (1 ≤ n ≤ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 ≤ si ≤ 100) — the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 ≤ ck ≤ 1000) — the sequence of the numbers on the cards...
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
null
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10. In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
[{"input": "2\n1 100\n2 1 10", "output": "101 10"}, {"input": "1\n9 2 8 6 5 9 4 7 1 3", "output": "30 15"}, {"input": "3\n3 1 3 2\n3 5 4 6\n2 8 7", "output": "18 18"}, {"input": "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000", "output": "7000 7000"}]
2,000
["games", "greedy", "sortings"]
43
[{"input": "2\r\n1 100\r\n2 1 10\r\n", "output": "101 10\r\n"}, {"input": "1\r\n9 2 8 6 5 9 4 7 1 3\r\n", "output": "30 15\r\n"}, {"input": "3\r\n3 1 3 2\r\n3 5 4 6\r\n2 8 7\r\n", "output": "18 18\r\n"}, {"input": "3\r\n3 1000 1000 1000\r\n6 1000 1000 1000 1000 1000 1000\r\n5 1000 1000 1000 1000 1000\r\n", "output": "7...
false
stdio
null
true
1006/C
1006
C
Python 3
TESTS
16
249
24,678,400
80307529
n = int(input()) a = [int(x) for x in input().split()] i = 0 j = n-1 p = 0 q = 0 s = -1 while(i<j): p = p + a[i] q = q + a[j] while(p < q): i+=1 p = p + a[i] while(q < p): j = j-1 q = q+a[j] if p == q and p > s: s = p i+=1 j-=1 print(max(s,0))
27
109
21,094,400
181264733
n=int(input()) d=[int(i) for i in input().split()] if n==1: print(0) else : sum1=sum3=0 i1=0 i2=n-1 temp1=d[i1] temp3=d[i2] while i1<i2: if temp1==temp3: sum1=temp1 sum3=temp3 i1+=1 i2-=1 temp1+=(d[i1]) temp3+=(d...
Codeforces Round 498 (Div. 3)
ICPC
2,018
1
256
Three Parts of the Array
You are given an array $$$d_1, d_2, \dots, d_n$$$ consisting of $$$n$$$ integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$d$$$. The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^9$$$) — the elements of the array $$$d$$$.
Print a single integer — the maximum possible value of $$$sum_1$$$, considering that the condition $$$sum_1 = sum_3$$$ must be met. Obviously, at least one valid way to split the array exists (use $$$a=c=0$$$ and $$$b=n$$$).
null
In the first example there is only one possible splitting which maximizes $$$sum_1$$$: $$$[1, 3, 1], [~], [1, 4]$$$. In the second example the only way to have $$$sum_1=4$$$ is: $$$[1, 3], [2, 1], [4]$$$. In the third example there is only one way to split the array: $$$[~], [4, 1, 2], [~]$$$.
[{"input": "5\n1 3 1 1 4", "output": "5"}, {"input": "5\n1 3 2 1 4", "output": "4"}, {"input": "3\n4 1 2", "output": "0"}]
1,200
["binary search", "data structures", "two pointers"]
27
[{"input": "5\r\n1 3 1 1 4\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 2 1 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 1 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 3 5 4 5\r\n", "output": "9\r\n"}]
false
stdio
null
true
618/B
618
B
Python 3
TESTS
2
62
0
16270713
n=int(input()) a=[0 for i in range(51)] b=[0 for i in range(51)] for i in range(n): c=input().split() m=max(c) m=int(m) while a[m]!=0: m+=1 a[m]=1 b[i]=m for i in range(n): print(b[i])
23
46
0
15653804
n = int(input()) M = [[int(x) for x in input().split()] for i in range(n)] last = False perm = [0 for i in range(n)] for i in range(n): S = set() for x in M[i]: if x in S: perm[i] = x break else: S.add(x) else: if last: perm[i] = n-1 ...
Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)
CF
2,016
2
256
Guess the Permutation
Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n. Bob gave you all the values of ai, j that he wro...
The first line of the input will contain a single integer n (2 ≤ n ≤ 50). The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It's guaranteed that ai, j = aj, i and there is at least one solution consistent with the infor...
Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.
null
In the first case, the answer can be {1, 2} or {2, 1}. In the second case, another possible answer is {2, 4, 5, 1, 3}.
[{"input": "2\n0 1\n1 0", "output": "2 1"}, {"input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0", "output": "2 5 4 1 3"}]
1,100
["constructive algorithms"]
23
[{"input": "2\r\n0 1\r\n1 0\r\n", "output": "2 1\r\n"}, {"input": "5\r\n0 2 2 1 2\r\n2 0 4 1 3\r\n2 4 0 1 3\r\n1 1 1 0 1\r\n2 3 3 1 0\r\n", "output": "2 5 4 1 3\r\n"}, {"input": "10\r\n0 1 5 2 5 3 4 5 5 5\r\n1 0 1 1 1 1 1 1 1 1\r\n5 1 0 2 6 3 4 6 6 6\r\n2 1 2 0 2 2 2 2 2 2\r\n5 1 6 2 0 3 4 8 8 7\r\n3 1 3 2 3 0 3 3 3 3\...
false
stdio
import sys def main(input_path, output_path, sub_path): with open(input_path) as f: lines = [line.strip() for line in f.readlines()] n = int(lines[0]) a = [list(map(int, line.split())) for line in lines[1:n+1]] with open(sub_path) as f: sub_line = f.read().strip() p = list(map(...
true
870/C
870
C
Python 3
TESTS
5
61
0
31987175
def check_prime(q): i = 2 while i * i <= q: if q % i == 0: return False i += 1 return True def solve(n): if n < 16: return first[n] else: answer = 1 answer += n // 4 n -= (n // 4) * 4 while check_prime(n): answer -= 1 ...
20
155
12,185,600
75787650
import os, sys, atexit if sys.version_info[0] < 3: range = xrange from cStringIO import StringIO as BytesIO sys.stdout = BytesIO() else: from io import BytesIO sys.stdout = BytesIO() _write = sys.stdout.write sys.stdout.write = lambda s: _write(s.encode()) atexit.register(lambda: os.write(...
Technocup 2018 - Elimination Round 2
CF
2,017
2
256
Maximum splitting
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if...
The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query.
For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.
null
12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
[{"input": "1\n12", "output": "3"}, {"input": "2\n6\n8", "output": "1\n2"}, {"input": "3\n1\n2\n3", "output": "-1\n-1\n-1"}]
1,300
["dp", "greedy", "math", "number theory"]
20
[{"input": "1\r\n12\r\n", "output": "3\r\n"}, {"input": "2\r\n6\r\n8\r\n", "output": "1\r\n2\r\n"}, {"input": "3\r\n1\r\n2\r\n3\r\n", "output": "-1\r\n-1\r\n-1\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n5\r\n7\r\n11\r\n", "output": "-1\r\n-1\r\n-1\r\n-1\r\n-1\r\n-1\r\n"}, {"input": "3\r\n4\r\n6\r\n9\r\n", "output": "1\r\n1\...
false
stdio
null
true
870/C
870
C
Python 3
TESTS
5
31
0
191083090
def find(n): if n == 5 or n == 7 or n == 11: return -1 if n < 4: return -1 rem = n % 4 div = n // 4 if rem == 0: return div elif rem == 1: n = n - 9 if n < 0: return 1 else: return 1 + (n // 4) elif rem == 2: n =...
20
264
10,342,400
158310761
from sys import stdin,stdout input = stdin.read r = map(int,input().split()) q = next(r) for _ in range(q): a = next(r) if(a < 4 or a == 5 or a == 7 or a == 11): stdout.write("-1\n") else: stdout.write(str(a//4 - (a%4)%2)) stdout.write("\n")
Technocup 2018 - Elimination Round 2
CF
2,017
2
256
Maximum splitting
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if...
The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query.
For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.
null
12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
[{"input": "1\n12", "output": "3"}, {"input": "2\n6\n8", "output": "1\n2"}, {"input": "3\n1\n2\n3", "output": "-1\n-1\n-1"}]
1,300
["dp", "greedy", "math", "number theory"]
20
[{"input": "1\r\n12\r\n", "output": "3\r\n"}, {"input": "2\r\n6\r\n8\r\n", "output": "1\r\n2\r\n"}, {"input": "3\r\n1\r\n2\r\n3\r\n", "output": "-1\r\n-1\r\n-1\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n5\r\n7\r\n11\r\n", "output": "-1\r\n-1\r\n-1\r\n-1\r\n-1\r\n-1\r\n"}, {"input": "3\r\n4\r\n6\r\n9\r\n", "output": "1\r\n1\...
false
stdio
null
true
755/B
755
B
Python 3
TESTS
10
187
1,433,600
139017847
n, m = map(int, input().split()) polland = [] enemy = [] for c in range(n): palavra = input() polland .append(palavra) for c in range(m): palavra = input() enemy.append(palavra) faladas = [] vez = True aux1 = aux2 = 0 p = 0 e = 0 while(aux1 < len(polland ) or aux2 < len(enemy)): if(vez): if(aux1 < len...
33
46
1,228,800
165729996
n, m = [int(num) for num in input().split()] palavras = {} num_repetidas = 0 for _ in range(n + m): palavra = input() if palavra in palavras: num_repetidas += 1 palavras[palavra] = True answer = '' if n > m: answer = 'YES' elif n < m: answer = 'NO' else: answer = 'NO' if num_repetidas ...
8VC Venture Cup 2017 - Elimination Round
CF
2,017
1
256
PolandBall and Game
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i...
The first input line contains two integers n and m (1 ≤ n, m ≤ 103) — number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per line — words familiar to PolandBall. Then m strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a word more than onc...
In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
null
In the first example PolandBall knows much more words and wins effortlessly. In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
[{"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope", "output": "YES"}, {"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "output": "YES"}, {"input": "1 2\na\na\nb", "output": "NO"}]
1,100
["binary search", "data structures", "games", "greedy", "sortings", "strings"]
33
[{"input": "5 1\r\npolandball\r\nis\r\na\r\ncool\r\ncharacter\r\nnope\r\n", "output": "YES"}, {"input": "2 2\r\nkremowka\r\nwadowicka\r\nkremowka\r\nwiedenska\r\n", "output": "YES"}, {"input": "1 2\r\na\r\na\r\nb\r\n", "output": "NO"}, {"input": "2 2\r\na\r\nb\r\nb\r\nc\r\n", "output": "YES"}, {"input": "2 1\r\nc\r\na\...
false
stdio
null
true
29/A
29
A
Python 3
TESTS
4
186
0
59110844
n=int(input()) l=[] for i in range(n): v=list(map(int,input().split())) l.append((v[0],v[1])) d=-1 for i in range(n): for j in range(i+1,n): c=abs(l[i][0]-l[j][0]) if c==l[i][1]: if c+l[j][1]==0: d=0 break if d==0: break if d==0: ...
30
92
0
143462946
def check(cam1, cam2): if cam1[0] + cam1[1] == cam2[0] and cam2[0] + cam2[1] == cam1[0]: return True return False camels = [[int(y) for y in input().split()] for x in range(int(input()))] for x in range(len(camels) - 1): for y in range(x + 1, len(camels)): if check(camels[x], camels[y]): ...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Spit Problem
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
The first line contains integer n (1 ≤ n ≤ 100) — the amount of camels in the zoo. Each of the following n lines contains two integers xi and di ( - 104 ≤ xi ≤ 104, 1 ≤ |di| ≤ 2·104) — records in Bob's notepad. xi is a position of the i-th camel, and di is a distance at which the i-th camel spitted. Positive values of ...
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
null
null
[{"input": "2\n0 1\n1 -1", "output": "YES"}, {"input": "3\n0 1\n1 1\n2 -2", "output": "NO"}, {"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES"}]
1,000
["brute force"]
30
[{"input": "2\r\n0 1\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n2 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 -10\r\n3 10\r\n0 5\r\n5 -5\r\n10 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n-9897 -1144\r\n-4230 -6350\r\n2116 -3551\r\n-3635 4993\r\n3907 -9071\r\n-2362 4120\r\n-6542 984\r\n5807...
false
stdio
null
true
756/B
756
B
PyPy 3-64
TESTS
5
62
1,638,400
210711984
import sys input = lambda: sys.stdin.readline().rstrip() from bisect import * N = int(input()) dp = [[0,0,0] for _ in range(N+1)] A = [] for i in range(N): A.append(int(input())) dp[i+1][0] = min(dp[i])+20 idx = bisect_left(A, A[-1]-89) #print(idx,A[-1],A[-1]-90) dp[i+1][1] = dp[idx][0]+50 ...
31
234
17,510,400
205217293
# Code by B3D # Love from math import * from collections import * import io, os import sys from bisect import * from heapq import * from itertools import permutations from functools import * import re import sys import threading from typing import * # from sortedcontainers import * # from sortedcontainerstemp import ...
8VC Venture Cup 2017 - Final Round
CF
2,017
2
256
Travel Card
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: 1. a ticket...
The first line of input contains integer number n (1 ≤ n ≤ 105) — the number of trips made by passenger. Each of the following n lines contains the time of trip ti (0 ≤ ti ≤ 109), measured in minutes from the time of starting the system. All ti are different, given in ascending order, i. e. ti + 1 > ti holds for all 1...
Output n integers. For each trip, print the sum the passenger is charged after it.
null
In the first example, the system works as follows: for the first and second trips it is cheaper to pay for two one-trip tickets, so each time 20 rubles is charged, after the third trip the system understands that it would be cheaper to buy a ticket for 90 minutes. This ticket costs 50 rubles, and the passenger had alre...
[{"input": "3\n10\n20\n30", "output": "20\n20\n10"}, {"input": "10\n13\n45\n46\n60\n103\n115\n126\n150\n256\n516", "output": "20\n20\n10\n0\n20\n0\n0\n20\n20\n10"}]
1,600
["binary search", "dp"]
31
[{"input": "3\r\n10\r\n20\r\n30\r\n", "output": "20\r\n20\r\n10\r\n"}, {"input": "10\r\n13\r\n45\r\n46\r\n60\r\n103\r\n115\r\n126\r\n150\r\n256\r\n516\r\n", "output": "20\r\n20\r\n10\r\n0\r\n20\r\n0\r\n0\r\n20\r\n20\r\n10\r\n"}, {"input": "7\r\n100\r\n138\r\n279\r\n308\r\n396\r\n412\r\n821\r\n", "output": "20\r\n20\r\n...
false
stdio
null
true
616/F
616
F
PyPy 3-64
TESTS
6
124
4,812,800
143457268
from itertools import zip_longest, islice from collections import defaultdict def ranks(l): index = {v: i for i, v in enumerate(sorted(set(l)))} return [index[v] for v in l] def suffixArray(s): line = ranks(s) n, k, ans, sa = len(s), 1, [line], [0]*len(s) while max(line) < n - 1: #k < n - 1 witho...
47
1,872
258,457,600
185595299
def SA_IS(S): S += [0] k = max(S) + 1 n = len(S) def induce_l(sa, a, n, k, stype): bucket = get_buckets(a, k, 1) for i in range(n): j = sa[i] - 1 if j >= 0 and (not stype[j]): sa[bucket[a[j]]] = j bucket[a[j]] += 1 def induce_...
Educational Codeforces Round 5
ICPC
2,016
6
512
Expensive Strings
You are given n strings ti. Each string has cost ci. Let's define the function of string $$s : f(s) = \sum_{i=1}^{n} c_i \cdot p_{s,i} \cdot |s|$$, where ps, i is the number of occurrences of s in ti, |s| is the length of the string s. Find the maximal value of function f(s) over all strings. Note that the string s i...
The first line contains the only integer n (1 ≤ n ≤ 105) — the number of strings in t. Each of the next n lines contains contains a non-empty string ti. ti contains only lowercase English letters. It is guaranteed that the sum of lengths of all strings in t is not greater than 5·105. The last line contains n integer...
Print the only integer a — the maximal value of the function f(s) over all strings s. Note one more time that the string s is not necessarily from t.
null
null
[{"input": "2\naa\nbb\n2 1", "output": "4"}, {"input": "2\naa\nab\n2 1", "output": "5"}]
2,700
["data structures", "sortings", "string suffix structures", "strings"]
47
[{"input": "2\r\naa\r\nbb\r\n2 1\r\n", "output": "4\r\n"}, {"input": "2\r\naa\r\nab\r\n2 1\r\n", "output": "5\r\n"}, {"input": "1\r\naaa\r\n2\r\n", "output": "8\r\n"}, {"input": "3\r\na\r\naa\r\naaa\r\n1 2 3\r\n", "output": "16\r\n"}, {"input": "3\r\na\r\naaa\r\naa\r\n2 1 3\r\n", "output": "11\r\n"}, {"input": "1\r\nab...
false
stdio
null
true
870/C
870
C
Python 3
TESTS
5
61
5,529,600
32840408
#http://codeforces.com/problemset/problem/870/C #solved n = int(input()) todo = [int(input()) for _ in range(n)] wrong = [1, 2, 3, 5, 7, 11] for i in todo: if i in wrong: print(-1) continue modulo = i % 4 if modulo == 0 or modulo == 2: print(i // 4) continue elif mod...
20
265
10,547,200
31342549
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**15 mod = 10**9+7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF()...
Technocup 2018 - Elimination Round 2
CF
2,017
2
256
Maximum splitting
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if...
The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query.
For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.
null
12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
[{"input": "1\n12", "output": "3"}, {"input": "2\n6\n8", "output": "1\n2"}, {"input": "3\n1\n2\n3", "output": "-1\n-1\n-1"}]
1,300
["dp", "greedy", "math", "number theory"]
20
[{"input": "1\r\n12\r\n", "output": "3\r\n"}, {"input": "2\r\n6\r\n8\r\n", "output": "1\r\n2\r\n"}, {"input": "3\r\n1\r\n2\r\n3\r\n", "output": "-1\r\n-1\r\n-1\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n5\r\n7\r\n11\r\n", "output": "-1\r\n-1\r\n-1\r\n-1\r\n-1\r\n-1\r\n"}, {"input": "3\r\n4\r\n6\r\n9\r\n", "output": "1\r\n1\...
false
stdio
null
true
756/B
756
B
Python 3
TESTS
5
46
4,608,000
25299038
def memoize(f): memo = {} def helper(x): if x not in memo: memo[x] = f(x) return memo[x] return helper n = int(input()) t = [0 for i in range(n+8)] #times = [0 for i in range(n+8)] @memoize def cost(i): #print('cost', i) if i<=0: return 0 nc = cost(i-1) + 20 pos = i while t[pos] > t[i] - 90 and pos>...
31
264
12,697,600
194604058
import sys input = sys.stdin.readline from bisect import bisect M = 10**5+1 n = int(input()) g = [int(input()) for _ in range(n)] d = [0] + [-1]*n x = [0] + [-1]*n for i in range(1, n+1): a = bisect(g, g[i-1]-90) b = bisect(g, g[i-1]-1440) d[i] = min(d[i-1]+20, d[a]+50, d[b]+120) x[i] = d[i]-d[i-1] ...
8VC Venture Cup 2017 - Final Round
CF
2,017
2
256
Travel Card
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: 1. a ticket...
The first line of input contains integer number n (1 ≤ n ≤ 105) — the number of trips made by passenger. Each of the following n lines contains the time of trip ti (0 ≤ ti ≤ 109), measured in minutes from the time of starting the system. All ti are different, given in ascending order, i. e. ti + 1 > ti holds for all 1...
Output n integers. For each trip, print the sum the passenger is charged after it.
null
In the first example, the system works as follows: for the first and second trips it is cheaper to pay for two one-trip tickets, so each time 20 rubles is charged, after the third trip the system understands that it would be cheaper to buy a ticket for 90 minutes. This ticket costs 50 rubles, and the passenger had alre...
[{"input": "3\n10\n20\n30", "output": "20\n20\n10"}, {"input": "10\n13\n45\n46\n60\n103\n115\n126\n150\n256\n516", "output": "20\n20\n10\n0\n20\n0\n0\n20\n20\n10"}]
1,600
["binary search", "dp"]
31
[{"input": "3\r\n10\r\n20\r\n30\r\n", "output": "20\r\n20\r\n10\r\n"}, {"input": "10\r\n13\r\n45\r\n46\r\n60\r\n103\r\n115\r\n126\r\n150\r\n256\r\n516\r\n", "output": "20\r\n20\r\n10\r\n0\r\n20\r\n0\r\n0\r\n20\r\n20\r\n10\r\n"}, {"input": "7\r\n100\r\n138\r\n279\r\n308\r\n396\r\n412\r\n821\r\n", "output": "20\r\n20\r\n...
false
stdio
null
true
755/B
755
B
Python 3
TESTS
10
202
1,433,600
184716372
x, y = [int(x) for x in input().split()] vez = 0 palx = [] paly = [] for i in range(x): pal = str(input()) palx.append(pal) for i in range(y): pal = str(input()) paly.append(pal) xp = 0 yp = 0 xk = 0 yk = 0 palas = [] while x > 0 and y > 0: if vez == 0: if not palx[xk] in palas: ...
33
46
1,228,800
172842807
n,m=map(int,input().split()) x=[] for i in range(n+m): x.append(input()) if n>m: print('YES') elif n<m: print('NO') elif n==m: if len(set(x))%2!=0: print('YES') else: print('NO')
8VC Venture Cup 2017 - Elimination Round
CF
2,017
1
256
PolandBall and Game
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i...
The first input line contains two integers n and m (1 ≤ n, m ≤ 103) — number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per line — words familiar to PolandBall. Then m strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a word more than onc...
In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
null
In the first example PolandBall knows much more words and wins effortlessly. In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
[{"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope", "output": "YES"}, {"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "output": "YES"}, {"input": "1 2\na\na\nb", "output": "NO"}]
1,100
["binary search", "data structures", "games", "greedy", "sortings", "strings"]
33
[{"input": "5 1\r\npolandball\r\nis\r\na\r\ncool\r\ncharacter\r\nnope\r\n", "output": "YES"}, {"input": "2 2\r\nkremowka\r\nwadowicka\r\nkremowka\r\nwiedenska\r\n", "output": "YES"}, {"input": "1 2\r\na\r\na\r\nb\r\n", "output": "NO"}, {"input": "2 2\r\na\r\nb\r\nb\r\nc\r\n", "output": "YES"}, {"input": "2 1\r\nc\r\na\...
false
stdio
null
true
755/B
755
B
PyPy 3-64
TESTS
10
218
4,300,800
138929395
n, m = [int(x) for x in input().split(' ')] polandWords = [] enemyWords = [] for _ in range(n): word = input() polandWords.append(word) for _ in range(m): word = input() enemyWords.append(word) words_used = set() pc = 0 pe = 0 while True: pw = None while pw == None and len(polandWords) > 0: pw = ...
33
46
1,228,800
176497750
polland_ball, enemy_ball = map(int, input().split()) palavras_polland = set() palavras_enemy = set() for i in range(polland_ball): palavras_polland.add(str(input())) for i in range(enemy_ball): palavras_enemy.add(str(input())) # Os jogadores vão iniciar com palavras que ambos conhecem. palavras_em_comum = p...
8VC Venture Cup 2017 - Elimination Round
CF
2,017
1
256
PolandBall and Game
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i...
The first input line contains two integers n and m (1 ≤ n, m ≤ 103) — number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per line — words familiar to PolandBall. Then m strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a word more than onc...
In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
null
In the first example PolandBall knows much more words and wins effortlessly. In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
[{"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope", "output": "YES"}, {"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "output": "YES"}, {"input": "1 2\na\na\nb", "output": "NO"}]
1,100
["binary search", "data structures", "games", "greedy", "sortings", "strings"]
33
[{"input": "5 1\r\npolandball\r\nis\r\na\r\ncool\r\ncharacter\r\nnope\r\n", "output": "YES"}, {"input": "2 2\r\nkremowka\r\nwadowicka\r\nkremowka\r\nwiedenska\r\n", "output": "YES"}, {"input": "1 2\r\na\r\na\r\nb\r\n", "output": "NO"}, {"input": "2 2\r\na\r\nb\r\nb\r\nc\r\n", "output": "YES"}, {"input": "2 1\r\nc\r\na\...
false
stdio
null
true
870/C
870
C
PyPy 3-64
TESTS
5
61
0
205335243
nums=[4,9,6,15] t=int(input()) for _ in range(t): n=int(input()) if n < nums[n%4]: print(-1) else: print((n-nums[n%4])//4+1)
20
280
11,059,200
158310978
from sys import stdin,stdout input = stdin.read r = map(int,input().split()) q = next(r) for _ in range(q): a = next(r) if(a in [1,2,3,5,7,11]): stdout.write("-1\n") else: stdout.write(str(a//4 - (a%4)%2)) stdout.write("\n")
Technocup 2018 - Elimination Round 2
CF
2,017
2
256
Maximum splitting
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if...
The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query.
For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.
null
12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
[{"input": "1\n12", "output": "3"}, {"input": "2\n6\n8", "output": "1\n2"}, {"input": "3\n1\n2\n3", "output": "-1\n-1\n-1"}]
1,300
["dp", "greedy", "math", "number theory"]
20
[{"input": "1\r\n12\r\n", "output": "3\r\n"}, {"input": "2\r\n6\r\n8\r\n", "output": "1\r\n2\r\n"}, {"input": "3\r\n1\r\n2\r\n3\r\n", "output": "-1\r\n-1\r\n-1\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n5\r\n7\r\n11\r\n", "output": "-1\r\n-1\r\n-1\r\n-1\r\n-1\r\n-1\r\n"}, {"input": "3\r\n4\r\n6\r\n9\r\n", "output": "1\r\n1\...
false
stdio
null
true
756/B
756
B
Python 3
TESTS
5
62
4,608,000
24631036
n = int(input()) travel_times = list() travel_pay = list() pay_ticket1 = 0 time_ticket1 = 0 pay_ticket2 = 0 time_ticket2 = 0 for travel_id in range(n): t = int(input()) travel_times.append(t) pay2 = 20 sum_time1 = t - travel_times[time_ticket1] sum_time2 = t - travel_times[time_ticket2...
31
342
10,547,200
93853498
from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop import math from collections import * from functools import reduce,cmp_to_key,lru_cache import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # import sys # input = sys.stdin.readline M = ...
8VC Venture Cup 2017 - Final Round
CF
2,017
2
256
Travel Card
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: 1. a ticket...
The first line of input contains integer number n (1 ≤ n ≤ 105) — the number of trips made by passenger. Each of the following n lines contains the time of trip ti (0 ≤ ti ≤ 109), measured in minutes from the time of starting the system. All ti are different, given in ascending order, i. e. ti + 1 > ti holds for all 1...
Output n integers. For each trip, print the sum the passenger is charged after it.
null
In the first example, the system works as follows: for the first and second trips it is cheaper to pay for two one-trip tickets, so each time 20 rubles is charged, after the third trip the system understands that it would be cheaper to buy a ticket for 90 minutes. This ticket costs 50 rubles, and the passenger had alre...
[{"input": "3\n10\n20\n30", "output": "20\n20\n10"}, {"input": "10\n13\n45\n46\n60\n103\n115\n126\n150\n256\n516", "output": "20\n20\n10\n0\n20\n0\n0\n20\n20\n10"}]
1,600
["binary search", "dp"]
31
[{"input": "3\r\n10\r\n20\r\n30\r\n", "output": "20\r\n20\r\n10\r\n"}, {"input": "10\r\n13\r\n45\r\n46\r\n60\r\n103\r\n115\r\n126\r\n150\r\n256\r\n516\r\n", "output": "20\r\n20\r\n10\r\n0\r\n20\r\n0\r\n0\r\n20\r\n20\r\n10\r\n"}, {"input": "7\r\n100\r\n138\r\n279\r\n308\r\n396\r\n412\r\n821\r\n", "output": "20\r\n20\r\n...
false
stdio
null
true
756/B
756
B
Python 3
TESTS
5
61
716,800
167850524
from typing import List import bisect def sum_of_trip(n: int, arr: List[int]) -> List[int]: result = [] sum = [0] arr.insert(0,0) for i in range(1,n+1): minimum_sum = sum[i-1]+ 20 last_90 = bisect.bisect_left(arr,arr[i]-89,0,i-1) # find leftmost value in array greater than x = arr[i...
31
343
9,830,400
231250121
# https://codeforces.com/contest/756/problem/B n = int(input()) # Number of trips by passenger t = [] for _ in range(n): t.append(int(input())) # Time of each trip, relative to starting the system """ Rules A ticket of one trip costs 20 rubles A ticket for 90 minutes costs 50 rubles A ticket for one day (1440 mi...
8VC Venture Cup 2017 - Final Round
CF
2,017
2
256
Travel Card
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: 1. a ticket...
The first line of input contains integer number n (1 ≤ n ≤ 105) — the number of trips made by passenger. Each of the following n lines contains the time of trip ti (0 ≤ ti ≤ 109), measured in minutes from the time of starting the system. All ti are different, given in ascending order, i. e. ti + 1 > ti holds for all 1...
Output n integers. For each trip, print the sum the passenger is charged after it.
null
In the first example, the system works as follows: for the first and second trips it is cheaper to pay for two one-trip tickets, so each time 20 rubles is charged, after the third trip the system understands that it would be cheaper to buy a ticket for 90 minutes. This ticket costs 50 rubles, and the passenger had alre...
[{"input": "3\n10\n20\n30", "output": "20\n20\n10"}, {"input": "10\n13\n45\n46\n60\n103\n115\n126\n150\n256\n516", "output": "20\n20\n10\n0\n20\n0\n0\n20\n20\n10"}]
1,600
["binary search", "dp"]
31
[{"input": "3\r\n10\r\n20\r\n30\r\n", "output": "20\r\n20\r\n10\r\n"}, {"input": "10\r\n13\r\n45\r\n46\r\n60\r\n103\r\n115\r\n126\r\n150\r\n256\r\n516\r\n", "output": "20\r\n20\r\n10\r\n0\r\n20\r\n0\r\n0\r\n20\r\n20\r\n10\r\n"}, {"input": "7\r\n100\r\n138\r\n279\r\n308\r\n396\r\n412\r\n821\r\n", "output": "20\r\n20\r\n...
false
stdio
null
true
756/B
756
B
Python 3
TESTS
5
61
5,529,600
31601336
a = b = 1 p, s = [0, 0], [0, 0] for i in range(int(input())): p += [int(input())] while p[-1] - p[a] > 89: a += 1 while p[-1] - p[b] > 1339: b += 1 s += [min(s[-1] + 20, s[a - 1] + 50, s[b - 1] + 120)] print(' '.join(str(u - v) for u, v in zip(s[2:], s[1:])))
31
358
10,649,600
105437041
import sys def bs (l,r,val): l1= l r1= r while (l1<= r1): mid = (l1 + r1)//2 if t[mid] >= val : res = mid r1 = mid -1 elif t[mid] < val : l1 = mid +1 return res t= [] n = int (sys.stdin.readline()) for i in range (n): temp = int(sys...
8VC Venture Cup 2017 - Final Round
CF
2,017
2
256
Travel Card
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: 1. a ticket...
The first line of input contains integer number n (1 ≤ n ≤ 105) — the number of trips made by passenger. Each of the following n lines contains the time of trip ti (0 ≤ ti ≤ 109), measured in minutes from the time of starting the system. All ti are different, given in ascending order, i. e. ti + 1 > ti holds for all 1...
Output n integers. For each trip, print the sum the passenger is charged after it.
null
In the first example, the system works as follows: for the first and second trips it is cheaper to pay for two one-trip tickets, so each time 20 rubles is charged, after the third trip the system understands that it would be cheaper to buy a ticket for 90 minutes. This ticket costs 50 rubles, and the passenger had alre...
[{"input": "3\n10\n20\n30", "output": "20\n20\n10"}, {"input": "10\n13\n45\n46\n60\n103\n115\n126\n150\n256\n516", "output": "20\n20\n10\n0\n20\n0\n0\n20\n20\n10"}]
1,600
["binary search", "dp"]
31
[{"input": "3\r\n10\r\n20\r\n30\r\n", "output": "20\r\n20\r\n10\r\n"}, {"input": "10\r\n13\r\n45\r\n46\r\n60\r\n103\r\n115\r\n126\r\n150\r\n256\r\n516\r\n", "output": "20\r\n20\r\n10\r\n0\r\n20\r\n0\r\n0\r\n20\r\n20\r\n10\r\n"}, {"input": "7\r\n100\r\n138\r\n279\r\n308\r\n396\r\n412\r\n821\r\n", "output": "20\r\n20\r\n...
false
stdio
null
true
870/C
870
C
PyPy 3-64
TESTS
5
46
0
148696523
t=int(input()) while t: n=int(input()) if n%2==0: if n==2:print(-1) else:print(n//4) else: if n<10 and n!=9:print(-1) else: x = n//4-2 y = n//6-1 if n-x*4==9 or n-y*6==9: print(n//4-1) else:print(-1) t-=1
20
296
8,704,000
47445707
# !/bin/env python3 # coding: UTF-8 # ✪ H4WK3yE乡 # Mohd. Farhan Tahir # Indian Institute Of Information Technology and Management,Gwalior # Question Link # https://codeforces.com/problemset/problem/870/C # # ///==========Libraries, Constants and Functions=============/// import sys inf = float("inf") mod = 10000...
Technocup 2018 - Elimination Round 2
CF
2,017
2
256
Maximum splitting
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if...
The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query.
For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.
null
12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
[{"input": "1\n12", "output": "3"}, {"input": "2\n6\n8", "output": "1\n2"}, {"input": "3\n1\n2\n3", "output": "-1\n-1\n-1"}]
1,300
["dp", "greedy", "math", "number theory"]
20
[{"input": "1\r\n12\r\n", "output": "3\r\n"}, {"input": "2\r\n6\r\n8\r\n", "output": "1\r\n2\r\n"}, {"input": "3\r\n1\r\n2\r\n3\r\n", "output": "-1\r\n-1\r\n-1\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n5\r\n7\r\n11\r\n", "output": "-1\r\n-1\r\n-1\r\n-1\r\n-1\r\n-1\r\n"}, {"input": "3\r\n4\r\n6\r\n9\r\n", "output": "1\r\n1\...
false
stdio
null
true
616/B
616
B
Python 3
TESTS
5
77
6,963,200
122684731
n,m=map(int,input().split()) l,x=[],10000000000 for i in range(n): l.append(list(map(int,input().split()))) t=min(l[i]) if t<x: x=t c,y=0,1000000000 for i in range(n): if min(l[i])==x: l[i]=-1 c+=1 else: t=min(l[i]) if t<y: y=t # print(l) if c==n: ...
16
31
0
180098575
n, m = map(int, input().split()) max_min_street = 0 for i in range(n): max_min_street = max(max_min_street, min(map(int, input().split()))) print(max_min_street)
Educational Codeforces Round 5
ICPC
2,016
1
256
Dinner with Emma
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets a...
The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan. Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Print the only integer a — the cost of the dinner for Jack and Emma.
null
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the din...
[{"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1", "output": "2"}, {"input": "3 3\n1 2 3\n2 3 1\n3 1 2", "output": "1"}]
1,000
["games", "greedy"]
16
[{"input": "3 4\r\n4 1 3 5\r\n2 2 2 2\r\n5 4 5 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 3 1\r\n3 1 2\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 10\r\n74 35 82 39 1 84 29 41 70 12\r\n", "output": "1\r\n"}, {"input": "10 1\r\n44\r\n23\r\n65\r\n17\r\n48\r\n29\r\n49...
false
stdio
null
true
616/B
616
B
Python 3
TESTS
5
109
0
91493734
n , m = map(int,input().split()) l1 = [] l2 = [] l3 = {} for i in range(n): l = list(map(int,input().split())) l1.append(min(l)) l2 += l for j in set(l1): l3[j] = l2.count(j) a = max(l3,key = l3.get) print(a)
16
31
102,400
207452116
n,m = map(int,input().split()) mn = [] for i in range(n): mn.append(min(list(map(int,input().split())))) print(max(mn))
Educational Codeforces Round 5
ICPC
2,016
1
256
Dinner with Emma
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets a...
The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan. Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Print the only integer a — the cost of the dinner for Jack and Emma.
null
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the din...
[{"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1", "output": "2"}, {"input": "3 3\n1 2 3\n2 3 1\n3 1 2", "output": "1"}]
1,000
["games", "greedy"]
16
[{"input": "3 4\r\n4 1 3 5\r\n2 2 2 2\r\n5 4 5 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 3 1\r\n3 1 2\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 10\r\n74 35 82 39 1 84 29 41 70 12\r\n", "output": "1\r\n"}, {"input": "10 1\r\n44\r\n23\r\n65\r\n17\r\n48\r\n29\r\n49...
false
stdio
null
true
48/C
48
C
PyPy 3
TESTS
2
124
17,715,200
133791248
n = int(input()) arr = list(map(int, input().split())) ls = [0] + arr track = [] for i in range(len(ls) - 1): track.append(ls[i+1] - ls[i]) a = max(track) if track.count(a) > 1: print('not unique') else: b = track.index(a) + 1 if n + 1 % b == 0: ans = a else: ans = arr[-1] + track[0]...
45
218
20,172,800
128377230
n = int(input()) p = [None] + list(map(int, input().split())) left_bound = 10 right_bound = 10**10 for i in range(1, n+1): #p[i]*10/i <= a < (10 + p[i]*10)/i left_bound = max(left_bound, (p[i]*10)/i) right_bound = min(right_bound, (10+p[i]*10)/i) start = p[n]+1 l = left_bound*(n+1) - 10*(p[-1]+1) r = r...
School Personal Contest #3 (Winter Computer School 2010/11) - Codeforces Beta Round 45 (ACM-ICPC Rules)
ICPC
2,010
2
256
The Race
Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name — The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with α li...
The first line contains an integer n (1 ≤ n ≤ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in ...
Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique".
null
In the second example the answer is not unique. For example, if α = 10, we'll have such a sequence as 1, 2, 3, and if α = 14, the sequence will be 1, 2, 4.
[{"input": "3\n1 2 4", "output": "unique\n5"}, {"input": "2\n1 2", "output": "not unique"}]
1,800
["math"]
45
[{"input": "3\r\n1 2 4\r\n", "output": "unique\r\n5\r\n"}, {"input": "2\r\n1 2\r\n", "output": "not unique\r\n"}, {"input": "1\r\n5\r\n", "output": "not unique\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "unique\r\n6\r\n"}, {"input": "5\r\n1 2 3 5 6\r\n", "output": "unique\r\n7\r\n"}, {"input": "6\r\n1 2 3 5 6 7\r\n",...
false
stdio
null
true
484/D
484
D
Python 3
TESTS
5
46
0
137778671
m=int(input()) n=list(map(int,input().split())) ret=0 mi,ma=n[0],n[0] for i in range(1,m): if n[i]>=n[i-1]: ma=n[i] else: ret+=(ma-mi) ma=n[i];mi=n[i] ret+=(ma-mi) print(ret)
71
373
5,427,200
223452331
import sys inf = float('inf') def read_int(): res = b'' while True: d = sys.stdin.buffer.read(1) if d == b'-' or d.isdigit(): res += d elif res: break return int(res) n = read_int() dp, neg, pos = 0, -inf, -inf for _ in range(n): v = read_int() ...
Codeforces Round 276 (Div. 1)
CF
2,014
2
256
Kindergarten
In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of consecutive children of a line. A group's sociability is the maxim...
The first line contains integer n — the number of children in the line (1 ≤ n ≤ 106). The second line contains n integers ai — the charisma of the i-th child ( - 109 ≤ ai ≤ 109).
Print the maximum possible total sociability of all groups.
null
In the first test sample one of the possible variants of an division is following: the first three children form a group with sociability 2, and the two remaining children form a group with sociability 1. In the second test sample any division leads to the same result, the sociability will be equal to 0 in each group.
[{"input": "5\n1 2 3 1 2", "output": "3"}, {"input": "3\n3 3 3", "output": "0"}]
2,400
["data structures", "dp", "greedy"]
71
[{"input": "5\r\n1 2 3 1 2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 3 3\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n-1000000000 1000000000\r\n", "output": "2000000000\r\n"}, {"input": "4\r\n1 4 2 3\r\n", "output": "4\r\n"}, {"input": "4\r\n23 5 7 1\r\n", "output": "24\r\n"},...
false
stdio
null
true
39/F
39
F
Python 3
TESTS
5
62
0
188642728
n,m,k=map(int,input().split()) lis=list(map(int,input().split())) klis=list(map(int,input().split())) dicti={} mini=10**9+1 for i in lis: dicti[i]=0 for j in klis: if j%i==0: dicti[i]+=1 mini=min(dicti[i],mini) count=0 #print(dicti) for i in dicti: if dicti[i]==mini: count+=1...
35
124
1,536,000
165078905
import sys input = sys.stdin.readline n, m, k = map(int, input().split()) w = list(map(int, input().split())) s = list(map(int, input().split())) d = [] for i in range(m): c = 0 for j in s: if j % w[i] == 0: c += 1 d.append((c, i+1)) d.sort() x = d[0][0] ans = [d[0][1]] for i in d[1:]:...
School Team Contest 1 (Winter Computer School 2010/11)
ICPC
2,010
2
64
Pacifist frogs
Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much. One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to n...
The first line contains three integers n, m and k (1 ≤ n ≤ 109, 1 ≤ m, k ≤ 100) — the number of hills, frogs and mosquitoes respectively. The second line contains m integers di (1 ≤ di ≤ 109) — the lengths of the frogs’ jumps. The third line contains k integers — the numbers of the hills on which each mosquito is sleep...
In the first line output the number of frogs that smash the minimal number of mosquitoes, in the second line — their numbers in increasing order separated by spaces. The frogs are numbered from 1 to m in the order of the jump length given in the input data.
null
null
[{"input": "5 3 5\n2 3 4\n1 2 3 4 5", "output": "2\n2 3"}, {"input": "1000000000 2 3\n2 5\n999999995 999999998 999999996", "output": "1\n2"}]
1,300
["implementation"]
35
[{"input": "5 3 5\r\n2 3 4\r\n1 2 3 4 5\r\n", "output": "2\r\n2 3\r\n"}, {"input": "1000000000 2 3\r\n2 5\r\n999999995 999999998 999999996\r\n", "output": "1\r\n2\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "2 2 1\r\n2 1\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "3 2 2\r\n2 4\r\n3 2\r...
false
stdio
null
true
39/F
39
F
PyPy 3-64
TESTS
6
92
0
167476518
n,m,k = map(int,input().split()) d = list(map(int,input().split())) a = set(map(int,input().split())) minn_l = set() minn = 1e10 for i in range(m): r = n//d[i]+1 if r<minn: minn = r minn_l = set() minn_l.add(i+1) elif r==minn: minn_l.add(i+1) print(len(minn_l)) print(*sorted(...
35
124
1,638,400
172966404
n,m,k=map(int,input().split()) A=list(map(int,input().split())) K=list(map(int,input().split())) ANS=[-1]*m for i in range(m): a=A[i] score=0 for k in K: if k%a==0: score+=1 ANS[i]=score MIN=min(ANS) ALIST=[] for i in range(m): if ANS[i]==MIN: ALIST.append(i+1) print...
School Team Contest 1 (Winter Computer School 2010/11)
ICPC
2,010
2
64
Pacifist frogs
Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much. One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to n...
The first line contains three integers n, m and k (1 ≤ n ≤ 109, 1 ≤ m, k ≤ 100) — the number of hills, frogs and mosquitoes respectively. The second line contains m integers di (1 ≤ di ≤ 109) — the lengths of the frogs’ jumps. The third line contains k integers — the numbers of the hills on which each mosquito is sleep...
In the first line output the number of frogs that smash the minimal number of mosquitoes, in the second line — their numbers in increasing order separated by spaces. The frogs are numbered from 1 to m in the order of the jump length given in the input data.
null
null
[{"input": "5 3 5\n2 3 4\n1 2 3 4 5", "output": "2\n2 3"}, {"input": "1000000000 2 3\n2 5\n999999995 999999998 999999996", "output": "1\n2"}]
1,300
["implementation"]
35
[{"input": "5 3 5\r\n2 3 4\r\n1 2 3 4 5\r\n", "output": "2\r\n2 3\r\n"}, {"input": "1000000000 2 3\r\n2 5\r\n999999995 999999998 999999996\r\n", "output": "1\r\n2\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "2 2 1\r\n2 1\r\n1\r\n", "output": "1\r\n1\r\n"}, {"input": "3 2 2\r\n2 4\r\n3 2\r...
false
stdio
null
true
616/B
616
B
PyPy 3
TESTS
5
108
0
109333713
cases, b = map(int, input().split()) st = set() while cases: cases -= 1 arr = list(map(int, input().split())) st.add(min(arr)) lst = sorted(st) if len(lst) == 1: print(*lst) else: print(lst[1])
16
31
102,400
217149912
arr=list(map(int, input().split())) n=arr[0] m=arr[1] less=[] for i in range(0,n): street=list(map(int, input().split())) less.append(min(street)) more=max(less) print(more)
Educational Codeforces Round 5
ICPC
2,016
1
256
Dinner with Emma
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets a...
The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan. Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Print the only integer a — the cost of the dinner for Jack and Emma.
null
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the din...
[{"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1", "output": "2"}, {"input": "3 3\n1 2 3\n2 3 1\n3 1 2", "output": "1"}]
1,000
["games", "greedy"]
16
[{"input": "3 4\r\n4 1 3 5\r\n2 2 2 2\r\n5 4 5 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 3 1\r\n3 1 2\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 10\r\n74 35 82 39 1 84 29 41 70 12\r\n", "output": "1\r\n"}, {"input": "10 1\r\n44\r\n23\r\n65\r\n17\r\n48\r\n29\r\n49...
false
stdio
null
true
729/D
729
D
Python 3
TESTS
6
171
9,420,800
87485729
"Codeforces Round #384 (Div. 2)" "C. Vladik and fractions" # y=int(input()) # a=y # b=a+1 # c=y*b # if y==1: # print(-1) # else: # print(a,b,c) "Technocup 2017 - Elimination Round 2" "D. Sea Battle" n,a,b,k=map(int,input().split()) s=list(input()) # n=len(s) lz=[] zeros=[] indexes=[] flage=0 if s[0]=="0": ...
21
93
16,179,200
215422065
n,a,b,k = map(int, input().split()) s = input() possible = [] i = 0 j = 0 while i<len(s): if s[i] == "1": j = 0 else : j += 1 if(j%b) == 0: possible += [i+1] j = 0 i += 1 possible = possible[a-1:] print(len(possible)) print(*possible)
Technocup 2017 - Elimination Round 2
CF
2,016
1
256
Sea Battle
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other. Galya doesn't know the ships location. She can shoot to some cells and after each shot ...
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made. The second line contains a string of length n, consisting of zeros and ones. If the i...
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship. In the second line print the cells Galya should shoot at. Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting fro...
null
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.
[{"input": "5 1 2 1\n00100", "output": "2\n4 2"}, {"input": "13 3 2 3\n1000000010001", "output": "2\n7 11"}]
1,700
["constructive algorithms", "greedy", "math"]
21
[{"input": "5 1 2 1\r\n00100\r\n", "output": "2\r\n2 5 \r\n"}, {"input": "13 3 2 3\r\n1000000010001\r\n", "output": "2\r\n3 5 \r\n"}, {"input": "1 1 1 0\r\n0\r\n", "output": "1\r\n1 \r\n"}, {"input": "2 2 1 0\r\n00\r\n", "output": "1\r\n1 \r\n"}, {"input": "5 4 1 0\r\n00000\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "...
false
stdio
null
true
31/C
31
C
Python 3
TESTS
8
122
1,024,000
144745125
N = int(input()) allMeetings = [None] * N for i in range(N): inLine = input().split(" ") start, finish = int(inLine[0]), int(inLine[1]) allMeetings[i] = (start, finish, i+1) allMeetings.sort() overlaps = [set() for _ in range(N)] totalOverlaps = 0 for i in range(N): start, finish, meetingNum ...
30
122
614,400
144790048
""" CP 2.B - Schedule Allan Lago Vjudge Username: alago1 """ n = int(input().strip()) lessons = [] keypoints = [] for i in range(n): s, e = tuple(int(x) for x in input().strip().split()) lessons.append((s, e)) keypoints.append((s, 1)) keypoints.append((e, -1)) keypoints.sort() k, start, end = (0,)*3 ...
Codeforces Beta Round 31 (Div. 2, Codeforces format)
CF
2,010
2
256
Schedule
At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, n groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, becaus...
The first line contains integer n (1 ≤ n ≤ 5000) — amount of groups, which have lessons in the room 31. Then n lines follow, each of them contains two integers li ri (1 ≤ li < ri ≤ 106) — starting and finishing times of lesson of the i-th group. It is possible that initially no two lessons intersect (see sample 1).
Output integer k — amount of ways to cancel the lesson in exactly one group so that no two time periods of lessons of the remaining groups intersect. In the second line output k numbers — indexes of groups, where it is possible to cancel the lesson. Groups are numbered starting from 1 in the order that they were given ...
null
null
[{"input": "3\n3 10\n20 30\n1 3", "output": "3\n1 2 3"}, {"input": "4\n3 10\n20 30\n1 3\n1 39", "output": "1\n4"}, {"input": "3\n1 5\n2 6\n3 7", "output": "0"}]
1,700
["implementation"]
30
[{"input": "3\r\n3 10\r\n20 30\r\n1 3\r\n", "output": "3\r\n1 2 3 "}, {"input": "4\r\n3 10\r\n20 30\r\n1 3\r\n1 39\r\n", "output": "1\r\n4 "}, {"input": "3\r\n1 5\r\n2 6\r\n3 7\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5\r\n5 7\r\n6 9\r\n9 10\r\n", "output": "2\r\n2 3 "}, {"input": "11\r\n717170 795210\r\n866429 9707...
false
stdio
null
true
754/C
754
C
PyPy 3
TESTS
0
93
0
59612774
t = int(input()) for g in range(t): n = int(input()) s = input().split() q = int(input()) x = [] for i in range(q): x += [input().split(':')] for i in x: if(i[0] != '?' and i[0] in s): index = s.index(i[0]) s = s[:index]+s[index+1:] for i in x: if(i[0] == '?'): for j in range(len(s)): if(s[j...
104
218
1,126,400
42141068
import re def proc(msgs): chg = False for i, msg in enumerate(msgs): if msg[0] != '?': continue ppn = msg[1] if i > 0: ppn.discard(msgs[i-1][0]) if i != len(msgs)-1: ppn.discard(msgs[i+1][0]) if len(ppn) == 1: msg[0] = ppn.pop() chg = True return chg def is_valid(msgs): for i, msg in enumerate(msg...
Codeforces Round 390 (Div. 2)
CF
2,017
2
256
Vladik and chat
Recently Vladik discovered a new entertainment — coding bots for social networks. He would like to use machine learning in his bots so now he want to prepare some learning data for them. At first, he need to download t chats. Vladik coded a script which should have downloaded the chats, however, something went wrong. ...
The first line contains single integer t (1 ≤ t ≤ 10) — the number of chats. The t chats follow. Each chat is given in the following format. The first line of each chat description contains single integer n (1 ≤ n ≤ 100) — the number of users in the chat. The next line contains n space-separated distinct usernames. E...
Print the information about the t chats in the following format: If it is not possible to recover senders, print single line "Impossible" for this chat. Otherwise print m messages in the following format: <username>:<text> If there are multiple answers, print any of them.
null
null
[{"input": "1\n2\nVladik netman\n2\n?: Hello, Vladik!\n?: Hi", "output": "netman: Hello, Vladik!\nVladik: Hi"}, {"input": "1\n2\nnetman vladik\n3\nnetman:how are you?\n?:wrong message\nvladik:im fine", "output": "Impossible"}, {"input": "2\n3\nnetman vladik Fedosik\n2\n?: users are netman, vladik, Fedosik\nvladik: some...
2,200
["brute force", "constructive algorithms", "dp", "implementation", "strings"]
104
[{"input": "1\r\n2\r\nVladik netman\r\n2\r\n?: Hello, Vladik!\r\n?: Hi\r\n", "output": "netman: Hello, Vladik!\r\nVladik: Hi\r\n"}, {"input": "1\r\n2\r\nnetman vladik\r\n3\r\nnetman:how are you?\r\n?:wrong message\r\nvladik:im fine\r\n", "output": "Impossible\r\n"}, {"input": "2\r\n3\r\nnetman vladik Fedosik\r\n2\r\n?:...
false
stdio
null
true
754/C
754
C
PyPy 3
TESTS
3
124
0
59613844
t = int(input()) for g in range(t): n = int(input()) s = input().split() orig = s q = int(input()) x = [] for i in range(q): x += [input().split(':')] last = "xxxxxxxxx" for i in range(len(x)): if(x[i][0]=='?'): for j in s: if(j not in x[i][1] and j != last and i+1 < len(x) and j != x[i+1][0]): ...
104
296
4,812,800
92426123
import re t = int(input()) for _ in range(t): n = int(input()) names = set(input().split()) m = int(input()) dp = [] a = [] for i in range(m): a.append(input()) for i in range(m): sender, msg = a[i].split(':') ls = set(filter(None, re.split('\W+',msg))) dp.append((nam...
Codeforces Round 390 (Div. 2)
CF
2,017
2
256
Vladik and chat
Recently Vladik discovered a new entertainment — coding bots for social networks. He would like to use machine learning in his bots so now he want to prepare some learning data for them. At first, he need to download t chats. Vladik coded a script which should have downloaded the chats, however, something went wrong. ...
The first line contains single integer t (1 ≤ t ≤ 10) — the number of chats. The t chats follow. Each chat is given in the following format. The first line of each chat description contains single integer n (1 ≤ n ≤ 100) — the number of users in the chat. The next line contains n space-separated distinct usernames. E...
Print the information about the t chats in the following format: If it is not possible to recover senders, print single line "Impossible" for this chat. Otherwise print m messages in the following format: <username>:<text> If there are multiple answers, print any of them.
null
null
[{"input": "1\n2\nVladik netman\n2\n?: Hello, Vladik!\n?: Hi", "output": "netman: Hello, Vladik!\nVladik: Hi"}, {"input": "1\n2\nnetman vladik\n3\nnetman:how are you?\n?:wrong message\nvladik:im fine", "output": "Impossible"}, {"input": "2\n3\nnetman vladik Fedosik\n2\n?: users are netman, vladik, Fedosik\nvladik: some...
2,200
["brute force", "constructive algorithms", "dp", "implementation", "strings"]
104
[{"input": "1\r\n2\r\nVladik netman\r\n2\r\n?: Hello, Vladik!\r\n?: Hi\r\n", "output": "netman: Hello, Vladik!\r\nVladik: Hi\r\n"}, {"input": "1\r\n2\r\nnetman vladik\r\n3\r\nnetman:how are you?\r\n?:wrong message\r\nvladik:im fine\r\n", "output": "Impossible\r\n"}, {"input": "2\r\n3\r\nnetman vladik Fedosik\r\n2\r\n?:...
false
stdio
null
true
87/B
87
B
PyPy 3
TESTS
3
248
0
61057097
class CodeforcesTask87BSolution: def __init__(self): self.result = '' self.n = 0 self.expressions = [] def read_input(self): self.n = int(input()) for x in range(self.n): self.expressions.append(input().split(" ")) def process_task(self): result ...
54
156
6,144,000
34230774
from collections import * import sys,re lines = [i[:-1] for i in sys.stdin.readlines()] n = int(lines[0]) lines = lines[1:] typeof = defaultdict(lambda:'errtype') typeof['void'] = 'void' def simplify(s): global typeof l,r = s.count('&'),s.count('*') result = typeof[s[l:len(s)-r]] #print(l,r,result,s[l:len(s)-r]) if...
Codeforces Beta Round 73 (Div. 1 Only)
CF
2,011
1
256
Vasya and Types
Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully understand the statement, please read the language's description below...
The first line contains an integer n (1 ≤ n ≤ 100) — the number of operators. Then follow n lines with operators. Each operator is of one of two types: either "typedef A B", or "typeof A". In the first case the B type differs from void and errtype types, and besides, doesn't have any asterisks and ampersands. All the ...
For every typeof operator print on the single line the answer to that operator — the type that the given operator returned.
null
Let's look at the second sample. After the first two queries typedef the b type is equivalent to void*, and c — to void**. The next query typedef redefines b — it is now equal to &b = &void* = void. At that, the c type doesn't change. After that the c type is defined as &&b* = &&void* = &void = errtype. It doesn't i...
[{"input": "5\ntypedef void* ptv\ntypeof ptv\ntypedef &&ptv node\ntypeof node\ntypeof &ptv", "output": "void*\nerrtype\nvoid"}, {"input": "17\ntypedef void* b\ntypedef b* c\ntypeof b\ntypeof c\ntypedef &b b\ntypeof b\ntypeof c\ntypedef &&b* c\ntypeof c\ntypedef &b* c\ntypeof c\ntypedef &void b\ntypeof b\ntypedef b*****...
1,800
["implementation", "strings"]
54
[{"input": "5\r\ntypedef void* ptv\r\ntypeof ptv\r\ntypedef &&ptv node\r\ntypeof node\r\ntypeof &ptv\r\n", "output": "void*\r\nerrtype\r\nvoid\r\n"}, {"input": "17\r\ntypedef void* b\r\ntypedef b* c\r\ntypeof b\r\ntypeof c\r\ntypedef &b b\r\ntypeof b\r\ntypeof c\r\ntypedef &&b* c\r\ntypeof c\r\ntypedef &b* c\r\ntypeof ...
false
stdio
null
true
616/B
616
B
PyPy 3
TESTS
5
77
0
109333829
cases, b = map(int, input().split()) st = set() while cases: cases -= 1 arr = sorted(map(int, input().split())) st.add(arr[0]) lst = sorted(st) if len(lst) == 1: print(*lst) else: print(lst[1])
16
31
204,800
152545117
n, m = map(int, input().split()) lis = [] for _ in range(n): lis.append(list(map(int, input().split()))) c = 0 s = 0 for i in range(len(lis)): if min(lis[i]) > c: c = min(lis[i]) s = i print(min(lis[s]))
Educational Codeforces Round 5
ICPC
2,016
1
256
Dinner with Emma
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets a...
The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan. Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Print the only integer a — the cost of the dinner for Jack and Emma.
null
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the din...
[{"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1", "output": "2"}, {"input": "3 3\n1 2 3\n2 3 1\n3 1 2", "output": "1"}]
1,000
["games", "greedy"]
16
[{"input": "3 4\r\n4 1 3 5\r\n2 2 2 2\r\n5 4 5 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 3 1\r\n3 1 2\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 10\r\n74 35 82 39 1 84 29 41 70 12\r\n", "output": "1\r\n"}, {"input": "10 1\r\n44\r\n23\r\n65\r\n17\r\n48\r\n29\r\n49...
false
stdio
null
true
616/B
616
B
PyPy 3
TESTS
5
124
0
81440430
n,m=map(int,input().split()) s=[] r=[] k=[] l=[] for j in range(1,n+1): listj=list(map(int,input().split())) a=max(listj) b=min(listj) s.append(a) r.append(b) t=min(s) k.append(t) w=max(r) k.append(w) h=min(k) print(h)
16
31
409,600
208839031
n, m = map(int, input().split()) b = [] mins=[] asdf=[] for i in range(n): c = list(map(int, input().split())) mins.append(min(c)) b.append(c) p = max(mins) for j in range(n): if mins[j]==p: a=j break for k in range(m): z = b[a][k] asdf.append(z) print(min(asdf))
Educational Codeforces Round 5
ICPC
2,016
1
256
Dinner with Emma
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets a...
The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan. Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Print the only integer a — the cost of the dinner for Jack and Emma.
null
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the din...
[{"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1", "output": "2"}, {"input": "3 3\n1 2 3\n2 3 1\n3 1 2", "output": "1"}]
1,000
["games", "greedy"]
16
[{"input": "3 4\r\n4 1 3 5\r\n2 2 2 2\r\n5 4 5 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 3 1\r\n3 1 2\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 10\r\n74 35 82 39 1 84 29 41 70 12\r\n", "output": "1\r\n"}, {"input": "10 1\r\n44\r\n23\r\n65\r\n17\r\n48\r\n29\r\n49...
false
stdio
null
true
31/D
31
D
PyPy 3-64
TESTS
5
122
0
214306244
import sys readline = sys.stdin.readline w, h, n = [int(w) for w in readline().split()] rect = [0, 0, w, h ] vcut = [] hcut = [] for _ in range(n): x1, y1, x2, y2 = [int(w) for w in readline().split()] if x1 == x2: if y1 > y2: y2, y1 = y1, y2 hcut.append([y2 - y1, x1, y1, x2, y2])...
33
218
307,200
85902665
WHn = [[0,0]] # WHn[0].extend(list(map(int, input().split(' ')))) WHn[0].extend([int(x) for x in input().split(' ')]) n = range(WHn[0][-1]) lines = [] lines_aux = [] for i in n: lines.append( [int(x) for x in input().split(' ')] ) lines_aux.append(True) while any(lines_aux): for i in n: if ...
Codeforces Beta Round 31 (Div. 2, Codeforces format)
CF
2,010
2
256
Chocolate
Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parall...
The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, ...
Output n + 1 numbers — areas of the resulting parts in the increasing order.
null
null
[{"input": "2 2 2\n1 0 1 2\n0 1 1 1", "output": "1 1 2"}, {"input": "2 2 3\n1 0 1 2\n0 1 1 1\n1 1 2 1", "output": "1 1 1 1"}, {"input": "2 4 2\n0 1 2 1\n0 3 2 3", "output": "2 2 4"}]
2,000
["dfs and similar", "implementation"]
33
[{"input": "2 2 2\r\n1 0 1 2\r\n0 1 1 1\r\n", "output": "1 1 2 "}, {"input": "2 2 3\r\n1 0 1 2\r\n0 1 1 1\r\n1 1 2 1\r\n", "output": "1 1 1 1 "}, {"input": "2 4 2\r\n0 1 2 1\r\n0 3 2 3\r\n", "output": "2 2 4 "}, {"input": "5 5 3\r\n2 1 2 5\r\n0 1 5 1\r\n4 0 4 1\r\n", "output": "1 4 8 12 "}, {"input": "10 10 4\r\n9 0 9 ...
false
stdio
null
true
482/B
482
B
PyPy 3-64
TESTS
2
77
3,481,600
223640236
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb alph = 'abcdefghijklmnopqrstuvwxyz' #pow(x,mod-2,mod) N,M = map(int,input().split(...
38
514
38,195,200
170446786
import sys input = sys.stdin.readline n, m = map(int, input().split()) ps = [[0] * (n + 2) for _ in range(30)] l, r, q, res = [0] * m, [0] * m, [0] * m, 'YES' for i in range(m): l[i], r[i], q[i] = map(int, input().split()) for i in range(m): for j in range(30): d = (1 << j) & q[i] ps[j][l[i]] +=...
Codeforces Round 275 (Div. 1)
CF
2,014
1
256
Interesting Array
We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value $$a[l_{i}] \& a[l_{i}+1] \& \ldots \& a[r_{i}]$$ should be equal to qi. Your task is to find any interest...
The first line contains two integers n, m (1 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of elements in the array and the number of limits. Each of the next m lines contains three integers li, ri, qi (1 ≤ li ≤ ri ≤ n, 0 ≤ qi < 230) describing the i-th limit.
If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print n integers a[1], a[2], ..., a[n] (0 ≤ a[i] < 230) decribing the interesting array. If there are multiple answers, print any of them. If the interesting array doesn't exist, print "NO" (without the quotes) i...
null
null
[{"input": "3 1\n1 3 3", "output": "YES\n3 3 3"}, {"input": "3 2\n1 3 3\n1 3 2", "output": "NO"}]
1,800
["constructive algorithms", "data structures", "trees"]
38
[{"input": "3 1\r\n1 3 3\r\n", "output": "YES\r\n3 3 3\r\n"}, {"input": "3 2\r\n1 3 3\r\n1 3 2\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 2 536870912\r\n2 3 536870911\r\n", "output": "YES\r\n536870912 1073741823 536870911\r\n"}, {"input": "1 1\r\n1 1 10\r\n", "output": "YES\r\n10\r\n"}, {"input": "1 2\r\n1 1 10\r\n...
false
stdio
null
true
616/B
616
B
PyPy 3-64
TESTS
3
46
0
170883881
import sys readline=sys.stdin.readline N,M=map(int,readline().split()) C=[list(map(int,readline().split())) for n in range(N)] inf=1<<30 ans=-inf for n in range(N): ans=max(ans,min(C[n][m] for m in range(M))) for m in range(M): ans=max(ans,min(C[n][m] for n in range(N))) print(ans)
16
31
512,000
192492228
# LUOGU_RID: 101606881 print(max(min(x) for x in [map(int, s.split()) for s in [*open(0)][1:]]))
Educational Codeforces Round 5
ICPC
2,016
1
256
Dinner with Emma
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets a...
The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan. Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Print the only integer a — the cost of the dinner for Jack and Emma.
null
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the din...
[{"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1", "output": "2"}, {"input": "3 3\n1 2 3\n2 3 1\n3 1 2", "output": "1"}]
1,000
["games", "greedy"]
16
[{"input": "3 4\r\n4 1 3 5\r\n2 2 2 2\r\n5 4 5 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 3 1\r\n3 1 2\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 10\r\n74 35 82 39 1 84 29 41 70 12\r\n", "output": "1\r\n"}, {"input": "10 1\r\n44\r\n23\r\n65\r\n17\r\n48\r\n29\r\n49...
false
stdio
null
true
616/B
616
B
Python 3
TESTS
4
62
6,758,400
130598113
n, m = map(int, input().split()) c = [] for i in range(n): c += [min(list(input().split()))] print(max(c))
16
31
512,000
217145495
n,m=list(map(int,input().split())) arr=[] costlist=[] for i in range(n): l1=list(map(int,input().split())) arr.append(l1) for j in arr: mincost=min(j) costlist.append(mincost) cost=max(costlist) print(cost)
Educational Codeforces Round 5
ICPC
2,016
1
256
Dinner with Emma
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets a...
The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan. Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Print the only integer a — the cost of the dinner for Jack and Emma.
null
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the din...
[{"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1", "output": "2"}, {"input": "3 3\n1 2 3\n2 3 1\n3 1 2", "output": "1"}]
1,000
["games", "greedy"]
16
[{"input": "3 4\r\n4 1 3 5\r\n2 2 2 2\r\n5 4 5 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 3 1\r\n3 1 2\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 10\r\n74 35 82 39 1 84 29 41 70 12\r\n", "output": "1\r\n"}, {"input": "10 1\r\n44\r\n23\r\n65\r\n17\r\n48\r\n29\r\n49...
false
stdio
null
true
731/C
731
C
PyPy 3-64
TESTS
4
62
0
209915686
import sys from collections import defaultdict, Counter input = sys.stdin.readline n, m, k = map(int, input().split()) d = defaultdict(list) c = [0] + list(map(int, input().split())) for i in range(m): u, v = map(int, input().split()) if(u > v): u, v = v, u d[u].append(v) d[v].append(u)...
70
1,138
71,884,800
228104946
from collections import defaultdict from collections import deque def addEdge(u, v): graph[u].append(v) graph[v].append(u) def dfs(u,visited): s = deque() component = [] colors = {} s.append(u) maxOccur = 0 predColor = 0 while len(s) > 0: v = s.pop() color = C[v-1] ...
Codeforces Round 376 (Div. 2)
CF
2,016
2
256
Socks
Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes. Ten minutes before her leave she realized that it would be also useful to prepare instruction of which particular clot...
The first line of input contains three integers n, m and k (2 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000, 1 ≤ k ≤ 200 000) — the number of socks, the number of days and the number of available colors respectively. The second line contain n integers c1, c2, ..., cn (1 ≤ ci ≤ k) — current colors of Arseniy's socks. Each of the fol...
Print one integer — the minimum number of socks that should have their colors changed in order to be able to obey the instructions and not make people laugh from watching the socks of different colors.
null
In the first sample, Arseniy can repaint the first and the third socks to the second color. In the second sample, there is no need to change any colors.
[{"input": "3 2 3\n1 2 3\n1 2\n2 3", "output": "2"}, {"input": "3 2 2\n1 1 2\n1 2\n2 1", "output": "0"}]
1,600
["dfs and similar", "dsu", "graphs", "greedy"]
70
[{"input": "3 2 3\r\n1 2 3\r\n1 2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "3 2 2\r\n1 1 2\r\n1 2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3 3 3\r\n1 2 3\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "2\r\n"}, {"input": "4 2 4\r\n1 2 3 4\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "10 3 2\r\n2 1 1 2 1 1 2 1 2 2\r\n4 ...
false
stdio
null
true
732/D
732
D
PyPy 3-64
TESTS
4
92
13,721,600
218606506
import sys input = lambda: sys.stdin.readline().rstrip() import math from heapq import heappush , heappop from collections import defaultdict,deque,Counter from bisect import * N,M = map(int, input().split()) D = list(map(int, input().split())) A = list(map(int, input().split())) days = sum(A) def check(m): seen ...
49
156
23,654,400
21685058
from collections import deque def main(): n, m = list(map(int, input().split())) test = list(map(int, input().split())) prepare = list(map(int, input().split())) least_days = sum(prepare) + m if least_days > len(test): print(-1) return index = list() for p in ...
Codeforces Round 377 (Div. 2)
CF
2,016
1
256
Exams
Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On e...
The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed t...
Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1.
null
In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four d...
[{"input": "7 2\n0 1 0 2 1 0 2\n2 1", "output": "5"}, {"input": "10 3\n0 0 1 2 3 0 2 0 1 2\n1 1 4", "output": "9"}, {"input": "5 1\n1 1 1 1 1\n5", "output": "-1"}]
1,700
["binary search", "greedy", "sortings"]
53
[{"input": "7 2\r\n0 1 0 2 1 0 2\r\n2 1\r\n", "output": "5\r\n"}, {"input": "10 3\r\n0 0 1 2 3 0 2 0 1 2\r\n1 1 4\r\n", "output": "9\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n5\r\n", "output": "-1\r\n"}, {"input": "100 10\r\n1 1 6 6 6 2 5 7 6 5 3 7 10 10 8 9 7 6 9 2 6 7 8 6 7 5 2 5 10 1 10 1 8 10 2 9 7 1 6 8 3 10 9 4 4 8 8...
false
stdio
null
true
615/B
615
B
PyPy 3-64
TESTS
3
61
0
190140755
from collections import defaultdict n, m = map(int, input().split()) adj = defaultdict(list) for i in range(m): u, v = map(int, input().split()) adj[u].append(v) adj[v].append(u) tried = set() best = 0 for v in adj: if v in tried: continue seen = set() s = [v] tail_size = 0 while s: node = s.pop() tai...
60
638
13,926,400
15249015
import sys def dfs(v): global g, links, used, tail, val used[v] = True maxv = 1 for u in g[v]: if not used[u]: # maxv = max(maxv, dfs(u) + 1) - было used вместо not used в условии dfs(u) maxv = max(maxv, tail[u] + 1) val[v] = links[v] * maxv tail[v]...
Codeforces Round 338 (Div. 2)
CF
2,016
3
256
Longtail Hedgehog
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hed...
First line of the input contains two integers n and m(2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number segments on the picture respectively. Then follow m lines, each containing two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the numbers of points connected by corresponding segment. It's guar...
Print the maximum possible value of the hedgehog's beauty.
null
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3·3 = 9.
[{"input": "8 6\n4 5\n3 5\n2 5\n1 2\n2 8\n6 7", "output": "9"}, {"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "12"}]
1,600
["dp", "graphs"]
60
[{"input": "8 6\r\n4 5\r\n3 5\r\n2 5\r\n1 2\r\n2 8\r\n6 7\r\n", "output": "9\r\n"}, {"input": "4 6\r\n1 2\r\n1 3\r\n1 4\r\n2 3\r\n2 4\r\n3 4\r\n", "output": "12\r\n"}, {"input": "5 7\r\n1 3\r\n2 4\r\n4 5\r\n5 3\r\n2 1\r\n1 4\r\n3 2\r\n", "output": "9\r\n"}, {"input": "5 9\r\n1 3\r\n2 4\r\n4 5\r\n5 3\r\n2 1\r\n1 4\r\n3 ...
false
stdio
null
true
296/B
296
B
Python 3
TESTS
3
92
204,800
14680375
# not E i, j((si > wi) and (sj < wj)) # forall i, j not(si > wi) or not (sj < wj) # forall i,j (si <= wi or sj >= wj) n = int(input()) s = list(input()) w = list(input()) contS = s.count("?") contW = w.count("?") total = 10 ** (contS + contW) maiorIgual = 1 menorIgual = 1 igual = 1 for i in range(0, n): if (s[i]...
38
374
27,443,200
129340367
p = int(1e9+7) def solv(A,B): global p n = len(A) A = [-1 if c=='?' else int(c) for c in A] B = [-1 if c=='?' else int(c) for c in B] s = [1,0,0,0] for i in range(n): if A[i]<0 and B[i]<0: si,ai,bi,ti=10,45,45,100 elif A[i]<0: si,ai,bi,ti=1,9...
Codeforces Round 179 (Div. 2)
CF
2,013
2
256
Yaroslav and Two Strings
Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s, similarly, wj represents the j-th digit of string w. A string's template is a string...
The first line contains integer n (1 ≤ n ≤ 105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals n. The third line contains the second template in the same format.
In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7).
null
The first test contains no question marks and both strings are incomparable, so the answer is 1. The second test has no question marks, but the given strings are comparable, so the answer is 0.
[{"input": "2\n90\n09", "output": "1"}, {"input": "2\n11\n55", "output": "0"}, {"input": "5\n?????\n?????", "output": "993531194"}]
2,000
["combinatorics", "dp"]
38
[{"input": "2\r\n90\r\n09\r\n", "output": "1\r\n"}, {"input": "2\r\n11\r\n55\r\n", "output": "0\r\n"}, {"input": "5\r\n?????\r\n?????\r\n", "output": "993531194\r\n"}, {"input": "10\r\n104?3?1??3\r\n?1755?1??7\r\n", "output": "91015750\r\n"}, {"input": "10\r\n6276405116\r\n6787?352?9\r\n", "output": "46\r\n"}, {"input"...
false
stdio
null
true
613/B
613
B
Python 3
TESTS
0
31
0
15396008
__author__ = 'abdujabbor' def calculate_strength(aa, a, cf, cm): c = 0 for i in aa: if i == a: c += 1 return c * cf + min(aa) * cm n, a, cf, cm, m = [int(x) for x in input().split()] aa = sorted([int(x) for x in input().split()], key=None, reverse=True) while m >= 0: updated = Fa...
35
405
17,510,400
15438013
def main(): from bisect import bisect n, A, cf, cm, m = map(int, input().split()) skills = list(map(int, input().split())) xlat = sorted(range(n), key=skills.__getitem__) sorted_skills = [skills[_] for _ in xlat] bottom_lift, a, c = [], 0, 0 for i, b in enumerate(sorted_skills): c +=...
Codeforces Round 339 (Div. 1)
CF
2,016
2
256
Skills
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai — the current skill level. All skills have the same maximum level A. Along with...
The first line of the input contains five space-separated integers n, A, cf, cm and m (1 ≤ n ≤ 100 000, 1 ≤ A ≤ 109, 0 ≤ cf, cm ≤ 1000, 0 ≤ m ≤ 1015). The second line contains exactly n integers ai (0 ≤ ai ≤ A), separated by spaces, — the current levels of skills.
On the first line print the maximum value of the Force that the character can achieve using no more than m currency units. On the second line print n integers a'i (ai ≤ a'i ≤ A), skill levels which one must achieve in order to reach the specified value of the Force, while using no more than m currency units. Numbers s...
null
In the first test the optimal strategy is to increase the second skill to its maximum, and increase the two others by 1. In the second test one should increase all skills to maximum.
[{"input": "3 5 10 1 5\n1 3 1", "output": "12\n2 5 2"}, {"input": "3 5 10 1 339\n1 3 1", "output": "35\n5 5 5"}]
1,900
["binary search", "brute force", "dp", "greedy", "sortings", "two pointers"]
35
[{"input": "3 5 10 1 5\r\n1 3 1\r\n", "output": "12\r\n2 5 2 \r\n"}, {"input": "3 5 10 1 339\r\n1 3 1\r\n", "output": "35\r\n5 5 5 \r\n"}, {"input": "2 6 0 1 4\r\n5 1\r\n", "output": "5\r\n5 5 \r\n"}, {"input": "1 1000000000 1000 1000 1000000000000000\r\n0\r\n", "output": "1000000001000\r\n1000000000 \r\n"}, {"input": ...
false
stdio
null
true
614/B
614
B
Python 3
TESTS
19
233
1,536,000
172643999
from math import log10 countries=int(input()) ; tanks=input().split() ; ans=0 ; nobea="" for i in tanks: if i == "0" : print(0) ; break plus=log10(int(i)) if int(plus)==plus: ans+=int(plus) else: nobea=i else: if len(nobea)>0: print(nobea+"0"*ans) else: ...
32
92
8,704,000
128679162
n = int(input()) l = list(map(str, input().split()))[:n] if n == 1: print(l[0]) exit(0) no = "1" t = 0 for i in l: if i == "0": print("0") exit(0) elif i == "1": continue elif i.count('1') != 1 or i.count('0') != len(i) - 1: no = i else: t += (len(i) - 1) output = no + ('0' * t) print(ou...
Codeforces Round 339 (Div. 2)
CF
2,016
0.5
256
Gena's Code
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not en...
The first line of the input contains the number of countries n (1 ≤ n ≤ 100 000). The second line contains n non-negative integers ai without leading zeroes — the number of tanks of the i-th country. It is guaranteed that the second line contains at least n - 1 beautiful numbers and the total length of all these numbe...
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
null
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
[{"input": "3\n5 10 1", "output": "50"}, {"input": "4\n1 1 10 11", "output": "110"}, {"input": "5\n0 3 1 100 1", "output": "0"}]
1,400
["implementation", "math"]
32
[{"input": "3\r\n5 10 1\r\n", "output": "50"}, {"input": "4\r\n1 1 10 11\r\n", "output": "110"}, {"input": "5\r\n0 3 1 100 1\r\n", "output": "0"}, {"input": "40\r\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 10 10 100 100\r\n", "output": ...
false
stdio
null
true
731/D
731
D
PyPy 3
TESTS
4
77
0
162204316
import sys readline=sys.stdin.readline N,C=map(int,readline().split()) imos=[0]*(C+1) W=[None]*N for i in range(N): L,*W[i]=map(int,readline().split()) for j in range(L): W[i][j]-=1 cnt=0 for i in range(N-1): for a,b in zip(W[i],W[i+1]): if a<b: imos[0]+=1 imos[C-b]-...
48
451
24,883,200
193087489
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, c = map(int, input().split()) w1 = list(map(int, input().split()))[1:] ng = [0] * (c + 1) ok = 1 for _ in range(n - 1): w2 = list(map(int, input().split()))[1:] f = 0 for i, j in zip(w1, w2): if i < j: l ...
Codeforces Round 376 (Div. 2)
CF
2,016
2
256
80-th Level Archeology
Archeologists have found a secret pass in the dungeon of one of the pyramids of Cycleland. To enter the treasury they have to open an unusual lock on the door. The lock consists of n words, each consisting of some hieroglyphs. The wall near the lock has a round switch. Each rotation of this switch changes the hieroglyp...
The first line of the input contains two integers n and c (2 ≤ n ≤ 500 000, 1 ≤ c ≤ 106) — the number of words, written on the lock, and the number of different hieroglyphs. Each of the following n lines contains the description of one word. The i-th of these lines starts with integer li (1 ≤ li ≤ 500 000), that denot...
If it is possible to open the door by rotating the round switch, print integer x (0 ≤ x ≤ c - 1) that defines the required number of clockwise rotations. If there are several valid x, print any of them. If it is impossible to open the door by this method, print - 1.
null
Word a1, a2, ..., am of length m is lexicographically not greater than word b1, b2, ..., bk of length k, if one of two conditions hold: - at first position i, such that ai ≠ bi, the character ai goes earlier in the alphabet than character bi, i.e. a has smaller character in the first position where they differ; - if t...
[{"input": "4 3\n2 3 2\n1 1\n3 2 3 1\n4 2 3 1 2", "output": "1"}, {"input": "2 5\n2 4 2\n2 4 2", "output": "0"}, {"input": "4 4\n1 2\n1 3\n1 4\n1 2", "output": "-1"}]
2,200
["brute force", "data structures", "greedy", "sortings"]
48
[{"input": "4 3\r\n2 3 2\r\n1 1\r\n3 2 3 1\r\n4 2 3 1 2\r\n", "output": "1\r\n"}, {"input": "2 5\r\n2 4 2\r\n2 4 2\r\n", "output": "0\r\n"}, {"input": "4 4\r\n1 2\r\n1 3\r\n1 4\r\n1 2\r\n", "output": "-1\r\n"}, {"input": "3 1\r\n2 1 1\r\n2 1 1\r\n3 1 1 1\r\n", "output": "0\r\n"}, {"input": "2 10\r\n14 9 6 7 1 6 9 3 1 9...
false
stdio
null
true
298/A
298
A
Python 3
TESTS
8
216
307,200
76282392
n = int(input()) m = input() s = 0 t = 0 flg = 0 flgm = 0 for i in range(n): if m[i] == "R": if flg == 0: s = i+1 flg = 1 if m[i] == "L": if flgm == 0: t = i flgm = 1 if t == 0: t = m.rfind("R")+2 if s == 0: s = m.find("L")+2 print (s,t)
23
92
0
146895360
n=int(input()) path=input() travel=list(filter(('.').__ne__ , path)) if travel[0]=='R' and travel[-1]=='L': start=path.find("R") end=start+path.count("R") print(start+1,end) elif len(travel)==1: position=path.find(travel[0]) if travel[0]=="R": print(position+1,position+2) else: p...
Codeforces Round 180 (Div. 2)
CF
2,013
1
256
Snow Footprints
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint ...
The first line of the input contains integer n (3 ≤ n ≤ 1000). The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed t...
Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them.
null
The first test sample is the one in the picture.
[{"input": "9\n..RRLL...", "output": "3 4"}, {"input": "11\n.RRRLLLLL..", "output": "7 5"}]
1,300
["greedy", "implementation"]
23
[{"input": "9\r\n..RRLL...\r\n", "output": "3 4\r\n"}, {"input": "11\r\n.RRRLLLLL..\r\n", "output": "7 5\r\n"}, {"input": "17\r\n.......RRRRR.....\r\n", "output": "12 13\r\n"}, {"input": "13\r\n....LLLLLL...\r\n", "output": "10 4\r\n"}, {"input": "4\r\n.RL.\r\n", "output": "3 2\r\n"}, {"input": "3\r\n.L.\r\n", "output"...
false
stdio
import sys from collections import deque def main(input_path, output_path, submission_path): with open(input_path) as f: n = int(f.readline().strip()) road = f.readline().strip() with open(submission_path) as f: line = f.readline().strip() try: s, t = map(int, l...
true
735/B
735
B
PyPy 3
TESTS
5
93
0
167648523
def _input(): return map(int, input().split()) n, n1, n2 = _input() lst = sorted(list(_input()), reverse = True) print( sum(lst[:n1])/n1 + sum(lst[n1:n1+n2+1])/n2)
37
92
14,336,000
186721043
import sys input = sys.stdin.readline n, n1, n2 = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse = True) if(n1 > n2): n1, n2 = n2, n1 print(sum(a[ : n1]) / n1 + sum(a[n1 : n1 + n2]) / n2)
Codeforces Round 382 (Div. 2)
CF
2,016
2
256
Urbanization
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities. The wealth of the i of them is equal to ai. Authorities plan to build two cities, first for n1 people and second for n2 peo...
The first line of the input contains three integers n, n1 and n2 (1 ≤ n, n1, n2 ≤ 100 000, n1 + n2 ≤ n) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city. The second line contains n integers a1, a2, ..., a...
Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You 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 ...
null
In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second. In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (a3 + a4) / 2 + a2 = (3 + 2) / 2 + 4 = 6.5
[{"input": "2 1 1\n1 5", "output": "6.00000000"}, {"input": "4 2 1\n1 4 2 3", "output": "6.50000000"}]
1,100
["greedy", "number theory", "sortings"]
37
[{"input": "2 1 1\r\n1 5\r\n", "output": "6.00000000\r\n"}, {"input": "4 2 1\r\n1 4 2 3\r\n", "output": "6.50000000\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "4.50000000\r\n"}, {"input": "10 4 6\r\n3 5 7 9 12 25 67 69 83 96\r\n", "output": "88.91666667\r\n"}, {"input": "19 7 12\r\n1 2 4 8 16 32 64 128 256 512 10...
false
stdio
import sys def main(): input_path, correct_output_path, submission_output_path = sys.argv[1:4] with open(correct_output_path, 'r') as f: correct_output = f.read().strip() with open(submission_output_path, 'r') as f: submission_output = f.read().strip() try: correct = float(cor...
true
612/E
612
E
Python 3
TESTS
2
46
204,800
15021353
import math import itertools n = int(input()) permutation = [int(x) for x in input().split()] cycles = [] visited = [False for i in range(n)] for i in range(n): if not visited[i]: visited[i] = True cycle = [i] j = permutation[i] - 1 while j != i: visited[j] = True ...
18
841
144,896,000
170812201
import sys from collections import defaultdict readline=sys.stdin.readline N=int(readline()) P=list(map(int,readline().split())) for x in range(N): P[x]-=1 perm=[] seen=[False]*N for x in range(N): if seen[x]: continue perm.append([]) perm[-1].append(x) seen[x]=True while not seen[P[x]]...
Educational Codeforces Round 4
ICPC
2,015
2
256
Square Root of Permutation
A permutation of length n is an array containing each integer from 1 to n exactly once. For example, q = [4, 5, 1, 2, 3] is a permutation. For the permutation q the square of permutation is the permutation p that p[i] = q[q[i]] for each i = 1... n. For example, the square of q = [4, 5, 1, 2, 3] is p = q2 = [2, 3, 4, 5,...
The first line contains integer n (1 ≤ n ≤ 106) — the number of elements in permutation p. The second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the elements of permutation p.
If there is no permutation q such that q2 = p print the number "-1". If the answer exists print it. The only line should contain n different integers qi (1 ≤ qi ≤ n) — the elements of the permutation q. If there are several solutions print any of them.
null
null
[{"input": "4\n2 1 4 3", "output": "3 4 2 1"}, {"input": "4\n2 1 3 4", "output": "-1"}, {"input": "5\n2 3 4 5 1", "output": "4 5 1 2 3"}]
2,200
["combinatorics", "constructive algorithms", "dfs and similar", "graphs", "math"]
18
[{"input": "4\r\n2 1 4 3\r\n", "output": "3 4 2 1\r\n"}, {"input": "4\r\n2 1 3 4\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 3 4 5 1\r\n", "output": "4 5 1 2 3\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n8 2 10 3 4 6 1 7 9 5\r\n", "output": "-1\r\n"},...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path, 'r') as f: n = int(f.readline()) p = list(map(int, f.readline().split())) with open(sub_path, 'r') as f: lines = f.readlines() sub_output = [] ...
true
732/D
732
D
PyPy 3-64
TESTS
3
62
13,414,400
218691750
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb alph = 'abcdefghijklmnopqrstuvwxyz' #pow(x,mod-2,mod) def find(days): s = set...
49
202
13,107,200
21538977
n,m = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) sums = sum(B)+len(B) last = [-1] * m cou = 0 ans = 0 per = 0 for j in range(n): if A[j] == 0: cou +=1 else: if last[A[j]-1] == -1: if j >= B[A[j]-1]: ...
Codeforces Round 377 (Div. 2)
CF
2,016
1
256
Exams
Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On e...
The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed t...
Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1.
null
In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four d...
[{"input": "7 2\n0 1 0 2 1 0 2\n2 1", "output": "5"}, {"input": "10 3\n0 0 1 2 3 0 2 0 1 2\n1 1 4", "output": "9"}, {"input": "5 1\n1 1 1 1 1\n5", "output": "-1"}]
1,700
["binary search", "greedy", "sortings"]
53
[{"input": "7 2\r\n0 1 0 2 1 0 2\r\n2 1\r\n", "output": "5\r\n"}, {"input": "10 3\r\n0 0 1 2 3 0 2 0 1 2\r\n1 1 4\r\n", "output": "9\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n5\r\n", "output": "-1\r\n"}, {"input": "100 10\r\n1 1 6 6 6 2 5 7 6 5 3 7 10 10 8 9 7 6 9 2 6 7 8 6 7 5 2 5 10 1 10 1 8 10 2 9 7 1 6 8 3 10 9 4 4 8 8...
false
stdio
null
true
298/A
298
A
Python 3
TESTS
9
62
0
221992962
def yzd_solution(n, road): s = 0 t = 0 if "R" in road and "L" in road: R_i_s = road.index("R") + 1 L_i_s = road.index("L") s = R_i_s if R_i_s < L_i_s else L_i_s t = R_i_s if R_i_s > L_i_s else L_i_s elif "R" in road and "L" not in road: s = road.index("R") + 1...
23
92
0
146956235
n = int(input()) arr = list(input()) def sol(): if 'L' in arr and 'R' in arr: start = 0 end = 0 for i in range(n): if arr[i] == 'R': if start == 0: start = i+1 if arr[i] == 'L': if end == 0: end =...
Codeforces Round 180 (Div. 2)
CF
2,013
1
256
Snow Footprints
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint ...
The first line of the input contains integer n (3 ≤ n ≤ 1000). The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed t...
Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them.
null
The first test sample is the one in the picture.
[{"input": "9\n..RRLL...", "output": "3 4"}, {"input": "11\n.RRRLLLLL..", "output": "7 5"}]
1,300
["greedy", "implementation"]
23
[{"input": "9\r\n..RRLL...\r\n", "output": "3 4\r\n"}, {"input": "11\r\n.RRRLLLLL..\r\n", "output": "7 5\r\n"}, {"input": "17\r\n.......RRRRR.....\r\n", "output": "12 13\r\n"}, {"input": "13\r\n....LLLLLL...\r\n", "output": "10 4\r\n"}, {"input": "4\r\n.RL.\r\n", "output": "3 2\r\n"}, {"input": "3\r\n.L.\r\n", "output"...
false
stdio
import sys from collections import deque def main(input_path, output_path, submission_path): with open(input_path) as f: n = int(f.readline().strip()) road = f.readline().strip() with open(submission_path) as f: line = f.readline().strip() try: s, t = map(int, l...
true
614/B
614
B
PyPy 3
TESTS
30
171
8,704,000
80929027
def check(string): if len(string) == 1: return string[0] != '1' if any(s != '0' for s in string[1:]): return True return False if __name__ == "__main__": n = int(input()) if n == 1: print(input()) exit(0) tanks = [str(x) for x in input().split(' ')] for x in tanks: if x == '0': print(0) exit(0) ...
32
108
1,024,000
202956615
import sys input=sys.stdin.readline n = int(input()) a = input().split() zeros_count = 0 to_multiple = '' for i in a: if (i.count('1') != 1 or i.count('0') != len(i) - 1) and i != '0': to_multiple = i elif i == '0': print(0) exit(0) else: zeros_count += i.count('0') print(t...
Codeforces Round 339 (Div. 2)
CF
2,016
0.5
256
Gena's Code
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not en...
The first line of the input contains the number of countries n (1 ≤ n ≤ 100 000). The second line contains n non-negative integers ai without leading zeroes — the number of tanks of the i-th country. It is guaranteed that the second line contains at least n - 1 beautiful numbers and the total length of all these numbe...
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
null
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
[{"input": "3\n5 10 1", "output": "50"}, {"input": "4\n1 1 10 11", "output": "110"}, {"input": "5\n0 3 1 100 1", "output": "0"}]
1,400
["implementation", "math"]
32
[{"input": "3\r\n5 10 1\r\n", "output": "50"}, {"input": "4\r\n1 1 10 11\r\n", "output": "110"}, {"input": "5\r\n0 3 1 100 1\r\n", "output": "0"}, {"input": "40\r\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 10 10 100 100\r\n", "output": ...
false
stdio
null
true
614/B
614
B
Python 3
TESTS
21
139
6,348,800
17417536
from sys import stdin def isBad(s): if s[0] != '1': return 1 for i in s[1:]: if i != '0': return 1 return 0 def getBad(a): for i in a: if isBad(i): return i return None def getPowerOfTen(a): res = 0 for i in a: if not isBad(i) and ...
32
108
1,638,400
15351667
#!/usr/bin/env python3 import sys N = int(input()) l = input().split() is_zero = True for i in l: if i == '0': break else: is_zero = False if is_zero: print('0') sys.exit(0) def are_all_zero(s): for c in s: if c != '0': return False return True times = 0 ugly = '1...
Codeforces Round 339 (Div. 2)
CF
2,016
0.5
256
Gena's Code
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not en...
The first line of the input contains the number of countries n (1 ≤ n ≤ 100 000). The second line contains n non-negative integers ai without leading zeroes — the number of tanks of the i-th country. It is guaranteed that the second line contains at least n - 1 beautiful numbers and the total length of all these numbe...
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
null
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
[{"input": "3\n5 10 1", "output": "50"}, {"input": "4\n1 1 10 11", "output": "110"}, {"input": "5\n0 3 1 100 1", "output": "0"}]
1,400
["implementation", "math"]
32
[{"input": "3\r\n5 10 1\r\n", "output": "50"}, {"input": "4\r\n1 1 10 11\r\n", "output": "110"}, {"input": "5\r\n0 3 1 100 1\r\n", "output": "0"}, {"input": "40\r\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 10 10 100 100\r\n", "output": ...
false
stdio
null
true
612/E
612
E
Python 3
TESTS
2
62
204,800
29532574
n = int(input()) c = input() c = c.split(" ") c = [int(p) - 1 for p in c] visited = [0 for p in range(0,n,1)] cycle_st = [] for i in range(0,n,1): if visited[i] != 1: cycle = [] cycle.append([i,c[i]]) visited[i] = 1 d = c[i] while visited[d] != 1: cycle.append([d,...
18
1,263
185,753,600
134372041
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) p = [0] + list(map(int, input().split())) visit = [0] * (n + 1) x = [[] for _ in range(n + 1)] q = [0] * n for i in range(1, n + 1): if visit[i]: continue y = [i] visit[i] = 1 while not visit[p[y[-1...
Educational Codeforces Round 4
ICPC
2,015
2
256
Square Root of Permutation
A permutation of length n is an array containing each integer from 1 to n exactly once. For example, q = [4, 5, 1, 2, 3] is a permutation. For the permutation q the square of permutation is the permutation p that p[i] = q[q[i]] for each i = 1... n. For example, the square of q = [4, 5, 1, 2, 3] is p = q2 = [2, 3, 4, 5,...
The first line contains integer n (1 ≤ n ≤ 106) — the number of elements in permutation p. The second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the elements of permutation p.
If there is no permutation q such that q2 = p print the number "-1". If the answer exists print it. The only line should contain n different integers qi (1 ≤ qi ≤ n) — the elements of the permutation q. If there are several solutions print any of them.
null
null
[{"input": "4\n2 1 4 3", "output": "3 4 2 1"}, {"input": "4\n2 1 3 4", "output": "-1"}, {"input": "5\n2 3 4 5 1", "output": "4 5 1 2 3"}]
2,200
["combinatorics", "constructive algorithms", "dfs and similar", "graphs", "math"]
18
[{"input": "4\r\n2 1 4 3\r\n", "output": "3 4 2 1\r\n"}, {"input": "4\r\n2 1 3 4\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 3 4 5 1\r\n", "output": "4 5 1 2 3\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n8 2 10 3 4 6 1 7 9 5\r\n", "output": "-1\r\n"},...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path, 'r') as f: n = int(f.readline()) p = list(map(int, f.readline().split())) with open(sub_path, 'r') as f: lines = f.readlines() sub_output = [] ...
true
614/B
614
B
Python 3
TESTS
22
249
8,601,600
128678674
n = int(input()) l = list(map(str, input().split()))[:n] if n == 1: print(l[0]) exit(0) if "0" in l: print("0") exit(0) l = list(filter(("1").__ne__, l)) if not l: print("1") exit(0) no = -1 t = 0 for i in l: if int(i) % 10: no = int(i) else: t += (len(i) - 1) if no == -1: print(f"1{'0' * t}")...
32
108
1,638,400
15359187
#!/usr/bin/env python3 import sys input() arr = list(input().split()) def isBeautiful(s): if s[0] != '1': return False for c in s[1:]: if c != '0': return False return True logAns = 0 nonBeautiful = None isZero = False for s in arr: if s == "0": isZero = True if isBeautiful(s): logAns += (len(s) - 1) el...
Codeforces Round 339 (Div. 2)
CF
2,016
0.5
256
Gena's Code
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not en...
The first line of the input contains the number of countries n (1 ≤ n ≤ 100 000). The second line contains n non-negative integers ai without leading zeroes — the number of tanks of the i-th country. It is guaranteed that the second line contains at least n - 1 beautiful numbers and the total length of all these numbe...
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
null
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
[{"input": "3\n5 10 1", "output": "50"}, {"input": "4\n1 1 10 11", "output": "110"}, {"input": "5\n0 3 1 100 1", "output": "0"}]
1,400
["implementation", "math"]
32
[{"input": "3\r\n5 10 1\r\n", "output": "50"}, {"input": "4\r\n1 1 10 11\r\n", "output": "110"}, {"input": "5\r\n0 3 1 100 1\r\n", "output": "0"}, {"input": "40\r\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 10 10 100 100\r\n", "output": ...
false
stdio
null
true
482/B
482
B
PyPy 3-64
TESTS
6
171
9,625,600
223635569
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb alph = 'abcdefghijklmnopqrstuvwxyz' #pow(x,mod-2,mod) N,M = map(int,input().split(...
38
670
40,755,200
149038976
import sys readline=sys.stdin.readline class Dual_Segment_Tree: def __init__(self,N,f_act,e_act,operate,lst): self.N=N self.f_act=f_act self.e_act=e_act self.operate=operate self.lst=[None]*self.N for i,x in enumerate(lst): self.lst[i]=x self.segm...
Codeforces Round 275 (Div. 1)
CF
2,014
1
256
Interesting Array
We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value $$a[l_{i}] \& a[l_{i}+1] \& \ldots \& a[r_{i}]$$ should be equal to qi. Your task is to find any interest...
The first line contains two integers n, m (1 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of elements in the array and the number of limits. Each of the next m lines contains three integers li, ri, qi (1 ≤ li ≤ ri ≤ n, 0 ≤ qi < 230) describing the i-th limit.
If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print n integers a[1], a[2], ..., a[n] (0 ≤ a[i] < 230) decribing the interesting array. If there are multiple answers, print any of them. If the interesting array doesn't exist, print "NO" (without the quotes) i...
null
null
[{"input": "3 1\n1 3 3", "output": "YES\n3 3 3"}, {"input": "3 2\n1 3 3\n1 3 2", "output": "NO"}]
1,800
["constructive algorithms", "data structures", "trees"]
38
[{"input": "3 1\r\n1 3 3\r\n", "output": "YES\r\n3 3 3\r\n"}, {"input": "3 2\r\n1 3 3\r\n1 3 2\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 2 536870912\r\n2 3 536870911\r\n", "output": "YES\r\n536870912 1073741823 536870911\r\n"}, {"input": "1 1\r\n1 1 10\r\n", "output": "YES\r\n10\r\n"}, {"input": "1 2\r\n1 1 10\r\n...
false
stdio
null
true
482/B
482
B
PyPy 3-64
TESTS
6
124
4,710,400
169491652
from itertools import accumulate n, m = map(int, input().split()) query = [list(map(int, input().split())) for _ in range(m)] a = [0] * (n + 1) cnt = [[0] * (n + 2) for _ in range(30)] for l, r, v in query: for i in range(30): if v >> i & 1: cnt[i][l] += 1 cnt[i][r + 1] -= 1 for i i...
38
732
25,190,400
121180267
from sys import stdin input=stdin.readline def funcand(a,b): return a&b class SegmentTree: def __init__(self, data, default=(1<<31)-1, func=max): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length...
Codeforces Round 275 (Div. 1)
CF
2,014
1
256
Interesting Array
We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value $$a[l_{i}] \& a[l_{i}+1] \& \ldots \& a[r_{i}]$$ should be equal to qi. Your task is to find any interest...
The first line contains two integers n, m (1 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of elements in the array and the number of limits. Each of the next m lines contains three integers li, ri, qi (1 ≤ li ≤ ri ≤ n, 0 ≤ qi < 230) describing the i-th limit.
If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print n integers a[1], a[2], ..., a[n] (0 ≤ a[i] < 230) decribing the interesting array. If there are multiple answers, print any of them. If the interesting array doesn't exist, print "NO" (without the quotes) i...
null
null
[{"input": "3 1\n1 3 3", "output": "YES\n3 3 3"}, {"input": "3 2\n1 3 3\n1 3 2", "output": "NO"}]
1,800
["constructive algorithms", "data structures", "trees"]
38
[{"input": "3 1\r\n1 3 3\r\n", "output": "YES\r\n3 3 3\r\n"}, {"input": "3 2\r\n1 3 3\r\n1 3 2\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 2 536870912\r\n2 3 536870911\r\n", "output": "YES\r\n536870912 1073741823 536870911\r\n"}, {"input": "1 1\r\n1 1 10\r\n", "output": "YES\r\n10\r\n"}, {"input": "1 2\r\n1 1 10\r\n...
false
stdio
null
true
482/B
482
B
Python 3
TESTS
6
77
409,600
9550202
n, m = map(int, input().split()) t = [list(map(int, input().split())) for i in range(m)] t.sort() def f(k, s): d = 1 << 30 a, b = 0, d for l, r, q in t: if l > a + 1: a, b = 0, d if l > b: b = d if q & k: if a: l = a for i in range(l - 1, r): s[i] += k ...
38
873
66,048,000
88422055
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.wri...
Codeforces Round 275 (Div. 1)
CF
2,014
1
256
Interesting Array
We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value $$a[l_{i}] \& a[l_{i}+1] \& \ldots \& a[r_{i}]$$ should be equal to qi. Your task is to find any interest...
The first line contains two integers n, m (1 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of elements in the array and the number of limits. Each of the next m lines contains three integers li, ri, qi (1 ≤ li ≤ ri ≤ n, 0 ≤ qi < 230) describing the i-th limit.
If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print n integers a[1], a[2], ..., a[n] (0 ≤ a[i] < 230) decribing the interesting array. If there are multiple answers, print any of them. If the interesting array doesn't exist, print "NO" (without the quotes) i...
null
null
[{"input": "3 1\n1 3 3", "output": "YES\n3 3 3"}, {"input": "3 2\n1 3 3\n1 3 2", "output": "NO"}]
1,800
["constructive algorithms", "data structures", "trees"]
38
[{"input": "3 1\r\n1 3 3\r\n", "output": "YES\r\n3 3 3\r\n"}, {"input": "3 2\r\n1 3 3\r\n1 3 2\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 2 536870912\r\n2 3 536870911\r\n", "output": "YES\r\n536870912 1073741823 536870911\r\n"}, {"input": "1 1\r\n1 1 10\r\n", "output": "YES\r\n10\r\n"}, {"input": "1 2\r\n1 1 10\r\n...
false
stdio
null
true
1004/D
1004
D
Python 3
PRETESTS
3
685
61,952,000
40002776
import sys import os def calculate(r, x1, x2, y1, y2): result = 0 s1 = -r if x1 is None else max(x1 + 1, -r) s2 = r if y2 is None else min(r, y2 - 1) result += max(0, abs(s1) + abs(s2) - r + 1) s1 = -r if x1 is None else max(x1 + 1, -r) s2 = -r if y1 is None else max(y1 + 1, -r) result += ...
47
358
79,564,800
142294522
import sys input = sys.stdin.buffer.readline def test(n, m, x, y, d): d2 = [0 for i in range(len(d))] for i in range(n): for j in range(m): D = abs(i-x)+abs(j-y) if D >= len(d2): return False d2[D]+=1 return d==d2 def process(A): t = len...
Codeforces Round 495 (Div. 2)
CF
2,018
2
256
Sonya and Matrix
Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all other cells have the Manhattan distance to the cell containing the zero. The cells with equal numbers ...
The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 10^6$$$) — the number of cells in the matrix. The second line contains $$$t$$$ integers $$$a_1, a_2, \ldots, a_t$$$ ($$$0\leq a_i< t$$$) — the values in the cells in arbitrary order.
In the first line, print two positive integers $$$n$$$ and $$$m$$$ ($$$n \times m = t$$$) — the size of the matrix. In the second line, print two integers $$$x$$$ and $$$y$$$ ($$$1\leq x\leq n$$$, $$$1\leq y\leq m$$$) — the row number and the column number where the cell with $$$0$$$ is located. If there are multiple...
null
You can see the solution to the first example in the legend. You also can choose the cell $$$(2, 2)$$$ for the cell where $$$0$$$ is located. You also can choose a $$$5\times 4$$$ matrix with zero at $$$(4, 2)$$$. In the second example, there is a $$$3\times 6$$$ matrix, where the zero is located at $$$(2, 3)$$$ there...
[{"input": "20\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4", "output": "4 5\n2 2"}, {"input": "18\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1", "output": "3 6\n2 3"}, {"input": "6\n2 1 0 2 1 2", "output": "-1"}]
2,300
["brute force", "constructive algorithms", "implementation"]
47
[{"input": "20\r\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4\r\n", "output": "4 5\r\n2 2\r\n"}, {"input": "18\r\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1\r\n", "output": "3 6\r\n2 3\r\n"}, {"input": "6\r\n2 1 0 2 1 2\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1 1\r\n1 1\r\n"}, {"input": "7\r\n0 1 2 3 4 2 6\r...
false
stdio
import sys from collections import defaultdict def read_ints(file): return list(map(int, file.read().split())) def main(input_path, output_path, submission_output_path): with open(input_path) as f: input_lines = f.read().splitlines() t = int(input_lines[0]) a = list(map(int, input_lines[1].spl...
true
990/F
990
F
PyPy 3-64
TESTS
0
31
0
186227210
from sys import stdin input=lambda :stdin.readline()[:-1] n=int(input()) a=list(map(int,input().split())) edges=[] edge=[[] for i in range(n)] m=int(input()) for _ in range(m): x,y=map(lambda x:int(x)-1,input().split()) edges.append((x,y)) edge[x].append(y) edge[y].append(x) use={} seen=[0]*n for i in range(n...
37
1,216
96,768,000
155788846
from collections import deque import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def get_root(s): v = [] while not s == root[s]: v.append(s) s = root[s] for i in v: root[i] = s return s def unite(s, t): rs, rt = get_root(s), get_root(t) if n...
Educational Codeforces Round 45 (Rated for Div. 2)
ICPC
2,018
2
256
Flow Control
You have to handle a very complex water distribution system. The system consists of $$$n$$$ junctions and $$$m$$$ pipes, $$$i$$$-th pipe connects junctions $$$x_i$$$ and $$$y_i$$$. The only thing you can do is adjusting the pipes. You have to choose $$$m$$$ integer numbers $$$f_1$$$, $$$f_2$$$, ..., $$$f_m$$$ and use ...
The first line contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of junctions. The second line contains $$$n$$$ integers $$$s_1, s_2, \dots, s_n$$$ ($$$-10^4 \le s_i \le 10^4$$$) — constraints for the junctions. The third line contains an integer $$$m$$$ ($$$0 \le m \le 2 \cdot 10^5$$$) — the ...
If you can choose such integer numbers $$$f_1, f_2, \dots, f_m$$$ in such a way that all requirements on incoming and outcoming flows are satisfied, then output "Possible" in the first line. Then output $$$m$$$ lines, $$$i$$$-th line should contain $$$f_i$$$ — the chosen setting numbers for the pipes. Pipes are numbere...
null
null
[{"input": "4\n3 -10 6 1\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "output": "Possible\n4\n-6\n8\n-7\n7"}, {"input": "4\n3 -10 6 4\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "output": "Impossible"}]
2,400
["dfs and similar", "dp", "greedy", "trees"]
37
[{"input": "4\r\n3 -10 6 1\r\n5\r\n1 2\r\n3 2\r\n2 4\r\n3 4\r\n3 1\r\n", "output": "Possible\r\n-3\r\n-6\r\n1\r\n0\r\n0\r\n"}, {"input": "4\r\n3 -10 6 4\r\n5\r\n1 2\r\n3 2\r\n2 4\r\n3 4\r\n3 1\r\n", "output": "Impossible\r\n"}, {"input": "1\r\n0\r\n0\r\n", "output": "Possible\r\n"}, {"input": "1\r\n123\r\n0\r\n", "outp...
false
stdio
import sys def main(): input_path = sys.argv[1] submission_path = sys.argv[3] with open(input_path) as f: n = int(f.readline()) s = list(map(int, f.readline().split())) m = int(f.readline()) pipes = [tuple(map(int, f.readline().split())) for _ in range(m)] sum_s = ...
true
486/C
486
C
PyPy 3-64
TESTS
3
46
0
227677847
# -*- coding : utf-8 -*- # @Time: 2023/10/11 19:34 # @Author: yefei.wang # @File: 486C.py import sys # sys.stdin = open('./../input.txt', 'r') I = lambda: int(input()) MI = lambda: map(int, input().split()) LI = lambda: list(map(int, input().split())) n, p = MI() p -= 1 s = input() i, j = 0, n - 1 idxs = [] ans = ...
40
77
2,560,000
229715065
from os import path from sys import stdin, stdout filename = "../templates/input.txt" if path.exists(filename): stdin = open(filename, 'r') def input(): return stdin.readline().rstrip() def print(*args, sep=' ', end='\n'): stdout.write(sep.join(map(str, args))) stdout.write(end) def solution(): ...
Codeforces Round 277 (Div. 2)
CF
2,014
1
256
Palindrome Transformation
Nam is playing with a string on his computer. The string consists of n lowercase English letters. It is meaningless, so Nam decided to make the string more beautiful, that is to make it be a palindrome by using 4 arrow keys: left, right, up, down. There is a cursor pointing at some symbol of the string. Suppose that c...
The first line contains two space-separated integers n (1 ≤ n ≤ 105) and p (1 ≤ p ≤ n), the length of Nam's string and the initial position of the text cursor. The next line contains n lowercase characters of Nam's string.
Print the minimum number of presses needed to change string into a palindrome.
null
A string is a palindrome if it reads the same forward or reversed. In the sample test, initial Nam's string is: $$aeabcaez$$ (cursor position is shown bold). In optimal solution, Nam may do 6 following steps: $$\begin{array}{cccc} \text{aeabcaez} & \xrightarrow{\text{right}} & \text{aeabcaez} & \xrightarrow{\text{up...
[{"input": "8 3\naeabcaez", "output": "6"}]
1,700
["brute force", "greedy", "implementation"]
40
[{"input": "8 3\r\naeabcaez\r\n", "output": "6\r\n"}, {"input": "8 3\r\nabcddcbb\r\n", "output": "3\r\n"}, {"input": "4 4\r\nrkoa\r\n", "output": "14\r\n"}, {"input": "39 30\r\nyehuqwaffoiyxhkmdipxroolhahbhzprioobxfy\r\n", "output": "138\r\n"}, {"input": "40 23\r\nvwjzsgpdsopsrpsyccavfkyyahdgkmdxrquhcplw\r\n", "output"...
false
stdio
null
true
384/B
384
B
PyPy 3
TESTS
1
77
0
206853412
n, m, descending = map(int, input().split()) arr = [] ptrs = [] solved = 0 for i in range(n): arr.append(list(map(int, input().split()))) ptrs.append([0, m-1]) res = [] for k in range(n): for i in range(m): for j in range(i+1, m): if arr[k][i] > arr[k][j]: res.append("%d ...
31
78
409,600
5803767
n,m,k = map(int,input().split()) print(str(m*(m-1)//2)) for i in range(m): for j in range(m-i-1): if k == 0: print(str(i+1)+' '+str(i+j+2)) else: print(str(i+j+2)+' '+str(i+1))
Codeforces Round 225 (Div. 2)
CF
2,014
1
256
Multitasking
Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers. Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position ...
The first line contains three integers n (1 ≤ n ≤ 1000), m (1 ≤ m ≤ 100) and k. Integer k is 0 if the arrays must be sorted in ascending order, and 1 if the arrays must be sorted in descending order. Each line i of the next n lines contains m integers separated by a space, representing the i-th array. For each elemen...
On the first line of the output print an integer p, the size of the array (p can be at most $$\frac{m(m-1)}{2}$$). Each of the next p lines must contain two distinct integers i and j (1 ≤ i, j ≤ m, i ≠ j), representing the chosen indices. If there are multiple correct answers, you can print any.
null
Consider the first sample. After the first operation, the arrays become [1, 3, 2, 5, 4] and [1, 2, 3, 4, 5]. After the second operation, the arrays become [1, 2, 3, 5, 4] and [1, 2, 3, 4, 5]. After the third operation they become [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5].
[{"input": "2 5 0\n1 3 2 5 4\n1 4 3 2 5", "output": "3\n2 4\n2 3\n4 5"}, {"input": "3 2 1\n1 2\n2 3\n3 4", "output": "1\n2 1"}]
1,500
["greedy", "implementation", "sortings", "two pointers"]
31
[{"input": "2 5 0\r\n1 3 2 5 4\r\n1 4 3 2 5\r\n", "output": "3\r\n2 4\r\n2 3\r\n4 5\r\n"}, {"input": "3 2 1\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "1\r\n2 1\r\n"}, {"input": "2 5 0\r\n836096 600367 472071 200387 79763\r\n714679 505282 233544 157810 152591\r\n", "output": "10\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n2 3\r\n2 4\r\n2...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: lines = f.read().splitlines() n, m, k = map(int, lines[0].split()) arrays = [list(map(int, line.split())) for line in lines[1:n+1]] try: with...
true
298/A
298
A
Python 3
TESTS
3
62
0
165724169
i=input i() x='.'+i() z='L' if x.count('R'):z='R' a,b=x.find('R'),x.rfind('R') if z=='L':a,b=b,a-1 else:b+=1 print(a,b)
23
92
0
148448686
n = int(input()) road = input() a = road.find('R') + 1 t = 0 if a == 0: a = road.find('L') + 1 t = a - 1 for x in range(1, len(road)): if road[x] != 'R' and road[x-1] == 'R': if road[x] == '.': t = x+1 break else: t = x break print(a, t)
Codeforces Round 180 (Div. 2)
CF
2,013
1
256
Snow Footprints
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint ...
The first line of the input contains integer n (3 ≤ n ≤ 1000). The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed t...
Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them.
null
The first test sample is the one in the picture.
[{"input": "9\n..RRLL...", "output": "3 4"}, {"input": "11\n.RRRLLLLL..", "output": "7 5"}]
1,300
["greedy", "implementation"]
23
[{"input": "9\r\n..RRLL...\r\n", "output": "3 4\r\n"}, {"input": "11\r\n.RRRLLLLL..\r\n", "output": "7 5\r\n"}, {"input": "17\r\n.......RRRRR.....\r\n", "output": "12 13\r\n"}, {"input": "13\r\n....LLLLLL...\r\n", "output": "10 4\r\n"}, {"input": "4\r\n.RL.\r\n", "output": "3 2\r\n"}, {"input": "3\r\n.L.\r\n", "output"...
false
stdio
import sys from collections import deque def main(input_path, output_path, submission_path): with open(input_path) as f: n = int(f.readline().strip()) road = f.readline().strip() with open(submission_path) as f: line = f.readline().strip() try: s, t = map(int, l...
true
482/B
482
B
Python 3
TESTS
5
77
0
197456731
import sys input = sys.stdin.readline 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,m = invr() res = [0 for i in range(n)] c = [] for i in range(m): l,r,q = ...
38
982
50,278,400
223672399
import sys input = lambda: sys.stdin.readline().rstrip() from collections import Counter class SegTree: def __init__(self, n, arr): self.size = n self.tree = [0]*(n*2) self.build(arr) def build(self, arr): for i in range(self.size): self.tree[self.size+i] = arr[i] ...
Codeforces Round 275 (Div. 1)
CF
2,014
1
256
Interesting Array
We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value $$a[l_{i}] \& a[l_{i}+1] \& \ldots \& a[r_{i}]$$ should be equal to qi. Your task is to find any interest...
The first line contains two integers n, m (1 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of elements in the array and the number of limits. Each of the next m lines contains three integers li, ri, qi (1 ≤ li ≤ ri ≤ n, 0 ≤ qi < 230) describing the i-th limit.
If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print n integers a[1], a[2], ..., a[n] (0 ≤ a[i] < 230) decribing the interesting array. If there are multiple answers, print any of them. If the interesting array doesn't exist, print "NO" (without the quotes) i...
null
null
[{"input": "3 1\n1 3 3", "output": "YES\n3 3 3"}, {"input": "3 2\n1 3 3\n1 3 2", "output": "NO"}]
1,800
["constructive algorithms", "data structures", "trees"]
38
[{"input": "3 1\r\n1 3 3\r\n", "output": "YES\r\n3 3 3\r\n"}, {"input": "3 2\r\n1 3 3\r\n1 3 2\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 2 536870912\r\n2 3 536870911\r\n", "output": "YES\r\n536870912 1073741823 536870911\r\n"}, {"input": "1 1\r\n1 1 10\r\n", "output": "YES\r\n10\r\n"}, {"input": "1 2\r\n1 1 10\r\n...
false
stdio
null
true
296/B
296
B
Python 3
TESTS
3
92
5,529,600
28195381
n, s = int(input()), 0 s1, s2 = str(input()), str(input()) b1, b2 = False, False for i in range(n): if s1[i] != '?' and s2[i] != '?': if ord(s1[i]) < ord(s2[i]): b1 = True if ord(s1[i]) > ord(s2[i]): b2 = True s += (s1[i] == '?') + (s2[i] == '?') if b1 and b2: print((10 ** s) % (1000000007)) e...
38
528
6,041,600
28195547
n, s = int(input()), 0 s1, s2 = str(input()), str(input()) b1, b2 = False, False for i in range(n): if s1[i] != '?' and s2[i] != '?': if ord(s1[i]) < ord(s2[i]): b1 = True if ord(s1[i]) > ord(s2[i]): b2 = True s += (s1[i] == '?') + (s2[i] == '?') ans1, ans2, ans3 = 1, 1, 1 for i in range(n): i...
Codeforces Round 179 (Div. 2)
CF
2,013
2
256
Yaroslav and Two Strings
Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s, similarly, wj represents the j-th digit of string w. A string's template is a string...
The first line contains integer n (1 ≤ n ≤ 105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals n. The third line contains the second template in the same format.
In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7).
null
The first test contains no question marks and both strings are incomparable, so the answer is 1. The second test has no question marks, but the given strings are comparable, so the answer is 0.
[{"input": "2\n90\n09", "output": "1"}, {"input": "2\n11\n55", "output": "0"}, {"input": "5\n?????\n?????", "output": "993531194"}]
2,000
["combinatorics", "dp"]
38
[{"input": "2\r\n90\r\n09\r\n", "output": "1\r\n"}, {"input": "2\r\n11\r\n55\r\n", "output": "0\r\n"}, {"input": "5\r\n?????\r\n?????\r\n", "output": "993531194\r\n"}, {"input": "10\r\n104?3?1??3\r\n?1755?1??7\r\n", "output": "91015750\r\n"}, {"input": "10\r\n6276405116\r\n6787?352?9\r\n", "output": "46\r\n"}, {"input"...
false
stdio
null
true
1006/C
1006
C
PyPy 3-64
TESTS
20
171
33,075,200
172291156
import sys from os import path if(path.exists('Input.txt')): sys.stdin = open("Input.txt","r") sys.stdout = open("Output.txt","w") from queue import PriorityQueue from math import gcd,floor,sqrt,log,ceil,inf import math from collections import * from collections import deque from bisect import bisect_left ...
27
109
21,094,400
209576531
n = int(input()) a = [int(i) for i in input().split()] i = 0 j = n - 1 si = a[i] sj = a[j] sum_max = 0 while i < j: if si < sj: i += 1 si += a[i] elif si > sj: j -= 1 sj += a[j] else: sum_max = si i += 1 j -= 1 si += a[i] sj += a[j] pri...
Codeforces Round 498 (Div. 3)
ICPC
2,018
1
256
Three Parts of the Array
You are given an array $$$d_1, d_2, \dots, d_n$$$ consisting of $$$n$$$ integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$d$$$. The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^9$$$) — the elements of the array $$$d$$$.
Print a single integer — the maximum possible value of $$$sum_1$$$, considering that the condition $$$sum_1 = sum_3$$$ must be met. Obviously, at least one valid way to split the array exists (use $$$a=c=0$$$ and $$$b=n$$$).
null
In the first example there is only one possible splitting which maximizes $$$sum_1$$$: $$$[1, 3, 1], [~], [1, 4]$$$. In the second example the only way to have $$$sum_1=4$$$ is: $$$[1, 3], [2, 1], [4]$$$. In the third example there is only one way to split the array: $$$[~], [4, 1, 2], [~]$$$.
[{"input": "5\n1 3 1 1 4", "output": "5"}, {"input": "5\n1 3 2 1 4", "output": "4"}, {"input": "3\n4 1 2", "output": "0"}]
1,200
["binary search", "data structures", "two pointers"]
27
[{"input": "5\r\n1 3 1 1 4\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 2 1 4\r\n", "output": "4\r\n"}, {"input": "3\r\n4 1 2\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 3 5 4 5\r\n", "output": "9\r\n"}]
false
stdio
null
true
982/C
982
C
Python 3
TESTS
7
249
9,830,400
146896135
import sys, threading input = sys.stdin.readline def solve(n, graph): stack = [0] parents = {} parents[0] = -1 numNodes = [1]*n while stack: node = stack[-1] isleaf = True for nei in graph[node]: if nei not in parents: parents[nei] = node ...
45
218
15,564,800
177348176
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def bfs(s): q, k = [s], 0 visit = [0] * (n + 1) visit[s] = 1 parent = [-1] * (n + 1) while len(q) ^ k: i = q[k] for j in G[i]: if not visit[j]: visit[j] = 1 pa...
Codeforces Round 484 (Div. 2)
CF
2,018
1
256
Cut 'em all!
You're given a tree with $$$n$$$ vertices. Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) denoting the size of the tree. The next $$$n - 1$$$ lines contain two integers $$$u$$$, $$$v$$$ ($$$1 \le u, v \le n$$$) each, describing the vertices connected by the $$$i$$$-th edge. It's guaranteed that the given edges form a tree.
Output a single integer $$$k$$$ — the maximum number of edges that can be removed to leave all connected components with even size, or $$$-1$$$ if it is impossible to remove edges in order to satisfy this property.
null
In the first example you can remove the edge between vertices $$$1$$$ and $$$4$$$. The graph after that will have two connected components with two vertices in each. In the second example you can't remove edges in such a way that all components have even number of vertices, so the answer is $$$-1$$$.
[{"input": "4\n2 4\n4 1\n3 1", "output": "1"}, {"input": "3\n1 2\n1 3", "output": "-1"}, {"input": "10\n7 1\n8 4\n8 10\n4 7\n6 5\n9 3\n3 5\n2 10\n2 5", "output": "4"}, {"input": "2\n1 2", "output": "0"}]
1,500
["dfs and similar", "dp", "graphs", "greedy", "trees"]
45
[{"input": "4\r\n2 4\r\n4 1\r\n3 1\r\n", "output": "1"}, {"input": "3\r\n1 2\r\n1 3\r\n", "output": "-1"}, {"input": "10\r\n7 1\r\n8 4\r\n8 10\r\n4 7\r\n6 5\r\n9 3\r\n3 5\r\n2 10\r\n2 5\r\n", "output": "4"}, {"input": "2\r\n1 2\r\n", "output": "0"}, {"input": "1\r\n", "output": "-1"}, {"input": "4\r\n1 2\r\n1 3\r\n1 4\...
false
stdio
null
true