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
908/C
908
C
Python 3
TESTS
6
77
5,632,000
33793953
from math import sqrt n, r = list(map(int, input().split())) x = list(map(int, input().split())) o = [] for j in x: k =True for i in reversed(o): if i[0] == j: o.append([j, i[1] + 2 * r]) k =False break elif i[0] + 2 * r == j or i[0] - 2 * r == j: ...
15
124
4,403,200
222645507
from sys import stdin, setrecursionlimit def solve(): n, r = (int(s) for s in stdin.readline().split()) mas = [int(s) for s in stdin.readline().split()] prev_x, prev_y = mas[0], r drop_mas = [(prev_x, prev_y)] ans = [prev_y] for i in range(1, n): cur_x = mas[i] cur_y = r ...
Good Bye 2017
CF
2,017
2
256
New Year and Curling
Carol is currently curling. She has n disks each with radius r on the 2D plane. Initially she has all these disks above the line y = 10100. She then will slide the disks towards the line y = 0 one by one in order from 1 to n. When she slides the i-th disk, she will place its center at the point (xi, 10100). She wil...
The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively. The next line will contain n integers x1, x2, ..., xn (1 ≤ xi ≤ 1 000) — the x-coordinates of the disks.
Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th disk. The output will be accepted if it has absolute or relative error at most 10 - 6. Namely, let's assume that your answer for a particular value of a coordinate is a and the answer of the jury is b. The checker pr...
null
The final positions of the disks will look as follows: In particular, note the position of the last disk.
[{"input": "6 2\n5 5 6 8 3 12", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613"}]
1,500
["brute force", "geometry", "implementation", "math"]
15
[{"input": "6 2\r\n5 5 6 8 3 12\r\n", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\r\n"}, {"input": "1 1\r\n5\r\n", "output": "1\r\n"}, {"input": "5 300\r\n939 465 129 611 532\r\n", "output": "300 667.864105343 1164.9596696 1522.27745533 2117.05388391\r\n"}, {"input": "5 1\r\n416 387 336 116...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, r = map(int, f.readline().split()) with open(output_path) as f: ref = list(map(float, f.read().strip().split())) with open(submission_path) as f: sub = list(map(float, f.read().st...
true
570/D
570
D
PyPy 3-64
TESTS
0
46
0
229667087
import bisect import sys from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: ...
65
1,263
131,379,200
205349623
import bisect import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def make_graph(n, m): x, s = [0] * (2 * m), [0] * (n + 3) for i in range(m): u, v = p[i + 2], i + 2 s[u + 2] += 1 x[2 * i], x[2 * i + 1] = u, v for i in range(3, n + 3): s[i] += s[i...
Codeforces Round 316 (Div. 2)
CF
2,015
2
256
Tree Requests
Roman planted a tree consisting of n vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the n - 1 remaining vertices has a parent in the tree. Vertex is connected with its parent by an edge. The parent of vertex i is vertex pi, the parent index is always less than the i...
The first line contains two integers n, m (1 ≤ n, m ≤ 500 000) — the number of nodes in the tree and queries, respectively. The following line contains n - 1 integers p2, p3, ..., pn — the parents of vertices from the second to the n-th (1 ≤ pi < i). The next line contains n lowercase English letters, the i-th of the...
Print m lines. In the i-th line print "Yes" (without the quotes), if in the i-th query you can make a palindrome from the letters written on the vertices, otherwise print "No" (without the quotes).
null
String s is a palindrome if reads the same from left to right and from right to left. In particular, an empty string is a palindrome. Clarification for the sample test. In the first query there exists only a vertex 1 satisfying all the conditions, we can form a palindrome "z". In the second query vertices 5 and 6 sa...
[{"input": "6 5\n1 1 1 3 3\nzacccd\n1 1\n3 3\n4 1\n6 1\n1 2", "output": "Yes\nNo\nYes\nYes\nYes"}]
2,200
["binary search", "bitmasks", "constructive algorithms", "dfs and similar", "graphs", "trees"]
65
[{"input": "6 5\r\n1 1 1 3 3\r\nzacccd\r\n1 1\r\n3 3\r\n4 1\r\n6 1\r\n1 2\r\n", "output": "Yes\r\nNo\r\nYes\r\nYes\r\nYes\r\n"}, {"input": "5 6\r\n1 1 2 3\r\ncbcab\r\n3 1\r\n5 2\r\n1 3\r\n4 1\r\n4 2\r\n1 1\r\n", "output": "Yes\r\nYes\r\nNo\r\nYes\r\nYes\r\nYes\r\n"}, {"input": "5 6\r\n1 2 2 1\r\nbaabb\r\n1 1\r\n1 2\r\n...
false
stdio
null
true
351/E
351
E
Python 3
TESTS
2
92
0
12311511
n = int(input()) inp = input() seq = inp.split(' ') seq = [ abs(int(x)) for x in seq ] Max = max(seq) nxt = [0] * n cnt = [0] * n pos = [n] * (Max+1) for i in range(n-1, -1, -1): nxt[i] = pos[seq[i]] pos[seq[i]] = i for i in range(0, Max+1): j = pos[i] while(j<n): front = sum(cnt[0:j]) b...
36
280
3,686,400
150804902
import sys input = sys.stdin.buffer.readline def process(A): n = len(A) S = [1 for i in range(n)] d = {} for i in range(n): ai = abs(A[i]) if ai not in d: d[ai] = [] d[ai].append(i) L = sorted(d) answer = 0 while len(L) > 0: ai = L.pop() f...
Codeforces Round 204 (Div. 1)
CF
2,013
2
256
Jeff and Permutation
Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p1, p2, ..., pn for his birthday. Jeff hates inversions in sequences. An inversion in sequence a1, a2, ..., an is a pair of indexes i, j (1 ≤ i < j ≤ n), such that an inequality ai > aj holds. Jeff c...
The first line contains integer n (1 ≤ n ≤ 2000). The next line contains n integers — sequence p1, p2, ..., pn (|pi| ≤ 105). The numbers are separated by spaces.
In a single line print the answer to the problem — the minimum number of inversions Jeff can get.
null
null
[{"input": "2\n2 1", "output": "0"}, {"input": "9\n-2 0 -1 0 -1 2 1 0 -1", "output": "6"}]
2,200
["greedy"]
36
[{"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "9\r\n-2 0 -1 0 -1 2 1 0 -1\r\n", "output": "6\r\n"}, {"input": "9\r\n0 0 1 1 0 0 1 0 1\r\n", "output": "5\r\n"}, {"input": "8\r\n0 1 2 -1 -2 1 -2 2\r\n", "output": "3\r\n"}, {"input": "24\r\n-1 -1 2 2 0 -2 2 -1 0 0 2 -2 3 0 2 -3 0 -3 -1 1 0 0 -1 -2\r\n", "output...
false
stdio
null
true
908/C
908
C
PyPy 3
TESTS
6
93
2,150,400
159926809
import math n, r = map(int, input().split(" ")) xs = [int(x) for x in input().split(" ")] disks = [] for x in xs: highestIntersection = -1 dx = None for disk in disks: if disk["x"] - 2 * r <= x <= disk["x"] + 2 * r: if disk["y"] > highestIntersection: highestIntersection = disk["y"] dx = abs(disk["x"...
15
124
32,256,000
176608726
n, r=[int(k) for k in input().split()] w=[int(k) for k in input().split()] w=w[::-1] z=[(w.pop(), r)] while w: x=w.pop() mx=r for j in z: if abs(x-j[0])<=2*r: mx=max(mx, j[1]+(4*r**2-(x-j[0])**2)**0.5) z.append((x, mx)) print(" ".join([str(k[1]) for k in z]))
Good Bye 2017
CF
2,017
2
256
New Year and Curling
Carol is currently curling. She has n disks each with radius r on the 2D plane. Initially she has all these disks above the line y = 10100. She then will slide the disks towards the line y = 0 one by one in order from 1 to n. When she slides the i-th disk, she will place its center at the point (xi, 10100). She wil...
The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively. The next line will contain n integers x1, x2, ..., xn (1 ≤ xi ≤ 1 000) — the x-coordinates of the disks.
Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th disk. The output will be accepted if it has absolute or relative error at most 10 - 6. Namely, let's assume that your answer for a particular value of a coordinate is a and the answer of the jury is b. The checker pr...
null
The final positions of the disks will look as follows: In particular, note the position of the last disk.
[{"input": "6 2\n5 5 6 8 3 12", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613"}]
1,500
["brute force", "geometry", "implementation", "math"]
15
[{"input": "6 2\r\n5 5 6 8 3 12\r\n", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\r\n"}, {"input": "1 1\r\n5\r\n", "output": "1\r\n"}, {"input": "5 300\r\n939 465 129 611 532\r\n", "output": "300 667.864105343 1164.9596696 1522.27745533 2117.05388391\r\n"}, {"input": "5 1\r\n416 387 336 116...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, r = map(int, f.readline().split()) with open(output_path) as f: ref = list(map(float, f.read().strip().split())) with open(submission_path) as f: sub = list(map(float, f.read().st...
true
908/C
908
C
Python 3
TESTS
6
108
6,246,400
34268593
from sys import stdin import operator class Pair: def __init__(self, x, y): self.x = x self.y = y def __str__(self): #return "(x:" + str(self.x) + ", y:" + str(self.y) + ")" return str(self.y) def calculateDistance(): global n, r, positions distance = 0 for i in ra...
15
140
2,867,200
104160893
import math as m nDiscs, r = [int(x) for x in input().split()] x = [int(x) for x in input().split()] y = [] for i in range(len(x)): tempY = [r] for j in range(i): diffX = abs(x[i] - x[j]) if diffX <= (2 * r): addY = m.sqrt((4 * r * r) - (diffX * diffX)) tempY.append(y[...
Good Bye 2017
CF
2,017
2
256
New Year and Curling
Carol is currently curling. She has n disks each with radius r on the 2D plane. Initially she has all these disks above the line y = 10100. She then will slide the disks towards the line y = 0 one by one in order from 1 to n. When she slides the i-th disk, she will place its center at the point (xi, 10100). She wil...
The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively. The next line will contain n integers x1, x2, ..., xn (1 ≤ xi ≤ 1 000) — the x-coordinates of the disks.
Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th disk. The output will be accepted if it has absolute or relative error at most 10 - 6. Namely, let's assume that your answer for a particular value of a coordinate is a and the answer of the jury is b. The checker pr...
null
The final positions of the disks will look as follows: In particular, note the position of the last disk.
[{"input": "6 2\n5 5 6 8 3 12", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613"}]
1,500
["brute force", "geometry", "implementation", "math"]
15
[{"input": "6 2\r\n5 5 6 8 3 12\r\n", "output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\r\n"}, {"input": "1 1\r\n5\r\n", "output": "1\r\n"}, {"input": "5 300\r\n939 465 129 611 532\r\n", "output": "300 667.864105343 1164.9596696 1522.27745533 2117.05388391\r\n"}, {"input": "5 1\r\n416 387 336 116...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, r = map(int, f.readline().split()) with open(output_path) as f: ref = list(map(float, f.read().strip().split())) with open(submission_path) as f: sub = list(map(float, f.read().st...
true
351/E
351
E
Python 3
TESTS
2
92
0
12311615
n = int(input()) inp = input() seq = inp.split(' ') seq = [ abs(int(x)) for x in seq ] Max = max(seq) nxt = [0] * n cnt = [0] * n pos = [n] * (Max+1) for i in range(n-1, -1, -1): nxt[i] = pos[seq[i]] pos[seq[i]] = i for i in range(0, Max+1): j = pos[i] while(j<n): front = sum(cnt[0:j]) b...
36
280
3,686,400
150804902
import sys input = sys.stdin.buffer.readline def process(A): n = len(A) S = [1 for i in range(n)] d = {} for i in range(n): ai = abs(A[i]) if ai not in d: d[ai] = [] d[ai].append(i) L = sorted(d) answer = 0 while len(L) > 0: ai = L.pop() f...
Codeforces Round 204 (Div. 1)
CF
2,013
2
256
Jeff and Permutation
Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p1, p2, ..., pn for his birthday. Jeff hates inversions in sequences. An inversion in sequence a1, a2, ..., an is a pair of indexes i, j (1 ≤ i < j ≤ n), such that an inequality ai > aj holds. Jeff c...
The first line contains integer n (1 ≤ n ≤ 2000). The next line contains n integers — sequence p1, p2, ..., pn (|pi| ≤ 105). The numbers are separated by spaces.
In a single line print the answer to the problem — the minimum number of inversions Jeff can get.
null
null
[{"input": "2\n2 1", "output": "0"}, {"input": "9\n-2 0 -1 0 -1 2 1 0 -1", "output": "6"}]
2,200
["greedy"]
36
[{"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "9\r\n-2 0 -1 0 -1 2 1 0 -1\r\n", "output": "6\r\n"}, {"input": "9\r\n0 0 1 1 0 0 1 0 1\r\n", "output": "5\r\n"}, {"input": "8\r\n0 1 2 -1 -2 1 -2 2\r\n", "output": "3\r\n"}, {"input": "24\r\n-1 -1 2 2 0 -2 2 -1 0 0 2 -2 3 0 2 -3 0 -3 -1 1 0 0 -1 -2\r\n", "output...
false
stdio
null
true
995/B
995
B
PyPy 3
TESTS
3
124
0
81714246
n = int(input()) a = list(map(int, input().split())) ct = 0 i = 0 while i < n: e = a[i] j = i+1 # print(e, a[j:]) t = j + a[j:].index(e) el = a.pop(t) a = a[:j] + [el] + a[j:] ct += t-j i += 2 print(ct)
22
46
0
228763045
n = int(input()) xs = [int(x) for x in input().split()] seen = {} res = 0 while xs: j = xs.index(xs[0], 1) res += j - 1 xs = xs[1:j] + xs[j+1:] print(res)
Codeforces Round 492 (Div. 1) [Thanks, uDebug!]
CF
2,018
2
256
Suit and Tie
Allen is hosting a formal dinner party. $$$2n$$$ people come to the event in $$$n$$$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $$$2n$$$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this m...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of pairs of people. The second line contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$. For each $$$i$$$ with $$$1 \le i \le n$$$, $$$i$$$ appears exactly twice. If $$$a_j = a_k = i$$$, that means that the $$$j$$$-th and $$$k$$$...
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
null
In the first sample case, we can transform $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$$$ in two steps. Note that the sequence $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$$$ also works in the same number of steps. The second sample case already satisfies th...
[{"input": "4\n1 1 2 3 3 2 4 4", "output": "2"}, {"input": "3\n1 1 2 2 3 3", "output": "0"}, {"input": "3\n3 1 2 3 1 2", "output": "3"}]
1,400
["greedy", "implementation", "math"]
22
[{"input": "4\r\n1 1 2 3 3 2 4 4\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2 2 3 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1 2 3 1 2\r\n", "output": "3\r\n"}, {"input": "8\r\n7 6 2 1 4 3 3 7 2 6 5 1 8 5 8 4\r\n", "output": "27\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 3 3 1 2\...
false
stdio
null
true
995/B
995
B
PyPy 3
TESTS
3
124
0
61724747
n, s = int(input()), 0 *a, = map(int, input().split()) for i in range(2 * n - 1, n - 1, -2): s += i - a.index(a[i]) - 1 a.remove(a[i]) print(s)
22
46
102,400
226139058
def up_map(a): mapp = dict() for i in range(len(a)): if a[i] not in mapp: mapp[a[i]] = [] mapp[a[i]].append(i) return mapp def solve(): n = int(input()) a = list(map(int, input().split())) res = 0 mapp = up_map(a) visit = set() for j in range(len(a)): ...
Codeforces Round 492 (Div. 1) [Thanks, uDebug!]
CF
2,018
2
256
Suit and Tie
Allen is hosting a formal dinner party. $$$2n$$$ people come to the event in $$$n$$$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $$$2n$$$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this m...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of pairs of people. The second line contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$. For each $$$i$$$ with $$$1 \le i \le n$$$, $$$i$$$ appears exactly twice. If $$$a_j = a_k = i$$$, that means that the $$$j$$$-th and $$$k$$$...
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
null
In the first sample case, we can transform $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$$$ in two steps. Note that the sequence $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$$$ also works in the same number of steps. The second sample case already satisfies th...
[{"input": "4\n1 1 2 3 3 2 4 4", "output": "2"}, {"input": "3\n1 1 2 2 3 3", "output": "0"}, {"input": "3\n3 1 2 3 1 2", "output": "3"}]
1,400
["greedy", "implementation", "math"]
22
[{"input": "4\r\n1 1 2 3 3 2 4 4\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2 2 3 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1 2 3 1 2\r\n", "output": "3\r\n"}, {"input": "8\r\n7 6 2 1 4 3 3 7 2 6 5 1 8 5 8 4\r\n", "output": "27\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 3 3 1 2\...
false
stdio
null
true
995/B
995
B
PyPy 3
TESTS
3
140
307,200
103702777
from collections import defaultdict n=int(input()) a=[int(x) for x in input().split()] z=defaultdict(list) for i in range(2*n): z[a[i]].append(i) an=0 for i in range(n-1): if a[i]!=a[i+1]: for j in range(z[a[i]][1],i+1,-1): a[j],a[j-1]=a[j-1],a[j] an+=1 print(an)
22
46
1,536,000
226136644
n = int(input()) A = list(map(int, input().split())) B = [] count = 0 while len(A) != 0: first_elem = A[0] i = 1 while i < len(A): if A[i] == first_elem: A.pop(i) A.pop(0) break else: count+=1 i+=1 print(count)
Codeforces Round 492 (Div. 1) [Thanks, uDebug!]
CF
2,018
2
256
Suit and Tie
Allen is hosting a formal dinner party. $$$2n$$$ people come to the event in $$$n$$$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $$$2n$$$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this m...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of pairs of people. The second line contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$. For each $$$i$$$ with $$$1 \le i \le n$$$, $$$i$$$ appears exactly twice. If $$$a_j = a_k = i$$$, that means that the $$$j$$$-th and $$$k$$$...
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
null
In the first sample case, we can transform $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$$$ in two steps. Note that the sequence $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$$$ also works in the same number of steps. The second sample case already satisfies th...
[{"input": "4\n1 1 2 3 3 2 4 4", "output": "2"}, {"input": "3\n1 1 2 2 3 3", "output": "0"}, {"input": "3\n3 1 2 3 1 2", "output": "3"}]
1,400
["greedy", "implementation", "math"]
22
[{"input": "4\r\n1 1 2 3 3 2 4 4\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2 2 3 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1 2 3 1 2\r\n", "output": "3\r\n"}, {"input": "8\r\n7 6 2 1 4 3 3 7 2 6 5 1 8 5 8 4\r\n", "output": "27\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 3 3 1 2\...
false
stdio
null
true
883/K
883
K
Python 3
TESTS
0
46
0
138783166
n = int(input()) a = [] for _ in range(n): a.append(list(map(int,input().split()))) ls = [[0,0] for i in range(n)] check = False for i in range(1,n): ls[i-1][0] = max(a[i][0]-1,a[i-1][0]) ls[i-1][1] = max(a[i][1]+1+a[i][0],ls[i-1][0]) ls[i-1][1] = min(ls[i-1][1],a[i-1][0]+a[i-1][1]) if a[i][0]+1+a[i...
109
1,637
20,377,600
42341522
n = int(input()) ss = [0] * (n + 1) gg = [0] * (n + 1) #mins = [0] * n maxs = [0] * n curMin = -10 ** 10 curMax = -curMin for i in range(n): s, g = map(int, input().split(' ')) ss[i] = s gg[i] = g curMin = max(curMin - 1, s) curMax = min(curMax + 1, s + g) if curMin > curMax: print(-1...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Road Widening
Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy! The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time o...
The first line contains integer n (1 ≤ n ≤ 2·105) — number of parts of the street. Each of the following n lines contains two integers si, gi (1 ≤ si ≤ 106, 0 ≤ gi ≤ 106) — current width of road and width of the lawn on the i-th part of the street.
In the first line print the total width of lawns which will be removed. In the second line print n integers s'1, s'2, ..., s'n (si ≤ s'i ≤ si + gi) — new widths of the road starting from the first part and to the last. If there is no solution, print the only integer -1 in the first line.
null
null
[{"input": "3\n4 5\n4 5\n4 10", "output": "16\n9 9 10"}, {"input": "4\n1 100\n100 1\n1 100\n100 1", "output": "202\n101 101 101 101"}, {"input": "3\n1 1\n100 100\n1 1", "output": "-1"}]
1,800
["constructive algorithms", "greedy", "implementation"]
109
[{"input": "3\r\n4 5\r\n4 5\r\n4 10\r\n", "output": "16\r\n9 9 10 \r\n"}, {"input": "4\r\n1 100\r\n100 1\r\n1 100\r\n100 1\r\n", "output": "202\r\n101 101 101 101 \r\n"}, {"input": "3\r\n1 1\r\n100 100\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "10\r\n21005 10850\r\n27020 13372\r\n28183 3724\r\n22874 13564\r\n27446 11...
false
stdio
null
true
846/D
846
D
PyPy 3
TESTS
18
1,949
53,350,400
80432694
n,m,k,q=list(map(int,input().split())) low,high=float('inf'),-1 qry=list() for _ in range(q): a,b,c=list(map(int,input().split())) low=min(low,c) high=max(high,c) qry.append([a,b,c]) arr=[[0]*(m) for _ in range(n)] for i in range(0,q): arr[qry[i][0]-1][qry[i][1]-1]=qry[i][2] #print(arr) def func...
38
249
35,430,400
130408692
from collections import deque import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def slide_max(n, k, a): ans = [] s = deque() for i in range(n): ai = a[i] while s: if a[s[-1]] <= ai: s.pop() else: break ...
Educational Codeforces Round 28
ICPC
2,017
2
256
Monitor
Recently Luba bought a monitor. Monitor is a rectangular matrix of size n × m. But then she started to notice that some pixels cease to work properly. Luba thinks that the monitor will become broken the first moment when it contains a square k × k consisting entirely of broken pixels. She knows that q pixels are alread...
The first line contains four integer numbers n, m, k, q (1 ≤ n, m ≤ 500, 1 ≤ k ≤ min(n, m), 0 ≤ q ≤ n·m) — the length and width of the monitor, the size of a rectangle such that the monitor is broken if there is a broken rectangle with this size, and the number of broken pixels. Each of next q lines contain three inte...
Print one number — the minimum moment the monitor became broken, or "-1" if it's still not broken after these q pixels stopped working.
null
null
[{"input": "2 3 2 5\n2 1 8\n2 2 8\n1 2 1\n1 3 4\n2 3 2", "output": "8"}, {"input": "3 3 2 5\n1 2 2\n2 2 1\n2 3 5\n3 2 10\n2 1 100", "output": "-1"}]
1,900
["binary search", "data structures"]
38
[{"input": "2 3 2 5\r\n2 1 8\r\n2 2 8\r\n1 2 1\r\n1 3 4\r\n2 3 2\r\n", "output": "8\r\n"}, {"input": "3 3 2 5\r\n1 2 2\r\n2 2 1\r\n2 3 5\r\n3 2 10\r\n2 1 100\r\n", "output": "-1\r\n"}, {"input": "29 50 5 29\r\n21 42 1565821\r\n21 43 53275635\r\n21 44 2717830\r\n21 45 9579585\r\n21 46 20725775\r\n22 42 2568372\r\n22 43 ...
false
stdio
null
true
370/B
370
B
PyPy 3
TESTS
1
140
20,172,800
84716592
n = int(input()) cards = list() for i in range(n): cards.append(list()) inp = [int(j) for j in input().split()] m = inp[0] inp.pop(0) inp.sort() cards[i] = inp c_have_equal_num = list() for i in range(n): c_have_equal_num.append(list()) for j in range(i + 1, n): c_have_equal_num...
24
77
819,200
5783895
# -*- coding: utf-8 -*- n = int(input()) cards = [[set(map(int, input().split()[1:])), i, True] for i in range(n)] cards.sort(key=lambda x: len(x[0])) for i in range(n-1, -1, -1): if not cards[i][2]: continue for j in range(0, i): if cards[j][0] == cards[i][0]: cards[j][2] = cards[...
Codeforces Round 217 (Div. 2)
CF
2,013
1
256
Berland Bingo
Lately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the i-th player contains mi numbers. During the game the host takes num...
The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of the players. Then follow n lines, each line describes a player's card. The line that describes a card starts from integer mi (1 ≤ mi ≤ 100) that shows how many numbers the i-th player's card has. Then follows a sequence of integers ai, 1, ai, ...
Print n lines, the i-th line must contain word "YES" (without the quotes), if the i-th player can win, and "NO" (without the quotes) otherwise.
null
null
[{"input": "3\n1 1\n3 2 4 1\n2 10 11", "output": "YES\nNO\nYES"}, {"input": "2\n1 1\n1 1", "output": "NO\nNO"}]
1,300
["implementation"]
24
[{"input": "3\r\n1 1\r\n3 2 4 1\r\n2 10 11\r\n", "output": "YES\r\nNO\r\nYES\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "NO\r\nNO\r\n"}, {"input": "1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2\r\n1 3\r\n", "output": "YES\r\nYES\r\n"}, {"input": "2\r\n1 1\r\n2 1 2\r\n", "output": "YES\r\nNO\r\n"}, {"i...
false
stdio
null
true
904/C
906
A
Python 3
TESTS
9
389
6,758,400
33883038
#!/usr/bin/python3 import string n = int(input()) exists = set(string.ascii_lowercase) ans = 0 for i in range(n): action, string = input().split(' ') newExists = set(string) #print(newExists) if (action == '.'): exists = exists - newExists if (action == '!'): if (len(exists & newExi...
38
186
5,939,200
33563841
import sys sys.setrecursionlimit(1000000) read = sys.stdin.readline q = int(read()) count = 0 psw = set(list("qwertyuiopasdfghjklzxcvbnm")) unique = None for _ in range(q): s, w = read().strip().split() if len(psw) != 1: if s == '!': _psw = set() for _w in w: if ...
Технокубок 2018 - Отборочный Раунд 4
CF
2,017
2
256
Shockers
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac...
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did. The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types: 1. Valentin pronounced some word and didn't get an electric shock. This action is...
Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined.
null
In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces ...
[{"input": "5\n! abc\n. ad\n. b\n! cd\n? c", "output": "1"}, {"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e", "output": "2"}, {"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h", "output": "0"}]
1,600
["strings"]
38
[{"input": "5\r\n! abc\r\n. ad\r\n. b\r\n! cd\r\n? c\r\n", "output": "1\r\n"}, {"input": "8\r\n! hello\r\n! codeforces\r\n? c\r\n. o\r\n? d\r\n? h\r\n. l\r\n? e\r\n", "output": "2\r\n"}, {"input": "7\r\n! ababahalamaha\r\n? a\r\n? b\r\n? a\r\n? b\r\n? a\r\n? h\r\n", "output": "0\r\n"}, {"input": "4\r\n! abcd\r\n! cdef\...
false
stdio
null
true
29/D
29
D
PyPy 3
TESTS
4
310
512,000
62222356
#TO MAKE THE PROGRAM FAST ''' ---------------------------------------------------------------------------------------------------- ''' import sys from collections import * input = sys.stdin.readline sys.setrecursionlimit(100000) ''' -------------------------------------------------------------------------------------...
35
186
2,150,400
162359731
import sys input = sys.stdin.readline n=int(input()) E=[[] for i in range(n+1)] for i in range(n-1): x,y=map(int,input().split()) E[x].append(y) E[y].append(x) K=list(map(int,input().split())) def dfs(fr,target): Q=[fr] USE=[-1]*(n+1) USE[fr]=0 while Q: x=Q.pop() for t...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Ant on the Tree
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connected by n - 1 edges so that there is a path between any pair of ver...
The first line contains integer n (3 ≤ n ≤ 300) — amount of vertexes in the tree. Next n - 1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has number 1. The las...
If the required route doesn't exist, output -1. Otherwise, output 2n - 1 numbers, describing the route. Every time the ant comes to a vertex, output it's index.
null
null
[{"input": "3\n1 2\n2 3\n3", "output": "1 2 3 2 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3", "output": "1 2 4 5 4 6 4 2 1 3 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6", "output": "-1"}]
2,000
["constructive algorithms", "dfs and similar", "trees"]
35
[{"input": "3\r\n1 2\r\n2 3\r\n3\r\n", "output": "1 2 3 2 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 6 3\r\n", "output": "1 2 4 5 4 6 4 2 1 3 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 3 6\r\n", "output": "-1\r\n"}, {"input": "10\r\n8 10\r\n2 1\r\n7 5\r\n5 4\r\n6 10\r\n2 3\r\n3 10\r\n2 9...
false
stdio
null
true
29/D
29
D
Python 3
TESTS
4
154
7,168,000
129459289
from collections import defaultdict n = int(input()) visit = [False]*301 adj = defaultdict(list) path = list() def dfs(v): global visit,path visit[v]=True path.append(v) for u in adj[v]: if visit[u]==False: dfs(u) path.append(v) for i in range(n-1): a,b = input()...
35
186
7,372,800
36637911
class Node: def __init__(self, data=None): self.data = data self.connections = [] self.path = [] class Tree: def __init__(self): self.root = None self.nodes = {} def addConnections(self, p, c): if p not in self.nodes: parent = Node(p) ...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Ant on the Tree
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connected by n - 1 edges so that there is a path between any pair of ver...
The first line contains integer n (3 ≤ n ≤ 300) — amount of vertexes in the tree. Next n - 1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has number 1. The las...
If the required route doesn't exist, output -1. Otherwise, output 2n - 1 numbers, describing the route. Every time the ant comes to a vertex, output it's index.
null
null
[{"input": "3\n1 2\n2 3\n3", "output": "1 2 3 2 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3", "output": "1 2 4 5 4 6 4 2 1 3 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6", "output": "-1"}]
2,000
["constructive algorithms", "dfs and similar", "trees"]
35
[{"input": "3\r\n1 2\r\n2 3\r\n3\r\n", "output": "1 2 3 2 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 6 3\r\n", "output": "1 2 4 5 4 6 4 2 1 3 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 3 6\r\n", "output": "-1\r\n"}, {"input": "10\r\n8 10\r\n2 1\r\n7 5\r\n5 4\r\n6 10\r\n2 3\r\n3 10\r\n2 9...
false
stdio
null
true
29/D
29
D
Python 3
TESTS
4
154
7,065,600
37731323
# from dust i have come, dust i will be class graph(object): def __init__(self,n): self.n=n self.adj=[list() for i in range(n+1)] self.parent=[0]*(n+1) self.vis=[0]*(n+1) def insert(self,u,v): self.adj[u].append(v) def dfs(self,s,pr): self.vis[s]=1 ...
35
218
1,228,800
139441302
def solve(): n = int(input()) g = [[] for _ in range(n + 1)] for i in range(n - 1): a, b = map(int, input().split(' ')) g[a].append(b) g[b].append(a) lfs = list(map(int, input().split(' '))) k = len(lfs) par = [0 for _ in range(n + 1)] def gp(x, p): par[x] = p for y in g[x]: if y != p: gp(y, x...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Ant on the Tree
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connected by n - 1 edges so that there is a path between any pair of ver...
The first line contains integer n (3 ≤ n ≤ 300) — amount of vertexes in the tree. Next n - 1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has number 1. The las...
If the required route doesn't exist, output -1. Otherwise, output 2n - 1 numbers, describing the route. Every time the ant comes to a vertex, output it's index.
null
null
[{"input": "3\n1 2\n2 3\n3", "output": "1 2 3 2 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3", "output": "1 2 4 5 4 6 4 2 1 3 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6", "output": "-1"}]
2,000
["constructive algorithms", "dfs and similar", "trees"]
35
[{"input": "3\r\n1 2\r\n2 3\r\n3\r\n", "output": "1 2 3 2 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 6 3\r\n", "output": "1 2 4 5 4 6 4 2 1 3 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 3 6\r\n", "output": "-1\r\n"}, {"input": "10\r\n8 10\r\n2 1\r\n7 5\r\n5 4\r\n6 10\r\n2 3\r\n3 10\r\n2 9...
false
stdio
null
true
29/D
29
D
PyPy 3-64
TESTS
4
124
1,126,400
143842124
class Operation: def __init__(self, name, function, function_on_equal, neutral_value=0): self.name = name self.f = function self.f_on_equal = function_on_equal def add_multiple(x, count): return x * count def min_multiple(x, count): return x def max_multiple(x, count): retu...
35
218
2,662,400
145991047
from collections import deque import sys input = sys.stdin.readline def bfs(s): q = deque() q.append(s) visit = [0] * (n + 1) visit[s] = 1 parent = [-1] * (n + 1) while q: i = q.popleft() for j in G[i]: if not visit[j]: q.append(j) vis...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Ant on the Tree
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connected by n - 1 edges so that there is a path between any pair of ver...
The first line contains integer n (3 ≤ n ≤ 300) — amount of vertexes in the tree. Next n - 1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has number 1. The las...
If the required route doesn't exist, output -1. Otherwise, output 2n - 1 numbers, describing the route. Every time the ant comes to a vertex, output it's index.
null
null
[{"input": "3\n1 2\n2 3\n3", "output": "1 2 3 2 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3", "output": "1 2 4 5 4 6 4 2 1 3 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6", "output": "-1"}]
2,000
["constructive algorithms", "dfs and similar", "trees"]
35
[{"input": "3\r\n1 2\r\n2 3\r\n3\r\n", "output": "1 2 3 2 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 6 3\r\n", "output": "1 2 4 5 4 6 4 2 1 3 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 3 6\r\n", "output": "-1\r\n"}, {"input": "10\r\n8 10\r\n2 1\r\n7 5\r\n5 4\r\n6 10\r\n2 3\r\n3 10\r\n2 9...
false
stdio
null
true
667/B
667
B
PyPy 3
PRETESTS
2
93
23,142,400
17571079
n = int(input()) s = [int(i) for i in input().split()] a = max(s) b = min(s) c = sum(s) print(a-(c-a-b))
51
62
3,174,400
153846872
input() s = list(map(int, input().split())) m = max(s) print(max(0, 2*m+1 - sum(s)))
Codeforces Round 349 (Div. 2)
CF
2,016
1
256
Coat of Anticubism
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore. A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-d...
The first line contains an integer n (3 ≤ n ≤ 105) — a number of rod-blanks. The second line contains n integers li (1 ≤ li ≤ 109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with n vertices and nonzero area using the rods Cicasso already has.
Print the only integer z — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (n + 1) vertices and nonzero area from all of the rods.
null
In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}. In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}.
[{"input": "3\n1 2 1", "output": "1"}, {"input": "5\n20 4 3 2 1", "output": "11"}]
1,100
["constructive algorithms", "geometry"]
51
[{"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n20 4 3 2 1\r\n", "output": "11\r\n"}, {"input": "7\r\n77486105 317474713 89523018 332007362 7897847 949616701 54820086\r\n", "output": "70407571\r\n"}, {"input": "14\r\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707 81525 104620306 8...
false
stdio
null
true
814/D
814
D
PyPy 3
TESTS
3
499
10,342,400
90324733
import sys from math import pi, sqrt from decimal import * from random import randint input = sys.stdin.readline N = int(input()) a = [tuple(map(int, input().split())) for _ in range(N)] e = [[0] * N for _ in range(N)] a.sort(key = lambda x: -x[2]) for i in range(N): x, y, r = a[i] for j in range(i + 1, N): u, ...
32
405
24,780,800
28197754
import math class circ: def __init__(self, x, y, r): self.x = x*1.0 self.y = y*1.0 self.r = r*1.0 n = 0 n = int(input()) vec = [] for i in range(n): st = input().split(' ') a = int(st[0]) b = int(st[1]) c = int(st[2]) vec.append(circ(a,b,c)) gr = [[] for i in range(n)] pad = [-1 for i in range(n)] vis = ...
Codeforces Round 418 (Div. 2)
CF
2,017
2
256
An overnight dance in discotheque
The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which i...
The first line of input contains a positive integer n (1 ≤ n ≤ 1 000) — the number of dancers. The following n lines each describes a dancer: the i-th line among them contains three space-separated integers xi, yi and ri ( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) w...
Output one decimal number — the largest achievable sum of spaciousness over two halves of the night. The output is considered correct if it has a relative or absolute error of at most 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $$\frac{|a-b|}{\max(1, |b|)} \...
null
The first sample corresponds to the illustrations in the legend.
[{"input": "5\n2 1 6\n0 4 1\n2 -1 3\n1 -2 1\n4 -1 1", "output": "138.23007676"}, {"input": "8\n0 0 1\n0 0 2\n0 0 3\n0 0 4\n0 0 5\n0 0 6\n0 0 7\n0 0 8", "output": "289.02652413"}]
2,000
["dfs and similar", "dp", "geometry", "greedy", "trees"]
32
[{"input": "5\r\n2 1 6\r\n0 4 1\r\n2 -1 3\r\n1 -2 1\r\n4 -1 1\r\n", "output": "138.23007676\r\n"}, {"input": "8\r\n0 0 1\r\n0 0 2\r\n0 0 3\r\n0 0 4\r\n0 0 5\r\n0 0 6\r\n0 0 7\r\n0 0 8\r\n", "output": "289.02652413\r\n"}, {"input": "4\r\n1000000 -1000000 2\r\n1000000 -1000000 3\r\n-1000000 1000000 2\r\n-1000000 1000000 ...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] # Read correct output with open(correct_output_path, 'r') as f: correct_line = f.readline().strip() try: b = float(correct_line) except: ...
true
159/A
159
A
PyPy 3
TESTS
6
280
0
76053331
n,d=map(int,input().split()) sen=[] re=[] ti=[] for i in range(n): ss=input() s=ss.split() sen.append(s[0]) re.append(s[1]) ti.append(s[2]) m=[] count=0 for i in range(len(sen)): if sen[i] in re: b=re.index(sen[i]) if re[i]==sen[int(b)]: if 0 < int(ti[i]) - int(ti[re...
30
374
204,800
160192565
def closest_value(input_list, input_value): Min = 100000 for num in input_list: dif = abs(num - input_value) if (dif == 0): continue Min = min(Min, dif) return Min n, d = input().split() n = int(n) d = int(d) D = {} F = {()} for i in range(n): a, b, t = input(...
VK Cup 2012 Qualification Round 2
CF
2,012
3
256
Friends or Not
Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ...
The first line of the input contains two integers n and d (1 ≤ n, d ≤ 1000). The next n lines contain the messages log. The i-th line contains one line of the log formatted as "Ai Bi ti" (without the quotes), which means that user Ai sent a message to user Bi at time ti (1 ≤ i ≤ n). Ai and Bi are non-empty strings at m...
In the first line print integer k — the number of pairs of friends. In the next k lines print pairs of friends as "Ai Bi" (without the quotes). You can print users in pairs and the pairs themselves in any order. Each pair must be printed exactly once.
null
In the first sample test case Vasya and Petya are friends because their messages' sending times are one second apart. Anya and Ivan are not, because their messages' sending times differ by more than one second.
[{"input": "4 1\nvasya petya 1\npetya vasya 2\nanya ivan 2\nivan anya 4", "output": "1\npetya vasya"}, {"input": "1 1000\na b 0", "output": "0"}]
1,400
["*special", "greedy", "implementation"]
30
[{"input": "4 1\r\nvasya petya 1\r\npetya vasya 2\r\nanya ivan 2\r\nivan anya 4\r\n", "output": "1\r\npetya vasya\r\n"}, {"input": "1 1000\r\na b 0\r\n", "output": "0\r\n"}, {"input": "2 1\r\na b 0\r\nb a 0\r\n", "output": "0\r\n"}, {"input": "3 1\r\na b 1\r\nb c 2\r\nc d 3\r\n", "output": "0\r\n"}, {"input": "10 2\r\n...
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, 'r') as f: lines = [line.strip() for line in f] n, d = map(int, lines[0].split()) messages = [] for line in lines[1:n+1]: parts = line.split() ...
true
159/A
159
A
Python 3
TESTS
10
122
6,963,200
115946275
n,d=map(int,input().split()) a,b={},set() for i in range(n): q,w,t=input().split() t=int(t) if (w,q)in a: if 0<abs(a[(w,q)]-t)<=d: b.add((q,w)) else:a[(q,w)]=t print(len(b)) for i in b:print(*[*i])
30
560
0
155315914
n,d=map(int,input().split()) lst=[] lst1=[] lst2=[] for i in range(n): lst+=[list(map(str,input().split()))] if n==1: print(0) else: for j in range(n): for k in range(n): if lst[j][0]==lst[k][1] and lst[j][1]==lst[k][0]\ and 0<(int(lst[j][2])-int(lst[k][2]))\ ...
VK Cup 2012 Qualification Round 2
CF
2,012
3
256
Friends or Not
Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ...
The first line of the input contains two integers n and d (1 ≤ n, d ≤ 1000). The next n lines contain the messages log. The i-th line contains one line of the log formatted as "Ai Bi ti" (without the quotes), which means that user Ai sent a message to user Bi at time ti (1 ≤ i ≤ n). Ai and Bi are non-empty strings at m...
In the first line print integer k — the number of pairs of friends. In the next k lines print pairs of friends as "Ai Bi" (without the quotes). You can print users in pairs and the pairs themselves in any order. Each pair must be printed exactly once.
null
In the first sample test case Vasya and Petya are friends because their messages' sending times are one second apart. Anya and Ivan are not, because their messages' sending times differ by more than one second.
[{"input": "4 1\nvasya petya 1\npetya vasya 2\nanya ivan 2\nivan anya 4", "output": "1\npetya vasya"}, {"input": "1 1000\na b 0", "output": "0"}]
1,400
["*special", "greedy", "implementation"]
30
[{"input": "4 1\r\nvasya petya 1\r\npetya vasya 2\r\nanya ivan 2\r\nivan anya 4\r\n", "output": "1\r\npetya vasya\r\n"}, {"input": "1 1000\r\na b 0\r\n", "output": "0\r\n"}, {"input": "2 1\r\na b 0\r\nb a 0\r\n", "output": "0\r\n"}, {"input": "3 1\r\na b 1\r\nb c 2\r\nc d 3\r\n", "output": "0\r\n"}, {"input": "10 2\r\n...
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, 'r') as f: lines = [line.strip() for line in f] n, d = map(int, lines[0].split()) messages = [] for line in lines[1:n+1]: parts = line.split() ...
true
159/A
159
A
PyPy 3-64
TESTS
13
124
102,400
167927881
import sys input = sys.stdin.readline from collections import defaultdict n, q = map(int, input().split()) d = defaultdict(int) s = set() for i in range(n): a, b, c = input()[:-1].split() c = int(c) d[(a, b)] = c if (b,a) in d: if 0 < c - d[(b,a)] <= q: a, b = sorted([a, b]) ...
30
624
6,963,200
123020256
n,d=map(int,input().split()) ans,hist=[],[] for i in range(n): s=input().split() t=int(s[2]) for x in hist: if 0<t-x[2]<=d and s[0]==x[1] and s[1]==x[0]: a=sorted([x[0],x[1]]) if not a in ans: ans.append(a) hist.append([s[0],s[1],t]) print(len(ans)) for x in ans: print(x[...
VK Cup 2012 Qualification Round 2
CF
2,012
3
256
Friends or Not
Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ...
The first line of the input contains two integers n and d (1 ≤ n, d ≤ 1000). The next n lines contain the messages log. The i-th line contains one line of the log formatted as "Ai Bi ti" (without the quotes), which means that user Ai sent a message to user Bi at time ti (1 ≤ i ≤ n). Ai and Bi are non-empty strings at m...
In the first line print integer k — the number of pairs of friends. In the next k lines print pairs of friends as "Ai Bi" (without the quotes). You can print users in pairs and the pairs themselves in any order. Each pair must be printed exactly once.
null
In the first sample test case Vasya and Petya are friends because their messages' sending times are one second apart. Anya and Ivan are not, because their messages' sending times differ by more than one second.
[{"input": "4 1\nvasya petya 1\npetya vasya 2\nanya ivan 2\nivan anya 4", "output": "1\npetya vasya"}, {"input": "1 1000\na b 0", "output": "0"}]
1,400
["*special", "greedy", "implementation"]
30
[{"input": "4 1\r\nvasya petya 1\r\npetya vasya 2\r\nanya ivan 2\r\nivan anya 4\r\n", "output": "1\r\npetya vasya\r\n"}, {"input": "1 1000\r\na b 0\r\n", "output": "0\r\n"}, {"input": "2 1\r\na b 0\r\nb a 0\r\n", "output": "0\r\n"}, {"input": "3 1\r\na b 1\r\nb c 2\r\nc d 3\r\n", "output": "0\r\n"}, {"input": "10 2\r\n...
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, 'r') as f: lines = [line.strip() for line in f] n, d = map(int, lines[0].split()) messages = [] for line in lines[1:n+1]: parts = line.split() ...
true
667/B
667
B
Python 3
TESTS
2
109
0
75809985
#----Kuzlyaev-Nikita-Codeforces----- #------------08.04.2020------------- import math alph="abcdefghijklmnopqrstuvwxyz" #----------------------------------- n=int(input()) l=list(map(int,input().split())) l.sort();r=sum(l)-l[0]-l[-1] print(l[-1]-r)
51
62
3,174,400
186434377
n = int(input()) s = list(map(int,input().split())) a = max(s) b = sum(s) c = max(s) print(a-(b-c)+1)
Codeforces Round 349 (Div. 2)
CF
2,016
1
256
Coat of Anticubism
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore. A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-d...
The first line contains an integer n (3 ≤ n ≤ 105) — a number of rod-blanks. The second line contains n integers li (1 ≤ li ≤ 109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with n vertices and nonzero area using the rods Cicasso already has.
Print the only integer z — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (n + 1) vertices and nonzero area from all of the rods.
null
In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}. In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}.
[{"input": "3\n1 2 1", "output": "1"}, {"input": "5\n20 4 3 2 1", "output": "11"}]
1,100
["constructive algorithms", "geometry"]
51
[{"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n20 4 3 2 1\r\n", "output": "11\r\n"}, {"input": "7\r\n77486105 317474713 89523018 332007362 7897847 949616701 54820086\r\n", "output": "70407571\r\n"}, {"input": "14\r\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707 81525 104620306 8...
false
stdio
null
true
814/D
814
D
Python 3
TESTS
3
108
0
45182548
import math def dist(p, q): x1, y1 = p x2, y2 = q return (x1 - x2) ** 2 + (y1 - y2) ** 2 def main(): n = int(input()) circles = [] for _ in range(n): x, y, r = map(int, input().split()) circles.append(((x, y), r)) circles = sorted(circles, key=lambda circle: circle[1], reverse=True) parent = [...
32
499
2,764,800
188608070
import math import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def bfs(s): q, k = [s], 0 dist[s] = 0 while len(q) ^ k: i = q[k] di = dist[i] for j in G[i]: if dist[j] == inf: dist[j] = di + 1 q.append(j) ...
Codeforces Round 418 (Div. 2)
CF
2,017
2
256
An overnight dance in discotheque
The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which i...
The first line of input contains a positive integer n (1 ≤ n ≤ 1 000) — the number of dancers. The following n lines each describes a dancer: the i-th line among them contains three space-separated integers xi, yi and ri ( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) w...
Output one decimal number — the largest achievable sum of spaciousness over two halves of the night. The output is considered correct if it has a relative or absolute error of at most 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $$\frac{|a-b|}{\max(1, |b|)} \...
null
The first sample corresponds to the illustrations in the legend.
[{"input": "5\n2 1 6\n0 4 1\n2 -1 3\n1 -2 1\n4 -1 1", "output": "138.23007676"}, {"input": "8\n0 0 1\n0 0 2\n0 0 3\n0 0 4\n0 0 5\n0 0 6\n0 0 7\n0 0 8", "output": "289.02652413"}]
2,000
["dfs and similar", "dp", "geometry", "greedy", "trees"]
32
[{"input": "5\r\n2 1 6\r\n0 4 1\r\n2 -1 3\r\n1 -2 1\r\n4 -1 1\r\n", "output": "138.23007676\r\n"}, {"input": "8\r\n0 0 1\r\n0 0 2\r\n0 0 3\r\n0 0 4\r\n0 0 5\r\n0 0 6\r\n0 0 7\r\n0 0 8\r\n", "output": "289.02652413\r\n"}, {"input": "4\r\n1000000 -1000000 2\r\n1000000 -1000000 3\r\n-1000000 1000000 2\r\n-1000000 1000000 ...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] # Read correct output with open(correct_output_path, 'r') as f: correct_line = f.readline().strip() try: b = float(correct_line) except: ...
true
814/D
814
D
PyPy 3
TESTS
3
171
0
90318952
import sys from math import pi, sqrt input = sys.stdin.readline N = int(input()) a = [tuple(map(int, input().split())) for _ in range(N)] e = [[0] * N for _ in range(N)] a.sort(key = lambda x: -x[2]) for i in range(N): x, y, r = a[i] for j in range(i + 1, N): u, v, rr = a[j] d = sqrt((x - u) ** 2 + (y - v) ...
32
561
8,601,600
197617795
s = 0 t = [list(map(int, input().split())) for i in range(int(input()))] f = lambda b: a[2] < b[2] and (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2 <= (a[2] - b[2]) ** 2 for a in t: k = sum(f(b) for b in t) s += (-1, 1)[(k < 1) + k & 1] * a[2] ** 2 print(3.1415926536 * s)
Codeforces Round 418 (Div. 2)
CF
2,017
2
256
An overnight dance in discotheque
The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which i...
The first line of input contains a positive integer n (1 ≤ n ≤ 1 000) — the number of dancers. The following n lines each describes a dancer: the i-th line among them contains three space-separated integers xi, yi and ri ( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) w...
Output one decimal number — the largest achievable sum of spaciousness over two halves of the night. The output is considered correct if it has a relative or absolute error of at most 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $$\frac{|a-b|}{\max(1, |b|)} \...
null
The first sample corresponds to the illustrations in the legend.
[{"input": "5\n2 1 6\n0 4 1\n2 -1 3\n1 -2 1\n4 -1 1", "output": "138.23007676"}, {"input": "8\n0 0 1\n0 0 2\n0 0 3\n0 0 4\n0 0 5\n0 0 6\n0 0 7\n0 0 8", "output": "289.02652413"}]
2,000
["dfs and similar", "dp", "geometry", "greedy", "trees"]
32
[{"input": "5\r\n2 1 6\r\n0 4 1\r\n2 -1 3\r\n1 -2 1\r\n4 -1 1\r\n", "output": "138.23007676\r\n"}, {"input": "8\r\n0 0 1\r\n0 0 2\r\n0 0 3\r\n0 0 4\r\n0 0 5\r\n0 0 6\r\n0 0 7\r\n0 0 8\r\n", "output": "289.02652413\r\n"}, {"input": "4\r\n1000000 -1000000 2\r\n1000000 -1000000 3\r\n-1000000 1000000 2\r\n-1000000 1000000 ...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] # Read correct output with open(correct_output_path, 'r') as f: correct_line = f.readline().strip() try: b = float(correct_line) except: ...
true
904/C
906
A
PyPy 3
TESTS
9
717
24,985,600
126447050
n = int(input()) s = set('abcdefghijklmnopqrstuvwxyz') ans = 0 for i in range(n): b = list(input().split()) if i == n - 1: break if b[0] == '!': s.intersection_update(set(b[1])) if len(s) == 1: ans += 1 elif b[0] == '.': s.difference_update(set(b[1])) else...
38
187
5,734,400
33555597
import sys #f = open('input', 'r') f = sys.stdin n = int(f.readline()) cset = set(chr(ord('a')+i) for i in range(26)) found = False res = 0 for _ in range(n): action, word = f.readline().split() if action == '!': if found: res += 1 cset &= set(word) elif action == '.': cset -= set(word) else:...
Технокубок 2018 - Отборочный Раунд 4
CF
2,017
2
256
Shockers
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac...
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did. The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types: 1. Valentin pronounced some word and didn't get an electric shock. This action is...
Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined.
null
In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces ...
[{"input": "5\n! abc\n. ad\n. b\n! cd\n? c", "output": "1"}, {"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e", "output": "2"}, {"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h", "output": "0"}]
1,600
["strings"]
38
[{"input": "5\r\n! abc\r\n. ad\r\n. b\r\n! cd\r\n? c\r\n", "output": "1\r\n"}, {"input": "8\r\n! hello\r\n! codeforces\r\n? c\r\n. o\r\n? d\r\n? h\r\n. l\r\n? e\r\n", "output": "2\r\n"}, {"input": "7\r\n! ababahalamaha\r\n? a\r\n? b\r\n? a\r\n? b\r\n? a\r\n? h\r\n", "output": "0\r\n"}, {"input": "4\r\n! abcd\r\n! cdef\...
false
stdio
null
true
223/C
223
C
Python 3
TESTS
7
124
5,529,600
33056201
leng, repeat=list(map(int,input().split())) Lis = list(map(int,input().split())) temp=Lis.copy() for rep in range(repeat): summ= Lis[0] for i in range(1,len(Lis)): temp[i]=(summ+Lis[i])%(10**9+7) summ = temp[i] print(*temp)
33
716
26,726,400
33056780
leng, repeat=list(map(int,input().split())) Lis = list(map(int,input().split())) mod = 10**9 + 7 cum = [1] ans = [0]*leng for i in range(1, 2001): cum.append((cum[-1] * (repeat + i - 1) * pow(i, mod-2, mod)) % mod) for i in range(leng): for j in range(i + 1): ans[i] = (ans[i] + cum[i-j] * Lis[j]) % mod...
Codeforces Round 138 (Div. 1)
CF
2,012
4
256
Partial Sums
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals $$s_i = \left( \sum_{j=1}^{i} a_j \right) \m...
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109).
Print n integers  — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces.
null
null
[{"input": "3 1\n1 2 3", "output": "1 3 6"}, {"input": "5 0\n3 14 15 92 6", "output": "3 14 15 92 6"}]
1,900
["combinatorics", "math", "number theory"]
33
[{"input": "3 1\r\n1 2 3\r\n", "output": "1 3 6\r\n"}, {"input": "5 0\r\n3 14 15 92 6\r\n", "output": "3 14 15 92 6\r\n"}, {"input": "1 1\r\n3\r\n", "output": "3\r\n"}, {"input": "1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "1 0\r\n123\r\n", "output": "123\r\n"}, {"input": "1 1\r\n0\r\n", "output": "0\r\n"}, {"input":...
false
stdio
null
true
223/C
223
C
PyPy 3
TESTS
7
216
0
121993979
mod= 10**9 +7 def multiply(a,b): res=[] for i in range(len(a)): ans=0 for j in range (0,i+1): ans+=a[j]*b[i-j] res.append(ans%mod) return res def compute_pow_k(b,k): if(k==1): return b if(k==2): return multiply(b,b) if(k%2==0): a=compute_po...
33
2,276
307,200
5628361
n, k = map(int, input().split()) a = list(map(int, input().split())) m = 1000000007 r = [ 0, 1 ] for i in range(2, n+1): r.append( (- (m // i) * r[m % i]) % m ) c = [ 1 ] for i in range(1, n): c.append((c[i-1] * (k+i-1) * r[i]) % m) ans = [] for i in range(n): t = 0 for j in range(i+1): t = (...
Codeforces Round 138 (Div. 1)
CF
2,012
4
256
Partial Sums
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals $$s_i = \left( \sum_{j=1}^{i} a_j \right) \m...
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109).
Print n integers  — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces.
null
null
[{"input": "3 1\n1 2 3", "output": "1 3 6"}, {"input": "5 0\n3 14 15 92 6", "output": "3 14 15 92 6"}]
1,900
["combinatorics", "math", "number theory"]
33
[{"input": "3 1\r\n1 2 3\r\n", "output": "1 3 6\r\n"}, {"input": "5 0\r\n3 14 15 92 6\r\n", "output": "3 14 15 92 6\r\n"}, {"input": "1 1\r\n3\r\n", "output": "3\r\n"}, {"input": "1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "1 0\r\n123\r\n", "output": "123\r\n"}, {"input": "1 1\r\n0\r\n", "output": "0\r\n"}, {"input":...
false
stdio
null
true
223/C
223
C
PyPy 3
TESTS
7
216
0
107175742
n,k=map(int,input().split()) mod=10**9+7 a=[int(x) for x in input().split()] p=a[:] for i in range(1,n): p[i]=(p[i]+p[i-1])%mod #print(p) for i in range(1,n): a[i]=(k*p[i-1]+a[i])%mod print(*a)
33
3,118
102,400
42134847
n, k = map(int, input().split()) num = list(map(int, input().split())) MOD = 10 ** 9 + 7 cf = [1] for i in range(1, 2020): cf.append((cf[-1] * (k + i - 1) * pow(i, MOD - 2, MOD)) % MOD) ans = [0 for i in range(n)] for i in range(n): for j in range(i + 1): ans[i] = (ans[i] + cf[i - j] * num[j]) % MOD ...
Codeforces Round 138 (Div. 1)
CF
2,012
4
256
Partial Sums
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals $$s_i = \left( \sum_{j=1}^{i} a_j \right) \m...
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109).
Print n integers  — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces.
null
null
[{"input": "3 1\n1 2 3", "output": "1 3 6"}, {"input": "5 0\n3 14 15 92 6", "output": "3 14 15 92 6"}]
1,900
["combinatorics", "math", "number theory"]
33
[{"input": "3 1\r\n1 2 3\r\n", "output": "1 3 6\r\n"}, {"input": "5 0\r\n3 14 15 92 6\r\n", "output": "3 14 15 92 6\r\n"}, {"input": "1 1\r\n3\r\n", "output": "3\r\n"}, {"input": "1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "1 0\r\n123\r\n", "output": "123\r\n"}, {"input": "1 1\r\n0\r\n", "output": "0\r\n"}, {"input":...
false
stdio
null
true
223/C
223
C
PyPy 3
TESTS
7
248
0
96434836
n,k=map(int,input().split()) a=list(map(int,input().split())) for i in range(1,n): a[i]+=a[i-1]*k print(a[i-1]) print(a[-1])
33
498
22,732,800
122265367
n, k= map(int, input().split()) a = list(map(int, input().split())) def find_cf(k,i,a,mod): cf=[1] ans=0 for j in range(1,i): aux=(i-j)*cf[-1]*pow(k+i-j-1,mod-2,mod)%mod cf.append(aux) ans+=aux*a[j-1] ans+=a[i-1] return ans def Combinations(n,r,mod): num = den...
Codeforces Round 138 (Div. 1)
CF
2,012
4
256
Partial Sums
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals $$s_i = \left( \sum_{j=1}^{i} a_j \right) \m...
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109).
Print n integers  — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces.
null
null
[{"input": "3 1\n1 2 3", "output": "1 3 6"}, {"input": "5 0\n3 14 15 92 6", "output": "3 14 15 92 6"}]
1,900
["combinatorics", "math", "number theory"]
33
[{"input": "3 1\r\n1 2 3\r\n", "output": "1 3 6\r\n"}, {"input": "5 0\r\n3 14 15 92 6\r\n", "output": "3 14 15 92 6\r\n"}, {"input": "1 1\r\n3\r\n", "output": "3\r\n"}, {"input": "1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "1 0\r\n123\r\n", "output": "123\r\n"}, {"input": "1 1\r\n0\r\n", "output": "0\r\n"}, {"input":...
false
stdio
null
true
353/B
353
B
PyPy 3
TESTS
9
312
0
82433989
n=int(input()) arr=list(map(int,input().split())) flip2=0 la=0 lb=0 a={} b={} for i in range(2*n): if arr[i] in a and arr[i] in b: if flip2==0 and la<n: a[arr[i]]+=1 arr[i]="1" flip2=1 la+=1 else: b[arr[i]]+=1 arr[i]="2" ...
40
92
0
4730958
n = int(input()) a = list(map(int, input().split())) g = [[] for i in range(100)] for i in range(2 * n): g[a[i]].append(i) x = [0, 0] cur = 1 mus = [] ans = [0] * 2 * n for i in range(10, 100): if len(g[i]) == 1: ans[g[i][0]] = cur x[cur - 1] += 1 cur = 3 - cur if len(g[i]) >= 2: ...
Codeforces Round 205 (Div. 2)
CF
2,013
1
256
Two Heaps
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube fro...
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps,...
null
In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal...
[{"input": "1\n10 99", "output": "1\n2 1"}, {"input": "2\n13 24 13 45", "output": "4\n1 2 2 1"}]
1,900
["combinatorics", "constructive algorithms", "greedy", "implementation", "math", "sortings"]
40
[{"input": "1\r\n10 99\r\n", "output": "1\r\n2 1 \r\n"}, {"input": "2\r\n13 24 13 45\r\n", "output": "4\r\n1 2 2 1 \r\n"}, {"input": "5\r\n21 60 18 21 17 39 58 74 62 34\r\n", "output": "25\r\n1 1 1 2 2 1 2 1 2 2 \r\n"}, {"input": "10\r\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98\r\n", "output": "100\r\...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input with open(input_path) as f: n = int(f.readline()) cubes = list(map(int, f.readline().split())) # Read reference output (to get the expected maximum) with open(output_path) as f: expected_max = int(f...
true
353/B
353
B
Python 3
TESTS
7
92
0
4730939
# from pprint import pprint # from sys import exit N = int(input()) * 2 data = [int(i) for i in input().split()] A = set() B = set() answer = [0] * N one, two = 1, 2 for i, x in enumerate(data): if len(A) > len(B): A, B = B, A one, two = two, one if x not in A: A.add(x) answer[...
40
124
0
4732895
n = int(input()) a = list(map(int, input().split())) proc = sorted([ (a.count(i), i) for i in range(10, 100) if a.count(i) > 0 ]) left, right = [], [] for cnt, val in proc: half = cnt // 2 left.extend([val] * half) right.extend([val] * half) if cnt % 2 == 1: if len(left) < len(right): ...
Codeforces Round 205 (Div. 2)
CF
2,013
1
256
Two Heaps
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube fro...
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps,...
null
In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal...
[{"input": "1\n10 99", "output": "1\n2 1"}, {"input": "2\n13 24 13 45", "output": "4\n1 2 2 1"}]
1,900
["combinatorics", "constructive algorithms", "greedy", "implementation", "math", "sortings"]
40
[{"input": "1\r\n10 99\r\n", "output": "1\r\n2 1 \r\n"}, {"input": "2\r\n13 24 13 45\r\n", "output": "4\r\n1 2 2 1 \r\n"}, {"input": "5\r\n21 60 18 21 17 39 58 74 62 34\r\n", "output": "25\r\n1 1 1 2 2 1 2 1 2 2 \r\n"}, {"input": "10\r\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98\r\n", "output": "100\r\...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input with open(input_path) as f: n = int(f.readline()) cubes = list(map(int, f.readline().split())) # Read reference output (to get the expected maximum) with open(output_path) as f: expected_max = int(f...
true
995/B
995
B
Python 3
TESTS
3
109
307,200
103103958
n = int(input()) pairs = [int(i) for i in input().split(" ")] yes=True i=0 output = 0 while i<=len(pairs)-2: if pairs[0+i]==pairs[1+i]: i+=2 else: a = pairs[0+i] pairs[0+i] = pairs[1+i] pairs[1+i] = a output+=1 i+=1 print(output)
22
61
0
154801963
n = int(input()) people = [int(i) for i in input().split()] switches = 0 for i in range(0, 2*n, 2): person = people[i] other = people.index(person, i+1) people.insert(i+1, people[other]) people.pop(other+1) switches += other - i - 1 print(switches)
Codeforces Round 492 (Div. 1) [Thanks, uDebug!]
CF
2,018
2
256
Suit and Tie
Allen is hosting a formal dinner party. $$$2n$$$ people come to the event in $$$n$$$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $$$2n$$$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this m...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of pairs of people. The second line contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$. For each $$$i$$$ with $$$1 \le i \le n$$$, $$$i$$$ appears exactly twice. If $$$a_j = a_k = i$$$, that means that the $$$j$$$-th and $$$k$$$...
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
null
In the first sample case, we can transform $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$$$ in two steps. Note that the sequence $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$$$ also works in the same number of steps. The second sample case already satisfies th...
[{"input": "4\n1 1 2 3 3 2 4 4", "output": "2"}, {"input": "3\n1 1 2 2 3 3", "output": "0"}, {"input": "3\n3 1 2 3 1 2", "output": "3"}]
1,400
["greedy", "implementation", "math"]
22
[{"input": "4\r\n1 1 2 3 3 2 4 4\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2 2 3 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1 2 3 1 2\r\n", "output": "3\r\n"}, {"input": "8\r\n7 6 2 1 4 3 3 7 2 6 5 1 8 5 8 4\r\n", "output": "27\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 3 3 1 2\...
false
stdio
null
true
813/D
813
D
Python 3
TESTS
1
61
0
27589913
n=int(input()) a=list(map(int,input().split())) maxx=2 for i in range(1,n-1): b=a[0]-1 c=0 for i0 in range(i): if abs(b-a[i])==1 or a[i]%7==a[i]%7: c=c+1 b=a[i]-1 for i0 in range(i,n): if abs(b-a[i])==1 or a[i]%7==a[i]%7: c=c+1 maxx=max(maxx,c) print(maxx)
35
1,434
104,243,200
112897541
import sys def solve(): n = int(sys.stdin.readline()) a = [0] + [int(i) for i in sys.stdin.readline().split()] dp = [[0]*(n + 1) for i in range(n + 1)] ans = 0 maxnum = [0] * (10**5 + 2) maxmod = [0] * 7 for y in range(n + 1): maxmod = [0] * 7 for ai in a: ...
Educational Codeforces Round 22
ICPC
2,017
2
256
Two Melodies
Alice is a beginner composer and now she is ready to create another masterpiece. And not even the single one but two at the same time! Alice has a sheet with n notes written on it. She wants to take two such non-empty non-intersecting subsequences that both of them form a melody and sum of their lengths is maximal. S...
The first line contains one integer number n (2 ≤ n ≤ 5000). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105) — notes written on a sheet.
Print maximum sum of lengths of such two non-empty non-intersecting subsequences that both of them form a melody.
null
In the first example subsequences [1, 2] and [4, 5] give length 4 in total. In the second example subsequences [62, 48, 49] and [60, 61] give length 5 in total. If you choose subsequence [62, 61] in the first place then the second melody will have maximum length 2, that gives the result of 4, which is not maximal.
[{"input": "4\n1 2 4 5", "output": "4"}, {"input": "6\n62 22 60 61 48 49", "output": "5"}]
2,600
["dp", "flows"]
35
[{"input": "4\r\n1 2 4 5\r\n", "output": "4\r\n"}, {"input": "6\r\n62 22 60 61 48 49\r\n", "output": "5\r\n"}, {"input": "2\r\n1 4\r\n", "output": "2\r\n"}, {"input": "2\r\n5 4\r\n", "output": "2\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "9\r\n"}, {"input": "10\r\n7776 32915 1030 71664 7542 72359 6538...
false
stdio
null
true
159/A
159
A
PyPy 3-64
TESTS
13
124
1,740,800
203984402
n, d = map(int,input().split()) mapping = {} friends = set() for _ in range(n): name_1, name_2, t = input().split() t = int(t) mapping[(name_1, name_2)] = t try: if 0 < mapping[(name_1, name_2)] - mapping[(name_2, name_1)] <= d: friends.add(tuple(sorted([name_1, name_2]))) except...
30
1,090
307,200
100395374
l=input().split() n=int(l[0]) d=int(l[1]) lfi=[] lofpairs=[] for you in range(n): s=input().split() for i in lfi: if(s[0]==i[1] and s[1]==i[0]): if(int(s[2])-int(i[2])<=d and int(s[2])-int(i[2])!=0): if((i[0],i[1]) not in lofpairs and (i[1],i[0]) not in lofpairs): ...
VK Cup 2012 Qualification Round 2
CF
2,012
3
256
Friends or Not
Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ...
The first line of the input contains two integers n and d (1 ≤ n, d ≤ 1000). The next n lines contain the messages log. The i-th line contains one line of the log formatted as "Ai Bi ti" (without the quotes), which means that user Ai sent a message to user Bi at time ti (1 ≤ i ≤ n). Ai and Bi are non-empty strings at m...
In the first line print integer k — the number of pairs of friends. In the next k lines print pairs of friends as "Ai Bi" (without the quotes). You can print users in pairs and the pairs themselves in any order. Each pair must be printed exactly once.
null
In the first sample test case Vasya and Petya are friends because their messages' sending times are one second apart. Anya and Ivan are not, because their messages' sending times differ by more than one second.
[{"input": "4 1\nvasya petya 1\npetya vasya 2\nanya ivan 2\nivan anya 4", "output": "1\npetya vasya"}, {"input": "1 1000\na b 0", "output": "0"}]
1,400
["*special", "greedy", "implementation"]
30
[{"input": "4 1\r\nvasya petya 1\r\npetya vasya 2\r\nanya ivan 2\r\nivan anya 4\r\n", "output": "1\r\npetya vasya\r\n"}, {"input": "1 1000\r\na b 0\r\n", "output": "0\r\n"}, {"input": "2 1\r\na b 0\r\nb a 0\r\n", "output": "0\r\n"}, {"input": "3 1\r\na b 1\r\nb c 2\r\nc d 3\r\n", "output": "0\r\n"}, {"input": "10 2\r\n...
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, 'r') as f: lines = [line.strip() for line in f] n, d = map(int, lines[0].split()) messages = [] for line in lines[1:n+1]: parts = line.split() ...
true
159/A
159
A
Python 3
TESTS
13
124
0
10252394
import sys def main(): messages = {} pairs = set() count, dt = sys.stdin.readline().split() dt = int(dt) for line in sys.stdin: res = line.split() p = frozenset((res[0], res[1])) now_t = int(res[2]) if p in pairs: continue forward = "__".join(...
30
1,122
6,963,200
115947862
n,d=map(int,input().split()) a,b=[],set() for i in range(n): q,w,t=input().split() t=int(t) a+=[[q,w,t]] for i in a: for j in a: if (i[1],i[0])not in b and i[0]==j[1]and i[1]==j[0]and 0<abs(i[2]-j[2])<=d: b.add((i[0],i[1])) print(len(b)) for i in b:print(*[*i])
VK Cup 2012 Qualification Round 2
CF
2,012
3
256
Friends or Not
Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ...
The first line of the input contains two integers n and d (1 ≤ n, d ≤ 1000). The next n lines contain the messages log. The i-th line contains one line of the log formatted as "Ai Bi ti" (without the quotes), which means that user Ai sent a message to user Bi at time ti (1 ≤ i ≤ n). Ai and Bi are non-empty strings at m...
In the first line print integer k — the number of pairs of friends. In the next k lines print pairs of friends as "Ai Bi" (without the quotes). You can print users in pairs and the pairs themselves in any order. Each pair must be printed exactly once.
null
In the first sample test case Vasya and Petya are friends because their messages' sending times are one second apart. Anya and Ivan are not, because their messages' sending times differ by more than one second.
[{"input": "4 1\nvasya petya 1\npetya vasya 2\nanya ivan 2\nivan anya 4", "output": "1\npetya vasya"}, {"input": "1 1000\na b 0", "output": "0"}]
1,400
["*special", "greedy", "implementation"]
30
[{"input": "4 1\r\nvasya petya 1\r\npetya vasya 2\r\nanya ivan 2\r\nivan anya 4\r\n", "output": "1\r\npetya vasya\r\n"}, {"input": "1 1000\r\na b 0\r\n", "output": "0\r\n"}, {"input": "2 1\r\na b 0\r\nb a 0\r\n", "output": "0\r\n"}, {"input": "3 1\r\na b 1\r\nb c 2\r\nc d 3\r\n", "output": "0\r\n"}, {"input": "10 2\r\n...
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, 'r') as f: lines = [line.strip() for line in f] n, d = map(int, lines[0].split()) messages = [] for line in lines[1:n+1]: parts = line.split() ...
true
725/D
725
D
Python 3
PRETESTS
2
46
0
21680619
from sys import stdin, stdout n = int(stdin.readline().replace('\n', '')) teams = [] for n in range(n): t, w = stdin.readline().replace('\n', '').split(' ') teams += [(int(t), int(w) - int(t), int(w))] limak = teams[0] steams = sorted(teams) ind = steams.index(limak) budget = limak[0] finalpos = ind if ind > 0:...
49
2,761
33,280,000
21684583
from bisect import bisect_right import heapq n = int(input()) l = [] ti, wi = map(int, input().split()) bal = ti pos = 1 for _ in range(n - 1): ti, wi = map(int, input().split()) if ti > bal: pos += 1 l.append((ti, wi - ti + 1)) l.sort() best_pos = pos op = bisect_right(l, (bal, float('inf'))) #...
Canada Cup 2016
CF
2,016
3
256
Contest Balloons
One tradition of ACM-ICPC contests is that a team gets a balloon for every solved problem. We assume that the submission time doesn't matter and teams are sorted only by the number of balloons they have. It means that one's place is equal to the number of teams with more balloons, increased by 1. For example, if there ...
The first line of the standard input contains one integer n (2 ≤ n ≤ 300 000) — the number of teams. The i-th of n following lines contains two integers ti and wi (0 ≤ ti ≤ wi ≤ 1018) — respectively the number of balloons and the weight of the i-th team. Limak is a member of the first team.
Print one integer denoting the best place Limak can get.
null
In the first sample, Limak has 20 balloons initially. There are three teams with more balloons (32, 40 and 45 balloons), so Limak has the fourth place initially. One optimal strategy is: 1. Limak gives 6 balloons away to a team with 32 balloons and weight 37, which is just enough to make them fly. Unfortunately, Limak...
[{"input": "8\n20 1000\n32 37\n40 1000\n45 50\n16 16\n16 16\n14 1000\n2 1000", "output": "3"}, {"input": "7\n4 4\n4 4\n4 4\n4 4\n4 4\n4 4\n5 5", "output": "2"}, {"input": "7\n14000000003 1000000000000000000\n81000000000 88000000000\n5000000000 7000000000\n15000000000 39000000000\n46000000000 51000000000\n0 1000000000\n...
1,800
["data structures", "greedy"]
49
[{"input": "8\r\n20 1000\r\n32 37\r\n40 1000\r\n45 50\r\n16 16\r\n16 16\r\n14 1000\r\n2 1000\r\n", "output": "3\r\n"}, {"input": "7\r\n4 4\r\n4 4\r\n4 4\r\n4 4\r\n4 4\r\n4 4\r\n5 5\r\n", "output": "2\r\n"}, {"input": "7\r\n14000000003 1000000000000000000\r\n81000000000 88000000000\r\n5000000000 7000000000\r\n1500000000...
false
stdio
null
true
995/B
995
B
PyPy 3-64
TESTS
3
62
0
189900147
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) s = [] m = 0 ans = 0 v = [0] * (n + 1) for i in range(2 * n): if(v[a[i]]): j = s.index(a[i]) ans += m - 1 - j if(j == 0): s.pop(j) m -= 1 else: s.app...
22
61
307,200
144028093
import math import sys import queue def solve(): n = int(input()) a = list(map(int, input().split())) res = 0 s = {} for i in range(n): if a[i * 2 + 1] != a[i * 2]: ind = 0 for j in range(i * 2 + 1, 2 * n): if a[j] == a[i * 2]: i...
Codeforces Round 492 (Div. 1) [Thanks, uDebug!]
CF
2,018
2
256
Suit and Tie
Allen is hosting a formal dinner party. $$$2n$$$ people come to the event in $$$n$$$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $$$2n$$$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this m...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of pairs of people. The second line contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$. For each $$$i$$$ with $$$1 \le i \le n$$$, $$$i$$$ appears exactly twice. If $$$a_j = a_k = i$$$, that means that the $$$j$$$-th and $$$k$$$...
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
null
In the first sample case, we can transform $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$$$ in two steps. Note that the sequence $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$$$ also works in the same number of steps. The second sample case already satisfies th...
[{"input": "4\n1 1 2 3 3 2 4 4", "output": "2"}, {"input": "3\n1 1 2 2 3 3", "output": "0"}, {"input": "3\n3 1 2 3 1 2", "output": "3"}]
1,400
["greedy", "implementation", "math"]
22
[{"input": "4\r\n1 1 2 3 3 2 4 4\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2 2 3 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1 2 3 1 2\r\n", "output": "3\r\n"}, {"input": "8\r\n7 6 2 1 4 3 3 7 2 6 5 1 8 5 8 4\r\n", "output": "27\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 3 3 1 2\...
false
stdio
null
true
995/B
995
B
Python 3
TESTS
3
62
409,600
104683463
from collections import defaultdict n = int(input()) list1 = list(map(int,input().split())) d = defaultdict(list) toadd=tosub = 0 i=0 while i<len(list1): # print(i) # if i<2*n-1 : # print(list1[i],list1[i+1]) if i<2*n-1 and list1[i]==list1[i+1]: i+=2 else: d[list1[i]].append(...
22
62
1,536,000
226127198
n = int(input()) a = list(map(int, input().split())) count = 0 i = 0 while i < 2 * n: if a[i] != a[i + 1]: for j in range(i + 1, 2 * n): if a[i] == a[j]: a = a[:i + 1] + [a[j]] + a[i + 1:j] + a[j + 1:] count += (j - i - 1) else: i += 1 i += 1 print...
Codeforces Round 492 (Div. 1) [Thanks, uDebug!]
CF
2,018
2
256
Suit and Tie
Allen is hosting a formal dinner party. $$$2n$$$ people come to the event in $$$n$$$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $$$2n$$$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this m...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of pairs of people. The second line contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$. For each $$$i$$$ with $$$1 \le i \le n$$$, $$$i$$$ appears exactly twice. If $$$a_j = a_k = i$$$, that means that the $$$j$$$-th and $$$k$$$...
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
null
In the first sample case, we can transform $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$$$ in two steps. Note that the sequence $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$$$ also works in the same number of steps. The second sample case already satisfies th...
[{"input": "4\n1 1 2 3 3 2 4 4", "output": "2"}, {"input": "3\n1 1 2 2 3 3", "output": "0"}, {"input": "3\n3 1 2 3 1 2", "output": "3"}]
1,400
["greedy", "implementation", "math"]
22
[{"input": "4\r\n1 1 2 3 3 2 4 4\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2 2 3 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1 2 3 1 2\r\n", "output": "3\r\n"}, {"input": "8\r\n7 6 2 1 4 3 3 7 2 6 5 1 8 5 8 4\r\n", "output": "27\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 3 3 1 2\...
false
stdio
null
true
883/G
883
G
Python 3
TESTS
3
46
0
31722734
def bfsCalc(succ, s): bfs = [s] queue = [s] while len(queue)>0: edge = queue.pop() for i in succ[edge]: if i not in bfs: bfs.append(i) queue.append(i) return bfs n,m,s = [int(i) for i in input().split(" ")] maxiGraph = {} miniGraph = {} succ = {} res = {} undirected = [] for i in range(1,m+1): succ...
141
2,963
69,222,400
88811817
def put(): return map(int, input().split()) def dfs(x,flag=1): s,vis,ans = [x],[0]*n,['+']*m vis[x]= 1 while s: i = s.pop() for j,k in graph[i]: if vis[j]==0: if k*flag<0: ans[abs(k)-1]='-' elif k*flag>0: ...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Orientation of Edges
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices. Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans: 1. to orient each undirected edge in one of two possible directions to maximize n...
The first line contains three integers n, m and s (2 ≤ n ≤ 3·105, 1 ≤ m ≤ 3·105, 1 ≤ s ≤ n) — number of vertices and edges in the graph, and the vertex Vasya has picked. The following m lines contain information about the graph edges. Each line contains three integers ti, ui and vi (1 ≤ ti ≤ 2, 1 ≤ ui, vi ≤ n, ui ≠ vi...
The first two lines should describe the plan which maximizes the number of reachable vertices. The lines three and four should describe the plan which minimizes the number of reachable vertices. A description of each plan should start with a line containing the number of reachable vertices. The second line of a plan s...
null
null
[{"input": "2 2 1\n1 1 2\n2 2 1", "output": "2\n-\n2\n+"}, {"input": "6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3", "output": "6\n++-\n2\n+-+"}]
1,900
["dfs and similar", "graphs"]
141
[{"input": "2 2 1\r\n1 1 2\r\n2 2 1\r\n", "output": "2\r\n-\r\n2\r\n+\r\n"}, {"input": "6 6 3\r\n2 2 6\r\n1 4 5\r\n2 3 4\r\n1 4 1\r\n1 3 1\r\n2 2 3\r\n", "output": "6\r\n++-\r\n2\r\n+-+\r\n"}, {"input": "5 5 5\r\n2 5 3\r\n1 2 3\r\n1 4 5\r\n2 5 2\r\n1 2 1\r\n", "output": "4\r\n++\r\n1\r\n--\r\n"}, {"input": "13 18 9\r\n...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n, m, s = map(int, f.readline().split()) all_edges = [] for _ in range(m): ti, u, v = m...
true
612/E
612
E
Python 3
TESTS
6
62
0
15199534
n = int(input()) p = list(map(int, input().split())) hasPrinted = False for i in range(1, n+1): q = [0]*n q[0] = i curPos = 0 for j in range(1, n+1): q[q[curPos]-1] = p[curPos] curPos = q[curPos]-1 if q.count(0) != 0: continue elif len(set(q)) != len(q): c...
18
670
110,796,800
165026043
import os from re import M 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...
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
616/B
616
B
PyPy 3
TESTS
7
140
0
78482096
import sys def ans(mat): emma = [] for i in range(len(mat)): emma.append(mat[i][0]) visited = [False]*len(emma) while True: m, n = max_from_emma(emma, visited) current_max = sys.maxsize for i in range(len(mat[0])): if mat[n][i] < current_max: ...
16
31
0
147946788
n,m = map(int,input().split()) max = 0 for i in range(n): a = list(map(int,input().split())) if min(a)>max: max = min(a) print(max)
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
159/A
159
A
Python 3
TESTS
13
62
0
144290254
from math import sqrt,log,ceil,gcd import sys # sys.stdin=open('input.txt','r') # sys.stdout=open('output.txt','w') from random import randint as r def solve(): n,limit=map(int,input().split()) d={} st=set() for i in range(n): a,b,t=map(str,input().split()) t=int(t) if (b,a) in ...
30
1,432
4,915,200
80772133
# n=int(input()) #q.sort(key=lambda x:((x[1]-x[0]),-x[0])) # n,k=map(int,input().split()) # arr=list(map(int,input().split())) #ls=list(map(int,input().split())) #for i in range(m): #from sys import stdin #n=int(stdin.readline()) #for _ in range(int(input())): import os import sys from io import BytesIO, IOBase BUFSIZ...
VK Cup 2012 Qualification Round 2
CF
2,012
3
256
Friends or Not
Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ...
The first line of the input contains two integers n and d (1 ≤ n, d ≤ 1000). The next n lines contain the messages log. The i-th line contains one line of the log formatted as "Ai Bi ti" (without the quotes), which means that user Ai sent a message to user Bi at time ti (1 ≤ i ≤ n). Ai and Bi are non-empty strings at m...
In the first line print integer k — the number of pairs of friends. In the next k lines print pairs of friends as "Ai Bi" (without the quotes). You can print users in pairs and the pairs themselves in any order. Each pair must be printed exactly once.
null
In the first sample test case Vasya and Petya are friends because their messages' sending times are one second apart. Anya and Ivan are not, because their messages' sending times differ by more than one second.
[{"input": "4 1\nvasya petya 1\npetya vasya 2\nanya ivan 2\nivan anya 4", "output": "1\npetya vasya"}, {"input": "1 1000\na b 0", "output": "0"}]
1,400
["*special", "greedy", "implementation"]
30
[{"input": "4 1\r\nvasya petya 1\r\npetya vasya 2\r\nanya ivan 2\r\nivan anya 4\r\n", "output": "1\r\npetya vasya\r\n"}, {"input": "1 1000\r\na b 0\r\n", "output": "0\r\n"}, {"input": "2 1\r\na b 0\r\nb a 0\r\n", "output": "0\r\n"}, {"input": "3 1\r\na b 1\r\nb c 2\r\nc d 3\r\n", "output": "0\r\n"}, {"input": "10 2\r\n...
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, 'r') as f: lines = [line.strip() for line in f] n, d = map(int, lines[0].split()) messages = [] for line in lines[1:n+1]: parts = line.split() ...
true
159/A
159
A
Python 3
TESTS
13
92
102,400
204557679
""" https://codeforces.com/problemset/problem/159/A """ n,temps=[int(x) for x in input().split()] d=dict() for _ in range(n): a,b,t=[x for x in input().split()] if (a,b) in d: d[(a,b)].append((int(t),a,b)) elif (b,a) in d: d[(b,a)].append((int(t),a,b)) else: d[(a,b)]=[(int(t),a,b...
30
124
204,800
204561136
""" https://codeforces.com/problemset/problem/159/A """ n, temps = [int(x) for x in input().split()] d = dict() for _ in range(n): a, b, t = [x for x in input().split()] if (a, b) in d: d[(a, b)].append((int(t), a, b)) elif (b, a) in d: d[(b, a)].append((int(t), a, b)) else: d[(a...
VK Cup 2012 Qualification Round 2
CF
2,012
3
256
Friends or Not
Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ...
The first line of the input contains two integers n and d (1 ≤ n, d ≤ 1000). The next n lines contain the messages log. The i-th line contains one line of the log formatted as "Ai Bi ti" (without the quotes), which means that user Ai sent a message to user Bi at time ti (1 ≤ i ≤ n). Ai and Bi are non-empty strings at m...
In the first line print integer k — the number of pairs of friends. In the next k lines print pairs of friends as "Ai Bi" (without the quotes). You can print users in pairs and the pairs themselves in any order. Each pair must be printed exactly once.
null
In the first sample test case Vasya and Petya are friends because their messages' sending times are one second apart. Anya and Ivan are not, because their messages' sending times differ by more than one second.
[{"input": "4 1\nvasya petya 1\npetya vasya 2\nanya ivan 2\nivan anya 4", "output": "1\npetya vasya"}, {"input": "1 1000\na b 0", "output": "0"}]
1,400
["*special", "greedy", "implementation"]
30
[{"input": "4 1\r\nvasya petya 1\r\npetya vasya 2\r\nanya ivan 2\r\nivan anya 4\r\n", "output": "1\r\npetya vasya\r\n"}, {"input": "1 1000\r\na b 0\r\n", "output": "0\r\n"}, {"input": "2 1\r\na b 0\r\nb a 0\r\n", "output": "0\r\n"}, {"input": "3 1\r\na b 1\r\nb c 2\r\nc d 3\r\n", "output": "0\r\n"}, {"input": "10 2\r\n...
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, 'r') as f: lines = [line.strip() for line in f] n, d = map(int, lines[0].split()) messages = [] for line in lines[1:n+1]: parts = line.split() ...
true
667/B
667
B
Python 3
PRETESTS
2
77
4,608,000
17572186
def solve(): N = int(input()) L = list(map(int, input().split())) ma = max(L) mi = min(L) re = sum(L) - ma - mi ans = ma - re print(ans) if __name__ == '__main__': solve()
51
62
6,246,400
204523432
while True: try: n = int(input()) a = list(map(int, input().split())) a.sort() sum = 0 for i in range(n-1): sum += a[i] print(a[n-1]-sum+1) except: break
Codeforces Round 349 (Div. 2)
CF
2,016
1
256
Coat of Anticubism
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore. A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-d...
The first line contains an integer n (3 ≤ n ≤ 105) — a number of rod-blanks. The second line contains n integers li (1 ≤ li ≤ 109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with n vertices and nonzero area using the rods Cicasso already has.
Print the only integer z — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (n + 1) vertices and nonzero area from all of the rods.
null
In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}. In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}.
[{"input": "3\n1 2 1", "output": "1"}, {"input": "5\n20 4 3 2 1", "output": "11"}]
1,100
["constructive algorithms", "geometry"]
51
[{"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n20 4 3 2 1\r\n", "output": "11\r\n"}, {"input": "7\r\n77486105 317474713 89523018 332007362 7897847 949616701 54820086\r\n", "output": "70407571\r\n"}, {"input": "14\r\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707 81525 104620306 8...
false
stdio
null
true
754/C
754
C
PyPy 3
TESTS
11
140
3,686,400
136298898
import re uname = re.compile(r"[a-zA-Z0-9]+") for _ in range(int(input())): input() users = set(input().split()) messages = [input().split(":") for _ in range(int(input()))] for i, (u, m) in enumerate(messages): allowed = set() if u == "?": allowed = users.copy() ...
104
77
5,017,600
23599678
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # @Author: wjh # @Date: 2017-01-06 22:56:27 # @Last Modified by: wjh # @Last Modified time: 2017-01-06 23:40:47 def solve(): global msg, rem, m flag = True while flag: flag = False for i in range(m): if (msg[i][0] == ' '): ...
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
Python 3
TESTS
5
124
0
42685514
t=(int)(input()) for q in range(0,t): n=(int)(input()) namelist = input().split(' ') m=(int)(input()) users=[] messages=[] for i in range(0,m): user,message=input().split(':') users.append(user) messages.append(message) # print(user) # print(message) ...
104
77
5,427,200
23605091
import sys import re def mentioned_usernames(line): return {x for x in re.split(r'[^A-Za-z0-9]+', line)} t = int(input()) for ti in range(t): possible_users = [] messages = [] n = int(input()) usernames = set(input().split()) # print("usernames =", usernames, file=sys.stderr) m = int(inpu...
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
821/E
821
E
Python 3
TESTS
2
46
4,915,200
28041116
def matpwr(b, e, mod = 10**9+7): if e == 0: return identity(len(b)) if e == 1: return b return matmul(matpwr(matmul(b, b), e//2), matpwr(b, e%2)) def matmul(a, b, mod = 10**9+7): n, m = len(a), len(b[0]) ret = [[0 for i in range(m)] for j in range(n)] for i in range(n): for j in range(m...
90
265
11,366,400
231212945
from functools import lru_cache mod = 10**9+7 maxc = 16 def solve(n, k, abc): v = [0]*maxc v[0] = 1 for a,b,c in abc: b = min(b,k) d = b-a p2 = 0 while d: d,r = divmod(d,2) if r: v = vecmul(matpow2(c, p2), v) p2 += 1 ...
Codeforces Round 420 (Div. 2)
CF
2,017
2
256
Okabe and El Psy Kongroo
Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can be represented as all points (x, y) such that x and y are non-negative. Okabe starts at the origin (point (0, 0)), and needs to re...
The first line of input contains the integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1018) — the number of segments and the destination x coordinate. The next n lines contain three space-separated integers ai, bi, and ci (0 ≤ ai < bi ≤ 1018, 0 ≤ ci ≤ 15) — the left and right ends of a segment, and its y coordinate. It is guar...
Print the number of walks satisfying the conditions, modulo 1000000007 (109 + 7).
null
The graph above corresponds to sample 1. The possible walks are: - $$(0,0)\rightarrow(1,0)\rightarrow(2,0)\rightarrow(3,0)$$ - $$(0,0)\rightarrow(1,1)\rightarrow(2,0)\rightarrow(3,0)$$ - $$(0,0)\rightarrow(1,0)\rightarrow(2,1)\rightarrow(3,0)$$ - $$(0,0)\rightarrow(1,1)\rightarrow(2,1)\rightarrow(3,0)$$ The graph abo...
[{"input": "1 3\n0 3 3", "output": "4"}, {"input": "2 6\n0 3 0\n3 10 2", "output": "4"}]
2,100
["dp", "matrices"]
91
[{"input": "1 3\r\n0 3 3\r\n", "output": "4\r\n"}, {"input": "2 6\r\n0 3 0\r\n3 10 2\r\n", "output": "4\r\n"}, {"input": "2 3\r\n0 2 13\r\n2 3 11\r\n", "output": "4\r\n"}, {"input": "2 9\r\n0 8 0\r\n8 10 10\r\n", "output": "1\r\n"}, {"input": "1 1\r\n0 3 9\r\n", "output": "1\r\n"}, {"input": "3 8\r\n0 7 3\r\n7 8 5\r\n8...
false
stdio
null
true
754/C
754
C
PyPy 3
TESTS
3
93
24,064,000
24469588
from sys import stdin, stdout def divide(s): strings = [] l = 0 r = len(s) - 1 while s[l] in '?!., ' and l < len(s): l += 1 while s[r] in '?!., ' and r >= 0: r -= 1 s = s[l:r + 1] while len(s): for i in range(len(s)): if s[i...
104
78
5,017,600
23603623
def main(): n = int(input()) names = input().split() m = int(input()) msg = [input().split(':') for _ in range(m)] texts = [] for i in msg: texts.append(i[1]) i[1] = i[1].replace(',', ' ').replace('.', ' ').replace('!', ' ').replace('?', ' ').split() if i[0] == '?': ...
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
108
1,945,600
191278900
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline t = int(input()) ans = [] for _ in range(t): n = int(input()) s = ["?"] + list(input().rstrip().decode().split()) d = dict() for i in range(1, n + 1): d[s[i]] = i m = int(input()) dp = [] x = [] for ...
104
171
1,228,800
100980582
#!/usr/bin/env python3 import re, sys def debug(*msg): print(*msg, file=sys.stderr) def solve(): def parse(line): mo = re.match(r'(.*?):(.*)', line) assert(mo) name, text = mo[1], mo[2] if name == '?': speaker = -1 else: assert (name in revP) ...
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
641/B
641
B
Python 3
TESTS
6
155
716,800
19452067
def main(): n, m, q = map(int, input().split()) nm = ["0"] * (n * m) a, b, c = m + 1, n - 1, (n - 1) * m qq = [input() for _ in range(q)] for s in reversed(qq): k, *l = s.split() if k == "3": row, col, x = l nm[int(row) * m + int(col) - a] = x pass...
26
202
1,433,600
18543653
n,m,q=map(int,input().split()) l=[list(map(int,input().split())) for _ in range(q)][::-1] adj=[[0]*m for _ in range(n)] for i in range(q): t=l[i] if t[0]==3: adj[t[1]-1][t[2]-1]=t[3] elif t[0]==2: j=t[1]-1 x=adj[-1][j] for i in range(n-1,0,-1): adj[i][j...
VK Cup 2016 - Round 2
CF
2,016
2
256
Little Artem and Matrix
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it. That element can store information about the matrix of integers size n × m. There a...
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the...
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
null
null
[{"input": "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "output": "8 2\n1 8"}, {"input": "3 3 2\n1 2\n3 2 2 5", "output": "0 0 0\n0 0 5\n0 0 0"}]
1,400
["implementation"]
26
[{"input": "2 2 6\r\n2 1\r\n2 2\r\n3 1 1 1\r\n3 2 2 2\r\n3 1 2 8\r\n3 2 1 8\r\n", "output": "8 2 \r\n1 8 \r\n"}, {"input": "3 3 2\r\n1 2\r\n3 2 2 5\r\n", "output": "0 0 0 \r\n0 0 5 \r\n0 0 0 \r\n"}, {"input": "5 5 1\r\n1 5\r\n", "output": "0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n0 0 0 0 0 \r\n"}, {"inpu...
false
stdio
null
true
366/C
366
C
PyPy 3
TESTS
5
233
25,497,600
88899494
n,k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] diff = [] for x in range(n): diff.append(a[x]-b[x]*k) totals = {0:0} for x in range(n): t = a[x] d = diff[x] newGuys = [] for y in totals: if y+d in totals: to...
28
389
66,150,400
196874771
class Dict(dict): def __missing__(self, key): return float('-inf') n, k = map(int, input().split()) a = [0] + list(map(int, input().split())) b = [0] + list(map(int, input().split())) f = [Dict() for _ in range( n + 1 ) ] f[0][n*100] = 0 for i in range( 1 , n + 1 ): s = a[i] - b[i]*k for j in ran...
Codeforces Round 214 (Div. 2)
CF
2,013
1
256
Dima and Salad
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad...
The first line of the input contains two integers n, k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10). The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 100) — the fruits' calories. Fruit number i has taste ai and c...
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer — the maximum possible sum of the taste values of the chosen fruits.
null
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition $$\frac{18}{9}=2=k$$ fulfills, that's exactly what Inna wants. In the second test sample we cannot choose the fruits so as to follow Inna's p...
[{"input": "3 2\n10 8 1\n2 7 1", "output": "18"}, {"input": "5 3\n4 4 4 4 4\n2 2 2 2 2", "output": "-1"}]
1,900
["dp"]
28
[{"input": "3 2\r\n10 8 1\r\n2 7 1\r\n", "output": "18\r\n"}, {"input": "5 3\r\n4 4 4 4 4\r\n2 2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n2\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n75 65\r\n16 60\r\n", "output": "-1\r\n"}, {"input": "21 8\r\n50 39 28...
false
stdio
null
true
883/G
883
G
Python 3
TESTS
3
62
0
31723170
def bfsCalc(succ, s): bfs = [s] queue = [s] while len(queue)>0: edge = queue.pop() for i in succ[edge]: if i not in bfs: bfs.append(i) queue.append(i) return bfs def dfsCalc(succ, s): dfs = [] queue = [s] while len(queue)>0: edge = queue[0] dfs.append(edge) if len(queue)>1: queue = queue...
141
1,200
48,844,800
95314305
import sys input = sys.stdin.readline def put(): return map(int, input().split()) def dfs0(x): s = [x] vis = [0] * n ans = ['+'] * m vis[x] = 1 while s: i = s.pop() for j, k in graph[i]: if (vis[j] == 0): if (k < 0): ans[-k - 1] = '-' elif (k > 0): ans[...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Orientation of Edges
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices. Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans: 1. to orient each undirected edge in one of two possible directions to maximize n...
The first line contains three integers n, m and s (2 ≤ n ≤ 3·105, 1 ≤ m ≤ 3·105, 1 ≤ s ≤ n) — number of vertices and edges in the graph, and the vertex Vasya has picked. The following m lines contain information about the graph edges. Each line contains three integers ti, ui and vi (1 ≤ ti ≤ 2, 1 ≤ ui, vi ≤ n, ui ≠ vi...
The first two lines should describe the plan which maximizes the number of reachable vertices. The lines three and four should describe the plan which minimizes the number of reachable vertices. A description of each plan should start with a line containing the number of reachable vertices. The second line of a plan s...
null
null
[{"input": "2 2 1\n1 1 2\n2 2 1", "output": "2\n-\n2\n+"}, {"input": "6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3", "output": "6\n++-\n2\n+-+"}]
1,900
["dfs and similar", "graphs"]
141
[{"input": "2 2 1\r\n1 1 2\r\n2 2 1\r\n", "output": "2\r\n-\r\n2\r\n+\r\n"}, {"input": "6 6 3\r\n2 2 6\r\n1 4 5\r\n2 3 4\r\n1 4 1\r\n1 3 1\r\n2 2 3\r\n", "output": "6\r\n++-\r\n2\r\n+-+\r\n"}, {"input": "5 5 5\r\n2 5 3\r\n1 2 3\r\n1 4 5\r\n2 5 2\r\n1 2 1\r\n", "output": "4\r\n++\r\n1\r\n--\r\n"}, {"input": "13 18 9\r\n...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n, m, s = map(int, f.readline().split()) all_edges = [] for _ in range(m): ti, u, v = m...
true
2/A
2
A
Python 3
TESTS
13
92
307,200
219548416
from collections import defaultdict n=int(input()) res='akxyn' data=defaultdict(int) for _ in range(n): name,score=input().split() score=int(score) data[name]+=score if data[name]>data[res]: res=name print(res)
20
62
102,400
222065059
n=int(input()) a=[0]*3 b=[0]*3 c=[0]*3 k={} d=[] for i in range(n): a,b=map(str,input().split()) k[a]=k.get(a,0)+int(b);d.append([a,k[a]]) m=max(k.values()) for i,j in d: if k[i]==m and int(j)>=m: print(i); break
Codeforces Beta Round 2
ICPC
2,010
1
64
Winner
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer numbe...
Print the name of the winner.
null
null
[{"input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew"}, {"input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew"}]
1,500
["hashing", "implementation"]
20
[{"input": "3\r\nmike 3\r\nandrew 5\r\nmike 2\r\n", "output": "andrew\r\n"}, {"input": "3\r\nandrew 3\r\nandrew 2\r\nmike 5\r\n", "output": "andrew\r\n"}, {"input": "5\r\nkaxqybeultn -352\r\nmgochgrmeyieyskhuourfg -910\r\nkaxqybeultn 691\r\nmgochgrmeyieyskhuourfg -76\r\nkaxqybeultn -303\r\n", "output": "kaxqybeultn\r\n...
false
stdio
null
true
2/A
2
A
Python 3
TESTS
13
92
102,400
175370038
from collections import defaultdict n = int(input()) max_score = 0 players_max_score_and_round =defaultdict(lambda: [0, 0]) players_scores = defaultdict(int) for round in range(1, n+1): name, score = input().split() score = int(score) players_scores[name] += score if players_scores[name] > players_ma...
20
62
204,800
208198879
import sys # sys.stdin = open("3.in", "r") n = int(input()) my_dict = dict() rounds = [] for i in range(n): name, point = input().split() point = int(point) rounds.append((name, point)) if name in my_dict: my_dict[name] += point else: my_dict[name] = point max_score = -sys.maxsize max_na...
Codeforces Beta Round 2
ICPC
2,010
1
64
Winner
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer numbe...
Print the name of the winner.
null
null
[{"input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew"}, {"input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew"}]
1,500
["hashing", "implementation"]
20
[{"input": "3\r\nmike 3\r\nandrew 5\r\nmike 2\r\n", "output": "andrew\r\n"}, {"input": "3\r\nandrew 3\r\nandrew 2\r\nmike 5\r\n", "output": "andrew\r\n"}, {"input": "5\r\nkaxqybeultn -352\r\nmgochgrmeyieyskhuourfg -910\r\nkaxqybeultn 691\r\nmgochgrmeyieyskhuourfg -76\r\nkaxqybeultn -303\r\n", "output": "kaxqybeultn\r\n...
false
stdio
null
true
873/C
873
C
PyPy 3-64
TESTS
2
46
0
206646205
n, m, k = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(n)] pr = [[0 for _ in range(m)] for _ in range(n)] for j in range(m): for i in range(n): if i == 0: pr[i][j] = a[i][j] else: pr[i][j] = pr[i - 1][j] + a[i][j] result = [0 for _ in range(m)...
20
77
0
32568148
n, m, k = map(int, input().split()); a = []; b = []; score = []; ct = 0 for i in range(n): a.append([int(x) for x in input().split()]) for i in range(m): b.append([]) for i in range(m): for j in range(n): b[i].append(a[j][i]) for i in range(m): maxsums = [] for j in range(n): ...
Educational Codeforces Round 30
ICPC
2,017
1
256
Strange Game On Matrix
Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score ...
The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1.
Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score.
null
In the first example Ivan will replace the element a1, 2.
[{"input": "4 3 2\n0 1 0\n1 0 1\n0 1 0\n1 1 1", "output": "4 1"}, {"input": "3 2 1\n1 0\n0 1\n0 0", "output": "2 0"}]
1,600
["greedy", "two pointers"]
20
[{"input": "4 3 2\r\n0 1 0\r\n1 0 1\r\n0 1 0\r\n1 1 1\r\n", "output": "4 1\r\n"}, {"input": "3 2 1\r\n1 0\r\n0 1\r\n0 0\r\n", "output": "2 0\r\n"}, {"input": "3 4 2\r\n0 1 1 1\r\n1 0 1 1\r\n1 0 0 1\r\n", "output": "7 0\r\n"}, {"input": "3 57 3\r\n1 0 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0...
false
stdio
null
true
484/D
484
D
Python 3
TESTS
6
93
6,656,000
86714699
l = input() a = list(map(int, input().split())) a.sort() x = 0 for i in range(len(a)//2): x+= (a[len(a)-1-i]- a[i]) print(x)
71
1,310
79,462,400
147542209
n = int(input()) if n == 1: print(0) else: a = [0]*(n+1) i = 1 for v in map(int, input().split()): a[i] = v i += 1 dp = [0]*(n+1) dp[2] = abs(a[1]-a[2]) for i in range(3, n+1): # 单调 if (a[i-2] < a[i-1] and a[i-1] < a[i]) or (a[i-2] > a[i-1] and a[i-1] > a[i]):...
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
1003/D
1003
D
PyPy 3
TESTS
1
904
13,209,600
118283804
from collections import defaultdict import sys input = sys.stdin.readline n, q = map(int, input().split()) a = list(map(int, input().split())) cnt = defaultdict(lambda : 0) for i in a: cnt[i] += 1 pow2 = [1] for _ in range(35): pow2.append(2 * pow2[-1]) for _ in range(q): x = [0] * 35 b = int(input()) ...
31
280
25,292,800
190200626
import sys input = lambda: sys.stdin.readline().rstrip() # ----------------------- # n, q = map(int, input().split()) A = list(map(int, input().split())) coins = [0] * 33 for a in A: coins[a.bit_length()-1] += 1 for _ in range(q): b = int(input()) ans = 0 for i in range(32, -1, -1): if coins[i] and b >...
Codeforces Round 494 (Div. 3)
ICPC
2,018
2
256
Coins and Queries
Polycarp has $$$n$$$ coins, the value of the $$$i$$$-th coin is $$$a_i$$$. It is guaranteed that all the values are integer powers of $$$2$$$ (i.e. $$$a_i = 2^d$$$ for some non-negative integer number $$$d$$$). Polycarp wants to know answers on $$$q$$$ queries. The $$$j$$$-th query is described as integer number $$$b_...
The first line of the input contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$) — the number of coins and the number of queries. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ — values of coins ($$$1 \le a_i \le 2 \cdot 10^9$$$). It is guaranteed that all $$...
Print $$$q$$$ integers $$$ans_j$$$. The $$$j$$$-th integer must be equal to the answer on the $$$j$$$-th query. If Polycarp can't obtain the value $$$b_j$$$ the answer to the $$$j$$$-th query is -1.
null
null
[{"input": "5 4\n2 4 8 2 4\n8\n5\n14\n10", "output": "1\n-1\n3\n2"}]
1,600
["greedy"]
31
[{"input": "5 4\r\n2 4 8 2 4\r\n8\r\n5\r\n14\r\n10\r\n", "output": "1\r\n-1\r\n3\r\n2\r\n"}, {"input": "3 3\r\n1 1 1\r\n1\r\n2\r\n3\r\n", "output": "1\r\n2\r\n3\r\n"}, {"input": "4 1\r\n2 4 16 32\r\n14\r\n", "output": "-1\r\n"}, {"input": "1 10\r\n8\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n16\r\n", "output": "-1...
false
stdio
null
true
43/C
43
C
PyPy 3-64
TESTS
4
154
0
202285328
def summ (p): x=0 while p!=0 : x=x+p%10 p=p//10 return x; n=int (input()) l = list(map(int, input().split())) s=0 trv=0 for i in range(n): for j in range(i,n): if (summ(l[i])+summ(l[j]))%3==0: s+=1 trv=1 break if(trv==1): break ...
21
62
614,400
148170167
input() myList = list(map(int, input().split())) rem0, rem1, rem2 = 0, 0, 0 for it in myList: if it % 3 == 0: rem0 += 1 elif it % 3 == 1: rem1 += 1 else: rem2 += 1 print(rem0//2 + min(rem2,rem1))
Codeforces Beta Round 42 (Div. 2)
CF
2,010
2
256
Lucky Tickets
Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid a...
The first line contains integer n (1 ≤ n ≤ 104) — the number of pieces. The second line contains n space-separated numbers ai (1 ≤ ai ≤ 108) — the numbers on the pieces. Vasya can only glue the pieces in pairs. Even if the number of a piece is already lucky, Vasya should glue the piece with some other one for it to cou...
Print the single number — the maximum number of lucky tickets that will be able to be restored. Don't forget that every lucky ticket is made of exactly two pieces glued together.
null
null
[{"input": "3\n123 123 99", "output": "1"}, {"input": "6\n1 1 1 23 10 3", "output": "1"}]
1,300
["greedy"]
21
[{"input": "3\r\n123 123 99\r\n", "output": "1\r\n"}, {"input": "6\r\n1 1 1 23 10 3\r\n", "output": "1\r\n"}, {"input": "3\r\n43440907 58238452 82582355\r\n", "output": "1\r\n"}, {"input": "4\r\n31450303 81222872 67526764 17516401\r\n", "output": "1\r\n"}, {"input": "5\r\n83280 20492640 21552119 7655071 47966344\r\n", ...
false
stdio
null
true
641/D
641
D
Python 3
PRETESTS
2
46
5,120,000
17492579
def quad(a, b, c): disc = (b**2-4*a*c) if disc<0: disc=0 disc = (disc)**0.5 return ((-b+disc)/2/a, (-b-disc)/2/a) x = int(input()) y = list(map(float, input().split(' '))) z = list(map(float, input().split(' '))) py = [0, y[0]] for i in range(1, x): py.append(py[-1]+y[i]) z.reverse() p...
20
530
47,616,000
17497190
def tle(): k=0 while (k>=0): k+=1 def quad(a, b, c): disc = (b**2-4*a*c) if disc<0: disc=0 disc = (disc)**0.5 return ((-b+disc)/2/a, (-b-disc)/2/a) x = int(input()) y = list(map(float, input().strip().split(' '))) z = list(map(float, input().strip().split(' '))) p...
VK Cup 2016 - Round 2
CF
2,016
2
256
Little Artem and Random Variable
Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them. Consider two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and dif...
First line contains the integer n (1 ≤ n ≤ 100 000) — the number of different values for both dices. Second line contains an array consisting of n real values with up to 8 digits after the decimal point  — probability distribution for max(a, b), the i-th of these values equals to the probability that max(a, b) = i. It...
Output two descriptions of the probability distribution for a on the first line and for b on the second line. The answer will be considered correct if each value of max(a, b) and min(a, b) probability distribution values does not differ by more than 10 - 6 from ones given in input. Also, probabilities should be non-ne...
null
null
[{"input": "2\n0.25 0.75\n0.75 0.25", "output": "0.5 0.5\n0.5 0.5"}, {"input": "3\n0.125 0.25 0.625\n0.625 0.25 0.125", "output": "0.25 0.25 0.5\n0.5 0.25 0.25"}]
2,400
["dp", "implementation", "math", "probabilities"]
20
[{"input": "2\r\n0.25 0.75\r\n0.75 0.25\r\n", "output": "0.5 0.5 \r\n0.5 0.5 \r\n"}, {"input": "3\r\n0.125 0.25 0.625\r\n0.625 0.25 0.125\r\n", "output": "0.25 0.25 0.5 \r\n0.5 0.25 0.25 \r\n"}, {"input": "10\r\n0.01 0.01 0.01 0.01 0.01 0.1 0.2 0.2 0.4 0.05\r\n1.0 0 0 0 0 0 0 0 0 0\r\n", "output": "0.010000000000000009...
false
stdio
import sys def read_floats(line): return list(map(float, line.strip().split())) def main(): input_path, output_path, submission_path = sys.argv[1:4] with open(input_path) as f: n = int(f.readline()) max_dist = read_floats(f.readline()) min_dist = read_floats(f.readline()) ...
true
31/D
31
D
PyPy 3
TESTS
8
154
2,560,000
141688873
from bisect import bisect_right from collections import defaultdict import os import sys from io import BytesIO, IOBase from collections import defaultdict BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self...
33
92
0
189949532
from bisect import bisect as bt w,h,n=map(int,input().split()) N,M=max(w,h),10 x=[[0,h]]+[[] for _ in range(N-1)] y=[[0,w]]+[[] for _ in range(N-1)] xy=[[0]*(N+1) for _ in range(N+1)] g=[0]*M+[[]] xy[0][0]=1 xs,ys={0},{0} def t(k,p): for i,j in zip(k,p): q=bt(i,j) if q==0 or i[q-1]!=j: i...
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
730/G
730
G
PyPy 3
TESTS
5
124
0
21712850
#!/usr/bin/env python3 def main(): try: while True: n = int(input()) req = [tuple(map(int, input().split())) for i in range(n)] used = [(req[0][0], req[0][0] + req[0][1])] print(used[0][0], used[0][1] - 1) for start, dur in req[1:]: ...
28
77
2,867,200
211349045
import sys input = lambda: sys.stdin.readline().rstrip() N = int(input()) A = [0,10**18] for _ in range(N): s,d = map(int, input().split()) find = False for i in range(1,len(A),2): if A[i]>s+d-1 and A[i-1]<s: print(s,s+d-1) A.append(s) A.append(s+d-1) ...
2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,016
2
512
Car Repair Shop
Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time. Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order...
The first line contains integer n (1 ≤ n ≤ 200) — the number of requests from clients. The following n lines contain requests, one request per line. The i-th request is given as the pair of integers si, di (1 ≤ si ≤ 109, 1 ≤ di ≤ 5·106), where si is the preferred time to start repairing the i-th car, di is the number ...
Print n lines. The i-th line should contain two integers — the start day to repair the i-th car and the finish day to repair the i-th car.
null
null
[{"input": "3\n9 2\n7 3\n2 4", "output": "9 10\n1 3\n4 7"}, {"input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000", "output": "1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000"}]
1,600
["implementation"]
28
[{"input": "3\r\n9 2\r\n7 3\r\n2 4\r\n", "output": "9 10\r\n1 3\r\n4 7\r\n"}, {"input": "4\r\n1000000000 1000000\r\n1000000000 1000000\r\n100000000 1000000\r\n1000000000 1000000\r\n", "output": "1000000000 1000999999\r\n1 1000000\r\n100000000 100999999\r\n1000001 2000000\r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 1\...
false
stdio
null
true
583/A
583
A
Python 3
PRETESTS
6
46
0
13369364
n=int(input('')) d1={} d2={} arr=[] for i in range(0,n*n): s=input('') a=s.split(" ") x=int(a[0]) y=int(a[1]) try: d1[x]=d1[x]+1 except: try: d2[y]=d2[y]+1 except: arr.append(str(i+1)) d1[x]=1 d2[y]=1 arr.sort() print(' '.j...
39
46
0
151474506
n=int(input()) r=[0]*(n+1) c=[0]*(n+1) for i in range(n*n): a,b=map(int,input().split()) if r[a]==0 and c[b]==0: print(i+1) r[a]=c[b]=1
Codeforces Round 323 (Div. 2)
CF
2,015
1
256
Asphalting Roads
City X consists of n vertical and n horizontal infinite roads, forming n × n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was made to asphal...
The first line contains integer n (1 ≤ n ≤ 50) — the number of vertical and horizontal roads in the city. Next n2 lines contain the order of intersections in the schedule. The i-th of them contains two numbers hi, vi (1 ≤ hi, vi ≤ n), separated by a space, and meaning that the intersection that goes i-th in the timeta...
In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1.
null
In the sample the brigade acts like that: 1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 2. On the second day the brigade of the workers comes to the int...
[{"input": "2\n1 1\n1 2\n2 1\n2 2", "output": "1 4"}, {"input": "1\n1 1", "output": "1"}]
1,000
["implementation"]
39
[{"input": "2\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "1 4 \r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 \r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n1 2\r\n2 1\r\n", "output": "1 2 \r\n"}, {"input": "2\r\n1 2\r\n2 2\r\n2 1\r\n1 1\r\n", "output": "1 3 \r\n"}, {"input": "3\r\n2 2\r\n1 2\r\n3 2\r\n3 3\r\n1 1\r\n2 3\r\n1 3\...
false
stdio
null
true
245/A
245
A
Python 3
TESTS
9
92
0
140483027
if __name__=="__main__": n = int(input()) count_dict = {} for i in range(n): t,x,y = [int(x) for x in input().split()] val = list(count_dict.get(t,[0,0])) val[0] += x val[1] += y count_dict[t] = val for key,val in count_dict.items(): ...
13
62
0
139623098
tc=int(input()) count1=0 count2=0 count3=0 count4=0 for i in range(tc): t,x,y=list(map(int,input().split())) if t==1: count1+=x count2+=10 else: count3+=x count4+=10 if count1>=(count2/2): print('LIVE') else: print('DEAD') if count3>=(count4/2): print('LIVE') else...
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
ICPC
2,012
2
256
System Administrator
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program re...
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti =...
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
null
Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this ...
[{"input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE"}, {"input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD"}]
800
["implementation"]
23
[{"input": "2\r\n1 5 5\r\n2 6 4\r\n", "output": "LIVE\r\nLIVE\r\n"}, {"input": "3\r\n1 0 10\r\n2 0 10\r\n1 10 0\r\n", "output": "LIVE\r\nDEAD\r\n"}, {"input": "10\r\n1 3 7\r\n2 4 6\r\n1 2 8\r\n2 5 5\r\n2 10 0\r\n2 10 0\r\n1 8 2\r\n2 2 8\r\n2 10 0\r\n1 1 9\r\n", "output": "DEAD\r\nLIVE\r\n"}, {"input": "11\r\n1 8 2\r\n1...
false
stdio
null
true
358/D
358
D
Python 3
TESTS
4
62
307,200
4892411
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) A = {0 : a[0]} B = {0 : b[0]} for i in range(1, n): A[i] = max(A[i-1] + b[i], B[i-1] + a[i]) # max(fed left, fed right) B[i] = max(A[i-1] + c[i], B[i-1] + b[i]) # max(fed left and right, fed ...
29
62
512,000
5035569
n = int( input() ) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] c = [int(x) for x in input().split()] DD = a[0] DP = b[0] PD = a[0] PP = b[0] for i in range(1,n): tDD = max(DP+a[i], PP+a[i]) tPD = max(PD+b[i], DD+b[i]) tDP = max(DP+b[i], PP+b[i]) tPP = max(PD+c[i], DD+c[i]) DD = ...
Codeforces Round 208 (Div. 2)
CF
2,013
2
256
Dima and Hares
Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more. Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with ca...
The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an. The second line contains b1, b2, ..., bn. The third line contains c1, c2, ..., cn. The following limits are fulfilled: 0 ≤ ai, bi, ci ≤ 1...
In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.
null
null
[{"input": "4\n1 2 3 4\n4 3 2 1\n0 1 1 0", "output": "13"}, {"input": "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3", "output": "44"}, {"input": "3\n1 1 1\n1 2 1\n1 1 1", "output": "4"}]
1,800
["dp", "greedy"]
29
[{"input": "4\r\n1 2 3 4\r\n4 3 2 1\r\n0 1 1 0\r\n", "output": "13\r\n"}, {"input": "7\r\n8 5 7 6 1 8 9\r\n2 7 9 5 4 3 1\r\n2 3 3 4 1 1 3\r\n", "output": "44\r\n"}, {"input": "3\r\n1 1 1\r\n1 2 1\r\n1 1 1\r\n", "output": "4\r\n"}, {"input": "7\r\n1 3 8 9 3 4 4\r\n6 0 6 6 1 8 4\r\n9 6 3 7 8 8 2\r\n", "output": "42\r\n"}...
false
stdio
null
true
1003/D
1003
D
PyPy 3-64
TESTS
3
451
23,552,000
193238672
import sys input = sys.stdin.readline from math import log2 n, q = map(int, input().split()) d = [0]*31 w = list(map(int, input().split())) for i in w: d[int(log2(i))] += 1 x = [0]*31 for i in range(31): if d[i] > 0: x[i] = 1 else: a, b = 0, 2 for j in range(i-1, -1, -1): ...
31
358
25,497,600
220844200
# https://codeforces.com/contest/1003 import sys input = lambda: sys.stdin.readline().rstrip() # faster! n, q = map(int, input().split()) a = list(map(int, input().split())) N_BITS = (2 * 10 ** 9).bit_length() + 1 coins = [0] * N_BITS for x in a: coins[x.bit_length() - 1] += 1 for _ in range(q): ans = 0 ...
Codeforces Round 494 (Div. 3)
ICPC
2,018
2
256
Coins and Queries
Polycarp has $$$n$$$ coins, the value of the $$$i$$$-th coin is $$$a_i$$$. It is guaranteed that all the values are integer powers of $$$2$$$ (i.e. $$$a_i = 2^d$$$ for some non-negative integer number $$$d$$$). Polycarp wants to know answers on $$$q$$$ queries. The $$$j$$$-th query is described as integer number $$$b_...
The first line of the input contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$) — the number of coins and the number of queries. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ — values of coins ($$$1 \le a_i \le 2 \cdot 10^9$$$). It is guaranteed that all $$...
Print $$$q$$$ integers $$$ans_j$$$. The $$$j$$$-th integer must be equal to the answer on the $$$j$$$-th query. If Polycarp can't obtain the value $$$b_j$$$ the answer to the $$$j$$$-th query is -1.
null
null
[{"input": "5 4\n2 4 8 2 4\n8\n5\n14\n10", "output": "1\n-1\n3\n2"}]
1,600
["greedy"]
31
[{"input": "5 4\r\n2 4 8 2 4\r\n8\r\n5\r\n14\r\n10\r\n", "output": "1\r\n-1\r\n3\r\n2\r\n"}, {"input": "3 3\r\n1 1 1\r\n1\r\n2\r\n3\r\n", "output": "1\r\n2\r\n3\r\n"}, {"input": "4 1\r\n2 4 16 32\r\n14\r\n", "output": "-1\r\n"}, {"input": "1 10\r\n8\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n16\r\n", "output": "-1...
false
stdio
null
true
1003/D
1003
D
PyPy 3-64
TESTS
3
420
23,347,200
207516276
import sys input = lambda: sys.stdin.readline().rstrip() from collections import Counter,defaultdict N,Q = map(int, input().split()) A = list(map(int, input().split())) cnt = [0]*32 for a in A: for i in range(32): if a&(1<<i): cnt[i]+=1 #print(cnt) for _ in range(Q): b = int(input()) a...
31
358
26,214,400
193240131
import sys input = sys.stdin.readline from math import log2 n, q = map(int, input().split()) d = [0]*31 w = list(map(int, input().split())) for i in w: d[int(log2(i))] += 1 x = list(2**i for i in range(31)) for _ in range(q): a = int(input()) c = 0 for j in range(30, -1, -1): b = min(d[j], a//...
Codeforces Round 494 (Div. 3)
ICPC
2,018
2
256
Coins and Queries
Polycarp has $$$n$$$ coins, the value of the $$$i$$$-th coin is $$$a_i$$$. It is guaranteed that all the values are integer powers of $$$2$$$ (i.e. $$$a_i = 2^d$$$ for some non-negative integer number $$$d$$$). Polycarp wants to know answers on $$$q$$$ queries. The $$$j$$$-th query is described as integer number $$$b_...
The first line of the input contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$) — the number of coins and the number of queries. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ — values of coins ($$$1 \le a_i \le 2 \cdot 10^9$$$). It is guaranteed that all $$...
Print $$$q$$$ integers $$$ans_j$$$. The $$$j$$$-th integer must be equal to the answer on the $$$j$$$-th query. If Polycarp can't obtain the value $$$b_j$$$ the answer to the $$$j$$$-th query is -1.
null
null
[{"input": "5 4\n2 4 8 2 4\n8\n5\n14\n10", "output": "1\n-1\n3\n2"}]
1,600
["greedy"]
31
[{"input": "5 4\r\n2 4 8 2 4\r\n8\r\n5\r\n14\r\n10\r\n", "output": "1\r\n-1\r\n3\r\n2\r\n"}, {"input": "3 3\r\n1 1 1\r\n1\r\n2\r\n3\r\n", "output": "1\r\n2\r\n3\r\n"}, {"input": "4 1\r\n2 4 16 32\r\n14\r\n", "output": "-1\r\n"}, {"input": "1 10\r\n8\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n16\r\n", "output": "-1...
false
stdio
null
true
364/D
364
D
PyPy 3
TESTS
4
2,776
124,108,800
71192608
from random import randrange from sys import stdin def read_integers(): return list(map(int, stdin.readline().strip().split())) def decompose(num, visited): if num in visited: return [] factors = [] i = 2 while i * i <= num: quo, rem = divmod(num, i) if i not in visited ...
115
3,900
133,734,400
179459001
import math from random import randint from bisect import bisect_left test = False if test: n = randint(100000,100000) a = [randint(1,100000000) for _ in range(n)] #print('n =', n) #print('a =', a) else: n = int(input()) a=[*map(int,input().split())] dr = 1 for x in range(9): ...
Codeforces Round 213 (Div. 1)
CF
2,013
4
256
Ghd
John Doe offered his sister Jane Doe find the gcd of some set of numbers a. Gcd is a positive integer g, such that all number from the set are evenly divisible by g and there isn't such g' (g' > g), that all numbers of the set are evenly divisible by g'. Unfortunately Jane couldn't cope with the task and John offered...
The first line contains an integer n (1 ≤ n ≤ 106) showing how many numbers are in set a. The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1012). Please note, that given set can contain equal numbers. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is pref...
Print a single integer g — the Ghd of set a.
null
null
[{"input": "6\n6 2 3 4 5 6", "output": "3"}, {"input": "5\n5 5 6 10 15", "output": "5"}]
2,900
["brute force", "math", "probabilities"]
115
[{"input": "6\r\n6 2 3 4 5 6\r\n", "output": "3\r\n"}, {"input": "5\r\n5 5 6 10 15\r\n", "output": "5\r\n"}, {"input": "100\r\n32 40 7 3 7560 21 7560 7560 10 12 3 7560 7560 7560 7560 5 7560 7560 6 7560 7560 7560 35 7560 18 7560 7560 7560 7560 7560 48 2 7 25 7560 2 2 49 7560 7560 15 16 7560 7560 2 7560 27 7560 7560 7560...
false
stdio
null
true
363/D
363
D
PyPy 3-64
TESTS
2
108
5,836,800
182267435
import sys import threading input=sys.stdin.readline from collections import Counter,defaultdict,deque from heapq import heappush,heappop,heapify #threading.stack_size(10**8) #sys.setrecursionlimit(10**6) def ri():return int(input()) def rs():return input() def rl():return list(map(int,input().split())) def rls():retu...
34
124
17,715,200
188178762
n, m, a = map(int, input().split()) B = [int(x) for x in input().split()] P = [int(x) for x in input().split()] B.sort() P.sort() def f(a): need = 0 for i in range(a): need += max(0, P[i] - B[n - a + i]) return need l = 0 r = min(n + 1, m + 1) while r - l > 1: mid = (l + r) // 2 if f(mid) ...
Codeforces Round 211 (Div. 2)
CF
2,013
1
256
Renting Bikes
A group of n schoolboys decided to ride bikes. As nobody of them has a bike, the boys need to rent them. The renting site offered them m bikes. The renting price is different for different bikes, renting the j-th bike costs pj rubles. In total, the boys' shared budget is a rubles. Besides, each of them has his own pe...
The first line of the input contains three integers n, m and a (1 ≤ n, m ≤ 105; 0 ≤ a ≤ 109). The second line contains the sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104), where bi is the amount of the i-th boy's personal money. The third line contains the sequence of integers p1, p2, ..., pm (1 ≤ pj ≤ 109), where ...
Print two integers r and s, where r is the maximum number of schoolboys that can rent a bike and s is the minimum total personal money needed to rent r bikes. If the schoolchildren cannot rent any bikes, then r = s = 0.
null
In the first sample both schoolchildren can rent a bike. For instance, they can split the shared budget in half (5 rubles each). In this case one of them will have to pay 1 ruble from the personal money and the other one will have to pay 2 rubles from the personal money. In total, they spend 3 rubles of their personal ...
[{"input": "2 2 10\n5 5\n7 6", "output": "2 3"}, {"input": "4 5 2\n8 1 1 2\n6 3 7 5 2", "output": "3 8"}]
1,800
["binary search", "greedy"]
34
[{"input": "2 2 10\r\n5 5\r\n7 6\r\n", "output": "2 3\r\n"}, {"input": "4 5 2\r\n8 1 1 2\r\n6 3 7 5 2\r\n", "output": "3 8\r\n"}, {"input": "1 1 2\r\n1\r\n2\r\n", "output": "1 0\r\n"}, {"input": "4 1 1\r\n3 2 3 2\r\n3\r\n", "output": "1 2\r\n"}, {"input": "1 4 1\r\n3\r\n2 4 5 5\r\n", "output": "1 1\r\n"}, {"input": "3 ...
false
stdio
null
true
363/D
363
D
PyPy 3-64
TESTS
0
30
0
199084354
n,m,budget = map(int, input().split()) money = sorted(list(map(int, input().split()))) costs = sorted(list(map(int, input().split()))) l = 0 r = min(n,m) mid = (l+r)//2 ans,cost = 0,0 def check(mid): global money, costs, budget cur_spending = 0 for i in range(mid): cur_spending += max(0,costs[i]-mon...
34
140
20,684,800
221831984
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(K): ans = 0 ...
Codeforces Round 211 (Div. 2)
CF
2,013
1
256
Renting Bikes
A group of n schoolboys decided to ride bikes. As nobody of them has a bike, the boys need to rent them. The renting site offered them m bikes. The renting price is different for different bikes, renting the j-th bike costs pj rubles. In total, the boys' shared budget is a rubles. Besides, each of them has his own pe...
The first line of the input contains three integers n, m and a (1 ≤ n, m ≤ 105; 0 ≤ a ≤ 109). The second line contains the sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104), where bi is the amount of the i-th boy's personal money. The third line contains the sequence of integers p1, p2, ..., pm (1 ≤ pj ≤ 109), where ...
Print two integers r and s, where r is the maximum number of schoolboys that can rent a bike and s is the minimum total personal money needed to rent r bikes. If the schoolchildren cannot rent any bikes, then r = s = 0.
null
In the first sample both schoolchildren can rent a bike. For instance, they can split the shared budget in half (5 rubles each). In this case one of them will have to pay 1 ruble from the personal money and the other one will have to pay 2 rubles from the personal money. In total, they spend 3 rubles of their personal ...
[{"input": "2 2 10\n5 5\n7 6", "output": "2 3"}, {"input": "4 5 2\n8 1 1 2\n6 3 7 5 2", "output": "3 8"}]
1,800
["binary search", "greedy"]
34
[{"input": "2 2 10\r\n5 5\r\n7 6\r\n", "output": "2 3\r\n"}, {"input": "4 5 2\r\n8 1 1 2\r\n6 3 7 5 2\r\n", "output": "3 8\r\n"}, {"input": "1 1 2\r\n1\r\n2\r\n", "output": "1 0\r\n"}, {"input": "4 1 1\r\n3 2 3 2\r\n3\r\n", "output": "1 2\r\n"}, {"input": "1 4 1\r\n3\r\n2 4 5 5\r\n", "output": "1 1\r\n"}, {"input": "3 ...
false
stdio
null
true
362/A
362
A
Python 3
PRETESTS
6
46
307,200
5106533
def main(): n = int(input()) out = "" for t in range(n): knights = [0 for i in range(8)] valid = [False for i in range(8)] for i in range(8): line = input() #print() for j in range(8): #print(get(i, j), end="") if line[j] == '.': valid[get(i, j)] = True ...
45
62
307,200
5102996
N = int(input()) for i in range(N): if i > 0: input() Pos = [] for i in range(8): S = input().strip() for j in range(8): if S[j] == "K": Pos.append((i, j)) Dx, Dy = abs(Pos[0][0] - Pos[1][0]), abs(Pos[0][1] - Pos[1][1]) if (Dx == 0 or Dx == 4) and ...
Codeforces Round 212 (Div. 2)
CF
2,013
1
256
Two Semiknights Meet
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the le...
The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed t...
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
null
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from squ...
[{"input": "2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#", "output": "YES\nNO"}]
1,500
["greedy", "math"]
45
[{"input": "2\r\n........\r\n........\r\n......#.\r\nK..##..#\r\n.......#\r\n...##..#\r\n......#.\r\nK.......\r\n\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...##...\r\n........\r\n....K#K#\r\n", "output": "YES\r\nNO\r\n"}, {"input": "3\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...
false
stdio
null
true
362/A
362
A
Python 3
TESTS
6
46
0
5237853
t = ['12341234', '56785678', '34123412', '78567856', '12341234', '56785678', '34123412', '78567856'] def f(): global t y, x = False, False for i in range(8): p = input() if y: continue for j in range(8): if p[j] == 'K': if x: ans = 'YNEOS'[x != t[i][j] :: ...
45
62
307,200
5104091
MOVS = [(2,-2),(-2,2),(-2,-2),(2,2)] def check(a): return 0<=a<8 set1 = set() set2 = set() dic1 = dict() dic2 = dict() def cango1(matrix,pos,lap): for dx,dy in MOVS: nx,ny = dx+pos[0],dy+pos[1] if not check (nx) or not check(ny): continue if (nx,ny) in set1: conti...
Codeforces Round 212 (Div. 2)
CF
2,013
1
256
Two Semiknights Meet
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the le...
The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed t...
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
null
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from squ...
[{"input": "2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#", "output": "YES\nNO"}]
1,500
["greedy", "math"]
45
[{"input": "2\r\n........\r\n........\r\n......#.\r\nK..##..#\r\n.......#\r\n...##..#\r\n......#.\r\nK.......\r\n\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...##...\r\n........\r\n....K#K#\r\n", "output": "YES\r\nNO\r\n"}, {"input": "3\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...
false
stdio
null
true
362/A
362
A
Python 3
PRETESTS
4
62
307,200
5098801
N = int(input()) for i in range(N): if i > 0: input() Pos = [] for i in range(8): S = input().strip() for j in range(8): if S[j] == "K": Pos.append((i, j)) A, B = Pos if A[0] % 4 + A[1] % 4 == B[0] % 4 + B[1] % 4: print("YES") else: ...
45
62
307,200
5107862
import collections n = list(map(int, input().split()))[0] di = ((2, 2), (-2, 2), (-2, -2), (2, -2)) def bfs(graph, x,y,tx, ty): vis = set() queue = collections.deque() queue.append((x,y)) vis.add((x,y)) dis = {} dis[(x,y)] = 0 while queue: elem = queue.popleft() #print (...
Codeforces Round 212 (Div. 2)
CF
2,013
1
256
Two Semiknights Meet
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the le...
The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed t...
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
null
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from squ...
[{"input": "2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#", "output": "YES\nNO"}]
1,500
["greedy", "math"]
45
[{"input": "2\r\n........\r\n........\r\n......#.\r\nK..##..#\r\n.......#\r\n...##..#\r\n......#.\r\nK.......\r\n\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...##...\r\n........\r\n....K#K#\r\n", "output": "YES\r\nNO\r\n"}, {"input": "3\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...
false
stdio
null
true
362/A
362
A
Python 3
TESTS
4
46
204,800
5132539
def solve(m, x,y , w,z): for i in range(8): for j in range(8): if m[i][j]: a, pa = movePossible(x,y , i,j) b, pb = movePossible(w,z , i,j) if a and b and pa==pb: return True return False def movePossible(x,y , w,z): a = z-w b = y-z pos=False ka=a//2 kb=b//2 if a%2==0 and b%2==0 and (ka+k...
45
62
307,200
5108178
import sys import collections class GetOutOfLoop(Exception): pass if __name__ == "__main__": n_cases = int(sys.stdin.readline()) for case in range(n_cases): board = [list(sys.stdin.readline().rstrip()) for i in range(8)] knight_init_loc = [None, None] knight = 0 for curr...
Codeforces Round 212 (Div. 2)
CF
2,013
1
256
Two Semiknights Meet
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the le...
The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed t...
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
null
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from squ...
[{"input": "2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#", "output": "YES\nNO"}]
1,500
["greedy", "math"]
45
[{"input": "2\r\n........\r\n........\r\n......#.\r\nK..##..#\r\n.......#\r\n...##..#\r\n......#.\r\nK.......\r\n\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...##...\r\n........\r\n....K#K#\r\n", "output": "YES\r\nNO\r\n"}, {"input": "3\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...
false
stdio
null
true
160/C
160
C
PyPy 3-64
TESTS
2
122
0
224681061
input1 = input().split(' ') n = int(input1[0]) x = int(input1[1]) lista = set() input1 = input().split(' ') for e in input1: lista.add(int(e)) order = sorted(lista) result = [] length = len(order) for i in range(length): for j in range(length): result.append((order[i], order[j])) print(result[x - 1]...
98
216
16,076,800
219016744
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,K = map(int,input().split(...
Codeforces Round 111 (Div. 2)
CF
2,012
1
256
Find Pair
You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing n (not necessarily different) integers a1, a2, ..., an. We are interested in all possible pairs of numbers (ai, aj), (1 ≤ i, j ≤ n). In other words, let's consider all n2 pairs of numbers, picked from the given array. For e...
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n2). The second line contains the array containing n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). The numbers in the array can coincide. All numbers are separated with spaces. Please do not use the %lld specificator to read or write 64-bit integers in...
In the single line print two numbers — the sought k-th pair.
null
In the first sample the sorted sequence for the given array looks as: (1, 1), (1, 2), (2, 1), (2, 2). The 4-th of them is pair (2, 2). The sorted sequence for the array from the second sample is given in the statement. The 2-nd pair there is (1, 3).
[{"input": "2 4\n2 1", "output": "2 2"}, {"input": "3 2\n3 1 5", "output": "1 3"}]
1,700
["implementation", "math", "sortings"]
98
[{"input": "2 4\r\n2 1\r\n", "output": "2 2\r\n"}, {"input": "3 2\r\n3 1 5\r\n", "output": "1 3\r\n"}, {"input": "3 3\r\n1 1 2\r\n", "output": "1 1\r\n"}, {"input": "1 1\r\n-4\r\n", "output": "-4 -4\r\n"}, {"input": "3 7\r\n5 4 3\r\n", "output": "5 3\r\n"}, {"input": "3 6\r\n10 1 3\r\n", "output": "3 10\r\n"}, {"input"...
false
stdio
null
true
484/D
484
D
Python 3
TESTS
6
46
0
137777319
m=int(input()) n=list(map(int,input().split())) n.sort() ret=0 for i in range(m//2): ret+=(n[m-1-i]-n[i]) print(ret)
71
1,435
92,364,800
114299610
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) dp = [0] * n pos, neg = -10 ** 18, -10 ** 18 for i, x in enumerate(a): prv = 0 if i == 0 else dp[i - 1] dp[i] = max(neg + x, pos - x, prv) pos = max(pos, prv + x) neg = max(neg, prv - x) print(dp[-1])
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
583/A
583
A
Python 3
TESTS
6
62
0
20455157
n = int(input()) asphaltedH = set() asphaltedV = set() days = [] for i in range(n * n): h, v = [int(i) for i in input().split()] if h not in asphaltedH and v not in asphaltedV: days.append(str(i + 1)) asphaltedH.add(h) asphaltedV.add(v) print(" ".join(sorted(days)))
39
46
0
154961547
A = [] B = [] C = [] s=0 for t in range(int(input())**2): a,b=list(map(int,input().split())) if a not in A and b not in B: A.append(a) B.append(b) C.append(str(t+1)) print(" ".join(C))
Codeforces Round 323 (Div. 2)
CF
2,015
1
256
Asphalting Roads
City X consists of n vertical and n horizontal infinite roads, forming n × n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was made to asphal...
The first line contains integer n (1 ≤ n ≤ 50) — the number of vertical and horizontal roads in the city. Next n2 lines contain the order of intersections in the schedule. The i-th of them contains two numbers hi, vi (1 ≤ hi, vi ≤ n), separated by a space, and meaning that the intersection that goes i-th in the timeta...
In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1.
null
In the sample the brigade acts like that: 1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 2. On the second day the brigade of the workers comes to the int...
[{"input": "2\n1 1\n1 2\n2 1\n2 2", "output": "1 4"}, {"input": "1\n1 1", "output": "1"}]
1,000
["implementation"]
39
[{"input": "2\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "1 4 \r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 \r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n1 2\r\n2 1\r\n", "output": "1 2 \r\n"}, {"input": "2\r\n1 2\r\n2 2\r\n2 1\r\n1 1\r\n", "output": "1 3 \r\n"}, {"input": "3\r\n2 2\r\n1 2\r\n3 2\r\n3 3\r\n1 1\r\n2 3\r\n1 3\...
false
stdio
null
true
583/A
583
A
PyPy 3
TESTS
6
156
20,172,800
79716915
a=int(input()) t=[] u=[] if a==1: c= list(set(list(map(int,input().split())))) c.sort() print(1) else: r=[] cl=[] for j in range(1,2*a+1): c,b=map(int,input().split()) o=0 if c not in r: o+=1 if b not in cl: o+=1 if o==2: ...
39
46
0
155758219
import sys input = sys.stdin.readline n = int(input()) a, b, d = [], [], [] for i in range(n**2): h, v = input()[:-1].split() if h not in a and v not in b: d.append(i+1) a.append(h) b.append(v) print(' '.join(map(str, d)))
Codeforces Round 323 (Div. 2)
CF
2,015
1
256
Asphalting Roads
City X consists of n vertical and n horizontal infinite roads, forming n × n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was made to asphal...
The first line contains integer n (1 ≤ n ≤ 50) — the number of vertical and horizontal roads in the city. Next n2 lines contain the order of intersections in the schedule. The i-th of them contains two numbers hi, vi (1 ≤ hi, vi ≤ n), separated by a space, and meaning that the intersection that goes i-th in the timeta...
In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1.
null
In the sample the brigade acts like that: 1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 2. On the second day the brigade of the workers comes to the int...
[{"input": "2\n1 1\n1 2\n2 1\n2 2", "output": "1 4"}, {"input": "1\n1 1", "output": "1"}]
1,000
["implementation"]
39
[{"input": "2\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "1 4 \r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 \r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n1 2\r\n2 1\r\n", "output": "1 2 \r\n"}, {"input": "2\r\n1 2\r\n2 2\r\n2 1\r\n1 1\r\n", "output": "1 3 \r\n"}, {"input": "3\r\n2 2\r\n1 2\r\n3 2\r\n3 3\r\n1 1\r\n2 3\r\n1 3\...
false
stdio
null
true
228/B
228
B
Python 3
TESTS
0
30
0
206053604
""" https://codeforces.com/problemset/problem/228/B """ def lit_table(): n, m = [int(x) for x in input().split()] # res=[[int(x) for x in row] for row in range(n)] res = [[0]] for _ in range(n): r = [0] + [int(x) for x in input().strip()] res.append(r) return n + 1, m + 1, res na...
46
654
6,656,000
207378818
def solve(x,y): ans=0 for i in range(na): for j in range(ma): if i+x<nb and i+x>-1 and j+y<mb and j+y>-1: v1=int(b[i+x][j+y]) v2=int(a[i][j]) ans+=v1*v2 return ans a,b=[],[] na,ma=list(map(int,input().split())) for i in range(na): p=inp...
Codeforces Round 141 (Div. 2)
CF
2,012
2
256
Two Tables
You've got two rectangular tables with sizes na × ma and nb × mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we w...
The first line contains two space-separated integers na, ma (1 ≤ na, ma ≤ 50) — the number of rows and columns in the first table. Then na lines contain ma characters each — the elements of the first table. Each character is either a "0", or a "1". The next line contains two space-separated integers nb, mb (1 ≤ nb, mb...
Print two space-separated integers x, y (|x|, |y| ≤ 109) — a shift with maximum overlap factor. If there are multiple solutions, print any of them.
null
null
[{"input": "3 2\n01\n10\n00\n2 3\n001\n111", "output": "0 1"}, {"input": "3 3\n000\n010\n000\n1 1\n1", "output": "-1 -1"}]
1,400
["brute force", "implementation"]
46
[{"input": "3 2\r\n01\r\n10\r\n00\r\n2 3\r\n001\r\n111\r\n", "output": "0 1\r\n"}, {"input": "3 3\r\n000\r\n010\r\n000\r\n1 1\r\n1\r\n", "output": "-1 -1\r\n"}, {"input": "2 4\r\n1010\r\n0011\r\n5 5\r\n01100\r\n01110\r\n00111\r\n00110\r\n00110\r\n", "output": "1 1\r\n"}, {"input": "3 1\r\n0\r\n1\r\n0\r\n2 2\r\n11\r\n00...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: lines = [line.strip() for line in f] # Parse first table na, ma = map(int, lines[0].split()) a_ones = [] for i in range(na): line = lines[i + 1] for j in range(ma): if lin...
true
24/A
24
A
PyPy 3-64
TESTS
4
124
0
208369815
from collections import defaultdict n = int(input()) h = defaultdict(list) start = None next = None apath = 0 # going one way bpath = 0 # going the other for i in range(n): a, b, c = map(int, input().split()) if start == None: start = a next = b bpath += c if a not in h: h[a...
21
62
102,400
206179133
''' Online Python Compiler. Code, Compile, Run and Debug python program online. Write your code in this editor and press "Run" button to execute it. ''' n=int(input()) l=[] for _ in range(n): l.append(list(map(int,input().split()))) d={} adj=[[] for t in range(n+1)] fo...
Codeforces Beta Round 24
ICPC
2,010
2
256
Ring road
Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all n cities of Berland were connected by n two-way roads in the ring, i. e. each city was connected directly to exactly two ot...
The first line contains integer n (3 ≤ n ≤ 100) — amount of cities (and roads) in Berland. Next n lines contain description of roads. Each road is described by three integers ai, bi, ci (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ ci ≤ 100) — road is directed from city ai to city bi, redirecting the traffic costs ci.
Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other.
null
null
[{"input": "3\n1 3 1\n1 2 1\n3 2 1", "output": "1"}, {"input": "3\n1 3 1\n1 2 5\n3 2 1", "output": "2"}, {"input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42", "output": "39"}, {"input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5", "output": "0"}]
1,400
["graphs"]
21
[{"input": "3\r\n1 3 1\r\n1 2 1\r\n3 2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 1\r\n1 2 5\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n1 5 4\r\n5 3 8\r\n2 4 15\r\n1 6 16\r\n2 3 23\r\n4 6 42\r\n", "output": "39\r\n"}, {"input": "4\r\n1 2 9\r\n2 3 8\r\n3 4 7\r\n4 1 5\r\n", "output": "0\r\n"}, {"input": "5\r...
false
stdio
null
true
24/A
24
A
Python 3
TESTS
4
186
0
94170329
n = int(input()) cnt = [0] * (n + 1) ss = 0 s1 = 0 for _ in range(n): aa,bb,cc = list(map(int, input().split())) ss += cc if (cnt[aa] == 0): cnt[aa] += 1 else: cnt[bb] += 1 s1 += cc print(min(s1, ss - s1))
21
92
0
139442495
def solve(): n = int(input()) x = 0 y = 0 d = {} g = [[] for _ in range(n + 1)] for i in range(n): a, b, c = map(int, input().split()) d[(a, b)] = 0 d[(b, a)] = c g[a].append(b) g[b].append(a) s = 1 pre = g[1][0] seen = set() while s not in seen: seen.add(s) nex = g[s][0] if nex == pre: nex...
Codeforces Beta Round 24
ICPC
2,010
2
256
Ring road
Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all n cities of Berland were connected by n two-way roads in the ring, i. e. each city was connected directly to exactly two ot...
The first line contains integer n (3 ≤ n ≤ 100) — amount of cities (and roads) in Berland. Next n lines contain description of roads. Each road is described by three integers ai, bi, ci (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ ci ≤ 100) — road is directed from city ai to city bi, redirecting the traffic costs ci.
Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other.
null
null
[{"input": "3\n1 3 1\n1 2 1\n3 2 1", "output": "1"}, {"input": "3\n1 3 1\n1 2 5\n3 2 1", "output": "2"}, {"input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42", "output": "39"}, {"input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5", "output": "0"}]
1,400
["graphs"]
21
[{"input": "3\r\n1 3 1\r\n1 2 1\r\n3 2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 1\r\n1 2 5\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n1 5 4\r\n5 3 8\r\n2 4 15\r\n1 6 16\r\n2 3 23\r\n4 6 42\r\n", "output": "39\r\n"}, {"input": "4\r\n1 2 9\r\n2 3 8\r\n3 4 7\r\n4 1 5\r\n", "output": "0\r\n"}, {"input": "5\r...
false
stdio
null
true
614/B
614
B
Python 3
TESTS
22
390
15,769,600
24418695
from math import log10 n=int(input()) l=input().split() if '0' in l: print(0) exit() d=-1 for i in range(n): if not log10(int(l[i])).is_integer(): d=i print(l[i], end='') break if d==-1: print(1,end='') for i in range(n): if i!=d: print(l[i][1:], end='') print('')
32
62
8,294,400
208581974
# https://codeforces.com/contest/614 import sys input = lambda: sys.stdin.readline().rstrip() # faster! n = int(input()) a = list(input().split()) f, z = "1", 0 for x in a: if x == "0": print(0) exit() else: i = len(x) - 1 while i >= 0 and x[i] == "0": i -= 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
296/B
296
B
Python 3
TESTS
3
218
307,200
68549146
mod = 1000000007 n = int(input()) s1 = input() s2 = input() ans = 1 tc = 1 for i in range(n): if s1[i] == '?': ans *= 10 ans %= mod if s2[i] == '?': ans *= 10 ans %= mod for i in range(n): if s1[i] != '?' and s2[i] != '?' and s1[i] > s2[i]: break if s1[i] == '?' and s2[i] == '?': tc *= 55 tc %= mod ...
38
840
7,065,600
28195911
from functools import reduce n, s1, s2, f1, f2 = int(input()), str(input()), str(input()), lambda x: reduce((lambda a, b: (a * b) % 1000000007), x, 1), lambda x: reduce((lambda a, b: a or b), x, False) print((10 ** sum([(s1[i] == '?') + (s2[i] == '?') for i in range(n)]) - (not f2([s1[i] != '?' and s2[i] != '?' and ord...
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
10/A
10
A
Python 3
TESTS
5
248
0
43898266
n, p1, p2, p3, t1, t2 = map(int, input().split()) consump = 0 z = [] k = [] for _ in range(n): z+=list(map(int, input().split())) for i in range(1, len(z)): k.append(z[i] - z[i-1]) for i in range(0, len(k), 2): consump+= p1*k[i] for i in range(1, len(k), 2): if k[i] <= t1: consump+=p1*k[i] elif t1 < k[i] <= t2: ...
30
62
0
223057731
inputs=list(map(int,input().split())) n=inputs[0] Ps=inputs[1:4] Ts=inputs[4:6] power=0 times=[] for i in range(n): time_i=list(map(int,input().split())) for time in time_i: times.append(time) power+=(time_i[1]-time_i[0])*Ps[0] for i in range(2,len(times),2): rest_time=times[i]-times[i-1] p1...
Codeforces Beta Round 10
ICPC
2,010
1
256
Power Consumption Calculation
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minut...
The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start a...
Output the answer to the problem.
null
null
[{"input": "1 3 2 1 5 10\n0 10", "output": "30"}, {"input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570"}]
900
["implementation"]
30
[{"input": "1 3 2 1 5 10\r\n0 10\r\n", "output": "30"}, {"input": "2 8 4 2 5 10\r\n20 30\r\n50 100\r\n", "output": "570"}, {"input": "3 15 9 95 39 19\r\n873 989\r\n1003 1137\r\n1172 1436\r\n", "output": "8445"}, {"input": "4 73 2 53 58 16\r\n51 52\r\n209 242\r\n281 407\r\n904 945\r\n", "output": "52870"}, {"input": "5 ...
false
stdio
null
true
362/A
362
A
Python 3
PRETESTS
6
46
307,200
5107417
import collections n = list(map(int, input().split()))[0] di = ((2, 2), (-2, 2), (-2, -2), (2, -2)) def bfs(graph, x,y,tx, ty): vis = set() queue = collections.deque() queue.append((x,y)) vis.add((x,y)) while queue: elem = queue.popleft() #print (elem) for direction in ...
45
62
307,200
5108423
def main(): n = int(input()) out = "" for t in range(n): knights = [0 for i in range(16)] valid = [False for i in range(16)] for i in range(8): line = input() #print() for j in range(8): #print(get(i, j), end="\t") if line[j] != '#': valid[get(i, j)] = Tr...
Codeforces Round 212 (Div. 2)
CF
2,013
1
256
Two Semiknights Meet
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the le...
The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed t...
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
null
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from squ...
[{"input": "2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#", "output": "YES\nNO"}]
1,500
["greedy", "math"]
45
[{"input": "2\r\n........\r\n........\r\n......#.\r\nK..##..#\r\n.......#\r\n...##..#\r\n......#.\r\nK.......\r\n\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...##...\r\n........\r\n....K#K#\r\n", "output": "YES\r\nNO\r\n"}, {"input": "3\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...
false
stdio
null
true
231/A
231
A
Python 3
TESTS
4
62
0
231505834
if __name__ == '__main__': count = 0 amount_of_lines = input() for x in range(int(amount_of_lines)): word = input() for y in range(len(word)): if word[y] == ' ': pass else: count += int(word[y]) print(int(count / 3))
21
62
0
226085773
num_of_problems = int(input()) total = 0 for i in range(num_of_problems): submission = input() agreed = 0 for char in submission: if char == "1": agreed += 1 if agreed >= 2: total += 1 print(total)
Codeforces Round 143 (Div. 2)
CF
2,012
2
256
Team
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Va...
Print a single integer — the number of problems the friends will implement on the contest.
null
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta...
[{"input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2"}, {"input": "2\n1 0 0\n0 1 1", "output": "1"}]
800
["brute force", "greedy"]
21
[{"input": "3\r\n1 1 0\r\n1 1 1\r\n1 0 0\r\n", "output": "2\r\n"}, {"input": "2\r\n1 0 0\r\n0 1 1\r\n", "output": "1\r\n"}, {"input": "1\r\n1 0 0\r\n", "output": "0\r\n"}, {"input": "2\r\n1 0 0\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 0 0\r\n0 1 0\r\n1 1 1\r\n0 0 1\r\n0 0 0\r\n", "output": "1\r\n"}, {"input...
false
stdio
null
true
10/A
10
A
Python 3
TESTS
5
92
0
177484103
[n,p1,p2,p3,t1,t2] = map(int, input().split()) times = [] for x in range(n): times.append(list(map(int, input().split()))) count = 0 for session in times: count += p1*(session[1] - session[0]) for index in range(n - 1): diff = times[index+1][0] - times[index][1] if diff >= t1: diff -= t1 ...
30
62
0
228831738
n, p1, p2, p3, t1, t2 = map(int, input().split()) periods = [] for _ in range(n): periods.append(list(map(int, input().split()))) c = 0 for i in range(n - 1): curr = periods[i] next = periods[i+1] c += (curr[-1] - curr[0]) * p1 gap = next[0] - curr[-1] if gap <= t1: c += gap * p1 elif gap <= t1 + t2: ...
Codeforces Beta Round 10
ICPC
2,010
1
256
Power Consumption Calculation
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minut...
The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start a...
Output the answer to the problem.
null
null
[{"input": "1 3 2 1 5 10\n0 10", "output": "30"}, {"input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570"}]
900
["implementation"]
30
[{"input": "1 3 2 1 5 10\r\n0 10\r\n", "output": "30"}, {"input": "2 8 4 2 5 10\r\n20 30\r\n50 100\r\n", "output": "570"}, {"input": "3 15 9 95 39 19\r\n873 989\r\n1003 1137\r\n1172 1436\r\n", "output": "8445"}, {"input": "4 73 2 53 58 16\r\n51 52\r\n209 242\r\n281 407\r\n904 945\r\n", "output": "52870"}, {"input": "5 ...
false
stdio
null
true
615/B
615
B
Python 3
TESTS
2
78
307,200
101012143
def DFS(G, start): n = len(G) S = [] S.append(start) visited[start] = True dist = [0] * n while (S != []): v = S[-1] S.pop() for i in G[v]: dist[v] = max(dist[i] + 1, dist[v]) if (visited[i] == False): S.append(i) ...
60
623
41,984,000
130604111
import sys lines = sys.stdin.read().splitlines() n, m = map(int, lines[0].split()) edges = [[] for _ in range(n)] for line_i in range(1, 1+m): u, v = map(int, lines[line_i].split()) edges[u-1].append(v-1) edges[v-1].append(u-1) longest = [0 for _ in range(n)] for index in range(n): longest[index] = max(...
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
362/A
362
A
PyPy 3
TESTS
6
124
20,172,800
85504567
t = int(input()) for _ in range(t): if _: input() knights = [] for i in range(8): s = input().strip() for j in range(8): if s[j] == 'K': knights.append((i,j)) n1 = knights[0] n2 = knights[1] if n1[0] % 2 == n2[0] % 2 and n1[1] % 2 == n2[1] % 2:...
45
62
307,200
5130546
N = range(8) test = int (input()) for i_test in range(test): if (i_test): input() x1,y1,x2,y2=0,0,0,0 map = [input() for i in N] for i in N: for j in N: if (map[i][j]=="K"): x1,y1,x2,y2 = x2,y2,i,j if (abs(x1-x2)%4==0 and abs(y1-y2)%4==0): print ("YES") else: print ("NO")
Codeforces Round 212 (Div. 2)
CF
2,013
1
256
Two Semiknights Meet
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the le...
The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed t...
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
null
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from squ...
[{"input": "2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#", "output": "YES\nNO"}]
1,500
["greedy", "math"]
45
[{"input": "2\r\n........\r\n........\r\n......#.\r\nK..##..#\r\n.......#\r\n...##..#\r\n......#.\r\nK.......\r\n\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...##...\r\n........\r\n....K#K#\r\n", "output": "YES\r\nNO\r\n"}, {"input": "3\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...
false
stdio
null
true
19/C
19
C
Python 3
TESTS
1
60
0
197317361
n = int(input()) numbers = list(map(int, input().split())) last_occurrence = {} for i in range(n-1, -1, -1): if numbers[i] not in last_occurrence: last_occurrence[numbers[i]] = i result = [] i = 0 while i < n: if i == last_occurrence[numbers[i]]: result.append(numbers[i]) i += 1 el...
70
1,216
14,131,200
174568804
import sys n=int(input()) a=list(map(int,input().split())) M=10**9+1 g={} for i in range(n): g[a[i]]=g.get(a[i],[])+[i] p=[1] for i in range(n): p+=[hash(M*p[-1])] h=[0]*(n+1) for i in range(n): h[i+1]=hash(h[i]*M+a[i]) gh=lambda k,l:hash(h[k+l]-h[k]*p[l])%sys.hash_info.modulus i,t=0,0 while i < n: for ...
Codeforces Beta Round 19
ICPC
2,010
2
256
Deletion of Repeats
Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a repeat of length x is such a substring of length 2x, that its first half coin...
The first input line contains integer n (1 ≤ n ≤ 105) — length of the string. The following line contains n space-separated integer numbers from 0 to 109 inclusive — numbers that stand for the letters of the string. It's guaranteed that each letter can be met in the string at most 10 times.
In the first line output the length of the string's part, left after Bob's deletions. In the second line output all the letters (separated by a space) of the string, left after Bob deleted all the repeats in the described way.
null
null
[{"input": "6\n1 2 3 1 2 3", "output": "3\n1 2 3"}, {"input": "7\n4 5 6 5 6 7 7", "output": "1\n7"}]
2,200
["greedy", "hashing", "string suffix structures"]
70
[{"input": "6\r\n1 2 3 1 2 3\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "7\r\n4 5 6 5 6 7 7\r\n", "output": "1\r\n7 \r\n"}, {"input": "10\r\n5 7 2 1 8 8 5 10 2 5\r\n", "output": "5\r\n8 5 10 2 5 \r\n"}, {"input": "10\r\n0 1 1 1 0 3 0 1 4 0\r\n", "output": "7\r\n1 0 3 0 1 4 0 \r\n"}, {"input": "10\r\n0 1 0 2 0 0 1 1 ...
false
stdio
null
true
743/E
743
E
PyPy 3
TESTS
4
108
3,072,000
151350468
def check(counts, m, add=[0, 0, 0, 0, 0, 0, 0, 0]): n1 = len(counts) I = 1 for i in range(1, n1): c1 = counts[i] c2 = [counts[-1][j]-counts[i][j] for j in range(8)] sides = [0, 0, 0, 0] for j in range(8): if c1[j] >= m+1: sides[0]+=1 if...
41
233
24,780,800
192171052
import bisect import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v): return (m + 1) * u + v n = int(input()) a = list(map(int, input().split())) m = 8 x = [[] for _ in range(m)] for i in range(n): x[a[i] - 1].append(i) s = 0 for y in x: s += min(len(y), 1) if s < m: ...
Codeforces Round 384 (Div. 2)
CF
2,016
2
256
Vladik and cards
Vladik was bored on his way home and decided to play the following game. He took n cards and put them in a row in front of himself. Every card has a positive integer number not exceeding 8 written on it. He decided to find the longest subsequence of cards which satisfies the following conditions: - the number of occur...
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of cards in Vladik's sequence. The second line contains the sequence of n positive integers not exceeding 8 — the description of Vladik's sequence.
Print single integer — the length of the longest subsequence of Vladik's sequence that satisfies both conditions.
null
In the first sample all the numbers written on the cards are equal, so you can't take more than one card, otherwise you'll violate the first condition.
[{"input": "3\n1 1 1", "output": "1"}, {"input": "8\n8 7 6 5 4 3 2 1", "output": "8"}, {"input": "24\n1 8 1 2 8 2 3 8 3 4 8 4 5 8 5 6 8 6 7 8 7 8 8 8", "output": "17"}]
2,200
["binary search", "bitmasks", "brute force", "dp"]
41
[{"input": "3\r\n1 1 1\r\n", "output": "1"}, {"input": "8\r\n8 7 6 5 4 3 2 1\r\n", "output": "8"}, {"input": "24\r\n1 8 1 2 8 2 3 8 3 4 8 4 5 8 5 6 8 6 7 8 7 8 8 8\r\n", "output": "17"}, {"input": "1\r\n8\r\n", "output": "1"}, {"input": "2\r\n5 4\r\n", "output": "2"}, {"input": "3\r\n3 3 2\r\n", "output": "2"}, {"input...
false
stdio
null
true
731/F
731
F
PyPy 3-64
TESTS
12
140
20,582,400
201632357
n=int(input()) a=list(map(int,input().split())) a.sort() ans=0 for i in range(n): s=0 for j in range(i,n): s+=a[j]//a[i]*a[i] ans=max(ans,s) if s<ans: break print(ans)
51
155
32,358,400
215746255
import sys from itertools import accumulate def main(): n = int(sys.stdin.readline().strip()) a = list(map(int, sys.stdin.readline().split())) max_val = max(a) C = [0] * (max_val + 1) for x in a: C[x] += 1 ans=0 C_sum = list(accumulate(C)) for x in set(a): cnt = 0 ...
Codeforces Round 376 (Div. 2)
CF
2,016
1
256
Video Cards
Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated. There are n video cards in the shop, the power of the i-th video card is equal to in...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of video cards in the shop. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 200 000) — powers of video cards.
The only line of the output should contain one integer value — the maximum possible total power of video cards working together.
null
In the first sample, it would be optimal to buy video cards with powers 3, 15 and 9. The video card with power 3 should be chosen as the leading one and all other video cards will be compatible with it. Thus, the total power would be 3 + 15 + 9 = 27. If he buys all the video cards and pick the one with the power 2 as t...
[{"input": "4\n3 2 15 9", "output": "27"}, {"input": "4\n8 2 2 7", "output": "18"}]
1,900
["brute force", "data structures", "implementation", "math", "number theory"]
51
[{"input": "4\r\n3 2 15 9\r\n", "output": "27\r\n"}, {"input": "4\r\n8 2 2 7\r\n", "output": "18\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n123819\r\n", "output": "123819\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "52\r\n"}, {"input": "100\r\n17 23 71 25 50 71 85 46 78 72 89 26 ...
false
stdio
null
true
10/A
10
A
PyPy 3
TESTS
5
218
20,172,800
129230931
n, p1, p2, p3, t1, t2 = map(int, input().split()) lr = 1441 result = 0 for i in range(0,n): l, r = map(int, input().split()) modo1 = t1 if (l - lr) >= t1 else (l - lr) modo2 = t2 if (l- lr - modo1) >= t2 else (l- lr - modo1) modo3 = (l - lr - modo1 - modo2) if (modo1 > 0): modo1 = m...
30
92
0
11583841
a = [] n,P1,P2,P3,T1,T2 = input().split() n = int(n) P1 = int(P1) P2 = int(P2) P3 = int(P3) T1 = int(T1) T2 = int(T2) for i in range(n): x,y = input().split() a.append([int(x),int(y)]) p = 0 for i in range(len(a)): p += (a[i][1] - a[i][0])*P1 for i in range(len(a)-1): z = abs(a[i][1] - a[i+1][...
Codeforces Beta Round 10
ICPC
2,010
1
256
Power Consumption Calculation
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minut...
The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start a...
Output the answer to the problem.
null
null
[{"input": "1 3 2 1 5 10\n0 10", "output": "30"}, {"input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570"}]
900
["implementation"]
30
[{"input": "1 3 2 1 5 10\r\n0 10\r\n", "output": "30"}, {"input": "2 8 4 2 5 10\r\n20 30\r\n50 100\r\n", "output": "570"}, {"input": "3 15 9 95 39 19\r\n873 989\r\n1003 1137\r\n1172 1436\r\n", "output": "8445"}, {"input": "4 73 2 53 58 16\r\n51 52\r\n209 242\r\n281 407\r\n904 945\r\n", "output": "52870"}, {"input": "5 ...
false
stdio
null
true
298/A
298
A
Python 3
TESTS
8
92
0
183038492
n = int(input()) seq = list(input()) if len(set(filter(lambda x: x.isalpha(), seq))) == 1: letters = tuple(filter(lambda x: x.isalpha(), seq)) l = letters[0] if l == "R": s = seq.index(l)+1 e = s+len(letters) print(s, e) else: e = seq.index(l) s = e+len(letters)-1...
23
62
0
147948126
n =int(input()) s=input() a=s.find('R')+1 t=0 if a==0 : a=s.find('L')+1 t=a-1 for x in range(1,len(s)) : if s[x]!='R' and s[x-1]=='R' : if s[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
362/A
362
A
PyPy 3-64
TESTS
6
46
0
203745295
import sys input = lambda: sys.stdin.readline().rstrip() for _ in range(int(input())): A = [] v = [] cnt = 0 for i in range(8): A.append(input()) for j in range(8): #print(i,j) if A[i][j]=='K': v.append((i,j,cnt)) cnt+=1 a...
45
62
409,600
5772053
def check(): board = [] for cont in range(0,8): board.append(input()) l = True for cont in range(0,8): for cont2 in range(0,8): if board[cont][cont2] == 'K': if l: xk1 = cont2 yk1 = cont l = False ...
Codeforces Round 212 (Div. 2)
CF
2,013
1
256
Two Semiknights Meet
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the le...
The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed t...
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
null
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from squ...
[{"input": "2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#", "output": "YES\nNO"}]
1,500
["greedy", "math"]
45
[{"input": "2\r\n........\r\n........\r\n......#.\r\nK..##..#\r\n.......#\r\n...##..#\r\n......#.\r\nK.......\r\n\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...##...\r\n........\r\n....K#K#\r\n", "output": "YES\r\nNO\r\n"}, {"input": "3\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...
false
stdio
null
true
825/E
825
E
PyPy 3
TESTS
6
155
0
93293235
import sys from heapq import heappop, heappush n, m = map(int, sys.stdin.buffer.readline().decode('utf-8').split()) adj = [[] for _ in range(n)] rev = [[] for _ in range(n)] indeg, outdeg = [0]*n, [0]*n for u, v in (map(int, line.decode('utf-8').split()) for line in sys.stdin.buffer): adj[u-1].append(v-1) rev...
19
311
27,033,600
177003198
from collections import defaultdict, deque import heapq import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ inp = sys.stdin.readline def input(): return inp().strip() def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(map(int, input().sp...
Educational Codeforces Round 25
ICPC
2,017
1
256
Minimal Labels
You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected. You should assign labels to all vertices in such a way that: - Labels form a valid permutation of length n — an integer sequence such that each integer...
The first line contains two integer numbers n, m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). Next m lines contain two integer numbers v and u (1 ≤ v, u ≤ n, v ≠ u) — edges of the graph. Edges are directed, graph doesn't contain loops or multiple edges.
Print n numbers — lexicographically smallest correct permutation of labels of vertices.
null
null
[{"input": "3 3\n1 2\n1 3\n3 2", "output": "1 3 2"}, {"input": "4 5\n3 1\n4 1\n2 3\n3 4\n2 4", "output": "4 1 2 3"}, {"input": "5 4\n3 1\n2 1\n2 3\n4 5", "output": "3 1 2 4 5"}]
2,300
["data structures", "dfs and similar", "graphs", "greedy"]
19
[{"input": "3 3\r\n1 2\r\n1 3\r\n3 2\r\n", "output": "1 3 2 \r\n"}, {"input": "4 5\r\n3 1\r\n4 1\r\n2 3\r\n3 4\r\n2 4\r\n", "output": "4 1 2 3 \r\n"}, {"input": "5 4\r\n3 1\r\n2 1\r\n2 3\r\n4 5\r\n", "output": "3 1 2 4 5 \r\n"}, {"input": "2 1\r\n2 1\r\n", "output": "2 1 \r\n"}, {"input": "5 10\r\n5 2\r\n4 1\r\n2 1\r\n...
false
stdio
null
true
825/E
825
E
Python 3
TESTS
6
46
102,400
177006518
from collections import defaultdict import heapq n,m = tuple(map(int,input().split())) in_degree = defaultdict(int) graph = defaultdict(list) for _ in range(m): edge = list(map(int,input().split())) graph[edge[0]].append(edge[1]) in_degree[edge[1]] += 1 next_minimum = {} def set_next_min(vertex): if...
19
342
17,408,000
93295209
import sys from heapq import heappop, heappush n, m = map(int, sys.stdin.buffer.readline().decode('utf-8').split()) rev = [[] for _ in range(n)] outdeg = [0]*n for u, v in (map(int, line.decode('utf-8').split()) for line in sys.stdin.buffer): rev[v-1].append(u-1) outdeg[u-1] += 1 ans = [0]*n num = n hq = [-i...
Educational Codeforces Round 25
ICPC
2,017
1
256
Minimal Labels
You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected. You should assign labels to all vertices in such a way that: - Labels form a valid permutation of length n — an integer sequence such that each integer...
The first line contains two integer numbers n, m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). Next m lines contain two integer numbers v and u (1 ≤ v, u ≤ n, v ≠ u) — edges of the graph. Edges are directed, graph doesn't contain loops or multiple edges.
Print n numbers — lexicographically smallest correct permutation of labels of vertices.
null
null
[{"input": "3 3\n1 2\n1 3\n3 2", "output": "1 3 2"}, {"input": "4 5\n3 1\n4 1\n2 3\n3 4\n2 4", "output": "4 1 2 3"}, {"input": "5 4\n3 1\n2 1\n2 3\n4 5", "output": "3 1 2 4 5"}]
2,300
["data structures", "dfs and similar", "graphs", "greedy"]
19
[{"input": "3 3\r\n1 2\r\n1 3\r\n3 2\r\n", "output": "1 3 2 \r\n"}, {"input": "4 5\r\n3 1\r\n4 1\r\n2 3\r\n3 4\r\n2 4\r\n", "output": "4 1 2 3 \r\n"}, {"input": "5 4\r\n3 1\r\n2 1\r\n2 3\r\n4 5\r\n", "output": "3 1 2 4 5 \r\n"}, {"input": "2 1\r\n2 1\r\n", "output": "2 1 \r\n"}, {"input": "5 10\r\n5 2\r\n4 1\r\n2 1\r\n...
false
stdio
null
true
825/E
825
E
Python 3
TESTS
6
46
512,000
227589716
import collections import heapq intInput = lambda : int(input()) tupInput = lambda : map(int, input().strip().split()) intListInput = lambda : list(map(int, input().strip().split())) strListInput = lambda : input().strip().split() strInput = lambda : list(input().strip()) def run(): n, m = tupInput() graph = ...
19
343
34,406,400
132641591
from collections import deque import heapq import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def main(): n, m = map(int, input().split()) rg = [[] for i in range(n)] outd = [0]*n for i in range(m): a, b = map(int, input().split()) a, b = a-1, b-1 ...
Educational Codeforces Round 25
ICPC
2,017
1
256
Minimal Labels
You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected. You should assign labels to all vertices in such a way that: - Labels form a valid permutation of length n — an integer sequence such that each integer...
The first line contains two integer numbers n, m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). Next m lines contain two integer numbers v and u (1 ≤ v, u ≤ n, v ≠ u) — edges of the graph. Edges are directed, graph doesn't contain loops or multiple edges.
Print n numbers — lexicographically smallest correct permutation of labels of vertices.
null
null
[{"input": "3 3\n1 2\n1 3\n3 2", "output": "1 3 2"}, {"input": "4 5\n3 1\n4 1\n2 3\n3 4\n2 4", "output": "4 1 2 3"}, {"input": "5 4\n3 1\n2 1\n2 3\n4 5", "output": "3 1 2 4 5"}]
2,300
["data structures", "dfs and similar", "graphs", "greedy"]
19
[{"input": "3 3\r\n1 2\r\n1 3\r\n3 2\r\n", "output": "1 3 2 \r\n"}, {"input": "4 5\r\n3 1\r\n4 1\r\n2 3\r\n3 4\r\n2 4\r\n", "output": "4 1 2 3 \r\n"}, {"input": "5 4\r\n3 1\r\n2 1\r\n2 3\r\n4 5\r\n", "output": "3 1 2 4 5 \r\n"}, {"input": "2 1\r\n2 1\r\n", "output": "2 1 \r\n"}, {"input": "5 10\r\n5 2\r\n4 1\r\n2 1\r\n...
false
stdio
null
true
825/E
825
E
PyPy 3-64
TESTS
6
46
131,481,600
181892884
from sys import stdin input=lambda :stdin.readline()[:-1] import sys sys.setrecursionlimit(10**5+10) n,m=map(int,input().split()) cnt=[0]*n edge=[[] for i in range(n)] for _ in range(m): u,v=map(lambda x:int(x)-1,input().split()) edge[v].append(u) seen=[0]*n tmp=1 ans=[0]*n def calc(v): if seen[v]: return ...
19
374
22,118,400
182150263
from sys import stdin input=lambda :stdin.readline()[:-1] from heapq import* n,m=map(int,input().split()) edge=[[] for i in range(n)] cnt=[0]*n for i in range(m): u,v=map(lambda x:int(x)-1,input().split()) edge[v].append(u) cnt[u]+=1 hq=[] for i in range(n): if cnt[i]==0: heappush(hq,-i) ans=[0]*n tmp=n ...
Educational Codeforces Round 25
ICPC
2,017
1
256
Minimal Labels
You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected. You should assign labels to all vertices in such a way that: - Labels form a valid permutation of length n — an integer sequence such that each integer...
The first line contains two integer numbers n, m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). Next m lines contain two integer numbers v and u (1 ≤ v, u ≤ n, v ≠ u) — edges of the graph. Edges are directed, graph doesn't contain loops or multiple edges.
Print n numbers — lexicographically smallest correct permutation of labels of vertices.
null
null
[{"input": "3 3\n1 2\n1 3\n3 2", "output": "1 3 2"}, {"input": "4 5\n3 1\n4 1\n2 3\n3 4\n2 4", "output": "4 1 2 3"}, {"input": "5 4\n3 1\n2 1\n2 3\n4 5", "output": "3 1 2 4 5"}]
2,300
["data structures", "dfs and similar", "graphs", "greedy"]
19
[{"input": "3 3\r\n1 2\r\n1 3\r\n3 2\r\n", "output": "1 3 2 \r\n"}, {"input": "4 5\r\n3 1\r\n4 1\r\n2 3\r\n3 4\r\n2 4\r\n", "output": "4 1 2 3 \r\n"}, {"input": "5 4\r\n3 1\r\n2 1\r\n2 3\r\n4 5\r\n", "output": "3 1 2 4 5 \r\n"}, {"input": "2 1\r\n2 1\r\n", "output": "2 1 \r\n"}, {"input": "5 10\r\n5 2\r\n4 1\r\n2 1\r\n...
false
stdio
null
true
825/E
825
E
Python 3
TESTS
6
62
102,400
177008152
from collections import defaultdict vertices, edges = list(map(int, input().split())) graph = defaultdict(set) indegree = defaultdict(int) for _ in range(edges): pre, nxt = list(map(int, input().split())) indegree[nxt] += 1 graph[pre].add(nxt) answer = [] path = [] color = defaultdict(int) array = defau...
19
390
30,924,800
212162167
import sys import math import collections from heapq import heappush, heappop input = sys.stdin.readline ints = lambda: list(map(int, input().split())) n, m = ints() g = [[] for _ in range(n)] deg = [0] * n for _ in range(m): u, v = ints() u -= 1 v -= 1 g[u].append((v, 0)) g[v].append((u, 1)) ...
Educational Codeforces Round 25
ICPC
2,017
1
256
Minimal Labels
You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected. You should assign labels to all vertices in such a way that: - Labels form a valid permutation of length n — an integer sequence such that each integer...
The first line contains two integer numbers n, m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). Next m lines contain two integer numbers v and u (1 ≤ v, u ≤ n, v ≠ u) — edges of the graph. Edges are directed, graph doesn't contain loops or multiple edges.
Print n numbers — lexicographically smallest correct permutation of labels of vertices.
null
null
[{"input": "3 3\n1 2\n1 3\n3 2", "output": "1 3 2"}, {"input": "4 5\n3 1\n4 1\n2 3\n3 4\n2 4", "output": "4 1 2 3"}, {"input": "5 4\n3 1\n2 1\n2 3\n4 5", "output": "3 1 2 4 5"}]
2,300
["data structures", "dfs and similar", "graphs", "greedy"]
19
[{"input": "3 3\r\n1 2\r\n1 3\r\n3 2\r\n", "output": "1 3 2 \r\n"}, {"input": "4 5\r\n3 1\r\n4 1\r\n2 3\r\n3 4\r\n2 4\r\n", "output": "4 1 2 3 \r\n"}, {"input": "5 4\r\n3 1\r\n2 1\r\n2 3\r\n4 5\r\n", "output": "3 1 2 4 5 \r\n"}, {"input": "2 1\r\n2 1\r\n", "output": "2 1 \r\n"}, {"input": "5 10\r\n5 2\r\n4 1\r\n2 1\r\n...
false
stdio
null
true