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
1006/D
1006
D
PyPy 3
TESTS
2
139
5,120,000
109034614
from sys import stdin,stdout from math import gcd,sqrt,factorial,pi,inf from collections import deque,defaultdict from bisect import bisect,bisect_left from itertools import permutations as per input=stdin.readline R=lambda:map(int,input().split()) I=lambda:int(input()) S=lambda:input().rstrip('\n') L=lambda:list(R()) ...
23
93
3,379,200
206735302
n=int(input()) s=input() t=input() ans=0 for i in range((n+1)//2): if 2*i==n-1: if s[i]!=t[i]: ans+=1 continue S=[s[i],s[n-1-i],t[i],t[n-i-1]] S.sort() if S[0]==S[1] and S[2]==S[3]: continue if len(set(S))==4: ans+=2 continue if len(set(S))==2: ans+=1 continue if s[i]==s[...
Codeforces Round 498 (Div. 3)
ICPC
2,018
2
256
Two Strings Swaps
You are given two strings $$$a$$$ and $$$b$$$ consisting of lowercase English letters, both of length $$$n$$$. The characters of both strings have indices from $$$1$$$ to $$$n$$$, inclusive. You are allowed to do the following changes: - Choose any index $$$i$$$ ($$$1 \le i \le n$$$) and swap characters $$$a_i$$$ and...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of strings $$$a$$$ and $$$b$$$. The second line contains the string $$$a$$$ consisting of exactly $$$n$$$ lowercase English letters. The third line contains the string $$$b$$$ consisting of exactly $$$n$$$ lowercase English...
Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string $$$a$$$ equal to string $$$b$$$ with a sequence of changes from the list above.
null
In the first example preprocess moves are as follows: $$$a_1 := $$$'b', $$$a_3 := $$$'c', $$$a_4 := $$$'a' and $$$a_5:=$$$'b'. Afterwards, $$$a = $$$"bbcabba". Then we can obtain equal strings by the following sequence of changes: $$$swap(a_2, b_2)$$$ and $$$swap(a_2, a_6)$$$. There is no way to use fewer than $$$4$$$ ...
[{"input": "7\nabacaba\nbacabaa", "output": "4"}, {"input": "5\nzcabd\ndbacz", "output": "0"}]
1,700
["implementation"]
23
[{"input": "7\r\nabacaba\r\nbacabaa\r\n", "output": "4\r\n"}, {"input": "5\r\nzcabd\r\ndbacz\r\n", "output": "0\r\n"}, {"input": "1\r\na\r\nb\r\n", "output": "1\r\n"}, {"input": "5\r\nahmad\r\nyogaa\r\n", "output": "3\r\n"}]
false
stdio
null
true
1006/D
1006
D
PyPy 3
TESTS
2
139
7,680,000
95549583
n = int(input()) A = list(str(input())) B = list(str(input())) ans = 0 if n%2 == 0: for i in range(n//2): sa = {A[i], A[n-1-i]} sb = {B[i], B[n-1-i]} #print(sa, sb) if len(sa) == 1 and len(sb) == 1: continue ans += max(len(sa-sb), len(sb-sa)) else: for i in r...
23
93
3,686,400
170137185
from collections import * from heapq import * from bisect import * from itertools import * from functools import * from math import * from string import * import operator import sys input = sys.stdin.readline def solve(): n = int(input()) A = input().strip() B = input().strip() ans = 0 for i in ...
Codeforces Round 498 (Div. 3)
ICPC
2,018
2
256
Two Strings Swaps
You are given two strings $$$a$$$ and $$$b$$$ consisting of lowercase English letters, both of length $$$n$$$. The characters of both strings have indices from $$$1$$$ to $$$n$$$, inclusive. You are allowed to do the following changes: - Choose any index $$$i$$$ ($$$1 \le i \le n$$$) and swap characters $$$a_i$$$ and...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of strings $$$a$$$ and $$$b$$$. The second line contains the string $$$a$$$ consisting of exactly $$$n$$$ lowercase English letters. The third line contains the string $$$b$$$ consisting of exactly $$$n$$$ lowercase English...
Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string $$$a$$$ equal to string $$$b$$$ with a sequence of changes from the list above.
null
In the first example preprocess moves are as follows: $$$a_1 := $$$'b', $$$a_3 := $$$'c', $$$a_4 := $$$'a' and $$$a_5:=$$$'b'. Afterwards, $$$a = $$$"bbcabba". Then we can obtain equal strings by the following sequence of changes: $$$swap(a_2, b_2)$$$ and $$$swap(a_2, a_6)$$$. There is no way to use fewer than $$$4$$$ ...
[{"input": "7\nabacaba\nbacabaa", "output": "4"}, {"input": "5\nzcabd\ndbacz", "output": "0"}]
1,700
["implementation"]
23
[{"input": "7\r\nabacaba\r\nbacabaa\r\n", "output": "4\r\n"}, {"input": "5\r\nzcabd\r\ndbacz\r\n", "output": "0\r\n"}, {"input": "1\r\na\r\nb\r\n", "output": "1\r\n"}, {"input": "5\r\nahmad\r\nyogaa\r\n", "output": "3\r\n"}]
false
stdio
null
true
515/E
515
E
PyPy 3-64
TESTS
3
62
2,662,400
213981380
""" We use a ST to encode vertex information: if vertex represents [l, r] then we keep (lbm, rbm, ism, sl, sr) where lbm: maximum lbm(x) where lbm(x) is distance from left boundary to x + 2*h(x) rbm: similarly for right ism: best intra-segment we can do sl: segment left index of arr sr: segment ...
27
967
57,036,800
214984801
from math import inf import sys input = lambda: sys.stdin.readline().rstrip("\r\n") fast_print = lambda p: sys.stdout.write(str(p) + "\n") n, m = [int(component) for component in input().split(" ")] d = [int(component) for component in input().split(" ")] h = [int(component) for component in input().split(" ")] ### ...
Codeforces Round 292 (Div. 2)
CF
2,015
2
512
Drazil and Park
Drazil is a monkey. He lives in a circular park. There are n trees around the park. The distance between the i-th tree and (i + 1)-st trees is di, the distance between the n-th tree and the first tree is dn. The height of the i-th tree is hi. Drazil starts each day with the morning run. The morning run consists of the...
The first line contains two integer n and m (3 ≤ n ≤ 105, 1 ≤ m ≤ 105), denoting number of trees and number of days, respectively. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 109), the distances between consecutive trees. The third line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 109), the heights...
For each day print the answer in a separate line.
null
null
[{"input": "5 3\n2 2 2 2 2\n3 5 2 1 4\n1 3\n2 2\n4 5", "output": "12\n16\n18"}, {"input": "3 3\n5 1 4\n5 1 4\n3 3\n2 2\n1 1", "output": "17\n22\n11"}]
2,300
["data structures"]
27
[{"input": "5 3\r\n2 2 2 2 2\r\n3 5 2 1 4\r\n1 3\r\n2 2\r\n4 5\r\n", "output": "12\r\n16\r\n18\r\n"}, {"input": "3 3\r\n5 1 4\r\n5 1 4\r\n3 3\r\n2 2\r\n1 1\r\n", "output": "17\r\n22\r\n11\r\n"}, {"input": "10 10\r\n8477 33103 38654 6582 27496 1106 15985 3644 29818 8849\r\n88745 72099 87767 85285 73517 94562 87214 63194...
false
stdio
null
true
247/D
250
D
Python 3
TESTS
11
840
13,619,200
13535353
__author__ = 'Michael Ilyin' import math # debug = True debug = False def dist(x1, y1, x2, y2): return math.sqrt(math.pow(x1 - x2, 2) + math.pow(y1 - y2, 2)) def get_y(x1, y1, x2, y2, x): return (((x - x1) * (y2 - y1)) / (x2 - x1)) + y1 if debug: with open("input.txt", "r") as inp: firstLine ...
33
794
14,745,600
106349764
import sys def pro(): return sys.stdin.readline().strip() def rop(): return map(int, pro().split()) def main(): s = list(rop()) a = list(rop()) q = list(rop()) o = list(rop()) p = -1 t = (1e100, -1, -1) for i in range(s[1]): while not((p == - 1 or s[2] * q[i] - s[3] * a[p] >= 0) and (p + 1 == s[0] o...
CROC-MBTU 2012, Final Round
CF
2,012
1
256
Building Bridge
Two villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages. The river banks can be assumed to be vertical straight lines x = a and x = b (0 < a < b). The west village lies in a steppe at point O = (0...
The first line contains integers n, m, a, b (1 ≤ n, m ≤ 105, 0 < a < b < 106). The second line contains n integers in the ascending order: the i-th integer determines the coordinate of point Ai and equals yi (|yi| ≤ 106). The third line contains m integers in the ascending order: the i-th integer determines the coord...
Print two integers — the numbers of points on the left (west) and right (east) banks, respectively, between which you need to build a bridge. You can assume that the points on the west bank are numbered from 1 to n, in the order in which they are given in the input. Similarly, the points on the east bank are numbered f...
null
null
[{"input": "3 2 3 5\n-2 -1 4\n-1 2\n7 3", "output": "2 2"}]
1,900
[]
33
[{"input": "3 2 3 5\r\n-2 -1 4\r\n-1 2\r\n7 3\r\n", "output": "2 2"}, {"input": "1 1 10 20\r\n5\r\n-5\r\n1\r\n", "output": "1 1"}, {"input": "2 2 1 2\r\n-1 10\r\n8 9\r\n3 7\r\n", "output": "1 1"}, {"input": "10 20 50 60\r\n-96 -75 32 37 42 43 44 57 61 65\r\n-95 -90 -86 -79 -65 -62 -47 -11 -8 -6 1 8 23 25 32 51 73 88 94...
false
stdio
null
true
175/B
175
B
Python 3
TESTS
0
154
0
53660628
n = int(input()) d = {} for _ in '0' * n: s, v = input().split() d[s] = max(d.get(s, 0), int(v)) v = d.values() res = str(len(d)) + '\n' for k in d: a, b = 0, 0 for x in v: a += x <= d[k] b += x > d[k] s = 'noob' a /= n b /= n if a >= .5 and b >= .2: s = 'random' if a...
46
434
204,800
214357322
# LUOGU_RID: 116285050 n=int(input()) d={} c=[] for _ in range(n): a,b=input().split() b=int(b) if a not in c: c.append(a) if a not in d: d[a]=b else: if d[a]<b: d[a]=b print(len(d)) m=len(c) x=[0]*m for i in range(m): for j in range(m): if d[c[i]]<d[c...
Codeforces Round 115
CF
2,012
2
256
Plane of Tanks: Pro
Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has...
The first line contains the only integer number n (1 ≤ n ≤ 1000) — a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. T...
Print on the first line the number m — the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). Th...
null
In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has bes...
[{"input": "5\nvasya 100\nvasya 200\nartem 100\nkolya 200\nigor 250", "output": "4\nartem noob\nigor pro\nkolya random\nvasya random"}, {"input": "3\nvasya 200\nkolya 1000\nvasya 1000", "output": "2\nkolya pro\nvasya pro"}]
1,400
["implementation"]
78
[{"input": "5\r\nvasya 100\r\nvasya 200\r\nartem 100\r\nkolya 200\r\nigor 250\r\n", "output": "4\r\nartem noob\r\nigor pro\r\nkolya random\r\nvasya random\r\n"}, {"input": "3\r\nvasya 200\r\nkolya 1000\r\nvasya 1000\r\n", "output": "2\r\nkolya pro\r\nvasya pro\r\n"}, {"input": "1\r\nvasya 1000\r\n", "output": "1\r\nvas...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input data with open(input_path) as f: n = int(f.readline()) players = {} for _ in range(n): name, points = f.readline().strip().split() points = int(points) if name not in players ...
true
412/D
412
D
Python 3
PRETESTS
2
77
0
6407699
n, p = map(int, input().split()) arr = [i + 1 for i in range(n)] operations = [] for i in range(p): t, y = map(int, input().split()) operations.append([t, y]) for elem in operations: a, b = elem[0], elem[1] if abs(arr.index(a) - arr.index(b)) > 1: continue else: k, l = arr.index(a), ...
33
327
9,830,400
197318855
n,m = map(int,input().split()) g = [set() for i in range(n)] for i in range(m): a,b = map(int,input().split()) g[a-1].add(b-1) c = [0]*n for i in range(n): c[i]=i for i in range(n): j=i while j>0 and c[j] in g[c[j-1]]: c[j],c[j-1]=c[j-1],c[j] j-=1 for i in c: print(i+1,end=' ')
Coder-Strike 2014 - Round 1
CF
2,014
1
256
Giving Awards
The employees of the R1 company often spend time together: they watch football, they go camping, they solve contests. So, it's no big deal that sometimes someone pays for someone else. Today is the day of giving out money rewards. The R1 company CEO will invite employees into his office one by one, rewarding each one ...
The first line contains space-separated integers n and m $$(2\leq n\leq3\cdot10^{4};1\leq m\leq min(10^{5},\frac{n(n-1)}{2}))$$ — the number of employees in R1 and the number of debt relations. Each of the following m lines contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi), these integers indicate ...
Print -1 if the described order does not exist. Otherwise, print the permutation of n distinct integers. The first number should denote the number of the person who goes to the CEO office first, the second number denote the person who goes second and so on. If there are multiple correct orders, you are allowed to prin...
null
null
[{"input": "2 1\n1 2", "output": "2 1"}, {"input": "3 3\n1 2\n2 3\n3 1", "output": "2 1 3"}]
2,000
["dfs and similar"]
33
[{"input": "2 1\r\n1 2\r\n", "output": "2 1 \r\n"}, {"input": "3 3\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "2 1 3 \r\n"}, {"input": "10 45\r\n10 5\r\n10 7\r\n6 1\r\n5 8\r\n3 5\r\n6 5\r\n1 2\r\n6 10\r\n2 9\r\n9 5\r\n4 1\r\n7 5\r\n1 8\r\n6 8\r\n10 9\r\n7 2\r\n7 9\r\n4 10\r\n7 3\r\n4 8\r\n10 3\r\n10 8\r\n2 10\r\n8 2\r\n4 2\r...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n, m = map(int, f.readline().split()) edges = set() for _ in range(m): a, b = map(int, f.readline().split()) ...
true
247/D
250
D
PyPy 3-64
TESTS
4
61
2,150,400
154037124
import math n,m,a,b = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) tar = float('inf') i = 0 dx2 = (a-b)*(a-b) for j in range(m): pdy = float('inf') for k in range(i,n): dy = abs(A[k]-B[j]) if dy>=pdy: ...
33
1,122
11,878,400
13858446
from math import sqrt,fabs def dist(x1, y1, x2, y2): return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2)) def calcOptimumRightPoint(startX, startY): l = float("inf") idx = -1 for i in range(len(B)): d = dist(startX, startY, b, B[i]) + L[i] if d <= l: l = d i...
CROC-MBTU 2012, Final Round
CF
2,012
1
256
Building Bridge
Two villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages. The river banks can be assumed to be vertical straight lines x = a and x = b (0 < a < b). The west village lies in a steppe at point O = (0...
The first line contains integers n, m, a, b (1 ≤ n, m ≤ 105, 0 < a < b < 106). The second line contains n integers in the ascending order: the i-th integer determines the coordinate of point Ai and equals yi (|yi| ≤ 106). The third line contains m integers in the ascending order: the i-th integer determines the coord...
Print two integers — the numbers of points on the left (west) and right (east) banks, respectively, between which you need to build a bridge. You can assume that the points on the west bank are numbered from 1 to n, in the order in which they are given in the input. Similarly, the points on the east bank are numbered f...
null
null
[{"input": "3 2 3 5\n-2 -1 4\n-1 2\n7 3", "output": "2 2"}]
1,900
[]
33
[{"input": "3 2 3 5\r\n-2 -1 4\r\n-1 2\r\n7 3\r\n", "output": "2 2"}, {"input": "1 1 10 20\r\n5\r\n-5\r\n1\r\n", "output": "1 1"}, {"input": "2 2 1 2\r\n-1 10\r\n8 9\r\n3 7\r\n", "output": "1 1"}, {"input": "10 20 50 60\r\n-96 -75 32 37 42 43 44 57 61 65\r\n-95 -90 -86 -79 -65 -62 -47 -11 -8 -6 1 8 23 25 32 51 73 88 94...
false
stdio
null
true
436/C
436
C
Python 3
TESTS
2
61
0
6888989
n, m, k, w = map(int, input().split()) m *= n x, y, z = range(n), range(m), range(k) t = [''.join(input() for i in x) for j in z] def f(a, b): return sum(a[i] != b[i] for i in y) u = [[w * f(t[i], t[j]) for j in range(i + 1, k)] for i in z] def g(i, j): return min(m, u[i][j - i - 1] if i < j else u[j][i - j - 1]) d,...
30
1,466
70,041,600
87968659
def put(): return map(int, input().split()) def diff(x,y): ans = 0 for i in range(n*m): if s[x][i]!= s[y][i]: ans+=1 return ans def find(i): if i==p[i]: return i p[i] = find(p[i]) return p[i] def union(i,j): if rank[i]>rank[j]: i,j = j,i elif rank[...
Zepto Code Rush 2014
CF
2,014
2
256
Dungeons and Candies
During the loading of the game "Dungeons and Candies" you are required to get descriptions of k levels from the server. Each description is a map of an n × m checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if a cell ...
The first line contains four integers n, m, k, w (1 ≤ n, m ≤ 10; 1 ≤ k, w ≤ 1000). Then follows the description of k levels. Each level is described by n lines, each line contains m characters. Each character is either a letter of the English alphabet or a dot ("."). Please note that the case of the letters matters.
In the first line print the required minimum number of transferred bytes. Then print k pairs of integers x1, y1, x2, y2, ..., xk, yk, describing the way to transfer levels. Pair xi, yi means that level xi needs to be transferred by way yi. If yi equals 0, that means that the level must be transferred using the first w...
null
null
[{"input": "2 3 3 2\nA.A\n...\nA.a\n..C\nX.Y\n...", "output": "14\n1 0\n2 1\n3 1"}, {"input": "1 1 4 1\nA\n.\nB\n.", "output": "3\n1 0\n2 0\n4 2\n3 0"}, {"input": "1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB", "output": "11\n1 0\n3 1\n2 3\n4 2\n5 1"}]
1,800
["dsu", "graphs", "greedy", "trees"]
30
[{"input": "2 3 3 2\r\nA.A\r\n...\r\nA.a\r\n..C\r\nX.Y\r\n...\r\n", "output": "14\r\n1 0\r\n2 1\r\n3 1\r\n"}, {"input": "1 1 4 1\r\nA\r\n.\r\nB\r\n.\r\n", "output": "3\r\n1 0\r\n2 0\r\n4 2\r\n3 0\r\n"}, {"input": "1 3 5 2\r\nABA\r\nBBB\r\nBBA\r\nBAB\r\nABB\r\n", "output": "11\r\n1 0\r\n3 1\r\n2 3\r\n4 2\r\n5 1\r\n"}, {...
false
stdio
import sys def read_levels(input_path): with open(input_path) as f: lines = [line.strip() for line in f.readlines() if line.strip()] first_line = lines[0].split() n, m, k, w = map(int, first_line) levels = [None] # 1-based indexing idx = 1 for _ in range(k): level = [] ...
true
174/C
174
C
PyPy 3
TESTS
0
124
20,172,800
127712038
def process(A): n = len(A) if n==1: return [[1,1] for i in range(A[0])] current = [1 for i in range(A[0])] answer = [] for i in range(1, n): if A[i] < A[i-1]: while len(current) > A[i]: a = current.pop() answer.append([a, i-1]) elif A[i] > A[i-1]: while l...
63
1,152
30,003,200
15764001
N = 100000 v = [] for i in range(0, N) : v.append([]) line = input() n = int(line) line = input() lineSplit = line.split() a = 0 for i in range(0, len(lineSplit)) : b = int(lineSplit[i]) if b > a : for j in range(a, b) : v[j].append([i, -1]) elif b < a : for j in range(a-1, b-1, -1) : v[j][-1][1] = i a ...
VK Cup 2012 Round 3 (Unofficial Div. 2 Edition)
CF
2,012
2
256
Range Increments
Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a for all indexes in the segment [l, r]. In other words, this function does the following: Polycarpus knows the state of the array a after...
The first input line contains a single integer n (1 ≤ n ≤ 105) — the length of the array a[1... n]. The second line contains its integer space-separated elements, a[1], a[2], ..., a[n] (0 ≤ a[i] ≤ 105) after some series of function calls rangeIncrement(l, r). It is guaranteed that at least one element of the array is...
Print on the first line t — the minimum number of calls of function rangeIncrement(l, r), that lead to the array from the input data. It is guaranteed that this number will turn out not more than 105. Then print t lines — the descriptions of function calls, one per line. Each line should contain two integers li, ri (1...
null
The first sample requires a call for the entire array, and four additional calls: - one for the segment [2,2] (i.e. the second element of the array), - three for the segment [5,5] (i.e. the fifth element of the array).
[{"input": "6\n1 2 1 1 4 1", "output": "5\n2 2\n5 5\n5 5\n5 5\n1 6"}, {"input": "5\n1 0 1 0 1", "output": "3\n1 1\n3 3\n5 5"}]
1,800
["data structures", "greedy"]
63
[{"input": "6\r\n1 2 1 1 4 1\r\n", "output": "5\r\n2 2\r\n5 5\r\n5 5\r\n5 5\r\n1 6\r\n"}, {"input": "5\r\n1 0 1 0 1\r\n", "output": "3\r\n1 1\r\n3 3\r\n5 5\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n1 1\r\n"}, {"input": "1\r\n100000\r\n", "output": "100000\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) # Compute minimal t minimal_t = 0 prev = 0 for num in a: if num > prev: minimal_t += num - prev ...
true
559/E
559
E
Python 3
TESTS
0
15
0
193545212
n = int(input()) a = [0] * (n + 1) l = [0] * (n + 1) for i in range(1, n + 1): a[i], l[i] = map(int, input().split()) a[0] = 0 # add monument at position 0 l[0] = 0 # monument has no illumination a, l = zip(*sorted(zip(a, l))) r = 0 # rightmost illuminated position total_length = 0 # total illuminated length for i...
90
373
20,684,800
163335825
import dataclasses import sys inf = float('inf') # change stdout buffer size buffer = open(1, 'w', 10**6) # fast printing function def print(*args, sep=' ', end='\n'): buffer.write(sep.join(str(arg) for arg in args) + end) # flush stdout def flush(): buffer.flush() def read_ints(index=None): if ind...
Codeforces Round 313 (Div. 1)
CF
2,015
4
256
Gerald and Path
The main walking trail in Geraldion is absolutely straight, and it passes strictly from the north to the south, it is so long that no one has ever reached its ends in either of the two directions. The Geraldionians love to walk on this path at any time, so the mayor of the city asked the Herald to illuminate this path ...
The first line contains integer n (1 ≤ n ≤ 100) — the number of spotlights. Each of the n lines contains two space-separated integers, ai and li (0 ≤ ai ≤ 108, 1 ≤ li ≤ 108). Number ai shows how much further the i-th spotlight to the north, and number li shows the length of the segment it illuminates. It is guaranteed...
Print a single integer — the maximum total length of the illuminated part of the path.
null
null
[{"input": "3\n1 1\n2 2\n3 3", "output": "5"}, {"input": "4\n1 2\n3 3\n4 3\n6 2", "output": "9"}]
3,000
["dp", "sortings"]
90
[{"input": "3\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "5\r\n"}, {"input": "4\r\n1 2\r\n3 3\r\n4 3\r\n6 2\r\n", "output": "9\r\n"}, {"input": "5\r\n3 3\r\n4 1\r\n2 2\r\n0 3\r\n9 5\r\n", "output": "13\r\n"}, {"input": "5\r\n3 3\r\n4 3\r\n6 4\r\n2 3\r\n1 5\r\n", "output": "14\r\n"}, {"input": "5\r\n1 2\r\n7 5\r\n9 4\r\n5 1\r...
false
stdio
null
true
562/F
566
A
Python 3
TESTS
2
109
307,200
67346273
class Tree(): def __init__(self, value, index): self.value = value self.left = None self.right = None self.count = 1 self.index = index def insert(self, value, index): if value == self.value: self.count += 1 return if value < self....
38
1,372
262,553,600
12334711
import sys class Node: def __init__(self, d): global nodes self.ch = {} self.a = [[], []] self.d = d nodes += [self] nodes = [] pairs = [] res = 0 N = int(sys.stdin.readline()) _input = sys.stdin.readlines() _input = [s[:-1] for s in _input] A = [_input[:N], _input[N:]] T ...
VK Cup 2015 - Finals
CF
2,015
2
256
Matching Names
Teachers of one programming summer school decided to make a surprise for the students by giving them names in the style of the "Hobbit" movie. Each student must get a pseudonym maximally similar to his own name. The pseudonym must be a name of some character of the popular saga and now the teachers are busy matching ps...
The first line contains number n (1 ≤ n ≤ 100 000) — the number of students in the summer school. Next n lines contain the name of the students. Each name is a non-empty word consisting of lowercase English letters. Some names can be repeating. The last n lines contain the given pseudonyms. Each pseudonym is a non-em...
In the first line print the maximum possible quality of matching pseudonyms to students. In the next n lines describe the optimal matching. Each line must have the form a b (1 ≤ a, b ≤ n), that means that the student who was number a in the input, must match to the pseudonym number b in the input. The matching should...
null
The first test from the statement the match looks as follows: - bill  →  bilbo (lcp = 3) - galya  →  galadriel (lcp = 3) - gennady  →  gendalf (lcp = 3) - toshik  →  torin (lcp = 2) - boris  →  smaug (lcp = 0)
[{"input": "5\ngennady\ngalya\nboris\nbill\ntoshik\nbilbo\ntorin\ngendalf\nsmaug\ngaladriel", "output": "11\n4 1\n2 5\n1 3\n5 2\n3 4"}]
2,300
[]
38
[{"input": "5\r\ngennady\r\ngalya\r\nboris\r\nbill\r\ntoshik\r\nbilbo\r\ntorin\r\ngendalf\r\nsmaug\r\ngaladriel\r\n", "output": "11\r\n4 1\r\n2 5\r\n1 3\r\n5 2\r\n3 4\r\n"}, {"input": "1\r\na\r\na\r\n", "output": "1\r\n1 1\r\n"}, {"input": "2\r\na\r\na\r\na\r\na\r\n", "output": "2\r\n1 1\r\n2 2\r\n"}, {"input": "2\r\na...
false
stdio
import sys def lcp(s, t): min_len = min(len(s), len(t)) cnt = 0 for i in range(min_len): if s[i] == t[i]: cnt += 1 else: break return cnt def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input ...
true
878/E
878
E
Python 3
TESTS
2
93
512,000
32122313
from random import randint def find_max_ind(arr): max_el, max_ind = arr[0], 0 for i in range(1, len(arr)): el = arr[i] if el >= max_el: max_el = el max_ind = i return max_ind def calc_max_prod(arr, l): if l == 1: return arr[0] if l == 2: a =...
55
999
80,281,600
303302080
import sys MOD = 10**9 + 7 INF = 2 * 10**9 + 5 def upd(a): a += (a >> 31) & MOD return a def init(n): _2 = [1] * (n + 1) for i in range(1, n + 1): _2[i] = (_2[i-1] << 1) % MOD return _2 def find(x, fa): if fa[x] != x: fa[x] = find(fa[x], fa) return fa[x] def merge(x, y, ...
Codeforces Round 443 (Div. 1)
CF
2,017
2
512
Numbers on the blackboard
A sequence of n integers is written on a blackboard. Soon Sasha will come to the blackboard and start the following actions: let x and y be two adjacent numbers (x before y), then he can remove them and write x + 2y instead of them. He will perform these operations until one number is left. Sasha likes big numbers and ...
The first line contains two integers n and q (1 ≤ n, q ≤ 105) — the number of integers on the blackboard and the number of Nikita's options. The next line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the sequence on the blackboard. Each of the next q lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n...
For each option output Sasha's result modulo 109 + 7.
null
In the second sample Nikita doesn't erase anything. Sasha first erases the numbers 1 and 2 and writes 5. Then he erases 5 and -3 and gets -1. -1 modulo 109 + 7 is 109 + 6.
[{"input": "3 3\n1 2 3\n1 3\n1 2\n2 3", "output": "17\n5\n8"}, {"input": "3 1\n1 2 -3\n1 3", "output": "1000000006"}, {"input": "4 2\n1 1 1 -1\n1 4\n3 4", "output": "5\n1000000006"}]
3,300
["combinatorics", "dp"]
55
[{"input": "3 3\r\n1 2 3\r\n1 3\r\n1 2\r\n2 3\r\n", "output": "17\r\n5\r\n8\r\n"}, {"input": "3 1\r\n1 2 -3\r\n1 3\r\n", "output": "1000000006\r\n"}, {"input": "4 2\r\n1 1 1 -1\r\n1 4\r\n3 4\r\n", "output": "5\r\n1000000006\r\n"}, {"input": "4 1\r\n1 1 -3 1\r\n1 4\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1000000000\...
false
stdio
null
true
30/C
30
C
Python 3
TESTS
4
186
0
7282597
def is_reachable(from_state, target): distance = ((from_state[0]-target[0])**2 + (from_state[1]-target[1])**2)**0.5 time_diff = target[2] - from_state[2] return time_diff >= distance num_iter = int(input()) targets = sorted([list(map(float, input().strip().split(' '))) for dummy in range(0, num_iter)]...
50
810
2,560,000
56455652
F = lambda: map(float, input().split()) n = int(input()) arr = [] for i in range(n): x, y, t, s = F() arr.append([int(x), int(y), int(t), s]) arr.sort(key=lambda x: x[2]) dp = [0] * n for i in range(n): dp[i] = arr[i][-1] for j in range(i): if (arr[i][0] - arr[j][0]) ** 2 + (arr[i][1] - arr[j][1...
Codeforces Beta Round 30 (Codeforces format)
CF
2,010
2
256
Shooting Gallery
One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize — big pink plush panda. The king is not good at shooting, so he invited you to help him. The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targ...
The first line contains integer n (1 ≤ n ≤ 1000) — amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti — integers, - 1000 ≤ xi, yi ≤ 1000, 0 ≤ ti ≤ 109, real number pi is given with no more than 6 digits ...
Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10 - 6.
null
null
[{"input": "1\n0 0 0 0.5", "output": "0.5000000000"}, {"input": "2\n0 0 0 0.6\n5 0 5 0.7", "output": "1.3000000000"}]
1,800
["dp", "probabilities"]
50
[{"input": "1\r\n0 0 0 0.5\r\n", "output": "0.5000000000\r\n"}, {"input": "2\r\n0 0 0 0.6\r\n5 0 5 0.7\r\n", "output": "1.3000000000\r\n"}, {"input": "1\r\n-5 2 3 0.886986\r\n", "output": "0.8869860000\r\n"}, {"input": "4\r\n10 -7 14 0.926305\r\n-7 -8 12 0.121809\r\n-7 7 14 0.413446\r\n3 -8 6 0.859061\r\n", "output": "...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: correct_line = f.readline().strip() try: correct = float(correct_line) except: print(0) return with...
true
1000/D
1000
D
PyPy 3
TESTS
2
93
3,584,000
147568159
import sys input = sys.stdin.readline MOD = 998244353 N = 10005 fact = [1] for i in range(1, N): fact.append(fact[-1] * i % MOD) factinv = [0] * N factinv[N - 1] = pow(fact[N - 1], MOD - 2, MOD) for j in range(N - 2, -1, -1): factinv[j] = factinv[j + 1] * (j + 1) % MOD def nCk(n, k): if k < 0 or n < k: re...
22
951
1,126,400
39719619
from copy import deepcopy import itertools from bisect import bisect_left from bisect import bisect_right import math from collections import deque def read(): return int(input()) def readmap(): return map(int, input().split()) def readlist(): return list(map(int, input().split())) MAX = 10000 MOD =...
Educational Codeforces Round 46 (Rated for Div. 2)
ICPC
2,018
2
256
Yet Another Problem On a Subsequence
The sequence of integers $$$a_1, a_2, \dots, a_k$$$ is called a good array if $$$a_1 = k - 1$$$ and $$$a_1 > 0$$$. For example, the sequences $$$[3, -1, 44, 0], [1, -99]$$$ are good arrays, and the sequences $$$[3, 7, 8], [2, 5, 4, 1], [0]$$$ — are not. A sequence of integers is called good if it can be divided into a...
The first line contains the number $$$n~(1 \le n \le 10^3)$$$ — the length of the initial sequence. The following line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n~(-10^9 \le a_i \le 10^9)$$$ — the sequence itself.
In the single line output one integer — the number of subsequences of the original sequence that are good sequences, taken modulo 998244353.
null
In the first test case, two good subsequences — $$$[a_1, a_2, a_3]$$$ and $$$[a_2, a_3]$$$. In the second test case, seven good subsequences — $$$[a_1, a_2, a_3, a_4], [a_1, a_2], [a_1, a_3], [a_1, a_4], [a_2, a_3], [a_2, a_4]$$$ and $$$[a_3, a_4]$$$.
[{"input": "3\n2 1 1", "output": "2"}, {"input": "4\n1 1 1 1", "output": "7"}]
1,900
["combinatorics", "dp"]
22
[{"input": "3\r\n2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "7\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}]
false
stdio
null
true
487/B
487
B
PyPy 3
TESTS
2
77
20,172,800
124967705
def adjust(A, l, s): B = [] m, M = A[0], A[0] for i in range(1, n): m = min(A[i], m) M = max(A[i], M) if M - m > s: B.append(i - 1) m = M = A[i] count = len(B) + 1 r = n - 1 m, M = A[-1], A[-1] for i in reversed(range(n - 1)): m = min...
35
280
30,208,000
134855235
from collections import deque # f[i] = min(f[k]) + 1 for g[i] - 1 <= k <= i - l # [g[i], i] is a valid seg # sliding window of max/min elements """ debug qmin (increasing) qmax (decreasing), [-1] is max/min debug deque([1]) deque([1]) debug deque([1, 2]) deque([2]) debug deque([3]) deque([2, 3]) debug deque([3, 4]) de...
Codeforces Round 278 (Div. 1)
CF
2,014
1
256
Strip
Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right. Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: - Each piece should contain at least l numbers. - The difference between the maximal and the minimal number on the piece sho...
The first line contains three space-separated integers n, s, l (1 ≤ n ≤ 105, 0 ≤ s ≤ 109, 1 ≤ l ≤ 105). The second line contains n integers ai separated by spaces ( - 109 ≤ ai ≤ 109).
Output the minimal number of strip pieces. If there are no ways to split the strip, output -1.
null
For the first sample, we can split the strip into 3 pieces: [1, 3, 1], [2, 4], [1, 2]. For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists.
[{"input": "7 2 2\n1 3 1 2 4 1 2", "output": "3"}, {"input": "7 2 2\n1 100 1 100 1 100 1", "output": "-1"}]
2,000
["binary search", "data structures", "dp", "two pointers"]
35
[{"input": "7 2 2\r\n1 3 1 2 4 1 2\r\n", "output": "3\r\n"}, {"input": "7 2 2\r\n1 100 1 100 1 100 1\r\n", "output": "-1\r\n"}, {"input": "1 0 1\r\n0\r\n", "output": "1\r\n"}, {"input": "6 565 2\r\n31 76 162 -182 -251 214\r\n", "output": "1\r\n"}, {"input": "1 0 1\r\n0\r\n", "output": "1\r\n"}, {"input": "1 0 1\r\n-100...
false
stdio
null
true
1000/D
1000
D
PyPy 3-64
TESTS
2
78
6,348,800
154497893
from math import sqrt,ceil import os import sys from collections import defaultdict,deque from io import BytesIO, IOBase # prime = [True for i in range(5*10**5 + 1)] # def SieveOfEratosthenes(n): # p = 2 # while (p * p <= n): # # If prime[p] is not changed, then it is a prime # i...
22
1,372
23,859,200
39716340
#!/usr/bin/python3 MOD = 998244353 def solve(N, A): dp = [[0] * N for _ in range(N + 1)] dp[0][0] = 1 for i in range(N): for j in range(N): c = dp[i][j] dp[i + 1][j] += c dp[i + 1][j] %= MOD if j == 0: if A[i] > 0 and A[i] < N: ...
Educational Codeforces Round 46 (Rated for Div. 2)
ICPC
2,018
2
256
Yet Another Problem On a Subsequence
The sequence of integers $$$a_1, a_2, \dots, a_k$$$ is called a good array if $$$a_1 = k - 1$$$ and $$$a_1 > 0$$$. For example, the sequences $$$[3, -1, 44, 0], [1, -99]$$$ are good arrays, and the sequences $$$[3, 7, 8], [2, 5, 4, 1], [0]$$$ — are not. A sequence of integers is called good if it can be divided into a...
The first line contains the number $$$n~(1 \le n \le 10^3)$$$ — the length of the initial sequence. The following line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n~(-10^9 \le a_i \le 10^9)$$$ — the sequence itself.
In the single line output one integer — the number of subsequences of the original sequence that are good sequences, taken modulo 998244353.
null
In the first test case, two good subsequences — $$$[a_1, a_2, a_3]$$$ and $$$[a_2, a_3]$$$. In the second test case, seven good subsequences — $$$[a_1, a_2, a_3, a_4], [a_1, a_2], [a_1, a_3], [a_1, a_4], [a_2, a_3], [a_2, a_4]$$$ and $$$[a_3, a_4]$$$.
[{"input": "3\n2 1 1", "output": "2"}, {"input": "4\n1 1 1 1", "output": "7"}]
1,900
["combinatorics", "dp"]
22
[{"input": "3\r\n2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "7\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}]
false
stdio
null
true
878/E
878
E
Python 3
TESTS
1
46
0
32123773
def find_ind(arr): max_ind, max_el = 0, arr[0] for i in range(1, len(arr)): el = arr[i] if el > max_el: max_el = el max_ind = i return max_ind def calc_max(arr): l = len(arr) if l == 0: return 0 if l == 1: return arr[0] if l == 2: ...
55
999
80,281,600
303302080
import sys MOD = 10**9 + 7 INF = 2 * 10**9 + 5 def upd(a): a += (a >> 31) & MOD return a def init(n): _2 = [1] * (n + 1) for i in range(1, n + 1): _2[i] = (_2[i-1] << 1) % MOD return _2 def find(x, fa): if fa[x] != x: fa[x] = find(fa[x], fa) return fa[x] def merge(x, y, ...
Codeforces Round 443 (Div. 1)
CF
2,017
2
512
Numbers on the blackboard
A sequence of n integers is written on a blackboard. Soon Sasha will come to the blackboard and start the following actions: let x and y be two adjacent numbers (x before y), then he can remove them and write x + 2y instead of them. He will perform these operations until one number is left. Sasha likes big numbers and ...
The first line contains two integers n and q (1 ≤ n, q ≤ 105) — the number of integers on the blackboard and the number of Nikita's options. The next line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the sequence on the blackboard. Each of the next q lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n...
For each option output Sasha's result modulo 109 + 7.
null
In the second sample Nikita doesn't erase anything. Sasha first erases the numbers 1 and 2 and writes 5. Then he erases 5 and -3 and gets -1. -1 modulo 109 + 7 is 109 + 6.
[{"input": "3 3\n1 2 3\n1 3\n1 2\n2 3", "output": "17\n5\n8"}, {"input": "3 1\n1 2 -3\n1 3", "output": "1000000006"}, {"input": "4 2\n1 1 1 -1\n1 4\n3 4", "output": "5\n1000000006"}]
3,300
["combinatorics", "dp"]
55
[{"input": "3 3\r\n1 2 3\r\n1 3\r\n1 2\r\n2 3\r\n", "output": "17\r\n5\r\n8\r\n"}, {"input": "3 1\r\n1 2 -3\r\n1 3\r\n", "output": "1000000006\r\n"}, {"input": "4 2\r\n1 1 1 -1\r\n1 4\r\n3 4\r\n", "output": "5\r\n1000000006\r\n"}, {"input": "4 1\r\n1 1 -3 1\r\n1 4\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1000000000\...
false
stdio
null
true
735/B
735
B
PyPy 3
TESTS
3
139
0
83912169
n, n1, n2 = [int(i) for i in input().split()] arr = [int(i) for i in input().split()] arr.sort(reverse=True) print(sum(arr[:min(n1, n2)]) / min(n1, n2) + sum(arr[min(n1, n2):max(n1, n2)+1]) / max(n1, n2))
37
93
7,065,600
147723791
in1=input().split() n=int(in1[0]) temp_n1=int(in1[1]) temp_n2=int(in1[2]) n1=min(temp_n1,temp_n2) n2=max(temp_n1,temp_n2) wealth=[int(i1) for i1 in input().split()] wealth.sort(reverse=True) avg1=sum(wealth[ :n1])/n1 avg2=sum(wealth[n1:n1+n2])/n2 print(avg1+avg2)
Codeforces Round 382 (Div. 2)
CF
2,016
2
256
Urbanization
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities. The wealth of the i of them is equal to ai. Authorities plan to build two cities, first for n1 people and second for n2 peo...
The first line of the input contains three integers n, n1 and n2 (1 ≤ n, n1, n2 ≤ 100 000, n1 + n2 ≤ n) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city. The second line contains n integers a1, a2, ..., a...
Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer ...
null
In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second. In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (a3 + a4) / 2 + a2 = (3 + 2) / 2 + 4 = 6.5
[{"input": "2 1 1\n1 5", "output": "6.00000000"}, {"input": "4 2 1\n1 4 2 3", "output": "6.50000000"}]
1,100
["greedy", "number theory", "sortings"]
37
[{"input": "2 1 1\r\n1 5\r\n", "output": "6.00000000\r\n"}, {"input": "4 2 1\r\n1 4 2 3\r\n", "output": "6.50000000\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n", "output": "4.50000000\r\n"}, {"input": "10 4 6\r\n3 5 7 9 12 25 67 69 83 96\r\n", "output": "88.91666667\r\n"}, {"input": "19 7 12\r\n1 2 4 8 16 32 64 128 256 512 10...
false
stdio
import sys def main(): input_path, correct_output_path, submission_output_path = sys.argv[1:4] with open(correct_output_path, 'r') as f: correct_output = f.read().strip() with open(submission_output_path, 'r') as f: submission_output = f.read().strip() try: correct = float(cor...
true
463/D
463
D
PyPy 3
TESTS
1
93
1,536,000
204890117
def solve_1(s1, s2): N = len(s1) dp = [[0] * (N + 1) for _ in range(N + 1)] for i in range(1, N + 1): for j in range(1, N + 1): if s1[i - 1] == s2[j - 1]: dp[i][j] = dp[i - 1][j - 1] + 1 else: dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) retu...
40
124
29,388,800
115843377
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO,IOBase def main(): n,k = map(int,input().split()) arr = [list(map(int,input().split())) for _ in range(k)] edg = [[1]*n for _ in range(n)] for i in range(k): for j in range(n): for l i...
Codeforces Round 264 (Div. 2)
CF
2,014
2
256
Gargari and Permutations
Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should find the length of the longest common subsequence of these permutations. Can...
The first line contains two integers n and k (1 ≤ n ≤ 1000; 2 ≤ k ≤ 5). Each of the next k lines contains integers 1, 2, ..., n in some order — description of the current permutation.
Print the length of the longest common subsequence.
null
The answer for the first test sample is subsequence [1, 2, 3].
[{"input": "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3", "output": "3"}]
1,900
["dfs and similar", "dp", "graphs", "implementation"]
40
[{"input": "4 3\r\n1 4 2 3\r\n4 1 2 3\r\n1 2 4 3\r\n", "output": "3\r\n"}, {"input": "6 3\r\n2 5 1 4 6 3\r\n5 1 4 3 2 6\r\n5 4 2 6 3 1\r\n", "output": "3\r\n"}, {"input": "41 4\r\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\r\n22 13 25 24 38 35 29 12...
false
stdio
null
true
594/A
594
A
PyPy 3-64
TESTS
2
46
0
181048619
n = int(input()) a = [int(i) for i in input().split()] a.sort() min_res = 200_010 for i in range(n//2): if a[i+n//2] - a[i] < min_res: min_res = a[i+n//2] - a[i] print(min_res)
50
217
16,179,200
189263054
# LUOGU_RID: 99814317 ans=0x3f3f3f3f n=int(input()) a=list(map(int,input().split()))#输入n个点的位置坐标 b=n//2 a.sort()#给n个点的位置坐标从小到大排序 for i in range(b):#找出最后剩下的两个点的位置坐标的最小值 ans=min(ans,a[b+i]-a[i])#a[b+i]为剩下右侧的点的位置坐标,a[i]为剩下左侧的点的位置坐标 print(ans)
Codeforces Round 330 (Div. 1)
CF
2,015
2
256
Warrior and Archer
In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest. V...
The first line on the input contains a single integer n (2 ≤ n ≤ 200 000, n is even) — the number of positions available initially. The second line contains n distinct integers x1, x2, ..., xn (0 ≤ xi ≤ 109), giving the coordinates of the corresponding positions.
Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally.
null
In the first sample one of the optimum behavior of the players looks like that: 1. Vova bans the position at coordinate 15; 2. Lesha bans the position at coordinate 3; 3. Vova bans the position at coordinate 31; 4. Lesha bans the position at coordinate 1. After these actions only positions 0 and 7 will remain, and th...
[{"input": "6\n0 1 3 7 15 31", "output": "7"}, {"input": "2\n73 37", "output": "36"}]
2,300
["games"]
50
[{"input": "6\r\n0 1 3 7 15 31\r\n", "output": "7\r\n"}, {"input": "2\r\n73 37\r\n", "output": "36\r\n"}, {"input": "2\r\n0 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "8\r\n729541013 135019377 88372488 319157478 682081360 558614617 258129110 790518782\r\n", "output": "470242129\r\n"}, {"input": "2\r\n0 1\r...
false
stdio
null
true
376/B
376
B
Python 3
TESTS
3
46
307,200
5692747
n,m=map(int,input().split()) f=[[0 for _ in range(n)] for _ in range(n)] for i in range(m): a,b,c=map(int,input().split()) f[a-1][b-1]=c for i in range(n): for j in range(n): if f[i][j]>0: for k in range(n): if f[j][k]>0: if f[i][j]>=f[j][k]: ...
29
46
0
189698875
n, m = map(int, input().split()) own = dict() for _ in range(m): a, b, c = map(int, input().split()) if a in own: own[a] += c else: own[a] = c if b in own: own[b] -= c else: own[b] = -c ans = 0 for i in own.values(): ans += i if i > 0 else 0 print(ans)
Codeforces Round 221 (Div. 2)
CF
2,013
1
256
I.O.U.
Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The...
The first line contains two integers n and m (1 ≤ n ≤ 100; 0 ≤ m ≤ 104). The next m lines contain the debts. The i-th line contains three integers ai, bi, ci (1 ≤ ai, bi ≤ n; ai ≠ bi; 1 ≤ ci ≤ 100), which mean that person ai owes person bi ci rubles. Assume that the people are numbered by integers from 1 to n. It is ...
Print a single integer — the minimum sum of debts in the optimal rearrangement.
null
In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10. In the second sample, there are no debts. In the third sample, you can annul all the debts.
[{"input": "5 3\n1 2 10\n2 3 1\n2 4 1", "output": "10"}, {"input": "3 0", "output": "0"}, {"input": "4 3\n1 2 1\n2 3 1\n3 1 1", "output": "0"}]
1,300
["implementation"]
29
[{"input": "5 3\r\n1 2 10\r\n2 3 1\r\n2 4 1\r\n", "output": "10\r\n"}, {"input": "3 0\r\n", "output": "0\r\n"}, {"input": "4 3\r\n1 2 1\r\n2 3 1\r\n3 1 1\r\n", "output": "0\r\n"}, {"input": "20 28\r\n1 5 6\r\n1 12 7\r\n1 13 4\r\n1 15 7\r\n1 20 3\r\n2 4 1\r\n2 15 6\r\n3 5 3\r\n3 8 10\r\n3 13 8\r\n3 20 6\r\n4 6 10\r\n4 1...
false
stdio
null
true
888/G
888
G
PyPy 3
TESTS
2
124
5,120,000
217245536
V = 2 MX = 3; class Node: def __init__(self) -> None: self.childs = [None]*V self.ended = False self.val = -1 self.cnt = 0 root = Node() def add(x): cur = root for i in range(MX,-1,-1): # store from msb...lsb ind = (x>>i)&1 if not cur.childs[ind]: cur.childs[i...
79
997
149,504,000
225470974
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def insert(x, la): j = 0 for i in p: if x & i: if not G[j] >> 25: la += 1 G[j] ^= la << 25 j = la else: j = G[j] >> 25 else: ...
Educational Codeforces Round 32
ICPC
2,017
2
256
Xor-MST
You are given a complete undirected graph with n vertices. A number ai is assigned to each vertex, and the weight of an edge between vertices i and j is equal to ai xor aj. Calculate the weight of the minimum spanning tree in this graph.
The first line contains n (1 ≤ n ≤ 200000) — the number of vertices in the graph. The second line contains n integers a1, a2, ..., an (0 ≤ ai < 230) — the numbers assigned to the vertices.
Print one number — the weight of the minimum spanning tree in the graph.
null
null
[{"input": "5\n1 2 3 4 5", "output": "8"}, {"input": "4\n1 2 3 4", "output": "8"}]
2,300
["bitmasks", "constructive algorithms", "data structures"]
79
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "8\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "8\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}]
false
stdio
null
true
888/G
888
G
PyPy 3-64
TESTS
2
109
9,113,600
184858836
def calc(a,k): if len(a)<=1: return 0 if k<0: return 0 c0=[] c1=[] for i in a: if (i>>k)&1: c1.append(i^(1<<k)) else: c0.append(i) res=1<<30 if len(c0)>=2: res=min(res,calc(c0,k-1)) if len(c1)>=2: res=min(res,calc(c1,k-1)) if len(c0)==len(c1)==1: res=min(res,(1<...
79
997
149,504,000
225470974
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def insert(x, la): j = 0 for i in p: if x & i: if not G[j] >> 25: la += 1 G[j] ^= la << 25 j = la else: j = G[j] >> 25 else: ...
Educational Codeforces Round 32
ICPC
2,017
2
256
Xor-MST
You are given a complete undirected graph with n vertices. A number ai is assigned to each vertex, and the weight of an edge between vertices i and j is equal to ai xor aj. Calculate the weight of the minimum spanning tree in this graph.
The first line contains n (1 ≤ n ≤ 200000) — the number of vertices in the graph. The second line contains n integers a1, a2, ..., an (0 ≤ ai < 230) — the numbers assigned to the vertices.
Print one number — the weight of the minimum spanning tree in the graph.
null
null
[{"input": "5\n1 2 3 4 5", "output": "8"}, {"input": "4\n1 2 3 4", "output": "8"}]
2,300
["bitmasks", "constructive algorithms", "data structures"]
79
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "8\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "8\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}]
false
stdio
null
true
177/D1
177
D2
Python 3
TESTS2
3
124
0
117258709
def range_sum(parr, l, r): if l==r and l==0: return parr[l] if l==r: return parr[l]-parr[l-1] if l==0: return parr[r] return parr[r] - parr[l-1] n,m,c = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) pb = [0]*m pb[0] = b[0] for i in range(1,m...
12
92
0
176975249
''' Online Python Compiler. Code, Compile, Run and Debug python program online. Write your code in this editor and press "Run" button to execute it. ''' n,m,c=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) prefsum=[0] for j in...
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Encrypting Messages
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers...
The first input line contains three integers n, m and c, separated by single spaces. The second input line contains n integers ai (0 ≤ ai < c), separated by single spaces — the original message. The third input line contains m integers bi (0 ≤ bi < c), separated by single spaces — the encryption key. The input limit...
Print n space-separated integers — the result of encrypting the original message.
null
In the first sample the encryption is performed in two steps: after the first step a = (0, 0, 0, 1) (remember that the calculations are performed modulo 2), after the second step a = (0, 1, 1, 0), and that is the answer.
[{"input": "4 3 2\n1 1 1 1\n1 1 1", "output": "0 1 1 0"}, {"input": "3 1 5\n1 2 3\n4", "output": "0 1 2"}]
1,200
["brute force"]
12
[{"input": "4 3 2\r\n1 1 1 1\r\n1 1 1\r\n", "output": "0 1 1 0\r\n"}, {"input": "3 1 5\r\n1 2 3\r\n4\r\n", "output": "0 1 2\r\n"}, {"input": "5 2 7\r\n0 0 1 2 4\r\n3 5\r\n", "output": "3 1 2 3 2\r\n"}, {"input": "20 15 17\r\n4 9 14 11 15 16 15 4 0 10 7 12 10 1 8 6 7 14 1 13\r\n6 3 14 8 8 11 16 4 5 9 2 13 6 14 15\r\n", ...
false
stdio
null
true
247/D
250
D
Python 3
TESTS
3
92
0
13550585
# http://codeforces.com/problemset/problem/250/D # inputFile.readline from math import sqrt def calcPath(x1, y1, x2, y2): return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)) # with open('h.in', 'r') as inputFile, open('h.out', 'w') as outputFile: (n, m, a, b) = [int(x) for x in input().strip().split(' ')] A = [int(x...
33
794
14,745,600
106349764
import sys def pro(): return sys.stdin.readline().strip() def rop(): return map(int, pro().split()) def main(): s = list(rop()) a = list(rop()) q = list(rop()) o = list(rop()) p = -1 t = (1e100, -1, -1) for i in range(s[1]): while not((p == - 1 or s[2] * q[i] - s[3] * a[p] >= 0) and (p + 1 == s[0] o...
CROC-MBTU 2012, Final Round
CF
2,012
1
256
Building Bridge
Two villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages. The river banks can be assumed to be vertical straight lines x = a and x = b (0 < a < b). The west village lies in a steppe at point O = (0...
The first line contains integers n, m, a, b (1 ≤ n, m ≤ 105, 0 < a < b < 106). The second line contains n integers in the ascending order: the i-th integer determines the coordinate of point Ai and equals yi (|yi| ≤ 106). The third line contains m integers in the ascending order: the i-th integer determines the coord...
Print two integers — the numbers of points on the left (west) and right (east) banks, respectively, between which you need to build a bridge. You can assume that the points on the west bank are numbered from 1 to n, in the order in which they are given in the input. Similarly, the points on the east bank are numbered f...
null
null
[{"input": "3 2 3 5\n-2 -1 4\n-1 2\n7 3", "output": "2 2"}]
1,900
[]
33
[{"input": "3 2 3 5\r\n-2 -1 4\r\n-1 2\r\n7 3\r\n", "output": "2 2"}, {"input": "1 1 10 20\r\n5\r\n-5\r\n1\r\n", "output": "1 1"}, {"input": "2 2 1 2\r\n-1 10\r\n8 9\r\n3 7\r\n", "output": "1 1"}, {"input": "10 20 50 60\r\n-96 -75 32 37 42 43 44 57 61 65\r\n-95 -90 -86 -79 -65 -62 -47 -11 -8 -6 1 8 23 25 32 51 73 88 94...
false
stdio
null
true
888/G
888
G
Python 3
TESTS
2
108
1,740,800
189721742
# LUOGU_RID: 100250825 class trie: def __init__(self): self.ch=[None,None] def add(self,s): cur=self for i in s: if not cur.ch[int(i)]: cur.ch[int(i)]=trie() cur=cur.ch[int(i)] def MST(self): tot=0 if self.ch[0]: tot=self.ch[0].MST() if self.ch[1]: tot+=self.ch[1].MST() if self.ch[0] an...
79
997
149,504,000
225470974
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def insert(x, la): j = 0 for i in p: if x & i: if not G[j] >> 25: la += 1 G[j] ^= la << 25 j = la else: j = G[j] >> 25 else: ...
Educational Codeforces Round 32
ICPC
2,017
2
256
Xor-MST
You are given a complete undirected graph with n vertices. A number ai is assigned to each vertex, and the weight of an edge between vertices i and j is equal to ai xor aj. Calculate the weight of the minimum spanning tree in this graph.
The first line contains n (1 ≤ n ≤ 200000) — the number of vertices in the graph. The second line contains n integers a1, a2, ..., an (0 ≤ ai < 230) — the numbers assigned to the vertices.
Print one number — the weight of the minimum spanning tree in the graph.
null
null
[{"input": "5\n1 2 3 4 5", "output": "8"}, {"input": "4\n1 2 3 4", "output": "8"}]
2,300
["bitmasks", "constructive algorithms", "data structures"]
79
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "8\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "8\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}]
false
stdio
null
true
888/G
888
G
PyPy 3-64
TESTS
2
155
103,833,600
224998215
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(l, u, v): return (l << 40) ^ (u << 20) ^ v def insert(x, c, la): j = 0 for i in p: if x & i: if not G[j] >> 25: la += 1 G[j] ^= la << 25 j = la ...
79
997
149,504,000
225470974
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def insert(x, la): j = 0 for i in p: if x & i: if not G[j] >> 25: la += 1 G[j] ^= la << 25 j = la else: j = G[j] >> 25 else: ...
Educational Codeforces Round 32
ICPC
2,017
2
256
Xor-MST
You are given a complete undirected graph with n vertices. A number ai is assigned to each vertex, and the weight of an edge between vertices i and j is equal to ai xor aj. Calculate the weight of the minimum spanning tree in this graph.
The first line contains n (1 ≤ n ≤ 200000) — the number of vertices in the graph. The second line contains n integers a1, a2, ..., an (0 ≤ ai < 230) — the numbers assigned to the vertices.
Print one number — the weight of the minimum spanning tree in the graph.
null
null
[{"input": "5\n1 2 3 4 5", "output": "8"}, {"input": "4\n1 2 3 4", "output": "8"}]
2,300
["bitmasks", "constructive algorithms", "data structures"]
79
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "8\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "8\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}]
false
stdio
null
true
177/D1
177
D1
Python 3
TESTS1
3
62
0
176972603
''' Online Python Compiler. Code, Compile, Run and Debug python program online. Write your code in this editor and press "Run" button to execute it. ''' n,m,c=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) prefsum=[b[0]] for j...
12
124
204,800
14750244
len_message, len_key, mod = map(int, input().split()) message = list(map(int, input().split())) key = list(map(int, input().split())) sum, low, high = 0, 0, 0 result = message[:] for i in range(len_message): if high < len_key: sum += key[high] high += 1 if i + len_key > len_message: sum...
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Encrypting Messages
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers...
The first input line contains three integers n, m and c, separated by single spaces. The second input line contains n integers ai (0 ≤ ai < c), separated by single spaces — the original message. The third input line contains m integers bi (0 ≤ bi < c), separated by single spaces — the encryption key. The input limit...
Print n space-separated integers — the result of encrypting the original message.
null
In the first sample the encryption is performed in two steps: after the first step a = (0, 0, 0, 1) (remember that the calculations are performed modulo 2), after the second step a = (0, 1, 1, 0), and that is the answer.
[{"input": "4 3 2\n1 1 1 1\n1 1 1", "output": "0 1 1 0"}, {"input": "3 1 5\n1 2 3\n4", "output": "0 1 2"}]
1,200
["brute force"]
12
[{"input": "4 3 2\r\n1 1 1 1\r\n1 1 1\r\n", "output": "0 1 1 0\r\n"}, {"input": "3 1 5\r\n1 2 3\r\n4\r\n", "output": "0 1 2\r\n"}, {"input": "5 2 7\r\n0 0 1 2 4\r\n3 5\r\n", "output": "3 1 2 3 2\r\n"}, {"input": "20 15 17\r\n4 9 14 11 15 16 15 4 0 10 7 12 10 1 8 6 7 14 1 13\r\n6 3 14 8 8 11 16 4 5 9 2 13 6 14 15\r\n", ...
false
stdio
null
true
151/B
151
B
Python 3
TESTS
0
15
0
206245008
n = int(input()) x={} for i in range(n) : nb , name = map(str , input().split() ) mx_tascore , max_pizzsco , max_girsco = 0 ,0 , 0 for j in range(int(nb)) : number = input() if (int(number[0]))>(int(number[1]))>(int(number[3]))>(int(number[4]))>(int(number[6])>(int(number[7])) ) : ...
38
77
0
187718251
n = int(input()) #taxi, pizza, girl all = [[], [], []] names = [] for i in range(n): s, name = input().split(" ") s = int(s) names.append(name) taxi = 0 pizza = 0 girl = 0 for ii in range(s): phone = [i for i in input().split("-")] phone = list(phone[0]) + list(phone[1])...
Codeforces Round 107 (Div. 2)
CF
2,012
2
256
Phone Numbers
Winters are just damn freezing cold in Nvodsk! That's why a group of n friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56). Each friend has a phonebook of size si (that's the number of phone numbers). We know that taxi numb...
The first line contains an integer n (1 ≤ n ≤ 100) — the number of friends. Then follow n data blocks that describe each friend's phone books. Each block is presented in the following form: first goes the line that contains integer si and string namei (0 ≤ si ≤ 100) — the number of phone numbers in the phone book of t...
In the first line print the phrase "If you want to call a taxi, you should call: ". Then print names of all friends whose phone books contain maximal number of taxi phone numbers. In the second line print the phrase "If you want to order a pizza, you should call: ". Then print names of all friends who have maximal num...
null
In the first sample you are given four friends. Fedorov's phone book contains one taxi number and one pizza delivery number, Melnikov's phone book only has 3 numbers of girls, Rogulenko's one has 6 taxi numbers and one pizza delivery number, Kaluzhin's one contains 2 taxi numbers and one pizza delivery number. Thus, i...
[{"input": "4\n2 Fedorov\n22-22-22\n98-76-54\n3 Melnikov\n75-19-09\n23-45-67\n99-99-98\n7 Rogulenko\n22-22-22\n11-11-11\n33-33-33\n44-44-44\n55-55-55\n66-66-66\n95-43-21\n3 Kaluzhin\n11-11-11\n99-99-99\n98-65-32", "output": "If you want to call a taxi, you should call: Rogulenko.\nIf you want to order a pizza, you shou...
1,200
["implementation", "strings"]
38
[{"input": "4\r\n2 Fedorov\r\n22-22-22\r\n98-76-54\r\n3 Melnikov\r\n75-19-09\r\n23-45-67\r\n99-99-98\r\n7 Rogulenko\r\n22-22-22\r\n11-11-11\r\n33-33-33\r\n44-44-44\r\n55-55-55\r\n66-66-66\r\n95-43-21\r\n3 Kaluzhin\r\n11-11-11\r\n99-99-99\r\n98-65-32\r\n", "output": "If you want to call a taxi, you should call: Rogulenk...
false
stdio
null
true
412/D
412
D
Python 3
PRETESTS
0
46
0
6411160
import sys line = str.split(input()," ") n = int(line[0]) m = int(line[1]) ab=[] for i in range(0,m): line = str.split(input()," ") ab.append([int(line[0]),int(line[1])]) #print("n:"+str(n)) #print("m:"+str(m)) #print("ab:"+str(ab)) def contains(a,b,ab): f = [a,b] for i in ab: if (f==i): ...
33
343
9,830,400
159254152
n,m=map(int,input().split()) g=[set()for i in range(n)] for i in range(m): a,b=map(int,input().split()) g[a-1].add(b-1) c=[0]*n for i in range(n): c[i]=i for i in range(n): j=i while j>0 and c[j] in g[c[j-1]]: c[j],c[j-1]=c[j-1],c[j] j-=1 for i in c: print(i+1,end=' ')
Coder-Strike 2014 - Round 1
CF
2,014
1
256
Giving Awards
The employees of the R1 company often spend time together: they watch football, they go camping, they solve contests. So, it's no big deal that sometimes someone pays for someone else. Today is the day of giving out money rewards. The R1 company CEO will invite employees into his office one by one, rewarding each one ...
The first line contains space-separated integers n and m $$(2\leq n\leq3\cdot10^{4};1\leq m\leq min(10^{5},\frac{n(n-1)}{2}))$$ — the number of employees in R1 and the number of debt relations. Each of the following m lines contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi), these integers indicate ...
Print -1 if the described order does not exist. Otherwise, print the permutation of n distinct integers. The first number should denote the number of the person who goes to the CEO office first, the second number denote the person who goes second and so on. If there are multiple correct orders, you are allowed to prin...
null
null
[{"input": "2 1\n1 2", "output": "2 1"}, {"input": "3 3\n1 2\n2 3\n3 1", "output": "2 1 3"}]
2,000
["dfs and similar"]
33
[{"input": "2 1\r\n1 2\r\n", "output": "2 1 \r\n"}, {"input": "3 3\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "2 1 3 \r\n"}, {"input": "10 45\r\n10 5\r\n10 7\r\n6 1\r\n5 8\r\n3 5\r\n6 5\r\n1 2\r\n6 10\r\n2 9\r\n9 5\r\n4 1\r\n7 5\r\n1 8\r\n6 8\r\n10 9\r\n7 2\r\n7 9\r\n4 10\r\n7 3\r\n4 8\r\n10 3\r\n10 8\r\n2 10\r\n8 2\r\n4 2\r...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n, m = map(int, f.readline().split()) edges = set() for _ in range(m): a, b = map(int, f.readline().split()) ...
true
436/C
436
C
PyPy 3-64
TESTS
2
46
0
176955206
import sys from array import array from bisect import * input = lambda: sys.stdin.buffer.readline().decode().strip() inp = lambda dtype: [dtype(x) for x in input().split()] inp_2d = lambda dtype, n: [dtype(input()) for _ in range(n)] inp_2ds = lambda dtype, n: [inp(dtype) for _ in range(n)] ceil1 = lambda a, b: (a + b...
30
1,964
62,873,600
232798881
import heapq total_bytes = 0 messages_sent = [] def send_message(messages, weight, start_ind): global total_bytes global messages_sent num_messages = len(messages) num_rows = len(messages[1]) num_cols = len(messages[1][0]) sent = [False] * num_messages # Send the first message tota...
Zepto Code Rush 2014
CF
2,014
2
256
Dungeons and Candies
During the loading of the game "Dungeons and Candies" you are required to get descriptions of k levels from the server. Each description is a map of an n × m checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if a cell ...
The first line contains four integers n, m, k, w (1 ≤ n, m ≤ 10; 1 ≤ k, w ≤ 1000). Then follows the description of k levels. Each level is described by n lines, each line contains m characters. Each character is either a letter of the English alphabet or a dot ("."). Please note that the case of the letters matters.
In the first line print the required minimum number of transferred bytes. Then print k pairs of integers x1, y1, x2, y2, ..., xk, yk, describing the way to transfer levels. Pair xi, yi means that level xi needs to be transferred by way yi. If yi equals 0, that means that the level must be transferred using the first w...
null
null
[{"input": "2 3 3 2\nA.A\n...\nA.a\n..C\nX.Y\n...", "output": "14\n1 0\n2 1\n3 1"}, {"input": "1 1 4 1\nA\n.\nB\n.", "output": "3\n1 0\n2 0\n4 2\n3 0"}, {"input": "1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB", "output": "11\n1 0\n3 1\n2 3\n4 2\n5 1"}]
1,800
["dsu", "graphs", "greedy", "trees"]
30
[{"input": "2 3 3 2\r\nA.A\r\n...\r\nA.a\r\n..C\r\nX.Y\r\n...\r\n", "output": "14\r\n1 0\r\n2 1\r\n3 1\r\n"}, {"input": "1 1 4 1\r\nA\r\n.\r\nB\r\n.\r\n", "output": "3\r\n1 0\r\n2 0\r\n4 2\r\n3 0\r\n"}, {"input": "1 3 5 2\r\nABA\r\nBBB\r\nBBA\r\nBAB\r\nABB\r\n", "output": "11\r\n1 0\r\n3 1\r\n2 3\r\n4 2\r\n5 1\r\n"}, {...
false
stdio
import sys def read_levels(input_path): with open(input_path) as f: lines = [line.strip() for line in f.readlines() if line.strip()] first_line = lines[0].split() n, m, k, w = map(int, first_line) levels = [None] # 1-based indexing idx = 1 for _ in range(k): level = [] ...
true
436/C
436
C
Python 3
TESTS
2
61
614,400
10516965
import random #dsu p = [] def finds(v): if p[v] != v: p[v] = finds(p[v]) return p[v] def union(v1,v2): r1 = finds(v1) r2 = finds(v2) if r1 != r2: if random.choice([0,1]) == 0: p[r1] = r2 else: p[r2] = r1 #input I = lambda:map(int,input().split()) n,m,k...
30
1,466
70,041,600
87968659
def put(): return map(int, input().split()) def diff(x,y): ans = 0 for i in range(n*m): if s[x][i]!= s[y][i]: ans+=1 return ans def find(i): if i==p[i]: return i p[i] = find(p[i]) return p[i] def union(i,j): if rank[i]>rank[j]: i,j = j,i elif rank[...
Zepto Code Rush 2014
CF
2,014
2
256
Dungeons and Candies
During the loading of the game "Dungeons and Candies" you are required to get descriptions of k levels from the server. Each description is a map of an n × m checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if a cell ...
The first line contains four integers n, m, k, w (1 ≤ n, m ≤ 10; 1 ≤ k, w ≤ 1000). Then follows the description of k levels. Each level is described by n lines, each line contains m characters. Each character is either a letter of the English alphabet or a dot ("."). Please note that the case of the letters matters.
In the first line print the required minimum number of transferred bytes. Then print k pairs of integers x1, y1, x2, y2, ..., xk, yk, describing the way to transfer levels. Pair xi, yi means that level xi needs to be transferred by way yi. If yi equals 0, that means that the level must be transferred using the first w...
null
null
[{"input": "2 3 3 2\nA.A\n...\nA.a\n..C\nX.Y\n...", "output": "14\n1 0\n2 1\n3 1"}, {"input": "1 1 4 1\nA\n.\nB\n.", "output": "3\n1 0\n2 0\n4 2\n3 0"}, {"input": "1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB", "output": "11\n1 0\n3 1\n2 3\n4 2\n5 1"}]
1,800
["dsu", "graphs", "greedy", "trees"]
30
[{"input": "2 3 3 2\r\nA.A\r\n...\r\nA.a\r\n..C\r\nX.Y\r\n...\r\n", "output": "14\r\n1 0\r\n2 1\r\n3 1\r\n"}, {"input": "1 1 4 1\r\nA\r\n.\r\nB\r\n.\r\n", "output": "3\r\n1 0\r\n2 0\r\n4 2\r\n3 0\r\n"}, {"input": "1 3 5 2\r\nABA\r\nBBB\r\nBBA\r\nBAB\r\nABB\r\n", "output": "11\r\n1 0\r\n3 1\r\n2 3\r\n4 2\r\n5 1\r\n"}, {...
false
stdio
import sys def read_levels(input_path): with open(input_path) as f: lines = [line.strip() for line in f.readlines() if line.strip()] first_line = lines[0].split() n, m, k, w = map(int, first_line) levels = [None] # 1-based indexing idx = 1 for _ in range(k): level = [] ...
true
412/D
412
D
Python 3
PRETESTS
3
62
0
6409547
from sys import setrecursionlimit setrecursionlimit(100500) def dfs(u): print(u + 1, end = ' ') visited[u] = True for x in edges[u]: if not visited[x]: dfs(x) n, m = map(int, input().split()) visited, drains, edges = [False] * n, [0] * n, [[] for x in range(n)] for x in range(m): ...
33
374
11,673,600
6413301
import sys n,m=map(int,sys.stdin.readline().split()) P={} for i in range(m): a,b=map(int,sys.stdin.readline().split()) P[(a-1,b-1)]=1 A=[-1]*n A[0]=0 for i in range(1,n): j=1 A[i]=i x=i while(x>0 and (A[x-1],A[x]) in P): A[x-1],A[x]=A[x],A[x-1] x-=1 Anss="" for i in range(n): ...
Coder-Strike 2014 - Round 1
CF
2,014
1
256
Giving Awards
The employees of the R1 company often spend time together: they watch football, they go camping, they solve contests. So, it's no big deal that sometimes someone pays for someone else. Today is the day of giving out money rewards. The R1 company CEO will invite employees into his office one by one, rewarding each one ...
The first line contains space-separated integers n and m $$(2\leq n\leq3\cdot10^{4};1\leq m\leq min(10^{5},\frac{n(n-1)}{2}))$$ — the number of employees in R1 and the number of debt relations. Each of the following m lines contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi), these integers indicate ...
Print -1 if the described order does not exist. Otherwise, print the permutation of n distinct integers. The first number should denote the number of the person who goes to the CEO office first, the second number denote the person who goes second and so on. If there are multiple correct orders, you are allowed to prin...
null
null
[{"input": "2 1\n1 2", "output": "2 1"}, {"input": "3 3\n1 2\n2 3\n3 1", "output": "2 1 3"}]
2,000
["dfs and similar"]
33
[{"input": "2 1\r\n1 2\r\n", "output": "2 1 \r\n"}, {"input": "3 3\r\n1 2\r\n2 3\r\n3 1\r\n", "output": "2 1 3 \r\n"}, {"input": "10 45\r\n10 5\r\n10 7\r\n6 1\r\n5 8\r\n3 5\r\n6 5\r\n1 2\r\n6 10\r\n2 9\r\n9 5\r\n4 1\r\n7 5\r\n1 8\r\n6 8\r\n10 9\r\n7 2\r\n7 9\r\n4 10\r\n7 3\r\n4 8\r\n10 3\r\n10 8\r\n2 10\r\n8 2\r\n4 2\r...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n, m = map(int, f.readline().split()) edges = set() for _ in range(m): a, b = map(int, f.readline().split()) ...
true
846/F
846
F
PyPy 3-64
TESTS
2
171
40,960,000
182256696
from sys import stdin input=lambda :stdin.readline()[:-1] n=int(input()) a=list(map(lambda x:int(x)-1,input().split())) c=[[] for i in range(10**6)] for i in range(n): c[a[i]].append(i) ans=1/n for i in range(10**6): if len(c[i])==0: continue x=[0]+c[i]+[n-1] res=n*(n-1) m=len(x) for i in range(1,m): ...
31
1,091
85,811,200
197617831
n=int(input()) a=list(map(int,input().split())) lastocc=[0]*1000006 ans=[0]*n ans[0]=1 lastocc[a[0]]=1 for i in range(1,n): ans[i]=ans[i-1]+(i+1-lastocc[a[i]]) lastocc[a[i]]=i+1 print((2*sum(ans)-n)/(n*n))
Educational Codeforces Round 28
ICPC
2,017
2
256
Random Query
You are given an array a consisting of n positive integers. You pick two integer numbers l and r from 1 to n, inclusive (numbers are picked randomly, equiprobably and independently). If l > r, then you swap values of l and r. You have to calculate the expected value of the number of unique elements in segment of the ar...
The first line contains one integer number n (1 ≤ n ≤ 106). The second line contains n integer numbers a1, a2, ... an (1 ≤ ai ≤ 106) — elements of the array.
Print one number — the expected number of unique elements in chosen segment. Your answer will be considered correct if its absolute or relative error doesn't exceed 10 - 4 — formally, the answer is correct if $${ \operatorname* { m i n } } ( | x - y |, { \frac { | x - y | } { x } } ) \leq 1 0 ^ { - 4 }$$, where x is j...
null
null
[{"input": "2\n1 2", "output": "1.500000"}, {"input": "2\n2 2", "output": "1.000000"}]
1,800
["data structures", "math", "probabilities", "two pointers"]
31
[{"input": "2\r\n1 2\r\n", "output": "1.500000\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1.000000\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "3.100000\r\n"}, {"input": "20\r\n49 33 9 8 50 21 12 44 23 39 24 10 17 4 17 40 24 19 27 21\r\n", "output": "7.010000\r\n"}, {"input": "1\r\n1000000\r\n", "outpu...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] # Read correct output with open(correct_output_path, 'r') as f: correct_line = f.readline().strip() x = float(correct_line) # Read submission output with open...
true
474/D
474
D
PyPy 3-64
TESTS
2
77
5,734,400
190973874
import sys input=sys.stdin.readline t,k=map(int,input().split()) dp=[0]*(100001) for i in range(1,k+1):dp[i]+=1 dp[k]+=1 for i in range(k+1,len(dp)): dp[i]=(dp[i-1]+dp[i-k])%(10**9+7) for i in range(len(dp)): dp[i]=(dp[i]+dp[i-1])%(10**9+7) for _ in range(t): l,r=map(int,input().split()) print(dp[r]-dp[...
43
156
10,444,800
209800957
from sys import stdin input = lambda: stdin.readline().rstrip('\r\n') M = int(1e9) + 7 N = int(1e5) + 5 t, k = map(int, input().split()) dp = [0]*N dp[0] = 1 for i in range(1, N): dp[i] = dp[i-1] + (i >= k) * dp[i-k] dp[i] %= M for i in range(1, N): dp[i] += dp[i-1] dp[i] %= M for _ in range(t): ...
Codeforces Round 271 (Div. 2)
CF
2,014
1.5
256
Flowers
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red. But, for a dinner to be tasty...
Input contains several test cases. The first line contains two integers t and k (1 ≤ t, k ≤ 105), where t represents the number of test cases. The next t lines contain two integers ai and bi (1 ≤ ai ≤ bi ≤ 105), describing the i-th test.
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
null
- For K = 2 and length 1 Marmot can eat (R). - For K = 2 and length 2 Marmot can eat (RR) and (WW). - For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR). - For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
[{"input": "3 2\n1 3\n2 3\n4 4", "output": "6\n5\n5"}]
1,700
["dp"]
43
[{"input": "3 2\r\n1 3\r\n2 3\r\n4 4\r\n", "output": "6\r\n5\r\n5\r\n"}, {"input": "1 1\r\n1 3\r\n", "output": "14\r\n"}, {"input": "1 2\r\n64329 79425\r\n", "output": "0\r\n"}]
false
stdio
null
true
351/E
351
E
Python 3
TESTS
1
92
0
228759640
def min_inversions(n, p): inv_count = 0 for i in range(n): # Count of numbers greater than |p[i]| that come after it greater_count = sum(1 for j in range(i+1, n) if abs(p[j]) > abs(p[i])) # Count of numbers smaller than |p[i]| that come after it smaller_count = sum(1 for j in ran...
36
280
3,686,400
150804902
import sys input = sys.stdin.buffer.readline def process(A): n = len(A) S = [1 for i in range(n)] d = {} for i in range(n): ai = abs(A[i]) if ai not in d: d[ai] = [] d[ai].append(i) L = sorted(d) answer = 0 while len(L) > 0: ai = L.pop() f...
Codeforces Round 204 (Div. 1)
CF
2,013
2
256
Jeff and Permutation
Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p1, p2, ..., pn for his birthday. Jeff hates inversions in sequences. An inversion in sequence a1, a2, ..., an is a pair of indexes i, j (1 ≤ i < j ≤ n), such that an inequality ai > aj holds. Jeff c...
The first line contains integer n (1 ≤ n ≤ 2000). The next line contains n integers — sequence p1, p2, ..., pn (|pi| ≤ 105). The numbers are separated by spaces.
In a single line print the answer to the problem — the minimum number of inversions Jeff can get.
null
null
[{"input": "2\n2 1", "output": "0"}, {"input": "9\n-2 0 -1 0 -1 2 1 0 -1", "output": "6"}]
2,200
["greedy"]
36
[{"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "9\r\n-2 0 -1 0 -1 2 1 0 -1\r\n", "output": "6\r\n"}, {"input": "9\r\n0 0 1 1 0 0 1 0 1\r\n", "output": "5\r\n"}, {"input": "8\r\n0 1 2 -1 -2 1 -2 2\r\n", "output": "3\r\n"}, {"input": "24\r\n-1 -1 2 2 0 -2 2 -1 0 0 2 -2 3 0 2 -3 0 -3 -1 1 0 0 -1 -2\r\n", "output...
false
stdio
null
true
247/D
250
D
Python 3
TESTS
3
92
0
13547255
# http://codeforces.com/problemset/problem/250/D from math import sqrt def calcPath(x1, y1, x2, y2): return sqrt(pow(x1-x2,2)+pow(y1-y2,2)) # with open('h.in', 'r') as inputFile, open('h.out', 'w') as outputFile: (n,m,a,b) = [int(x) for x in input().strip().split(' ')] A = [int(x) for x in input().strip().split(' ')...
33
1,122
11,878,400
13858446
from math import sqrt,fabs def dist(x1, y1, x2, y2): return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2)) def calcOptimumRightPoint(startX, startY): l = float("inf") idx = -1 for i in range(len(B)): d = dist(startX, startY, b, B[i]) + L[i] if d <= l: l = d i...
CROC-MBTU 2012, Final Round
CF
2,012
1
256
Building Bridge
Two villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages. The river banks can be assumed to be vertical straight lines x = a and x = b (0 < a < b). The west village lies in a steppe at point O = (0...
The first line contains integers n, m, a, b (1 ≤ n, m ≤ 105, 0 < a < b < 106). The second line contains n integers in the ascending order: the i-th integer determines the coordinate of point Ai and equals yi (|yi| ≤ 106). The third line contains m integers in the ascending order: the i-th integer determines the coord...
Print two integers — the numbers of points on the left (west) and right (east) banks, respectively, between which you need to build a bridge. You can assume that the points on the west bank are numbered from 1 to n, in the order in which they are given in the input. Similarly, the points on the east bank are numbered f...
null
null
[{"input": "3 2 3 5\n-2 -1 4\n-1 2\n7 3", "output": "2 2"}]
1,900
[]
33
[{"input": "3 2 3 5\r\n-2 -1 4\r\n-1 2\r\n7 3\r\n", "output": "2 2"}, {"input": "1 1 10 20\r\n5\r\n-5\r\n1\r\n", "output": "1 1"}, {"input": "2 2 1 2\r\n-1 10\r\n8 9\r\n3 7\r\n", "output": "1 1"}, {"input": "10 20 50 60\r\n-96 -75 32 37 42 43 44 57 61 65\r\n-95 -90 -86 -79 -65 -62 -47 -11 -8 -6 1 8 23 25 32 51 73 88 94...
false
stdio
null
true
265/B
265
B
Python 3
TESTS
2
122
7,065,600
129628906
#265B t = int(input()) tree = [] for i in range(t): tree.append(int(input())) m = min(tree) total = 0 for i in range(t): if (i == t - 1): total+= (tree[i] - m) else: total+= (tree[i] - m) * 2 ans = total + (m * t) + t print(ans)
15
124
2,662,400
177435498
import sys input = lambda: sys.stdin.buffer.readline().decode().strip() inl = lambda: list(map(int, input().split())) n = int(input()) a = [int(input()) for _ in range(n)] # 1. intial value ans = n + a[0] # 2. diff between each two tress for i in range(len(a) - 1): ans += abs(a[i] - a[i + 1]) + 1 # 3. print an...
Codeforces Round 162 (Div. 2)
CF
2,013
2
256
Roadside Trees (Simplified Edition)
Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following act...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of trees. Next n lines contains the height of trees: i-th line contains an integer hi (1 ≤ hi ≤ 104) — the height of the tree with the number i.
Print a single integer — the minimal time required to eat all nuts in seconds.
null
null
[{"input": "2\n1\n2", "output": "5"}, {"input": "5\n2\n1\n2\n1\n1", "output": "14"}]
1,000
["greedy", "implementation"]
15
[{"input": "2\r\n1\r\n2\r\n", "output": "5\r\n"}, {"input": "5\r\n2\r\n1\r\n2\r\n1\r\n1\r\n", "output": "14\r\n"}, {"input": "1\r\n1\r\n", "output": "2\r\n"}]
false
stdio
null
true
265/B
265
B
Python 3
TESTS
2
122
0
105161618
n=int(input()) count=0 h=int(input()) count=h+1 while(n>1): n-=1 h1=int(input()) if(h>h1): count+=h-h1 h=h-h1 count+=1 count+=h1-h count+=1 h=h1 print(count)
15
186
0
155483755
import sys input = sys.stdin.readline c, h = 0, 0 k = int(input()) for _ in range(k): n = int(input()) c += abs(n - h) + 1 h += n - h print(c+k-1)
Codeforces Round 162 (Div. 2)
CF
2,013
2
256
Roadside Trees (Simplified Edition)
Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following act...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of trees. Next n lines contains the height of trees: i-th line contains an integer hi (1 ≤ hi ≤ 104) — the height of the tree with the number i.
Print a single integer — the minimal time required to eat all nuts in seconds.
null
null
[{"input": "2\n1\n2", "output": "5"}, {"input": "5\n2\n1\n2\n1\n1", "output": "14"}]
1,000
["greedy", "implementation"]
15
[{"input": "2\r\n1\r\n2\r\n", "output": "5\r\n"}, {"input": "5\r\n2\r\n1\r\n2\r\n1\r\n1\r\n", "output": "14\r\n"}, {"input": "1\r\n1\r\n", "output": "2\r\n"}]
false
stdio
null
true
265/B
265
B
Python 3
TESTS
2
122
0
114982362
n = int(input()) p=int(input()) t=p+1 for i in range(1,n): h=int(input()) if(h<p): t+=(p-h)+2 else: t+=2+(h-p) print(t)
15
186
10,547,200
172097524
import math import copy import itertools import bisect import sys input = sys.stdin.readline def ilst(): return list(map(int,input().split())) def inum(): return map(int,input().split()) def islst(): return list(map(str,input().split())) n = int(input()) l = [] for _ in range(n): l.append(i...
Codeforces Round 162 (Div. 2)
CF
2,013
2
256
Roadside Trees (Simplified Edition)
Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following act...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of trees. Next n lines contains the height of trees: i-th line contains an integer hi (1 ≤ hi ≤ 104) — the height of the tree with the number i.
Print a single integer — the minimal time required to eat all nuts in seconds.
null
null
[{"input": "2\n1\n2", "output": "5"}, {"input": "5\n2\n1\n2\n1\n1", "output": "14"}]
1,000
["greedy", "implementation"]
15
[{"input": "2\r\n1\r\n2\r\n", "output": "5\r\n"}, {"input": "5\r\n2\r\n1\r\n2\r\n1\r\n1\r\n", "output": "14\r\n"}, {"input": "1\r\n1\r\n", "output": "2\r\n"}]
false
stdio
null
true
265/B
265
B
Python 3
TESTS
2
122
0
178157411
""" https://codeforces.com/problemset/problem/265/B """ x = int(input()) trees = [int(input()) for _ in range(x)] hauteur = trees[0] total = trees[0] indice = 1 while indice < x: if hauteur <= trees[indice]: total += trees[indice] - hauteur else: total += trees[indice] hauteur = trees[indice...
15
218
3,174,400
179967935
import sys input = sys.stdin.readline n = int (input()) prev = 0 ans = n + (n-1) while n > 0: x = int (input()) ans += abs(prev-x) prev = x n-=1 print (ans)
Codeforces Round 162 (Div. 2)
CF
2,013
2
256
Roadside Trees (Simplified Edition)
Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following act...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of trees. Next n lines contains the height of trees: i-th line contains an integer hi (1 ≤ hi ≤ 104) — the height of the tree with the number i.
Print a single integer — the minimal time required to eat all nuts in seconds.
null
null
[{"input": "2\n1\n2", "output": "5"}, {"input": "5\n2\n1\n2\n1\n1", "output": "14"}]
1,000
["greedy", "implementation"]
15
[{"input": "2\r\n1\r\n2\r\n", "output": "5\r\n"}, {"input": "5\r\n2\r\n1\r\n2\r\n1\r\n1\r\n", "output": "14\r\n"}, {"input": "1\r\n1\r\n", "output": "2\r\n"}]
false
stdio
null
true
32/A
32
A
Python 3
TESTS
3
218
0
46680942
n, d = map(int, input().split()) a = [int(i) for i in input().split()] m = [] for k in range(n): l = [a[i]-a[k] for i in range(n) if abs(a[i]-a[k]) <= 10] m.append(len(l)) print(max(m)*(max(m)-1))
32
122
307,200
27425665
n, d = (int(x) for x in input().split()) a = sorted([int(x) for x in input().split()]) s = 0 l = 0 for r in range(1, n): while a[r] - a[l] > d: l += 1 s += (r - l) * 2 print(s)
Codeforces Beta Round 32 (Div. 2, Codeforces format)
CF
2,010
2
256
Reconnaissance
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are ...
The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
null
null
[{"input": "5 10\n10 20 50 60 65", "output": "6"}, {"input": "5 1\n55 30 29 31 55", "output": "6"}]
800
["brute force"]
32
[{"input": "5 10\r\n10 20 50 60 65\r\n", "output": "6\r\n"}, {"input": "5 1\r\n55 30 29 31 55\r\n", "output": "6\r\n"}, {"input": "6 10\r\n4 6 4 1 9 3\r\n", "output": "30\r\n"}, {"input": "7 100\r\n19 1694 261 162 1 234 513\r\n", "output": "8\r\n"}, {"input": "8 42\r\n37 53 74 187 568 22 5 65\r\n", "output": "20\r\n"},...
false
stdio
null
true
813/F
813
F
PyPy 3-64
TESTS
2
62
0
173855331
from collections import defaultdict, deque from math import inf def bfsBipartite(graph,s=1): colors = dict() cola = deque() cola.append(s) colors[s] = 1 while len(cola)> 0: u = cola.popleft() ady = filter(lambda x: graph[u][x]!= inf,graph[u].keys()) for v in ady: ...
25
1,185
83,660,800
215838651
from collections import defaultdict import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v, w): return (u * n2 + v) * n2 + w def g(u, v): return u * n2 + v def get_root(s): while s ^ root[s]: s = root[s] return s def unite(s, t, i): s, t = get_root(s),...
Educational Codeforces Round 22
ICPC
2,017
6
256
Bipartite Checking
You are given an undirected graph consisting of n vertices. Initially there are no edges in the graph. Also you are given q queries, each query either adds one undirected edge to the graph or removes it. After each query you have to check if the resulting graph is bipartite (that is, you can paint all vertices of the g...
The first line contains two integers n and q (2 ≤ n, q ≤ 100000). Then q lines follow. ith line contains two numbers xi and yi (1 ≤ xi < yi ≤ n). These numbers describe ith query: if there is an edge between vertices xi and yi, then remove it, otherwise add it.
Print q lines. ith line must contain YES if the graph is bipartite after ith query, and NO otherwise.
null
null
[{"input": "3 5\n2 3\n1 3\n1 2\n1 2\n1 2", "output": "YES\nYES\nNO\nYES\nNO"}]
2,500
["data structures", "dsu", "graphs"]
25
[{"input": "3 5\r\n2 3\r\n1 3\r\n1 2\r\n1 2\r\n1 2\r\n", "output": "YES\r\nYES\r\nNO\r\nYES\r\nNO\r\n"}, {"input": "5 10\r\n1 5\r\n2 5\r\n2 4\r\n1 4\r\n4 5\r\n2 4\r\n2 5\r\n1 4\r\n2 3\r\n1 2\r\n", "output": "YES\r\nYES\r\nYES\r\nYES\r\nNO\r\nNO\r\nNO\r\nYES\r\nYES\r\nYES\r\n"}, {"input": "10 20\r\n1 10\r\n5 7\r\n1 2\r\...
false
stdio
null
true
247/D
250
D
Python 3
TESTS
1
78
307,200
51285153
import sys from math import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) n, m, a, b = mints() A = list(mints()) B = list(mints()) l = list(mints()) j = -1 r = (1e100,-1,-1) for i in range(m): while not((j == -1 or a*B[i]-b*A[j] >= ...
33
794
14,745,600
106349764
import sys def pro(): return sys.stdin.readline().strip() def rop(): return map(int, pro().split()) def main(): s = list(rop()) a = list(rop()) q = list(rop()) o = list(rop()) p = -1 t = (1e100, -1, -1) for i in range(s[1]): while not((p == - 1 or s[2] * q[i] - s[3] * a[p] >= 0) and (p + 1 == s[0] o...
CROC-MBTU 2012, Final Round
CF
2,012
1
256
Building Bridge
Two villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages. The river banks can be assumed to be vertical straight lines x = a and x = b (0 < a < b). The west village lies in a steppe at point O = (0...
The first line contains integers n, m, a, b (1 ≤ n, m ≤ 105, 0 < a < b < 106). The second line contains n integers in the ascending order: the i-th integer determines the coordinate of point Ai and equals yi (|yi| ≤ 106). The third line contains m integers in the ascending order: the i-th integer determines the coord...
Print two integers — the numbers of points on the left (west) and right (east) banks, respectively, between which you need to build a bridge. You can assume that the points on the west bank are numbered from 1 to n, in the order in which they are given in the input. Similarly, the points on the east bank are numbered f...
null
null
[{"input": "3 2 3 5\n-2 -1 4\n-1 2\n7 3", "output": "2 2"}]
1,900
[]
33
[{"input": "3 2 3 5\r\n-2 -1 4\r\n-1 2\r\n7 3\r\n", "output": "2 2"}, {"input": "1 1 10 20\r\n5\r\n-5\r\n1\r\n", "output": "1 1"}, {"input": "2 2 1 2\r\n-1 10\r\n8 9\r\n3 7\r\n", "output": "1 1"}, {"input": "10 20 50 60\r\n-96 -75 32 37 42 43 44 57 61 65\r\n-95 -90 -86 -79 -65 -62 -47 -11 -8 -6 1 8 23 25 32 51 73 88 94...
false
stdio
null
true
32/A
32
A
Python 3
TESTS
3
92
0
177074613
"""According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldie...
32
122
1,945,600
202802705
_, b = map(int, input().split()) a = list(map(int, input().split())) a.sort();k = 0 for i in range(len(a)): for j in range(i+1, len(a)): if abs(a[j] - a[i]) <= b: k += 1; print(k *2)
Codeforces Beta Round 32 (Div. 2, Codeforces format)
CF
2,010
2
256
Reconnaissance
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are ...
The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
null
null
[{"input": "5 10\n10 20 50 60 65", "output": "6"}, {"input": "5 1\n55 30 29 31 55", "output": "6"}]
800
["brute force"]
32
[{"input": "5 10\r\n10 20 50 60 65\r\n", "output": "6\r\n"}, {"input": "5 1\r\n55 30 29 31 55\r\n", "output": "6\r\n"}, {"input": "6 10\r\n4 6 4 1 9 3\r\n", "output": "30\r\n"}, {"input": "7 100\r\n19 1694 261 162 1 234 513\r\n", "output": "8\r\n"}, {"input": "8 42\r\n37 53 74 187 568 22 5 65\r\n", "output": "20\r\n"},...
false
stdio
null
true
846/F
846
F
PyPy 3-64
TESTS
2
46
0
229354204
n = int(input()) a = list(map(int, input().split())) e = [.0] * n ds, st = 1, 1 ans = 0.0 sll = len(set(a)) while st < n: ans += ds * 1 / n if a[st] != a[st - 1]: ds += 1 st += 1 ans += ds / n e[0] = ans i, ds = 1, 0 while i < n: e[i] = e[i - 1] if a[i] != a[i - 1]: ds += 1 if a[...
31
1,091
122,163,200
226537020
import math import sys def solve(): n = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().split())) last = {} all_possible = (n * n) not_pos = {} for i in range(n): if a[i] not in last: last[a[i]] = i not_pos[a[i]] = i * i else: ...
Educational Codeforces Round 28
ICPC
2,017
2
256
Random Query
You are given an array a consisting of n positive integers. You pick two integer numbers l and r from 1 to n, inclusive (numbers are picked randomly, equiprobably and independently). If l > r, then you swap values of l and r. You have to calculate the expected value of the number of unique elements in segment of the ar...
The first line contains one integer number n (1 ≤ n ≤ 106). The second line contains n integer numbers a1, a2, ... an (1 ≤ ai ≤ 106) — elements of the array.
Print one number — the expected number of unique elements in chosen segment. Your answer will be considered correct if its absolute or relative error doesn't exceed 10 - 4 — formally, the answer is correct if $${ \operatorname* { m i n } } ( | x - y |, { \frac { | x - y | } { x } } ) \leq 1 0 ^ { - 4 }$$, where x is j...
null
null
[{"input": "2\n1 2", "output": "1.500000"}, {"input": "2\n2 2", "output": "1.000000"}]
1,800
["data structures", "math", "probabilities", "two pointers"]
31
[{"input": "2\r\n1 2\r\n", "output": "1.500000\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1.000000\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "3.100000\r\n"}, {"input": "20\r\n49 33 9 8 50 21 12 44 23 39 24 10 17 4 17 40 24 19 27 21\r\n", "output": "7.010000\r\n"}, {"input": "1\r\n1000000\r\n", "outpu...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] # Read correct output with open(correct_output_path, 'r') as f: correct_line = f.readline().strip() x = float(correct_line) # Read submission output with open...
true
265/B
265
B
Python 3
TESTS
2
124
0
104007793
n = int(input()) curr = 0 time = 0 prev = 0 for i in range(n): h = int(input()) if prev<=h: curr = prev else: time+=(prev-h) curr = prev-h time+= (h-curr)+1 prev = h print(time+(n-1))# for jumps
15
248
0
214675105
n = int(input()) o = 0 t = 0 for i in range(n): x = int(input()) if x < o: t += o - x + 1 o = x else: t += x - o + 1 o = x t += 1 print(t - 1)
Codeforces Round 162 (Div. 2)
CF
2,013
2
256
Roadside Trees (Simplified Edition)
Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following act...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of trees. Next n lines contains the height of trees: i-th line contains an integer hi (1 ≤ hi ≤ 104) — the height of the tree with the number i.
Print a single integer — the minimal time required to eat all nuts in seconds.
null
null
[{"input": "2\n1\n2", "output": "5"}, {"input": "5\n2\n1\n2\n1\n1", "output": "14"}]
1,000
["greedy", "implementation"]
15
[{"input": "2\r\n1\r\n2\r\n", "output": "5\r\n"}, {"input": "5\r\n2\r\n1\r\n2\r\n1\r\n1\r\n", "output": "14\r\n"}, {"input": "1\r\n1\r\n", "output": "2\r\n"}]
false
stdio
null
true
265/B
265
B
Python 3
TESTS
2
124
0
112649662
n = int(input()) count = 0 g = int(input()) count+=g+1 for i in range(n-1): a = int(input()) if(a>g): count+=a-g+1+1 g = a else: count+=g-a+1+1 print(count)
15
248
0
220679465
n=int(input()) ans=2*n-1 pre=0 for i in range(n): cur=int(input()) ans+=abs(cur-pre) pre=cur print(ans)
Codeforces Round 162 (Div. 2)
CF
2,013
2
256
Roadside Trees (Simplified Edition)
Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following act...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of trees. Next n lines contains the height of trees: i-th line contains an integer hi (1 ≤ hi ≤ 104) — the height of the tree with the number i.
Print a single integer — the minimal time required to eat all nuts in seconds.
null
null
[{"input": "2\n1\n2", "output": "5"}, {"input": "5\n2\n1\n2\n1\n1", "output": "14"}]
1,000
["greedy", "implementation"]
15
[{"input": "2\r\n1\r\n2\r\n", "output": "5\r\n"}, {"input": "5\r\n2\r\n1\r\n2\r\n1\r\n1\r\n", "output": "14\r\n"}, {"input": "1\r\n1\r\n", "output": "2\r\n"}]
false
stdio
null
true
265/B
265
B
PyPy 3-64
TESTS
2
92
1,331,200
204337506
n, x = int(input()), 0 s = n * 2 for i in range(n): s += abs(x - i) x = i print(s)
15
248
0
230813787
n=int(input()) h=0 t=0 for j in range(n): hi = int(input()) if(j==0): h=hi t+=(hi+1) else: t+=(abs(hi-h)+2) h=hi # print(t) print(t)
Codeforces Round 162 (Div. 2)
CF
2,013
2
256
Roadside Trees (Simplified Edition)
Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following act...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of trees. Next n lines contains the height of trees: i-th line contains an integer hi (1 ≤ hi ≤ 104) — the height of the tree with the number i.
Print a single integer — the minimal time required to eat all nuts in seconds.
null
null
[{"input": "2\n1\n2", "output": "5"}, {"input": "5\n2\n1\n2\n1\n1", "output": "14"}]
1,000
["greedy", "implementation"]
15
[{"input": "2\r\n1\r\n2\r\n", "output": "5\r\n"}, {"input": "5\r\n2\r\n1\r\n2\r\n1\r\n1\r\n", "output": "14\r\n"}, {"input": "1\r\n1\r\n", "output": "2\r\n"}]
false
stdio
null
true
803/G
803
G
Python 3
TESTS
2
46
204,800
26910361
from sys import stdin, stdout n, k = map(int, stdin.readline().split()) values = [0] + list(map(int, stdin.readline().split())) m = int(stdin.readline()) questions = [] ar = set() for i in range(m): questions.append(tuple(map(int, stdin.readline().strip().split()))) ar.add(int(questions[-1][1])) ar.add(i...
32
2,823
117,350,400
230770543
import sys import random input = sys.stdin.readline rd = random.randint(10 ** 9, 2 * 10 ** 9) class SegmentTree(): def __init__(self, init, unitX, f): self.f = f # (X, X) -> X self.unitX = unitX self.f = f if type(init) == int: self.n = init self.n = 1 << ...
Educational Codeforces Round 20
ICPC
2,017
4
512
Periodic RMQ Problem
You are given an array a consisting of positive integers and q queries to this array. There are two types of queries: - 1 l r x — for each index i such that l ≤ i ≤ r set ai = x. - 2 l r — find the minimum among such ai that l ≤ i ≤ r. We decided that this problem is too easy. So the array a is given in a compressed ...
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 104). The second line contains n integers — elements of the array b (1 ≤ bi ≤ 109). The third line contains one integer q (1 ≤ q ≤ 105). Then q lines follow, each representing a query. Each query is given either as 1 l r x — set all elements in the s...
For each query of type 2 print the answer to this query — the minimum on the corresponding segment.
null
null
[{"input": "3 1\n1 2 3\n3\n2 1 3\n1 1 2 4\n2 1 3", "output": "1\n3"}, {"input": "3 2\n1 2 3\n5\n2 4 4\n1 4 4 5\n2 4 4\n1 1 6 1\n2 6 6", "output": "1\n5\n1"}]
2,300
["data structures"]
32
[{"input": "3 1\r\n1 2 3\r\n3\r\n2 1 3\r\n1 1 2 4\r\n2 1 3\r\n", "output": "1\r\n3\r\n"}, {"input": "3 2\r\n1 2 3\r\n5\r\n2 4 4\r\n1 4 4 5\r\n2 4 4\r\n1 1 6 1\r\n2 6 6\r\n", "output": "1\r\n5\r\n1\r\n"}, {"input": "10 10\r\n10 8 10 9 2 2 4 6 10 1\r\n10\r\n1 17 87 5\r\n2 31 94\r\n1 5 56 8\r\n1 56 90 10\r\n1 25 93 6\r\n1...
false
stdio
null
true
617/C
617
C
PyPy 3-64
TESTS
3
46
0
224668092
def app(x,y,a,b,r): return (abs(x-a)**2 + abs(y-b)**2) <= r def des(x,y,a,b): return (abs(x-a)**2 + abs(y-b)**2) numbers = input().split() arr = [] for i in range(int(numbers[0])): x,y = input().split() arr.append((int(x),int(y))) con = [] i=1 while i <len(numbers): con.append((int(numbers[i]),in...
31
124
2,457,600
231028527
import sys input=sys.stdin.readline n,x1,y1,x2,y2=map(int,input().split()) l=[] for _ in range(n): x,y=map(int,input().split()) l.append([(x-x1)**2+(y-y1)**2,(x-x2)**2+(y-y2)**2]) l.sort(reverse=True) s=10**18 q=0 for u,v in l: s=min(s,u+q) q=max(q,v) print(min(s,q))
Codeforces Round 340 (Div. 2)
CF
2,016
2
256
Watering Flowers
A flowerbed has many flowers and two fountains. You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, t...
The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000, - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain. Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flo...
Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.
null
The first sample is (r12 = 5, r22 = 1): The second sample is (r12 = 1, r22 = 32):
[{"input": "2 -1 0 5 3\n0 2\n5 2", "output": "6"}, {"input": "4 0 0 5 0\n9 4\n8 3\n-1 0\n1 4", "output": "33"}]
1,600
["implementation"]
31
[{"input": "2 -1 0 5 3\r\n0 2\r\n5 2\r\n", "output": "6\r\n"}, {"input": "4 0 0 5 0\r\n9 4\r\n8 3\r\n-1 0\r\n1 4\r\n", "output": "33\r\n"}, {"input": "5 -6 -4 0 10\r\n-7 6\r\n-9 7\r\n-5 -1\r\n-2 1\r\n-8 10\r\n", "output": "100\r\n"}, {"input": "10 -68 10 87 22\r\n30 89\r\n82 -97\r\n-52 25\r\n76 -22\r\n-20 95\r\n21 25\r...
false
stdio
null
true
504/D
504
D
Python 3
TESTS
0
92
204,800
97682151
m = int(input()) b = [] k = [] for i in range(m): x = int(input()) c = 0 for i in range(len(b)): v = b[i] d = k[i] if (x ^ v) < x: x ^= v c ^= d if x != 0: print(0) c ^= 2 ** i b.append(x) k.append(c) else: a =...
52
1,123
13,004,800
153501285
m = int(input()) basis = [] for i in range(m): a = int(input()) need=0 for v,bitset in basis: if a^v<a: need^=bitset a^=v if a: basis.append((a,need^(1<<i))) print(0) else: res = [d for d in range(i) if 1<<d&need] print(len(res), *res)
Codeforces Round 285 (Div. 1)
CF
2,015
2
256
Misha and XOR
After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the robot puts a number x to the basket, Misha should answer the quest...
The first line contains number m (1 ≤ m ≤ 2000), showing how many numbers are scattered around the room. The next m lines contain the numbers in the order in which the robot puts them in the basket. Each number is a positive integer strictly less than 10600 that doesn't contain leading zeroes.
For each number either print a 0 on the corresponding line, if the number cannot be represented as a XOR sum of numbers that are in the basket, or print integer k showing how many numbers are in the representation and the indexes of these numbers. Separate the numbers by spaces. Each number can occur in the representat...
null
The XOR sum of numbers is the result of bitwise sum of numbers modulo 2.
[{"input": "7\n7\n6\n5\n4\n3\n2\n1", "output": "0\n0\n0\n3 0 1 2\n2 1 2\n2 0 2\n2 0 1"}, {"input": "2\n5\n5", "output": "0\n1 0"}]
2,700
["bitmasks"]
52
[{"input": "7\r\n7\r\n6\r\n5\r\n4\r\n3\r\n2\r\n1\r\n", "output": "0\r\n0\r\n0\r\n3 0 1 2\r\n2 1 2\r\n2 0 2\r\n2 0 1\r\n"}, {"input": "2\r\n5\r\n5\r\n", "output": "0\r\n1 0\r\n"}, {"input": "10\r\n81\r\n97\r\n12\r\n2\r\n16\r\n96\r\n80\r\n99\r\n6\r\n83\r\n", "output": "0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n3 0 1 5\r\n2 1 3\r\n0\...
false
stdio
null
true
1006/E
1006
E
Python 3
TESTS
2
717
31,948,800
151488498
import threading import sys from sys import stdin input=stdin.readline sys.setrecursionlimit(10**7) from collections import defaultdict def main(): ans=[] size=[] n,q=map(int,input().split()) arr=list(map(int,input().split())) graph=[[] for _ in range(n)] for i in range(n-1): gra...
31
514
53,657,600
197438558
# https://codeforces.com/contest/1006 import sys from collections import deque input = lambda: sys.stdin.readline().rstrip() # faster! def solve_case(): n, q = map(int, input().split()) p = list(map(int, input().split())) direct_subordinates = [[] for _ in range(n + 1)] for officer, direct_superio...
Codeforces Round 498 (Div. 3)
ICPC
2,018
3
256
Military Problem
In this problem you will have to help Berland army with organizing their command delivery system. There are $$$n$$$ officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has exactly one direct superior. If officer $$$a$$$ is the direct superio...
The first line of the input contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 2 \cdot 10^5, 1 \le q \le 2 \cdot 10^5$$$) — the number of officers in Berland army and the number of queries. The second line of the input contains $$$n - 1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i < i$$$), where $$$p_i$...
Print $$$q$$$ numbers, where the $$$i$$$-th number is the officer at the position $$$k_i$$$ in the list which describes the order in which officers will receive the command if it starts spreading from officer $$$u_i$$$. Print "-1" if the number of officers which receive the command is less than $$$k_i$$$. You should p...
null
null
[{"input": "9 6\n1 1 1 3 5 3 5 7\n3 1\n1 5\n3 4\n7 3\n1 8\n1 9", "output": "3\n6\n8\n-1\n9\n4"}]
1,600
["dfs and similar", "graphs", "trees"]
31
[{"input": "9 6\r\n1 1 1 3 5 3 5 7\r\n3 1\r\n1 5\r\n3 4\r\n7 3\r\n1 8\r\n1 9\r\n", "output": "3\r\n6\r\n8\r\n-1\r\n9\r\n4\r\n"}, {"input": "2 1\r\n1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "13 12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n", "out...
false
stdio
null
true
975/E
975
E
Python 3
TESTS
2
77
7,065,600
37858919
from sys import stdin, stdout from math import atan2, sqrt, sin, cos, pi def main(): n, q = stdin.readline().split() n = int(n) q = int(q) lines = stdin.readlines() x = [0] * (n + 1) y = [0] * (n + 1) for i in range(n): x[i], y[i] = lines[i].split() x[i] = int(x[i]) ...
31
1,060
9,318,400
230718925
import sys read=lambda:map(int,sys.stdin.buffer.readline().split()) from math import * n,q=read() x,y=[],[] cx,cy=0,0 deg=0 p1,p2=0,1 def pos(i): return (cx+x[i]*cos(deg)-y[i]*sin(deg),cy+y[i]*cos(deg)+x[i]*sin(deg)) for i in range(n): _x,_y=read() x.append(_x);y.append(_y) s=0 for i in range(2,n): _s=(x[i]-x[0])*(...
Codeforces Round 478 (Div. 2)
CF
2,018
3
256
Hag's Khashba
Hag is a very talented person. He has always had an artist inside him but his father forced him to study mechanical engineering. Yesterday he spent all of his time cutting a giant piece of wood trying to make it look like a goose. Anyway, his dad found out that he was doing arts rather than studying mechanics and othe...
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$3\leq n \leq 10\,000$$$, $$$1 \leq q \leq 200000$$$) — the number of vertices in the polygon and the number of queries. The next $$$n$$$ lines describe the wooden polygon, the $$$i$$$-th line contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$|x_i|, |y_i|\leq...
The output should contain the answer to each query of second type — two numbers in a separate line. Your answer is considered correct, if its absolute or relative error does not exceed $$$10^{-4}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|...
null
In the first test note the initial and the final state of the wooden polygon. Red Triangle is the initial state and the green one is the triangle after rotation around $$$(2,0)$$$. In the second sample note that the polygon rotates $$$180$$$ degrees counter-clockwise or clockwise direction (it does not matter), becau...
[{"input": "3 4\n0 0\n2 0\n2 2\n1 1 2\n2 1\n2 2\n2 3", "output": "3.4142135624 -1.4142135624\n2.0000000000 0.0000000000\n0.5857864376 -1.4142135624"}, {"input": "3 2\n-1 1\n0 0\n1 1\n1 1 2\n2 1", "output": "1.0000000000 -1.0000000000"}]
2,600
["geometry"]
31
[{"input": "3 4\r\n0 0\r\n2 0\r\n2 2\r\n1 1 2\r\n2 1\r\n2 2\r\n2 3\r\n", "output": "3.4142135624 -1.4142135624\r\n2.0000000000 0.0000000000\r\n0.5857864376 -1.4142135624\r\n"}, {"input": "3 2\r\n-1 1\r\n0 0\r\n1 1\r\n1 1 2\r\n2 1\r\n", "output": "1.0000000000 -1.0000000000\r\n"}, {"input": "10 10\r\n0 -100000000\r\n1 -...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input to count type 2 queries with open(input_path, 'r') as f: n, q = map(int, f.readline().split()) for _ in range(n): f.readline() # skip vertices t...
true
803/G
803
G
Python 3
TESTS
2
46
204,800
26910715
from sys import stdin, stdout n, k = map(int, stdin.readline().split()) values = list(map(int, stdin.readline().split())) * k m = int(stdin.readline()) n *= k size = 1 while (size < n): size *= 2 tree = [float('inf') for i in range(2 * size)] for i in range(n): tree[size + i] = values[i] for i in range(s...
32
2,823
117,350,400
230770543
import sys import random input = sys.stdin.readline rd = random.randint(10 ** 9, 2 * 10 ** 9) class SegmentTree(): def __init__(self, init, unitX, f): self.f = f # (X, X) -> X self.unitX = unitX self.f = f if type(init) == int: self.n = init self.n = 1 << ...
Educational Codeforces Round 20
ICPC
2,017
4
512
Periodic RMQ Problem
You are given an array a consisting of positive integers and q queries to this array. There are two types of queries: - 1 l r x — for each index i such that l ≤ i ≤ r set ai = x. - 2 l r — find the minimum among such ai that l ≤ i ≤ r. We decided that this problem is too easy. So the array a is given in a compressed ...
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 104). The second line contains n integers — elements of the array b (1 ≤ bi ≤ 109). The third line contains one integer q (1 ≤ q ≤ 105). Then q lines follow, each representing a query. Each query is given either as 1 l r x — set all elements in the s...
For each query of type 2 print the answer to this query — the minimum on the corresponding segment.
null
null
[{"input": "3 1\n1 2 3\n3\n2 1 3\n1 1 2 4\n2 1 3", "output": "1\n3"}, {"input": "3 2\n1 2 3\n5\n2 4 4\n1 4 4 5\n2 4 4\n1 1 6 1\n2 6 6", "output": "1\n5\n1"}]
2,300
["data structures"]
32
[{"input": "3 1\r\n1 2 3\r\n3\r\n2 1 3\r\n1 1 2 4\r\n2 1 3\r\n", "output": "1\r\n3\r\n"}, {"input": "3 2\r\n1 2 3\r\n5\r\n2 4 4\r\n1 4 4 5\r\n2 4 4\r\n1 1 6 1\r\n2 6 6\r\n", "output": "1\r\n5\r\n1\r\n"}, {"input": "10 10\r\n10 8 10 9 2 2 4 6 10 1\r\n10\r\n1 17 87 5\r\n2 31 94\r\n1 5 56 8\r\n1 56 90 10\r\n1 25 93 6\r\n1...
false
stdio
null
true
265/B
265
B
Python 3
TESTS
2
124
6,963,200
127025057
n=int(input()) a=[] ans=0 for i in range(n): t=int(input()) a.append(t) ans+=a[0]+1 for i in range(1,n): if(a[i]<a[i-1]): ans+=a[i]+1 else: ans+=(a[i]-a[i-1]+1) ans+=1 print(ans)
15
248
3,072,000
106210111
from sys import stdin t = int(stdin.readline()) ans = 0 a = 1 for k in range(t): b = int(stdin.readline()) ans += abs(a-b) + 2 a = b print(ans)
Codeforces Round 162 (Div. 2)
CF
2,013
2
256
Roadside Trees (Simplified Edition)
Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following act...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of trees. Next n lines contains the height of trees: i-th line contains an integer hi (1 ≤ hi ≤ 104) — the height of the tree with the number i.
Print a single integer — the minimal time required to eat all nuts in seconds.
null
null
[{"input": "2\n1\n2", "output": "5"}, {"input": "5\n2\n1\n2\n1\n1", "output": "14"}]
1,000
["greedy", "implementation"]
15
[{"input": "2\r\n1\r\n2\r\n", "output": "5\r\n"}, {"input": "5\r\n2\r\n1\r\n2\r\n1\r\n1\r\n", "output": "14\r\n"}, {"input": "1\r\n1\r\n", "output": "2\r\n"}]
false
stdio
null
true
265/B
265
B
PyPy 3
TESTS
2
124
1,433,600
129913770
n=int(input()) l=[] for i in range(n): l.append(i) t=l[0]+2 for i in range(len(l)-1): if l[i+1]>=l[i]: t+=l[i+1]-l[i]+2 else: t+=l[i+1]+2 print(t)
15
248
7,065,600
137094837
#!/usr/bin/env pypy3 from sys import stdin, stdout def input(): return stdin.readline().strip() def read_int_list(): return list(map(int, input().split())) def read_int_tuple(): return tuple(map(int, input().split())) def read_int(): return int(input()) ### CODE HERE arr = [read_int() for _ in range(read_int())] y...
Codeforces Round 162 (Div. 2)
CF
2,013
2
256
Roadside Trees (Simplified Edition)
Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following act...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of trees. Next n lines contains the height of trees: i-th line contains an integer hi (1 ≤ hi ≤ 104) — the height of the tree with the number i.
Print a single integer — the minimal time required to eat all nuts in seconds.
null
null
[{"input": "2\n1\n2", "output": "5"}, {"input": "5\n2\n1\n2\n1\n1", "output": "14"}]
1,000
["greedy", "implementation"]
15
[{"input": "2\r\n1\r\n2\r\n", "output": "5\r\n"}, {"input": "5\r\n2\r\n1\r\n2\r\n1\r\n1\r\n", "output": "14\r\n"}, {"input": "1\r\n1\r\n", "output": "2\r\n"}]
false
stdio
null
true
265/B
265
B
Python 3
TESTS
2
124
409,600
107040910
n=int(input()) arr=[] for i in range(n): arr.append(int(input())) t1=arr[0]+1 i=0 while(i<n-1): if arr[i]>arr[i+1]: t1=t1+2 i=i+1 else: t1=t1+arr[i]+arr[i+1]+1 i=i+1 arr=arr[::-1] t2=arr[0]+1 i=0 while(i<n-1): if arr[i]>arr[i+1]: t2=t2+2 i=i+1 else: ...
15
248
9,113,600
146829397
def solve(n,arr): t=0 pos=0 for i in range(n-1) : t+= arr[i]-pos t+=1 if arr[i]<=arr[i+1] : t+=1 pos = arr[i] continue else: t+= arr[i]-arr[i+1] pos = arr[i+1] t+=1 return t+arr[-1]-pos+1 from sys import stdin input = stdin.readline l=[] n=int(input()) for i in r...
Codeforces Round 162 (Div. 2)
CF
2,013
2
256
Roadside Trees (Simplified Edition)
Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following act...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of trees. Next n lines contains the height of trees: i-th line contains an integer hi (1 ≤ hi ≤ 104) — the height of the tree with the number i.
Print a single integer — the minimal time required to eat all nuts in seconds.
null
null
[{"input": "2\n1\n2", "output": "5"}, {"input": "5\n2\n1\n2\n1\n1", "output": "14"}]
1,000
["greedy", "implementation"]
15
[{"input": "2\r\n1\r\n2\r\n", "output": "5\r\n"}, {"input": "5\r\n2\r\n1\r\n2\r\n1\r\n1\r\n", "output": "14\r\n"}, {"input": "1\r\n1\r\n", "output": "2\r\n"}]
false
stdio
null
true
1006/E
1006
E
Python 3
TESTS
2
702
154,419,200
140337141
from collections import defaultdict import threading from sys import stdin,setrecursionlimit setrecursionlimit(10**5) input=stdin.readline path=[] g=defaultdict(list) def dfs(node,g,dp): global path path.append(node) for i in g[node]: dp[node]+=dfs(i,g,dp) return dp[node]+1 def main(): glo...
31
529
70,656,000
206735860
from sys import stdin input=lambda :stdin.readline()[:-1] n,q=map(int,input().split()) p=[-1]+list(map(lambda x:int(x)-1,input().split())) edge=[[] for i in range(n)] for i in range(1,n): edge[i].append(p[i]) edge[p[i]].append(i) res=[] size=[1]*n todo=[(0,-1)] while todo: v,p=todo.pop() if v>=0: res.appe...
Codeforces Round 498 (Div. 3)
ICPC
2,018
3
256
Military Problem
In this problem you will have to help Berland army with organizing their command delivery system. There are $$$n$$$ officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has exactly one direct superior. If officer $$$a$$$ is the direct superio...
The first line of the input contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 2 \cdot 10^5, 1 \le q \le 2 \cdot 10^5$$$) — the number of officers in Berland army and the number of queries. The second line of the input contains $$$n - 1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i < i$$$), where $$$p_i$...
Print $$$q$$$ numbers, where the $$$i$$$-th number is the officer at the position $$$k_i$$$ in the list which describes the order in which officers will receive the command if it starts spreading from officer $$$u_i$$$. Print "-1" if the number of officers which receive the command is less than $$$k_i$$$. You should p...
null
null
[{"input": "9 6\n1 1 1 3 5 3 5 7\n3 1\n1 5\n3 4\n7 3\n1 8\n1 9", "output": "3\n6\n8\n-1\n9\n4"}]
1,600
["dfs and similar", "graphs", "trees"]
31
[{"input": "9 6\r\n1 1 1 3 5 3 5 7\r\n3 1\r\n1 5\r\n3 4\r\n7 3\r\n1 8\r\n1 9\r\n", "output": "3\r\n6\r\n8\r\n-1\r\n9\r\n4\r\n"}, {"input": "2 1\r\n1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "13 12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n", "out...
false
stdio
null
true
975/E
975
E
PyPy 3
TESTS
2
140
307,200
66399535
# -*- coding: utf-8 -*- """ Created on Tue Dec 3 11:47:37 2019 @author: CronuS """ def mult (m1, m2): return [[sum([m1[i][k] * m2[k][l] for k in range(3)]) for l in range(3)] for i in range(len(m1))] def getmatr (xc, yc, xi, yi, matr): xc_ = matr[0][0] * xc + matr[1][0] * yc + matr[2][0] yc_ = matr[0][1] ...
31
2,074
8,089,600
37912848
from math import hypot, atan2, cos, sin, sqrt, pi import sys mapInt = lambda:map(int,sys.stdin.buffer.readline().split()) N, Q = mapInt() # Get points from input points = {} for n in range(N) : x, y = mapInt() points[n+1] = [x,y] # Calculate COM (centroid) centroid = [0,0] A = 0 for n in range(1,N+1) : ...
Codeforces Round 478 (Div. 2)
CF
2,018
3
256
Hag's Khashba
Hag is a very talented person. He has always had an artist inside him but his father forced him to study mechanical engineering. Yesterday he spent all of his time cutting a giant piece of wood trying to make it look like a goose. Anyway, his dad found out that he was doing arts rather than studying mechanics and othe...
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$3\leq n \leq 10\,000$$$, $$$1 \leq q \leq 200000$$$) — the number of vertices in the polygon and the number of queries. The next $$$n$$$ lines describe the wooden polygon, the $$$i$$$-th line contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$|x_i|, |y_i|\leq...
The output should contain the answer to each query of second type — two numbers in a separate line. Your answer is considered correct, if its absolute or relative error does not exceed $$$10^{-4}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|...
null
In the first test note the initial and the final state of the wooden polygon. Red Triangle is the initial state and the green one is the triangle after rotation around $$$(2,0)$$$. In the second sample note that the polygon rotates $$$180$$$ degrees counter-clockwise or clockwise direction (it does not matter), becau...
[{"input": "3 4\n0 0\n2 0\n2 2\n1 1 2\n2 1\n2 2\n2 3", "output": "3.4142135624 -1.4142135624\n2.0000000000 0.0000000000\n0.5857864376 -1.4142135624"}, {"input": "3 2\n-1 1\n0 0\n1 1\n1 1 2\n2 1", "output": "1.0000000000 -1.0000000000"}]
2,600
["geometry"]
31
[{"input": "3 4\r\n0 0\r\n2 0\r\n2 2\r\n1 1 2\r\n2 1\r\n2 2\r\n2 3\r\n", "output": "3.4142135624 -1.4142135624\r\n2.0000000000 0.0000000000\r\n0.5857864376 -1.4142135624\r\n"}, {"input": "3 2\r\n-1 1\r\n0 0\r\n1 1\r\n1 1 2\r\n2 1\r\n", "output": "1.0000000000 -1.0000000000\r\n"}, {"input": "10 10\r\n0 -100000000\r\n1 -...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input to count type 2 queries with open(input_path, 'r') as f: n, q = map(int, f.readline().split()) for _ in range(n): f.readline() # skip vertices t...
true
852/E
852
E
Python 3
TESTS
3
358
512,000
66270400
n = int(input()) degree = n*[0] for i in range(0, n-1): u, v = input().split() u = int(u) v = int(v) u -= 1 v -= 1 degree[u] += 1 degree[v] += 1 numL = 0 for i in range(0, n): if degree[i] == 1: numL += 1 ans = (n-numL)*2**(n-numL) + numL*2**(n+1-numL) print(ans)
12
93
3,686,400
214753050
import sys input = sys.stdin.readline n = int(input()) mod = 10 ** 9 + 7 degs = [0] * n for _ in range(n-1): u, v = map(int, input().split()) u -= 1 v -= 1 degs[u] += 1 degs[v] += 1 leaves_count = degs.count(1) print((n + leaves_count) * pow(2, n - leaves_count, mod) % mod)
Bubble Cup X - Finals [Online Mirror]
ICPC
2,017
1
256
Casinos and travel
John has just bought a new car and is planning a journey around the country. Country has N cities, some of which are connected by bidirectional roads. There are N - 1 roads and every city is reachable from any other city. Cities are labeled from 1 to N. John first has to select from which city he will start his journe...
In the first line, a positive integer N (1 ≤ N ≤ 100000), the number of cities. In the next N - 1 lines, two numbers a, b (1 ≤ a, b ≤ N) separated by a single space meaning that cities a and b are connected by a bidirectional road.
Output one number, the answer to the problem modulo 109 + 7.
null
Example 1: If Jack selects city 1 as John's starting city, he can either build 0 casinos, so John will be happy all the time, or build a casino in both cities, so John would visit a casino in city 1, become unhappy, then go to city 2, visit a casino there and become happy and his journey ends there because he can't go ...
[{"input": "2\n1 2", "output": "4"}, {"input": "3\n1 2\n2 3", "output": "10"}]
2,100
["dp"]
12
[{"input": "2\r\n1 2\r\n", "output": "4\r\n"}, {"input": "3\r\n1 2\r\n2 3\r\n", "output": "10\r\n"}, {"input": "4\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "24\r\n"}]
false
stdio
null
true
898/C
898
C
Python 3
TESTS
2
31
0
158634578
d = {} for s in [*open(0)][1:]: s = s.split() d.setdefault(s[0],[]) for i in s[2:]:d[s[0]].append(i) for i in d: x = d[i] if len(x)>1: for j in range (len(x)): for k in range (len(x)): if x[j] == x[k]:continue a,b = x[j],x[k] a,b = ...
59
62
5,529,600
33298133
phones = dict() n = int(input()) for i in range(n): name, num, *numbers = input().split() for number in numbers: try: for el in phones[name]: if el.endswith(number): break if number.endswith(el): phones[name].remove(el)...
Codeforces Round 451 (Div. 2)
CF
2,017
2
256
Phone Numbers
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a fri...
First line contains the integer n (1 ≤ n ≤ 20) — number of entries in Vasya's phone books. The following n lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English lett...
Print out the ordered information about the phone numbers of Vasya's friends. First output m — number of friends that are found in Vasya's phone books. The following m lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each rec...
null
null
[{"input": "2\nivan 1 00123\nmasha 1 00123", "output": "2\nmasha 1 00123\nivan 1 00123"}, {"input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "output": "3\nkatya 1 612\npetr 1 12\nkarl 1 612"}, {"input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789", "output": "2\ndasha 2 23 789...
1,400
["implementation", "strings"]
59
[{"input": "2\r\nivan 1 00123\r\nmasha 1 00123\r\n", "output": "2\r\nmasha 1 00123 \r\nivan 1 00123 \r\n"}, {"input": "3\r\nkarl 2 612 12\r\npetr 1 12\r\nkatya 1 612\r\n", "output": "3\r\nkatya 1 612 \r\npetr 1 12 \r\nkarl 1 612 \r\n"}, {"input": "4\r\nivan 3 123 123 456\r\nivan 2 456 456\r\nivan 8 789 3 23 6 56 9 89 2...
false
stdio
import sys from collections import defaultdict def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input and build friends data friends = defaultdict(set) with open(input_path, 'r') as f: n = int(f.readline()) for _ in range(n): ...
true
840/B
840
B
Python 3
TESTS
2
46
0
29675269
n, m = map(int, input().split()) d = [-123] + list(map(int, input().split())) edges = [] for i in range(m): u, v = map(int, input().split()) edges.append((u, v)) def gao(): if 0 in d or -1 in d: return 0 for i, edge in enumerate(edges): u, v = edge if d[u] == d[v]: ...
73
2,979
87,756,800
167362143
import bisect import copy import decimal import fractions import heapq import itertools import math import random import sys import time from collections import Counter,deque,defaultdict from functools import lru_cache,reduce from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max def _heappush...
Codeforces Round 429 (Div. 1)
CF
2,017
3
256
Leha and another game about graph
Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or - 1. To pass the level, he needs to find a «good» subset of edges of the graph or say...
The first line contains two integers n, m (1 ≤ n ≤ 3·105, n - 1 ≤ m ≤ 3·105) — number of vertices and edges. The second line contains n integers d1, d2, ..., dn ( - 1 ≤ di ≤ 1) — numbers on the vertices. Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n) — edges. It's guaranteed, that graph in the ...
Print - 1 in a single line, if solution doesn't exist. Otherwise in the first line k — number of edges in a subset. In the next k lines indexes of edges. Edges are numerated in order as they are given in the input, starting from 1.
null
In the first sample we have single vertex without edges. It's degree is 0 and we can not get 1.
[{"input": "1 0\n1", "output": "-1"}, {"input": "4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4", "output": "0"}, {"input": "2 1\n1 1\n1 2", "output": "1\n1"}, {"input": "3 3\n0 -1 1\n1 2\n2 3\n1 3", "output": "1\n2"}]
2,100
["constructive algorithms", "data structures", "dfs and similar", "dp", "graphs"]
73
[{"input": "1 0\r\n1\r\n", "output": "-1\r\n"}, {"input": "4 5\r\n0 0 0 -1\r\n1 2\r\n2 3\r\n3 4\r\n1 4\r\n2 4\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n1 2\r\n", "output": "1\r\n1\r\n"}, {"input": "3 3\r\n0 -1 1\r\n1 2\r\n2 3\r\n1 3\r\n", "output": "1\r\n2\r\n"}, {"input": "10 10\r\n-1 -1 -1 -1 -1 -1 -1 -1 -1 ...
false
stdio
import sys def main(input_path, output_path, submission_output_path): # Read input with open(input_path, 'r') as f: n, m = map(int, f.readline().split()) d = list(map(int, f.readline().split())) edges = [tuple(map(int, f.readline().split())) for _ in range(m)] # Read submission...
true
925/B
925
B
Python 3
TESTS
0
109
102,400
47186519
# -*- coding:utf-8 -*- """ created by shuangquan.huang at 12/18/18 """ import collections import time import os import sys import bisect import heapq n, x1, x2 = map(int, input().split()) C = [int(x) for x in input().split()] C = [(v, i+1) for i, v in enumerate(C)] C.sort() def check(x1, x2, rev): r =...
40
1,341
31,846,400
197614973
def fin(c, x): return (x + c - 1) // c def ck(x, b): r = (n, n) for i in range(b, n): r = min(r, (i + fin(c[i][0], x), i)) return r def sol(r, l): if r[0] <= n and l[0] <= n and r[1] < n and l[1] < n : print("Yes") print(r[0] - r[1], l[0]- l[1]) print(' '.join([str...
VK Cup 2018 - Round 3
CF
2,018
2
256
Resource Distribution
One department of some software company has $$$n$$$ servers of different specifications. Servers are indexed with consecutive integers from $$$1$$$ to $$$n$$$. Suppose that the specifications of the $$$j$$$-th server may be expressed with a single integer number $$$c_j$$$ of artificial resource units. In order for pro...
The first line contains three integers $$$n$$$, $$$x_1$$$, $$$x_2$$$ ($$$2 \leq n \leq 300\,000$$$, $$$1 \leq x_1, x_2 \leq 10^9$$$) — the number of servers that the department may use, and resource units requirements for each of the services. The second line contains $$$n$$$ space-separated integers $$$c_1, c_2, \ldo...
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes). Otherwise print the word "Yes" (without the quotes). In the second line print two integers $$$k_1$$$ and $$$k_2$$$ ($$$1 \leq k_1, k_2 \leq n$$$) — the number of servers used for each of the services. ...
null
In the first sample test each of the servers 1, 2 and 6 will will provide $$$8 / 3 = 2.(6)$$$ resource units and each of the servers 5, 4 will provide $$$16 / 2 = 8$$$ resource units. In the second sample test the first server will provide $$$20$$$ resource units and each of the remaining servers will provide $$$32 / ...
[{"input": "6 8 16\n3 5 2 9 8 7", "output": "Yes\n3 2\n1 2 6\n5 4"}, {"input": "4 20 32\n21 11 11 12", "output": "Yes\n1 3\n1\n2 3 4"}, {"input": "4 11 32\n5 5 16 16", "output": "No"}, {"input": "5 12 20\n7 8 4 11 9", "output": "No"}]
1,700
["binary search", "implementation", "sortings"]
40
[{"input": "6 8 16\r\n3 5 2 9 8 7\r\n", "output": "Yes\r\n4 2\r\n3 1 2 6\r\n5 4\r\n"}, {"input": "4 20 32\r\n21 11 11 12\r\n", "output": "Yes\r\n1 3\r\n1\r\n2 3 4\r\n"}, {"input": "4 11 32\r\n5 5 16 16\r\n", "output": "No\r\n"}, {"input": "5 12 20\r\n7 8 4 11 9\r\n", "output": "No\r\n"}, {"input": "2 1 1\r\n1 1\r\n", "...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, x1, x2 = map(int, f.readline().split()) c = list(map(int, f.readline().split())) with open(output_path) as f: ref_lines = [line.strip() for line in f] with open(submission_path) a...
true
723/D
723
D
Python 3
TESTS
2
31
0
195520964
dr = [-1, 0, 0, 1] dc = [0, -1, 1, 0] def isValid(r, c): return r in range(n) and c in range(m) def DFS(sr, sc): is_sea = False count = 1 stack = [(sr, sc)] visited[sr][sc] = True while stack: r, c = stack.pop() for i in range(4): nr = r + dr[i] nc = c + d...
26
77
1,433,600
21180350
import sys sys.setrecursionlimit(5000) n, m, k = [int(x) for x in input().split()] land = [] cc = 0 visit = [[0 for _ in range(m)] for _ in range(n)] for i in range(n): land.append(list(input())) edge = False def DFS(i, j, c): global land, n, m, k, cc, visit, edge if i <= 0 or j <= 0 or i...
Codeforces Round 375 (Div. 2)
CF
2,016
2
256
Lakes in Berland
The map of Berland is a rectangle of the size n × m, which consists of cells of size 1 × 1. Each cell is either land or water. The map is surrounded by the ocean. Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that ...
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 50, 0 ≤ k ≤ 50) — the sizes of the map and the number of lakes which should be left on the map. The next n lines contain m characters each — the description of the map. Each of the characters is either '.' (it means that the corresponding cell ...
In the first line print the minimum number of cells which should be transformed from water to land. In the next n lines print m symbols — the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, pri...
null
In the first example there are only two lakes — the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with th...
[{"input": "5 4 1\n****\n*..*\n****\n**.*\n..**", "output": "1\n****\n*..*\n****\n****\n..**"}, {"input": "3 3 0\n***\n*.*\n***", "output": "1\n***\n***\n***"}]
1,600
["dfs and similar", "dsu", "graphs", "greedy", "implementation"]
26
[{"input": "5 4 1\r\n****\r\n*..*\r\n****\r\n**.*\r\n..**\r\n", "output": "1\r\n****\r\n*..*\r\n****\r\n****\r\n..**\r\n"}, {"input": "3 3 0\r\n***\r\n*.*\r\n***\r\n", "output": "1\r\n***\r\n***\r\n***\r\n"}, {"input": "3 5 1\r\n.**.*\r\n*.*.*\r\n***..\r\n", "output": "0\r\n.**.*\r\n*.*.*\r\n***..\r\n"}, {"input": "3 5...
false
stdio
import sys from sys import argv def main(): input_path = argv[1] output_path = argv[2] submission_path = argv[3] with open(input_path, 'r') as f: input_lines = f.read().splitlines() n, m, k = map(int, input_lines[0].split()) original_map = input_lines[1:n+1] with open(output_path,...
true
474/D
474
D
Python 3
TESTS
2
124
3,276,800
190986436
import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import gcd,log,comb,perm,factorial mod = int(1e9 + 7) inf = int(1e20) input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda...
43
171
10,240,000
198619907
import sys input = lambda: sys.stdin.readline().rstrip() MOD = 1000000007 t , k = map( int , input( ).split( ) ) f = [0] * 100005 f[0] = 1 for i in range( 1 , 100005 ) : f[i] = f[i-1] if i >= k : f[i] += f[i-k] f[i] %= MOD f[0] = 0 for i in range( 1 , 100001 ) : f[i] += f[i-1] f[i] %= MOD fo...
Codeforces Round 271 (Div. 2)
CF
2,014
1.5
256
Flowers
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red. But, for a dinner to be tasty...
Input contains several test cases. The first line contains two integers t and k (1 ≤ t, k ≤ 105), where t represents the number of test cases. The next t lines contain two integers ai and bi (1 ≤ ai ≤ bi ≤ 105), describing the i-th test.
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
null
- For K = 2 and length 1 Marmot can eat (R). - For K = 2 and length 2 Marmot can eat (RR) and (WW). - For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR). - For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
[{"input": "3 2\n1 3\n2 3\n4 4", "output": "6\n5\n5"}]
1,700
["dp"]
43
[{"input": "3 2\r\n1 3\r\n2 3\r\n4 4\r\n", "output": "6\r\n5\r\n5\r\n"}, {"input": "1 1\r\n1 3\r\n", "output": "14\r\n"}, {"input": "1 2\r\n64329 79425\r\n", "output": "0\r\n"}]
false
stdio
null
true
474/D
474
D
Python 3
TESTS
2
109
137,318,400
187213387
from collections import defaultdict, Counter, deque from math import inf from functools import lru_cache from heapq import heappop, heappush import sys #input=sys.stdin.readline Mod = 10**9 + 7 def solution(): t, k = map(int, input().split()) N = 10**5+1 dp = [0]*N for i in range(1, N): ...
43
186
10,752,000
216377371
import sys input = sys.stdin.readline M = 10**9+7 t, k = map(int, input().split()) d = [1]*k for i in range(10**5): d.append((d[-1]+d[-k])%M) q = [0] for i in range(1, 10**5+1): q.append((q[-1]+d[i])%M) for i in range(t): a, b = map(int, input().split()) print((q[b]-q[a-1])%M)
Codeforces Round 271 (Div. 2)
CF
2,014
1.5
256
Flowers
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red. But, for a dinner to be tasty...
Input contains several test cases. The first line contains two integers t and k (1 ≤ t, k ≤ 105), where t represents the number of test cases. The next t lines contain two integers ai and bi (1 ≤ ai ≤ bi ≤ 105), describing the i-th test.
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
null
- For K = 2 and length 1 Marmot can eat (R). - For K = 2 and length 2 Marmot can eat (RR) and (WW). - For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR). - For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
[{"input": "3 2\n1 3\n2 3\n4 4", "output": "6\n5\n5"}]
1,700
["dp"]
43
[{"input": "3 2\r\n1 3\r\n2 3\r\n4 4\r\n", "output": "6\r\n5\r\n5\r\n"}, {"input": "1 1\r\n1 3\r\n", "output": "14\r\n"}, {"input": "1 2\r\n64329 79425\r\n", "output": "0\r\n"}]
false
stdio
null
true
925/B
925
B
Python 3
TESTS
0
61
7,065,600
38069595
from math import ceil def merge(arr, l, m, r): n1 = m - l + 1 n2 = r- m # create temp arrays L = [0] * (n1) R = [0] * (n2) # Copy data to temp arrays L[] and R[] for i in range(0 , n1): L[i] = arr[l + i] for j in range(0 , n2): R[j] = arr[m + 1 + j] # Merge th...
40
748
42,700,800
159295631
I = lambda:list(map(int, input().split())) n,x1,x2 = I() servers = I() idx = list(range(n)) idx.sort(key = lambda i : servers[i]) def solve(a, b, rev): j = len(idx)-1 while j >= 0 and (n-j)*servers[idx[j]] < b: j -= 1 if j < 0: return i = j-1 while i >= 0 and (j-i)*servers[idx[i]] <...
VK Cup 2018 - Round 3
CF
2,018
2
256
Resource Distribution
One department of some software company has $$$n$$$ servers of different specifications. Servers are indexed with consecutive integers from $$$1$$$ to $$$n$$$. Suppose that the specifications of the $$$j$$$-th server may be expressed with a single integer number $$$c_j$$$ of artificial resource units. In order for pro...
The first line contains three integers $$$n$$$, $$$x_1$$$, $$$x_2$$$ ($$$2 \leq n \leq 300\,000$$$, $$$1 \leq x_1, x_2 \leq 10^9$$$) — the number of servers that the department may use, and resource units requirements for each of the services. The second line contains $$$n$$$ space-separated integers $$$c_1, c_2, \ldo...
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes). Otherwise print the word "Yes" (without the quotes). In the second line print two integers $$$k_1$$$ and $$$k_2$$$ ($$$1 \leq k_1, k_2 \leq n$$$) — the number of servers used for each of the services. ...
null
In the first sample test each of the servers 1, 2 and 6 will will provide $$$8 / 3 = 2.(6)$$$ resource units and each of the servers 5, 4 will provide $$$16 / 2 = 8$$$ resource units. In the second sample test the first server will provide $$$20$$$ resource units and each of the remaining servers will provide $$$32 / ...
[{"input": "6 8 16\n3 5 2 9 8 7", "output": "Yes\n3 2\n1 2 6\n5 4"}, {"input": "4 20 32\n21 11 11 12", "output": "Yes\n1 3\n1\n2 3 4"}, {"input": "4 11 32\n5 5 16 16", "output": "No"}, {"input": "5 12 20\n7 8 4 11 9", "output": "No"}]
1,700
["binary search", "implementation", "sortings"]
40
[{"input": "6 8 16\r\n3 5 2 9 8 7\r\n", "output": "Yes\r\n4 2\r\n3 1 2 6\r\n5 4\r\n"}, {"input": "4 20 32\r\n21 11 11 12\r\n", "output": "Yes\r\n1 3\r\n1\r\n2 3 4\r\n"}, {"input": "4 11 32\r\n5 5 16 16\r\n", "output": "No\r\n"}, {"input": "5 12 20\r\n7 8 4 11 9\r\n", "output": "No\r\n"}, {"input": "2 1 1\r\n1 1\r\n", "...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, x1, x2 = map(int, f.readline().split()) c = list(map(int, f.readline().split())) with open(output_path) as f: ref_lines = [line.strip() for line in f] with open(submission_path) a...
true
908/E
908
E
PyPy 3
TESTS
4
93
23,756,800
33796723
from collections import defaultdict as di MOD = int(1e9+7) bells = di(int) bells[0,0] = 1 K=60 for j in range(1,K): bells[0,j] = bells[j-1,j-1] for i in range(j): bells[i+1,j] = (bells[i,j] + bells[i,j-1])%MOD def bellman(n): return bells[n-1,n-1] m,n = [int(x) for x in input().split()] Tlist...
37
77
6,451,200
33788749
import sys #f = open('input', 'r') f = sys.stdin n,m = list(map(int, f.readline().split())) s = [f.readline().strip() for _ in range(m)] s = [list(x) for x in s] d = {} for k in zip(*s): if k in d: d[k] += 1 else: d[k] = 1 dv = d.values() got = [1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975, 678570, 421...
Good Bye 2017
CF
2,017
2
256
New Year and Entity Enumeration
You are given an integer m. Let M = 2m - 1. You are also given a set of n integers denoted as the set T. The integers will be provided in base 2 as n binary strings of length m. A set of integers S is called "good" if the following hold. 1. If $$a \in S$$, then $$a \text{ XOR } M \in S$$. 2. If $$a,b\in S$$, then $...
The first line will contain two integers m and n (1 ≤ m ≤ 1 000, 1 ≤ n ≤ min(2m, 50)). The next n lines will contain the elements of T. Each line will contain exactly m zeros and ones. Elements of T will be distinct.
Print a single integer, the number of good sets modulo 109 + 7.
null
An example of a valid set S is {00000, 00101, 00010, 00111, 11000, 11010, 11101, 11111}.
[{"input": "5 3\n11010\n00101\n11000", "output": "4"}, {"input": "30 2\n010101010101010010101010101010\n110110110110110011011011011011", "output": "860616440"}]
2,500
["bitmasks", "combinatorics", "dp", "math"]
37
[{"input": "5 3\r\n11010\r\n00101\r\n11000\r\n", "output": "4\r\n"}, {"input": "30 2\r\n010101010101010010101010101010\r\n110110110110110011011011011011\r\n", "output": "860616440\r\n"}, {"input": "30 10\r\n001000000011000111000010010000\r\n000001100001010000000000000100\r\n000110100010100000000000101000\r\n11000001000...
false
stdio
null
true
158/C
158
C
Python 3
TESTS
0
92
0
230971727
vhod = input() current_dir = '/' last_input = '' pwd_commands = [] counter = 0 for i in range(0, int(vhod)): current_input = input() if current_input == 'pwd': #print(current_dir) pwd_commands.append(current_dir) elif 'cd' in current_input: if '..' in current_input: curre...
29
124
0
18858108
class Shell: def __init__(self): self.wd = [''] def cd(self, where: str): glob = where.startswith('/') directories = where.split('/') if directories and not directories[0]: directories.pop(0) if glob: self._reset() for d in directories: ...
VK Cup 2012 Qualification Round 1
CF
2,012
3
256
Cd and pwd commands
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure...
The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Lat...
For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots.
null
null
[{"input": "7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "output": "/\n/home/vasya/\n/home/\n/home/petya/"}, {"input": "4\ncd /a/b\npwd\ncd ../a/b\npwd", "output": "/a/b/\n/a/a/b/"}]
1,400
["*special", "data structures", "implementation"]
29
[{"input": "7\r\npwd\r\ncd /home/vasya\r\npwd\r\ncd ..\r\npwd\r\ncd vasya/../petya\r\npwd\r\n", "output": "/\r\n/home/vasya/\r\n/home/\r\n/home/petya/\r\n"}, {"input": "4\r\ncd /a/b\r\npwd\r\ncd ../a/b\r\npwd\r\n", "output": "/a/b/\r\n/a/a/b/\r\n"}, {"input": "1\r\npwd\r\n", "output": "/\r\n"}, {"input": "2\r\ncd /test...
false
stdio
null
true
1006/E
1006
E
Python 3
TESTS
2
2,979
15,667,200
166707942
import sys import threading sys.setrecursionlimit(10 ** 6) n , q = list(map(int,input().split())) graph = [[] for i in range(n+1)] a = list(map(int,input().split())) a.insert(0 , 0) for i in range(2,n+1): graph[i].append(a[i-1]) graph[a[i-1]].append(i) size = [0 for i in range(n+1)] out = [] vis = [0 for i in rang...
31
608
80,281,600
225580588
import random import sys # sys.setrecursionlimit(10**8)设置最大递归次数 class FastIO: def __init__(self): self.random_seed = random.randint(0, 10 ** 9 + 7) return @staticmethod def read_int(): return int(sys.stdin.readline().strip()) @staticmethod def read_float(): retu...
Codeforces Round 498 (Div. 3)
ICPC
2,018
3
256
Military Problem
In this problem you will have to help Berland army with organizing their command delivery system. There are $$$n$$$ officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has exactly one direct superior. If officer $$$a$$$ is the direct superio...
The first line of the input contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 2 \cdot 10^5, 1 \le q \le 2 \cdot 10^5$$$) — the number of officers in Berland army and the number of queries. The second line of the input contains $$$n - 1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i < i$$$), where $$$p_i$...
Print $$$q$$$ numbers, where the $$$i$$$-th number is the officer at the position $$$k_i$$$ in the list which describes the order in which officers will receive the command if it starts spreading from officer $$$u_i$$$. Print "-1" if the number of officers which receive the command is less than $$$k_i$$$. You should p...
null
null
[{"input": "9 6\n1 1 1 3 5 3 5 7\n3 1\n1 5\n3 4\n7 3\n1 8\n1 9", "output": "3\n6\n8\n-1\n9\n4"}]
1,600
["dfs and similar", "graphs", "trees"]
31
[{"input": "9 6\r\n1 1 1 3 5 3 5 7\r\n3 1\r\n1 5\r\n3 4\r\n7 3\r\n1 8\r\n1 9\r\n", "output": "3\r\n6\r\n8\r\n-1\r\n9\r\n4\r\n"}, {"input": "2 1\r\n1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "13 12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n", "out...
false
stdio
null
true
898/C
898
C
PyPy 3
TESTS
2
93
0
120273289
n = int(input()) d = {} for i in range(n): l = list(map(str, input().split())) if l[0] not in d: d[l[0]] = list(set(l[2:])) else: d[l[0]] = list(d[l[0]] + list(set(l[2:]))) for i in d: a = d[i] ans = [] q = len(a) for j in range(q): c = 1 k = len(a[j]) ...
59
62
5,529,600
33301284
n = int(input()) D = {} for _ in range(n): name, amount, *numbers = input().split() if name in D: D[name] += numbers else: D[name] = numbers #for name, numbers in D.items(): # print(name, numbers) for name, numbers in D.items(): ns = sorted(numbers, key=len)[::-1] nn = [ns[0]]...
Codeforces Round 451 (Div. 2)
CF
2,017
2
256
Phone Numbers
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a fri...
First line contains the integer n (1 ≤ n ≤ 20) — number of entries in Vasya's phone books. The following n lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English lett...
Print out the ordered information about the phone numbers of Vasya's friends. First output m — number of friends that are found in Vasya's phone books. The following m lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each rec...
null
null
[{"input": "2\nivan 1 00123\nmasha 1 00123", "output": "2\nmasha 1 00123\nivan 1 00123"}, {"input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "output": "3\nkatya 1 612\npetr 1 12\nkarl 1 612"}, {"input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789", "output": "2\ndasha 2 23 789...
1,400
["implementation", "strings"]
59
[{"input": "2\r\nivan 1 00123\r\nmasha 1 00123\r\n", "output": "2\r\nmasha 1 00123 \r\nivan 1 00123 \r\n"}, {"input": "3\r\nkarl 2 612 12\r\npetr 1 12\r\nkatya 1 612\r\n", "output": "3\r\nkatya 1 612 \r\npetr 1 12 \r\nkarl 1 612 \r\n"}, {"input": "4\r\nivan 3 123 123 456\r\nivan 2 456 456\r\nivan 8 789 3 23 6 56 9 89 2...
false
stdio
import sys from collections import defaultdict def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input and build friends data friends = defaultdict(set) with open(input_path, 'r') as f: n = int(f.readline()) for _ in range(n): ...
true
400/A
400
A
PyPy 3
TESTS
1
92
0
216130444
t=int(input()) for i in range(t): f=input() if(f=="XXXXXXXXXXXX"): print("6 1x12 2x6 3x4 4x3 6x2 12x1") elif(f=="OOOOOOOOOOOO"): print("0") else: k=list(f) nb=0 st="" if(k[11]=="X"): st+="1x12 " nb+=1 if(k[5]=="X" and k[11]=...
44
46
0
156023101
import sys input = sys.stdin.readline for _ in range(int(input())): s = input()[:-1] d = [] l = [1,2,3,4,6,12] for j in l: k = 12//j for i in range(k): if s[i::k] == 'X' * j: d += [str(j)+'x'+str(k)] break print(len(d), ' '.join(d))
Codeforces Round 234 (Div. 2)
CF
2,014
1
256
Inna and Choose Options
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below: There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"...
The first line of the input contains integer t (1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line. The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th chara...
For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespac...
null
null
[{"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO", "output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"}]
1,000
["implementation"]
44
[{"input": "4\r\nOXXXOXOOXOOX\r\nOXOXOXOXOXOX\r\nXXXXXXXXXXXX\r\nOOOOOOOOOOOO\r\n", "output": "3 1x12 2x6 4x3\r\n4 1x12 2x6 3x4 6x2\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n0\r\n"}, {"input": "2\r\nOOOOOOOOOOOO\r\nXXXXXXXXXXXX\r\n", "output": "0\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n"}, {"input": "13\r\nXXXXXXXXXXXX\r\nXXXXXXXXXX...
false
stdio
null
true
400/A
400
A
Python 3
TESTS
1
109
0
61170847
le=int(input()) for _ in range(le): str1=input() count=0 arr=[12,6,4,3,2,1] arr1=[] for num in arr: j=0 flag=True while(j<12): j+=num if(str1[j-1]!="X"): flag=False break if(flag): count+=1 ...
44
46
0
179040613
#!/usr/bin/env/python # -*- coding: utf-8 -*- tests = int(input()) for _ in range(tests): m = input() res = [] for i in [1, 2, 3, 4, 6, 12]: j = 12 // i flag = False for kk in range(j): stmp = '' if flag: break for k in range(i): ...
Codeforces Round 234 (Div. 2)
CF
2,014
1
256
Inna and Choose Options
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below: There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"...
The first line of the input contains integer t (1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line. The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th chara...
For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespac...
null
null
[{"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO", "output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"}]
1,000
["implementation"]
44
[{"input": "4\r\nOXXXOXOOXOOX\r\nOXOXOXOXOXOX\r\nXXXXXXXXXXXX\r\nOOOOOOOOOOOO\r\n", "output": "3 1x12 2x6 4x3\r\n4 1x12 2x6 3x4 6x2\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n0\r\n"}, {"input": "2\r\nOOOOOOOOOOOO\r\nXXXXXXXXXXXX\r\n", "output": "0\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n"}, {"input": "13\r\nXXXXXXXXXXXX\r\nXXXXXXXXXX...
false
stdio
null
true
898/C
898
C
PyPy 3-64
TESTS
2
46
512,000
153721776
n = int(input()) records = {} for i in range(n): record = input().split() records[record[0]] = list(set(record[2:])) res = {k: [] for k in records} for k in records: for number in records[k]: isGood = True for p in records[k]: isGood &= not (p.endswith(number) and p != number) ...
59
62
5,529,600
33302491
k = int(input()) d = dict() for _ in range(k): name, *nums = input().split() nums = set(nums[1:]) if name in d: d[name] = d[name].union(nums) else: d[name] = nums print(len(d)) for name in d: arr = sorted(list(map(lambda x: x[::-1], d[name]))) i = 0 while i < len(arr...
Codeforces Round 451 (Div. 2)
CF
2,017
2
256
Phone Numbers
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a fri...
First line contains the integer n (1 ≤ n ≤ 20) — number of entries in Vasya's phone books. The following n lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English lett...
Print out the ordered information about the phone numbers of Vasya's friends. First output m — number of friends that are found in Vasya's phone books. The following m lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each rec...
null
null
[{"input": "2\nivan 1 00123\nmasha 1 00123", "output": "2\nmasha 1 00123\nivan 1 00123"}, {"input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "output": "3\nkatya 1 612\npetr 1 12\nkarl 1 612"}, {"input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789", "output": "2\ndasha 2 23 789...
1,400
["implementation", "strings"]
59
[{"input": "2\r\nivan 1 00123\r\nmasha 1 00123\r\n", "output": "2\r\nmasha 1 00123 \r\nivan 1 00123 \r\n"}, {"input": "3\r\nkarl 2 612 12\r\npetr 1 12\r\nkatya 1 612\r\n", "output": "3\r\nkatya 1 612 \r\npetr 1 12 \r\nkarl 1 612 \r\n"}, {"input": "4\r\nivan 3 123 123 456\r\nivan 2 456 456\r\nivan 8 789 3 23 6 56 9 89 2...
false
stdio
import sys from collections import defaultdict def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input and build friends data friends = defaultdict(set) with open(input_path, 'r') as f: n = int(f.readline()) for _ in range(n): ...
true
852/E
852
E
PyPy 3
TESTS
3
904
6,553,600
30146944
n=int(input()) a=[0]*n for i in range(n-1): for j in input().split(): a[int(j)-1]+=1 l=a.count(1) print(l*2**(n-l+1)+(n-l)*2**(n-l))
12
264
102,400
203394745
n=int(input()) a = [0]*(n+1) for i in range(n-1): for i in input().split(): a[int(i)]+=1 l = a.count(1) print ((l*2**(n-l+1)+(n-l)*(2**(n-l)))%(10**9+7))
Bubble Cup X - Finals [Online Mirror]
ICPC
2,017
1
256
Casinos and travel
John has just bought a new car and is planning a journey around the country. Country has N cities, some of which are connected by bidirectional roads. There are N - 1 roads and every city is reachable from any other city. Cities are labeled from 1 to N. John first has to select from which city he will start his journe...
In the first line, a positive integer N (1 ≤ N ≤ 100000), the number of cities. In the next N - 1 lines, two numbers a, b (1 ≤ a, b ≤ N) separated by a single space meaning that cities a and b are connected by a bidirectional road.
Output one number, the answer to the problem modulo 109 + 7.
null
Example 1: If Jack selects city 1 as John's starting city, he can either build 0 casinos, so John will be happy all the time, or build a casino in both cities, so John would visit a casino in city 1, become unhappy, then go to city 2, visit a casino there and become happy and his journey ends there because he can't go ...
[{"input": "2\n1 2", "output": "4"}, {"input": "3\n1 2\n2 3", "output": "10"}]
2,100
["dp"]
12
[{"input": "2\r\n1 2\r\n", "output": "4\r\n"}, {"input": "3\r\n1 2\r\n2 3\r\n", "output": "10\r\n"}, {"input": "4\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "24\r\n"}]
false
stdio
null
true
21/D
21
D
PyPy 3
TESTS
0
122
0
152774562
from heapq import heappop,heappush n,m=map(int,input().split()) E=[[] for i in range(n)] for i in range(m): x,y,c=map(int,input().split()) x-=1 y-=1 E[x].append((y,c)) E[y].append((x,c)) DP=[[1<<30]*(1<<n) for i in range(n)] DP[0][1<<0]=0 Q=[] Q.append((0,0,1<<0)) while Q: dis,fr,passed=heapp...
60
280
5,017,600
153611194
from itertools import repeat inf = 10000000000 ans = inf mat = 0 def solve(odd, graph_matrix): global ans global mat if (len(odd) == 0): ans = min(ans, mat) return e = odd.pop() i = 0 while i<len(odd): cur = odd.pop(i) mat+=graph_matrix[cur][e] solve(odd, ...
Codeforces Alpha Round 21 (Codeforces format)
CF
2,010
0.5
64
Traveling Graph
You are given undirected weighted graph. Find the length of the shortest cycle which starts from the vertex 1 and passes throught all the edges at least once. Graph may contain multiply edges between a pair of vertices and loops (edges from the vertex to itself).
The first line of the input contains two integers n and m (1 ≤ n ≤ 15, 0 ≤ m ≤ 2000), n is the amount of vertices, and m is the amount of edges. Following m lines contain edges as a triples x, y, w (1 ≤ x, y ≤ n, 1 ≤ w ≤ 10000), x, y are edge endpoints, and w is the edge length.
Output minimal cycle length or -1 if it doesn't exists.
null
null
[{"input": "3 3\n1 2 1\n2 3 1\n3 1 1", "output": "3"}, {"input": "3 2\n1 2 3\n2 3 4", "output": "14"}]
2,400
["bitmasks", "graph matchings", "graphs"]
60
[{"input": "4 6\r\n1 2 10\r\n2 3 1000\r\n3 4 10\r\n4 1 1000\r\n4 2 5000\r\n1 3 2\r\n", "output": "7042\r\n"}, {"input": "2 9\r\n1 2 9\r\n1 2 9\r\n2 1 9\r\n1 2 8\r\n2 1 9\r\n1 2 9\r\n1 2 9\r\n1 2 11\r\n1 2 9\r\n", "output": "90\r\n"}, {"input": "2 10\r\n1 2 9\r\n1 2 9\r\n2 1 9\r\n1 2 8\r\n2 1 9\r\n1 2 9\r\n1 2 9\r\n1 2 ...
false
stdio
null
true
383/C
383
C
Python 3
TESTS
5
623
127,692,800
119294347
from collections import defaultdict import threading def dfs(node,parent,g,sons): for e in g[node]: if e==parent: continue else: sons[node].append(e) dfs(e,node,g,sons) return def prop(parent,val,sons,par,ar): if par==0: ar[parent]+=val else: ar[parent]+=-(val) par^=1 for i in sons[parent]: p...
54
1,107
130,252,800
192697070
class BIT(): """区間加算、一点取得クエリをそれぞれO(logN)で応えるデータ構造を構築する add: 区間[begin, end)にvalを加える get_val: i番目(0-indexed)の値を求める """ def __init__(self, n): self.n = n self.bit = [0] * (n + 1) def get_val(self, i): i = i + 1 s = 0 while i <= self.n: s += self....
Codeforces Round 225 (Div. 1)
CF
2,014
2
256
Propagating tree
Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numbered from 1 to n, each node i having an initial value ai. The root of the tree is node 1. This tree has a special property: when a value val is added to a value of node i, the value -val is ...
The first line contains two integers n and m (1 ≤ n, m ≤ 200000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000). Each of the next n–1 lines contains two integers vi and ui (1 ≤ vi, ui ≤ n), meaning that there is an edge between nodes vi and ui. Each of the next m lines contains a query in the for...
For each query of type two (print the value of node x) you must print the answer to the query on a separate line. The queries must be answered in the order given in the input.
null
The values of the nodes are [1, 2, 1, 1, 2] at the beginning. Then value 3 is added to node 2. It propagates and value -3 is added to it's sons, node 4 and node 5. Then it cannot propagate any more. So the values of the nodes are [1, 5, 1, - 2, - 1]. Then value 2 is added to node 1. It propagates and value -2 is ad...
[{"input": "5 5\n1 2 1 1 2\n1 2\n1 3\n2 4\n2 5\n1 2 3\n1 1 2\n2 1\n2 2\n2 4", "output": "3\n3\n0"}]
2,000
["data structures", "dfs and similar", "trees"]
54
[{"input": "5 5\r\n1 2 1 1 2\r\n1 2\r\n1 3\r\n2 4\r\n2 5\r\n1 2 3\r\n1 1 2\r\n2 1\r\n2 2\r\n2 4\r\n", "output": "3\r\n3\r\n0\r\n"}, {"input": "10 10\r\n137 197 856 768 825 894 86 174 218 326\r\n7 8\r\n4 7\r\n8 9\r\n7 10\r\n1 2\r\n2 4\r\n3 6\r\n3 5\r\n2 3\r\n1 9 624\r\n2 1\r\n2 4\r\n1 6 505\r\n1 8 467\r\n1 3 643\r\n2 1\...
false
stdio
null
true
474/D
474
D
PyPy 3-64
TESTS
2
78
7,884,800
188602238
import sys import math import heapq as hp #hp.heapify hp.heappush hp.heappop from collections import deque #appendleft append pop popleft input=sys.stdin.readline m=1000000007 def inp(): return int(input()) def minp(): return map(int,input().split()) def strinp(): S=input().rstrip() return S def lst()...
43
186
18,944,000
211154609
import sys input=sys.stdin.readline from itertools import permutations, accumulate from collections import defaultdict as dd from collections import deque from bisect import bisect_left,bisect_right from math import lcm,gcd,sqrt,ceil,comb from heapq import heappop,heappush,heapify toBin=lambda x:bin(x).replace("0b","")...
Codeforces Round 271 (Div. 2)
CF
2,014
1.5
256
Flowers
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red. But, for a dinner to be tasty...
Input contains several test cases. The first line contains two integers t and k (1 ≤ t, k ≤ 105), where t represents the number of test cases. The next t lines contain two integers ai and bi (1 ≤ ai ≤ bi ≤ 105), describing the i-th test.
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
null
- For K = 2 and length 1 Marmot can eat (R). - For K = 2 and length 2 Marmot can eat (RR) and (WW). - For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR). - For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
[{"input": "3 2\n1 3\n2 3\n4 4", "output": "6\n5\n5"}]
1,700
["dp"]
43
[{"input": "3 2\r\n1 3\r\n2 3\r\n4 4\r\n", "output": "6\r\n5\r\n5\r\n"}, {"input": "1 1\r\n1 3\r\n", "output": "14\r\n"}, {"input": "1 2\r\n64329 79425\r\n", "output": "0\r\n"}]
false
stdio
null
true
995/D
995
D
Python 3
TESTS
3
951
32,153,600
39730476
from sys import stdin from math import fsum def main(): n, m = map(int, input().split()) ff = list(map(float, input().split())) scale, r = .5 ** n, fsum(ff) res = [r * scale] for i, f in map(str.split, stdin.read().splitlines()): r += float(f) - ff[int(i)] res.append(r * scale) ...
53
1,154
32,051,200
39730546
from sys import stdin from math import fsum def main(): n, m = map(int, input().split()) ff = list(map(float, input().split())) scale, r = .5 ** n, fsum(ff) res = [r * scale] for si, sf in map(str.split, stdin.read().splitlines()): i, f = int(si), float(sf) r += f - ff[i] f...
Codeforces Round 492 (Div. 1) [Thanks, uDebug!]
CF
2,018
3
256
Game
Allen and Bessie are playing a simple number game. They both know a function $$$f: \{0, 1\}^n \to \mathbb{R}$$$, i. e. the function takes $$$n$$$ binary arguments and returns a real value. At the start of the game, the variables $$$x_1, x_2, \dots, x_n$$$ are all set to $$$-1$$$. Each round, with equal probability, one...
The first line contains two integers $$$n$$$ and $$$r$$$ ($$$1 \le n \le 18$$$, $$$0 \le r \le 2^{18}$$$). The next line contains $$$2^n$$$ integers $$$c_0, c_1, \dots, c_{2^n-1}$$$ ($$$0 \le c_i \le 10^9$$$), denoting the initial values of $$$f$$$. More specifically, $$$f(x_0, x_1, \dots, x_{n-1}) = c_x$$$, if $$$x =...
Print $$$r+1$$$ lines, the $$$i$$$-th of which denotes the value of the game $$$f$$$ during the $$$i$$$-th round. Your answer must have absolute or relative error within $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|a - b|}{\max{(1...
null
Consider the second test case. If Allen goes first, he will set $$$x_1 \to 1$$$, so the final value will be $$$3$$$. If Bessie goes first, then she will set $$$x_1 \to 0$$$ so the final value will be $$$2$$$. Thus the answer is $$$2.5$$$. In the third test case, the game value will always be $$$1$$$ regardless of Alle...
[{"input": "2 2\n0 1 2 3\n2 5\n0 4", "output": "1.500000\n2.250000\n3.250000"}, {"input": "1 0\n2 3", "output": "2.500000"}, {"input": "2 0\n1 1 1 1", "output": "1.000000"}]
2,500
["math"]
53
[{"input": "2 2\r\n0 1 2 3\r\n2 5\r\n0 4\r\n", "output": "1.500000\r\n2.250000\r\n3.250000\r\n"}, {"input": "1 0\r\n2 3\r\n", "output": "2.500000\r\n"}, {"input": "2 0\r\n1 1 1 1\r\n", "output": "1.000000\r\n"}]
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n, r = map(int, f.readline().split()) expected_lines = r + 1 with open(output_path) as f: correct = [float(line.strip()) for line in f] if le...
true
32/A
32
A
Python 3
TESTS
2
62
0
185880775
n,d=map(int,input().split()) ls=list(map(int,input().split())) ls.sort() cntr=0 for x in range(n): if abs(ls[x]-ls[x-1])<=d: cntr+=1 print(2*cntr)
32
122
2,355,200
151388817
from sys import stdin input = stdin.readline nums, diff = map(int,input().split()) heights = list(map(int,input().split())) heights.sort() matched = 0 for i,shorter in enumerate(heights): for higher in heights[i+1:]: if higher - shorter > diff: break matched += 1 print(matched*2)
Codeforces Beta Round 32 (Div. 2, Codeforces format)
CF
2,010
2
256
Reconnaissance
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are ...
The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
null
null
[{"input": "5 10\n10 20 50 60 65", "output": "6"}, {"input": "5 1\n55 30 29 31 55", "output": "6"}]
800
["brute force"]
32
[{"input": "5 10\r\n10 20 50 60 65\r\n", "output": "6\r\n"}, {"input": "5 1\r\n55 30 29 31 55\r\n", "output": "6\r\n"}, {"input": "6 10\r\n4 6 4 1 9 3\r\n", "output": "30\r\n"}, {"input": "7 100\r\n19 1694 261 162 1 234 513\r\n", "output": "8\r\n"}, {"input": "8 42\r\n37 53 74 187 568 22 5 65\r\n", "output": "20\r\n"},...
false
stdio
null
true
756/F
756
F
Python 3
TESTS
0
31
0
203818251
MOD = int(1e9) + 7 def eval_expression(p): w = 0 result = 0 while w < len(p): if p[w].isdigit(): num = int(p[w]) w += 1 while w < len(p) and p[w].isdigit(): ...
41
842
145,920,000
164916281
# a ^ (P-1) ≡ 1 (mod P) # a ^ k ≡ (a % P) ^ (k % (P-1)) (mod P) import sys sys.setrecursionlimit(10**5) MOD = 10**9 + 7 def inv(x): return pow(x, MOD - 2, MOD) class Number: def __init__(self, value, length): self.value = value % MOD self.length = length % (MOD - 1) ...
8VC Venture Cup 2017 - Final Round
CF
2,017
2
512
Long number
Consider the following grammar: - <expression> ::= <term> | <expression> '+' <term> - <term> ::= <number> | <number> '-' <number> | <number> '(' <expression> ')' - <number> ::= <pos_digit> | <number> <digit> - <digit> ::= '0' | <pos_digit> - <pos_digit> ::= '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' This gra...
The only line contains a non-empty string at most 105 characters long which is valid according to the given grammar. In particular, it means that in terms l-r l ≤ r holds.
Print single integer — the number described by the expression modulo 109 + 7.
null
null
[{"input": "8-11", "output": "891011"}, {"input": "2(2-4+1)+2(2(17))", "output": "100783079"}, {"input": "1234-5678", "output": "745428774"}, {"input": "1+2+3+4-5+6+7-9", "output": "123456789"}]
3,400
["expression parsing", "math", "number theory"]
41
[{"input": "8-11\r\n", "output": "891011\r\n"}, {"input": "2(2-4+1)+2(2(17))\r\n", "output": "100783079\r\n"}, {"input": "1234-5678\r\n", "output": "745428774\r\n"}, {"input": "1+2+3+4-5+6+7-9\r\n", "output": "123456789\r\n"}, {"input": "598777\r\n", "output": "598777\r\n"}, {"input": "49603501749575096738857\r\n", "ou...
false
stdio
null
true
69/C
69
C
PyPy 3
TESTS
2
248
0
81754120
import sys inp = sys.stdin.readlines() all_lines = [] first_line = inp[0].split(' ') allies = int(first_line[0]) basic = int(first_line[1]) composite= int(first_line[2]) friend_purchases = int(first_line[3]) friend = {} for count in range(allies+1)[1:]: friend[count] = [] for owned in inp[basic+1+composite:bas...
47
374
2,969,600
95919675
import sys from array import array # noqa: F401 from collections import defaultdict def input(): return sys.stdin.buffer.readline().decode('utf-8') k, n, m, q = map(int, input().split()) basic = [input().rstrip() for _ in range(n)] composite = defaultdict(list) for _ in range(m): name, desc = input().split...
Codeforces Beta Round 63 (Div. 2)
CF
2,011
2
256
Game
In one school with Vasya there is a student Kostya. Kostya does not like physics, he likes different online games. Every day, having come home, Kostya throws his bag in the farthest corner and sits down at his beloved computer. Kostya even eats glued to the game. A few days ago Kostya bought a new RPG game "HaresButtle...
The first line has 4 natural numbers: k (1 ≤ k ≤ 100) — the number of Kostya's allies, n (1 ≤ n ≤ 50) — the number of basic artifacts, m (0 ≤ m ≤ 50) — the number of composite artifacts, q (1 ≤ q ≤ 500) — the number of his friends' purchases. The following n lines contain the names of basic artifacts. After them m line...
The output file should consist of k blocks. The first line should contain number bi — the number of different artifacts the i-th ally has. Then the block should contain bi lines with the names of these artifacts and the number of these artifacts. At that the lines should be printed in accordance with the lexicographica...
null
null
[{"input": "2 3 2 5\ndesolator\nrefresher\nperseverance\nvanguard: desolator 1, refresher 1\nmaelstorm: perseverance 2\n1 desolator\n2 perseverance\n1 refresher\n2 desolator\n2 perseverance", "output": "1\nvanguard 1\n2\ndesolator 1\nmaelstorm 1"}]
2,000
["implementation"]
47
[{"input": "2 3 2 5\r\ndesolator\r\nrefresher\r\nperseverance\r\nvanguard: desolator 1, refresher 1\r\nmaelstorm: perseverance 2\r\n1 desolator\r\n2 perseverance\r\n1 refresher\r\n2 desolator\r\n2 perseverance\r\n", "output": "1\r\nvanguard 1\r\n2\r\ndesolator 1\r\nmaelstorm 1\r\n"}, {"input": "2 3 2 5\r\na\r\nb\r\nc\r...
false
stdio
null
true
393/B
393
B
PyPy 3
TESTS
0
124
0
93462429
n=int(input()) w=[list(map(int,input().split()))for i in range(n)] a=[[0for i in range(n)]for i in range(n)] b=[[0for i in range(n)]for i in range(n)] for i in range(n): for j in range(n): if i==j: a[i][j]=w[i][j] else: a[i][j]=w[i][j]//2 b[i][j]=w[i][j]-a[i][j] f...
40
155
9,113,600
127862133
n=int(input()) lis=[] for x in range(n): lis.append(list(map(int,input().split()))) A=[] B=[] for x in range(n): A.append([ (lis[x][i]+lis[i][x])/2 for i in range(n) ]) B.append([lis[x][i]-A[x][i] for i in range(n)]) for x in A: for y in x: print(y,end=' ') print() for x in B: for y in...
Codeforces Round 230 (Div. 2)
CF
2,014
1
256
Three matrices
Chubby Yang is studying linear equations right now. He came up with a nice problem. In the problem you are given an n × n matrix W, consisting of integers, and you should find two n × n matrices A and B, all the following conditions must hold: - Aij = Aji, for all i, j (1 ≤ i, j ≤ n); - Bij =  - Bji, for all i, j (1 ≤...
The first line contains an integer n (1 ≤ n ≤ 170). Each of the following n lines contains n integers. The j-th integer in the i-th line is Wij (0 ≤ |Wij| < 1717).
The first n lines must contain matrix A. The next n lines must contain matrix B. Print the matrices in the format equal to format of matrix W in input. It is guaranteed that the answer exists. If there are multiple answers, you are allowed to print any of them. The answer will be considered correct if the absolute or ...
null
null
[{"input": "2\n1 4\n3 2", "output": "1.00000000 3.50000000\n3.50000000 2.00000000\n0.00000000 0.50000000\n-0.50000000 0.00000000"}, {"input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "1.00000000 3.00000000 5.00000000\n3.00000000 5.00000000 7.00000000\n5.00000000 7.00000000 9.00000000\n0.00000000 -1.00000000 -2.00000000\n1.0...
null
[]
40
[{"input": "2\r\n1 4\r\n3 2\r\n", "output": "1.00000000 3.50000000\r\n3.50000000 2.00000000\r\n0.00000000 0.50000000\r\n-0.50000000 0.00000000\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "1.00000000 3.00000000 5.00000000\r\n3.00000000 5.00000000 7.00000000\r\n5.00000000 7.00000000 9.00000000\r\n0.000...
false
stdio
import sys def is_close(a, b): abs_tol = 1e-4 rel_tol = 1e-4 diff = abs(a - b) if diff <= abs_tol: return True max_val = max(abs(a), abs(b)) return diff <= rel_tol * max_val def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.read().spl...
true
393/B
393
B
Python 3
TESTS
0
93
0
61959882
n = int(input()) mat = [] for k in range(0, n): mat.append(list(map(int, input().rstrip().split()))) A = mat B = [[0] * n for _ in range(n)] for i in range(1, n): for j in range(0, i): a = (mat[i][j] + mat[j][i]) / 2 b = mat[j][i] - a A[i][j] = a B[i][j] = b ...
40
171
1,945,600
114797070
R = lambda: list(map(int, input().split())) n = int(input()) w = [R() for _ in ' '*n] wd = [[0]*n for _ in ' '*n] for i in range(n): for j in range(n): wd[i][j] = w[j][i] a = [[0]*n for _ in ' '*n] b = [[0]*n for _ in ' '*n] for i in range(n): for j in range(n): a[i][j] = (w[i][j] + ...
Codeforces Round 230 (Div. 2)
CF
2,014
1
256
Three matrices
Chubby Yang is studying linear equations right now. He came up with a nice problem. In the problem you are given an n × n matrix W, consisting of integers, and you should find two n × n matrices A and B, all the following conditions must hold: - Aij = Aji, for all i, j (1 ≤ i, j ≤ n); - Bij =  - Bji, for all i, j (1 ≤...
The first line contains an integer n (1 ≤ n ≤ 170). Each of the following n lines contains n integers. The j-th integer in the i-th line is Wij (0 ≤ |Wij| < 1717).
The first n lines must contain matrix A. The next n lines must contain matrix B. Print the matrices in the format equal to format of matrix W in input. It is guaranteed that the answer exists. If there are multiple answers, you are allowed to print any of them. The answer will be considered correct if the absolute or ...
null
null
[{"input": "2\n1 4\n3 2", "output": "1.00000000 3.50000000\n3.50000000 2.00000000\n0.00000000 0.50000000\n-0.50000000 0.00000000"}, {"input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "1.00000000 3.00000000 5.00000000\n3.00000000 5.00000000 7.00000000\n5.00000000 7.00000000 9.00000000\n0.00000000 -1.00000000 -2.00000000\n1.0...
null
[]
40
[{"input": "2\r\n1 4\r\n3 2\r\n", "output": "1.00000000 3.50000000\r\n3.50000000 2.00000000\r\n0.00000000 0.50000000\r\n-0.50000000 0.00000000\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "1.00000000 3.00000000 5.00000000\r\n3.00000000 5.00000000 7.00000000\r\n5.00000000 7.00000000 9.00000000\r\n0.000...
false
stdio
import sys def is_close(a, b): abs_tol = 1e-4 rel_tol = 1e-4 diff = abs(a - b) if diff <= abs_tol: return True max_val = max(abs(a), abs(b)) return diff <= rel_tol * max_val def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.read().spl...
true
393/B
393
B
Python 3
TESTS
0
77
307,200
69578715
# Design_by_JOKER import math import cmath n = int(input()) w = [] a = [] b = [] for _ in range(n): w.append(list(map(int, input().split()))) a.append([0.0]*n) b.append([0.0]*n) for x in range(n): a[x][x] = 1.0*w[x][x] for y in range(x): a[x][y] = a[y][x] = (w[x][y] + w[y][x])/2 b[...
40
171
8,806,400
130600943
# import numpy as np n = int(input()) arr = [] for i in range(n): arr1 = [int(x) for x in input().split()] arr.append(arr1) dasharr = [[None for j in range(n)] for i in range(n)] for i in range(n): for j in range(n): dasharr[i][j] = arr[j][i] a = [[None for i in range(n)] for i in range(n)] b = [[No...
Codeforces Round 230 (Div. 2)
CF
2,014
1
256
Three matrices
Chubby Yang is studying linear equations right now. He came up with a nice problem. In the problem you are given an n × n matrix W, consisting of integers, and you should find two n × n matrices A and B, all the following conditions must hold: - Aij = Aji, for all i, j (1 ≤ i, j ≤ n); - Bij =  - Bji, for all i, j (1 ≤...
The first line contains an integer n (1 ≤ n ≤ 170). Each of the following n lines contains n integers. The j-th integer in the i-th line is Wij (0 ≤ |Wij| < 1717).
The first n lines must contain matrix A. The next n lines must contain matrix B. Print the matrices in the format equal to format of matrix W in input. It is guaranteed that the answer exists. If there are multiple answers, you are allowed to print any of them. The answer will be considered correct if the absolute or ...
null
null
[{"input": "2\n1 4\n3 2", "output": "1.00000000 3.50000000\n3.50000000 2.00000000\n0.00000000 0.50000000\n-0.50000000 0.00000000"}, {"input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "1.00000000 3.00000000 5.00000000\n3.00000000 5.00000000 7.00000000\n5.00000000 7.00000000 9.00000000\n0.00000000 -1.00000000 -2.00000000\n1.0...
null
[]
40
[{"input": "2\r\n1 4\r\n3 2\r\n", "output": "1.00000000 3.50000000\r\n3.50000000 2.00000000\r\n0.00000000 0.50000000\r\n-0.50000000 0.00000000\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "1.00000000 3.00000000 5.00000000\r\n3.00000000 5.00000000 7.00000000\r\n5.00000000 7.00000000 9.00000000\r\n0.000...
false
stdio
import sys def is_close(a, b): abs_tol = 1e-4 rel_tol = 1e-4 diff = abs(a - b) if diff <= abs_tol: return True max_val = max(abs(a), abs(b)) return diff <= rel_tol * max_val def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.read().spl...
true
886/F
886
F
Python 3
PRETESTS
2
61
0
32267865
n=int(input()) a=[] ma=0 for i in range(n): s=input() z=s.split() k1=int(z[0])-1 k2=int(z[1])-1 ma=max(k1,k2,ma) a.append(s) b=[[0]*(ma+1) for i in range(ma+1)] for i in a: z=i.split() k1=int(z[0])-1 k2=int(z[1])-1 b[k1][k2]=1 a=[] k=0 fl=True for i in range(ma+1): if b[i][i]...
51
794
19,046,400
211944348
from fractions import Fraction import time class Point: def __init__(self, x, y): self.x = x self.y = y def to_tuple(self): return (self.x, self.y) def __repr__(self): return "Point({}, {})".format(self.x, self.y) def __eq__(self, other): return self.to_tuple...
Технокубок 2018 - Отборочный Раунд 3
CF
2,017
2
256
Symmetric Projections
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines. Multiset is a set where equal elements are allowed. Multiset is called symmetric, if there is a point P on t...
The first line contains a single integer n (1 ≤ n ≤ 2000) — the number of points in the set. Each of the next n lines contains two integers xi and yi ( - 106 ≤ xi, yi ≤ 106) — the coordinates of the points. It is guaranteed that no two points coincide.
If there are infinitely many good lines, print -1. Otherwise, print single integer — the number of good lines.
null
Picture to the first sample test: In the second sample, any line containing the origin is good.
[{"input": "3\n1 2\n2 1\n3 3", "output": "3"}, {"input": "2\n4 3\n1 2", "output": "-1"}]
2,900
["geometry"]
51
[{"input": "3\r\n1 2\r\n2 1\r\n3 3\r\n", "output": "3\r\n"}, {"input": "2\r\n4 3\r\n1 2\r\n", "output": "-1\r\n"}, {"input": "6\r\n0 4\r\n1 5\r\n2 1\r\n3 2\r\n4 3\r\n5 0\r\n", "output": "5\r\n"}, {"input": "1\r\n5 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 4\r\n1 2\r\n0 0\r\n-2 -4\r\n", "output": "1\r\n"}, {"input"...
false
stdio
null
true
400/A
400
A
Python 3
TESTS
1
46
0
18541074
from sys import stdin, stdout n = int(stdin.readline()) a = [1,2,3,4,6,12] for i in range(n): s = stdin.readline() ans = list() for x in a: p = 12//x flag = True for j in range(p,13,p): if s[j-1] != 'X': flag = False if flag: ans.appen...
44
46
0
193117487
import math loops = int(input()) for x in range(loops): line = input() line = line.lower() out = "" sum = 0 for i in range(12): if line[i] == "x": out = out + "1x12 " sum+=1 break for i in range(6): if line[i] == "x" and line[i + 6] == "x": ...
Codeforces Round 234 (Div. 2)
CF
2,014
1
256
Inna and Choose Options
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below: There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"...
The first line of the input contains integer t (1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line. The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th chara...
For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespac...
null
null
[{"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO", "output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"}]
1,000
["implementation"]
44
[{"input": "4\r\nOXXXOXOOXOOX\r\nOXOXOXOXOXOX\r\nXXXXXXXXXXXX\r\nOOOOOOOOOOOO\r\n", "output": "3 1x12 2x6 4x3\r\n4 1x12 2x6 3x4 6x2\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n0\r\n"}, {"input": "2\r\nOOOOOOOOOOOO\r\nXXXXXXXXXXXX\r\n", "output": "0\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n"}, {"input": "13\r\nXXXXXXXXXXXX\r\nXXXXXXXXXX...
false
stdio
null
true
194/B
194
B
PyPy 3
TESTS
3
93
3,891,200
150667371
t=int(input()) arr=[int(i) for i in input().split()] for i in range(t): if(arr[i]%4==0): arr[i]=(4*arr[i])+1 elif(arr[i]%4==1): arr[i]=(2*arr[i])+1 elif(arr[i]%4==2): arr[i]=(4*arr[i]) elif(arr[i]%4==3): arr[i]=arr[i]+1 for i in range(t): ...
8
46
614,400
147587674
n = int(input()) a=[] b = input() b = b.split() for i in range(len(b)): a.append(int(b[i])) for i in range(n): if a[i]%4 == 1 : print(1 + a[i]*2) elif a[i]%2 == 0 : print(1+a[i]*4) else: print(int(4*((a[i]+1)/4)))
Codeforces Round 122 (Div. 2)
CF
2,012
2
256
Square
There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downward...
The first line contains integer t (1 ≤ t ≤ 104) — the number of test cases. The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample.
For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input. Please do not use the %lld specifier to read or write 64-bit...
null
null
[{"input": "3\n4 8 100", "output": "17\n33\n401"}]
1,200
["math"]
8
[{"input": "3\r\n4 8 100\r\n", "output": "17\r\n33\r\n401\r\n"}, {"input": "8\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13\r\n", "output": "4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n4000000001\r\n27\r\n"}, {"input": "3\r\n13 17 21\r\n", "ou...
false
stdio
null
true
175/B
175
B
Python 3
TESTS
1
62
0
214310458
# LUOGU_RID: 116207345 n=int(input()) d={} c=[] for _ in range(n): a,b=input().split() if a not in c: c.append(a) if a not in d: d[a]=b else: if d[a]<b: d[a]=b print(len(d)) m=len(c) x=[0]*m for i in range(m): for j in range(m): if d[c[i]]<d[c[j]]: ...
46
436
204,800
214355001
# LUOGU_RID: 116281298 n=int(input()) d={} c=[] for _ in range(n): a,b=input().split() b=int(b) if a not in c: c.append(a) if a not in d: d[a]=b else: if d[a]<b: d[a]=b print(len(d)) m=len(c) x=[0]*m for i in range(m): for j in range(m): if d[c[i]]<d[c...
Codeforces Round 115
CF
2,012
2
256
Plane of Tanks: Pro
Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has...
The first line contains the only integer number n (1 ≤ n ≤ 1000) — a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. T...
Print on the first line the number m — the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). Th...
null
In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has bes...
[{"input": "5\nvasya 100\nvasya 200\nartem 100\nkolya 200\nigor 250", "output": "4\nartem noob\nigor pro\nkolya random\nvasya random"}, {"input": "3\nvasya 200\nkolya 1000\nvasya 1000", "output": "2\nkolya pro\nvasya pro"}]
1,400
["implementation"]
78
[{"input": "5\r\nvasya 100\r\nvasya 200\r\nartem 100\r\nkolya 200\r\nigor 250\r\n", "output": "4\r\nartem noob\r\nigor pro\r\nkolya random\r\nvasya random\r\n"}, {"input": "3\r\nvasya 200\r\nkolya 1000\r\nvasya 1000\r\n", "output": "2\r\nkolya pro\r\nvasya pro\r\n"}, {"input": "1\r\nvasya 1000\r\n", "output": "1\r\nvas...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input data with open(input_path) as f: n = int(f.readline()) players = {} for _ in range(n): name, points = f.readline().strip().split() points = int(points) if name not in players ...
true
400/A
400
A
PyPy 3-64
TESTS
1
31
1,433,600
213973055
n = int(input()) otv = [] result = "" counter = 0 flag = True for _ in range(n): temp = input() for i in range(12): if 12 % (i+1) == 0 and temp[i] == "X": for j in range((i*2)+1, 12, i+1): if temp[j] != temp[i]: flag = False break ...
44
46
0
195790246
t = int(input()) N = 12 divisors = [1,2,3,4,6,12] L = 6 for _ in range(t): cards = input() goodDivs = [] for k in range(L): numCols = divisors[k] state = [True] * numCols for m in range(N): if cards[m] == 'O': state[m % numCols] = False if any(sta...
Codeforces Round 234 (Div. 2)
CF
2,014
1
256
Inna and Choose Options
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below: There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"...
The first line of the input contains integer t (1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line. The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th chara...
For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespac...
null
null
[{"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO", "output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"}]
1,000
["implementation"]
44
[{"input": "4\r\nOXXXOXOOXOOX\r\nOXOXOXOXOXOX\r\nXXXXXXXXXXXX\r\nOOOOOOOOOOOO\r\n", "output": "3 1x12 2x6 4x3\r\n4 1x12 2x6 3x4 6x2\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n0\r\n"}, {"input": "2\r\nOOOOOOOOOOOO\r\nXXXXXXXXXXXX\r\n", "output": "0\r\n6 1x12 2x6 3x4 4x3 6x2 12x1\r\n"}, {"input": "13\r\nXXXXXXXXXXXX\r\nXXXXXXXXXX...
false
stdio
null
true
863/D
863
D
PyPy 3
TESTS
6
1,777
16,486,400
93021857
n,q,m=map(int,input().split()) l=list(map(int,input().split())) w=[] for i in range(q): a,b,c=map(int,input().split()) w.append((a,b,c)) w.reverse() b=list(map(int,input().split())) for j in range(m): for i in range(q): a,b1,c=w[i] if b1<=b[j]<=c: if a==1: b[j]-=1...
23
499
19,660,800
113065724
import sys n, q, m = map(int, sys.stdin.buffer.readline().decode('utf-8').split()) a = list(map(int, sys.stdin.buffer.readline().decode('utf-8').split())) query = [list(map(int, sys.stdin.buffer.readline().decode('utf-8').split())) for _ in range(q)] b = list(map(int, sys.stdin.buffer.readline().decode('ut...
Educational Codeforces Round 29
ICPC
2,017
2
256
Yet Another Array Queries Problem
You are given an array a of size n, and q queries to it. There are queries of two types: - 1 li ri — perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li ≤ x < ri new value of ax + 1 becomes equal to old value of ax, and new value of ali becomes equal to old value of ari; - 2 ...
The first line contains three integer numbers n, q and m (1 ≤ n, q ≤ 2·105, 1 ≤ m ≤ 100). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109). Then q lines follow. i-th of them contains three integer numbers ti, li, ri, where ti is the type of i-th query, and [li, ri] is the segment where this q...
Print m numbers, i-th of which is equal to the number at index bi after all queries are done.
null
null
[{"input": "6 3 5\n1 2 3 4 5 6\n2 1 3\n2 3 6\n1 1 6\n2 2 1 5 3", "output": "3 3 1 5 2"}]
1,800
["data structures", "implementation"]
23
[{"input": "6 3 5\r\n1 2 3 4 5 6\r\n2 1 3\r\n2 3 6\r\n1 1 6\r\n2 2 1 5 3\r\n", "output": "3 3 1 5 2 \r\n"}, {"input": "5 2 5\r\n64 3 4 665 2\r\n1 1 3\r\n2 1 5\r\n1 2 3 4 5\r\n", "output": "2 665 3 64 4 \r\n"}, {"input": "1 1 1\r\n474812122\r\n2 1 1\r\n1\r\n", "output": "474812122 \r\n"}]
false
stdio
null
true
393/B
393
B
PyPy 3
TESTS
0
124
0
70848947
def nine(n,queries): A=[[0 for _ in range(n)] for _ in range(n)] B=[[0 for _ in range(n)] for _ in range(n)] for i in range(n): for j in range(i+1,n): a=queries[i][j] b=queries[j][i] x=(a+b)/2 y=a-x A[i][j]=x A[j][i]=x ...
40
171
9,318,400
115451908
import sys from os import path from collections import Counter if(path.exists("inp.txt")): sys.stdin = open("inp.txt",'r') sys.stdout = open("out.txt",'w') import math n=int(input()) w=[] li=[0]*((2*n)-1) for i in range(n): temp=list(map(int,input().split())) w.append(temp) a=[[0 for i in range(n)] for j in range(n...
Codeforces Round 230 (Div. 2)
CF
2,014
1
256
Three matrices
Chubby Yang is studying linear equations right now. He came up with a nice problem. In the problem you are given an n × n matrix W, consisting of integers, and you should find two n × n matrices A and B, all the following conditions must hold: - Aij = Aji, for all i, j (1 ≤ i, j ≤ n); - Bij =  - Bji, for all i, j (1 ≤...
The first line contains an integer n (1 ≤ n ≤ 170). Each of the following n lines contains n integers. The j-th integer in the i-th line is Wij (0 ≤ |Wij| < 1717).
The first n lines must contain matrix A. The next n lines must contain matrix B. Print the matrices in the format equal to format of matrix W in input. It is guaranteed that the answer exists. If there are multiple answers, you are allowed to print any of them. The answer will be considered correct if the absolute or ...
null
null
[{"input": "2\n1 4\n3 2", "output": "1.00000000 3.50000000\n3.50000000 2.00000000\n0.00000000 0.50000000\n-0.50000000 0.00000000"}, {"input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "1.00000000 3.00000000 5.00000000\n3.00000000 5.00000000 7.00000000\n5.00000000 7.00000000 9.00000000\n0.00000000 -1.00000000 -2.00000000\n1.0...
null
[]
40
[{"input": "2\r\n1 4\r\n3 2\r\n", "output": "1.00000000 3.50000000\r\n3.50000000 2.00000000\r\n0.00000000 0.50000000\r\n-0.50000000 0.00000000\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "1.00000000 3.00000000 5.00000000\r\n3.00000000 5.00000000 7.00000000\r\n5.00000000 7.00000000 9.00000000\r\n0.000...
false
stdio
import sys def is_close(a, b): abs_tol = 1e-4 rel_tol = 1e-4 diff = abs(a - b) if diff <= abs_tol: return True max_val = max(abs(a), abs(b)) return diff <= rel_tol * max_val def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.read().spl...
true
522/C
522
C
Python 3
PRETESTS
3
46
0
10199729
t = int(input()) for i in range(t): input() m,k = map(int,input().split()) ak = list(map(int,input().split())) ak2 = [0]*k tjrj = [list(map(int,input().split())) for j in range(m-1)] num = 0 num2 = 0 for j in range(m-1): if num2 == 1 or tjrj[j][1] == 0: if tjrj[j][0] ...
48
654
10,342,400
10207272
import sys test_count = int(sys.stdin.readline()) for test in range(test_count): sys.stdin.readline() m, k = map(int, sys.stdin.readline().split()) counts = list(map(int, sys.stdin.readline().split())) took = [] unhappy = [] for i in range(m - 1): t, r = map(int, sys.stdin.readline().sp...
VK Cup 2015 - Qualification Round 1
CF
2,015
1
256
Chicken or Fish?
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food. The flight menu has k dishes in t...
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line. The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000,...
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
null
In the first input set depending on the choice of the second passenger the situation could develop in different ways: - If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish; - If he chose the fourth dish, then by the moment the stewardess reaches Poly...
[{"input": "2\n3 4\n2 3 2 1\n1 0\n0 0\n5 5\n1 2 1 3 1\n3 0\n0 0\n2 1\n4 0", "output": "YNNY\nYYYNY"}]
2,100
["greedy"]
48
[{"input": "2\r\n\r\n3 4\r\n2 3 2 1\r\n1 0\r\n0 0\r\n\r\n5 5\r\n1 2 1 3 1\r\n3 0\r\n0 0\r\n2 1\r\n4 0\r\n", "output": "YNNY\r\nYYYNY\r\n"}, {"input": "4\r\n\r\n2 1\r\n42\r\n0 0\r\n\r\n2 1\r\n2\r\n0 0\r\n\r\n2 1\r\n42\r\n1 0\r\n\r\n2 1\r\n2\r\n1 0\r\n", "output": "N\r\nN\r\nN\r\nN\r\n"}, {"input": "5\r\n\r\n3 3\r\n1 1 1...
false
stdio
null
true
522/C
522
C
Python 3
PRETESTS
3
46
0
10202926
for ts in range(int(input())): input() m, k = tuple(map(int, input().split())) a = list(map(int, input().split())) at = [] o = 'N'*k for i in range(m-1): tj, rj = tuple(map(int, input().split())) if tj > 0: a[tj-1] -= 1 if a[tj-1] == 0: o =...
48
967
7,475,200
10211431
t = int(input()) for j in range(t): e = input() m, k = map(int, input().split()) arr = [int(i) for i in input().split()] sum, bfail = [0] * k, [0] * k ffail, undef = -1, 0 used = [False] * k ubfail = 0 for i in range(m - 1): c, ns = map(int, input().split()) if c == 0: ...
VK Cup 2015 - Qualification Round 1
CF
2,015
1
256
Chicken or Fish?
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food. The flight menu has k dishes in t...
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line. The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000,...
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
null
In the first input set depending on the choice of the second passenger the situation could develop in different ways: - If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish; - If he chose the fourth dish, then by the moment the stewardess reaches Poly...
[{"input": "2\n3 4\n2 3 2 1\n1 0\n0 0\n5 5\n1 2 1 3 1\n3 0\n0 0\n2 1\n4 0", "output": "YNNY\nYYYNY"}]
2,100
["greedy"]
48
[{"input": "2\r\n\r\n3 4\r\n2 3 2 1\r\n1 0\r\n0 0\r\n\r\n5 5\r\n1 2 1 3 1\r\n3 0\r\n0 0\r\n2 1\r\n4 0\r\n", "output": "YNNY\r\nYYYNY\r\n"}, {"input": "4\r\n\r\n2 1\r\n42\r\n0 0\r\n\r\n2 1\r\n2\r\n0 0\r\n\r\n2 1\r\n42\r\n1 0\r\n\r\n2 1\r\n2\r\n1 0\r\n", "output": "N\r\nN\r\nN\r\nN\r\n"}, {"input": "5\r\n\r\n3 3\r\n1 1 1...
false
stdio
null
true
713/C
713
C
PyPy 3-64
TESTS
0
30
0
200936448
import heapq n = int(input()) a = list(map(int, input().split())) INF = 10 ** 18 dp = [INF] * n dp[0] = 0 min_last = a[0] heap_left = [-min_last] heap_right = [] for i in range(1, n): heapq.heappush(heap_right, a[i] - i) if len(heap_right) > len(heap_left): x = heapq.heappop(heap_right) heapq....
57
202
4,096,000
73327542
from bisect import insort class Graph: def __init__(_): _.change = [-10**27] # increment slope at ... _.a = _.y = 0 # last line has slope a, starts from y _.dx = 0 # the whole graph is shifted right by ... def __repr__(_): return f"<{[x+_.dx for x in _.change]}; {_.a} {_.y}>" ...
Codeforces Round 371 (Div. 1)
CF
2,016
5
256
Sonya and Problem Wihtout a Legend
Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operati...
The first line of the input contains a single integer n (1 ≤ n ≤ 3000) — the length of the array. Next line contains n integer ai (1 ≤ ai ≤ 109).
Print the minimum number of operation required to make the array strictly increasing.
null
In the first sample, the array is going to look as follows: 2 3 5 6 7 9 11 |2 - 2| + |1 - 3| + |5 - 5| + |11 - 6| + |5 - 7| + |9 - 9| + |11 - 11| = 9 And for the second sample: 1 2 3 4 5 |5 - 1| + |4 - 2| + |3 - 3| + |2 - 4| + |1 - 5| = 12
[{"input": "7\n2 1 5 11 5 9 11", "output": "9"}, {"input": "5\n5 4 3 2 1", "output": "12"}]
2,300
["dp", "sortings"]
57
[{"input": "7\r\n2 1 5 11 5 9 11\r\n", "output": "9\r\n"}, {"input": "5\r\n5 4 3 2 1\r\n", "output": "12\r\n"}, {"input": "2\r\n1 1000\r\n", "output": "0\r\n"}, {"input": "2\r\n1000 1\r\n", "output": "1000\r\n"}, {"input": "5\r\n100 80 60 70 90\r\n", "output": "54\r\n"}, {"input": "10\r\n10 16 17 11 1213 1216 1216 1209...
false
stdio
null
true
522/C
522
C
Python 3
PRETESTS
3
61
0
10196356
def algorithm(): try: sum_m = 0 sum_k = 0 set_count = int(input()) if not (1 <= set_count <= 100000): return None result = list() for i in range(0, set_count): input() first = input().split(' ') i_count = int(first[0]) k_count = int(first[1]) sum_m += i_count sum_k += i_count if su...
48
998
13,926,400
10199791
t = int(input()) for i in range(t): input() m,k = map(int,input().split()) ak = list(map(int,input().split())) ak2 = [0]*k tjrj = [list(map(int,input().split())) for j in range(m-1)] num = 0 num2 = 0 num3 = 100002 for j in range(m-1): if num2 == 1 or tjrj[j][1] == 0: ...
VK Cup 2015 - Qualification Round 1
CF
2,015
1
256
Chicken or Fish?
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food. The flight menu has k dishes in t...
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line. The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000,...
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
null
In the first input set depending on the choice of the second passenger the situation could develop in different ways: - If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish; - If he chose the fourth dish, then by the moment the stewardess reaches Poly...
[{"input": "2\n3 4\n2 3 2 1\n1 0\n0 0\n5 5\n1 2 1 3 1\n3 0\n0 0\n2 1\n4 0", "output": "YNNY\nYYYNY"}]
2,100
["greedy"]
48
[{"input": "2\r\n\r\n3 4\r\n2 3 2 1\r\n1 0\r\n0 0\r\n\r\n5 5\r\n1 2 1 3 1\r\n3 0\r\n0 0\r\n2 1\r\n4 0\r\n", "output": "YNNY\r\nYYYNY\r\n"}, {"input": "4\r\n\r\n2 1\r\n42\r\n0 0\r\n\r\n2 1\r\n2\r\n0 0\r\n\r\n2 1\r\n42\r\n1 0\r\n\r\n2 1\r\n2\r\n1 0\r\n", "output": "N\r\nN\r\nN\r\nN\r\n"}, {"input": "5\r\n\r\n3 3\r\n1 1 1...
false
stdio
null
true
522/C
522
C
Python 3
PRETESTS
3
62
0
10207046
tests = int(input()) for i in range(tests): input() inp = input().split() m = int(inp[0]) k = int(inp[1]) a = [] inp = input().split() sum = 0 for j in range(k): a.append(int(inp[j])) sum += a[j] has_zero = False for j in range(m-1): inp = input().split() ...
48
654
10,342,400
10207272
import sys test_count = int(sys.stdin.readline()) for test in range(test_count): sys.stdin.readline() m, k = map(int, sys.stdin.readline().split()) counts = list(map(int, sys.stdin.readline().split())) took = [] unhappy = [] for i in range(m - 1): t, r = map(int, sys.stdin.readline().sp...
VK Cup 2015 - Qualification Round 1
CF
2,015
1
256
Chicken or Fish?
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food. The flight menu has k dishes in t...
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line. The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000,...
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
null
In the first input set depending on the choice of the second passenger the situation could develop in different ways: - If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish; - If he chose the fourth dish, then by the moment the stewardess reaches Poly...
[{"input": "2\n3 4\n2 3 2 1\n1 0\n0 0\n5 5\n1 2 1 3 1\n3 0\n0 0\n2 1\n4 0", "output": "YNNY\nYYYNY"}]
2,100
["greedy"]
48
[{"input": "2\r\n\r\n3 4\r\n2 3 2 1\r\n1 0\r\n0 0\r\n\r\n5 5\r\n1 2 1 3 1\r\n3 0\r\n0 0\r\n2 1\r\n4 0\r\n", "output": "YNNY\r\nYYYNY\r\n"}, {"input": "4\r\n\r\n2 1\r\n42\r\n0 0\r\n\r\n2 1\r\n2\r\n0 0\r\n\r\n2 1\r\n42\r\n1 0\r\n\r\n2 1\r\n2\r\n1 0\r\n", "output": "N\r\nN\r\nN\r\nN\r\n"}, {"input": "5\r\n\r\n3 3\r\n1 1 1...
false
stdio
null
true
522/C
522
C
Python 3
PRETESTS
3
46
0
10195992
for i in range(int(input())): _ = input() m, k = [int(x) for x in input().split()] foods = [[int(x), 0] for x in input().split()] n = 0 for i in range(m-1): eat, sad = [int(x) for x in input().split()] if sad: maybe = [(i, x) for i, x in enumerate(foods) if x[0] - x[1] - ...
48
967
7,475,200
10211431
t = int(input()) for j in range(t): e = input() m, k = map(int, input().split()) arr = [int(i) for i in input().split()] sum, bfail = [0] * k, [0] * k ffail, undef = -1, 0 used = [False] * k ubfail = 0 for i in range(m - 1): c, ns = map(int, input().split()) if c == 0: ...
VK Cup 2015 - Qualification Round 1
CF
2,015
1
256
Chicken or Fish?
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food. The flight menu has k dishes in t...
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line. The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000,...
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
null
In the first input set depending on the choice of the second passenger the situation could develop in different ways: - If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish; - If he chose the fourth dish, then by the moment the stewardess reaches Poly...
[{"input": "2\n3 4\n2 3 2 1\n1 0\n0 0\n5 5\n1 2 1 3 1\n3 0\n0 0\n2 1\n4 0", "output": "YNNY\nYYYNY"}]
2,100
["greedy"]
48
[{"input": "2\r\n\r\n3 4\r\n2 3 2 1\r\n1 0\r\n0 0\r\n\r\n5 5\r\n1 2 1 3 1\r\n3 0\r\n0 0\r\n2 1\r\n4 0\r\n", "output": "YNNY\r\nYYYNY\r\n"}, {"input": "4\r\n\r\n2 1\r\n42\r\n0 0\r\n\r\n2 1\r\n2\r\n0 0\r\n\r\n2 1\r\n42\r\n1 0\r\n\r\n2 1\r\n2\r\n1 0\r\n", "output": "N\r\nN\r\nN\r\nN\r\n"}, {"input": "5\r\n\r\n3 3\r\n1 1 1...
false
stdio
null
true
522/C
522
C
Python 3
PRETESTS
3
61
0
10208721
t = int(input()) for v in range(t): q = 0 empty_line = input() m,k = map(int,input().split()) res = [0]*k t,r = [0]*(m-1),[0]*(m-1) help = [0]*k amount_of_food = list(map(int,input().split())) for i in range(m-1): t[i],r[i] = map(int,input().split()) for i in range(m-1): ...
48
998
13,926,400
10199791
t = int(input()) for i in range(t): input() m,k = map(int,input().split()) ak = list(map(int,input().split())) ak2 = [0]*k tjrj = [list(map(int,input().split())) for j in range(m-1)] num = 0 num2 = 0 num3 = 100002 for j in range(m-1): if num2 == 1 or tjrj[j][1] == 0: ...
VK Cup 2015 - Qualification Round 1
CF
2,015
1
256
Chicken or Fish?
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food. The flight menu has k dishes in t...
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line. The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000,...
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
null
In the first input set depending on the choice of the second passenger the situation could develop in different ways: - If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish; - If he chose the fourth dish, then by the moment the stewardess reaches Poly...
[{"input": "2\n3 4\n2 3 2 1\n1 0\n0 0\n5 5\n1 2 1 3 1\n3 0\n0 0\n2 1\n4 0", "output": "YNNY\nYYYNY"}]
2,100
["greedy"]
48
[{"input": "2\r\n\r\n3 4\r\n2 3 2 1\r\n1 0\r\n0 0\r\n\r\n5 5\r\n1 2 1 3 1\r\n3 0\r\n0 0\r\n2 1\r\n4 0\r\n", "output": "YNNY\r\nYYYNY\r\n"}, {"input": "4\r\n\r\n2 1\r\n42\r\n0 0\r\n\r\n2 1\r\n2\r\n0 0\r\n\r\n2 1\r\n42\r\n1 0\r\n\r\n2 1\r\n2\r\n1 0\r\n", "output": "N\r\nN\r\nN\r\nN\r\n"}, {"input": "5\r\n\r\n3 3\r\n1 1 1...
false
stdio
null
true