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
113/B
113
B
Python 3
TESTS
6
122
5,632,000
34127288
t, a, b = input(), input(), input() def f(q): s = q + ' ' + t n, m = len(s), len(q) p = [-1] + [0] * n i, r = 0, [] for j in range(1, n): while i + 1 and s[i] != s[j]: i = p[i] i += 1 p[j + 1] = i if i == m: r.append(j - m - 1) return r p = f(b)[::-1] s = [] for i...
88
280
5,734,400
27992641
def calc_lcp(s, sa): n = len(s) rank = [0 for _ in range(n)] for i in range(n): rank[sa[i]] = i lcp = [0 for _ in range(n - 1)] h = 0 for i in range(n): if rank[i] < n - 1: while s[i + h] == s[sa[rank[i] + 1] + h]: h += 1 lcp[rank[i]] = h ...
Codeforces Beta Round 86 (Div. 1 Only)
CF
2,011
2
256
Petr#
Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the sbegin and ending with the send (it is possible sbegin = send), the given string t has. Substrings...
The input file consists of three lines. The first line contains string t. The second and the third lines contain the sbegin and send identificators, correspondingly. All three lines are non-empty strings consisting of lowercase Latin letters. The length of each string doesn't exceed 2000 characters.
Output the only number — the amount of different substrings of t that start with sbegin and end with send.
null
In the third sample there are four appropriate different substrings. They are: ab, abab, ababab, abababab. In the fourth sample identificators intersect.
[{"input": "round\nro\nou", "output": "1"}, {"input": "codeforces\ncode\nforca", "output": "0"}, {"input": "abababab\na\nb", "output": "4"}, {"input": "aba\nab\nba", "output": "1"}]
2,000
["brute force", "data structures", "hashing", "strings"]
88
[{"input": "round\r\nro\r\nou\r\n", "output": "1\r\n"}, {"input": "codeforces\r\ncode\r\nforca\r\n", "output": "0\r\n"}, {"input": "abababab\r\na\r\nb\r\n", "output": "4\r\n"}, {"input": "aba\r\nab\r\nba\r\n", "output": "1\r\n"}, {"input": "abcdefghijklmnopqrstuvwxyz\r\nabc\r\nxyz\r\n", "output": "1\r\n"}, {"input": "a...
false
stdio
null
true
733/D
733
D
Python 3
TESTS
7
530
19,660,800
55079195
A=[] for val in range(1,int(input())+1): a=list(map(int,input().split())) a.sort(reverse=True) a += [val] A.append(a) A.sort(key=lambda x:(-x[0],-x[1],-x[2])) T=A[0] Max = (min(T[:3])/2) Ans=[T[3]] count = 1 for val in A[1:]: count += 1 X=val lmax=min(X)/2 if lmax > Max: Max = lm...
104
514
16,588,800
109816728
n = int(input()) mv = 0 mn = [] data = {} for i in range (n): cur = list(sorted(map(int, input().split()))) key = (cur[1], cur[2]) if key in data: old, k = data[key] res = [old + cur[0], cur[1], cur[2]] m = min(res) if m > mv: mv = m mn = [k, i] if old < cur[0]: data[key] = ...
Codeforces Round 378 (Div. 2)
CF
2,016
3
256
Kostya the Sculptor
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangula...
The first line contains the integer n (1 ≤ n ≤ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≤ ai, bi, ci ≤ 109) — the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones.
In the first line print k (1 ≤ k ≤ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in ar...
null
In the first example we can connect the pairs of stones: - 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 - 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. - 2 and 6, the size of the...
[{"input": "6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4", "output": "1\n1"}, {"input": "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7", "output": "2\n1 5"}]
1,600
["data structures", "hashing"]
104
[{"input": "6\r\n5 5 5\r\n3 2 4\r\n1 4 1\r\n2 1 3\r\n3 2 4\r\n3 3 4\r\n", "output": "1\r\n1\r\n"}, {"input": "7\r\n10 7 8\r\n5 10 3\r\n4 2 6\r\n5 5 5\r\n10 2 8\r\n4 2 1\r\n7 7 7\r\n", "output": "2\r\n1 5\r\n"}, {"input": "1\r\n1 1 1\r\n", "output": "1\r\n1\r\n"}, {"input": "2\r\n2 3 1\r\n2 2 3\r\n", "output": "2\r\n2 1...
false
stdio
import sys import os from collections import defaultdict EPS = 1e-9 def main(input_path, output_path, submission_output_path): # Read input with open(input_path) as f: n = int(f.readline()) stones = [] for _ in range(n): a, b, c = map(int, f.readline().split()) ...
true
352/A
352
A
PyPy 3-64
TESTS
18
124
0
196274659
n=int(input()) a=list(map(int,input().split())) z=a.count(5) if z>9 and n-z>0: t=z-z%9 print("5"*t+"0"*(n-z)) elif n%9!=0 and n-z>0: print(0) else: print(-1)
42
92
0
4666596
n = int(input()) seq = list(map(int, input().split())) five = 0 zero = 0 for i in seq: if i == 5: five += 1 elif i == 0: zero += 1 if five >= 9: mod = five % 9 if zero >= 1: print((five - mod) * '5' + zero * '0') else: print(-1) else: if zero > 0: print...
Codeforces Round 204 (Div. 2)
CF
2,013
1
256
Jeff and Digits
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that number ...
The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
null
In the first test you can make only one number that is a multiple of 90 — 0. In the second test you can make number 5555555550, it is a multiple of 90.
[{"input": "4\n5 0 5 0", "output": "0"}, {"input": "11\n5 5 5 5 5 5 5 5 0 5 5", "output": "5555555550"}]
1,000
["brute force", "implementation", "math"]
42
[{"input": "4\r\n5 0 5 0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 0 5 5\r\n", "output": "5555555550\r\n"}, {"input": "7\r\n5 5 5 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n5\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 0 5 5 5 0 0 5 5 5 5\r\n", "out...
false
stdio
null
true
618/C
618
C
Python 3
TESTS
84
1,029
20,582,400
15657802
def cross_pr(a_): x1, y1, x2, y2 = a_[:] return x1 * y2 - x2 * y1 def vector(a_): x1, y1, x2, y2 = a_[:] return [x1 - x2, y1 - y2] def dist(a_): x1, y1 = a_[:] return (x1 * x1 + y1 * y1) ** 0.5 n = int(input()) x = [[] for i in range(n)] for i in range(n): x[i] = [int(i) for i in input...
98
623
16,281,600
15661989
def mykey(ar): return ar[0]*10000000000+ar[1] n = int(input()) a = [[0, 0, 0]for i in range(n)] for i in range(n): a[i][0], a[i][1] = map(int, input().split()) a[i][2] = i+1 a.sort(key=mykey) for i in range(2,n): if (a[i][0]-a[0][0])*(a[1][1]-a[0][1])!=(a[i][1]-a[0][1])*(a[1][0]-a[0][0]): print(a[0][2], a[1][2],...
Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)
CF
2,016
2
256
Constellation
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position. In the evening Noku is going to take a look at the night sky. He would like to find three d...
The first line of the input contains a single integer n (3 ≤ n ≤ 100 000). Each of the next n lines contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109). It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Print three distinct integers on a single line — the indices of the three points that form a triangle that satisfies the conditions stated in the problem. If there are multiple possible answers, you may print any of them.
null
In the first sample, we can print the three indices in any order. In the second sample, we have the following picture. Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
[{"input": "3\n0 1\n1 0\n1 1", "output": "1 2 3"}, {"input": "5\n0 0\n0 2\n2 0\n2 2\n1 1", "output": "1 3 5"}]
1,600
["geometry", "implementation"]
98
[{"input": "3\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "1 2 3\r\n"}, {"input": "5\r\n0 0\r\n0 2\r\n2 0\r\n2 2\r\n1 1\r\n", "output": "1 3 5\r\n"}, {"input": "3\r\n819934317 939682125\r\n487662889 8614219\r\n-557136619 382982369\r\n", "output": "1 3 2\r\n"}, {"input": "10\r\n25280705 121178189\r\n219147240 -570920213\r\n-82...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input points with open(input_path, 'r') as f: n = int(f.readline().strip()) points = [] for _ in range(n): x, y = map(int, f.readline().strip().split()) points.append((x, y)) # Read su...
true
958/F2
958
F2
PyPy 3
TESTS
1
108
20,275,200
123100267
from heapq import heappop,heappush,heapify from collections import deque n,m=map(int,input().split()) arr=list(map(int,input().split())) brr=list(map(int,input().split())) sum_brr=sum(brr) c={} for i in range(m): c[i+1] =brr[i] lst=[[] for i in range(m+1)] for i in range(n): lst[arr[i]].append(i) maxi_indx=-1 f...
59
561
21,094,400
37542646
n, m = map(int, input().split()) c = list(map(int, input().split())) k = list(map(int, input().split())) p = [0] * m c = [i -1 for i in c] s = sum(k) cnt = k.count(0) l = 0 r = 0 while r < n and cnt < m: p[c[r]] += 1 if p[c[r]] == k[c[r]]: cnt += 1 r += 1 if cnt != m: print(-1) exit(0) ans =...
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
1
256
Lightsabers (medium)
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th...
The first line of the input contains n (1 ≤ n ≤ 2·105) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with $$1 \leq \sum_{i=1}^{m} k_i \leq n$$) – the desired co...
Output one number: the minimum number of Jedi Knights that need to be removed from the sequence so that, in what remains, there is an interval with the prescribed counts of lightsaber colors. If this is not possible, output - 1.
null
null
[{"input": "8 3\n3 3 1 2 2 1 1 3\n3 1 1", "output": "1"}]
1,800
["binary search", "two pointers"]
59
[{"input": "8 3\r\n3 3 1 2 2 1 1 3\r\n3 1 1\r\n", "output": "1\r\n"}, {"input": "6 5\r\n1 2 4 2 4 3\r\n0 0 1 0 0\r\n", "output": "0\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\...
false
stdio
null
true
691/A
691
A
PyPy 3
TESTS
13
62
0
146693946
n=int(input()) a=list(map(int,input().split())) c=a.count(0) if n==1 and a[0]==1: print('YES') elif c==1: print('YES') else: print('NO')
83
46
0
155873739
import sys input = sys.stdin.readline n = int(input()) s = input()[:-1].replace(' ','') if n == 1: if s == '1': print("YES") else: print("NO") else: if s.count('0') == 1: print("YES") else: print("NO")
Educational Codeforces Round 14
ICPC
2,016
1
256
Fashion in Berland
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with n buttons. Determine if it is fasten...
The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket. The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1.
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
null
null
[{"input": "3\n1 0 1", "output": "YES"}, {"input": "3\n1 0 0", "output": "NO"}]
1,000
["implementation"]
83
[{"input": "3\r\n1 0 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r...
false
stdio
null
true
733/D
733
D
PyPy 3-64
TESTS
6
608
96,460,800
194325932
import sys input = sys.stdin.readline from collections import defaultdict d = defaultdict(set) n = int(input()) x = 0 q = [0] for i in range(1, n+1): a, b, c = sorted(map(int, input().split())) d[(a,b)].add((c, i)) d[(b,c)].add((a, i)) d[(a,c)].add((b, i)) y = a*b*c if y > x: x = y ...
104
545
16,588,800
181717466
""" Prositka 20.11.2022""" n = int(input()) data = {} ans = 0 res = 0 pos = 0 ind = [] for i in range(n): tmp = sorted(list(map(int, input().split()))) if min(tmp) > ans: ans = min(tmp) ind = [i, -1] t = (tmp[1], tmp[2]) if t in data: third, _ = data[t] if min([third + tmp[0], tmp[1], tmp[2]]) > ans: an...
Codeforces Round 378 (Div. 2)
CF
2,016
3
256
Kostya the Sculptor
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangula...
The first line contains the integer n (1 ≤ n ≤ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≤ ai, bi, ci ≤ 109) — the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones.
In the first line print k (1 ≤ k ≤ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in ar...
null
In the first example we can connect the pairs of stones: - 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 - 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. - 2 and 6, the size of the...
[{"input": "6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4", "output": "1\n1"}, {"input": "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7", "output": "2\n1 5"}]
1,600
["data structures", "hashing"]
104
[{"input": "6\r\n5 5 5\r\n3 2 4\r\n1 4 1\r\n2 1 3\r\n3 2 4\r\n3 3 4\r\n", "output": "1\r\n1\r\n"}, {"input": "7\r\n10 7 8\r\n5 10 3\r\n4 2 6\r\n5 5 5\r\n10 2 8\r\n4 2 1\r\n7 7 7\r\n", "output": "2\r\n1 5\r\n"}, {"input": "1\r\n1 1 1\r\n", "output": "1\r\n1\r\n"}, {"input": "2\r\n2 3 1\r\n2 2 3\r\n", "output": "2\r\n2 1...
false
stdio
import sys import os from collections import defaultdict EPS = 1e-9 def main(input_path, output_path, submission_output_path): # Read input with open(input_path) as f: n = int(f.readline()) stones = [] for _ in range(n): a, b, c = map(int, f.readline().split()) ...
true
269/A
269
A
PyPy 3
TESTS
3
154
0
116926838
import sys input=sys.stdin.readline n=int(input()) ka=[list(map(int,input().split())) for i in range(n)] m=0 for k,a in ka: cnt=k x=1 while x<a: x*=4 cnt+=1 m=max(m,cnt) print(m)
46
872
9,625,600
5145447
n = int(input()) t = [tuple(map(int, input().split())) for i in range(n)] m = max(t) d = 2 * m[0] + len(bin(m[1])) - 1 t = sorted([i for i in t if 2 * i[0] + len(bin(i[1])) > d]) p, k = t[0][0], t[0][1] - 1 for i in range(1, len(t)): p, k = t[i][0], max(t[i][1] - 1, k >> 2 * (t[i][0] - p)) print(p + (len(bin(k)...
Codeforces Round 165 (Div. 1)
CF
2,013
2
256
Magical Boxes
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes. From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a...
The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.
Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.
null
Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture. In the second test case, we can put all four small boxes into a box with side length 2.
[{"input": "2\n0 3\n1 5", "output": "3"}, {"input": "1\n0 4", "output": "1"}, {"input": "2\n1 10\n2 2", "output": "3"}]
1,600
["greedy", "math"]
46
[{"input": "2\r\n0 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "1\r\n0 4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 10\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "1\r\n"}, {"input": "1\r\n1000000000 1000000000\r\n", "output": "1000000015\r\n"}, {"input": "1\r\n0 16\r\n", "output": "2\r\n"}, ...
false
stdio
null
true
269/A
269
A
PyPy 3
TESTS
3
186
20,172,800
116135607
from math import * c=-1 for i in range(int(input())): k,a=list(map(int,input().split())) b=int(log(a,4)) if a!=4**b: b+=1 if c==-1 or k+b>c: c=k+b print(c)
46
1,340
9,011,200
221595338
from math import ceil,log n,r=int(input()),0 for i in range(n): k,a=list(map(int,input().split())) val=int(ceil(log(a,4))) val+=k r=max(r,val) if a==1: r=max(r, k+1) print(r)
Codeforces Round 165 (Div. 1)
CF
2,013
2
256
Magical Boxes
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes. From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a...
The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.
Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.
null
Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture. In the second test case, we can put all four small boxes into a box with side length 2.
[{"input": "2\n0 3\n1 5", "output": "3"}, {"input": "1\n0 4", "output": "1"}, {"input": "2\n1 10\n2 2", "output": "3"}]
1,600
["greedy", "math"]
46
[{"input": "2\r\n0 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "1\r\n0 4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 10\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "1\r\n"}, {"input": "1\r\n1000000000 1000000000\r\n", "output": "1000000015\r\n"}, {"input": "1\r\n0 16\r\n", "output": "2\r\n"}, ...
false
stdio
null
true
796/B
796
B
Python 3
TESTS
13
1,496
87,449,600
119563831
from collections import * n, m, k = map(int, input().split()) d = defaultdict(int) for i in map(int, input().split()): d[i] += 1 l = [0]*(n+1) l[1] = 1 for i in range(k): u, v = map(int, input().split()) if (l[u] or l[v]) and v in d: print(v) exit(0) elif(l[u] or l[v]) and u in d: ...
73
483
102,400,000
189011260
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, m, k = map(int, input().split()) h = list(map(int, input().split())) s = [0] * (n + 1) s[1] = 1 ng = [0] * (n + 1) for i in h: ng[i] = 1 ans = ng[1] uv = [tuple(map(int, input().split())) for _ in range(k)] for u, v in uv: if an...
Codeforces Round 408 (Div. 2)
CF
2,017
2
256
Find The Bone
Zane the wizard is going to perform a magic show shuffling the cups. There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x = i. The problematic bone is initially at the position x = 1. Zane will confuse the audience b...
The first line contains three integers n, m, and k (2 ≤ n ≤ 106, 1 ≤ m ≤ n, 1 ≤ k ≤ 3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively. The second line contains m distinct integers h1, h2, ..., hm (1 ≤ hi ≤ n) — the positions along the x-axis where there ...
Print one integer — the final position along the x-axis of the bone.
null
In the first sample, after the operations, the bone becomes at x = 2, x = 5, x = 7, and x = 1, respectively. In the second sample, after the first operation, the bone becomes at x = 2, and falls into the hole onto the ground.
[{"input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1", "output": "1"}, {"input": "5 1 2\n2\n1 2\n2 4", "output": "2"}]
1,300
["implementation"]
73
[{"input": "7 3 4\r\n3 4 6\r\n1 2\r\n2 5\r\n5 7\r\n7 1\r\n", "output": "1"}, {"input": "5 1 2\r\n2\r\n1 2\r\n2 4\r\n", "output": "2"}, {"input": "10000 1 9\r\n55\r\n44 1\r\n2929 9292\r\n9999 9998\r\n44 55\r\n49 94\r\n55 53\r\n100 199\r\n55 50\r\n53 11\r\n", "output": "55"}, {"input": "100000 3 7\r\n2 3 4\r\n1 5\r\n5 1\...
false
stdio
null
true
518/E
518
E
Python 3
TESTS
4
93
1,536,000
117546131
from collections import Counter def questions(n, k, A): B = A[:] for i in range(k): a0 = None j0 = None q = 0 for j in range(i, n, k): a1 = A[j] if a1 is None: q += 1 continue if q: if a0 is None...
75
217
12,595,200
217516366
def calculate_next_range(left, right, number): left += 1 right -= 1 if right - left + 1 < number: return 10 ** 10 num = number // 2 if number % 2: if num <= right and -num >= left: return -num else: if -num >= left and num - 1 <= right: return...
Codeforces Round 293 (Div. 2)
CF
2,015
2
256
Arthur and Questions
After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length n (a1, a2, ..., an), consisting of integers and integer k, not exceeding n. This sequence had the following property: if you write out the sums of all its segments consisting of k consecutive elements (a1  +  a2 ...  +  ...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105), showing how many numbers are in Arthur's sequence and the lengths of segments respectively. The next line contains n space-separated elements ai (1 ≤ i ≤ n). If ai  =  ?, then the i-th element of Arthur's sequence was replaced by a question mark. Otherw...
If Arthur is wrong at some point and there is no sequence that could fit the given information, print a single string "Incorrect sequence" (without the quotes). Otherwise, print n integers — Arthur's favorite sequence. If there are multiple such sequences, print the sequence with the minimum sum |ai|, where |ai| is th...
null
null
[{"input": "3 2\n? 1 2", "output": "0 1 2"}, {"input": "5 1\n-10 -9 ? -7 -6", "output": "-10 -9 -8 -7 -6"}, {"input": "5 3\n4 6 7 2 9", "output": "Incorrect sequence"}]
2,200
["greedy", "implementation", "math", "ternary search"]
75
[{"input": "3 2\r\n? 1 2\r\n", "output": "0 1 2 \r\n"}, {"input": "5 1\r\n-10 -9 ? -7 -6\r\n", "output": "-10 -9 -8 -7 -6 \r\n"}, {"input": "5 3\r\n4 6 7 2 9\r\n", "output": "Incorrect sequence\r\n"}, {"input": "9 3\r\n? ? ? ? ? ? ? ? ?\r\n", "output": "-1 -1 -1 0 0 0 1 1 1 \r\n"}, {"input": "5 1\r\n1000000000 ? ? ? ?\...
false
stdio
import sys def read_sequence(file): line = file.readline().strip() if line == 'Incorrect sequence': return None try: return list(map(int, line.split())) except: return None def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv...
true
958/F2
958
F2
PyPy 3-64
TESTS
6
202
20,275,200
188041676
import itertools import math import threading import time from builtins import input, range from math import gcd as gcd import sys from io import BytesIO, IOBase import queue import itertools import collections from heapq import heappop, heappush import random import os from random import randint import decimal from ma...
59
577
20,992,000
37323536
n, m = map(int, input().split()) c = list(map(int, input().split())) k = list(map(int, input().split())) p = [0] * m c = [o - 1 for o in c] s = sum(k) ok = k.count(0) i1 = 0 i2 = 0 while i2 < n and ok < m: p[c[i2]] += 1 if p[c[i2]] == k[c[i2]]: ok += 1 i2 += 1 if ok != m: print(-1) exit(0) a...
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
1
256
Lightsabers (medium)
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th...
The first line of the input contains n (1 ≤ n ≤ 2·105) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with $$1 \leq \sum_{i=1}^{m} k_i \leq n$$) – the desired co...
Output one number: the minimum number of Jedi Knights that need to be removed from the sequence so that, in what remains, there is an interval with the prescribed counts of lightsaber colors. If this is not possible, output - 1.
null
null
[{"input": "8 3\n3 3 1 2 2 1 1 3\n3 1 1", "output": "1"}]
1,800
["binary search", "two pointers"]
59
[{"input": "8 3\r\n3 3 1 2 2 1 1 3\r\n3 1 1\r\n", "output": "1\r\n"}, {"input": "6 5\r\n1 2 4 2 4 3\r\n0 0 1 0 0\r\n", "output": "0\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\...
false
stdio
null
true
498/A
498
A
Python 3
TESTS
39
109
0
41005023
x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) n = int(input()) d = [[int(i) for i in input().split()] for j in range(n)] count = 0 if x1 != x2: k = (y2 - y1) / (x2 - x1) b = (y1 * x2 - y2 * x1) / (x2 - x1) for i in range(n): if d[i][0] != d[i][1] * k: x3 = -1 * (d...
51
61
0
11565468
x1,y1 = map(int,input().split()) x2,y2 = map(int,input().split()) n = int(input()) s = 0 for i in range(n): a,b,c = map(int,input().split()) if ((((a * x1) + (b * y1) + c) * ((a * x2) + (b * y2) + c)) < 0): s = s + 1 print(s)
Codeforces Round 284 (Div. 1)
CF
2,014
1
256
Crazy Town
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po...
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home. The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at. The third line contains an integer n (1 ≤ n ≤ 300) — th...
Output the answer to the problem.
null
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
[{"input": "1 1\n-1 -1\n2\n0 1 0\n1 0 0", "output": "2"}, {"input": "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3", "output": "2"}]
1,700
["geometry"]
51
[{"input": "1 1\r\n-1 -1\r\n2\r\n0 1 0\r\n1 0 0\r\n", "output": "2\r\n"}, {"input": "1 1\r\n-1 -1\r\n3\r\n1 0 0\r\n0 1 0\r\n1 1 -3\r\n", "output": "2\r\n"}, {"input": "841746 527518\r\n595261 331297\r\n10\r\n-946901 129987 670374\r\n-140388 -684770 309555\r\n-302589 415564 -387435\r\n-565799 -72069 -395358\r\n-523453 -...
false
stdio
null
true
498/A
498
A
PyPy 3
TESTS
32
233
2,457,600
56372553
import math import sys,string,bisect input=sys.stdin.readline from collections import deque,defaultdict L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) def line(l,p): d=(l[0]*p[0]+l[1]*p[1]+l[2]) if(d>0): return 1 ...
51
62
0
9246953
#import sys #sys.stdin = open('input.txt', 'r') #sys.stdout = open('output.txt', 'w') def norm(a, b, c, d): if (b * c >= 0): return a * abs(c) <= abs(b) <= d * abs(c) return -a * abs(c) >= abs(b) >= -d * abs(c) x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) a2 = y2 - y1 b2 = x1 - x2 c2 = 0 ...
Codeforces Round 284 (Div. 1)
CF
2,014
1
256
Crazy Town
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po...
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home. The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at. The third line contains an integer n (1 ≤ n ≤ 300) — th...
Output the answer to the problem.
null
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
[{"input": "1 1\n-1 -1\n2\n0 1 0\n1 0 0", "output": "2"}, {"input": "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3", "output": "2"}]
1,700
["geometry"]
51
[{"input": "1 1\r\n-1 -1\r\n2\r\n0 1 0\r\n1 0 0\r\n", "output": "2\r\n"}, {"input": "1 1\r\n-1 -1\r\n3\r\n1 0 0\r\n0 1 0\r\n1 1 -3\r\n", "output": "2\r\n"}, {"input": "841746 527518\r\n595261 331297\r\n10\r\n-946901 129987 670374\r\n-140388 -684770 309555\r\n-302589 415564 -387435\r\n-565799 -72069 -395358\r\n-523453 -...
false
stdio
null
true
864/D
864
D
PyPy 3-64
TESTS
7
171
27,750,400
229504476
import sys from collections import Counter # region fastio input = lambda: sys.stdin.readline().rstrip() sint = lambda: int(input()) mint = lambda: map(int, input().split()) ints = lambda: list(map(int, input().split())) # endregion fastio # MOD = 998_244_353 # MOD = 10 ** 9 + 7 # DIR4 = ((-1, 0), (0, 1), (1, 0), (0,...
46
202
27,136,000
230450289
n, a = int(input()), [0] + [int(x) for x in input().split()] c = [0] * (n + 2) s = set() for x in a : s.add(x) c[x] += 1 f = [] for i in range(1, n + 1) : if not i in s : f.append(i) f = f[::-1] s = set() ans = 0 def work(i : int) -> None : global a, c, f, ans c[a[i]] -= 1 c[f[-1]] +...
Codeforces Round 436 (Div. 2)
CF
2,017
2
256
Make a Permutation!
Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n. Recently Ivan learned about permutations and their lexicographical order. Now he wants to change (replace) minimum number of elements in his array in such a way that his array becomes a permutation (i.e. each of the integers fr...
The first line contains an single integer n (2 ≤ n ≤ 200 000) — the number of elements in Ivan's array. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ n) — the description of Ivan's array.
In the first line print q — the minimum number of elements that need to be changed in Ivan's array in order to make his array a permutation. In the second line, print the lexicographically minimal permutation which can be obtained from array with q changes.
null
In the first example Ivan needs to replace number three in position 1 with number one, and number two in position 3 with number four. Then he will get a permutation [1, 2, 4, 3] with only two changed numbers — this permutation is lexicographically minimal among all suitable. In the second example Ivan does not need to...
[{"input": "4\n3 2 2 3", "output": "2\n1 2 4 3"}, {"input": "6\n4 5 6 3 2 1", "output": "0\n4 5 6 3 2 1"}, {"input": "10\n6 8 4 6 7 1 6 3 4 5", "output": "3\n2 8 4 6 7 1 9 3 10 5"}]
1,500
["greedy", "implementation", "math"]
70
[{"input": "4\r\n3 2 2 3\r\n", "output": "2\r\n1 2 4 3 \r\n"}, {"input": "6\r\n4 5 6 3 2 1\r\n", "output": "0\r\n4 5 6 3 2 1 \r\n"}, {"input": "10\r\n6 8 4 6 7 1 6 3 4 5\r\n", "output": "3\r\n2 8 4 6 7 1 9 3 10 5 \r\n"}, {"input": "6\r\n5 5 5 6 4 6\r\n", "output": "3\r\n1 2 5 3 4 6 \r\n"}, {"input": "50\r\n1 1 1 1 1 1 ...
false
stdio
null
true
532/E
533
E
Python 3
TESTS
18
46
102,400
182326342
from collections import Counter length = int(input()) string1 = input() string2 = input() count1 = Counter(string1) count2 = Counter(string2) mismatch1 = 0 letter1 = None for char in count1: if count1[char] > count2[char]: mismatch1 += 1 letter1 = char mismatch2 = 0 letter2 = None for char in c...
89
124
716,800
58257158
from sys import stdin read = stdin.readline n = int(read()) S = read() T = read() for i in range(n): if S[i] != T[i]: break a = b = 1 for j in range(i,n-1): if S[j] != T[j+1]: a = (S[j+1:] == T[j+1:]) break for j in range(i,n-1): if S[j+1] != T[j]: b = (S[j+1:] == T[j+1:...
VK Cup 2015 - Round 2
CF
2,015
2
256
Correcting Mistakes
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether t...
The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words.
Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo.
null
In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either wo...
[{"input": "7\nreading\ntrading", "output": "1"}, {"input": "5\nsweet\nsheep", "output": "0"}, {"input": "3\ntoy\ntry", "output": "2"}]
1,800
[]
89
[{"input": "7\r\nreading\r\ntrading\r\n", "output": "1\n"}, {"input": "5\r\nsweet\r\nsheep\r\n", "output": "0\n"}, {"input": "3\r\ntoy\r\ntry\r\n", "output": "2\n"}, {"input": "5\r\nspare\r\nspars\r\n", "output": "2\n"}, {"input": "1\r\na\r\nb\r\n", "output": "2\n"}, {"input": "1\r\nz\r\ny\r\n", "output": "2\n"}, {"inp...
false
stdio
null
true
886/D
886
D
Python 3
PRETESTS
1
62
0
32267462
n=int(input()) a=[] for i in range(n): a.append(input()) for j in range(len(a)-1): if a[-1] in a[j]: a[-1:]=[] break if a[j] in a[-1]: a[j:j+1]=[] break for i in range(len(a)): k=a[i][-1] l=1 for j in range(len(a)): if k in a[j...
47
62
0
32269200
def cm(s1,s2): for i in range(1, len(s1)): if s1[:i] == s2[-i:] : s = s2 + s1[i:] if len(s) == len(set(list(s))): return s if s2[:i] == s1[-i:]: s = s1 + s2[i:] if len(s) == len(set(list(s))): return s return None n...
Технокубок 2018 - Отборочный Раунд 3
CF
2,017
2
256
Restoration of string
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
The first line contains integer n (1 ≤ n ≤ 105) — the number of strings in the set. Each of the next n lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct. The total length of the strings doesn't exceed 105.
Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings.
null
One can show that in the first sample only two good strings with minimum length exist: "cfmailru" and "mailrucf". The first string is lexicographically minimum.
[{"input": "4\nmail\nai\nlru\ncf", "output": "cfmailru"}, {"input": "3\nkek\npreceq\ncheburek", "output": "NO"}]
2,000
["constructive algorithms", "graphs", "implementation"]
47
[{"input": "4\r\nmail\r\nai\r\nlru\r\ncf\r\n", "output": "cfmailru\r\n"}, {"input": "3\r\nkek\r\npreceq\r\ncheburek\r\n", "output": "NO\r\n"}, {"input": "1\r\nz\r\n", "output": "z\r\n"}, {"input": "2\r\nab\r\nba\r\n", "output": "NO\r\n"}, {"input": "2\r\nac\r\nbc\r\n", "output": "NO\r\n"}, {"input": "2\r\ncd\r\nce\r\n"...
false
stdio
null
true
396/A
396
A
Python 3
TESTS
6
966
1,638,400
53681977
def SieveOfEratosthenes(n): prime = [True for i in range(n + 1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n + 1, p): prime[i] = False p += 1 l = [] for p in range(2, n): if prime[p]: l.append(p) retu...
85
436
614,400
5963253
from collections import defaultdict m = 1000000007 f = [0] * 15001 f[0] = 1 for i in range(1, 15001): f[i] = (f[i - 1] * i) % m def c(n, k): return (f[n] * pow((f[k] * f[n - k]) % m, m - 2, m)) % m def prime(n): m = int(n ** 0.5) + 1 t = [1] * (n + 1) for i in range(3, m): if t[i]: t[i * i :: 2 * ...
Codeforces Round 232 (Div. 1)
CF
2,014
1
256
On Number of Decompositions into Multipliers
You are given an integer m as a product of integers a1, a2, ... an $$(m=\prod_{i=1}^{n}a_{i})$$. Your task is to find the number of distinct decompositions of number m into the product of n ordered positive integers. Decomposition into n products, given in the input, must also be considered in the answer. As the answe...
The first line contains positive integer n (1 ≤ n ≤ 500). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
In a single line print a single number k — the number of distinct decompositions of number m into n ordered multipliers modulo 1000000007 (109 + 7).
null
In the second sample, the get a decomposition of number 2, you need any one number out of three to equal 2, and the rest to equal 1. In the third sample, the possible ways of decomposing into ordered multipliers are [7,5], [5,7], [1,35], [35,1]. A decomposition of positive integer m into n ordered multipliers is a co...
[{"input": "1\n15", "output": "1"}, {"input": "3\n1 1 2", "output": "3"}, {"input": "2\n5 7", "output": "4"}]
null
["combinatorics", "math", "number theory"]
85
[{"input": "1\r\n15\r\n", "output": "1\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "3\r\n"}, {"input": "2\r\n5 7\r\n", "output": "4\r\n"}, {"input": "2\r\n5 10\r\n", "output": "6\r\n"}, {"input": "3\r\n1 30 1\r\n", "output": "27\r\n"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "361\r\n"}, {"input": "1\r\n1...
false
stdio
null
true
213/A
213
A
PyPy 3-64
TESTS
5
92
0
182204448
# https://codeforces.com/problemset/problem/213/A def cost(u, v): if u == v: return 0 if v - 1 == u % 3: return 1 return 2 def solve(n, c, v_out, deg): total = 0 remain = n current_part = None while remain: playable = [] for i in range(n): if de...
74
184
1,024,000
22020168
from collections import * read_line = lambda: [int(i) for i in input().split(' ')] n = read_line()[0] cs = [c - 1 for c in read_line()] g = [[] for v in range(n)] parent_cnt = [0] * n for v in range(n): parents = read_line() parent_cnt[v] = len(parents) - 1 for i in range(1, len(parents)): ...
Codeforces Round 131 (Div. 1)
CF
2,012
1
256
Game
Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies....
The first line contains integer n (1 ≤ n ≤ 200) — the number of game parts. The next line contains n integers, the i-th integer — ci (1 ≤ ci ≤ 3) represents the number of the computer, on which you can complete the game part number i. Next n lines contain descriptions of game parts. The i-th line first contains intege...
On a single line print the answer to the problem.
null
Note to the second sample: before the beginning of the game the best strategy is to stand by the third computer. First we complete part 5. Then we go to the 1-st computer and complete parts 3 and 4. Then we go to the 2-nd computer and complete parts 1 and 2. In total we get 1+1+2+1+2, which equals 7 hours.
[{"input": "1\n1\n0", "output": "1"}, {"input": "5\n2 2 1 1 3\n1 5\n2 5 1\n2 5 4\n1 5\n0", "output": "7"}]
1,700
["dfs and similar", "greedy"]
74
[{"input": "1\r\n1\r\n0\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1 3\r\n1 5\r\n2 5 1\r\n2 5 4\r\n1 5\r\n0\r\n", "output": "7\r\n"}, {"input": "7\r\n1 3 3 1 2 1 1\r\n0\r\n1 1\r\n1 1\r\n2 1 6\r\n3 1 2 7\r\n1 1\r\n1 1\r\n", "output": "11\r\n"}, {"input": "2\r\n2 1\r\n0\r\n1 1\r\n", "output": "4\r\n"}, {"input": "3\...
false
stdio
null
true
691/A
691
A
Python 3
TESTS
13
77
0
118912113
n=int(input()) l=list(map(int,input().split())) if n==1 and sum(l)==1: print("YES") elif ( sum(l)==n-1 ) : print("YES") else: print("NO")
83
46
0
158316369
def checkJacket(v, n): if n == 1: if v[0] == 1: return True else: return False count = 0 for i in range(n): if v[i] == 0: count += 1 if count == 1: return True else: return False n = int(input()) v = list(map(int, input(...
Educational Codeforces Round 14
ICPC
2,016
1
256
Fashion in Berland
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with n buttons. Determine if it is fasten...
The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket. The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1.
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
null
null
[{"input": "3\n1 0 1", "output": "YES"}, {"input": "3\n1 0 0", "output": "NO"}]
1,000
["implementation"]
83
[{"input": "3\r\n1 0 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r...
false
stdio
null
true
883/K
883
K
PyPy 3
TESTS
0
514
11,366,400
97723392
from random import choice, randint from string import ascii_uppercase, ascii_letters, digits, ascii_lowercase from sys import stdin, stdout from random import choice from functools import reduce import time from math import * from itertools import combinations from decimal import * '''s = set(list(input())) subs = [se...
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
691/A
691
A
Python 3
TESTS
13
77
0
20326802
n=int(input()) l=sum(map(int,input().split())) if n==1 or n==l+1: print("YES") else: print("NO")
83
46
0
159177028
def fashion_in_berland(n, buttons): count = 0 if n == 1: if buttons[0] == 1: return "YES" else: return "NO" else: for i in range(len(buttons)): if buttons[i] == 0: count += 1 if count == 1: return "YES" retur...
Educational Codeforces Round 14
ICPC
2,016
1
256
Fashion in Berland
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with n buttons. Determine if it is fasten...
The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket. The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1.
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
null
null
[{"input": "3\n1 0 1", "output": "YES"}, {"input": "3\n1 0 0", "output": "NO"}]
1,000
["implementation"]
83
[{"input": "3\r\n1 0 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r...
false
stdio
null
true
1004/A
1004
A
Python 3
TESTS
9
155
102,400
39996473
from collections import defaultdict def solve(): total = 0 if n == 1: return 2 if n == 2: if abs(coords[0] - coords[1]) >= 2*d: return 3 else: return 2 for i in range(n): if i == 0: # check only in front and add one behind by default total += 1 if abs(coords[i] - coords[i+1]) >= 2*d: t...
45
46
0
136128478
n,d=[int(x) for x in input().split()] a=[int(x) for x in input().split()] if n==1: print(2) elif n==2: if a[1]-a[0]<2*d: print(2) elif a[1]-a[0]==2*d: print(3) else: print(4) else: res=2 for i in range(1,n): if a[i]-a[i-1]==2*d: res+=1 elif a[i]-a[i-1]>2*d: res+=2 print(r...
Codeforces Round 495 (Div. 2)
CF
2,018
1
256
Sonya and Hotels
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $$$n$$$ hotels, where the $$$i$$$-th hotel is located in the city with...
The first line contains two integers $$$n$$$ and $$$d$$$ ($$$1\leq n\leq 100$$$, $$$1\leq d\leq 10^9$$$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $$$n$$$ different integers in strictly increasing order $$$x_1, x_2, \ldots, x_n$$$ ($$$-10^9\...
Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $$$d$$$.
null
In the first example, there are $$$6$$$ possible cities where Sonya can build a hotel. These cities have coordinates $$$-6$$$, $$$5$$$, $$$6$$$, $$$12$$$, $$$13$$$, and $$$19$$$. In the second example, there are $$$5$$$ possible cities where Sonya can build a hotel. These cities have coordinates $$$2$$$, $$$6$$$, $$$1...
[{"input": "4 3\n-3 2 9 16", "output": "6"}, {"input": "5 2\n4 8 11 18 19", "output": "5"}]
900
["implementation"]
45
[{"input": "4 3\r\n-3 2 9 16\r\n", "output": "6\r\n"}, {"input": "5 2\r\n4 8 11 18 19\r\n", "output": "5\r\n"}, {"input": "10 10\r\n-67 -59 -49 -38 -8 20 41 59 74 83\r\n", "output": "8\r\n"}, {"input": "10 10\r\n0 20 48 58 81 95 111 137 147 159\r\n", "output": "9\r\n"}, {"input": "100 1\r\n0 1 2 3 4 5 7 8 10 11 12 13 1...
false
stdio
null
true
534/D
534
D
PyPy 3
TESTS
7
124
0
90452205
n = int(input()) a = list(map(int, input().split())) dic = [0]*n for i, item in enumerate(a, start=1): if not dic[item]: dic[item] = [] dic[item].append(i) if not dic[0]: print("Impossible") exit() route = [dic[0][-1]] stack = [(dic, 0, route)] while stack: dic, current, route = stack.pop...
85
296
51,609,600
229677329
import sys maxn = 200500 v = [[] for _ in range(maxn)] answer = [] n = int(input()) data = list(map(int, input().split())) for i in range(n): x = data[i] v[x].append(i + 1) it = n cur = 0 while it > 0: while cur >= 0 and not v[cur]: cur -= 3 if cur < 0: print("Impossible") sys.ex...
Codeforces Round 298 (Div. 2)
CF
2,015
1
256
Handshakes
On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came in...
The first line contains integer n (1 ≤ n ≤ 2·105) — the number of students who came to CTOP. The next line contains n integers a1, a2, ..., an (0 ≤ ai < n), where ai is the number of students with who the i-th student shook hands.
If the sought order of students exists, print in the first line "Possible" and in the second line print the permutation of the students' numbers defining the order in which the students entered the center. Number i that stands to the left of number j in this permutation means that the i-th student came earlier than the...
null
In the first sample from the statement the order of events could be as follows: - student 4 comes in (a4 = 0), he has no one to greet; - student 5 comes in (a5 = 1), he shakes hands with student 4; - student 1 comes in (a1 = 2), he shakes hands with two students (students 4, 5); - student 3 comes in (a3 = 3), he shake...
[{"input": "5\n2 1 3 0 1", "output": "Possible\n4 5 1 3 2"}, {"input": "9\n0 2 3 4 1 1 0 2 2", "output": "Possible\n7 5 2 1 6 8 3 4 9"}, {"input": "4\n0 2 1 1", "output": "Impossible"}]
1,900
["binary search", "constructive algorithms", "data structures", "greedy"]
85
[{"input": "5\r\n2 1 3 0 1\r\n", "output": "Possible\r\n4 5 1 3 2 "}, {"input": "9\r\n0 2 3 4 1 1 0 2 2\r\n", "output": "Possible\r\n7 6 9 3 4 8 1 5 2 "}, {"input": "4\r\n0 2 1 1\r\n", "output": "Impossible\r\n"}, {"input": "5\r\n1 0 2 1 0\r\n", "output": "Possible\r\n5 4 3 2 1 "}, {"input": "1\r\n0\r\n", "output": "Po...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) a_dict = {i+1: a[i] for i in range(n)} # Read submission output with open(submission_path) as f: lines = [l...
true
441/B
441
B
Python 3
TESTS
33
77
7,168,000
123051963
n, v = map(int, input().split()) d = {} for i in range(n): a,b = map(int, input().split()) if a in d : d[a] += b else : d[a] = b m = min(d.keys()) c = 0 for i in range(m, m+n+1): quota = v if i-1 in d : if quota>d[i-1]: c += d[i-1] quota -= d[i-1] ...
51
46
409,600
208252411
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) ############ ---- Input Func...
Codeforces Round 252 (Div. 2)
CF
2,014
1
256
Valera and Fruits
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,...
The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 30...
Print a single integer — the maximum number of fruit that Valera can collect.
null
In the first sample, in order to obtain the optimal answer, you should act as follows. - On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree. In the second sampl...
[{"input": "2 3\n1 5\n2 3", "output": "8"}, {"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60"}]
1,400
["greedy", "implementation"]
51
[{"input": "2 3\r\n1 5\r\n2 3\r\n", "output": "8\r\n"}, {"input": "5 10\r\n3 20\r\n2 20\r\n1 20\r\n4 20\r\n5 20\r\n", "output": "60\r\n"}, {"input": "10 3000\r\n1 2522\r\n4 445\r\n8 1629\r\n5 772\r\n9 2497\r\n6 81\r\n3 426\r\n7 1447\r\n2 575\r\n10 202\r\n", "output": "10596\r\n"}, {"input": "5 3000\r\n5 772\r\n1 2522\r...
false
stdio
null
true
701/C
701
C
PyPy 3-64
TESTS
73
93
6,758,400
222987696
n = int(input()) s = [i for i in input()] cnt = len(set(s)) l = r = 0 d = {} mn = 10 ** 20 if len(s) == cnt: print(cnt) else: for r in range(n): d[s[r]] = r while len(d) == cnt: if d[s[l]] != l: l += 1 mn = min(mn, r + 1 - l) else: ...
80
93
3,072,000
217181644
n = int(input()) s = input() unique = set() for char in s: unique.add(char) ele = len(unique) seen = {} l = 0 r = 0 ans = n f1 = False f2 = False while r < n: while r < n and len(seen) < ele: f1 = True seen[s[r]] = seen.setdefault(s[r],0) + 1 r+=1 if len(seen) == el...
Codeforces Round 364 (Div. 2)
CF
2,016
2
256
They Are Everywhere
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of flats in the house. The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
null
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2. In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6. In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
[{"input": "3\nAaA", "output": "2"}, {"input": "7\nbcAAcbc", "output": "3"}, {"input": "6\naaBCCe", "output": "5"}]
1,500
["binary search", "strings", "two pointers"]
80
[{"input": "3\r\nAaA\r\n", "output": "2\r\n"}, {"input": "7\r\nbcAAcbc\r\n", "output": "3\r\n"}, {"input": "6\r\naaBCCe\r\n", "output": "5\r\n"}, {"input": "1\r\nA\r\n", "output": "1\r\n"}, {"input": "1\r\ng\r\n", "output": "1\r\n"}, {"input": "52\r\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n", "output": ...
false
stdio
null
true
786/A
786
A
PyPy 3-64
TESTS
48
1,887
43,520,000
157510341
import sys from array import array from collections import deque def get(x): if x == 0: return 'Lose' elif x == 1: return 'Win' else: return 'Loop' input = lambda: sys.stdin.buffer.readline().decode().strip() n = int(input()) a = [array('i', [int(x) for x in input().split()]) fo...
49
733
4,300,800
53973991
import sys #range = xrange #input = raw_input n = int(input()) k1,*A = [int(x) for x in input().split()] k2,*B = [int(x) for x in input().split()] DPA = [None]*n DPA[0] = False counterA = [k1]*n counterA[0] = -1 DPB = [None]*n DPB[0] = False counterB = [k2]*n counterB[0] = -1 QA = [0] QB = [0] while QA or QB: ...
Codeforces Round 406 (Div. 1)
CF
2,017
4
256
Berzerk
Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer. In this game there are n objects numbered from 1 to n arranged in a circle (in clockwise order). Object number 1 is a black hole and the oth...
The first line of input contains a single integer n (2 ≤ n ≤ 7000) — number of objects in game. The second line contains integer k1 followed by k1 distinct integers s1, 1, s1, 2, ..., s1, k1 — Rick's set. The third line contains integer k2 followed by k2 distinct integers s2, 1, s2, 2, ..., s2, k2 — Morty's set 1 ≤ ...
In the first line print n - 1 words separated by spaces where i-th word is "Win" (without quotations) if in the scenario that Rick plays first and monster is initially in object number i + 1 he wins, "Lose" if he loses and "Loop" if the game will never end. Similarly, in the second line print n - 1 words separated by ...
null
null
[{"input": "5\n2 3 2\n3 1 2 3", "output": "Lose Win Win Loop\nLoop Win Win Win"}, {"input": "8\n4 6 2 3 4\n2 3 6", "output": "Win Win Win Win Win Win Win\nLose Win Lose Lose Win Lose Lose"}]
2,000
["dfs and similar", "dp", "games"]
49
[{"input": "5\r\n2 3 2\r\n3 1 2 3\r\n", "output": "Lose Win Win Loop\r\nLoop Win Win Win\r\n"}, {"input": "8\r\n4 6 2 3 4\r\n2 3 6\r\n", "output": "Win Win Win Win Win Win Win\r\nLose Win Lose Lose Win Lose Lose\r\n"}, {"input": "10\r\n3 4 7 5\r\n2 8 5\r\n", "output": "Win Win Win Win Win Win Win Loop Win\r\nLose Win L...
false
stdio
null
true
463/A
463
A
Python 3
TESTS
5
31
0
150964082
n,s = map(int,input().split(" ")) ans = [] value_box = [] for i in range(n): x,y = map(int,input().split(" ")) ans.append((x,y)) ans = dict(ans) x_box = list(ans.keys()) s = s*100 for j in range(len(x_box)): value_box.append(x_box[j]*100+ans[x_box[j]]) amount = -1 for i in value_box: if s >= i: ...
35
46
0
183159192
''' Caisa и сахар 1200''' #n = int(input()) ch = input() ch = ch.split() ch = [int(x) for x in ch] n, s = ch s = s * 100 mx = 0 f = False for i in range(n): x = input() x = x.split() c = eval(x[0] + '* 100 +'+x[1]);# print(c) if s >= c: sda4a = (s - c) % 100 # ; print(sda4a) f = True ...
Codeforces Round 264 (Div. 2)
CF
2,014
1
256
Caisa and Sugar
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town. Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But t...
The first line contains two space-separated integers n, s (1 ≤ n, s ≤ 100). The i-th of the next n lines contains two integers xi, yi (1 ≤ xi ≤ 100; 0 ≤ yi < 100), where xi represents the number of dollars and yi the number of cents needed in order to buy the i-th type of sugar.
Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.
null
In the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change.
[{"input": "5 10\n3 90\n12 0\n9 70\n5 50\n7 0", "output": "50"}, {"input": "5 5\n10 10\n20 20\n30 30\n40 40\n50 50", "output": "-1"}]
1,200
["brute force", "implementation"]
35
[{"input": "5 10\r\n3 90\r\n12 0\r\n9 70\r\n5 50\r\n7 0\r\n", "output": "50\r\n"}, {"input": "5 5\r\n10 10\r\n20 20\r\n30 30\r\n40 40\r\n50 50\r\n", "output": "-1\r\n"}, {"input": "1 2\r\n1 0\r\n", "output": "0\r\n"}, {"input": "2 10\r\n20 99\r\n30 99\r\n", "output": "-1\r\n"}, {"input": "15 21\r\n16 51\r\n33 44\r\n32 ...
false
stdio
null
true
662/D
662
D
Python 3
TESTS
3
46
4,812,800
17362173
def main(): l = [input()[4:] for _ in range(int(input()))] for i, s in enumerate(l): le = len(s) if le == 1: s = ("199", "198")[s == "9"] + s elif le == 2: s = "1999" if s == "99" else "20" + s elif le == 3: s = "2" + s else: ...
45
62
0
17348457
n = int(input()) for _ in range(n): s = input().rstrip() k = len(s) - 4 r = int(s[4:]) ans = None if k == 1: if r == 9: ans = 1989 else: ans = 1990 + r elif k == 2: if r == 99: ans = 1999 else: ans = 2000 + r elif k == 3: if r <= 98: ans = 3000 + r...
CROC 2016 - Final Round [Private, For Onsite Finalists Only]
CF
2,016
1
256
International Olympiad
International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Amo...
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits.
For each abbreviation given in the input, find the year of the corresponding Olympiad.
null
null
[{"input": "5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0", "output": "2015\n12015\n1991\n1989\n1990"}, {"input": "4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999", "output": "1989\n1999\n2999\n9999"}]
2,000
["constructive algorithms", "greedy", "implementation", "math"]
45
[{"input": "5\r\nIAO'15\r\nIAO'2015\r\nIAO'1\r\nIAO'9\r\nIAO'0\r\n", "output": "2015\r\n12015\r\n1991\r\n1989\r\n1990\r\n"}, {"input": "4\r\nIAO'9\r\nIAO'99\r\nIAO'999\r\nIAO'9999\r\n", "output": "1989\r\n1999\r\n2999\r\n9999\r\n"}, {"input": "1\r\nIAO'111110\r\n", "output": "1111110\r\n"}, {"input": "2\r\nIAO'0\r\nIAO...
false
stdio
null
true
812/E
812
E
PyPy 3
TESTS
9
186
38,195,200
129045048
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n = int(input()) A = list(map(int, input().split())) P = list(map(int, input().split())) P = [p-1 for p in P] P = [-1]+P ch = [[] for i in range(n)] for i, p in enumerate(P): if p != -1: ch[p].append(i) s = [] order = [] ...
76
217
9,830,400
181716370
""" Prositka 20.11.2022""" n= int(input()) a = [int(_) for _ in input().split()] c = [int(_) for _ in input().split()] depth = [0] * (n) for i in range(1,n): depth[i] = depth[c[i-1]-1] + 1 MAX = max(depth) t = 0 store = {} todo = [] p = 0 for i in range(n): if (MAX-depth[i]) % 2 == 0: # odd, useful t ^= ...
Codeforces Round 417 (Div. 2)
CF
2,017
2
256
Sagheer and Apple Tree
Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has ai apples. This tree has a special property: the lengths of all paths from the root to any leaf have the same parity (i.e. all paths have even length or all paths have odd ...
The first line will contain one integer n (2 ≤ n ≤ 105) — the number of nodes in the apple tree. The second line will contain n integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the number of apples on each node of the tree. The third line will contain n - 1 integers p2, p3, ..., pn (1 ≤ pi ≤ n) — the parent of each node of ...
On a single line, print the number of different pairs of nodes (u, v), u ≠ v such that if they start playing after swapping the apples of both nodes, Sagheer will win the game. (u, v) and (v, u) are considered to be the same pair.
null
In the first sample, Sagheer can only win if he swapped node 1 with node 3. In this case, both leaves will have 2 apples. If Soliman makes a move in a leaf node, Sagheer can make the same move in the other leaf. If Soliman moved some apples from a root to a leaf, Sagheer will eat those moved apples. Eventually, Soliman...
[{"input": "3\n2 2 3\n1 1", "output": "1"}, {"input": "3\n1 2 3\n1 1", "output": "0"}, {"input": "8\n7 2 2 5 4 3 1 1\n1 1 1 4 4 5 6", "output": "4"}]
2,300
["games", "trees"]
76
[{"input": "3\r\n2 2 3\r\n1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 3\r\n1 1\r\n", "output": "0\r\n"}, {"input": "8\r\n7 2 2 5 4 3 1 1\r\n1 1 1 4 4 5 6\r\n", "output": "4\r\n"}, {"input": "6\r\n7 7 7 7 7 7\r\n1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n3 1 1 1 2 2\r\n1 1 1 1 1\r\n", "output": "2\r\n"}, ...
false
stdio
null
true
750/C
750
C
PyPy 3-64
TESTS
6
46
0
200605465
n=int(input()) arr=[] p=0 for _ in range(n): c,d=map(int,input().split()) arr.append((c,d)) if d==1: p+=1 if p==n: print("Infinity") else: ans=0 div=[[],[]] for a,b in arr: div[b-1].append(ans) ans+=a if div[0] and div[-1] and min(div[0])<=max(div[-1]): ...
81
140
6,144,000
208005614
import sys input = lambda: sys.stdin.readline().rstrip() from collections import defaultdict from heapq import * INF = float('inf') l,r=-INF,INF for _ in range(int(input())): c,d = map(int, input().split()) if d==1: l = max(l,1900) else: r = min(r,1899) if l>r: exit(print('...
Good Bye 2016
CF
2,016
2
256
New Year and Rating
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating ch...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers ci and di ( - 100 ≤ ci ≤ 100, 1 ≤ di ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
null
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: - Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. - With rating 1894 Limak is in the division 2. His rating increases by 5. - Limak has rating ...
[{"input": "3\n-7 1\n5 2\n8 2", "output": "1907"}, {"input": "2\n57 1\n22 2", "output": "Impossible"}, {"input": "1\n-5 1", "output": "Infinity"}, {"input": "4\n27 2\n13 1\n-50 1\n8 2", "output": "1897"}]
1,600
["binary search", "greedy", "math"]
81
[{"input": "3\r\n-7 1\r\n5 2\r\n8 2\r\n", "output": "1907\r\n"}, {"input": "2\r\n57 1\r\n22 2\r\n", "output": "Impossible\r\n"}, {"input": "1\r\n-5 1\r\n", "output": "Infinity\r\n"}, {"input": "4\r\n27 2\r\n13 1\r\n-50 1\r\n8 2\r\n", "output": "1897\r\n"}, {"input": "6\r\n8 1\r\n-22 1\r\n9 2\r\n-7 2\r\n85 2\r\n77 1\r\n...
false
stdio
null
true
81/B
81
B
Python 3
TESTS
1
62
0
31932815
ans = input() while " ," in ans: ans = ans.replace(" ,", ",") ans = ans.replace("...", " ...").replace(",", ", ") for ps, pv in [(" ", " "), ("... ", "...")]: while ps in ans: ans = ans.replace(ps, pv) print(ans.strip(), end="")
45
154
307,200
104115690
# вводим строку s s, i, v = input() + ' ', 0, ' ' # перебираем строку while i < len(s): # если в строке запятая, поставить пробел после нее if s[i] == ',': v += ', ' # если в строке точки, заменить их на многоточия и пробел перед ними elif s[i] == '.': v += ('' if v[-1] == ' ' else ' ')...
Yandex.Algorithm Open 2011: Qualification 1
CF
2,011
2
256
Sequence Formatting
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,...,   10" will be corrected ...
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
null
null
[{"input": "1,2 ,3,..., 10", "output": "1, 2, 3, ..., 10"}, {"input": "1,,,4...5......6", "output": "1, , , 4 ...5 ... ...6"}, {"input": "...,1,2,3,...", "output": "..., 1, 2, 3, ..."}]
1,700
["implementation", "strings"]
45
[{"input": "1,2 ,3,..., 10\r\n", "output": "1, 2, 3, ..., 10\r\n"}, {"input": "1,,,4...5......6\r\n", "output": "1, , , 4 ...5 ... ...6\r\n"}, {"input": "...,1,2,3,...\r\n", "output": "..., 1, 2, 3, ...\r\n"}, {"input": "......\r\n", "output": "... ...\r\n"}, {"input": ",,,,,,,,,,,,,\r\n", "output": ", , , , , , , ...
false
stdio
null
true
888/C
888
C
Python 3
TESTS
18
202
9,216,000
84939440
s=input() se=set(s) if len(se)==len(s): print((len(s)//2)+1) elif len(se)==1: print(1) else: dif={} d={} for index,i in enumerate(s): if d.get(i,[])!=[]: if len(d[i])>=2: dif[i]=max(index-d[i][-1],dif[i]) else: dif[i] =index - d[i][-1] ...
51
77
7,065,600
174013291
import sys from collections import defaultdict input = sys.stdin.readline def main(): word = [ *input().strip() ] n = len(word) letters_map = defaultdict(list) for i in range(27): letters_map[i] = [-1, -1] for index, letter in enumerate(word): letter_key = ord(letter) - 97 ...
Educational Codeforces Round 32
ICPC
2,017
2
256
K-Dominant Character
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character.
The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).
Print one number — the minimum value of k such that there exists at least one k-dominant character.
null
null
[{"input": "abacaba", "output": "2"}, {"input": "zzzzz", "output": "1"}, {"input": "abcde", "output": "3"}]
1,400
["binary search", "implementation", "two pointers"]
51
[{"input": "abacaba\r\n", "output": "2\r\n"}, {"input": "zzzzz\r\n", "output": "1\r\n"}, {"input": "abcde\r\n", "output": "3\r\n"}, {"input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab\r\n", "output": "8\r\n"}, {"input": "daabcdabbabbacacbaacabacbcaabaacac\r\n", "o...
false
stdio
null
true
463/A
463
A
PyPy 3
TESTS
5
124
0
96757640
from sys import stdin,stdout mp=lambda:map(int,stdin.readline().split()) n,s=mp() d={} for _ in range(n): x,y=mp() if x <= s: d[x]=y if not len(d): print(-1) else: m=100;f=0 for k in d: if d[k] and k<s: m=min(d[k],m) if k<s or (d[k]==0 and k==s): f=...
35
46
0
206794849
def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) n,s = invr() total = -1 for i in range(n): x,y = invr() if x*100 + y <= s*100: total = max(total,((x+1...
Codeforces Round 264 (Div. 2)
CF
2,014
1
256
Caisa and Sugar
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town. Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But t...
The first line contains two space-separated integers n, s (1 ≤ n, s ≤ 100). The i-th of the next n lines contains two integers xi, yi (1 ≤ xi ≤ 100; 0 ≤ yi < 100), where xi represents the number of dollars and yi the number of cents needed in order to buy the i-th type of sugar.
Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.
null
In the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change.
[{"input": "5 10\n3 90\n12 0\n9 70\n5 50\n7 0", "output": "50"}, {"input": "5 5\n10 10\n20 20\n30 30\n40 40\n50 50", "output": "-1"}]
1,200
["brute force", "implementation"]
35
[{"input": "5 10\r\n3 90\r\n12 0\r\n9 70\r\n5 50\r\n7 0\r\n", "output": "50\r\n"}, {"input": "5 5\r\n10 10\r\n20 20\r\n30 30\r\n40 40\r\n50 50\r\n", "output": "-1\r\n"}, {"input": "1 2\r\n1 0\r\n", "output": "0\r\n"}, {"input": "2 10\r\n20 99\r\n30 99\r\n", "output": "-1\r\n"}, {"input": "15 21\r\n16 51\r\n33 44\r\n32 ...
false
stdio
null
true
330/B
330
B
PyPy 3
TESTS
37
372
2,969,600
92014650
n,m=[int(x) for x in input().split()] forbidden=set() for i in range(m): a,b=[int(x) for x in input().split()] forbidden.add(a) forbidden.add(b) for i in range(1,n): if i not in forbidden: print(n-1) for j in range(1,n+1): if j!=i: print(j,i) exit()
43
92
0
141920095
z=lambda :map(int,input().split());a,b=z();s=set(range(1,a+1)) for _ in " "*b:s-=set(z()) s=next(iter(s));print(a-1);[print(s,i) for i in range(1,a+1) if i!=s]
Codeforces Round 192 (Div. 2)
CF
2,013
2
256
Road Construction
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two r...
The first line consists of two integers n and m $$( 1 \leq n \leq 1 0 ^ { 3 }, 0 \leq m < \frac { n } { 2 } )$$. Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbere...
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi. If there are several solutions, you may prin...
null
This is one possible solution of the example: These are examples of wrong solutions:
[{"input": "4 1\n1 3", "output": "3\n1 2\n4 2\n2 3"}]
1,300
["constructive algorithms", "graphs"]
43
[{"input": "4 1\r\n1 3\r\n", "output": "3\r\n1 2\r\n4 2\r\n2 3\r\n"}, {"input": "1000 0\r\n", "output": "999\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] n, m, forbidden = read_input(input_path) with open(output_path, 'r') as f: s_ref = int(f.readline().strip()) with open(submission_path, 'r') as f: lines = f.readlines() ...
true
330/B
330
B
PyPy 3-64
TESTS
39
186
3,788,800
191790150
n, m = map(int, input().split()) a = [] b = [] if n == 1: print(0) else: for i in range(m): a.append(tuple(map(int, input().split()))) b.append(a[i][0]) b.append(a[i][1]) b.sort() ans = 1 for i in range(1, len(b)): if b[i] - b[i-1] > 1: ans = b[i] - 1 ...
43
92
0
153624193
import math def main_function(): n, m = [int(i) for i in input().split(" ")] collector = [[] for i in range(n + 1)] for i in range(m): a, b = [int(i) for i in input().split(" ")] collector[a].append(b) collector[b].append(a) for i in range(1, len(collector)): if len(col...
Codeforces Round 192 (Div. 2)
CF
2,013
2
256
Road Construction
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two r...
The first line consists of two integers n and m $$( 1 \leq n \leq 1 0 ^ { 3 }, 0 \leq m < \frac { n } { 2 } )$$. Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbere...
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi. If there are several solutions, you may prin...
null
This is one possible solution of the example: These are examples of wrong solutions:
[{"input": "4 1\n1 3", "output": "3\n1 2\n4 2\n2 3"}]
1,300
["constructive algorithms", "graphs"]
43
[{"input": "4 1\r\n1 3\r\n", "output": "3\r\n1 2\r\n4 2\r\n2 3\r\n"}, {"input": "1000 0\r\n", "output": "999\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] n, m, forbidden = read_input(input_path) with open(output_path, 'r') as f: s_ref = int(f.readline().strip()) with open(submission_path, 'r') as f: lines = f.readlines() ...
true
48/D
48
D
PyPy 3
TESTS
4
77
0
109283291
n=int(input()) t = list(map(int,input().split())) f=[] for j in set(t): f.append([j,t.count(j)]) f.sort() u=len(f)-1 m=f[u][1] v=f[u][0] h=0 while u: u-=1 if f[u][0]+1==v and f[u][1]>=m: m=f[u][1] v=f[u][0] else: print(-1) h+=1 break if h==0: v=[]...
60
93
17,715,200
178413503
from sys import stdin, stdout input = stdin.readline MAX_ARR = 100001 def main(): input() arr = list(map(int, input().split())) dct = [0] * MAX_ARR result = list() for i in arr: dct[i] += 1 # result = result + str(dct[i]) + " " result.append(str(dct[i])) pre = MAX_A...
School Personal Contest #3 (Winter Computer School 2010/11) - Codeforces Beta Round 45 (ACM-ICPC Rules)
ICPC
2,010
1
256
Permutations
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine that somebody took ...
The first line contains an integer n (1 ≤ n ≤ 105). The next line contains the mixed array of n integers, divided with a single space. The numbers in the array are from 1 to 105.
If this array can be split into several permutations so that every element of the array belongs to exactly one permutation, print in the first line the number of permutations. The second line should contain n numbers, corresponding to the elements of the given array. If the i-th element belongs to the first permutation...
null
In the first sample test the array is split into three permutations: (2, 1), (3, 2, 1, 4, 5), (1, 2). The first permutation is formed by the second and the fourth elements of the array, the second one — by the third, the fifth, the sixth, the seventh and the ninth elements, the third one — by the first and the eigth el...
[{"input": "9\n1 2 3 1 2 1 4 2 5", "output": "3\n3 1 2 1 2 2 2 3 2"}, {"input": "4\n4 3 2 1", "output": "1\n1 1 1 1"}, {"input": "4\n1 2 2 3", "output": "-1"}]
1,500
["greedy"]
60
[{"input": "9\r\n1 2 3 1 2 1 4 2 5\r\n", "output": "3\r\n1 1 1 2 2 3 1 3 1 "}, {"input": "4\r\n4 3 2 1\r\n", "output": "1\r\n1 1 1 1 "}, {"input": "4\r\n1 2 2 3\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n1 "}, {"input": "1\r\n2\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output":...
false
stdio
import sys from collections import defaultdict, Counter def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: lines = f.read().splitlines() n = int(lines[0]) arr = list(map(int, lines[1].split())) with open(output_...
true
609/A
609
A
Python 3
TESTS
6
93
0
48415302
n = int(input()) m = int(input()) a = [] d = 0 k = 0 for i in range(n): a.append(int(input())) a.sort(reverse = True) for i in a: if i+d != m: d += i k += 1 if d >= m: break print(k)
34
46
0
14881083
# cook your dish here n=int(input()) m=int(input()) arr=[0]*n for x in range(n) : arr[x]=int(input()) arr.sort() arr=arr[::-1] su=0 for x in range(n): su=su+arr[x] if su>=m: break print(x+1)
Educational Codeforces Round 3
ICPC
2,015
2
256
USB Flash Drives
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of USB flash drives. The second line contains positive integer m (1 ≤ m ≤ 105) — the size of Sean's file. Each of the next n lines contains positive integer ai (1 ≤ ai ≤ 1000) — the sizes of USB flash drives in megabytes. It is guaranteed that the...
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
null
In the first example Sean needs only two USB flash drives — the first and the third. In the second example Sean needs all three USB flash drives. In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.
[{"input": "3\n5\n2\n1\n3", "output": "2"}, {"input": "3\n6\n2\n3\n2", "output": "3"}, {"input": "2\n5\n5\n10", "output": "1"}]
800
["greedy", "implementation", "sortings"]
34
[{"input": "3\r\n5\r\n2\r\n1\r\n3\r\n", "output": "2\r\n"}, {"input": "3\r\n6\r\n2\r\n3\r\n2\r\n", "output": "3\r\n"}, {"input": "2\r\n5\r\n5\r\n10\r\n", "output": "1\r\n"}, {"input": "5\r\n16\r\n8\r\n1\r\n3\r\n4\r\n9\r\n", "output": "2\r\n"}, {"input": "10\r\n121\r\n10\r\n37\r\n74\r\n56\r\n42\r\n39\r\n6\r\n68\r\n8\r\n...
false
stdio
null
true
534/D
534
D
Python 3
PRETESTS
7
62
0
10676519
#!/usr/bin/env python3 from sys import stdin, stdout from math import * from itertools import * lmap = lambda x, y: list(map(x, y)) lfilter = lambda x, y: list(filter(x, y)) def solve(test): inp = lmap(int, test.strip().split()) n = inp[0] a = sorted(zip(inp[1:], range(1, n + 1))) m0 = lfilter(lambda...
85
342
36,249,600
208081109
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) a = [0] + list(map(int, input().split())) x = [[] for _ in range(n + 5)] for i in range(1, n + 1): x[a[i]].append(i) i = 0 ans = [] while x[i]: ans.append(x[i].pop()) i += 1 while i >= 0 and not x[i]: ...
Codeforces Round 298 (Div. 2)
CF
2,015
1
256
Handshakes
On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came in...
The first line contains integer n (1 ≤ n ≤ 2·105) — the number of students who came to CTOP. The next line contains n integers a1, a2, ..., an (0 ≤ ai < n), where ai is the number of students with who the i-th student shook hands.
If the sought order of students exists, print in the first line "Possible" and in the second line print the permutation of the students' numbers defining the order in which the students entered the center. Number i that stands to the left of number j in this permutation means that the i-th student came earlier than the...
null
In the first sample from the statement the order of events could be as follows: - student 4 comes in (a4 = 0), he has no one to greet; - student 5 comes in (a5 = 1), he shakes hands with student 4; - student 1 comes in (a1 = 2), he shakes hands with two students (students 4, 5); - student 3 comes in (a3 = 3), he shake...
[{"input": "5\n2 1 3 0 1", "output": "Possible\n4 5 1 3 2"}, {"input": "9\n0 2 3 4 1 1 0 2 2", "output": "Possible\n7 5 2 1 6 8 3 4 9"}, {"input": "4\n0 2 1 1", "output": "Impossible"}]
1,900
["binary search", "constructive algorithms", "data structures", "greedy"]
85
[{"input": "5\r\n2 1 3 0 1\r\n", "output": "Possible\r\n4 5 1 3 2 "}, {"input": "9\r\n0 2 3 4 1 1 0 2 2\r\n", "output": "Possible\r\n7 6 9 3 4 8 1 5 2 "}, {"input": "4\r\n0 2 1 1\r\n", "output": "Impossible\r\n"}, {"input": "5\r\n1 0 2 1 0\r\n", "output": "Possible\r\n5 4 3 2 1 "}, {"input": "1\r\n0\r\n", "output": "Po...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) a_dict = {i+1: a[i] for i in range(n)} # Read submission output with open(submission_path) as f: lines = [l...
true
534/D
534
D
Python 3
TESTS
7
108
0
65399892
n = int(input()) a = list(map(int, input().split())) max_a = max(a) ps = [[] for _ in range(max_a+3)] for i in range(n): ps[a[i]].append(i+1) a_left = len(a) sol = [] valid = True base = 0 while len(ps[base]) > 0 and valid: if len(ps[base]) > 1: sol.append(ps[base].pop()) if len(ps[base+1]) ...
85
374
38,502,400
90674957
def main(): n = int(input()) a = list(map(int, input().split())) dic = [[] for i in range(n)] for i, item in enumerate(a, start=1): dic[item].append(i) if not dic[0]: print("Impossible") exit() route = [dic[0].pop()] s = 0 for i in range(1, n): ...
Codeforces Round 298 (Div. 2)
CF
2,015
1
256
Handshakes
On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came in...
The first line contains integer n (1 ≤ n ≤ 2·105) — the number of students who came to CTOP. The next line contains n integers a1, a2, ..., an (0 ≤ ai < n), where ai is the number of students with who the i-th student shook hands.
If the sought order of students exists, print in the first line "Possible" and in the second line print the permutation of the students' numbers defining the order in which the students entered the center. Number i that stands to the left of number j in this permutation means that the i-th student came earlier than the...
null
In the first sample from the statement the order of events could be as follows: - student 4 comes in (a4 = 0), he has no one to greet; - student 5 comes in (a5 = 1), he shakes hands with student 4; - student 1 comes in (a1 = 2), he shakes hands with two students (students 4, 5); - student 3 comes in (a3 = 3), he shake...
[{"input": "5\n2 1 3 0 1", "output": "Possible\n4 5 1 3 2"}, {"input": "9\n0 2 3 4 1 1 0 2 2", "output": "Possible\n7 5 2 1 6 8 3 4 9"}, {"input": "4\n0 2 1 1", "output": "Impossible"}]
1,900
["binary search", "constructive algorithms", "data structures", "greedy"]
85
[{"input": "5\r\n2 1 3 0 1\r\n", "output": "Possible\r\n4 5 1 3 2 "}, {"input": "9\r\n0 2 3 4 1 1 0 2 2\r\n", "output": "Possible\r\n7 6 9 3 4 8 1 5 2 "}, {"input": "4\r\n0 2 1 1\r\n", "output": "Impossible\r\n"}, {"input": "5\r\n1 0 2 1 0\r\n", "output": "Possible\r\n5 4 3 2 1 "}, {"input": "1\r\n0\r\n", "output": "Po...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) a_dict = {i+1: a[i] for i in range(n)} # Read submission output with open(submission_path) as f: lines = [l...
true
21/D
21
D
PyPy 3
TESTS
15
372
6,553,600
153732522
INF = 1000 * 1000 * 100 def find_pair_combination(vertexes): if len(vertexes) == 0: return 0 ans = INF for i in range(1, len(vertexes)): ans = min(ans, dist[vertexes[0]][vertexes[i]] + find_pair_combination(vertexes[1:i] + vertexes[i + 1:])) return ans def build_dijskatra(dist): for ...
60
342
5,939,200
153734864
INF = 1000 * 1000 * 100 def get_ans(vertexes): if not vertexes: return 0 ans = INF for i in range(1, len(vertexes)): ans = min(ans, dist[vertexes[0]][vertexes[i]] + get_ans(vertexes[1:i] + vertexes[i + 1:])) return ans def build_dijskatra(dist): for a in range(n): # this calculate i...
Codeforces Alpha Round 21 (Codeforces format)
CF
2,010
0.5
64
Traveling Graph
You are given undirected weighted graph. Find the length of the shortest cycle which starts from the vertex 1 and passes throught all the edges at least once. Graph may contain multiply edges between a pair of vertices and loops (edges from the vertex to itself).
The first line of the input contains two integers n and m (1 ≤ n ≤ 15, 0 ≤ m ≤ 2000), n is the amount of vertices, and m is the amount of edges. Following m lines contain edges as a triples x, y, w (1 ≤ x, y ≤ n, 1 ≤ w ≤ 10000), x, y are edge endpoints, and w is the edge length.
Output minimal cycle length or -1 if it doesn't exists.
null
null
[{"input": "3 3\n1 2 1\n2 3 1\n3 1 1", "output": "3"}, {"input": "3 2\n1 2 3\n2 3 4", "output": "14"}]
2,400
["bitmasks", "graph matchings", "graphs"]
60
[{"input": "4 6\r\n1 2 10\r\n2 3 1000\r\n3 4 10\r\n4 1 1000\r\n4 2 5000\r\n1 3 2\r\n", "output": "7042\r\n"}, {"input": "2 9\r\n1 2 9\r\n1 2 9\r\n2 1 9\r\n1 2 8\r\n2 1 9\r\n1 2 9\r\n1 2 9\r\n1 2 11\r\n1 2 9\r\n", "output": "90\r\n"}, {"input": "2 10\r\n1 2 9\r\n1 2 9\r\n2 1 9\r\n1 2 8\r\n2 1 9\r\n1 2 9\r\n1 2 9\r\n1 2 ...
false
stdio
null
true
958/F2
958
F2
PyPy 3
TESTS
6
77
20,172,800
127418718
def f(a,b): lo=0 b=[0]+b cnt=[0]*(len(b)) ans=float("inf") for i in range(len(a)): id=a[i] hi=i cnt[id]+=1 while lo<=hi: if cnt[a[lo]]-1>=b[a[lo]]: cnt[a[lo]]-=1 lo+=1 else: break l=list(m...
59
623
18,022,400
76986175
import random, math from copy import deepcopy as dc from bisect import bisect_left, bisect_right # Function to call the actual solution def solution(li, li1): freq = {} for i in range(len(li1)): if li1[i]: freq[i+1] = li1[i] maxi = len(li) # Exclusive ranges j - i i = 0 j = 0 req = dc(freq) cur_freq ...
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
1
256
Lightsabers (medium)
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th...
The first line of the input contains n (1 ≤ n ≤ 2·105) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with $$1 \leq \sum_{i=1}^{m} k_i \leq n$$) – the desired co...
Output one number: the minimum number of Jedi Knights that need to be removed from the sequence so that, in what remains, there is an interval with the prescribed counts of lightsaber colors. If this is not possible, output - 1.
null
null
[{"input": "8 3\n3 3 1 2 2 1 1 3\n3 1 1", "output": "1"}]
1,800
["binary search", "two pointers"]
59
[{"input": "8 3\r\n3 3 1 2 2 1 1 3\r\n3 1 1\r\n", "output": "1\r\n"}, {"input": "6 5\r\n1 2 4 2 4 3\r\n0 0 1 0 0\r\n", "output": "0\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\...
false
stdio
null
true
609/A
609
A
Python 3
TESTS
6
108
0
45288364
x=int(input()) f=int(input()) eyad=[] w=[] sol=0 for i in range(x): a=int(input()) eyad.append(a) w=sorted(eyad,reverse=True) for i in range(x): if f-w[i]<0: sol+=1 break if f-w[i]>0 : sol+=1 f-=w[i] print(sol)
34
46
0
14885573
n = int(input()) m = int(input()) l = [int(input()) for i in range(n)] l.sort(reverse=True) tot = 0 idx = 0 for i in range(n): if tot >= m: break else: tot += l[i] idx += 1 print(idx)
Educational Codeforces Round 3
ICPC
2,015
2
256
USB Flash Drives
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of USB flash drives. The second line contains positive integer m (1 ≤ m ≤ 105) — the size of Sean's file. Each of the next n lines contains positive integer ai (1 ≤ ai ≤ 1000) — the sizes of USB flash drives in megabytes. It is guaranteed that the...
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
null
In the first example Sean needs only two USB flash drives — the first and the third. In the second example Sean needs all three USB flash drives. In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.
[{"input": "3\n5\n2\n1\n3", "output": "2"}, {"input": "3\n6\n2\n3\n2", "output": "3"}, {"input": "2\n5\n5\n10", "output": "1"}]
800
["greedy", "implementation", "sortings"]
34
[{"input": "3\r\n5\r\n2\r\n1\r\n3\r\n", "output": "2\r\n"}, {"input": "3\r\n6\r\n2\r\n3\r\n2\r\n", "output": "3\r\n"}, {"input": "2\r\n5\r\n5\r\n10\r\n", "output": "1\r\n"}, {"input": "5\r\n16\r\n8\r\n1\r\n3\r\n4\r\n9\r\n", "output": "2\r\n"}, {"input": "10\r\n121\r\n10\r\n37\r\n74\r\n56\r\n42\r\n39\r\n6\r\n68\r\n8\r\n...
false
stdio
null
true
534/D
534
D
Python 3
TESTS
7
62
4,710,400
10812290
n = int(input()) a = [[ ] for i in range(n)] for i, x in enumerate(map(int, input().split())): a[x].append(i) cur = 0 result = [ ] for i in range(n): if cur >= 3 and a[cur - 3]: result.append(str(a[cur - 3].pop() + 1)) cur -= 2 elif a[cur]: result.append(str(a[cur].pop() + 1)) ...
85
436
55,091,200
86328722
def read_int(): return int(input().strip()) def read_ints(): return list(map(int, input().strip().split(' '))) def solve(): """ 4 2 1 3 5 0 2 3 4 1 1 0 2 2 x x x x x x x x x 1 5 8 3 4 2 7 6 9 10 0 3 4 2 0 1 2 3 4 5 """ N = read_int() shakes = [[] for _ in range(N)] f...
Codeforces Round 298 (Div. 2)
CF
2,015
1
256
Handshakes
On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came in...
The first line contains integer n (1 ≤ n ≤ 2·105) — the number of students who came to CTOP. The next line contains n integers a1, a2, ..., an (0 ≤ ai < n), where ai is the number of students with who the i-th student shook hands.
If the sought order of students exists, print in the first line "Possible" and in the second line print the permutation of the students' numbers defining the order in which the students entered the center. Number i that stands to the left of number j in this permutation means that the i-th student came earlier than the...
null
In the first sample from the statement the order of events could be as follows: - student 4 comes in (a4 = 0), he has no one to greet; - student 5 comes in (a5 = 1), he shakes hands with student 4; - student 1 comes in (a1 = 2), he shakes hands with two students (students 4, 5); - student 3 comes in (a3 = 3), he shake...
[{"input": "5\n2 1 3 0 1", "output": "Possible\n4 5 1 3 2"}, {"input": "9\n0 2 3 4 1 1 0 2 2", "output": "Possible\n7 5 2 1 6 8 3 4 9"}, {"input": "4\n0 2 1 1", "output": "Impossible"}]
1,900
["binary search", "constructive algorithms", "data structures", "greedy"]
85
[{"input": "5\r\n2 1 3 0 1\r\n", "output": "Possible\r\n4 5 1 3 2 "}, {"input": "9\r\n0 2 3 4 1 1 0 2 2\r\n", "output": "Possible\r\n7 6 9 3 4 8 1 5 2 "}, {"input": "4\r\n0 2 1 1\r\n", "output": "Impossible\r\n"}, {"input": "5\r\n1 0 2 1 0\r\n", "output": "Possible\r\n5 4 3 2 1 "}, {"input": "1\r\n0\r\n", "output": "Po...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) a_dict = {i+1: a[i] for i in range(n)} # Read submission output with open(submission_path) as f: lines = [l...
true
305/A
305
A
PyPy 3
TESTS
22
310
0
65930962
n = int(input()) sets = list(map(int,input().split())) a =[] if 0 in sets: a+=[0] if 100 in sets: a+=[100] for i in sets: if i>0 and i<10: a+=[i] break for i in sets: if i!=0 and i!=100: if i%10 ==0: a+=[i] break if len(a)==0: for i in sets: if...
35
92
0
160962765
input() a = list(map(int, input().split())) d = [] for i in a: if i in range(1, 10): d += [i] break for i in a: if i in range(10, 100, 10): d += [i] break if len(d) == 0: for i in a: if i not in (0, 100): d += [i] break if 100 in a: d += [100] if 0 in a: d += [0] print(len(d)) ...
Codeforces Round 184 (Div. 2)
CF
2,013
2
256
Strange Addition
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers ...
The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
null
null
[{"input": "4\n100 10 1 0", "output": "4\n0 1 10 100"}, {"input": "3\n2 70 3", "output": "2\n2 70"}]
1,600
["brute force", "constructive algorithms", "implementation"]
35
[{"input": "4\r\n100 10 1 0\r\n", "output": "4\r\n0 1 10 100 "}, {"input": "3\r\n2 70 3\r\n", "output": "2\r\n2 70 "}, {"input": "39\r\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\r\n", "output": "4\r\n0 6 30 100 "}, {"input": "50\r\n20 67 96 6 75 ...
false
stdio
import sys def mask(num): s = f"{num:03d}" mask = 0 if s[0] != '0': mask |= 4 if s[1] != '0': mask |= 2 if s[2] != '0': mask |= 1 return mask def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.readlines() k = int(li...
true
78/A
78
A
Python 3
TESTS
15
218
6,963,200
89644804
d={'a':0,'e':0,'i':0,'o':0,'u':0} l=[5,7,5] c=0 for i in range(3): c=0 t=1 s=input() for j in s: if(j in d): c+=1 if(c>l[i]): t=0 break if(t==0): print('NO') break if(t==1): print('YES')
40
62
0
204992836
a=input() b=input() c=input() def counter(d): count=0 for i in range(len(d)): if d[i]=='a' or d[i]=='e' or d[i]=='i' or d[i]=='o' or d[i]=='u': count+=1 return count if counter(a)==5 and counter(b)==7 and counter(c)==5: print('YES') else: print('NO')
Codeforces Beta Round 70 (Div. 2)
CF
2,011
2
256
Haiku
Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll...
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing sp...
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
null
null
[{"input": "on codeforces\nbeta round is running\na rustling of keys", "output": "YES"}, {"input": "how many gallons\nof edo s rain did you drink\ncuckoo", "output": "NO"}]
800
["implementation", "strings"]
40
[{"input": "on codeforces \r\nbeta round is running\r\n a rustling of keys \r\n", "output": "YES"}, {"input": "how many gallons\r\nof edo s rain did you drink\r\n cuckoo\r\n", "output": "NO"}, {"input": " hatsu shigure\r\n saru mo komino wo\r\nhoshige nari\r\n", "output": "Y...
false
stdio
null
true
787/B
787
B
Python 3
TESTS
56
93
6,246,400
26155889
n,m = map(int, input().split()) def solve(): for i in range(m): current = set(map(int, input().split())) for i,j in enumerate(current,1): if -j in current: break elif i == len(current): return "YES" return "NO" print(solve())
65
46
1,433,600
213494515
n, m = map(int, input().split()) stop = False for _ in range(m): k, *a = map(int, input().split()) s = set(a) if all(x > 0 or -x not in s for x in a): stop = True if stop: print("YES") else: print("NO")
Codeforces Round 406 (Div. 2)
CF
2,017
2
256
Not Afraid
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one ...
The first line of input contains two integers n and m (1 ≤ n, m ≤ 104) — number of universes and number of groups respectively. The next m lines contain the information about the groups. i-th of them first contains an integer k (number of times someone joined i-th group, k > 0) followed by k integers vi, 1, vi, 2, ......
In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise.
null
In the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he's a traitor, then all members of this group are traitors and so Summer should cancel the event.
[{"input": "4 2\n1 -3\n4 -2 3 2 -3", "output": "YES"}, {"input": "5 2\n5 3 -2 1 -1 5\n3 -5 2 5", "output": "NO"}, {"input": "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4", "output": "YES"}]
1,300
["greedy", "implementation", "math"]
65
[{"input": "4 2\r\n1 -3\r\n4 -2 3 2 -3\r\n", "output": "YES\r\n"}, {"input": "5 2\r\n5 3 -2 1 -1 5\r\n3 -5 2 5\r\n", "output": "NO\r\n"}, {"input": "7 2\r\n3 -1 6 7\r\n7 -5 4 2 4 7 -3 4\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n2 -2 2\r\n", "output": "NO\r\n"}, {"input": "7 7\r\n1 -2\r\n1 6\r\n2 7 -6\r\n2 -6 4\r\n2...
false
stdio
null
true
626/E
626
E
Python 3
PRETESTS
7
483
18,022,400
16002061
n = int(input()) l = list(map(int, input().split())) arr = sorted(l) j = 0 down = [arr[0]]*n up = [arr[-1]]*n ans = 0 for i in range(1, n): down[i] = down[i-1] + arr[i] up[i] = up[i-1] + arr[n-i-1] for i in range(1, n // 2): kans = (down[i] + up[i-1]) / (2*i+1) - arr[i] if ans < kans: ans = ...
94
1,560
55,398,400
125835053
from fractions import Fraction def findMean(prefixSum, n, k, medianIdx): total = prefixSum[medianIdx + 1] - prefixSum[medianIdx - k] + prefixSum[n] - prefixSum[n - k] return Fraction(total, (2 * k + 1)) n = int(input()) nums = sorted(list(map(int, input().split()))) ans, bestK, bestMedianIdx = -1, 0, 0 prefS...
8VC Venture Cup 2016 - Elimination Round
CF
2,016
3
256
Simple Skewness
Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness. The mean of a collection is the average of its elements. The median of a colle...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in the list. The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list.
In the first line, print a single integer k — the size of the subset. In the second line, print k integers — the elements of the subset in any order. If there are multiple optimal subsets, print any.
null
In the first case, the optimal subset is $${ \{ 1, 2, 1 2 \} }$$, which has mean 5, median 2, and simple skewness of 5 - 2 = 3. In the second case, the optimal subset is $${ \{ 1, 1, 2 \} }$$. Note that repetition is allowed. In the last case, any subset has the same median and mean, so all have simple skewness of 0.
[{"input": "4\n1 2 3 12", "output": "3\n1 2 12"}, {"input": "4\n1 1 2 2", "output": "3\n1 1 2"}, {"input": "2\n1 2", "output": "2\n1 2"}]
2,400
["binary search", "math", "ternary search"]
94
[{"input": "4\r\n1 2 3 12\r\n", "output": "3\r\n1 2 12 \r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "3\r\n1 1 2 \r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n1 2\r\n"}, {"input": "1\r\n1000000\r\n", "output": "1\r\n1000000 \r\n"}, {"input": "20\r\n999999 999998 999996 999992 999984 999968 999936 999872 999744 99...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: lines = f.readlines() return [line.strip() for line in lines] def compute_skewness(subset): sorted_subset = sorted(subset) k = len(sorted_subset) if k == 0: return None total = sum(sorted_subset) mean = total / k ...
true
305/A
305
A
Python 3
TESTS
22
124
5,632,000
35141640
from sys import stdin inputIdx = 0; input = stdin.read().strip().split(); def nextToken(): global inputIdx, input; if inputIdx == len(input): exit(); token = input[inputIdx]; inputIdx += 1; return token; def main(): while True: n = int(nextToken()); s = set( [ int(nextToken()) for i in range(...
35
92
0
205157898
input() a=[-1]*5 for i in map(int,input().split()): if i==0: a[0]=i elif i<10: a[1]=i elif i>99: a[2]=i elif i%10==0: a[3]=i else: a[4]=i x,y=[*filter((z:=lambda j:j>-1),a[:4])],[*filter(z,a[:5:2])] print(max(len(x),len(y))) print(*(x if len(x)>len(y) else y))
Codeforces Round 184 (Div. 2)
CF
2,013
2
256
Strange Addition
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers ...
The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
null
null
[{"input": "4\n100 10 1 0", "output": "4\n0 1 10 100"}, {"input": "3\n2 70 3", "output": "2\n2 70"}]
1,600
["brute force", "constructive algorithms", "implementation"]
35
[{"input": "4\r\n100 10 1 0\r\n", "output": "4\r\n0 1 10 100 "}, {"input": "3\r\n2 70 3\r\n", "output": "2\r\n2 70 "}, {"input": "39\r\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\r\n", "output": "4\r\n0 6 30 100 "}, {"input": "50\r\n20 67 96 6 75 ...
false
stdio
import sys def mask(num): s = f"{num:03d}" mask = 0 if s[0] != '0': mask |= 4 if s[1] != '0': mask |= 2 if s[2] != '0': mask |= 1 return mask def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.readlines() k = int(li...
true
78/A
78
A
Python 3
TESTS
15
62
0
221811556
phrase1 = input() phrase2 = input() phrase3 = input() yes = True counter = 0 for c in phrase1: if c in ['a', 'e', 'i', 'o', 'u']: counter += 1 if counter > 5: yes = False break counter = 0 for c in phrase2: if c in ['a', 'e', 'i', 'o', 'u']: counter += 1 if counter > 7:...
40
62
0
205291768
def count_vowels(s): return sum(1 for c in s if c in 'aeiou') s1 = input().strip() s2 = input().strip() s3 = input().strip() if count_vowels(s1) == 5 and count_vowels(s2) == 7 and count_vowels(s3) == 5: print("YES") else: print("NO")
Codeforces Beta Round 70 (Div. 2)
CF
2,011
2
256
Haiku
Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll...
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing sp...
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
null
null
[{"input": "on codeforces\nbeta round is running\na rustling of keys", "output": "YES"}, {"input": "how many gallons\nof edo s rain did you drink\ncuckoo", "output": "NO"}]
800
["implementation", "strings"]
40
[{"input": "on codeforces \r\nbeta round is running\r\n a rustling of keys \r\n", "output": "YES"}, {"input": "how many gallons\r\nof edo s rain did you drink\r\n cuckoo\r\n", "output": "NO"}, {"input": " hatsu shigure\r\n saru mo komino wo\r\nhoshige nari\r\n", "output": "Y...
false
stdio
null
true
463/A
463
A
PyPy 3-64
TESTS
8
62
0
228719633
n,s=input().split() n,s=int(n),int(s) d=[] l=1 for i in range(n): x,y=input().split() x,y=int(x),int(y) if x+y/100<=s and y!=0: d.append(y) elif y==0: l=0 if len(d)!=0: print(100-min(d)) elif l==0: print(0) else: print(-1)
35
46
0
223514410
n,s = list(map(int,input().split())) res = 100 cnt = 0 arr = [] for i in range(n): x,y = list(map(int,input().split())) if x<s: if y: res = min(res,y) if x<s or (x==s and y==0): cnt=1 # arr.append((x,y)) if not cnt: print(-1) else: print(100-res)
Codeforces Round 264 (Div. 2)
CF
2,014
1
256
Caisa and Sugar
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town. Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But t...
The first line contains two space-separated integers n, s (1 ≤ n, s ≤ 100). The i-th of the next n lines contains two integers xi, yi (1 ≤ xi ≤ 100; 0 ≤ yi < 100), where xi represents the number of dollars and yi the number of cents needed in order to buy the i-th type of sugar.
Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.
null
In the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change.
[{"input": "5 10\n3 90\n12 0\n9 70\n5 50\n7 0", "output": "50"}, {"input": "5 5\n10 10\n20 20\n30 30\n40 40\n50 50", "output": "-1"}]
1,200
["brute force", "implementation"]
35
[{"input": "5 10\r\n3 90\r\n12 0\r\n9 70\r\n5 50\r\n7 0\r\n", "output": "50\r\n"}, {"input": "5 5\r\n10 10\r\n20 20\r\n30 30\r\n40 40\r\n50 50\r\n", "output": "-1\r\n"}, {"input": "1 2\r\n1 0\r\n", "output": "0\r\n"}, {"input": "2 10\r\n20 99\r\n30 99\r\n", "output": "-1\r\n"}, {"input": "15 21\r\n16 51\r\n33 44\r\n32 ...
false
stdio
null
true
570/A
570
A
PyPy 3-64
TESTS
12
46
0
157967536
n, m = map(int, input().split()) mx = 0 mn = n for i in range(m): l = list(map(int, input().split())) if(max(l) > mx): mx = max(l) mn = l.index(mx) + 1 elif(max(l) == mx): mn = min(mn, l.index(mx) + 1) print(mn)
62
46
102,400
205211878
candidates , cities = map(int ,input().split()) res = [0] * candidates for i in range(cities) : cite = list(map(int , input().split())) winner = cite.index(max(cite)) res[winner] += 1 print(res.index(max(res)) + 1 )
Codeforces Round 316 (Div. 2)
CF
2,015
1
256
Elections
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each...
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. I...
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
null
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm...
[{"input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2"}, {"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1"}]
1,100
["implementation"]
62
[{"input": "3 3\r\n1 2 3\r\n2 3 1\r\n1 2 1\r\n", "output": "2"}, {"input": "3 4\r\n10 10 3\r\n5 1 6\r\n2 2 2\r\n1 5 7\r\n", "output": "1"}, {"input": "1 3\r\n5\r\n3\r\n2\r\n", "output": "1"}, {"input": "3 1\r\n1 2 3\r\n", "output": "3"}, {"input": "3 1\r\n100 100 100\r\n", "output": "1"}, {"input": "2 2\r\n1 2\r\n2 1\r...
false
stdio
null
true
802/G
802
G
Python 3
TESTS
6
61
0
109154099
S=input() if "heidi" in S: print("NO") else: A=["h","e","i","d","i"] for i in range(len(S)): if A[0]==S[i]: A.pop(0) if len(A)==0: break if len(A)==0: print("YES") else: print("NO")
58
46
0
132378755
s = input() found = 'YES' idx = 0 for ch in 'heidi': idx = s.find(ch, idx) if idx == -1: found = 'NO' break print(found)
Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
ICPC
2,017
1
256
Fake News (easy)
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
The first and only line of input contains a single nonempty string s of length at most 1000 composed of lowercase letters (a-z).
Output YES if the string s contains heidi as a subsequence and NO otherwise.
null
A string s contains another string p as a subsequence if it is possible to delete some characters from s and obtain p.
[{"input": "abcheaibcdi", "output": "YES"}, {"input": "hiedi", "output": "NO"}]
800
["implementation", "strings"]
58
[{"input": "abcheaibcdi\r\n", "output": "YES"}, {"input": "hiedi\r\n", "output": "NO"}, {"input": "ihied\r\n", "output": "NO"}, {"input": "diehi\r\n", "output": "NO"}, {"input": "deiih\r\n", "output": "NO"}, {"input": "iheid\r\n", "output": "NO"}, {"input": "eihdi\r\n", "output": "NO"}, {"input": "ehdii\r\n", "output":...
false
stdio
null
true
78/A
78
A
PyPy 3-64
TESTS
15
92
0
194231076
a=input() b=input() c=input() l=0 for i in a: if i in 'aeiou': l+=1 if l>5: print('NO') exit() if l>5: print('NO') exit() l=0 for i in b: if i in 'aeiou': l+=1 if l>7: print('NO') exit() if l>7: print('NO') exit() l=0 for i in c: if i i...
40
62
0
208093735
def countVowels(string): vowels = ['a','e','i','o','u'] total = 0 for s in string: if s in vowels: total += 1 return total a1 = input() a2 = input() a3 = input() print("YES" if countVowels(a1) == 5 and countVowels(a2) == 7 and countVowels(a3) == 5 else "NO")
Codeforces Beta Round 70 (Div. 2)
CF
2,011
2
256
Haiku
Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll...
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing sp...
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
null
null
[{"input": "on codeforces\nbeta round is running\na rustling of keys", "output": "YES"}, {"input": "how many gallons\nof edo s rain did you drink\ncuckoo", "output": "NO"}]
800
["implementation", "strings"]
40
[{"input": "on codeforces \r\nbeta round is running\r\n a rustling of keys \r\n", "output": "YES"}, {"input": "how many gallons\r\nof edo s rain did you drink\r\n cuckoo\r\n", "output": "NO"}, {"input": " hatsu shigure\r\n saru mo komino wo\r\nhoshige nari\r\n", "output": "Y...
false
stdio
null
true
305/A
305
A
Python 3
TESTS
22
124
4,915,200
23372716
# codeforces 184 n=int(input()) b,c=[],[] aa,bb,cc,dd,ee,sumi=0,0,0,0,0,0 a=sorted(list(map(int,input().split()))) for i in range(0,len(a)): if a[i]==100 and aa==0: b.append(100) sumi+=100 aa+=1 elif a[i]==0 and ee==0: b.append(0) ee+=1 elif len(str(a[i]))==1 and bb==...
35
93
102,400
3740619
k = int(input()) dk = list(map(int,input().split())) ans = [] if 0 in dk: ans.append(0) if 100 in dk: ans.append(100) f1 = False for q in dk: if 0<q<10: ans.append(q) f1 = True break f2 = False for q in dk: if 9<q<100 and q%10==0: ans.append(q) f2 = True ...
Codeforces Round 184 (Div. 2)
CF
2,013
2
256
Strange Addition
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers ...
The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
null
null
[{"input": "4\n100 10 1 0", "output": "4\n0 1 10 100"}, {"input": "3\n2 70 3", "output": "2\n2 70"}]
1,600
["brute force", "constructive algorithms", "implementation"]
35
[{"input": "4\r\n100 10 1 0\r\n", "output": "4\r\n0 1 10 100 "}, {"input": "3\r\n2 70 3\r\n", "output": "2\r\n2 70 "}, {"input": "39\r\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\r\n", "output": "4\r\n0 6 30 100 "}, {"input": "50\r\n20 67 96 6 75 ...
false
stdio
import sys def mask(num): s = f"{num:03d}" mask = 0 if s[0] != '0': mask |= 4 if s[1] != '0': mask |= 2 if s[2] != '0': mask |= 1 return mask def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.readlines() k = int(li...
true
305/A
305
A
Python 3
TESTS
22
124
0
7990281
from sys import stdin def main(): num=stdin.readline().strip().split() num=stdin.readline().strip().split() num=[int(num[i]) for i in range(len(num))] bol0=False bol100=False bole=False beli=False vl=True num.sort() res=[] res1=[] cont=0; while(cont<len(num) and (bol0...
35
93
102,400
3740827
k = int(input()) dk = list(map(int,input().split())) ans = [] if 0 in dk: ans.append(0) if 100 in dk: ans.append(100) f1 = False for q in dk: if 0<q<10: ans.append(q) f1 = True break f2 = False for q in dk: if 9<q<100 and q%10==0: ans.append(q) f2 = True break if...
Codeforces Round 184 (Div. 2)
CF
2,013
2
256
Strange Addition
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers ...
The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
null
null
[{"input": "4\n100 10 1 0", "output": "4\n0 1 10 100"}, {"input": "3\n2 70 3", "output": "2\n2 70"}]
1,600
["brute force", "constructive algorithms", "implementation"]
35
[{"input": "4\r\n100 10 1 0\r\n", "output": "4\r\n0 1 10 100 "}, {"input": "3\r\n2 70 3\r\n", "output": "2\r\n2 70 "}, {"input": "39\r\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\r\n", "output": "4\r\n0 6 30 100 "}, {"input": "50\r\n20 67 96 6 75 ...
false
stdio
import sys def mask(num): s = f"{num:03d}" mask = 0 if s[0] != '0': mask |= 4 if s[1] != '0': mask |= 2 if s[2] != '0': mask |= 1 return mask def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.readlines() k = int(li...
true
257/C
257
C
PyPy 3-64
TESTS
20
186
9,318,400
213297200
import sys #sys.setrecursionlimit(10**7) input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())...
56
372
5,427,200
220943488
import sys; input = sys.stdin.readline from math import atan2, degrees n = int(input()) angles = sorted(degrees(atan2(*tuple(map(int, input().split())))) for _ in range(n)) result = 0 for i in range(n - 1): result = max(result, angles[i + 1] - angles[i]) result = max(result, 360 + angles[0] - angles[-1]) print(36...
Codeforces Round 159 (Div. 2)
CF
2,013
2
256
View Angle
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this a...
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of mannequins. Next n lines contain two space-separated integers each: xi, yi (|xi|, |yi| ≤ 1000) — the coordinates of the i-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that no two mannequins ...
Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10 - 6.
null
Solution for the first sample test is shown below: Solution for the second sample test is shown below: Solution for the third sample test is shown below: Solution for the fourth sample test is shown below:
[{"input": "2\n2 0\n0 2", "output": "90.0000000000"}, {"input": "3\n2 0\n0 2\n-2 2", "output": "135.0000000000"}, {"input": "4\n2 0\n0 2\n-2 0\n0 -2", "output": "270.0000000000"}, {"input": "2\n2 1\n1 2", "output": "36.8698976458"}]
1,800
["brute force", "geometry", "math"]
56
[{"input": "2\r\n2 0\r\n0 2\r\n", "output": "90.0000000000\r\n"}, {"input": "3\r\n2 0\r\n0 2\r\n-2 2\r\n", "output": "135.0000000000\r\n"}, {"input": "4\r\n2 0\r\n0 2\r\n-2 0\r\n0 -2\r\n", "output": "270.0000000000\r\n"}, {"input": "2\r\n2 1\r\n1 2\r\n", "output": "36.8698976458\r\n"}, {"input": "1\r\n1 1\r\n", "output...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] sub_path = sys.argv[3] # Read correct output try: with open(output_path, 'r') as f: correct_lines = f.readlines() if len(correct_lines) != 1: print(0) return ...
true
729/E
729
E
Python 3
TESTS
24
249
14,438,400
22807280
""" This is a solution to the problem Subordinates on codeforces.com There is a DAG with n nodes, pointing towards the root, without further constraints. Given: for each node, a number signifying the count of (direct and indirect) predecessors, and the ID of root s. Some of these counts might be wrong...
99
296
15,872,000
59972485
[n, s] = [int(x) for x in input().split()] a = [int(x) for x in input().split()] mistakes = 0 mistakes += (a[s-1] is not 0) a[s - 1] = 0 numSuperiors = [0]*(2*100000+100) for superiors in a: numSuperiors[superiors] += 1 cachedMistakes = 0 while numSuperiors[0] != 1: cachedMistakes += 1 numSuperiors[0...
Technocup 2017 - Elimination Round 2
CF
2,016
1
256
Subordinates
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior. There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate ...
The first line contains two positive integers n and s (1 ≤ n ≤ 2·105, 1 ≤ s ≤ n) — the number of workers and the id of the chief. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.
Print the minimum number of workers that could make a mistake.
null
In the first example it is possible that only the first worker made a mistake. Then: - the immediate superior of the first worker is the second worker, - the immediate superior of the third worker is the first worker, - the second worker is the chief.
[{"input": "3 2\n2 0 2", "output": "1"}, {"input": "5 3\n1 0 0 4 1", "output": "2"}]
1,900
["constructive algorithms", "data structures", "graphs", "greedy", "sortings"]
99
[{"input": "3 2\r\n2 0 2\r\n", "output": "1\r\n"}, {"input": "5 3\r\n1 0 0 4 1\r\n", "output": "2\r\n"}, {"input": "1 1\r\n0\r\n", "output": "0\r\n"}, {"input": "2 1\r\n0 0\r\n", "output": "1\r\n"}, {"input": "2 1\r\n0 1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 0\r\n", "output": "2\r\n"}, {"input": "2 1\r\n1 1\r\n...
false
stdio
null
true
305/A
305
A
Python 3
TESTS
22
124
0
30561418
#!/usr/bin/python3 n = int(input()) b = [] f1 = 0 f2 = 0 val = 0 for x in input().split(): val = int(x) if (val == 0 or val == 100): b.append(val) elif (val > 0 and val < 10 and not f1): b.append(val) f1 = 1 elif (val >= 10 and val < 100 and val%10 == 0 and not f2): b.append(val) f2 = 1 if (len(b) == 0)...
35
122
0
213508799
n=int(input()) a=list(map(int,input().split())) ans,b,c,d=[],[],[],[] for x in a: if 0<x<10: b.append(x) elif 10<=x<100: if x%10==0: c.append(x) else: d.append(x) if 0 in a: ans.append(0) if 100 in a: ans.append(100) if len(b)>0: ans.append(b[0]) if len(c)>0: ans....
Codeforces Round 184 (Div. 2)
CF
2,013
2
256
Strange Addition
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers ...
The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
null
null
[{"input": "4\n100 10 1 0", "output": "4\n0 1 10 100"}, {"input": "3\n2 70 3", "output": "2\n2 70"}]
1,600
["brute force", "constructive algorithms", "implementation"]
35
[{"input": "4\r\n100 10 1 0\r\n", "output": "4\r\n0 1 10 100 "}, {"input": "3\r\n2 70 3\r\n", "output": "2\r\n2 70 "}, {"input": "39\r\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\r\n", "output": "4\r\n0 6 30 100 "}, {"input": "50\r\n20 67 96 6 75 ...
false
stdio
import sys def mask(num): s = f"{num:03d}" mask = 0 if s[0] != '0': mask |= 4 if s[1] != '0': mask |= 2 if s[2] != '0': mask |= 1 return mask def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.readlines() k = int(li...
true
276/B
276
B
PyPy 3-64
TESTS
19
124
0
230778238
from collections import defaultdict def count_letters(s): d = defaultdict(int) for i in s: d[i] += 1 return d def count_even_values_in_dict(d): n_evens = 0 for i in d.keys(): if d[i]%2==0: n_evens += 1 return n_evens s = input() d = count_letters(s) n_eve...
51
92
0
137763306
n=input() a=0 for i in set(n): if n.count(i)%2!=0: a+=1 if a == 0 or a == 1: print("First") else: if (a-1)%2==0: print("First") else: print("Second")
Codeforces Round 169 (Div. 2)
CF
2,013
2
256
Little Girl and Game
The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: - The players move in turns; In one move the player can remove an arbitrary letter from string s. - If the player ...
The input contains a single line, containing string s (1 ≤ |s| ≤ 103). String s consists of lowercase English letters.
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
null
null
[{"input": "aba", "output": "First"}, {"input": "abca", "output": "Second"}]
1,300
["games", "greedy"]
51
[{"input": "aba\r\n", "output": "First\r\n"}, {"input": "abca\r\n", "output": "Second\r\n"}, {"input": "aabb\r\n", "output": "First\r\n"}, {"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo\r\n", "output": "Second\r\n"}, {"input": "gevqgtaorjixsxnbcoybr\r\n", "output": "First\r\n"}, {"input": "xvhtcbtouuddhylxhplgjxwlo\r\n"...
false
stdio
null
true
218/A
218
A
Python 3
TESTS
8
218
307,200
68742116
x,y=map(int,input().split()) l=list(map(int,input().split())) r=[] for i in range(1,len(l)): if l[i] >l[i-1] and l[i] >l[i+1]: r.append( [l[i],i]) r=sorted(r ,reverse= True) for i in range(y): #print(l[r[i][1]]) l[r[i][1]]-=1 print(*l)
48
62
0
147995673
n, k = tuple(map(int, input().split())) nodes = list(map(int, input().split())) i = 1 if nodes[0] > nodes[1]: i = 0 while k > 0: temp = nodes[i] - 1 if temp > nodes[i - 1] and temp > nodes[i + 1]: nodes[i] = temp k -= 1 i += 2 print(' '.join(map(str, nodes)), end = '')
Codeforces Round 134 (Div. 2)
CF
2,012
2
256
Mountain Scenery
Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point...
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture. It is guaranteed that we can obtain the given picture after performing the describe...
Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.
null
null
[{"input": "3 2\n0 5 3 5 1 5 2", "output": "0 5 3 4 1 4 2"}, {"input": "1 1\n0 2 0", "output": "0 1 0"}]
1,100
["brute force", "constructive algorithms", "implementation"]
48
[{"input": "3 2\r\n0 5 3 5 1 5 2\r\n", "output": "0 5 3 4 1 4 2 \r\n"}, {"input": "1 1\r\n0 2 0\r\n", "output": "0 1 0 \r\n"}, {"input": "1 1\r\n1 100 0\r\n", "output": "1 99 0 \r\n"}, {"input": "3 1\r\n0 1 0 1 0 2 0\r\n", "output": "0 1 0 1 0 1 0 \r\n"}, {"input": "3 1\r\n0 1 0 2 0 1 0\r\n", "output": "0 1 0 1 0 1 0 \...
false
stdio
import sys def main(): input_path = sys.argv[1] submission_path = sys.argv[3] with open(input_path) as f: lines = f.read().splitlines() n, k = map(int, lines[0].split()) r = list(map(int, lines[1].split())) with open(submission_path) as f: y = list(map(int, f.read().split())) ...
true
276/B
276
B
Python 3
TESTS
11
92
0
158718996
import random def ispalindrome(x): return True if x == x[::-1] else False player = "First" flag = 0 x = list(input().strip()) while True: result = ispalindrome(x) if result == True: break elif len(x) == 1: break else: x.pop(random.randrange(0,len(x))) if flag == 0: ...
51
92
0
138800500
st = input() se = set(st) valods = 0 for i in se: if st.count(i)%2 != 0: valods += 1 if valods <= 1: print("First") elif valods%2 == 0: print("Second") else : print("First")
Codeforces Round 169 (Div. 2)
CF
2,013
2
256
Little Girl and Game
The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: - The players move in turns; In one move the player can remove an arbitrary letter from string s. - If the player ...
The input contains a single line, containing string s (1 ≤ |s| ≤ 103). String s consists of lowercase English letters.
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
null
null
[{"input": "aba", "output": "First"}, {"input": "abca", "output": "Second"}]
1,300
["games", "greedy"]
51
[{"input": "aba\r\n", "output": "First\r\n"}, {"input": "abca\r\n", "output": "Second\r\n"}, {"input": "aabb\r\n", "output": "First\r\n"}, {"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo\r\n", "output": "Second\r\n"}, {"input": "gevqgtaorjixsxnbcoybr\r\n", "output": "First\r\n"}, {"input": "xvhtcbtouuddhylxhplgjxwlo\r\n"...
false
stdio
null
true
276/B
276
B
Python 3
TESTS
15
92
0
221714937
s=list(input()) s1="" j=0 for i in range(len(s)-1,-1,-1) : s1+=s[i] if s[len(s)-1-i]!=s1[-1] : j+=1 if len(s)%2==0 : j//=2 if j%2==0 : print("First") else : print("Second")
51
92
0
140653169
s = input() st = set(s) l = [] for ele in st: x = s.count(ele) if x%2!=0: l.append(x) # print(l) if len(l) == 0 or len(l)%2!=0: print("First") else: print("Second")
Codeforces Round 169 (Div. 2)
CF
2,013
2
256
Little Girl and Game
The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: - The players move in turns; In one move the player can remove an arbitrary letter from string s. - If the player ...
The input contains a single line, containing string s (1 ≤ |s| ≤ 103). String s consists of lowercase English letters.
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
null
null
[{"input": "aba", "output": "First"}, {"input": "abca", "output": "Second"}]
1,300
["games", "greedy"]
51
[{"input": "aba\r\n", "output": "First\r\n"}, {"input": "abca\r\n", "output": "Second\r\n"}, {"input": "aabb\r\n", "output": "First\r\n"}, {"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo\r\n", "output": "Second\r\n"}, {"input": "gevqgtaorjixsxnbcoybr\r\n", "output": "First\r\n"}, {"input": "xvhtcbtouuddhylxhplgjxwlo\r\n"...
false
stdio
null
true
508/B
508
B
PyPy 3-64
TESTS
9
93
19,558,400
206738803
n = input() n = list(n) for i in range(len(n)): n[i] = int(n[i]) a = [] b = [] for j in range(len(n)): if n[j]%2 == 0: a.append(n[j]) b.append(j) if a == []: print('-1') else: c = n e = [] for k in range(len(a)): d = c.copy() if d[len(n)-1] > d[b[k]]: ...
58
62
204,800
224782763
# https://codeforces.com/problemset/problem/508/B def change_pos(word, pos): return f'{word[:pos]}{word[-1]}{word[pos+1:-1]}{word[pos]}' def solve(word): last_number = int(word[-1]) pos = -1 for i in range(len(word)-1): number = int(word[i]) if number % 2 == 0: pos = i ...
Codeforces Round 288 (Div. 2)
CF
2,015
0.5
256
Anton and currency you all know
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer. Reliable sources have informed the financier Anton of some information about the exchange rate of...
The first line contains an odd positive integer n — the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from ...
null
null
[{"input": "527", "output": "572"}, {"input": "4573", "output": "3574"}, {"input": "1357997531", "output": "-1"}]
1,300
["greedy", "math", "strings"]
58
[{"input": "527\r\n", "output": "572\r\n"}, {"input": "4573\r\n", "output": "3574\r\n"}, {"input": "1357997531\r\n", "output": "-1\r\n"}, {"input": "444443\r\n", "output": "444434\r\n"}, {"input": "22227\r\n", "output": "72222\r\n"}, {"input": "24683\r\n", "output": "34682\r\n"}, {"input": "11\r\n", "output": "-1\r\n"}...
false
stdio
null
true
508/B
508
B
PyPy 3-64
TESTS
9
155
13,312,000
166903041
s =[] y=input() for i in y: s.append(i) a="k" b="k" for i in range(len(s)): if(int(s[i])%2==0): a=i; break; i=len(s)-1 while(i>=0): if(int(s[i])%2==0): b=i; break; i-=1; if a=='k': print(-1) elif(int(s[len(s)-1])>=int(s[min(a,b)])): s[min(a,b)],s[len(s)-...
58
62
3,072,000
156389504
s=input() index=-1 n=len(s) for i in range(n): if s[i] in "02468": index=i if s[i]<s[-1]: break if index==-1: print(-1) else: print(s[:index]+s[-1]+s[index+1:n-1]+s[index])
Codeforces Round 288 (Div. 2)
CF
2,015
0.5
256
Anton and currency you all know
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer. Reliable sources have informed the financier Anton of some information about the exchange rate of...
The first line contains an odd positive integer n — the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from ...
null
null
[{"input": "527", "output": "572"}, {"input": "4573", "output": "3574"}, {"input": "1357997531", "output": "-1"}]
1,300
["greedy", "math", "strings"]
58
[{"input": "527\r\n", "output": "572\r\n"}, {"input": "4573\r\n", "output": "3574\r\n"}, {"input": "1357997531\r\n", "output": "-1\r\n"}, {"input": "444443\r\n", "output": "444434\r\n"}, {"input": "22227\r\n", "output": "72222\r\n"}, {"input": "24683\r\n", "output": "34682\r\n"}, {"input": "11\r\n", "output": "-1\r\n"}...
false
stdio
null
true
401/A
401
A
Python 3
TESTS
36
62
307,200
110554144
n,x=[int(i) for i in input().split()] xi=[int(x) for x in input().split()] s=sum(xi) s=abs(s) cnt=0 for i in range(x,0,-1): if(s<=0): print(cnt) break if(s>i): q=s//i s-=(i*q) cnt+=q else: s-=i cnt+=1
47
46
0
143399386
import math n, x = map(int, input().split()) a = list(map(int, input().split())) print(math.ceil(abs(sum(a)/x)))
Codeforces Round 235 (Div. 2)
CF
2,014
1
256
Vanya and Cards
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time pla...
The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value.
Print a single number — the answer to the problem.
null
In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
[{"input": "3 2\n-1 1 2", "output": "1"}, {"input": "2 3\n-2 -2", "output": "2"}]
800
["implementation", "math"]
47
[{"input": "3 2\r\n-1 1 2\r\n", "output": "1\r\n"}, {"input": "2 3\r\n-2 -2\r\n", "output": "2\r\n"}, {"input": "4 4\r\n1 2 3 4\r\n", "output": "3\r\n"}, {"input": "2 2\r\n-1 -1\r\n", "output": "1\r\n"}, {"input": "15 5\r\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2\r\n", "output": "4\r\n"}, {"input": "15 16\r\n-15 -5 -15...
false
stdio
null
true
81/B
81
B
Python 3
TESTS
7
92
204,800
5127513
t = input() t = t.replace(' ', '') t = t.replace(',', ', ') t = t.replace(' ...', '...') t = t.replace('...', ' ...') if t[0] == ' ': t = t[1: ] if t[-1] == ' ': t = t[: -1] print(t)
45
154
512,000
14581771
import re s = input().strip() s = re.sub('(\d)\s+(?=\d)', r'\1x', s) s = re.sub('\s', '', s) s = re.sub(',', ', ', s) s = re.sub('\.\.\.', ' ...', s) s = re.sub('^\s|\s$', '', s) s = re.sub('\s\s', ' ', s) s = re.sub('x', ' ', s) print(s)
Yandex.Algorithm Open 2011: Qualification 1
CF
2,011
2
256
Sequence Formatting
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,...,   10" will be corrected ...
The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above.
Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
null
null
[{"input": "1,2 ,3,..., 10", "output": "1, 2, 3, ..., 10"}, {"input": "1,,,4...5......6", "output": "1, , , 4 ...5 ... ...6"}, {"input": "...,1,2,3,...", "output": "..., 1, 2, 3, ..."}]
1,700
["implementation", "strings"]
45
[{"input": "1,2 ,3,..., 10\r\n", "output": "1, 2, 3, ..., 10\r\n"}, {"input": "1,,,4...5......6\r\n", "output": "1, , , 4 ...5 ... ...6\r\n"}, {"input": "...,1,2,3,...\r\n", "output": "..., 1, 2, 3, ...\r\n"}, {"input": "......\r\n", "output": "... ...\r\n"}, {"input": ",,,,,,,,,,,,,\r\n", "output": ", , , , , , , ...
false
stdio
null
true
401/A
401
A
Python 3
TESTS
36
109
307,200
68895139
n,x=map(int,input().split()) y=[int(q) for q in input().split()] s=sum(y) l=0 d=abs(s) for i in range(x,1,-1): while (d)>0: d-=x l+=1 print(l)
47
46
0
146910377
n , x = map(int,input().split()) y = list(map(int,input().split())) z = abs(sum(y))//x if abs(sum(y)) % x == 0: print(z) else: print(z+1)
Codeforces Round 235 (Div. 2)
CF
2,014
1
256
Vanya and Cards
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time pla...
The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value.
Print a single number — the answer to the problem.
null
In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
[{"input": "3 2\n-1 1 2", "output": "1"}, {"input": "2 3\n-2 -2", "output": "2"}]
800
["implementation", "math"]
47
[{"input": "3 2\r\n-1 1 2\r\n", "output": "1\r\n"}, {"input": "2 3\r\n-2 -2\r\n", "output": "2\r\n"}, {"input": "4 4\r\n1 2 3 4\r\n", "output": "3\r\n"}, {"input": "2 2\r\n-1 -1\r\n", "output": "1\r\n"}, {"input": "15 5\r\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2\r\n", "output": "4\r\n"}, {"input": "15 16\r\n-15 -5 -15...
false
stdio
null
true
330/B
330
B
Python 3
TESTS
10
218
307,200
78613772
n,m = map(int,input().split()) if m==0: print(n-1) for i in range(1,1000): print(1000,i) else: cond = [] for i in range(m): ai,bi = map(int,input().split()) cond.append(ai) cond.append(bi) for j in range(1,n+1): if j not in set(cond): break a=j...
43
92
0
161151674
n, m = map(int, input().split()) k = [True for i in range(n)] for i in range(m): u, v = map(int, input().split()) k[u-1] = False; k[v-1] = False for i in range(n): if k[i]: print(n-1) for j in range(n): if i != j: print(i+1, j+1) break
Codeforces Round 192 (Div. 2)
CF
2,013
2
256
Road Construction
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two r...
The first line consists of two integers n and m $$( 1 \leq n \leq 1 0 ^ { 3 }, 0 \leq m < \frac { n } { 2 } )$$. Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbere...
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi. If there are several solutions, you may prin...
null
This is one possible solution of the example: These are examples of wrong solutions:
[{"input": "4 1\n1 3", "output": "3\n1 2\n4 2\n2 3"}]
1,300
["constructive algorithms", "graphs"]
43
[{"input": "4 1\r\n1 3\r\n", "output": "3\r\n1 2\r\n4 2\r\n2 3\r\n"}, {"input": "1000 0\r\n", "output": "999\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] n, m, forbidden = read_input(input_path) with open(output_path, 'r') as f: s_ref = int(f.readline().strip()) with open(submission_path, 'r') as f: lines = f.readlines() ...
true
498/A
498
A
PyPy 3
TESTS
17
764
10,035,200
66542879
from fractions import Fraction as f R = lambda: map(int, input().split()) x1, y1 = R() x2, y2 = R() ans = 0 for _ in range(int(input())): a, b, c = map(int, input().split()) if b: x3, y3, x4, y4 = 0, f(-c, b), 1, f(-(c + a), b) else: x3, y3, x4, y4 = f(-c, a), 0, f(-(c + b), a), 1 x1, y1...
51
62
0
9247304
line = input().split() x1 = int(line[0]) y1 = int(line[1]) line = input().split() x2 = int(line[0]) y2 = int(line[1]) n = int(input()) ans = 0 for i in range(n): line = input().split() a = int(line[0]) b = int(line[1]) c = int(line[2]) d1 = (a * x1 + b * y1 + c) d2 = (a * x2 + b * y2 + c) if...
Codeforces Round 284 (Div. 1)
CF
2,014
1
256
Crazy Town
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po...
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home. The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at. The third line contains an integer n (1 ≤ n ≤ 300) — th...
Output the answer to the problem.
null
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
[{"input": "1 1\n-1 -1\n2\n0 1 0\n1 0 0", "output": "2"}, {"input": "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3", "output": "2"}]
1,700
["geometry"]
51
[{"input": "1 1\r\n-1 -1\r\n2\r\n0 1 0\r\n1 0 0\r\n", "output": "2\r\n"}, {"input": "1 1\r\n-1 -1\r\n3\r\n1 0 0\r\n0 1 0\r\n1 1 -3\r\n", "output": "2\r\n"}, {"input": "841746 527518\r\n595261 331297\r\n10\r\n-946901 129987 670374\r\n-140388 -684770 309555\r\n-302589 415564 -387435\r\n-565799 -72069 -395358\r\n-523453 -...
false
stdio
null
true
498/A
498
A
PyPy 3
TESTS
17
140
102,400
66542729
R = lambda: map(int, input().split()) x1, y1 = R() x2, y2 = R() ans = 0 for _ in range(int(input())): a, b, c = map(int, input().split()) if b: x3, y3, x4, y4 = 0, -c / b, 1, -(c + a) / b else: x3, y3, x4, y4 = -c / a, 0, -(c + b) / a, 1 x1, y1, x2, y2, x4, y4 = x1 - x3, y1 - y3, x2 - x3...
51
62
0
9250102
x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) n = int(input()) ans = 0 for i in range(n): a, b, c = map(int, input().split()) f1 = a * x1 + b * y1 + c f2 = a * x2 + b * y2 + c if f1 * f2 < 0: ans += 1 print(ans)
Codeforces Round 284 (Div. 1)
CF
2,014
1
256
Crazy Town
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po...
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home. The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at. The third line contains an integer n (1 ≤ n ≤ 300) — th...
Output the answer to the problem.
null
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
[{"input": "1 1\n-1 -1\n2\n0 1 0\n1 0 0", "output": "2"}, {"input": "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3", "output": "2"}]
1,700
["geometry"]
51
[{"input": "1 1\r\n-1 -1\r\n2\r\n0 1 0\r\n1 0 0\r\n", "output": "2\r\n"}, {"input": "1 1\r\n-1 -1\r\n3\r\n1 0 0\r\n0 1 0\r\n1 1 -3\r\n", "output": "2\r\n"}, {"input": "841746 527518\r\n595261 331297\r\n10\r\n-946901 129987 670374\r\n-140388 -684770 309555\r\n-302589 415564 -387435\r\n-565799 -72069 -395358\r\n-523453 -...
false
stdio
null
true
498/A
498
A
PyPy 3
TESTS
38
93
0
132289505
inf = 10**100 x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) one = 0 if x1==x2 and y1==y2: one=1 if x1 == x2: b = 0; a = 1; c = -x1 elif y1 == y2: a = 0; b = 1; c = -y1 else: a = 1; b = (x1-x2)/(y2-y1); c = -a*x1 - b*y1 n = int(input()) ans = 0 for i in range(n): ai...
51
62
0
9250264
ct = 0 x1, y1 = map(int, input().split(' ')) x2, y2 = map(int, input().split(' ')) for i in range(int(input())): a, b, c = map(int, input().split(' ')) if b == 0: if x1 < -c / a < x2 or x2 < -c/a < x1: ct += 1 else: b1 = y1 > (-a * x1 - c) / b b2 = y2 > (-a * x2 - c) / b ...
Codeforces Round 284 (Div. 1)
CF
2,014
1
256
Crazy Town
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po...
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home. The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at. The third line contains an integer n (1 ≤ n ≤ 300) — th...
Output the answer to the problem.
null
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
[{"input": "1 1\n-1 -1\n2\n0 1 0\n1 0 0", "output": "2"}, {"input": "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3", "output": "2"}]
1,700
["geometry"]
51
[{"input": "1 1\r\n-1 -1\r\n2\r\n0 1 0\r\n1 0 0\r\n", "output": "2\r\n"}, {"input": "1 1\r\n-1 -1\r\n3\r\n1 0 0\r\n0 1 0\r\n1 1 -3\r\n", "output": "2\r\n"}, {"input": "841746 527518\r\n595261 331297\r\n10\r\n-946901 129987 670374\r\n-140388 -684770 309555\r\n-302589 415564 -387435\r\n-565799 -72069 -395358\r\n-523453 -...
false
stdio
null
true
701/C
701
C
PyPy 3
TESTS
14
155
4,403,200
80725116
"""609C""" # import math def main(): n= int(input()) string = str(input()) k = len(set(string)) d = {} cnt = 0 i = 0 j = 0 while j<n: if d.get(string[j])==None: cnt+=1 d[string[j]]=1 else: d[string[j]]+=1 if cnt==k: break j+=1 mn = j-i+1 # print("j",j) if mn==k: print(k) return while...
80
93
3,481,600
186415659
#import sys #sys.stdin = open("pokemon.inp","r") #sys.stdout = open("pokemon.out","w") n = int(input()) s = input() dic = {} cnt = 0 for x in s: if (dic.get(x) == None): cnt += 1 dic[x] = 1 s = " " + s + " "; l = r = 1; ans = n; dic = {} dic[s[1]] = 1; d = 1; while (l <= r and r <= n): if (d =...
Codeforces Round 364 (Div. 2)
CF
2,016
2
256
They Are Everywhere
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of flats in the house. The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
null
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2. In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6. In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
[{"input": "3\nAaA", "output": "2"}, {"input": "7\nbcAAcbc", "output": "3"}, {"input": "6\naaBCCe", "output": "5"}]
1,500
["binary search", "strings", "two pointers"]
80
[{"input": "3\r\nAaA\r\n", "output": "2\r\n"}, {"input": "7\r\nbcAAcbc\r\n", "output": "3\r\n"}, {"input": "6\r\naaBCCe\r\n", "output": "5\r\n"}, {"input": "1\r\nA\r\n", "output": "1\r\n"}, {"input": "1\r\ng\r\n", "output": "1\r\n"}, {"input": "52\r\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n", "output": ...
false
stdio
null
true
701/C
701
C
Python 3
TESTS
11
545
819,200
79147051
def solve(): add = sum length = len order = sorted n = int(input()) arr = list(input()) unique = order(list(set(arr))) left_index = 0 right_index = len(unique) lowest = length(arr) queue = [x for x in arr[left_index:right_index]] letter_freq = {} for i in queue: ...
80
93
3,891,200
169541870
import sys from math import sqrt, gcd, factorial, ceil, floor, pi, inf from collections import deque, Counter, OrderedDict from heapq import heapify, heappush, heappop #sys.setrecursionlimit(10**5) #======================================================# input = lambda: sys.stdin.readline() I = lambda: int(input().str...
Codeforces Round 364 (Div. 2)
CF
2,016
2
256
They Are Everywhere
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of flats in the house. The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
null
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2. In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6. In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
[{"input": "3\nAaA", "output": "2"}, {"input": "7\nbcAAcbc", "output": "3"}, {"input": "6\naaBCCe", "output": "5"}]
1,500
["binary search", "strings", "two pointers"]
80
[{"input": "3\r\nAaA\r\n", "output": "2\r\n"}, {"input": "7\r\nbcAAcbc\r\n", "output": "3\r\n"}, {"input": "6\r\naaBCCe\r\n", "output": "5\r\n"}, {"input": "1\r\nA\r\n", "output": "1\r\n"}, {"input": "1\r\ng\r\n", "output": "1\r\n"}, {"input": "52\r\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n", "output": ...
false
stdio
null
true
863/F
863
F
PyPy 3
TESTS
9
280
4,505,600
82734691
import sys readline = sys.stdin.readline from heapq import heappop as hpp, heappush as hp class MinCostFlowwithDijkstra: INF = 1<<60 def __init__(self, N): self.N = N self.Edge = [[] for _ in range(N)] def add_edge(self, st, en, cap, cost): self.Edge[st].append([en, cap, c...
45
280
1,843,200
183071417
import math import heapq import math class MCF: def __init__(self): self.edges = {} self.edge_indexes = {} self.source = 0 self.sink = 1 self.nodes = set() self.sources = set() self.sinks = set() self.visiting = dict() self.dijkstra_path = di...
Educational Codeforces Round 29
ICPC
2,017
3
512
Almost Permutation
Recently Ivan noticed an array a while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reproduce the bug. Ivan clearly remembers that there were n elements in the array, and each element was not less...
The first line contains two integer numbers n and q (1 ≤ n ≤ 50, 0 ≤ q ≤ 100). Then q lines follow, each representing a fact about the array. i-th line contains the numbers ti, li, ri and vi for i-th fact (1 ≤ ti ≤ 2, 1 ≤ li ≤ ri ≤ n, 1 ≤ vi ≤ n, ti denotes the type of the fact).
If the facts are controversial and there is no array that corresponds to them, print -1. Otherwise, print minimum possible cost of the array.
null
null
[{"input": "3 0", "output": "3"}, {"input": "3 1\n1 1 3 2", "output": "5"}, {"input": "3 2\n1 1 3 2\n2 1 3 2", "output": "9"}, {"input": "3 2\n1 1 3 2\n2 1 3 1", "output": "-1"}]
2,200
["flows"]
45
[{"input": "3 0\r\n", "output": "3\r\n"}, {"input": "3 1\r\n1 1 3 2\r\n", "output": "5\r\n"}, {"input": "3 2\r\n1 1 3 2\r\n2 1 3 2\r\n", "output": "9\r\n"}, {"input": "3 2\r\n1 1 3 2\r\n2 1 3 1\r\n", "output": "-1\r\n"}, {"input": "50 0\r\n", "output": "50\r\n"}, {"input": "50 1\r\n2 31 38 25\r\n", "output": "50\r\n"},...
false
stdio
null
true
618/C
618
C
Python 3
TESTS
14
483
13,824,000
120862285
def side_len(p0, p1): return ( (p1[0] - p0[0])**2 + (p1[1] - p0[1])**2 )**0.5 def triangle_area(a, b, c): p = (a+b+c)/2 return (p*(p-a)*(p-b)*(p-c))**0.5 vertices = [] n = int(input()) for i in range(n): point = list(map(int, input().split())) vertices.append(point) for i in range(n): v1 = vertices[i] ...
98
639
10,956,800
15666269
p = sorted(tuple(map(int, input().split())) + (i + 1,) for i in range(int(input()))) x1, y1 = p[1][0] - p[0][0], p[1][1] - p[0][1] for i in range(2, len(p)): if x1 == 0 and p[i][0] == p[1][0]: continue elif x1 and p[i][0] != p[1][0]: x2, y2 = p[i][0] - p[1][0], p[i][1] - p[1][1] if x1 * ...
Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)
CF
2,016
2
256
Constellation
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position. In the evening Noku is going to take a look at the night sky. He would like to find three d...
The first line of the input contains a single integer n (3 ≤ n ≤ 100 000). Each of the next n lines contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109). It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Print three distinct integers on a single line — the indices of the three points that form a triangle that satisfies the conditions stated in the problem. If there are multiple possible answers, you may print any of them.
null
In the first sample, we can print the three indices in any order. In the second sample, we have the following picture. Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
[{"input": "3\n0 1\n1 0\n1 1", "output": "1 2 3"}, {"input": "5\n0 0\n0 2\n2 0\n2 2\n1 1", "output": "1 3 5"}]
1,600
["geometry", "implementation"]
98
[{"input": "3\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "1 2 3\r\n"}, {"input": "5\r\n0 0\r\n0 2\r\n2 0\r\n2 2\r\n1 1\r\n", "output": "1 3 5\r\n"}, {"input": "3\r\n819934317 939682125\r\n487662889 8614219\r\n-557136619 382982369\r\n", "output": "1 3 2\r\n"}, {"input": "10\r\n25280705 121178189\r\n219147240 -570920213\r\n-82...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input points with open(input_path, 'r') as f: n = int(f.readline().strip()) points = [] for _ in range(n): x, y = map(int, f.readline().strip().split()) points.append((x, y)) # Read su...
true
352/A
352
A
Python 3
TESTS
8
62
0
196844908
n = int(input()) a = sorted(input().split(), reverse=True) num = ''.join(a) ans = int(num) while ans >= 0: if ans % 90 == 0: print(ans) break ans //= 100 if ans == 0 and '0' not in num: print(-1) break if '0' in num: ans *= 10 else: ans = ans * 10 + 5...
42
92
0
4668504
n = int(input()) a = list(map(int, input().split())) count0 = 0 count5 = 0 for i in range(n): if a[i] == 5: count5 += 1 else: count0 += 1 if count0 == 0: print(-1) elif count5 < 9: print(0) else: print('5' * (count5 - count5 % 9) + '0' * count0)
Codeforces Round 204 (Div. 2)
CF
2,013
1
256
Jeff and Digits
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that number ...
The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
null
In the first test you can make only one number that is a multiple of 90 — 0. In the second test you can make number 5555555550, it is a multiple of 90.
[{"input": "4\n5 0 5 0", "output": "0"}, {"input": "11\n5 5 5 5 5 5 5 5 0 5 5", "output": "5555555550"}]
1,000
["brute force", "implementation", "math"]
42
[{"input": "4\r\n5 0 5 0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 0 5 5\r\n", "output": "5555555550\r\n"}, {"input": "7\r\n5 5 5 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n5\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 0 5 5 5 0 0 5 5 5 5\r\n", "out...
false
stdio
null
true
463/A
463
A
Python 3
TESTS
8
62
0
137737581
n, s = map(int, input().split()) res = -1 for i in range(n): d, c = map(int, input().split()) if c == 0: res = max(res, 0) elif s > d: res = max(res, 100 - c) print(res)
35
61
0
165489399
r=lambda:map(int,input().split()) n,s=r() ans=-1 s*=100 while n: n-=1 x,y=r() x=x*100+y if x<=s: ans=max(ans,(s-x)%100) print(ans)
Codeforces Round 264 (Div. 2)
CF
2,014
1
256
Caisa and Sugar
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town. Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But t...
The first line contains two space-separated integers n, s (1 ≤ n, s ≤ 100). The i-th of the next n lines contains two integers xi, yi (1 ≤ xi ≤ 100; 0 ≤ yi < 100), where xi represents the number of dollars and yi the number of cents needed in order to buy the i-th type of sugar.
Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.
null
In the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change.
[{"input": "5 10\n3 90\n12 0\n9 70\n5 50\n7 0", "output": "50"}, {"input": "5 5\n10 10\n20 20\n30 30\n40 40\n50 50", "output": "-1"}]
1,200
["brute force", "implementation"]
35
[{"input": "5 10\r\n3 90\r\n12 0\r\n9 70\r\n5 50\r\n7 0\r\n", "output": "50\r\n"}, {"input": "5 5\r\n10 10\r\n20 20\r\n30 30\r\n40 40\r\n50 50\r\n", "output": "-1\r\n"}, {"input": "1 2\r\n1 0\r\n", "output": "0\r\n"}, {"input": "2 10\r\n20 99\r\n30 99\r\n", "output": "-1\r\n"}, {"input": "15 21\r\n16 51\r\n33 44\r\n32 ...
false
stdio
null
true
747/D
747
D
Python 3
TESTS
11
202
13,824,000
23202463
#!/usr/bin/env python3 def ri(): return map(int, input().split()) n, k = ri() t = list(ri()) tt = [] mc = 0 for i in range(n): if i == 0: if t[i] < 0: tt.append(-1) mc += 1 else: tt.append(1) continue if t[i] < 0: mc += 1 if t[i-1...
59
514
36,659,200
157807204
import copy import gc import itertools from array import array from fractions import Fraction import heapq import math import operator import os, sys import profile import cProfile import random import re import string from bisect import bisect_left, bisect_right from collections import defaultdict, deque, Counter from...
Codeforces Round 387 (Div. 2)
CF
2,016
1
256
Winter Is Coming
The winter in Berland lasts n days. For each day we know the forecast for the average air temperature that day. Vasya has a new set of winter tires which allows him to drive safely no more than k days at any average air temperature. After k days of using it (regardless of the temperature of these days) the set of wint...
The first line contains two positive integers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — the number of winter days and the number of days winter tires can be used. It is allowed to drive on winter tires at any temperature, but no more than k days in total. The second line contains a sequence of n integers t1, t2, ..., tn ( ...
Print the minimum number of times Vasya has to change summer tires to winter tires and vice versa to drive safely during all winter. If it is impossible, print -1.
null
In the first example before the first winter day Vasya should change summer tires to winter tires, use it for three days, and then change winter tires to summer tires because he can drive safely with the winter tires for just three days. Thus, the total number of tires' changes equals two. In the second example before...
[{"input": "4 3\n-5 20 -3 0", "output": "2"}, {"input": "4 2\n-5 20 -3 0", "output": "4"}, {"input": "10 6\n2 -5 1 3 0 0 -4 -3 1 0", "output": "3"}]
1,800
["dp", "greedy", "sortings"]
59
[{"input": "4 3\r\n-5 20 -3 0\r\n", "output": "2\r\n"}, {"input": "4 2\r\n-5 20 -3 0\r\n", "output": "4\r\n"}, {"input": "10 6\r\n2 -5 1 3 0 0 -4 -3 1 0\r\n", "output": "3\r\n"}, {"input": "4 4\r\n-5 20 -3 0\r\n", "output": "1\r\n"}, {"input": "4 1\r\n-5 20 -3 0\r\n", "output": "-1\r\n"}, {"input": "1 0\r\n-13\r\n", "o...
false
stdio
null
true
106/B
106
B
Python 3
TESTS
22
62
0
153667656
n= int(input()) position = 0 def find_base(mat): a, b, c = 0,0,0 for i in mat: if(a<i[0] and b<i[1] and c<i[2]): a,b,c = i[0],i[1],i[2] return a,b,c mat = [] for i in range(n): mat.append(list(map(int, input().split()))) a,b,c = find_base(mat) price = 1001 for i in range(n): ...
55
92
0
136805239
import itertools cases = int(input()) full_list = [[*map(lambda x: int(x), input().split())] for i in range(cases)] def laptop_finder(full_list): a = list(full_list) to_remove = [] for i in a: for n in a: if i[0] < n[0] and i[1] < n[1] and i[2] < n[2]: to_remove.append(...
Codeforces Beta Round 82 (Div. 2)
CF
2,011
2
256
Choosing Laptop
Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties ...
The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, - speed, ram, hdd and cost are integers - 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz - 256 ≤ ram ≤ 4096 the RAM volume in megabytes - 1 ≤ hdd ≤ 500 is the HDD in gigabytes - 100 ...
Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data.
null
In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
[{"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "output": "4"}]
1,000
["brute force", "implementation"]
55
[{"input": "5\r\n2100 512 150 200\r\n2000 2048 240 350\r\n2300 1024 200 320\r\n2500 2048 80 300\r\n2000 512 180 150\r\n", "output": "4"}, {"input": "2\r\n1500 500 50 755\r\n1600 600 80 700\r\n", "output": "2"}, {"input": "2\r\n1500 512 50 567\r\n1600 400 70 789\r\n", "output": "1"}, {"input": "4\r\n1000 300 5 700\r\n11...
false
stdio
null
true
106/B
106
B
PyPy 3-64
TESTS
22
216
512,000
143122797
import math,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353 n =I() sp,rp,hp,cp = 0,0,0,1001 indexp = -1 values = [] for i in range(n): s,r,h,c = M() values.append([s,r,h,c]) if s>sp and r>rp and h>hp: ...
55
92
0
138611091
n=int(input()) a=[] for i in range(n): a.append([int(x) for x in input().split()]) res=[] for i in range(n): check=1 for j in range(n): if a[i][0]<a[j][0] and a[i][1]<a[j][1] and a[i][2]<a[j][2]: check=0 break if check==1: res.append(i) if len(res)==0: ans,pos=a[0][3],0 for i in rang...
Codeforces Beta Round 82 (Div. 2)
CF
2,011
2
256
Choosing Laptop
Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties ...
The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, - speed, ram, hdd and cost are integers - 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz - 256 ≤ ram ≤ 4096 the RAM volume in megabytes - 1 ≤ hdd ≤ 500 is the HDD in gigabytes - 100 ...
Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data.
null
In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
[{"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "output": "4"}]
1,000
["brute force", "implementation"]
55
[{"input": "5\r\n2100 512 150 200\r\n2000 2048 240 350\r\n2300 1024 200 320\r\n2500 2048 80 300\r\n2000 512 180 150\r\n", "output": "4"}, {"input": "2\r\n1500 500 50 755\r\n1600 600 80 700\r\n", "output": "2"}, {"input": "2\r\n1500 512 50 567\r\n1600 400 70 789\r\n", "output": "1"}, {"input": "4\r\n1000 300 5 700\r\n11...
false
stdio
null
true
534/D
534
D
Python 3
TESTS
7
62
0
117322907
n=int(input());s=input().split() def cmp(a): return int(s[a]) l=[[],[],[]];ans=[] for i in range(n): l[int(s[i])%3].append(i) for i in range(3): l[i].sort(key=cmp,reverse=True) try: for i in range(n): ans.append(l[i%3].pop()) for i in range(1,n): k=int(s[ans[i]])-int(s[ans[i-1]]) ...
85
514
50,995,200
32948897
n = int(input()) d = [[] for i in range(n)] for i, q in enumerate(input().split(), 1): d[int(q)] += [i] q = j = 0 t = [0] * n while j < n and q >= 0: if d[q]: t[j] = d[q].pop() q += 1 j += 1 else: q -= 3 if q < 0: print('Impossible') else: print('Possible', *t)
Codeforces Round 298 (Div. 2)
CF
2,015
1
256
Handshakes
On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came in...
The first line contains integer n (1 ≤ n ≤ 2·105) — the number of students who came to CTOP. The next line contains n integers a1, a2, ..., an (0 ≤ ai < n), where ai is the number of students with who the i-th student shook hands.
If the sought order of students exists, print in the first line "Possible" and in the second line print the permutation of the students' numbers defining the order in which the students entered the center. Number i that stands to the left of number j in this permutation means that the i-th student came earlier than the...
null
In the first sample from the statement the order of events could be as follows: - student 4 comes in (a4 = 0), he has no one to greet; - student 5 comes in (a5 = 1), he shakes hands with student 4; - student 1 comes in (a1 = 2), he shakes hands with two students (students 4, 5); - student 3 comes in (a3 = 3), he shake...
[{"input": "5\n2 1 3 0 1", "output": "Possible\n4 5 1 3 2"}, {"input": "9\n0 2 3 4 1 1 0 2 2", "output": "Possible\n7 5 2 1 6 8 3 4 9"}, {"input": "4\n0 2 1 1", "output": "Impossible"}]
1,900
["binary search", "constructive algorithms", "data structures", "greedy"]
85
[{"input": "5\r\n2 1 3 0 1\r\n", "output": "Possible\r\n4 5 1 3 2 "}, {"input": "9\r\n0 2 3 4 1 1 0 2 2\r\n", "output": "Possible\r\n7 6 9 3 4 8 1 5 2 "}, {"input": "4\r\n0 2 1 1\r\n", "output": "Impossible\r\n"}, {"input": "5\r\n1 0 2 1 0\r\n", "output": "Possible\r\n5 4 3 2 1 "}, {"input": "1\r\n0\r\n", "output": "Po...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) a_dict = {i+1: a[i] for i in range(n)} # Read submission output with open(submission_path) as f: lines = [l...
true
230/A
230
A
Python 3
TESTS
8
92
102,400
230283430
a,b=map(int,input().split()) aa=a l=[] k=[] p=[] for i in range(b): d=list(map(int,input().split())) l.append(d) l.sort(key=lambda x: x[0]) count=0 for i in range(len(l)): if(a>l[i][0]): a+=l[i][1] for i in range(len(l)): aa+=l[i][1] if(a==aa): print("YES") else: print("NO")
54
92
0
230359005
s, n = map(int, input().split()) dragons = [] for i in range(n): x,y = map(int, input().split()) dragons.append((x,y)) dragons.sort() for i in dragons: if s > i[0]: s += i[1] else: print('NO') break else: print('YES')
Codeforces Round 142 (Div. 2)
CF
2,012
2
256
Dragons
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'...
The first line contains two space-separated integers s and n (1 ≤ s ≤ 104, 1 ≤ n ≤ 103). Then n lines follow: the i-th line contains space-separated integers xi and yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — the i-th dragon's strength and the bonus for defeating it.
On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.
null
In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level. In the second sample Kirito's strength ...
[{"input": "2 2\n1 99\n100 0", "output": "YES"}, {"input": "10 1\n100 100", "output": "NO"}]
1,000
["greedy", "sortings"]
54
[{"input": "2 2\r\n1 99\r\n100 0\r\n", "output": "YES\r\n"}, {"input": "10 1\r\n100 100\r\n", "output": "NO\r\n"}, {"input": "123 2\r\n78 10\r\n130 0\r\n", "output": "YES\r\n"}, {"input": "999 2\r\n1010 10\r\n67 89\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 1\r\n2 1\r\n3 1\r\n1 1\r\n4 1\r\n", "output": "YES\r\n"},...
false
stdio
null
true
230/A
230
A
Python 3
TESTS
8
92
0
227520877
s,n=map(int,input().split()) ds=[0]*n b=[0]*n for i in range(n): ds[i],b[i]=map(int,input().split()) arr=ds.copy() arr.sort() flag=1 # print(arr[0]) for i in range(n): if s>=arr[i]: s+=b[ds.index(arr[i])] else: flag=0 break if flag==1: print("YES") else: print("NO")
54
92
0
230575963
s,n = list(map(int,input().split())) d = [tuple(map(int,input().split())) for i in range(n)] d.sort() for j in d: if s>j[0]: s+=j[1] else: print("NO") break else: print("YES")
Codeforces Round 142 (Div. 2)
CF
2,012
2
256
Dragons
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'...
The first line contains two space-separated integers s and n (1 ≤ s ≤ 104, 1 ≤ n ≤ 103). Then n lines follow: the i-th line contains space-separated integers xi and yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — the i-th dragon's strength and the bonus for defeating it.
On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.
null
In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level. In the second sample Kirito's strength ...
[{"input": "2 2\n1 99\n100 0", "output": "YES"}, {"input": "10 1\n100 100", "output": "NO"}]
1,000
["greedy", "sortings"]
54
[{"input": "2 2\r\n1 99\r\n100 0\r\n", "output": "YES\r\n"}, {"input": "10 1\r\n100 100\r\n", "output": "NO\r\n"}, {"input": "123 2\r\n78 10\r\n130 0\r\n", "output": "YES\r\n"}, {"input": "999 2\r\n1010 10\r\n67 89\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 1\r\n2 1\r\n3 1\r\n1 1\r\n4 1\r\n", "output": "YES\r\n"},...
false
stdio
null
true
107/B
107
B
PyPy 3-64
TESTS
42
62
0
199003050
def nCr(n, r): s = 1 for i in range(1, r+1): s = s * (n - r + i) / i return s def sol(): n, m, h = map(int, input().split()) a = list(map(int, input().split())) n -= 1 a[h - 1] -= 1 total = sum(a) if total < n: print(-1) return totalM = total - a[h - 1] ...
60
46
0
161224637
n, m, h = map(int, input().split()) s = list(map(int, input().split())) s[h-1] = s[h-1] - 1 total = sum(s) tot_withoutwafadep = total - s[h-1] n = n - 1 if total<n: print(-1) exit() result = 1 res_two = 1 for i in range(n): result = result * (tot_withoutwafadep - i) res_two = res_two * (total - i) print...
Codeforces Beta Round 83 (Div. 1 Only)
CF
2,011
1
256
Basketball Team
As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different...
The first line contains three integers n, m and h (1 ≤ n ≤ 100, 1 ≤ m ≤ 1000, 1 ≤ h ≤ m) — the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≤ si ≤ 100), denoting the number of stud...
Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.
null
In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possi...
[{"input": "3 2 1\n2 1", "output": "1"}, {"input": "3 2 1\n1 1", "output": "-1"}, {"input": "3 2 1\n2 2", "output": "0.666667"}]
1,600
["combinatorics", "dp", "math", "probabilities"]
60
[{"input": "3 2 1\r\n2 1\r\n", "output": "1.0\r\n"}, {"input": "3 2 1\r\n1 1\r\n", "output": "-1.0\r\n"}, {"input": "3 2 1\r\n2 2\r\n", "output": "0.6666666666666667\r\n"}, {"input": "3 2 1\r\n1 2\r\n", "output": "0.0\r\n"}, {"input": "6 5 3\r\n5 2 3 10 5\r\n", "output": "0.3804347826086957\r\n"}, {"input": "7 10 6\r\n...
false
stdio
import sys def read_input(input_path): with open(input_path) as f: line1 = f.readline().strip().split() n, m, h = map(int, line1) s = list(map(int, f.readline().strip().split())) return n, m, h, s def compute_correct_answer(n, m, h, s): sum_s = sum(s) s_h = s[h-1] if su...
true
106/B
106
B
Python 3
TESTS
24
92
0
153666698
n= int(input()) position = 0 a, b, c, d = 0,0,0,0 for i in range(n): a1, b1, c1, d1 = map(int, input().split()) if(a<a1 and b<b1 and c<c1): a,b,c,d = a1,b1,c1,d1 position = i+1 elif(a>a1 and b>b1 and c>c1): next elif(d1<d): d = d1 position = i+1 print(pos...
55
92
0
149697311
def main(): n = int(input()) arr = [] for i in range(n): arr.append([int(x) for x in input().split()]) arr[i].append(i) for i in range(n): for j in range(n): if ( arr[i][0] < arr[j][0] and arr[i][1] < arr[j][1] and arr[i...
Codeforces Beta Round 82 (Div. 2)
CF
2,011
2
256
Choosing Laptop
Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties ...
The first line contains number n (1 ≤ n ≤ 100). Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides, - speed, ram, hdd and cost are integers - 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz - 256 ≤ ram ≤ 4096 the RAM volume in megabytes - 1 ≤ hdd ≤ 500 is the HDD in gigabytes - 100 ...
Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data.
null
In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
[{"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "output": "4"}]
1,000
["brute force", "implementation"]
55
[{"input": "5\r\n2100 512 150 200\r\n2000 2048 240 350\r\n2300 1024 200 320\r\n2500 2048 80 300\r\n2000 512 180 150\r\n", "output": "4"}, {"input": "2\r\n1500 500 50 755\r\n1600 600 80 700\r\n", "output": "2"}, {"input": "2\r\n1500 512 50 567\r\n1600 400 70 789\r\n", "output": "1"}, {"input": "4\r\n1000 300 5 700\r\n11...
false
stdio
null
true
441/B
441
B
Python 3
TESTS
4
31
409,600
228812883
n, v = map(int, input().split()) arr=[] fruits=dict() for i in range(n): a, b = map(int, input().split()) if a not in fruits: fruits[a]=b arr.append(a) else: fruits[a]=fruits[a]+b arr.sort() total=0 prev=0 for i in range(len(arr)): if (prev+fruits[arr[i]])<=v: total+=frui...
51
46
614,400
224653853
from collections import defaultdict n,v=map(int,input().split()) hashmap=[0]*(30002) m=-1 for _ in range(n): a,b=map(int,input().split()) hashmap[a]+=b m=max(m,a) ans=0 for i in range(1,m+2): took=0 # print(hashmap[i-1],'#') if hashmap[i-1]>0: took=min(hashmap[i-1],v) hashmap[i-1...
Codeforces Round 252 (Div. 2)
CF
2,014
1
256
Valera and Fruits
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,...
The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 30...
Print a single integer — the maximum number of fruit that Valera can collect.
null
In the first sample, in order to obtain the optimal answer, you should act as follows. - On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree. In the second sampl...
[{"input": "2 3\n1 5\n2 3", "output": "8"}, {"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60"}]
1,400
["greedy", "implementation"]
51
[{"input": "2 3\r\n1 5\r\n2 3\r\n", "output": "8\r\n"}, {"input": "5 10\r\n3 20\r\n2 20\r\n1 20\r\n4 20\r\n5 20\r\n", "output": "60\r\n"}, {"input": "10 3000\r\n1 2522\r\n4 445\r\n8 1629\r\n5 772\r\n9 2497\r\n6 81\r\n3 426\r\n7 1447\r\n2 575\r\n10 202\r\n", "output": "10596\r\n"}, {"input": "5 3000\r\n5 772\r\n1 2522\r...
false
stdio
null
true
638/C
638
C
Python 3
PRETESTS
11
919
41,062,400
16845594
n = int(input()) res = [0] roads = [] for i in range(n-1): roads.append(input().split()+[0]) fl = True while(fl): fl = False curN = set() croads = [] for i, it in enumerate(roads): if it[2] == 0 and it[0] not in curN and it[1] not in curN: fl = True roads[i][2] = 1 ...
132
888
99,123,200
197272233
import sys from array import array input = lambda: sys.stdin.buffer.readline().decode().strip() inp = lambda dtype: [dtype(x) for x in input().split()] debug = lambda *x: print(*x, file=sys.stderr) ceil_ = lambda a, b: (a + b - 1) // b sum_n = lambda n: (n * (n + 1)) // 2 get_bit = lambda x, i: (x >> i) & 1 Mint, Mlon...
VK Cup 2016 - Qualification Round 2
CF
2,016
2
256
Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
The first line of the input contains a positive integer n (2 ≤ n ≤ 200 000) — the number of cities in Berland. Each of the next n - 1 lines contains two numbers ui, vi, meaning that the i-th road connects city ui and city vi (1 ≤ ui, vi ≤ n, ui ≠ vi).
First print number k — the minimum number of days needed to repair all the roads in Berland. In next k lines print the description of the roads that should be repaired on each of the k days. On the i-th line print first number di — the number of roads that should be repaired on the i-th day, and then di space-separate...
null
In the first sample you can repair all the roads in two days, for example, if you repair roads 1 and 2 on the first day and road 3 — on the second day.
[{"input": "4\n1 2\n3 4\n3 2", "output": "2\n2 2 1\n1 3"}, {"input": "6\n3 4\n5 4\n3 2\n1 3\n4 6", "output": "3\n1 1\n2 2 3\n2 4 5"}]
1,800
["*special", "dfs and similar", "graphs", "greedy", "trees"]
132
[{"input": "4\r\n1 2\r\n3 4\r\n3 2\r\n", "output": "2\r\n2 1 2 \r\n1 3 \r\n"}, {"input": "6\r\n3 4\r\n5 4\r\n3 2\r\n1 3\r\n4 6\r\n", "output": "3\r\n1 1 \r\n2 2 3 \r\n2 4 5 \r\n"}, {"input": "8\r\n1 3\r\n1 6\r\n3 4\r\n6 2\r\n5 6\r\n6 7\r\n7 8\r\n", "output": "4\r\n3 2 3 7 \r\n2 1 4 \r\n1 5 \r\n1 6 \r\n"}, {"input": "5\...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input roads with open(input_path, 'r') as f: lines = [l.strip() for l in f.readlines() if l.strip()] n = int(lines[0]) input_roads = [] for line in lines[1:1 + (n-1)]: u, v = map(int, line.split()) input_r...
true
638/C
638
C
Python 3
PRETESTS
11
1,856
43,008,000
16846647
#!/usr/bin/python3 n = int(input()) degrees = [0 for i in range(n)] max_deg = 0 adj = [list() for i in range(n)] roads = [] for i in range(n-1): f,t = map(int, input().split()) f -= 1 t -= 1 degrees[f] += 1 degrees[t] += 1 max_deg = max(max_deg, degrees[f], degrees[t]) roads.append((f, t)) adj[f].append(t...
132
888
99,123,200
197272233
import sys from array import array input = lambda: sys.stdin.buffer.readline().decode().strip() inp = lambda dtype: [dtype(x) for x in input().split()] debug = lambda *x: print(*x, file=sys.stderr) ceil_ = lambda a, b: (a + b - 1) // b sum_n = lambda n: (n * (n + 1)) // 2 get_bit = lambda x, i: (x >> i) & 1 Mint, Mlon...
VK Cup 2016 - Qualification Round 2
CF
2,016
2
256
Road Improvement
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simulta...
The first line of the input contains a positive integer n (2 ≤ n ≤ 200 000) — the number of cities in Berland. Each of the next n - 1 lines contains two numbers ui, vi, meaning that the i-th road connects city ui and city vi (1 ≤ ui, vi ≤ n, ui ≠ vi).
First print number k — the minimum number of days needed to repair all the roads in Berland. In next k lines print the description of the roads that should be repaired on each of the k days. On the i-th line print first number di — the number of roads that should be repaired on the i-th day, and then di space-separate...
null
In the first sample you can repair all the roads in two days, for example, if you repair roads 1 and 2 on the first day and road 3 — on the second day.
[{"input": "4\n1 2\n3 4\n3 2", "output": "2\n2 2 1\n1 3"}, {"input": "6\n3 4\n5 4\n3 2\n1 3\n4 6", "output": "3\n1 1\n2 2 3\n2 4 5"}]
1,800
["*special", "dfs and similar", "graphs", "greedy", "trees"]
132
[{"input": "4\r\n1 2\r\n3 4\r\n3 2\r\n", "output": "2\r\n2 1 2 \r\n1 3 \r\n"}, {"input": "6\r\n3 4\r\n5 4\r\n3 2\r\n1 3\r\n4 6\r\n", "output": "3\r\n1 1 \r\n2 2 3 \r\n2 4 5 \r\n"}, {"input": "8\r\n1 3\r\n1 6\r\n3 4\r\n6 2\r\n5 6\r\n6 7\r\n7 8\r\n", "output": "4\r\n3 2 3 7 \r\n2 1 4 \r\n1 5 \r\n1 6 \r\n"}, {"input": "5\...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input roads with open(input_path, 'r') as f: lines = [l.strip() for l in f.readlines() if l.strip()] n = int(lines[0]) input_roads = [] for line in lines[1:1 + (n-1)]: u, v = map(int, line.split()) input_r...
true
837/F
837
F
Python 3
TESTS
3
467
3,891,200
68390581
n, k = map(int,input().split()) a = list(map(int,input().split())) def check(x): if x==0: return max(a) >= k binomial = 1 sum = 0 for i in range(n): if binomial >= k: return True sum += binomial * a[n-i-1] binomial *= (x+i) binomial //= (i+1) if sum >= k: return T...
40
218
23,040,000
203452069
import sys from collections import deque input = sys.stdin.readline def fgh(): return [int(xx) for xx in input().split()] def fg(): return int(input()) n, ok = fgh() a = fgh() if max(a) >= ok: print(0) quit() if n == 2: print((ok - a[1] + a[0] - 1) // a[0]) quit() fac = [1] for i in range(1, 200...
Educational Codeforces Round 26
ICPC
2,017
1
256
Prefix Sums
Consider the function p(x), where x is an array of m integers, which returns an array y consisting of m + 1 integers such that yi is equal to the sum of first i elements of array x (0 ≤ i ≤ m). You have an infinite sequence of arrays A0, A1, A2..., where A0 is given in the input, and for each i ≥ 1 Ai = p(Ai - 1). Als...
The first line contains two integers n and k (2 ≤ n ≤ 200000, 1 ≤ k ≤ 1018). n is the size of array A0. The second line contains n integers A00, A01... A0n - 1 — the elements of A0 (0 ≤ A0i ≤ 109). At least two elements of A0 are positive.
Print the minimum i such that Ai contains a number which is larger or equal than k.
null
null
[{"input": "2 2\n1 1", "output": "1"}, {"input": "3 6\n1 1 1", "output": "2"}, {"input": "3 1\n1 0 1", "output": "0"}]
2,400
["binary search", "brute force", "combinatorics", "math", "matrices"]
40
[{"input": "2 2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "3 6\r\n1 1 1\r\n", "output": "2\r\n"}, {"input": "3 1\r\n1 0 1\r\n", "output": "0\r\n"}, {"input": "3 1000000000000000000\r\n5 4 5\r\n", "output": "632455531\r\n"}, {"input": "4 1000000000000000000\r\n0 4 4 5\r\n", "output": "707106780\r\n"}, {"input": "5 1000...
false
stdio
null
true
671/A
671
A
Python 3
TESTS
3
46
4,812,800
18096306
from math import sqrt ax, ay, bx, by, tx, ty = map(int, input().split()) n = int(input()) dist = list() adist = list() bdist = list() for i in range(n): x, y = map(int, input().split()) dist.append((tx - x) ** 2 + (ty - y) ** 2) # print(dist[i], (ax - x) ** 2 + (ay - y) ** 2) adist.append((dist[i] - (...
148
1,684
28,364,800
18035361
ax, ay, bx, by, tx, ty = map(int, input().split()) n = int(input()) X = [0] * n Y = [0] * n T = [0.0] * n res = 0.0 for i in range(n): X[i], Y[i] = map(int, input().split()) T[i] = ((X[i] - tx) ** 2 + (Y[i] - ty) ** 2) ** 0.5 res += T[i] * 2 L1 = [[0]] * (n + 2) L2 = [[0]] * (n + 2) fo...
Codeforces Round 352 (Div. 1)
CF
2,016
2
256
Recycling Bottles
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c...
First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively. The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground. Then follow n lines, each of them contains t...
Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checke...
null
Consider the first sample. Adil will use the following path: $$(3,1)\rightarrow(2,1)\rightarrow(0,0)\rightarrow(1,1)\rightarrow(0,0)$$. Bera will use the following path: $$(1,2)\rightarrow(2,3)\rightarrow(0,0)$$. Adil's path will be $$1 + \sqrt{5} + \sqrt{2} + \sqrt{2}$$ units long, while Bera's path will be $$\sqrt...
[{"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "output": "11.084259940083"}, {"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "output": "33.121375178000"}]
1,800
["dp", "geometry", "greedy", "implementation"]
148
[{"input": "3 1 1 2 0 0\r\n3\r\n1 1\r\n2 1\r\n2 3\r\n", "output": "11.084259940083\r\n"}, {"input": "5 0 4 2 2 0\r\n5\r\n5 2\r\n3 0\r\n5 5\r\n3 5\r\n3 3\r\n", "output": "33.121375178000\r\n"}, {"input": "107 50 116 37 104 118\r\n12\r\n16 78\r\n95 113\r\n112 84\r\n5 88\r\n54 85\r\n112 80\r\n19 98\r\n25 14\r\n48 76\r\n95...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path) as f: correct = f.read().strip() with open(submission_path) as f: submission = f.read().strip() try: correct_val = float(correct) subm...
true
352/A
352
A
Python 3
TESTS
9
92
6,963,200
130766526
n= int(input()) arr= list(map(int,input().split())) five=0 for i in arr: if i==5: five+=1 total= five*5 zero= n-five if total%9==0 and zero>=1 : ans= '5'*five +'0'*zero elif total>45 and zero>=1: while total%9!=0: total-=5 five-=1 ans='5'*five +'0'*zero else: ...
42
92
0
4668631
n = int(input()) arr = list(map(int, input().split())) fives = 0 if 5 in arr: fives = arr.count(5) nulls = n - fives fives -= fives % 9 if nulls == 0 : print(-1) else: print(int(str(5) * fives + str(0) * nulls))
Codeforces Round 204 (Div. 2)
CF
2,013
1
256
Jeff and Digits
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that number ...
The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
null
In the first test you can make only one number that is a multiple of 90 — 0. In the second test you can make number 5555555550, it is a multiple of 90.
[{"input": "4\n5 0 5 0", "output": "0"}, {"input": "11\n5 5 5 5 5 5 5 5 0 5 5", "output": "5555555550"}]
1,000
["brute force", "implementation", "math"]
42
[{"input": "4\r\n5 0 5 0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 0 5 5\r\n", "output": "5555555550\r\n"}, {"input": "7\r\n5 5 5 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n5\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 0 5 5 5 0 0 5 5 5 5\r\n", "out...
false
stdio
null
true
743/A
743
A
PyPy 3
TESTS
34
171
1,945,600
73699479
n, a, b = map(int, input().split()) s = input() mi = 10**9 o = -10**18 z = -10**18 for i in range(1, n): if s[i] == '1': o = i mi = min(mi, i-z) elif s[i] == '0': z = i mi = min(mi, i-o) if s[a-1] == s[b-1]: mi = 0 print(mi)
56
46
0
178955894
n, a, b = map(int, input().split()) s = input() # Если аэропорты a и b принадлежат одной компании, то ответ равен 0. # Иначе найдется два соседних аэропорта, принадлежащие разным компаниям, # рассмотрим их. Долетим бесплатно до одного из этих аэропортов, # перелетим заплатив 1 в другой и из него бесплатно в b. # А зна...
Codeforces Round 384 (Div. 2)
CF
2,016
2
256
Vladik and flights
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad. Vladik knows n airports. All the airports are located on a straight line. Each airport has uni...
The first line contains three integers n, a, and b (1 ≤ n ≤ 105, 1 ≤ a, b ≤ n) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach. The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th char...
Print single integer — the minimum cost Vladik has to pay to get to the olympiad.
null
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to th...
[{"input": "4 1 4\n1010", "output": "1"}, {"input": "5 5 2\n10110", "output": "0"}]
1,200
["constructive algorithms", "greedy", "implementation"]
56
[{"input": "4 1 4\r\n1010\r\n", "output": "1"}, {"input": "5 5 2\r\n10110\r\n", "output": "0"}, {"input": "10 9 5\r\n1011111001\r\n", "output": "1"}, {"input": "7 3 7\r\n1110111\r\n", "output": "0"}, {"input": "1 1 1\r\n1\r\n", "output": "0"}, {"input": "10 3 3\r\n1001011011\r\n", "output": "0"}, {"input": "1 1 1\r\n0\...
false
stdio
null
true
893/D
893
D
PyPy 3
TESTS
6
77
0
108788079
n,d=map(int,input().split()) arr=list(map(int,input().split())) def main(): curr=0 ans=0 for a in arr: if a>0: curr+=a elif a<0: curr+=a else: if curr<0: curr=0 ans+=1 if curr>d: return -1 ret...
79
78
13,619,200
210522834
n, d = map(int, input().split()) a = [0] + list(map(int, input().split())) b = [0] * (n + 2) b[n] = a[n] now = a[n] for i in range(n - 1 , 0 , -1): now = a[i] + max(now, 0) b[i] = now now = 0 res = 0 for i in range(1 , n + 1): if a[i] == 0: if now < 0: res += 1 now = min(d, m...
Educational Codeforces Round 33 (Rated for Div. 2)
ICPC
2,017
2
256
Credit Card
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card. She starts with 0 money on her account. In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, ...
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation. The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
null
null
[{"input": "5 10\n-1 5 0 -5 3", "output": "0"}, {"input": "3 4\n-10 0 20", "output": "-1"}, {"input": "5 10\n-5 0 10 -11 0", "output": "2"}]
1,900
["data structures", "dp", "greedy", "implementation"]
79
[{"input": "5 10\r\n-1 5 0 -5 3\r\n", "output": "0\r\n"}, {"input": "3 4\r\n-10 0 20\r\n", "output": "-1\r\n"}, {"input": "5 10\r\n-5 0 10 -11 0\r\n", "output": "2\r\n"}, {"input": "5 13756\r\n-2 -9 -10 0 10\r\n", "output": "1\r\n"}, {"input": "20 23036\r\n-1 1 -1 -1 -1 -1 1 -1 -1 0 0 1 1 0 0 1 0 0 -1 -1\r\n", "output"...
false
stdio
null
true
886/D
886
D
Python 3
TESTS
12
78
1,331,200
32269252
n = int(input()) strs = [] isNo = False for i in range(n): strs.append(input()) for s in strs: alph = dict() for i in s: alph[i] = alph.get(i, 0) + 1 if alph[i] > 1: break if alph[i] > 1: isNo = True break if isNo: print('NO') else: ans = '' ...
47
109
0
32260750
import sys def no(): print('NO') sys.exit(0) def align(s, t, i, j): if i < j: i, j = j, i s, t = t, s result = s[:i - j] s = s[i - j:] for k in range(max(len(s), len(t))): if k < len(s) and k < len(t): if s[k] != t[k]: no() result ...
Технокубок 2018 - Отборочный Раунд 3
CF
2,017
2
256
Restoration of string
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
The first line contains integer n (1 ≤ n ≤ 105) — the number of strings in the set. Each of the next n lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct. The total length of the strings doesn't exceed 105.
Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings.
null
One can show that in the first sample only two good strings with minimum length exist: "cfmailru" and "mailrucf". The first string is lexicographically minimum.
[{"input": "4\nmail\nai\nlru\ncf", "output": "cfmailru"}, {"input": "3\nkek\npreceq\ncheburek", "output": "NO"}]
2,000
["constructive algorithms", "graphs", "implementation"]
47
[{"input": "4\r\nmail\r\nai\r\nlru\r\ncf\r\n", "output": "cfmailru\r\n"}, {"input": "3\r\nkek\r\npreceq\r\ncheburek\r\n", "output": "NO\r\n"}, {"input": "1\r\nz\r\n", "output": "z\r\n"}, {"input": "2\r\nab\r\nba\r\n", "output": "NO\r\n"}, {"input": "2\r\nac\r\nbc\r\n", "output": "NO\r\n"}, {"input": "2\r\ncd\r\nce\r\n"...
false
stdio
null
true
605/B
605
B
Python 3
TESTS
11
108
6,963,200
80595504
n, m = [int(x) for x in input().split()] edges1 = [] edges0 = [] s1 = [] s0 = [] we = [] for i in range(m): w, v = [int(x) for x in input().split()] we.append(w) if(v==0): s0.append(i) edges0.append(w) else: s1.append(i) edges1.append(w) r0 = sorted(range(len(s0)), key=la...
76
982
19,148,800
229725120
n, m = map(int, input().split()) ansu = [0] * 100005 ansv = [0] * 100005 w = [0] * 100005 v = [] s = [] nw = 1 for i in range(1, m + 1): x, y = map(int, input().split()) if y == 1: nw += 1 w[nw] = x ansu[i] = 1 ansv[i] = nw s.append((x, nw)) else: v.append((x,...
Codeforces Round 335 (Div. 1)
CF
2,015
2
256
Lazy Student
Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following defin...
The first line of the input contains two integers n and m ($$2 \leq n \leq 100\ 000, 1 \leq m \leq 100\ 000, n - 1 \leq m \leq \frac{n(n-1)}{2}$$) — the number of vertices and the number of edges in the graph. Each of the next m lines describes an edge of the graph and consists of two integers aj and bj (1 ≤ aj ≤ 109,...
If Vladislav has made a mistake and such graph doesn't exist, print - 1. Otherwise print m lines. On the j-th line print a pair of vertices (uj, vj) (1 ≤ uj, vj ≤ n, uj ≠ vj), that should be connected by the j-th edge. The edges are numbered in the same order as in the input. The graph, determined by these edges, mus...
null
null
[{"input": "4 5\n2 1\n3 1\n4 0\n1 1\n5 0", "output": "2 4\n1 4\n3 4\n3 1\n3 2"}, {"input": "3 3\n1 0\n2 1\n3 1", "output": "-1"}]
1,700
["constructive algorithms", "data structures", "graphs"]
76
[{"input": "4 5\r\n2 1\r\n3 1\r\n4 0\r\n1 1\r\n5 0\r\n", "output": "2 4\r\n1 4\r\n3 4\r\n3 1\r\n3 2\r\n"}, {"input": "3 3\r\n1 0\r\n2 1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n7 1\r\n", "output": "1 2\r\n"}, {"input": "3 2\r\n8 1\r\n9 1\r\n", "output": "1 2\r\n1 3\r\n"}, {"input": "3 3\r\n4 1\r\n5 0\r\n7 1\...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: input_lines = f.read().splitlines() with open(output_path) as f: reference_output = f.read().strip() with open(sub...
true
276/B
276
B
Python 3
TESTS
19
92
0
177283236
s=input() dict_alpha=dict() for i in s: if i in dict_alpha.keys(): dict_alpha[i]+=1 else: dict_alpha[i]=1 count_2=0 count_3=0 for g in dict_alpha.values(): if g%2==0: count_2+=2 if g==3: count_3+=3 if len(s)%2==0: if count_2==len(s): print("First") else: ...
51
92
0
140842816
c = 0 s = list(input()) for l in set(s): if s.count(l) % 2 == 0: c += 1 s = len(set(s)) - c if s % 2 == 0: if s != 0: print("Second") else: print("First") else: print("First")
Codeforces Round 169 (Div. 2)
CF
2,013
2
256
Little Girl and Game
The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: - The players move in turns; In one move the player can remove an arbitrary letter from string s. - If the player ...
The input contains a single line, containing string s (1 ≤ |s| ≤ 103). String s consists of lowercase English letters.
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
null
null
[{"input": "aba", "output": "First"}, {"input": "abca", "output": "Second"}]
1,300
["games", "greedy"]
51
[{"input": "aba\r\n", "output": "First\r\n"}, {"input": "abca\r\n", "output": "Second\r\n"}, {"input": "aabb\r\n", "output": "First\r\n"}, {"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo\r\n", "output": "Second\r\n"}, {"input": "gevqgtaorjixsxnbcoybr\r\n", "output": "First\r\n"}, {"input": "xvhtcbtouuddhylxhplgjxwlo\r\n"...
false
stdio
null
true
787/B
787
B
Python 3
TESTS
56
62
5,529,600
25769547
def main(): n, m = map(int, input().split()) for i in range(m): numbers = tuple(map(int, input().split())) s = set() is_safe = False for t in numbers: if -t in s: is_safe = True break s.add(t) if is_safe == False: ...
65
46
1,433,600
223634045
# https://codeforces.com/problemset/problem/787/B n, m = map(int, input().split()) # n = number of universes, m = number of gorups group_information = [None for _ in range(m)] # List of lists containing group information for i in range(m): group_information[i] = list(map(int, input().split()[1:])) # Remove first e...
Codeforces Round 406 (Div. 2)
CF
2,017
2
256
Not Afraid
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one ...
The first line of input contains two integers n and m (1 ≤ n, m ≤ 104) — number of universes and number of groups respectively. The next m lines contain the information about the groups. i-th of them first contains an integer k (number of times someone joined i-th group, k > 0) followed by k integers vi, 1, vi, 2, ......
In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise.
null
In the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he's a traitor, then all members of this group are traitors and so Summer should cancel the event.
[{"input": "4 2\n1 -3\n4 -2 3 2 -3", "output": "YES"}, {"input": "5 2\n5 3 -2 1 -1 5\n3 -5 2 5", "output": "NO"}, {"input": "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4", "output": "YES"}]
1,300
["greedy", "implementation", "math"]
65
[{"input": "4 2\r\n1 -3\r\n4 -2 3 2 -3\r\n", "output": "YES\r\n"}, {"input": "5 2\r\n5 3 -2 1 -1 5\r\n3 -5 2 5\r\n", "output": "NO\r\n"}, {"input": "7 2\r\n3 -1 6 7\r\n7 -5 4 2 4 7 -3 4\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n2 -2 2\r\n", "output": "NO\r\n"}, {"input": "7 7\r\n1 -2\r\n1 6\r\n2 7 -6\r\n2 -6 4\r\n2...
false
stdio
null
true
787/B
787
B
Python 3
TESTS
56
62
5,632,000
25747634
n, m = map(int, input().split()) for i in range(m): d = set(map(int, input().split())) for v in d: if -v in d: break else: print("YES") break else: print("NO")
65
62
5,427,200
25745763
import sys def solve(): n, m = map(int, input().split()) for i in range(m): k, *a = [int(j) for j in input().split()] a.sort(key=abs) # print(a) if k == 1: print('YES') return for j in range(len(a) - 1): if a[j] == -a[j + 1]: ...
Codeforces Round 406 (Div. 2)
CF
2,017
2
256
Not Afraid
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one ...
The first line of input contains two integers n and m (1 ≤ n, m ≤ 104) — number of universes and number of groups respectively. The next m lines contain the information about the groups. i-th of them first contains an integer k (number of times someone joined i-th group, k > 0) followed by k integers vi, 1, vi, 2, ......
In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise.
null
In the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he's a traitor, then all members of this group are traitors and so Summer should cancel the event.
[{"input": "4 2\n1 -3\n4 -2 3 2 -3", "output": "YES"}, {"input": "5 2\n5 3 -2 1 -1 5\n3 -5 2 5", "output": "NO"}, {"input": "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4", "output": "YES"}]
1,300
["greedy", "implementation", "math"]
65
[{"input": "4 2\r\n1 -3\r\n4 -2 3 2 -3\r\n", "output": "YES\r\n"}, {"input": "5 2\r\n5 3 -2 1 -1 5\r\n3 -5 2 5\r\n", "output": "NO\r\n"}, {"input": "7 2\r\n3 -1 6 7\r\n7 -5 4 2 4 7 -3 4\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n2 -2 2\r\n", "output": "NO\r\n"}, {"input": "7 7\r\n1 -2\r\n1 6\r\n2 7 -6\r\n2 -6 4\r\n2...
false
stdio
null
true
787/B
787
B
Python 3
TESTS
56
62
6,144,000
26397811
n, m = map(int, input().split()) for i in range(m): p = set(int(x) for x in input().split()) found = False for x in p: if -x in p: found = True break if not found: print("YES") exit(0) print("NO")
65
62
5,529,600
25738933
n, m = map(int, input().split()) flag1 = 0 for i in range(m): a = list(map(int, input().split())) a = set(a[1:]) flag = 0 for x in a: if -x in a: flag = 1 break if not flag: flag1 = 1 break print('YES' if flag1 else 'NO')
Codeforces Round 406 (Div. 2)
CF
2,017
2
256
Not Afraid
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one ...
The first line of input contains two integers n and m (1 ≤ n, m ≤ 104) — number of universes and number of groups respectively. The next m lines contain the information about the groups. i-th of them first contains an integer k (number of times someone joined i-th group, k > 0) followed by k integers vi, 1, vi, 2, ......
In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise.
null
In the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he's a traitor, then all members of this group are traitors and so Summer should cancel the event.
[{"input": "4 2\n1 -3\n4 -2 3 2 -3", "output": "YES"}, {"input": "5 2\n5 3 -2 1 -1 5\n3 -5 2 5", "output": "NO"}, {"input": "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4", "output": "YES"}]
1,300
["greedy", "implementation", "math"]
65
[{"input": "4 2\r\n1 -3\r\n4 -2 3 2 -3\r\n", "output": "YES\r\n"}, {"input": "5 2\r\n5 3 -2 1 -1 5\r\n3 -5 2 5\r\n", "output": "NO\r\n"}, {"input": "7 2\r\n3 -1 6 7\r\n7 -5 4 2 4 7 -3 4\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n2 -2 2\r\n", "output": "NO\r\n"}, {"input": "7 7\r\n1 -2\r\n1 6\r\n2 7 -6\r\n2 -6 4\r\n2...
false
stdio
null
true