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
270/A
270
A
Python 3
TESTS
2
60
0
227538365
n=int(input()) for i in range(n): angle=int(input()) if angle in [60,90,120,135,144,150,160,162,165,168,170,171,174,175,176,177,178,179]: print('YES') else: print('NO')
3
30
0
144631819
for i in range(int(input())): n=int(input()) if n<60: print("NO") else: if (360%(180-n))==0: print("YES") else: print("NO")
Codeforces Round 165 (Div. 2)
CF
2,013
2
256
Fancy Fence
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a. Will the robot be able to build the fence Emuskald...
The first line of input contains an integer t (0 < t < 180) — the number of tests. Each of the following t lines contains a single integer a (0 < a < 180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
null
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle $$30^\circ$$. In the second test case, the fence is a regular triangle, and in the last test case — a square.
[{"input": "3\n30\n60\n90", "output": "NO\nYES\nYES"}]
1,100
["geometry", "implementation", "math"]
3
[{"input": "3\r\n30\r\n60\r\n90\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n170\r\n179\r\n25\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\nYES\r\nNO\r\n"}]
false
stdio
null
true
270/A
270
A
Python 3
TESTS
2
60
0
193129242
n = int(input()) l = [-180, 0, 60, 90, 108, 120, 135, 140, 144, 150, 156, 160, 162, 165, 168, 170, 171, 172, 174, 175, 176, 178, 179] for i in range(n): x = int(input()) if x in l: print('YES') else: print('NO')
3
30
0
146321238
def solve(): t = int(input()) q = [int(input()) for i in range(t)] angles = {} for i in q: n = -360/(i-180) if n.is_integer(): print('YES') else: print('NO') solve()
Codeforces Round 165 (Div. 2)
CF
2,013
2
256
Fancy Fence
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a. Will the robot be able to build the fence Emuskald...
The first line of input contains an integer t (0 < t < 180) — the number of tests. Each of the following t lines contains a single integer a (0 < a < 180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
null
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle $$30^\circ$$. In the second test case, the fence is a regular triangle, and in the last test case — a square.
[{"input": "3\n30\n60\n90", "output": "NO\nYES\nYES"}]
1,100
["geometry", "implementation", "math"]
3
[{"input": "3\r\n30\r\n60\r\n90\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n170\r\n179\r\n25\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\nYES\r\nNO\r\n"}]
false
stdio
null
true
786/A
786
A
Python 3
TESTS
0
30
0
227030291
n = int(input()) rick_set = list(map(int, input().split()))[1:] morty_set = list(map(int, input().split()))[1:] win_rick = [False] * (n - 1) win_morty = [False] * (n - 1) for i in range(n - 1, 0, -1): if i + rick_set[0] >= n: win_rick[i - 1] = True for i in range(n - 1, 0, -1): for x in morty_set: ...
49
1,309
28,979,200
33321494
f = lambda: list(map(int, input().split()))[1:] n = int(input()) s, p, q = [], [], [] for x in [0, 1]: r = f() s.append(r) t = [len(r)] * n t[0] = 0 p.append(t) q.append((x, 0)) while q: x, i = q.pop() y = 1 - x for d in s[y]: j = (i - d) % n if p[y][j] < 1: continue ...
Codeforces Round 406 (Div. 1)
CF
2,017
4
256
Berzerk
Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer. In this game there are n objects numbered from 1 to n arranged in a circle (in clockwise order). Object number 1 is a black hole and the oth...
The first line of input contains a single integer n (2 ≤ n ≤ 7000) — number of objects in game. The second line contains integer k1 followed by k1 distinct integers s1, 1, s1, 2, ..., s1, k1 — Rick's set. The third line contains integer k2 followed by k2 distinct integers s2, 1, s2, 2, ..., s2, k2 — Morty's set 1 ≤ ...
In the first line print n - 1 words separated by spaces where i-th word is "Win" (without quotations) if in the scenario that Rick plays first and monster is initially in object number i + 1 he wins, "Lose" if he loses and "Loop" if the game will never end. Similarly, in the second line print n - 1 words separated by ...
null
null
[{"input": "5\n2 3 2\n3 1 2 3", "output": "Lose Win Win Loop\nLoop Win Win Win"}, {"input": "8\n4 6 2 3 4\n2 3 6", "output": "Win Win Win Win Win Win Win\nLose Win Lose Lose Win Lose Lose"}]
2,000
["dfs and similar", "dp", "games"]
49
[{"input": "5\r\n2 3 2\r\n3 1 2 3\r\n", "output": "Lose Win Win Loop\r\nLoop Win Win Win\r\n"}, {"input": "8\r\n4 6 2 3 4\r\n2 3 6\r\n", "output": "Win Win Win Win Win Win Win\r\nLose Win Lose Lose Win Lose Lose\r\n"}, {"input": "10\r\n3 4 7 5\r\n2 8 5\r\n", "output": "Win Win Win Win Win Win Win Loop Win\r\nLose Win L...
false
stdio
null
true
270/A
270
A
Python 3
TESTS
2
60
0
200430380
a=int(input()) b=[] for i in range(a): c=int(input()) if c>=60 and c<=179: b.append("YES") else: b.append("NO") for i in b: print(i)
3
30
0
175516098
# -*- coding: utf-8 -*- """ Created on Tue Oct 11 15:21:27 2022 @author: lpf """ t=int(input()) for i in range(t): a=int(input()) print('YES'if 360%(180-a)==0 else 'NO')
Codeforces Round 165 (Div. 2)
CF
2,013
2
256
Fancy Fence
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a. Will the robot be able to build the fence Emuskald...
The first line of input contains an integer t (0 < t < 180) — the number of tests. Each of the following t lines contains a single integer a (0 < a < 180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
null
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle $$30^\circ$$. In the second test case, the fence is a regular triangle, and in the last test case — a square.
[{"input": "3\n30\n60\n90", "output": "NO\nYES\nYES"}]
1,100
["geometry", "implementation", "math"]
3
[{"input": "3\r\n30\r\n60\r\n90\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n170\r\n179\r\n25\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\nYES\r\nNO\r\n"}]
false
stdio
null
true
990/F
990
F
Python 3
TESTS
0
31
0
158501113
print("Impossible") # 凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数
37
1,388
80,486,400
39209819
import sys from time import time def i_ints(): return list(map(int, sys.stdin.readline().split())) def main(): limit =10**10 n, = i_ints() s = [0] + i_ints() if sum(s): print("Impossible") return print("Possible") m, = i_ints() es = [i_ints() for _ in range(m)] n...
Educational Codeforces Round 45 (Rated for Div. 2)
ICPC
2,018
2
256
Flow Control
You have to handle a very complex water distribution system. The system consists of $$$n$$$ junctions and $$$m$$$ pipes, $$$i$$$-th pipe connects junctions $$$x_i$$$ and $$$y_i$$$. The only thing you can do is adjusting the pipes. You have to choose $$$m$$$ integer numbers $$$f_1$$$, $$$f_2$$$, ..., $$$f_m$$$ and use ...
The first line contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of junctions. The second line contains $$$n$$$ integers $$$s_1, s_2, \dots, s_n$$$ ($$$-10^4 \le s_i \le 10^4$$$) — constraints for the junctions. The third line contains an integer $$$m$$$ ($$$0 \le m \le 2 \cdot 10^5$$$) — the ...
If you can choose such integer numbers $$$f_1, f_2, \dots, f_m$$$ in such a way that all requirements on incoming and outcoming flows are satisfied, then output "Possible" in the first line. Then output $$$m$$$ lines, $$$i$$$-th line should contain $$$f_i$$$ — the chosen setting numbers for the pipes. Pipes are numbere...
null
null
[{"input": "4\n3 -10 6 1\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "output": "Possible\n4\n-6\n8\n-7\n7"}, {"input": "4\n3 -10 6 4\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "output": "Impossible"}]
2,400
["dfs and similar", "dp", "greedy", "trees"]
37
[{"input": "4\r\n3 -10 6 1\r\n5\r\n1 2\r\n3 2\r\n2 4\r\n3 4\r\n3 1\r\n", "output": "Possible\r\n-3\r\n-6\r\n1\r\n0\r\n0\r\n"}, {"input": "4\r\n3 -10 6 4\r\n5\r\n1 2\r\n3 2\r\n2 4\r\n3 4\r\n3 1\r\n", "output": "Impossible\r\n"}, {"input": "1\r\n0\r\n0\r\n", "output": "Possible\r\n"}, {"input": "1\r\n123\r\n0\r\n", "outp...
false
stdio
import sys def main(): input_path = sys.argv[1] submission_path = sys.argv[3] with open(input_path) as f: n = int(f.readline()) s = list(map(int, f.readline().split())) m = int(f.readline()) pipes = [tuple(map(int, f.readline().split())) for _ in range(m)] sum_s = ...
true
785/D
785
D
PyPy 3-64
TESTS
0
46
3,072,000
222605411
R=10**5 M=10**9+7 F=[1]*(R+1) for i in range(1,R+1): F[i]=(F[i-1]*i)%M Fhyp=[1]*(R+1) Fhyp[R]=pow(F[R],M-2,M) for i in range(R-1,-1,-1): Fhyp[i]=(Fhyp[i+1]*(i+1))%M def C(n,k): if n<0 or k<0 or n<k: return 0 return (F[n]*Fhyp[n-k]*Fhyp[k])%M s=[e==')' for e in input()] n=len(s) L=[0]*n L[0]=int(...
60
561
25,702,400
197613643
t = input() n, m = len(t) + 1, 1000000007 a, b = 0, t.count(')') - 1 f = [1] * n for i in range(2, n): f[i] = i * f[i - 1] % m g = [pow(q, m - 2, m) for q in f] s = 0 for q in t: if b < 0: break if q == '(': a += 1 s += f[a + b] * g[a] * g[b] else: b -= 1 print(s % m)
Codeforces Round 404 (Div. 2)
CF
2,017
2
256
Anton and School - 2
As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket s...
The only line of the input contains a string s — the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed 200 000.
Output one number — the answer for the task modulo 109 + 7.
null
In the first sample the following subsequences are possible: - If we delete characters at the positions 1 and 5 (numbering starts with one), we will get the subsequence "(())". - If we delete characters at the positions 1, 2, 3 and 4, we will get the subsequence "()". - If we delete characters at the positions 1, 2, 4...
[{"input": ")(()()", "output": "6"}, {"input": "()()()", "output": "7"}, {"input": ")))", "output": "0"}]
2,300
["combinatorics", "dp", "math", "number theory"]
60
[{"input": ")(()()\r\n", "output": "6\r\n"}, {"input": "()()()\r\n", "output": "7\r\n"}, {"input": ")))\r\n", "output": "0\r\n"}, {"input": ")())((((((()))()((()))()((()()()((()()()))\r\n", "output": "4344426\r\n"}, {"input": "(\r\n", "output": "0\r\n"}, {"input": ")\r\n", "output": "0\r\n"}, {"input": "((\r\n", "outpu...
false
stdio
null
true
241/A
241
A
Python 3
TESTS
2
186
0
58515097
import sys def solution(k, d_arr, s_arr): hours = 0 liters = 0 for i in range(len(d_arr)): liters += s_arr[i] d_curr = d_arr[i] while liters <= d_curr: liters += s_arr[i] hours += k hours += d_curr return hours if __name__ == '__main__': ...
52
124
5,120,000
17870511
# -*- coding: utf-8 -*- def main(): m, k = [int(x) for x in input().split()] d = [int(x) for x in input().split()] s = [int(x) for x in input().split()] ans = 0 # total time spent fuel = 0 # amount of fuel in the tank mx = 0 # largest depo seen so far for i in range(m): ...
Bayan 2012-2013 Elimination Round (ACM ICPC Rules, English statements)
ICPC
2,012
2
256
Old Peykan
There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city c1 to cn using roads. There are (n - 1) one way roads, the i-th road goes from city ci to city ci + 1 and is di kil...
The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000). The value m specifies the number of roads between cities which is equal to n - 1. The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and the following line contains m space-separated integers s1,...
In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cn from city c1.
null
In the second sample above, the Old Peykan stays in c1 for 3 hours.
[{"input": "4 6\n1 2 5 2\n2 3 3 4", "output": "10"}, {"input": "2 3\n5 6\n5 5", "output": "14"}]
1,300
["greedy"]
52
[{"input": "4 6\r\n1 2 5 2\r\n2 3 3 4\r\n", "output": "10\r\n"}, {"input": "2 3\r\n5 6\r\n5 5\r\n", "output": "14\r\n"}, {"input": "24 3\r\n11 8 8 12 17 4 4 25 39 37 31 32 38 34 29 29 34 39 39 39 17 9 24 6\r\n3 5 4 3 3 3 4 3 4 3 3 3 3 4 3 3 4 3 4 3 3 3 3 3\r\n", "output": "862\r\n"}, {"input": "43 5\r\n6 7 15 12 15 7 2...
false
stdio
null
true
241/A
241
A
PyPy 3
TESTS
2
278
1,228,800
93616866
a,b=map(int,input().split()) d=list(map(int,input().split())) p=list(map(int,input().split()));k=int(1e9) for i in range(a): if sum(d[:i+1])>sum(p[:i+1]):k=min(k,b*(sum(p[:i+1])+max(d[:i+1])-1-sum(p[:i+1]))//max(p[:i+1])) print(sum(d)+[k,0][k==int(1e9)])
52
154
1,536,000
209795812
import math ''' 4 6 1 2 5 2 2 3 3 4 ''' m, k = map(int, input().split()) n = m+1 distance = list(map(int, input().split())) supply = list(map(int, input().split())) currentTank = supply[0] currentCity = 1 biggestSupply = supply[0] time = sum(distance) #the next road is distance[currentCity-1] #the supply of currentCi...
Bayan 2012-2013 Elimination Round (ACM ICPC Rules, English statements)
ICPC
2,012
2
256
Old Peykan
There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city c1 to cn using roads. There are (n - 1) one way roads, the i-th road goes from city ci to city ci + 1 and is di kil...
The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000). The value m specifies the number of roads between cities which is equal to n - 1. The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and the following line contains m space-separated integers s1,...
In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cn from city c1.
null
In the second sample above, the Old Peykan stays in c1 for 3 hours.
[{"input": "4 6\n1 2 5 2\n2 3 3 4", "output": "10"}, {"input": "2 3\n5 6\n5 5", "output": "14"}]
1,300
["greedy"]
52
[{"input": "4 6\r\n1 2 5 2\r\n2 3 3 4\r\n", "output": "10\r\n"}, {"input": "2 3\r\n5 6\r\n5 5\r\n", "output": "14\r\n"}, {"input": "24 3\r\n11 8 8 12 17 4 4 25 39 37 31 32 38 34 29 29 34 39 39 39 17 9 24 6\r\n3 5 4 3 3 3 4 3 4 3 3 3 3 4 3 3 4 3 4 3 3 3 3 3\r\n", "output": "862\r\n"}, {"input": "43 5\r\n6 7 15 12 15 7 2...
false
stdio
null
true
241/A
241
A
PyPy 3-64
TESTS
2
92
0
164830634
import sys input = sys.stdin.readline from math import ceil m, k = map(int, input().split()) w = list(map(int, input().split())) s = list(map(int, input().split())) c = 0 t = 0 for i in range(m): t += s[i] if t < w[i]: x = ceil((w[i] - t)/s[i]) t += x*s[i] c += x*k t -= w[i] c...
52
218
6,963,200
80074357
from math import ceil n, k = map(int,input().split()) d = list(map(int,input().split())) s = list(map(int,input().split())) fuel = 0 stor = 0 time = 0 for i in range(n): fuel+= s[i] stor = max(stor, s[i]) if fuel >= d[i]: fuel-= d[i] time+= d[i] else: yy = ceil((d[i] - fuel) / stor) time+= k * yy time+= ...
Bayan 2012-2013 Elimination Round (ACM ICPC Rules, English statements)
ICPC
2,012
2
256
Old Peykan
There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city c1 to cn using roads. There are (n - 1) one way roads, the i-th road goes from city ci to city ci + 1 and is di kil...
The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000). The value m specifies the number of roads between cities which is equal to n - 1. The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and the following line contains m space-separated integers s1,...
In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cn from city c1.
null
In the second sample above, the Old Peykan stays in c1 for 3 hours.
[{"input": "4 6\n1 2 5 2\n2 3 3 4", "output": "10"}, {"input": "2 3\n5 6\n5 5", "output": "14"}]
1,300
["greedy"]
52
[{"input": "4 6\r\n1 2 5 2\r\n2 3 3 4\r\n", "output": "10\r\n"}, {"input": "2 3\r\n5 6\r\n5 5\r\n", "output": "14\r\n"}, {"input": "24 3\r\n11 8 8 12 17 4 4 25 39 37 31 32 38 34 29 29 34 39 39 39 17 9 24 6\r\n3 5 4 3 3 3 4 3 4 3 3 3 3 4 3 3 4 3 4 3 3 3 3 3\r\n", "output": "862\r\n"}, {"input": "43 5\r\n6 7 15 12 15 7 2...
false
stdio
null
true
489/A
489
A
PyPy 3-64
TESTS
0
46
0
201606017
n=int(input()) x = list(map(lambda q:int(q), input().split(" "))) y=x.copy() y.sort() a=[] t=0 for i in range(n): for j in range(n): if y[i]==x[j]: t+=1 f=(j,i) a.append(f) break if x==y: break print(t) for i in range(t): print(...
22
218
409,600
8719997
import operator n = int(input()) xs = list(map(int, str.split(input()))) if xs == sorted(xs): print(0) else: swaps = [] counter = 0 while xs: i = xs.index(min(xs)) if i: swaps.append(str.format("{} {}", counter, i + counter)) xs[0], xs[i] = xs[i], xs[0] ...
Codeforces Round 277.5 (Div. 2)
CF
2,014
1
256
SwapSort
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another. Note that in this problem you do not have to minimize the number of sw...
The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≤ ai ≤ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the arr...
In the first line print k (0 ≤ k ≤ n) — the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≤ i, j ≤ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are per...
null
null
[{"input": "5\n5 2 5 1 4", "output": "2\n0 3\n4 2"}, {"input": "6\n10 20 20 40 60 60", "output": "0"}, {"input": "2\n101 100", "output": "1\n0 1"}]
1,200
["greedy", "implementation", "sortings"]
22
[{"input": "5\r\n5 2 5 1 4\r\n", "output": "2\r\n0 3\r\n4 2\r\n"}, {"input": "6\r\n10 20 20 40 60 60\r\n", "output": "0\r\n"}, {"input": "2\r\n101 100\r\n", "output": "1\r\n0 1\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "2\r\n1000000000 -1000000000\r\n", "output": "1\r\n0 1\r\n"}, {"input": "8\r\n5...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path) as f: n = int(f.readline().strip()) arr = list(map(int, f.readline().split())) with open(sub_path) as f: lines = f.readlines() if not lines: ...
true
379/C
379
C
PyPy 3-64
TESTS
2
46
0
187473498
n=int(input()) a=list(map(int,input().split())) b=[] for i in range(n): if a[i] not in b: b.append(a[i]) else: while a[i] in b: a[i]+=1 b.append(a[i]) a[i]=i print(*a)
41
670
53,862,400
167040474
import sys input = sys.stdin.readline n = int(input()) w = sorted(enumerate(map(int, input().split())), key=lambda x:x[1]) x = [0]*n c = 0 for i in range(n): if w[i][1] > c: x[w[i][0]] = w[i][1] c = w[i][1] + 1 else: x[w[i][0]] = c c += 1 print(' '.join(map(str, x)))
Good Bye 2013
CF
2,013
1
256
New Year Ratings Change
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors. There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai ratin...
The first line contains integer n (1 ≤ n ≤ 3·105) — the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 ≤ ai ≤ 109).
Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions. If there are multiple optimal solutions, print any of them.
null
null
[{"input": "3\n5 1 1", "output": "5 1 2"}, {"input": "1\n1000000000", "output": "1000000000"}]
1,400
["greedy", "sortings"]
41
[{"input": "3\r\n5 1 1\r\n", "output": "5 1 2\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "1000000000\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1 2 3 4 5 6 7 8 9 10\r\n"}, {"input": "10\r\n1 10 1 10 1 1 7 8 6 7\r\n", "output": "1 10 2 11 3 4 7 9 6 8\r\n"}, {"input": "10\r\n20 19 12 1 12 15 2 12...
false
stdio
null
true
394/C
394
C
Python 3
TESTS
0
93
0
45285029
a,b=map(int,input().split()) c=list() cn=list() x00=0 x01=0 x11=0 for i in range(a): c.append(list(input().split())) x11=c[-1].count('11') x01=c[-1].count('01')+c[-1].count('10') d=x11//b for i in range(d): print((b-1)*'11 '+'11') d=x11%b e=x01//2 f=(d+e)//b for i in range(f): print((d//f)*'11 '+(e/...
27
951
45,977,600
48909369
a,b=map(int,input().split()) c=list() x00=0 x01=0 x11=0 for i in range(a): c.append(list(input().split())) x11+=c[-1].count('11') x01+=c[-1].count('01')+c[-1].count('10') x00=a*b-x11-x01 new=[[]for i in range(b)] i=0 while x11>0: x11-=1 new[i].append('11') i+=1 i%=b step=1 reverse=False whil...
Codeforces Round 231 (Div. 2)
CF
2,014
2
256
Dominoes
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes. The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half...
The first line contains integers n, m (1 ≤ n, m ≤ 103). In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes. If there are multiple optimal solutions, print any of them.
null
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal. Note that the dominoes can be rotated by 180 degrees.
[{"input": "2 3\n01 11 00\n00 01 11", "output": "11 11 10\n00 00 01"}, {"input": "4 1\n11\n10\n01\n00", "output": "11\n10\n01\n00"}]
null
["constructive algorithms", "greedy"]
27
[{"input": "2 3\r\n01 11 00\r\n00 01 11\r\n", "output": "11 11 10\r\n00 00 01\r\n"}, {"input": "4 1\r\n11\r\n10\r\n01\r\n00\r\n", "output": "11\r\n10\r\n01\r\n00\r\n"}, {"input": "1 1\r\n00\r\n", "output": "00\r\n"}, {"input": "1 1\r\n01\r\n", "output": "10\r\n"}, {"input": "1 1\r\n11\r\n", "output": "11\r\n"}, {"input...
false
stdio
import sys from collections import Counter def read_dominoes(file, n, m): dominoes = [] grid = [] for _ in range(n): line = file.readline().strip() if not line: return [], [] row_dominoes = line.split() grid_row = [] for d in row_dominoes: a, ...
true
367/B
367
B
Python 3
TESTS
2
61
0
116267494
st=input().split() n=int(st[0]) m=int(st[1]) p=int(st[2]) a=list(map(int,input().split())) b=list(map(int,input().split())) q=n-(m-1)*p print(2) print(1,q)
59
452
27,750,400
5995052
from collections import defaultdict n, m, p = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) u = defaultdict(int) for i in b: u[i] += 1 ans = [] for q in range(p): c = a[q: n: p] if len(c) < m: break v = defaultdict(int) for i in c[: m]: v[i] += 1 ...
Codeforces Round 215 (Div. 1)
CF
2,013
1
256
Sereja ans Anagrams
Sereja has two sequences a and b and number p. Sequence a consists of n integers a1, a2, ..., an. Similarly, sequence b consists of m integers b1, b2, ..., bm. As usual, Sereja studies the sequences he has. Today he wants to find the number of positions q (q + (m - 1)·p ≤ n; q ≥ 1), such that sequence b can be obtained...
The first line contains three integers n, m and p (1 ≤ n, m ≤ 2·105, 1 ≤ p ≤ 2·105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). The next line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 109).
In the first line print the number of valid qs. In the second line, print the valid values in the increasing order.
null
null
[{"input": "5 3 1\n1 2 3 2 1\n1 2 3", "output": "2\n1 3"}, {"input": "6 3 2\n1 3 2 2 3 1\n1 2 3", "output": "2\n1 2"}]
1,900
["binary search", "data structures"]
45
[{"input": "5 3 1\r\n1 2 3 2 1\r\n1 2 3\r\n", "output": "2\r\n1 3\r\n"}, {"input": "6 3 2\r\n1 3 2 2 3 1\r\n1 2 3\r\n", "output": "2\r\n1 2\r\n"}, {"input": "68 16 3\r\n5 3 4 3 3 3 2 2 2 3 2 4 2 2 2 2 4 3 5 1 1 2 2 2 3 1 5 1 2 2 1 5 1 5 3 2 3 5 2 1 1 4 2 3 4 3 4 3 3 1 3 4 1 5 2 5 3 4 4 1 4 5 5 1 1 2 2 2\r\n5 4 4 3 5 1 ...
false
stdio
null
true
270/A
270
A
Python 3
TESTS
2
60
0
149414735
t = int(input()) works = [60,90,108,120,135,140,144,150,156,160,165,168,170,171,172,174,175,176,177,178,179] for i in range(t): angle = int(input()) if angle in works: print("YES") else: print("NO")
3
30
0
176961603
iter = int(input()) for i in range(iter): a = int(input()) if (360 % (180 - a) == 0): print("YES\n") else: print("NO\n")
Codeforces Round 165 (Div. 2)
CF
2,013
2
256
Fancy Fence
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a. Will the robot be able to build the fence Emuskald...
The first line of input contains an integer t (0 < t < 180) — the number of tests. Each of the following t lines contains a single integer a (0 < a < 180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
null
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle $$30^\circ$$. In the second test case, the fence is a regular triangle, and in the last test case — a square.
[{"input": "3\n30\n60\n90", "output": "NO\nYES\nYES"}]
1,100
["geometry", "implementation", "math"]
3
[{"input": "3\r\n30\r\n60\r\n90\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n170\r\n179\r\n25\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\nYES\r\nNO\r\n"}]
false
stdio
null
true
270/A
270
A
Python 3
TESTS
2
62
0
228567216
x = int(input()) for _ in range(x): a = int(input()) if 59 < a < 180: print("YES") else: print("NO")
3
30
0
206103584
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) ############ ---- Input Func...
Codeforces Round 165 (Div. 2)
CF
2,013
2
256
Fancy Fence
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a. Will the robot be able to build the fence Emuskald...
The first line of input contains an integer t (0 < t < 180) — the number of tests. Each of the following t lines contains a single integer a (0 < a < 180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
null
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle $$30^\circ$$. In the second test case, the fence is a regular triangle, and in the last test case — a square.
[{"input": "3\n30\n60\n90", "output": "NO\nYES\nYES"}]
1,100
["geometry", "implementation", "math"]
3
[{"input": "3\r\n30\r\n60\r\n90\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n170\r\n179\r\n25\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\nYES\r\nNO\r\n"}]
false
stdio
null
true
270/A
270
A
Python 3
TESTS
2
62
0
227569325
t=int(input()) for _ in range(t): s=int(input()) i=3 flag=0 while 1: tmp=(i-2)*180//i i+=1 if s==tmp: print("YES");flag=1;break if tmp>s: break if not flag: print("NO")
3
30
0
223965776
t=int(input()) output=[] for _ in range(t): a=int(input()) line=3 while True: if (180-a)*line==360: output.append("YES") break else: line+=1 if (180-a)*line>360: output.append("NO") break [print(i) for i in output]
Codeforces Round 165 (Div. 2)
CF
2,013
2
256
Fancy Fence
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a. Will the robot be able to build the fence Emuskald...
The first line of input contains an integer t (0 < t < 180) — the number of tests. Each of the following t lines contains a single integer a (0 < a < 180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
null
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle $$30^\circ$$. In the second test case, the fence is a regular triangle, and in the last test case — a square.
[{"input": "3\n30\n60\n90", "output": "NO\nYES\nYES"}]
1,100
["geometry", "implementation", "math"]
3
[{"input": "3\r\n30\r\n60\r\n90\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n170\r\n179\r\n25\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\nYES\r\nNO\r\n"}]
false
stdio
null
true
270/A
270
A
Python 3
TESTS
2
60
0
144931394
for i in range(int(input())): n = int(input()) t= 0 i=3 while t<n: t = int(((i-2)*180)/i) i+=1 if t>n: print('NO') else: print('YES')
3
30
0
227500778
t=int(input()) for i in range(t): a=int(input()) b=360/(180-a) if b%1==0 and b>=3: print('YES') else: print('NO')
Codeforces Round 165 (Div. 2)
CF
2,013
2
256
Fancy Fence
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a. Will the robot be able to build the fence Emuskald...
The first line of input contains an integer t (0 < t < 180) — the number of tests. Each of the following t lines contains a single integer a (0 < a < 180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
null
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle $$30^\circ$$. In the second test case, the fence is a regular triangle, and in the last test case — a square.
[{"input": "3\n30\n60\n90", "output": "NO\nYES\nYES"}]
1,100
["geometry", "implementation", "math"]
3
[{"input": "3\r\n30\r\n60\r\n90\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n170\r\n179\r\n25\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\nYES\r\nNO\r\n"}]
false
stdio
null
true
126/D
126
D
PyPy 3
TESTS
2
155
0
92453952
import sys,bisect as bi input = sys.stdin.readline I = lambda : list(map(int,input().split())) #Fibonacci Sums n,=I() fi=[1,2] an=[1,1] for i in range(82): fi.append(fi[-1]+fi[-2]) cr=2 for i in range(82): an.append(cr) if i%2: cr+=1 #print(fi[:20]) for _ in range(n): x,=I() te=x cr=82;ar=[] ans=1;pr=0 while ...
55
218
12,288,000
185884877
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline t = int(input()) ans = [] f = [1, 2] inf = pow(10, 18) + 1 while f[-1] + f[-2] < inf: f.append(f[-1] + f[-2]) l = len(f) for _ in range(t): n = int(input()) x = [] for i in range(l - 1, -1, -1): if n >= f[i]: ...
Codeforces Beta Round 93 (Div. 1 Only)
CF
2,011
1
256
Fibonacci Sums
Fibonacci numbers have the following form: F1 = 1, F2 = 2, Fi = Fi - 1 + Fi - 2, i > 2. Let's consider some non-empty set S = {s1, s2, ..., sk}, consisting of different Fibonacci numbers. Let's find the sum of values of this set's elements: $$\sum_{i=1}^{k}s_{i}=n$$ Let's call the set S a number n's decomposition...
The first line contains an integer t — the number of tests (1 ≤ t ≤ 105). Each of the following t lines contains one test. Each test is an integer n (1 ≤ n ≤ 1018). Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
For each input data test print a single number on a single line — the answer to the problem.
null
Two decompositions are different if there exists a number that is contained in the first decomposition, but is not contained in the second one. Decompositions that differ only in the order of summands are considered equal.
[{"input": "2\n13\n16", "output": "3\n4"}]
2,300
["dp", "math"]
56
[{"input": "2\r\n13\r\n16\r\n", "output": "3\r\n4\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n", "output": "1\r\n1\r\n2\r\n1\r\n2\r\n2\r\n1\r\n3\r\n2\r\n2\r\n"}, {"input": "10\r\n24\r\n37\r\n42\r\n58\r\n60\r\n73\r\n79\r\n84\r\n92\r\n99\r\n", "output": "5\r\n6\r\n6\r\n7\r\n6\r\n6\r\n8\r\n7...
false
stdio
null
true
270/A
270
A
Python 3
TESTS
2
60
0
130251087
# -*- coding: utf-8 -*- """ Created on Wed Sep 29 17:44:39 2021 @author: Boush """ output = [] t = int(input()) for i in range(t): a = int(input()) n = 3 while 1: q = int(180*(n-2)/n) if a == q : output.append("YES");break elif a > q : n += 1 else : output.append("NO");bre...
3
30
0
227569211
'''程文奇 2100015898''' def fence(a): if 360%(180-a)==0: return 'YES' else: return 'NO' n=int(input()) answerlist=[] for i in range(n): answerlist.append(fence(int(input()))) for j in answerlist: print(j)
Codeforces Round 165 (Div. 2)
CF
2,013
2
256
Fancy Fence
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a. Will the robot be able to build the fence Emuskald...
The first line of input contains an integer t (0 < t < 180) — the number of tests. Each of the following t lines contains a single integer a (0 < a < 180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
null
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle $$30^\circ$$. In the second test case, the fence is a regular triangle, and in the last test case — a square.
[{"input": "3\n30\n60\n90", "output": "NO\nYES\nYES"}]
1,100
["geometry", "implementation", "math"]
3
[{"input": "3\r\n30\r\n60\r\n90\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n170\r\n179\r\n25\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\nYES\r\nNO\r\n"}]
false
stdio
null
true
652/F
652
F
Python 3
TESTS
1
46
0
114146139
n, m, t = map(int, input().split()) saida = [] for i in range(n): entrada = input().split() p, d = entrada p = int(p) if d == 'R': saida.append((p + t) % m) else: saida.append((p - t) % m) print(" ".join([str(x) for x in saida]))
30
1,372
46,284,800
144096677
I = lambda: [int(i) for i in input().split()] import sys input = sys.stdin.readline n, L, T = I() a, b, ans, cnt = [0]*n, [0]*n, [0]*n, 0 for i in range(n): x, ch = input().split() a[i] = int(x) - 1 b[i] = (a[i], i) dr = 1 if ch == "R" else -1 w, u = divmod(a[i] + T * dr, L) a[i],...
Educational Codeforces Round 10
ICPC
2,016
2
256
Ants on a Circle
n ants are on a circle of length m. An ant travels one unit of distance per one unit of time. Initially, the ant number i is located at the position si and is facing in the direction di (which is either L or R). Positions are numbered in counterclockwise order starting from some point. Positions of the all ants are dis...
The first line contains three integers n, m and t (2 ≤ n ≤ 3·105, 2 ≤ m ≤ 109, 0 ≤ t ≤ 1018) — the number of ants, the length of the circle and the number of time units. Each of the next n lines contains integer si and symbol di (1 ≤ si ≤ m and di is either L or R) — the position and the direction of the i-th ant at t...
Print n integers xj — the position of the j-th ant after t units of time. The ants are numbered from 1 to n in order of their appearing in input.
null
null
[{"input": "2 4 8\n1 R\n3 L", "output": "1 3"}, {"input": "4 8 6\n6 R\n5 L\n1 R\n8 L", "output": "7 4 2 7"}, {"input": "4 8 2\n1 R\n5 L\n6 L\n8 R", "output": "3 3 4 2"}]
2,800
["constructive algorithms", "math"]
30
[{"input": "2 4 8\r\n1 R\r\n3 L\r\n", "output": "1 3\r\n"}, {"input": "4 8 6\r\n6 R\r\n5 L\r\n1 R\r\n8 L\r\n", "output": "7 4 2 7\r\n"}, {"input": "4 8 2\r\n1 R\r\n5 L\r\n6 L\r\n8 R\r\n", "output": "3 3 4 2\r\n"}, {"input": "10 10 90\r\n2 R\r\n1 R\r\n3 L\r\n4 R\r\n7 L\r\n8 L\r\n6 R\r\n9 R\r\n5 R\r\n10 L\r\n", "output":...
false
stdio
null
true
270/A
270
A
Python 3
TESTS
2
60
0
221950002
A=[60,90,108,120,135,140,144,150,156,160,165] for x in range(1,12): if 360%x==0: A.append(180-x) for _ in range(int(input())): if int(input()) in A: print("YES") else: print("NO")
3
60
0
20656108
n = int(input()) for i in range(n): t = int(input()) if 360%(180-t)==0: print('YES') else: print('NO')
Codeforces Round 165 (Div. 2)
CF
2,013
2
256
Fancy Fence
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a. Will the robot be able to build the fence Emuskald...
The first line of input contains an integer t (0 < t < 180) — the number of tests. Each of the following t lines contains a single integer a (0 < a < 180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
null
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle $$30^\circ$$. In the second test case, the fence is a regular triangle, and in the last test case — a square.
[{"input": "3\n30\n60\n90", "output": "NO\nYES\nYES"}]
1,100
["geometry", "implementation", "math"]
3
[{"input": "3\r\n30\r\n60\r\n90\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "6\r\n1\r\n2\r\n3\r\n170\r\n179\r\n25\r\n", "output": "NO\r\nNO\r\nNO\r\nYES\r\nYES\r\nNO\r\n"}]
false
stdio
null
true
1212/D
977
D
PyPy 3-64
TESTS
0
31
0
227965961
n = int(input()) a = list(map(int, input().split())) start = max(a, key=lambda x: (-x, sum(1 for i in range(60) if x % (3**i) == 0))) ans = [start] a.remove(start) while len(ans) < n: next_value = ans[-1] // 3 if ans[-1] % 3 == 0 else ans[-1] * 2 if next_value in a: ans.append(next_value) a.re...
26
62
0
225011252
import sys # sys.setrecursionlimit(10**8)设置最大递归次数 class FastIO: def __init__(self): return @staticmethod def read_int(): return int(sys.stdin.readline().strip()) @staticmethod def read_list_ints(): return list(map(int, sys.stdin.readline().strip().split())) @static...
Kotlin Heroes: Practice 2
ICPC
2,019
1
256
Divide by three, multiply by two
Polycarp likes to play with numbers. He takes some integer number $$$x$$$, writes it down on the board, and then performs with it $$$n - 1$$$ operations of the two kinds: - divide the number $$$x$$$ by $$$3$$$ ($$$x$$$ must be divisible by $$$3$$$); - multiply the number $$$x$$$ by $$$2$$$. After each operation, Poly...
The first line of the input contatins an integer number $$$n$$$ ($$$2 \le n \le 100$$$) — the number of the elements in the sequence. The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 3 \cdot 10^{18}$$$) — rearranged (reordered) sequence that Polycarp can wrote d...
Print $$$n$$$ integer numbers — rearranged (reordered) input sequence that can be the sequence that Polycarp could write down on the board. It is guaranteed that the answer exists.
null
In the first example the given sequence can be rearranged in the following way: $$$[9, 3, 6, 12, 4, 8]$$$. It can match possible Polycarp's game which started with $$$x = 9$$$.
[{"input": "6\n4 8 6 3 12 9", "output": "9 3 6 12 4 8"}, {"input": "4\n42 28 84 126", "output": "126 42 84 28"}, {"input": "2\n1000000000000000000 3000000000000000000", "output": "3000000000000000000 1000000000000000000"}]
1,400
["*special", "math"]
26
[{"input": "6\r\n4 8 6 3 12 9\r\n", "output": "9 3 6 12 4 8 \r\n"}, {"input": "4\r\n42 28 84 126\r\n", "output": "126 42 84 28 \r\n"}, {"input": "2\r\n1000000000000000000 3000000000000000000\r\n", "output": "3000000000000000000 1000000000000000000 \r\n"}, {"input": "19\r\n46875000000000000 732421875000000 5859375000000...
false
stdio
null
true
958/B1
958
B1
Python 3
TESTS
2
124
0
77721340
t = int(input()) first = [] sec = [] for i in range(0, t-1): u, v = map(int, input().split()) first.append(u) sec.append(v) first = list(dict.fromkeys(first)) sec = list(dict.fromkeys(sec)) count = 0 for i in sec: if i not in first: count += 1 else: continue print(count)
9
31
0
194344376
N = int(input()) planets = [] ans = 0 for i in range(N - 1): tunnel = [int(x) for x in input().split()] planets.append(tunnel[0]) planets.append(tunnel[1]) planets.sort() for i in range(len(planets)): if i == 0: if planets[i] != planets[i + 1]: ans += 1 elif i == len(planets) - 1: if planets[i]...
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
2
256
Maximum Control (easy)
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect s...
The first line of the input contains an integer N (2 ≤ N ≤ 1000) – the number of planets in the galaxy. The next N - 1 lines describe the hyperspace tunnels between the planets. Each of the N - 1 lines contains two space-separated integers u and v (1 ≤ u, v ≤ N) indicating that there is a bidirectional hyperspace tunn...
A single integer denoting the number of remote planets.
null
In the first example, only planets 2, 3 and 5 are connected by a single tunnel. In the second example, the remote planets are 2 and 3. Note that this problem has only two versions – easy and medium.
[{"input": "5\n4 1\n4 2\n1 3\n1 5", "output": "3"}, {"input": "4\n1 2\n4 3\n1 4", "output": "2"}]
1,000
["implementation"]
9
[{"input": "5\r\n4 1\r\n4 2\r\n1 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2\r\n4 3\r\n1 4\r\n", "output": "2\r\n"}, {"input": "10\r\n4 3\r\n2 6\r\n10 1\r\n5 7\r\n5 8\r\n10 6\r\n5 9\r\n9 3\r\n2 9\r\n", "output": "4\r\n"}]
false
stdio
null
true
958/A2
958
A2
Python 3
TESTS
1
124
8,192,000
37316715
N, M = input().split(' ') N = int(N) M = int(M) matrix_1 = [] matrix_2 = [] for i in range(N): matrix_1.append(input()) for i in range(M): matrix_2.append(input()) def find(word): if word in matrix_2[0]: return matrix_2[0].index(word) return False def go(): for i in range(N): x =...
28
1,278
43,929,600
38869030
n,m=list(map(int,input().split())) s=[] h=[] mod=10**9 mod+=7 for i in range(n): s=(input()) s=s.lower() hw=0 for i in range(m): hw+=ord(s[i])*(10**(m-i)) h.append(hw%mod) h1=[[] for i in range(n-m+1)] for i in range(m): hw=0 s=input() s=s.lower() aux=[] for i in range(m)...
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
2.5
256
Death Stars (medium)
The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the so...
The first line of the input contains two space-separated integers N and M (1 ≤ N ≤ 2000, 1 ≤ M ≤ 200, M ≤ N). The next N lines each contain M lower-case Latin characters (a-z), denoting the first map. Different characters correspond to different cosmic object types. The next M lines each contain N characters, describin...
The only line of the output should contain two space-separated integers i and j, denoting that the section of size M × M in the first map that starts at the i-th row is equal to the section of the second map that starts at the j-th column. Rows and columns are numbered starting from 1. If there are several possible wa...
null
The 5-by-5 grid for the first test case looks like this:
[{"input": "10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo", "output": "4 6"}]
2,000
["hashing", "strings"]
28
[{"input": "10 5\r\nsomer\r\nandom\r\nnoise\r\nmayth\r\neforc\r\nebewi\r\nthyou\r\nhctwo\r\nagain\r\nnoise\r\nsomermayth\r\nandomeforc\r\nnoiseebewi\r\nagainthyou\r\nnoisehctwo\r\n", "output": "4 6\r\n"}, {"input": "1 1\r\ng\r\ng\r\n", "output": "1 1\r\n"}]
false
stdio
null
true
690/D1
690
D1
PyPy 3
TESTS
1
93
23,040,000
32975171
from sys import * print((stdin.readlines()[-1] + '.').count('B.'))
119
62
0
19000257
import sys, math n,m = map(int,input().split()) for i in range(n-1): input() w=input() w+='.' ans = 0 now=1 for i in w: if i == 'B': if now: now = 0 ans+=1 else: continue else: now = 1 print(ans)
Helvetic Coding Contest 2016 online mirror (teams, unrated)
ICPC
2,016
0.5
256
The Wall (easy)
"The zombies are lurking outside. Waiting. Moaning. And when they come..." "When they come?" "I hope the Wall is high enough." Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segment...
The first line of the input consists of two space-separated integers R and C, 1 ≤ R, C ≤ 100. The next R lines provide a description of the columns as follows: - each of the R lines contains a string of length C, - the c-th character of line r is B if there is a brick in column c and row R - r + 1, and . otherwise.
The number of wall segments in the input configuration.
null
In the first sample case, the 2nd and 3rd columns define the first wall segment, and the 5th column defines the second.
[{"input": "3 7\n.......\n.......\n.BB.B..", "output": "2"}, {"input": "4 5\n..B..\n..B..\nB.B.B\nBBB.B", "output": "2"}, {"input": "4 6\n..B...\nB.B.BB\nBBB.BB\nBBBBBB", "output": "1"}, {"input": "1 1\nB", "output": "1"}, {"input": "10 7\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n...B...\...
1,200
[]
119
[{"input": "3 7\r\n.......\r\n.......\r\n.BB.B..\r\n", "output": "2\r\n"}, {"input": "4 5\r\n..B..\r\n..B..\r\nB.B.B\r\nBBB.B\r\n", "output": "2\r\n"}, {"input": "4 6\r\n..B...\r\nB.B.BB\r\nBBB.BB\r\nBBBBBB\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "1\r\n"}, {"input": "10 7\r\n.......\r\n.......\r\n...
false
stdio
null
true
958/A2
958
A2
Python 3
TESTS
5
624
27,545,600
37322117
n,m=map(int,input().strip().split(' ')) Dicti={} M=[] DP=[] for i in range(m): DP.append([[0]]*n) for i in range(n): s=input() if s in Dicti: Dicti[s].append(i+1) else: Dicti[s]=[i+1] for i in range(m): M.append(input()) for i in range(m): j=0 while j+m<=n : a=M[i][j:j+m] if a ...
28
1,481
10,956,800
37327090
n, m = list(map(int, input().strip().split(' '))) mat1, mat2 = [], [] for i in range(0, n): mat1.append(tuple(input().strip())) for i in range(0, m): mat2.append(tuple(input().strip())) ix, jx, flg = -1, -1, 0 matr, matc = [], [] for i in range(0, n-m+1): si, se = i, i+m matr.append(hash(tuple(mat1[si:se]))) matcur2...
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
2.5
256
Death Stars (medium)
The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the so...
The first line of the input contains two space-separated integers N and M (1 ≤ N ≤ 2000, 1 ≤ M ≤ 200, M ≤ N). The next N lines each contain M lower-case Latin characters (a-z), denoting the first map. Different characters correspond to different cosmic object types. The next M lines each contain N characters, describin...
The only line of the output should contain two space-separated integers i and j, denoting that the section of size M × M in the first map that starts at the i-th row is equal to the section of the second map that starts at the j-th column. Rows and columns are numbered starting from 1. If there are several possible wa...
null
The 5-by-5 grid for the first test case looks like this:
[{"input": "10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo", "output": "4 6"}]
2,000
["hashing", "strings"]
28
[{"input": "10 5\r\nsomer\r\nandom\r\nnoise\r\nmayth\r\neforc\r\nebewi\r\nthyou\r\nhctwo\r\nagain\r\nnoise\r\nsomermayth\r\nandomeforc\r\nnoiseebewi\r\nagainthyou\r\nnoisehctwo\r\n", "output": "4 6\r\n"}, {"input": "1 1\r\ng\r\ng\r\n", "output": "1 1\r\n"}]
false
stdio
null
true
958/B1
958
B1
Python 3
TESTS
2
77
7,168,000
37323384
import sys from collections import Counter def main(args): n = int(input()) counter = Counter() for _ in range(n - 1): u, v = map(int, input().split()) counter[u] += 1 counter[v] += 1 print(counter[1]) if __name__ == '__main__': sys.exit(main(sys.argv))
9
31
0
215291281
N = int(input()) a = [0] * N for _ in range(N-1): u, v = list(map(int, input().split())) a[u-1] += 1 a[v-1] += 1 print(a.count(1))
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
2
256
Maximum Control (easy)
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect s...
The first line of the input contains an integer N (2 ≤ N ≤ 1000) – the number of planets in the galaxy. The next N - 1 lines describe the hyperspace tunnels between the planets. Each of the N - 1 lines contains two space-separated integers u and v (1 ≤ u, v ≤ N) indicating that there is a bidirectional hyperspace tunn...
A single integer denoting the number of remote planets.
null
In the first example, only planets 2, 3 and 5 are connected by a single tunnel. In the second example, the remote planets are 2 and 3. Note that this problem has only two versions – easy and medium.
[{"input": "5\n4 1\n4 2\n1 3\n1 5", "output": "3"}, {"input": "4\n1 2\n4 3\n1 4", "output": "2"}]
1,000
["implementation"]
9
[{"input": "5\r\n4 1\r\n4 2\r\n1 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2\r\n4 3\r\n1 4\r\n", "output": "2\r\n"}, {"input": "10\r\n4 3\r\n2 6\r\n10 1\r\n5 7\r\n5 8\r\n10 6\r\n5 9\r\n9 3\r\n2 9\r\n", "output": "4\r\n"}]
false
stdio
null
true
958/B1
958
B1
PyPy 3
TESTS
2
109
20,172,800
90813432
#author : SanskarxRawat n=int(input()) s=set() for i in range(n-1): u,v=map(int,input().strip().split()) s.add(u) print(n-len(s))
9
46
0
135895593
def solve(l1,l2): ans = 0 M = {} for i in range(len(l1)): if l1[i] in M: M[l1[i]] += 1 else: M[l1[i]] = 1 for i in range(len(l2)): if l2[i] in M: M[l2[i]] += 1 else: M[l2[i]] = 1 for i in M: if M[i] < 2: ...
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
2
256
Maximum Control (easy)
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect s...
The first line of the input contains an integer N (2 ≤ N ≤ 1000) – the number of planets in the galaxy. The next N - 1 lines describe the hyperspace tunnels between the planets. Each of the N - 1 lines contains two space-separated integers u and v (1 ≤ u, v ≤ N) indicating that there is a bidirectional hyperspace tunn...
A single integer denoting the number of remote planets.
null
In the first example, only planets 2, 3 and 5 are connected by a single tunnel. In the second example, the remote planets are 2 and 3. Note that this problem has only two versions – easy and medium.
[{"input": "5\n4 1\n4 2\n1 3\n1 5", "output": "3"}, {"input": "4\n1 2\n4 3\n1 4", "output": "2"}]
1,000
["implementation"]
9
[{"input": "5\r\n4 1\r\n4 2\r\n1 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2\r\n4 3\r\n1 4\r\n", "output": "2\r\n"}, {"input": "10\r\n4 3\r\n2 6\r\n10 1\r\n5 7\r\n5 8\r\n10 6\r\n5 9\r\n9 3\r\n2 9\r\n", "output": "4\r\n"}]
false
stdio
null
true
958/A2
958
A2
Python 3
TESTS
5
545
9,932,800
37318146
n,m=map(int,input().strip().split(' ')) Dicti={} M=[] DP=[] for i in range(m): DP.append([0]*n) for i in range(n): Dicti[input()]=i+1 for i in range(m): M.append(input()) for i in range(m): j=0 k=0 while j!=n: a=M[i][j:j+m] if a in Dicti: DP[i][j]=Dicti[a] else : DP[i][j]=0 ...
28
1,715
83,558,400
37339782
n, m = list(map(int, input().strip().split(' '))) L, M = [], [] for i in range(n): L.append(tuple(input().strip())) for i in range(0, m): M.append(tuple(input().strip())) k=0 row, col = [], [] for i in range(n-m+1): init, end = i, i+m row.append(hash(tuple(L[init:end]))) D = [] for j in range(0, m): D.ap...
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
2.5
256
Death Stars (medium)
The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the so...
The first line of the input contains two space-separated integers N and M (1 ≤ N ≤ 2000, 1 ≤ M ≤ 200, M ≤ N). The next N lines each contain M lower-case Latin characters (a-z), denoting the first map. Different characters correspond to different cosmic object types. The next M lines each contain N characters, describin...
The only line of the output should contain two space-separated integers i and j, denoting that the section of size M × M in the first map that starts at the i-th row is equal to the section of the second map that starts at the j-th column. Rows and columns are numbered starting from 1. If there are several possible wa...
null
The 5-by-5 grid for the first test case looks like this:
[{"input": "10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo", "output": "4 6"}]
2,000
["hashing", "strings"]
28
[{"input": "10 5\r\nsomer\r\nandom\r\nnoise\r\nmayth\r\neforc\r\nebewi\r\nthyou\r\nhctwo\r\nagain\r\nnoise\r\nsomermayth\r\nandomeforc\r\nnoiseebewi\r\nagainthyou\r\nnoisehctwo\r\n", "output": "4 6\r\n"}, {"input": "1 1\r\ng\r\ng\r\n", "output": "1 1\r\n"}]
false
stdio
null
true
958/B1
958
B1
PyPy 3
TESTS
2
77
0
108081635
def dfs(edges,source,path = [],count = 0): if source not in path: path.append(source) if(source not in edges): return [path,count+1] for n in edges[source]: path,count = dfs(edges,n,path,count) return [path,count] n = int(input()) edges = {} root =[] for i in rang...
9
46
0
136744943
n=int(input()) a=[0]*(n+1) for i in range(n-1): u,v=map(int,input().split()) a[u]+=1 a[v]+=1 cnt=0 for i in range(1,n+1): if a[i]==1: cnt+=1 print(cnt)
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
2
256
Maximum Control (easy)
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect s...
The first line of the input contains an integer N (2 ≤ N ≤ 1000) – the number of planets in the galaxy. The next N - 1 lines describe the hyperspace tunnels between the planets. Each of the N - 1 lines contains two space-separated integers u and v (1 ≤ u, v ≤ N) indicating that there is a bidirectional hyperspace tunn...
A single integer denoting the number of remote planets.
null
In the first example, only planets 2, 3 and 5 are connected by a single tunnel. In the second example, the remote planets are 2 and 3. Note that this problem has only two versions – easy and medium.
[{"input": "5\n4 1\n4 2\n1 3\n1 5", "output": "3"}, {"input": "4\n1 2\n4 3\n1 4", "output": "2"}]
1,000
["implementation"]
9
[{"input": "5\r\n4 1\r\n4 2\r\n1 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2\r\n4 3\r\n1 4\r\n", "output": "2\r\n"}, {"input": "10\r\n4 3\r\n2 6\r\n10 1\r\n5 7\r\n5 8\r\n10 6\r\n5 9\r\n9 3\r\n2 9\r\n", "output": "4\r\n"}]
false
stdio
null
true
958/B1
958
B1
Python 3
TESTS
2
46
0
105234619
resole = [] result = 0 for i in range(int(input()) - 1): resole.extend(list(map(lambda x: int(x), input().split(' ')))) resole.sort() _temp = 0 for i in range(0, len(resole)): if not resole[i] == _temp: result += 1 _temp = resole[i] print(len(resole) - result)
9
46
0
156078340
import sys input = sys.stdin.readline n = int(input()) d = [0]*n for _ in range(n-1): a, b = map(int, input().split()) d[a-1] += 1 d[b-1] += 1 c = 0 for i in d: if i < 2: c += 1 print(c)
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
2
256
Maximum Control (easy)
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect s...
The first line of the input contains an integer N (2 ≤ N ≤ 1000) – the number of planets in the galaxy. The next N - 1 lines describe the hyperspace tunnels between the planets. Each of the N - 1 lines contains two space-separated integers u and v (1 ≤ u, v ≤ N) indicating that there is a bidirectional hyperspace tunn...
A single integer denoting the number of remote planets.
null
In the first example, only planets 2, 3 and 5 are connected by a single tunnel. In the second example, the remote planets are 2 and 3. Note that this problem has only two versions – easy and medium.
[{"input": "5\n4 1\n4 2\n1 3\n1 5", "output": "3"}, {"input": "4\n1 2\n4 3\n1 4", "output": "2"}]
1,000
["implementation"]
9
[{"input": "5\r\n4 1\r\n4 2\r\n1 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2\r\n4 3\r\n1 4\r\n", "output": "2\r\n"}, {"input": "10\r\n4 3\r\n2 6\r\n10 1\r\n5 7\r\n5 8\r\n10 6\r\n5 9\r\n9 3\r\n2 9\r\n", "output": "4\r\n"}]
false
stdio
null
true
958/B1
958
B1
PyPy 3
TESTS
2
77
0
109409974
n = int(input()) a = 0 p = {x: 0 for x in range(1, n+1)} for _ in range(n-1): u, v = map(int, input().split()) p[u] += 1 p[v] += 1 if p[u] > 1: a += 1 if p[v] > 1: a += 1 print(a)
9
46
0
166115802
n = int(input()) li = list([[0]*n]) li = li[0] count = n for i in range(n-1): a, b = map(int, input().split()) if li[a-1] == 0: li[a-1] = b elif li[a-1] == -1: li[a-1] = li[a-1] else: count -= 1 li[a-1] = -1 if li[b-1] == 0: li[b-1] = a elif li[b-1] == -...
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
2
256
Maximum Control (easy)
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect s...
The first line of the input contains an integer N (2 ≤ N ≤ 1000) – the number of planets in the galaxy. The next N - 1 lines describe the hyperspace tunnels between the planets. Each of the N - 1 lines contains two space-separated integers u and v (1 ≤ u, v ≤ N) indicating that there is a bidirectional hyperspace tunn...
A single integer denoting the number of remote planets.
null
In the first example, only planets 2, 3 and 5 are connected by a single tunnel. In the second example, the remote planets are 2 and 3. Note that this problem has only two versions – easy and medium.
[{"input": "5\n4 1\n4 2\n1 3\n1 5", "output": "3"}, {"input": "4\n1 2\n4 3\n1 4", "output": "2"}]
1,000
["implementation"]
9
[{"input": "5\r\n4 1\r\n4 2\r\n1 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2\r\n4 3\r\n1 4\r\n", "output": "2\r\n"}, {"input": "10\r\n4 3\r\n2 6\r\n10 1\r\n5 7\r\n5 8\r\n10 6\r\n5 9\r\n9 3\r\n2 9\r\n", "output": "4\r\n"}]
false
stdio
null
true
958/B1
958
B1
Python 3
TESTS
2
31
0
208281795
res = [] t = int(input()) for _ in range(t-1): a,b = list(map(int,input().split())) res.append(a) res.append(b) dc = {} fd = [] for i in res: dc.update({i:res.count(i)}) fd.append(res.count(i)) mx = max(fd) ans = 0 for k,v in dc.items(): if v==mx: ans=v print(ans) # print(dc)
9
46
0
172245267
n=int(input()) l=[0]*(n) for _ in range(n-1): a,b=list(map(int,input().split())) l[a-1]+=1 l[b-1]+=1 print(l.count(1))
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
2
256
Maximum Control (easy)
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect s...
The first line of the input contains an integer N (2 ≤ N ≤ 1000) – the number of planets in the galaxy. The next N - 1 lines describe the hyperspace tunnels between the planets. Each of the N - 1 lines contains two space-separated integers u and v (1 ≤ u, v ≤ N) indicating that there is a bidirectional hyperspace tunn...
A single integer denoting the number of remote planets.
null
In the first example, only planets 2, 3 and 5 are connected by a single tunnel. In the second example, the remote planets are 2 and 3. Note that this problem has only two versions – easy and medium.
[{"input": "5\n4 1\n4 2\n1 3\n1 5", "output": "3"}, {"input": "4\n1 2\n4 3\n1 4", "output": "2"}]
1,000
["implementation"]
9
[{"input": "5\r\n4 1\r\n4 2\r\n1 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2\r\n4 3\r\n1 4\r\n", "output": "2\r\n"}, {"input": "10\r\n4 3\r\n2 6\r\n10 1\r\n5 7\r\n5 8\r\n10 6\r\n5 9\r\n9 3\r\n2 9\r\n", "output": "4\r\n"}]
false
stdio
null
true
958/B1
958
B1
Python 3
TESTS
2
46
0
120642713
n=int(input()) f=[0 for i in range(n+1)] for i in range(n-1): x,y=map(int,input().split()) f[x]+=1 f[y]+=1 print(max(f))
9
46
0
179980889
""" https://codeforces.com/problemset/problem/958/B1 """ planets = int(input()) links = dict() for _ in range(planets - 1): a, b = [x for x in input().split()] links.setdefault(a, []).append(b) links.setdefault(b, []).append(a) compte=0 for v in links.values(): if len(v)==1: compte+=1 print(comp...
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
2
256
Maximum Control (easy)
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect s...
The first line of the input contains an integer N (2 ≤ N ≤ 1000) – the number of planets in the galaxy. The next N - 1 lines describe the hyperspace tunnels between the planets. Each of the N - 1 lines contains two space-separated integers u and v (1 ≤ u, v ≤ N) indicating that there is a bidirectional hyperspace tunn...
A single integer denoting the number of remote planets.
null
In the first example, only planets 2, 3 and 5 are connected by a single tunnel. In the second example, the remote planets are 2 and 3. Note that this problem has only two versions – easy and medium.
[{"input": "5\n4 1\n4 2\n1 3\n1 5", "output": "3"}, {"input": "4\n1 2\n4 3\n1 4", "output": "2"}]
1,000
["implementation"]
9
[{"input": "5\r\n4 1\r\n4 2\r\n1 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2\r\n4 3\r\n1 4\r\n", "output": "2\r\n"}, {"input": "10\r\n4 3\r\n2 6\r\n10 1\r\n5 7\r\n5 8\r\n10 6\r\n5 9\r\n9 3\r\n2 9\r\n", "output": "4\r\n"}]
false
stdio
null
true
127/A
127
A
Python 3
TESTS
1
92
0
113590925
import math t,l=0,[] n,p=map(int,input().split(' ')) for i in range(n): x,y=map(int,input().split(' ')) l.append(math.sqrt(x**2 + y**2)) for i in range(1,n): t+=abs(l[i]-l[i-1]) print((t/50)*p)
42
62
0
210675325
import math n, k = map(int, input().split()) # Read the values of n and k points = [] for _ in range(n): x, y = map(int, input().split()) # Read the coordinates of each point points.append((x, y)) total_distance = 0 for i in range(n - 1): x1, y1 = points[i] x2, y2 = points[i + 1] distance = mat...
Codeforces Beta Round 93 (Div. 2 Only)
CF
2,011
2
256
Wasted Time
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline ...
The first line contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai — integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates ...
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
null
null
[{"input": "2 1\n0 0\n10 0", "output": "0.200000000"}, {"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "output": "6.032163204"}, {"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0", "output": "3.000000000"}]
900
["geometry"]
42
[{"input": "2 1\r\n0 0\r\n10 0\r\n", "output": "0.200000000"}, {"input": "5 10\r\n3 1\r\n-5 6\r\n-2 -1\r\n3 2\r\n10 0\r\n", "output": "6.032163204"}, {"input": "6 10\r\n5 0\r\n4 0\r\n6 0\r\n3 0\r\n7 0\r\n2 0\r\n", "output": "3.000000000"}, {"input": "10 95\r\n-20 -5\r\n2 -8\r\n14 13\r\n10 3\r\n17 11\r\n13 -12\r\n-6 11\...
false
stdio
import sys import math def read_points(n, input_file): points = [] for _ in range(n): x, y = map(int, input_file.readline().split()) points.append((x, y)) return points def compute_total_time(n, k, points): total_length = 0.0 for i in range(1, n): x0, y0 = points[i-1] ...
true
990/F
990
F
Python 3
TESTS
0
77
0
39208122
def i_ints(): return list(map(int, input().split())) ############# n, = i_ints() s = [0] + i_ints() if sum(s): print("Impossible") else: print("Possible") m, = i_ints() es = [i_ints() for _ in range(m)] nb = [[] for i in range(n+1)] for i, (x, y) in enumerate(es): nb[x].append((y, ...
37
1,216
96,768,000
155788846
from collections import deque import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def get_root(s): v = [] while not s == root[s]: v.append(s) s = root[s] for i in v: root[i] = s return s def unite(s, t): rs, rt = get_root(s), get_root(t) if n...
Educational Codeforces Round 45 (Rated for Div. 2)
ICPC
2,018
2
256
Flow Control
You have to handle a very complex water distribution system. The system consists of $$$n$$$ junctions and $$$m$$$ pipes, $$$i$$$-th pipe connects junctions $$$x_i$$$ and $$$y_i$$$. The only thing you can do is adjusting the pipes. You have to choose $$$m$$$ integer numbers $$$f_1$$$, $$$f_2$$$, ..., $$$f_m$$$ and use ...
The first line contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of junctions. The second line contains $$$n$$$ integers $$$s_1, s_2, \dots, s_n$$$ ($$$-10^4 \le s_i \le 10^4$$$) — constraints for the junctions. The third line contains an integer $$$m$$$ ($$$0 \le m \le 2 \cdot 10^5$$$) — the ...
If you can choose such integer numbers $$$f_1, f_2, \dots, f_m$$$ in such a way that all requirements on incoming and outcoming flows are satisfied, then output "Possible" in the first line. Then output $$$m$$$ lines, $$$i$$$-th line should contain $$$f_i$$$ — the chosen setting numbers for the pipes. Pipes are numbere...
null
null
[{"input": "4\n3 -10 6 1\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "output": "Possible\n4\n-6\n8\n-7\n7"}, {"input": "4\n3 -10 6 4\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "output": "Impossible"}]
2,400
["dfs and similar", "dp", "greedy", "trees"]
37
[{"input": "4\r\n3 -10 6 1\r\n5\r\n1 2\r\n3 2\r\n2 4\r\n3 4\r\n3 1\r\n", "output": "Possible\r\n-3\r\n-6\r\n1\r\n0\r\n0\r\n"}, {"input": "4\r\n3 -10 6 4\r\n5\r\n1 2\r\n3 2\r\n2 4\r\n3 4\r\n3 1\r\n", "output": "Impossible\r\n"}, {"input": "1\r\n0\r\n0\r\n", "output": "Possible\r\n"}, {"input": "1\r\n123\r\n0\r\n", "outp...
false
stdio
import sys def main(): input_path = sys.argv[1] submission_path = sys.argv[3] with open(input_path) as f: n = int(f.readline()) s = list(map(int, f.readline().split())) m = int(f.readline()) pipes = [tuple(map(int, f.readline().split())) for _ in range(m)] sum_s = ...
true
958/B1
958
B1
Python 3
TESTS
2
30
0
208283359
res = [] t = int(input()) for _ in range(t-1): a,b = list(map(int,input().split())) res.append(a) res.append(b) print(res.count(a))
9
46
0
196616253
# from dust i have come dust i will be n=int(input()) a=[0]*(n+1) for i in range(n-1): u,v=map(int,input().split()) a[u]+=1 a[v]+=1 cnt=0 for i in range(1,n+1): if a[i]==1: cnt+=1 print(cnt)
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
2
256
Maximum Control (easy)
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect s...
The first line of the input contains an integer N (2 ≤ N ≤ 1000) – the number of planets in the galaxy. The next N - 1 lines describe the hyperspace tunnels between the planets. Each of the N - 1 lines contains two space-separated integers u and v (1 ≤ u, v ≤ N) indicating that there is a bidirectional hyperspace tunn...
A single integer denoting the number of remote planets.
null
In the first example, only planets 2, 3 and 5 are connected by a single tunnel. In the second example, the remote planets are 2 and 3. Note that this problem has only two versions – easy and medium.
[{"input": "5\n4 1\n4 2\n1 3\n1 5", "output": "3"}, {"input": "4\n1 2\n4 3\n1 4", "output": "2"}]
1,000
["implementation"]
9
[{"input": "5\r\n4 1\r\n4 2\r\n1 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2\r\n4 3\r\n1 4\r\n", "output": "2\r\n"}, {"input": "10\r\n4 3\r\n2 6\r\n10 1\r\n5 7\r\n5 8\r\n10 6\r\n5 9\r\n9 3\r\n2 9\r\n", "output": "4\r\n"}]
false
stdio
null
true
831/B
831
B
Python 3
TESTS
0
15
0
205403071
# Read input layout1 = input().strip() layout2 = input().strip() text = input().strip() # Create a dictionary to map each letter from layout1 to its corresponding letter in layout2 mapping = {} for i in range(len(layout1)): mapping[layout1[i]] = layout2[i] # Apply the mapping to each letter in the text, and keep ...
19
31
0
147198336
s=input() s1=input() d={} for i in range(26): d[s[i]]=s1[i] s2=input() r="" for i in s2: if(i.isupper()): r=r+d[i.lower()].upper() elif(i.isalpha()): r=r+d[i] else: r=r+i print(r)
Codeforces Round 424 (Div. 2, rated, based on VK Cup Finals)
CF
2,017
1
256
Keyboard Layouts
There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet. You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts i...
The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and...
Print the text if the same keys were pressed in the second layout.
null
null
[{"input": "qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "output": "HelloVKCup2017"}, {"input": "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7", "output": "7uduGUDUUDUgudu7"}]
800
["implementation", "strings"]
19
[{"input": "qwertyuiopasdfghjklzxcvbnm\r\nveamhjsgqocnrbfxdtwkylupzi\r\nTwccpQZAvb2017\r\n", "output": "HelloVKCup2017\r\n"}, {"input": "mnbvcxzlkjhgfdsapoiuytrewq\r\nasdfghjklqwertyuiopzxcvbnm\r\n7abaCABAABAcaba7\r\n", "output": "7uduGUDUUDUgudu7\r\n"}, {"input": "ayvguplhjsoiencbkxdrfwmqtz\r\nkhzvtbspcndierqumlojyagf...
false
stdio
null
true
127/A
127
A
Python 3
TESTS
1
186
6,963,200
89463256
from math import sqrt n,k=input().split(" ") n,k=int(n),int(k) x,y=-0.5,-1 a,b=-1,-1 time=0 for i in range(n): a,b=input().split(" ") a,b=int(a),int(b) if x!=-0.5: time+=sqrt((x-a)**2+(y-b)**2)/50 x,y=a,b print(time)
42
62
0
213562730
take = input().split() n = int(take[0]) k = int(take[1]) X = [] Y = [] for i in range(n) : point = input().split() X.append(int(point[0])) Y.append(int(point[1])) import math length = 0 for i in range(n-1) : dist = math.sqrt((X[i+1]-X[i])**2+(Y[i+1]-Y[i])**2) length += dist print(length*k/50)
Codeforces Beta Round 93 (Div. 2 Only)
CF
2,011
2
256
Wasted Time
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline ...
The first line contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai — integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates ...
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
null
null
[{"input": "2 1\n0 0\n10 0", "output": "0.200000000"}, {"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "output": "6.032163204"}, {"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0", "output": "3.000000000"}]
900
["geometry"]
42
[{"input": "2 1\r\n0 0\r\n10 0\r\n", "output": "0.200000000"}, {"input": "5 10\r\n3 1\r\n-5 6\r\n-2 -1\r\n3 2\r\n10 0\r\n", "output": "6.032163204"}, {"input": "6 10\r\n5 0\r\n4 0\r\n6 0\r\n3 0\r\n7 0\r\n2 0\r\n", "output": "3.000000000"}, {"input": "10 95\r\n-20 -5\r\n2 -8\r\n14 13\r\n10 3\r\n17 11\r\n13 -12\r\n-6 11\...
false
stdio
import sys import math def read_points(n, input_file): points = [] for _ in range(n): x, y = map(int, input_file.readline().split()) points.append((x, y)) return points def compute_total_time(n, k, points): total_length = 0.0 for i in range(1, n): x0, y0 = points[i-1] ...
true
127/A
127
A
Python 3
TESTS
1
186
307,200
94580553
import math n, k = [int(x) for x in input().split(' ')] points = [] t = 0 for i in range(n): points.append([int(x) for x in input().split(' ')]) for i in range(n - 1): t += math.sqrt((points[i][0] - points[i + 1][0]) ** 2 + (points[i][1] - points[i + 1][1]) ** 2) print(t / 50)
42
62
0
215806788
n, k = map(int, input().split()) x0, y0 = map(int, input().split()) a = 0 for _ in range(n-1): x1, y1 = map(int, input().split()) a += ((x1-x0)**2+(y1-y0)**2)**0.5 x0, y0 = x1, y1 print(k*a/50)
Codeforces Beta Round 93 (Div. 2 Only)
CF
2,011
2
256
Wasted Time
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline ...
The first line contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai — integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates ...
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
null
null
[{"input": "2 1\n0 0\n10 0", "output": "0.200000000"}, {"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "output": "6.032163204"}, {"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0", "output": "3.000000000"}]
900
["geometry"]
42
[{"input": "2 1\r\n0 0\r\n10 0\r\n", "output": "0.200000000"}, {"input": "5 10\r\n3 1\r\n-5 6\r\n-2 -1\r\n3 2\r\n10 0\r\n", "output": "6.032163204"}, {"input": "6 10\r\n5 0\r\n4 0\r\n6 0\r\n3 0\r\n7 0\r\n2 0\r\n", "output": "3.000000000"}, {"input": "10 95\r\n-20 -5\r\n2 -8\r\n14 13\r\n10 3\r\n17 11\r\n13 -12\r\n-6 11\...
false
stdio
import sys import math def read_points(n, input_file): points = [] for _ in range(n): x, y = map(int, input_file.readline().split()) points.append((x, y)) return points def compute_total_time(n, k, points): total_length = 0.0 for i in range(1, n): x0, y0 = points[i-1] ...
true
127/A
127
A
Python 3
TESTS
1
186
0
48373556
n, k = map(int, input().split()) coords = [] for _ in range(n): x, y = map(int, input().split()) coords.append((x, y)) px, py = coords[0] space = 0 for i in range(1, n): cx, cy = coords[i] dist = ((cx - px) * (cx - px) + (cy - py) * (cy - py)) ** 0.5 space += dist px, py = cx, cy ans = space ...
42
62
0
231468713
from math import sqrt n, k = input().split() n, k = int(n), int(k) coordinates = [] for i in range(n): coordinates += [tuple(map(int, input().split()))] total = 0 for j in range(n - 1): total += sqrt((coordinates[j][0] - coordinates[j + 1][0]) ** 2 + (coordinates[j][1] - coordinates[j + 1][1]) ** 2) print(f'{...
Codeforces Beta Round 93 (Div. 2 Only)
CF
2,011
2
256
Wasted Time
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline ...
The first line contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai — integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates ...
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
null
null
[{"input": "2 1\n0 0\n10 0", "output": "0.200000000"}, {"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "output": "6.032163204"}, {"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0", "output": "3.000000000"}]
900
["geometry"]
42
[{"input": "2 1\r\n0 0\r\n10 0\r\n", "output": "0.200000000"}, {"input": "5 10\r\n3 1\r\n-5 6\r\n-2 -1\r\n3 2\r\n10 0\r\n", "output": "6.032163204"}, {"input": "6 10\r\n5 0\r\n4 0\r\n6 0\r\n3 0\r\n7 0\r\n2 0\r\n", "output": "3.000000000"}, {"input": "10 95\r\n-20 -5\r\n2 -8\r\n14 13\r\n10 3\r\n17 11\r\n13 -12\r\n-6 11\...
false
stdio
import sys import math def read_points(n, input_file): points = [] for _ in range(n): x, y = map(int, input_file.readline().split()) points.append((x, y)) return points def compute_total_time(n, k, points): total_length = 0.0 for i in range(1, n): x0, y0 = points[i-1] ...
true
127/A
127
A
Python 3
TESTS
1
186
0
55098827
n, k = map(int, input().split()) x0 = 0 y0 = 0 r = 0 for i in range(n): x,y = map(int, input().split()) if i > 0: r += ((x-x0)**2 + (y-y0)**2)**0.5 x0 = x y0 = y t = r / 50 print(t)
42
92
0
4607148
n, k = map(int, input().split()) x, y = map(int, input().split()) l = 0 for i in range(n - 1): u, v = map(int, input().split()) l += ((x - u) ** 2 + (y - v) ** 2) ** 0.5 x, y = u, v print(k * l / 50)
Codeforces Beta Round 93 (Div. 2 Only)
CF
2,011
2
256
Wasted Time
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline ...
The first line contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai — integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates ...
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
null
null
[{"input": "2 1\n0 0\n10 0", "output": "0.200000000"}, {"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "output": "6.032163204"}, {"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0", "output": "3.000000000"}]
900
["geometry"]
42
[{"input": "2 1\r\n0 0\r\n10 0\r\n", "output": "0.200000000"}, {"input": "5 10\r\n3 1\r\n-5 6\r\n-2 -1\r\n3 2\r\n10 0\r\n", "output": "6.032163204"}, {"input": "6 10\r\n5 0\r\n4 0\r\n6 0\r\n3 0\r\n7 0\r\n2 0\r\n", "output": "3.000000000"}, {"input": "10 95\r\n-20 -5\r\n2 -8\r\n14 13\r\n10 3\r\n17 11\r\n13 -12\r\n-6 11\...
false
stdio
import sys import math def read_points(n, input_file): points = [] for _ in range(n): x, y = map(int, input_file.readline().split()) points.append((x, y)) return points def compute_total_time(n, k, points): total_length = 0.0 for i in range(1, n): x0, y0 = points[i-1] ...
true
127/A
127
A
PyPy 3
TESTS
1
186
20,172,800
125533270
""" reading 9:16 -> 9:20 thinking 9:20 -> 9:24 coding 9:24 -> 9:40 debugging 9:40 -> """ """ Se toma n veces las posiciones de los trazos, como son líneas rectas, se calcula la distancia entre A_k y A_k+1, luego se multiplica por k y se divide entre su velocidad. """ def distance(a : tuple, b : tuple): return ((...
42
92
0
136191539
nk = list(map(int, input().split(' '))) n = nk[0] k = nk[1] dist = 0.0 xy = list(map(int, input().split(' '))) x = xy[0] y = xy[1] for idx in range(n-1): xy1 = list(map(int, input().split(' '))) x1 = xy1[0] y1 = xy1[1] dist += ((((x1 - x) ** 2) + ((y1 - y) ** 2)) ** 0.5) x = x1 y = y1 time = di...
Codeforces Beta Round 93 (Div. 2 Only)
CF
2,011
2
256
Wasted Time
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline ...
The first line contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai — integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates ...
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
null
null
[{"input": "2 1\n0 0\n10 0", "output": "0.200000000"}, {"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "output": "6.032163204"}, {"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0", "output": "3.000000000"}]
900
["geometry"]
42
[{"input": "2 1\r\n0 0\r\n10 0\r\n", "output": "0.200000000"}, {"input": "5 10\r\n3 1\r\n-5 6\r\n-2 -1\r\n3 2\r\n10 0\r\n", "output": "6.032163204"}, {"input": "6 10\r\n5 0\r\n4 0\r\n6 0\r\n3 0\r\n7 0\r\n2 0\r\n", "output": "3.000000000"}, {"input": "10 95\r\n-20 -5\r\n2 -8\r\n14 13\r\n10 3\r\n17 11\r\n13 -12\r\n-6 11\...
false
stdio
import sys import math def read_points(n, input_file): points = [] for _ in range(n): x, y = map(int, input_file.readline().split()) points.append((x, y)) return points def compute_total_time(n, k, points): total_length = 0.0 for i in range(1, n): x0, y0 = points[i-1] ...
true
31/D
31
D
Python 3
TESTS
2
62
102,400
207016922
# LUOGU_RID: 111131923 from sys import stdin input = stdin.readline row = col = [[0] * 110 for i in range(110)] vis = [[False] * 110 for i in range(110)] ans = [] def get() : return map(int,input().split()) W,H,N = get() for _ in range(N) : x1, y1, x2, y2 = get() if x1 == x2 : for i in ran...
33
278
4,505,600
146016755
from collections import deque import sys input = sys.stdin.readline def bfs(x, y): q = deque() q.append((x, y)) visit[x][y] = 1 c = 0 while q: i, j = q.popleft() c += 1 for di, dj in G[i][j]: ni, nj = i + di, j + dj if 0 <= ni < w and 0 <= nj < h: ...
Codeforces Beta Round 31 (Div. 2, Codeforces format)
CF
2,010
2
256
Chocolate
Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parall...
The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, ...
Output n + 1 numbers — areas of the resulting parts in the increasing order.
null
null
[{"input": "2 2 2\n1 0 1 2\n0 1 1 1", "output": "1 1 2"}, {"input": "2 2 3\n1 0 1 2\n0 1 1 1\n1 1 2 1", "output": "1 1 1 1"}, {"input": "2 4 2\n0 1 2 1\n0 3 2 3", "output": "2 2 4"}]
2,000
["dfs and similar", "implementation"]
33
[{"input": "2 2 2\r\n1 0 1 2\r\n0 1 1 1\r\n", "output": "1 1 2 "}, {"input": "2 2 3\r\n1 0 1 2\r\n0 1 1 1\r\n1 1 2 1\r\n", "output": "1 1 1 1 "}, {"input": "2 4 2\r\n0 1 2 1\r\n0 3 2 3\r\n", "output": "2 2 4 "}, {"input": "5 5 3\r\n2 1 2 5\r\n0 1 5 1\r\n4 0 4 1\r\n", "output": "1 4 8 12 "}, {"input": "10 10 4\r\n9 0 9 ...
false
stdio
null
true
127/A
127
A
Python 3
TESTS
1
216
0
49985139
cnt=lambda s,i:s.count(i) iip=lambda:int(input()) sip=lambda:input() f=lambda:map(int,input().split()) lf=lambda:list(map(int,input().split())) n,k=f() l=lf() d=0 for i in range(n-1): l2=lf() d+=((l2[0]-l[0])**2+(l2[1]-l[1])**2)**0.5 l=l2 print('%0.9f'%(d/50))
42
92
0
136781502
(N, K) = [int(i) for i in input().split()] total_distance = 0 last_point = [int(i) for i in input().split()] for i in range(N-1): point = [int(i) for i in input().split()] total_distance += (abs(point[0]-last_point[0])**2 + abs(point[1]-last_point[1])**2)**0.5 last_point = point wasted_time = (total_distance / 50)...
Codeforces Beta Round 93 (Div. 2 Only)
CF
2,011
2
256
Wasted Time
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline ...
The first line contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai — integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates ...
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
null
null
[{"input": "2 1\n0 0\n10 0", "output": "0.200000000"}, {"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "output": "6.032163204"}, {"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0", "output": "3.000000000"}]
900
["geometry"]
42
[{"input": "2 1\r\n0 0\r\n10 0\r\n", "output": "0.200000000"}, {"input": "5 10\r\n3 1\r\n-5 6\r\n-2 -1\r\n3 2\r\n10 0\r\n", "output": "6.032163204"}, {"input": "6 10\r\n5 0\r\n4 0\r\n6 0\r\n3 0\r\n7 0\r\n2 0\r\n", "output": "3.000000000"}, {"input": "10 95\r\n-20 -5\r\n2 -8\r\n14 13\r\n10 3\r\n17 11\r\n13 -12\r\n-6 11\...
false
stdio
import sys import math def read_points(n, input_file): points = [] for _ in range(n): x, y = map(int, input_file.readline().split()) points.append((x, y)) return points def compute_total_time(n, k, points): total_length = 0.0 for i in range(1, n): x0, y0 = points[i-1] ...
true
127/A
127
A
Python 3
TESTS
1
60
0
174158343
a=input().split() n=int(a[0]) k=int(a[1]) lista = [] for l in range(n): coord = [] b=input().split() for i in b: coord.append(int(i)) lista.append(coord) total=0 for i in range(len(lista)-1): x1=lista[i][0] x2=lista[i+1][0] y1=lista[i][1] y2=lista[i+1][1] dist = ( (x2 - x1)**2 + (y2 - y1)**2 )**(1/2...
42
92
0
139640508
n, k = map(int, input().split()); x, y = map(int, input().split()); distance = 0 for i in range(n - 1): a, b = map(int, input().split()) t = (a - x) ** 2 + (b - y) ** 2; distance += t ** 0.5 x, y = a, b print(distance * k / 50)
Codeforces Beta Round 93 (Div. 2 Only)
CF
2,011
2
256
Wasted Time
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline ...
The first line contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai — integers xi and yi, separated by a space. All points Ai are different. The absolute value of all coordinates ...
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.
null
null
[{"input": "2 1\n0 0\n10 0", "output": "0.200000000"}, {"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "output": "6.032163204"}, {"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0", "output": "3.000000000"}]
900
["geometry"]
42
[{"input": "2 1\r\n0 0\r\n10 0\r\n", "output": "0.200000000"}, {"input": "5 10\r\n3 1\r\n-5 6\r\n-2 -1\r\n3 2\r\n10 0\r\n", "output": "6.032163204"}, {"input": "6 10\r\n5 0\r\n4 0\r\n6 0\r\n3 0\r\n7 0\r\n2 0\r\n", "output": "3.000000000"}, {"input": "10 95\r\n-20 -5\r\n2 -8\r\n14 13\r\n10 3\r\n17 11\r\n13 -12\r\n-6 11\...
false
stdio
import sys import math def read_points(n, input_file): points = [] for _ in range(n): x, y = map(int, input_file.readline().split()) points.append((x, y)) return points def compute_total_time(n, k, points): total_length = 0.0 for i in range(1, n): x0, y0 = points[i-1] ...
true
526/D
526
D
Python 3
TESTS
0
15
0
193252335
# LUOGU_RID: 101971216 print("0")
57
140
22,528,000
223321082
def prefix_function(s: str): n = len(s) pi = [0] * n k = 0 for i in range(1, n): while k > 0 and s[i] != s[k]: k = pi[k - 1] if s[i] == s[k]: k += 1 pi[i] = k return pi def z_function(s: str): n = len(s) z = [0] * n l, r = 0, 0 for i in range(1, n): z[i] = 0 if i >= r else...
ZeptoLab Code Rush 2015
CF
2,015
1
256
Om Nom and Necklace
One day Om Nom found a thread with n beads of different colors. He decided to cut the first several beads from this thread to make a bead necklace and present it to his girlfriend Om Nelly. Om Nom knows that his girlfriend loves beautiful patterns. That's why he wants the beads on the necklace to form a regular patter...
The first line contains two integers n, k (1 ≤ n, k ≤ 1 000 000) — the number of beads on the thread that Om Nom found and number k from the definition of the regular sequence above. The second line contains the sequence of n lowercase Latin letters that represent the colors of the beads. Each color corresponds to a s...
Print a string consisting of n zeroes and ones. Position i (1 ≤ i ≤ n) must contain either number one if the first i beads on the thread form a regular sequence, or a zero otherwise.
null
In the first sample test a regular sequence is both a sequence of the first 6 beads (we can take A = "", B = "bca"), and a sequence of the first 7 beads (we can take A = "b", B = "ca"). In the second sample test, for example, a sequence of the first 13 beads is regular, if we take A = "aba", B = "ba".
[{"input": "7 2\nbcabcab", "output": "0000011"}, {"input": "21 2\nababaababaababaababaa", "output": "000110000111111000011"}]
2,200
["hashing", "string suffix structures", "strings"]
57
[{"input": "7 2\r\nbcabcab\r\n", "output": "0000011"}, {"input": "21 2\r\nababaababaababaababaa\r\n", "output": "000110000111111000011"}, {"input": "321 2\r\nabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaaba...
false
stdio
null
true
729/D
729
D
PyPy 3
TESTS
4
140
409,600
56168221
'''input 5 1 2 1 00100 ''' from sys import stdin import collections def get_working(string): aux = [] first = None if string[0] == 1: pass else: first = -1 for i in range(len(string)): if string[i] == '1': if first == None: first = i elif first != None: aux.append([first, i, (i - first - 1)])...
21
171
14,643,200
22697999
n,a,b,k=map(int,input().split()) A=input() B=A.split('1') C=[] l=1 for i in B: if len(i)>=b: for j in range(b-1,len(i),b): C.append(j+l) l+=len(i)+1 C=C[:len(C)-a+1] print(len(C)) print(' '.join(list(map(str,C))))
Technocup 2017 - Elimination Round 2
CF
2,016
1
256
Sea Battle
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other. Galya doesn't know the ships location. She can shoot to some cells and after each shot ...
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made. The second line contains a string of length n, consisting of zeros and ones. If the i...
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship. In the second line print the cells Galya should shoot at. Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting fro...
null
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.
[{"input": "5 1 2 1\n00100", "output": "2\n4 2"}, {"input": "13 3 2 3\n1000000010001", "output": "2\n7 11"}]
1,700
["constructive algorithms", "greedy", "math"]
21
[{"input": "5 1 2 1\r\n00100\r\n", "output": "2\r\n2 5 \r\n"}, {"input": "13 3 2 3\r\n1000000010001\r\n", "output": "2\r\n3 5 \r\n"}, {"input": "1 1 1 0\r\n0\r\n", "output": "1\r\n1 \r\n"}, {"input": "2 2 1 0\r\n00\r\n", "output": "1\r\n1 \r\n"}, {"input": "5 4 1 0\r\n00000\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "...
false
stdio
null
true
241/A
241
A
PyPy 3
TESTS
2
278
0
78814214
import math m,k = map(int,input().split()) d = list(map(int,input().split())) f = list(map(int,input().split())) h = 0 fuel = 0 for i in range(0,m): fuel = fuel + f[i] if(fuel < d[i]): h = h + math.ceil((d[i]-f[i])/f[i])*k fuel = fuel + math.ceil((d[i]-f[i])/f[i])*k*f[i] h = h + d[i] fu...
52
248
0
41983593
m,k=map(int,input().split()) D=list(map(int,input().split())) S=list(map(int,input().split())) ans=0 fuel=S[0] maxx=S[0] for i in range(m): if(D[i]>fuel): x=D[i]-fuel y=x//maxx if(x%maxx>0): y+=1 ans+=y*k fuel+=maxx*y fuel-=D[i] ans+...
Bayan 2012-2013 Elimination Round (ACM ICPC Rules, English statements)
ICPC
2,012
2
256
Old Peykan
There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city c1 to cn using roads. There are (n - 1) one way roads, the i-th road goes from city ci to city ci + 1 and is di kil...
The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000). The value m specifies the number of roads between cities which is equal to n - 1. The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and the following line contains m space-separated integers s1,...
In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cn from city c1.
null
In the second sample above, the Old Peykan stays in c1 for 3 hours.
[{"input": "4 6\n1 2 5 2\n2 3 3 4", "output": "10"}, {"input": "2 3\n5 6\n5 5", "output": "14"}]
1,300
["greedy"]
52
[{"input": "4 6\r\n1 2 5 2\r\n2 3 3 4\r\n", "output": "10\r\n"}, {"input": "2 3\r\n5 6\r\n5 5\r\n", "output": "14\r\n"}, {"input": "24 3\r\n11 8 8 12 17 4 4 25 39 37 31 32 38 34 29 29 34 39 39 39 17 9 24 6\r\n3 5 4 3 3 3 4 3 4 3 3 3 3 4 3 3 4 3 4 3 3 3 3 3\r\n", "output": "862\r\n"}, {"input": "43 5\r\n6 7 15 12 15 7 2...
false
stdio
null
true
379/B
379
B
PyPy 3-64
TESTS
0
30
0
164186410
nofwallets = int(input()) given = input().split() intlist = [int(a) for a in given] startstr = "" done = False while not done: done = True for i in range(nofwallets-1): if intlist[i] != 0: startstr += 'P' intlist[i] -= 1 done = False startstr += 'R' startst...
15
46
409,600
144587271
n=int(input()) lis=list(map(int,input().split())) command='PRL'*lis[0] for i in range(1,len(lis)): command+=('R'+'LRP'*lis[i]) print(command)
Good Bye 2013
CF
2,013
1
256
New Year Present
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception. Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided t...
The first line contains integer n (2 ≤ n ≤ 300) — the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 300). It is guaranteed that at least one ai is positive.
Print the sequence that consists of k (1 ≤ k ≤ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot ...
null
null
[{"input": "2\n1 2", "output": "PRPLRP"}, {"input": "4\n0 2 0 2", "output": "RPRRPLLPLRRRP"}]
1,200
["constructive algorithms", "implementation"]
15
[{"input": "2\r\n1 2\r\n", "output": "PRPLRP"}, {"input": "4\r\n0 2 0 2\r\n", "output": "RPRRPLLPLRRRP"}, {"input": "10\r\n2 3 4 0 0 1 1 3 4 2\r\n", "output": "PRPRPRRRPRPRPRPRPLPLPLLLLLPLPLPRPRPRRRRRPRPRPLPLLLLLLPLL"}, {"input": "10\r\n0 0 0 0 0 0 0 0 1 0\r\n", "output": "RRRRRRRRPR"}, {"input": "5\r\n2 2 2 2 2\r\n", ...
false
stdio
import sys def main(input_path, output_path, sub_output_path): with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) with open(sub_output_path) as f: s = f.read().strip() if len(s) < 1 or len(s) > 10**6: print(0) return ...
true
397/B
397
B
PyPy 3
TESTS
0
124
0
52266183
def possible(numbers): return int(numbers[0])//int(numbers[1])!=0 and int(numbers[0])%int(numbers[1])//(int(numbers[0])//int(numbers[1]))<=int(numbers[2])-int(numbers[1]) and int(numbers[0])%int(numbers[1])%int(numbers[0])//int(numbers[1])+int(numbers[0])%int(numbers[1])%(int(numbers[0])//int(numbers[1]))<=(int...
6
61
0
12258359
import sys; sys.setrecursionlimit(1000000) def solve(): tests, = rv() for test in range(tests): n,l,r, = rv() largestused = (n + r - 1) // r totalnum = largestused * r mostcansubtract = largestused * (r - l) lowerbound = totalnum - mostcansubtract if lowerbound <...
Codeforces Round 232 (Div. 2)
CF
2,014
1
256
On Corruption and Numbers
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to w...
The first line contains the number of universities t, (1 ≤ t ≤ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 ≤ ni, li, ri ≤ 109; li ≤ ri).
For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.
null
You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.
[{"input": "2\n5 2 3\n6 4 5", "output": "Yes\nNo"}]
null
["constructive algorithms", "implementation", "math"]
6
[{"input": "2\r\n5 2 3\r\n6 4 5\r\n", "output": "Yes\r\nNo\r\n"}, {"input": "50\r\n69 6 6\r\n22 1 1\r\n23 3 3\r\n60 13 13\r\n13 3 3\r\n7 4 7\r\n6 1 1\r\n49 7 9\r\n68 8 8\r\n20 2 2\r\n34 1 1\r\n79 5 5\r\n22 1 1\r\n77 58 65\r\n10 3 3\r\n72 5 5\r\n47 1 1\r\n82 3 3\r\n92 8 8\r\n34 1 1\r\n42 9 10\r\n63 14 14\r\n10 3 3\r\n38...
false
stdio
null
true
600/E
600
E
PyPy 3-64
TESTS
2
46
0
199803690
import sys input = lambda:sys.stdin.readline().strip() n = int(input()) c = list(map(int,input().split())) has = [[] for _ in range(n)] for _ in range(n-1): a,b = map(lambda x:int(x)-1,input().split()) has[a].append(b) has[b].append(a) ans = [0]*(n) def dsu(x,p): xx = {c[x]} for y in has[x]: ...
28
529
52,019,200
172847049
import sys readline = sys.stdin.readline write = sys.stdout.write def dsu_on_tree(N, G, Prop): order = [] et_f = [-1]*N prt = [-1]*N que = [0] used = [0]*N used[0] = 1 while que: v = que.pop() for w in G[v]: if used[w]: continue used[...
Educational Codeforces Round 2
ICPC
2,015
2
256
Lomsat gelral
You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour. Let's call colour c dominating in the subtree of vertex v if there are no other colours that appear in the subtree of vertex v more times than colour c. So it's possible that two or more colours will be dominating in the subtree...
The first line contains integer n (1 ≤ n ≤ 105) — the number of vertices in the tree. The second line contains n integers ci (1 ≤ ci ≤ n), ci — the colour of the i-th vertex. Each of the next n - 1 lines contains two integers xj, yj (1 ≤ xj, yj ≤ n) — the edge of the tree. The first vertex is the root of the tree.
Print n integers — the sums of dominating colours for each vertex.
null
null
[{"input": "4\n1 2 3 4\n1 2\n2 3\n2 4", "output": "10 9 3 4"}, {"input": "15\n1 2 3 1 2 3 3 1 1 3 2 2 1 2 3\n1 2\n1 3\n1 4\n1 14\n1 15\n2 5\n2 6\n2 7\n3 8\n3 9\n3 10\n4 11\n4 12\n4 13", "output": "6 5 4 3 2 3 3 1 1 3 2 2 1 2 3"}]
2,300
["data structures", "dfs and similar", "dsu", "trees"]
28
[{"input": "4\r\n1 2 3 4\r\n1 2\r\n2 3\r\n2 4\r\n", "output": "10 9 3 4\r\n"}, {"input": "15\r\n1 2 3 1 2 3 3 1 1 3 2 2 1 2 3\r\n1 2\r\n1 3\r\n1 4\r\n1 14\r\n1 15\r\n2 5\r\n2 6\r\n2 7\r\n3 8\r\n3 9\r\n3 10\r\n4 11\r\n4 12\r\n4 13\r\n", "output": "6 5 4 3 2 3 3 1 1 3 2 2 1 2 3\r\n"}]
false
stdio
null
true
241/A
241
A
Python 3
TESTS
2
216
0
58515265
import sys import math header = sys.stdin.readline() while header: m, k = [int(x) for x in header.split()] distances = [int(d) for d in sys.stdin.readline().split()] supplies = [int(s) for s in sys.stdin.readline().split()] gas = 0 time = 0 for i in range(len(distances)): d = distances[...
52
248
0
54079119
estradas,k = [int(i) for i in input().split()] d = [int(i) for i in input().split()] s = [int(i) for i in input().split()] fuel = 0 time = 0 currMax = 0 for i in range(estradas): fuel+=s[i] currMax = max(currMax,s[i]) while(fuel<d[i]): time+=k fuel+=currMax ...
Bayan 2012-2013 Elimination Round (ACM ICPC Rules, English statements)
ICPC
2,012
2
256
Old Peykan
There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city c1 to cn using roads. There are (n - 1) one way roads, the i-th road goes from city ci to city ci + 1 and is di kil...
The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000). The value m specifies the number of roads between cities which is equal to n - 1. The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and the following line contains m space-separated integers s1,...
In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cn from city c1.
null
In the second sample above, the Old Peykan stays in c1 for 3 hours.
[{"input": "4 6\n1 2 5 2\n2 3 3 4", "output": "10"}, {"input": "2 3\n5 6\n5 5", "output": "14"}]
1,300
["greedy"]
52
[{"input": "4 6\r\n1 2 5 2\r\n2 3 3 4\r\n", "output": "10\r\n"}, {"input": "2 3\r\n5 6\r\n5 5\r\n", "output": "14\r\n"}, {"input": "24 3\r\n11 8 8 12 17 4 4 25 39 37 31 32 38 34 29 29 34 39 39 39 17 9 24 6\r\n3 5 4 3 3 3 4 3 4 3 3 3 3 4 3 3 4 3 4 3 3 3 3 3\r\n", "output": "862\r\n"}, {"input": "43 5\r\n6 7 15 12 15 7 2...
false
stdio
null
true
241/A
241
A
PyPy 3-64
TESTS
2
92
0
182710115
m_k = input().split(" ") m = int(m_k[0]) k = int(m_k[1]) distances = input().split(" ") supplys = input().split(" ") benzin = 0 full_time = 0 for i in range(m): benzin += int(supplys[i]) while benzin < int(distances[i]): benzin += int(supplys[i]) full_time += k benzin -= int(distances[i]) ...
52
248
307,200
79046881
from math import ceil X = list(map(int, input().split())) Distance = list(map(int, input().split())) Fuel = list(map(int, input().split())) Tank, Time, Max = 0, 0, 0 for i in range(X[0]): Tank += Fuel[i] Max = max(Max, Fuel[i]) Stay = max(0, ceil((Distance[i] - Tank) / Max)) Time += Stay * X[1] + Dista...
Bayan 2012-2013 Elimination Round (ACM ICPC Rules, English statements)
ICPC
2,012
2
256
Old Peykan
There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city c1 to cn using roads. There are (n - 1) one way roads, the i-th road goes from city ci to city ci + 1 and is di kil...
The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000). The value m specifies the number of roads between cities which is equal to n - 1. The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and the following line contains m space-separated integers s1,...
In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cn from city c1.
null
In the second sample above, the Old Peykan stays in c1 for 3 hours.
[{"input": "4 6\n1 2 5 2\n2 3 3 4", "output": "10"}, {"input": "2 3\n5 6\n5 5", "output": "14"}]
1,300
["greedy"]
52
[{"input": "4 6\r\n1 2 5 2\r\n2 3 3 4\r\n", "output": "10\r\n"}, {"input": "2 3\r\n5 6\r\n5 5\r\n", "output": "14\r\n"}, {"input": "24 3\r\n11 8 8 12 17 4 4 25 39 37 31 32 38 34 29 29 34 39 39 39 17 9 24 6\r\n3 5 4 3 3 3 4 3 4 3 3 3 3 4 3 3 4 3 4 3 3 3 3 3\r\n", "output": "862\r\n"}, {"input": "43 5\r\n6 7 15 12 15 7 2...
false
stdio
null
true
19/C
19
C
Python 3
TESTS
0
186
0
41975374
def get_pow_list(x, exp, mod): res = [1] for i in range(exp): res.append((res[-1] * x) % mod) return res MOD = 2 ** 61 - 1 n = int(input()) orig_vals = list(map(int, input().split())) sv = list(set(orig_vals)) sv_inv = {sv[i]: i + 1 for i in range(len(sv))} vals = [sv_inv[x] for x in orig_vals]...
70
1,216
14,131,200
174568804
import sys n=int(input()) a=list(map(int,input().split())) M=10**9+1 g={} for i in range(n): g[a[i]]=g.get(a[i],[])+[i] p=[1] for i in range(n): p+=[hash(M*p[-1])] h=[0]*(n+1) for i in range(n): h[i+1]=hash(h[i]*M+a[i]) gh=lambda k,l:hash(h[k+l]-h[k]*p[l])%sys.hash_info.modulus i,t=0,0 while i < n: for ...
Codeforces Beta Round 19
ICPC
2,010
2
256
Deletion of Repeats
Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a repeat of length x is such a substring of length 2x, that its first half coin...
The first input line contains integer n (1 ≤ n ≤ 105) — length of the string. The following line contains n space-separated integer numbers from 0 to 109 inclusive — numbers that stand for the letters of the string. It's guaranteed that each letter can be met in the string at most 10 times.
In the first line output the length of the string's part, left after Bob's deletions. In the second line output all the letters (separated by a space) of the string, left after Bob deleted all the repeats in the described way.
null
null
[{"input": "6\n1 2 3 1 2 3", "output": "3\n1 2 3"}, {"input": "7\n4 5 6 5 6 7 7", "output": "1\n7"}]
2,200
["greedy", "hashing", "string suffix structures"]
70
[{"input": "6\r\n1 2 3 1 2 3\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "7\r\n4 5 6 5 6 7 7\r\n", "output": "1\r\n7 \r\n"}, {"input": "10\r\n5 7 2 1 8 8 5 10 2 5\r\n", "output": "5\r\n8 5 10 2 5 \r\n"}, {"input": "10\r\n0 1 1 1 0 3 0 1 4 0\r\n", "output": "7\r\n1 0 3 0 1 4 0 \r\n"}, {"input": "10\r\n0 1 0 2 0 0 1 1 ...
false
stdio
null
true
875/D
875
D
PyPy 3-64
TESTS
2
61
0
204069401
import sys from collections import deque input = sys.stdin.readline def fg(): return int(input()) def fgh(): return [int(Xx) for Xx in input().split()] n = fg() a = fgh() S = 30 step = [1] for i in range(S): step.append(step[-1] * 2) d = [[] for i in range(S)] for i in range(n): for j in range(S): ...
78
514
127,283,200
226308676
from collections import defaultdict def read_ints(): return map(int, input().split()) def read_int(): return int(input()) def yes_no(yes): print('Yes' if yes else 'No') return yes def solve_test(): n = read_int() a = list(read_ints()) def get_ans(): bit_size = 32 lef...
Codeforces Round 441 (Div. 1, by Moscow Team Olympiad)
CF
2,017
1
512
High Cry
Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :) Rick and Morty like to go to the ridge High Cry for crying loudly — there is an extraordinary echo. Recently they discovered an interesting acoustic characteristic of this...
The first line contains integer n (1 ≤ n ≤ 200 000), the number of mountains in the ridge. Second line contains n integers ai (0 ≤ ai ≤ 109), the heights of mountains in order they are located in the ridge.
Print the only integer, the number of ways to choose two different mountains.
null
In the first test case all the ways are pairs of mountains with the numbers (numbering from one): (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5) In the second test case there are no such pairs because for any pair of mountains the height of cry from them is 3, and this height is equal to the height of...
[{"input": "5\n3 2 1 6 5", "output": "8"}, {"input": "4\n3 3 3 3", "output": "0"}]
2,200
["binary search", "bitmasks", "combinatorics", "data structures", "divide and conquer"]
78
[{"input": "5\r\n3 2 1 6 5\r\n", "output": "8\r\n"}, {"input": "4\r\n3 3 3 3\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "0\r\n"}, {"input": "1\r\n6\r\n", "output": "0\r\n"}, {"input": "228\r\n1 3 1 7 1 3 1 ...
false
stdio
null
true
314/A
314
A
PyPy 3-64
TESTS
3
122
0
183327872
import sys input = sys.stdin.readline n, k = map(int, input().split()) w = list(map(int, input().split())) ew = set() t = 0 while 1: d = [] c = 0 for i in range(n): x = c - i * w[i] * (n-i-1) c += i * w[i] if x >= k: d.append(w[i]) else: ew.add(i+t+1...
22
404
26,931,200
211355857
import sys input = lambda: sys.stdin.readline().rstrip() N,K = map(int, input().split()) A = list(map(int, input().split())) pre,cnt=0,0 for i in range(N): a = A[i] b = pre-(N-i-1)*a*(i-cnt) if b<K: #print(pre,cnt,i,b) print(i+1) cnt+=1 else: pre+=(i-cnt)*a
Codeforces Round 187 (Div. 1)
CF
2,013
2
256
Sereja and Contest
During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants. Let's assume that n people took part in the contest. Let's assume that the participant who got the first place has rating a1, the second place participant has rating a2, ..., the ...
The first line contains two integers n, k (1 ≤ n ≤ 2·105, - 109 ≤ k ≤ 0). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — ratings of the participants in the initial table.
Print the numbers of participants in the order in which they were removed from the table. Print the initial numbers of the participants, that is, the numbers that the participants had in the initial table.
null
Consider the first test sample. 1. Initially the sequence of the contest participants' ratings equals [5, 3, 4, 1, 2]. You can use this sequence to calculate the sequence of rating changes: [0, -9, -13, 8, 14]. According to the problem statement, the application of the participant who won the second place will be cons...
[{"input": "5 0\n5 3 4 1 2", "output": "2\n3\n4"}, {"input": "10 -10\n5 5 1 7 5 1 2 4 9 2", "output": "2\n4\n5\n7\n8\n9"}]
1,600
["implementation"]
22
[{"input": "5 0\r\n5 3 4 1 2\r\n", "output": "2\r\n3\r\n4\r\n"}, {"input": "10 -10\r\n5 5 1 7 5 1 2 4 9 2\r\n", "output": "2\r\n4\r\n5\r\n7\r\n8\r\n9\r\n"}]
false
stdio
null
true
314/A
314
A
PyPy 3
TESTS
3
184
0
106169062
from sys import stdin,stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) for _ in range(1):#nmbr()): n,k=lst() a=lst() pos=[0] neg=[] for i in range(1,n): pos+=[pos[-1]+a[i]*i] removed=0;sm=0 for i in range(1,n): positive_term=po...
22
468
33,792,000
183439329
import sys input = sys.stdin.readline n, k = map(int, input().split()) w = list(map(int, input().split())) ew = set() c = 0 t = 0 for i in range(n): x = (i-t)*w[i]*(n-i-1) if c - x < k: t += 1 ew.add(i+1) else: c += (i-t)*w[i] for i in ew: print(i)
Codeforces Round 187 (Div. 1)
CF
2,013
2
256
Sereja and Contest
During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants. Let's assume that n people took part in the contest. Let's assume that the participant who got the first place has rating a1, the second place participant has rating a2, ..., the ...
The first line contains two integers n, k (1 ≤ n ≤ 2·105, - 109 ≤ k ≤ 0). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — ratings of the participants in the initial table.
Print the numbers of participants in the order in which they were removed from the table. Print the initial numbers of the participants, that is, the numbers that the participants had in the initial table.
null
Consider the first test sample. 1. Initially the sequence of the contest participants' ratings equals [5, 3, 4, 1, 2]. You can use this sequence to calculate the sequence of rating changes: [0, -9, -13, 8, 14]. According to the problem statement, the application of the participant who won the second place will be cons...
[{"input": "5 0\n5 3 4 1 2", "output": "2\n3\n4"}, {"input": "10 -10\n5 5 1 7 5 1 2 4 9 2", "output": "2\n4\n5\n7\n8\n9"}]
1,600
["implementation"]
22
[{"input": "5 0\r\n5 3 4 1 2\r\n", "output": "2\r\n3\r\n4\r\n"}, {"input": "10 -10\r\n5 5 1 7 5 1 2 4 9 2\r\n", "output": "2\r\n4\r\n5\r\n7\r\n8\r\n9\r\n"}]
false
stdio
null
true
167/A
167
A
Python 3
TESTS
0
93
6,656,000
88151890
n, a, d = map(int, input().split()) r = [] for i in range(0, n): t, v = map(int, input().split()) current = d / v + t if i == 0: r.append(current) else: last = r[i - 1] if current < last: r.append(last) for x in r: print(x)
57
312
11,673,600
211354808
import sys input = lambda: sys.stdin.readline().rstrip() import math N,A,D = map(int, input().split()) pre = 0 for _ in range(N): t,v = map(int, input().split()) # 到达最高速度需要的时间 t1 = v/A # 加速时间段行走距离(已知时间和加速度求距离) d1 = t1*(t1*A/2) # 能加到全速 if d1<=D: # 剩下距离需要的时间 t2 = (D-...
Codeforces Round 114 (Div. 1)
CF
2,012
1
256
Wizards and Trolleybuses
In some country live wizards. They love to ride trolleybuses. A city in this country has a trolleybus depot with n trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a distance of d meters from the depot. We know for the i-th trolleybus that it lea...
The first input line contains three space-separated integers n, a, d (1 ≤ n ≤ 105, 1 ≤ a, d ≤ 106) — the number of trolleybuses, their maximum acceleration and the distance from the depot to the final station, correspondingly. Next n lines contain pairs of integers ti vi (0 ≤ t1 < t2... < tn - 1 < tn ≤ 106, 1 ≤ vi ≤ 1...
For each trolleybus print a single line the time it arrives to the final station. Print the times for the trolleybuses in the order in which the trolleybuses are given in the input. The answer will be accepted if the absolute or relative error doesn't exceed 10 - 4.
null
In the first sample the second trolleybus will catch up with the first one, that will happen at distance 510.5 meters from the depot. The trolleybuses will go the remaining 9489.5 meters together at speed 10 meters per second. As a result, both trolleybuses will arrive to the final station by the moment of time 1000.5 ...
[{"input": "3 10 10000\n0 10\n5 11\n1000 1", "output": "1000.5000000000\n1000.5000000000\n11000.0500000000"}, {"input": "1 2 26\n28 29", "output": "33.0990195136"}]
1,600
["implementation", "math"]
57
[{"input": "3 10 10000\r\n0 10\r\n5 11\r\n1000 1\r\n", "output": "1000.5000000000\r\n1000.5000000000\r\n11000.0500000000\r\n"}, {"input": "1 2 26\r\n28 29\r\n", "output": "33.0990195136\r\n"}, {"input": "7 8 3\r\n1 3\r\n5 26\r\n7 3\r\n10 15\r\n18 7\r\n21 17\r\n23 21\r\n", "output": "2.1875000000\r\n5.8660254038\r\n8.18...
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, a, d = map(int, f.readline().split()) # Read correct output correct = [] with open(output_path) as f: for line in f: line = li...
true
314/A
314
A
Python 3
TESTS
3
92
5,529,600
31660973
f = lambda: map(int, input().split()) n, k = f() s = j = 0 for i, q in enumerate(f(), 1): if s - j * (n - i) * q < k: print(i) else: s += q * (i - 1) j += 1
22
778
23,961,600
197616117
n, k = map(int, input().split()) S = D = i = 0 ans = [] for val in map(int, input().split()): f = (n - i - 1) * val * (i - D) if S - f < k: D += 1 ans.append(i + 1) else: S += val * (i - D) i += 1 print(' '.join(map(str, ans)))
Codeforces Round 187 (Div. 1)
CF
2,013
2
256
Sereja and Contest
During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants. Let's assume that n people took part in the contest. Let's assume that the participant who got the first place has rating a1, the second place participant has rating a2, ..., the ...
The first line contains two integers n, k (1 ≤ n ≤ 2·105, - 109 ≤ k ≤ 0). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — ratings of the participants in the initial table.
Print the numbers of participants in the order in which they were removed from the table. Print the initial numbers of the participants, that is, the numbers that the participants had in the initial table.
null
Consider the first test sample. 1. Initially the sequence of the contest participants' ratings equals [5, 3, 4, 1, 2]. You can use this sequence to calculate the sequence of rating changes: [0, -9, -13, 8, 14]. According to the problem statement, the application of the participant who won the second place will be cons...
[{"input": "5 0\n5 3 4 1 2", "output": "2\n3\n4"}, {"input": "10 -10\n5 5 1 7 5 1 2 4 9 2", "output": "2\n4\n5\n7\n8\n9"}]
1,600
["implementation"]
22
[{"input": "5 0\r\n5 3 4 1 2\r\n", "output": "2\r\n3\r\n4\r\n"}, {"input": "10 -10\r\n5 5 1 7 5 1 2 4 9 2\r\n", "output": "2\r\n4\r\n5\r\n7\r\n8\r\n9\r\n"}]
false
stdio
null
true
545/B
545
B
Python 3
TESTS
0
15
0
178522689
n = int(input()) tree = [] # empty list for i in range(n): tree.append(list(map(int,input().split()))) s = 2 t = sorted(tree,reverse = True) t = sorted(tree) # arrange in ascending order for j in range(1,-1): a,b = tree[i] if x - tree[i-1][0] > b: s += 1 elif tree[i-1][0] -x >b: s += 1 ...
54
109
409,600
11151633
s=input() s2=input() s3='' f = True for i in range(len(s)): if s[i] == s2[i]: s3 +='1' elif f: s3 += s[i] f = not(f) else: s3 += s2[i] f = not(f) if f: print(s3) else: print('impossible')
Codeforces Round 303 (Div. 2)
CF
2,015
1
256
Equidistant String
Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance: We will define the distance between two strings s and t of the same length consisting of digits zero and one as the num...
The first line contains string s of length n. The second line contains string t of length n. The length of string n is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one.
Print a string of length n, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line "impossible" (without the quotes). If there are multiple possible answers, print any of them.
null
In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101.
[{"input": "0001\n1011", "output": "0011"}, {"input": "000\n111", "output": "impossible"}]
1,100
["greedy"]
54
[{"input": "0001\r\n1011\r\n", "output": "0011\r\n"}, {"input": "000\r\n111\r\n", "output": "impossible\r\n"}, {"input": "1010101011111110111111001111111111111111111111101101110111111111111110110110101011111110110111111101\r\n0101111111000100010100001100010101000000011000000000011011000001100100001110111011111000001110...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: s = f.readline().strip() t = f.readline().strip() n = len(s) assert len(t) == n with open(submission_path, 'r') as f: submission...
true
545/A
545
A
PyPy 3-64
TESTS
0
30
0
195250157
def solve(): n=int(input());a=[];ans=[] for i in range(n): r=list(map(int,input().split()));a.append(r) for index,i in enumerate(a): for j in i: if j==1 or j==3:break else:ans.append(index+1) print(*ans) if len(ans)>0 else print(0) solve()
35
31
0
205323724
n = int(input()) collisions = [] for i in range(n): row = list(map(int, input().split())) collisions.append(row) good_cars = set(range(n)) # initially all cars are good for i in range(n): for j in range(i+1, n): if collisions[i][j] == 1: good_cars.discard(i) # i-th car turned over, s...
Codeforces Round 303 (Div. 2)
CF
2,015
1
256
Toy Cars
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph. There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned ...
The first line contains integer n (1 ≤ n ≤ 100) — the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are - 1, and - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that ...
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
null
null
[{"input": "3\n-1 0 0\n0 -1 1\n0 2 -1", "output": "2\n1 3"}, {"input": "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1", "output": "0"}]
900
["implementation"]
35
[{"input": "3\r\n-1 0 0\r\n0 -1 1\r\n0 2 -1\r\n", "output": "2\r\n1 3 "}, {"input": "4\r\n-1 3 3 3\r\n3 -1 3 3\r\n3 3 -1 3\r\n3 3 3 -1\r\n", "output": "0\r\n"}, {"input": "1\r\n-1\r\n", "output": "1\r\n1 "}, {"input": "2\r\n-1 0\r\n0 -1\r\n", "output": "2\r\n1 2 "}, {"input": "2\r\n-1 1\r\n2 -1\r\n", "output": "1\r\n2 ...
false
stdio
null
true
600/E
600
E
PyPy 3-64
TESTS
2
46
0
230239871
def cin(r=1): if not r: return int(input()) if r == 1: return list(map(int, input().split())) return [list(map(int, input().split())), cin(r - 1)] n = cin(0) c = [0] + cin() e = [[] for i in range(n + 1)] res = [0] * (n + 1) def dfs(u): cnt = {c[u]: 1} for i in e[u]: x = ...
28
560
72,499,200
219697319
import sys input = sys.stdin.buffer.readline def merge(u, v): if len(colors[u]) < len(colors[v]): colors[v], colors[u] = colors[u], colors[v] _sum[v], _sum[u] = _sum[u], _sum[v] mx[v], mx[u] = mx[u], mx[v] for c, value in colors[v].items(): if c not in colors[u]: col...
Educational Codeforces Round 2
ICPC
2,015
2
256
Lomsat gelral
You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour. Let's call colour c dominating in the subtree of vertex v if there are no other colours that appear in the subtree of vertex v more times than colour c. So it's possible that two or more colours will be dominating in the subtree...
The first line contains integer n (1 ≤ n ≤ 105) — the number of vertices in the tree. The second line contains n integers ci (1 ≤ ci ≤ n), ci — the colour of the i-th vertex. Each of the next n - 1 lines contains two integers xj, yj (1 ≤ xj, yj ≤ n) — the edge of the tree. The first vertex is the root of the tree.
Print n integers — the sums of dominating colours for each vertex.
null
null
[{"input": "4\n1 2 3 4\n1 2\n2 3\n2 4", "output": "10 9 3 4"}, {"input": "15\n1 2 3 1 2 3 3 1 1 3 2 2 1 2 3\n1 2\n1 3\n1 4\n1 14\n1 15\n2 5\n2 6\n2 7\n3 8\n3 9\n3 10\n4 11\n4 12\n4 13", "output": "6 5 4 3 2 3 3 1 1 3 2 2 1 2 3"}]
2,300
["data structures", "dfs and similar", "dsu", "trees"]
28
[{"input": "4\r\n1 2 3 4\r\n1 2\r\n2 3\r\n2 4\r\n", "output": "10 9 3 4\r\n"}, {"input": "15\r\n1 2 3 1 2 3 3 1 1 3 2 2 1 2 3\r\n1 2\r\n1 3\r\n1 4\r\n1 14\r\n1 15\r\n2 5\r\n2 6\r\n2 7\r\n3 8\r\n3 9\r\n3 10\r\n4 11\r\n4 12\r\n4 13\r\n", "output": "6 5 4 3 2 3 3 1 1 3 2 2 1 2 3\r\n"}]
false
stdio
null
true
314/A
314
A
PyPy 3
TESTS
3
248
0
64365517
def IO(): import sys sys.stdout = open('output.txt', 'w') sys.stdin = open('input.txt', 'r') ###################### MAIN PROGRAM ##################### def main(): #IO() n, k = map(int, input().split()) a = list(map(int, input().split())) ans = list() run = int(0) deleted = 0 fo...
22
840
16,896,000
14704422
n, k = map(int, input().split()) c, v = 0, [] for i, a in enumerate(map(int, input().split())): j = i + 1 - len(v) d = c - (j - 1) * (n - j) * a if d < k: v.append(i + 1) n -= 1 else: c += a * (j - 1) print('\n'.join(map(str, v)))
Codeforces Round 187 (Div. 1)
CF
2,013
2
256
Sereja and Contest
During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants. Let's assume that n people took part in the contest. Let's assume that the participant who got the first place has rating a1, the second place participant has rating a2, ..., the ...
The first line contains two integers n, k (1 ≤ n ≤ 2·105, - 109 ≤ k ≤ 0). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — ratings of the participants in the initial table.
Print the numbers of participants in the order in which they were removed from the table. Print the initial numbers of the participants, that is, the numbers that the participants had in the initial table.
null
Consider the first test sample. 1. Initially the sequence of the contest participants' ratings equals [5, 3, 4, 1, 2]. You can use this sequence to calculate the sequence of rating changes: [0, -9, -13, 8, 14]. According to the problem statement, the application of the participant who won the second place will be cons...
[{"input": "5 0\n5 3 4 1 2", "output": "2\n3\n4"}, {"input": "10 -10\n5 5 1 7 5 1 2 4 9 2", "output": "2\n4\n5\n7\n8\n9"}]
1,600
["implementation"]
22
[{"input": "5 0\r\n5 3 4 1 2\r\n", "output": "2\r\n3\r\n4\r\n"}, {"input": "10 -10\r\n5 5 1 7 5 1 2 4 9 2\r\n", "output": "2\r\n4\r\n5\r\n7\r\n8\r\n9\r\n"}]
false
stdio
null
true
314/A
314
A
PyPy 3
TESTS
3
248
0
92461680
n, k = input().split() n = int(n) k = int(k) v = [] v.append(0) for aux in input().split(): aux = int(aux) v.append(aux) s = [] s.append(0) ant = 0 for i in range(1, n+1): if i==1: s.append(0) else: ant+=(v[i-1]*(i-2)) s.append(ant-((n-i)*v[i]*(i-1))) ans = [] cn = 0 for i in range(2, n+1): tam = len(ans)...
22
872
17,305,600
106177048
from sys import stdin,stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) for _ in range(1):#nmbr()): n,k=lst() a=lst() removed=0 positive_term=0 for i in range(1,n): negative_term=(i-removed)*a[i]*(n-i-1) if (positive_term-negative_term)...
Codeforces Round 187 (Div. 1)
CF
2,013
2
256
Sereja and Contest
During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants. Let's assume that n people took part in the contest. Let's assume that the participant who got the first place has rating a1, the second place participant has rating a2, ..., the ...
The first line contains two integers n, k (1 ≤ n ≤ 2·105, - 109 ≤ k ≤ 0). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — ratings of the participants in the initial table.
Print the numbers of participants in the order in which they were removed from the table. Print the initial numbers of the participants, that is, the numbers that the participants had in the initial table.
null
Consider the first test sample. 1. Initially the sequence of the contest participants' ratings equals [5, 3, 4, 1, 2]. You can use this sequence to calculate the sequence of rating changes: [0, -9, -13, 8, 14]. According to the problem statement, the application of the participant who won the second place will be cons...
[{"input": "5 0\n5 3 4 1 2", "output": "2\n3\n4"}, {"input": "10 -10\n5 5 1 7 5 1 2 4 9 2", "output": "2\n4\n5\n7\n8\n9"}]
1,600
["implementation"]
22
[{"input": "5 0\r\n5 3 4 1 2\r\n", "output": "2\r\n3\r\n4\r\n"}, {"input": "10 -10\r\n5 5 1 7 5 1 2 4 9 2\r\n", "output": "2\r\n4\r\n5\r\n7\r\n8\r\n9\r\n"}]
false
stdio
null
true
280/C
280
C
Python 3
TESTS
1
60
0
193944668
# LUOGU_RID: 102285147 import sys sys.setrecursionlimit(10**6) (n, ), *a = [[*map(int, s.split())] for s in open(0)] g = [[] for _ in range(n)] for u, v in a: u -= 1 v -= 1 g[u] += v, g[v] += u, d = [1] * n def dfs(u): for v in g[u]: if d[v] == 1 and v != 1: d[v] = d[u] + 1 ...
52
280
16,076,800
198355800
import io import os input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def solve(): n = int(input()) adj = [[] for _ in range(n)] for _ in range(n-1): a, b = map(int, input().split()) a -= 1 b -= 1 adj[a].append(b) adj[b].append(a) d = [0] * n d[...
Codeforces Round 172 (Div. 1)
CF
2,013
1
256
Game on Tree
Momiji has got a rooted tree, consisting of n nodes. The tree nodes are numbered by integers from 1 to n. The root has number 1. Momiji decided to play a game on this tree. The game consists of several steps. On each step, Momiji chooses one of the remaining tree nodes (let's denote it by v) and removes all the subtre...
The first line contains integer n (1 ≤ n ≤ 105) — the number of nodes in the tree. The next n - 1 lines contain the tree edges. The i-th line contains integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi) — the numbers of the nodes that are connected by the i-th edge. It is guaranteed that the given graph is a tree.
Print a single real number — the expectation of the number of steps in the described game. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.
null
In the first sample, there are two cases. One is directly remove the root and another is remove the root after one step. Thus the expected steps are: 1 × (1 / 2) + 2 × (1 / 2) = 1.5 In the second sample, things get more complex. There are two cases that reduce to the first sample, and one case cleaned at once. Thus t...
[{"input": "2\n1 2", "output": "1.50000000000000000000"}, {"input": "3\n1 2\n1 3", "output": "2.00000000000000000000"}]
2,200
["implementation", "math", "probabilities", "trees"]
52
[{"input": "2\r\n1 2\r\n", "output": "1.50000000000000000000\r\n"}, {"input": "3\r\n1 2\r\n1 3\r\n", "output": "2.00000000000000000000\r\n"}, {"input": "10\r\n1 2\r\n2 3\r\n3 4\r\n1 5\r\n2 6\r\n6 7\r\n4 8\r\n6 9\r\n9 10\r\n", "output": "3.81666666666666690000\r\n"}, {"input": "6\r\n1 3\r\n2 4\r\n5 6\r\n3 6\r\n5 4\r\n",...
false
stdio
import sys def read_number(path): with open(path, 'r') as f: lines = f.readlines() if len(lines) != 1: return None line = lines[0].strip() try: return float(line) except: return None def main(): input_path = sys.argv[1] output_pat...
true
962/D
962
D
Python 3
TESTS
10
576
13,004,800
38591601
def appendDict(dict, key, value): if key in dict: dict[key] += [value] else: dict[key] = [value] def main(): input() numbers = list(map(int, input().split())) dict = {} idx = 0 for number in numbers: appendDict(dict, number, idx) idx += 1 while len(di...
26
140
27,648,000
229880624
input() a = {} for i in list(map(int,input().split())): while i in a: del a[i] i *= 2 a[i] = 1 print(len(a)) print(*a)# 1698329597.4687905
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Merge Equals
You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $$$x$$$ that occurs in the array $$$2$$$ or more times. Take the first two occurrences of $$$x$$$ in this array (the two leftmost occurrences). Remove the left ...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 150\,000$$$) — the number of elements in the array. The second line contains a sequence from $$$n$$$ elements $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{9}$$$) — the elements of the array.
In the first line print an integer $$$k$$$ — the number of elements in the array after all the performed operations. In the second line print $$$k$$$ integers — the elements of the array after all the performed operations.
null
The first two examples were considered in the statement. In the third example all integers in the given array are distinct, so it will not change.
[{"input": "7\n3 4 1 2 2 1 1", "output": "4\n3 8 2 1"}, {"input": "5\n1 1 3 1 1", "output": "2\n3 4"}, {"input": "5\n10 40 20 50 30", "output": "5\n10 40 20 50 30"}]
1,600
["data structures", "implementation"]
26
[{"input": "7\r\n3 4 1 2 2 1 1\r\n", "output": "4\r\n3 8 2 1 \r\n"}, {"input": "5\r\n1 1 3 1 1\r\n", "output": "2\r\n3 4 \r\n"}, {"input": "5\r\n10 40 20 50 30\r\n", "output": "5\r\n10 40 20 50 30 \r\n"}, {"input": "100\r\n10 10 15 12 15 13 15 12 10 10 15 11 13 14 13 14 10 13 12 10 14 12 13 11 14 15 12 11 11 15 12 12 1...
false
stdio
null
true
545/A
545
A
Python 3
TESTS
0
30
0
219937961
n = int(input()) s = 1 m = [] for i in range(n): row = list(map(int, input().split())) m.append(row) ch = '' for i in range(n): contains_1_or_3 = False for j in range(n): if m[i][j] == 1 or m[i][j] == 3: contains_1_or_3 = True break if not contains_1_or_3: ...
35
46
0
187908142
n,a=int(input()),[] for i in range(n): x = list(map(int, input().split(" "))) if 1 not in x and 3 not in x: a.append(i+1) print(len(a)) print(*sorted(a))
Codeforces Round 303 (Div. 2)
CF
2,015
1
256
Toy Cars
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph. There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned ...
The first line contains integer n (1 ≤ n ≤ 100) — the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are - 1, and - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that ...
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
null
null
[{"input": "3\n-1 0 0\n0 -1 1\n0 2 -1", "output": "2\n1 3"}, {"input": "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1", "output": "0"}]
900
["implementation"]
35
[{"input": "3\r\n-1 0 0\r\n0 -1 1\r\n0 2 -1\r\n", "output": "2\r\n1 3 "}, {"input": "4\r\n-1 3 3 3\r\n3 -1 3 3\r\n3 3 -1 3\r\n3 3 3 -1\r\n", "output": "0\r\n"}, {"input": "1\r\n-1\r\n", "output": "1\r\n1 "}, {"input": "2\r\n-1 0\r\n0 -1\r\n", "output": "2\r\n1 2 "}, {"input": "2\r\n-1 1\r\n2 -1\r\n", "output": "1\r\n2 ...
false
stdio
null
true
962/D
962
D
Python 3
TESTS
10
358
20,992,000
37257591
from collections import defaultdict from heapq import heappush , heappop def process() : n = int(input()) l = [int(x) for x in input().split(' ')] sorted_list = [] d = defaultdict(list) for index,i in enumerate(l) : heappush(d[i],index) for i in d.keys() : heappush(sorted_list...
26
155
29,696,000
193672717
n=int(input()) a=list(map(int,input().split())) d={} for i in range(n): while a[i] in d: del d[a[i]] a[i]*=2 d[a[i]]=i print(len(d)) print(*d,sep=" ")
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Merge Equals
You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $$$x$$$ that occurs in the array $$$2$$$ or more times. Take the first two occurrences of $$$x$$$ in this array (the two leftmost occurrences). Remove the left ...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 150\,000$$$) — the number of elements in the array. The second line contains a sequence from $$$n$$$ elements $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{9}$$$) — the elements of the array.
In the first line print an integer $$$k$$$ — the number of elements in the array after all the performed operations. In the second line print $$$k$$$ integers — the elements of the array after all the performed operations.
null
The first two examples were considered in the statement. In the third example all integers in the given array are distinct, so it will not change.
[{"input": "7\n3 4 1 2 2 1 1", "output": "4\n3 8 2 1"}, {"input": "5\n1 1 3 1 1", "output": "2\n3 4"}, {"input": "5\n10 40 20 50 30", "output": "5\n10 40 20 50 30"}]
1,600
["data structures", "implementation"]
26
[{"input": "7\r\n3 4 1 2 2 1 1\r\n", "output": "4\r\n3 8 2 1 \r\n"}, {"input": "5\r\n1 1 3 1 1\r\n", "output": "2\r\n3 4 \r\n"}, {"input": "5\r\n10 40 20 50 30\r\n", "output": "5\r\n10 40 20 50 30 \r\n"}, {"input": "100\r\n10 10 15 12 15 13 15 12 10 10 15 11 13 14 13 14 10 13 12 10 14 12 13 11 14 15 12 11 11 15 12 12 1...
false
stdio
null
true
717/D
717
D
PyPy 3
TESTS
1
249
4,915,200
52463904
from sys import stdin,stdout from decimal import Decimal from functools import reduce n,x = map(int,stdin.readline().split()) print(1 - reduce(lambda x,y: x +y*y,map(Decimal,stdin.readline().split()),Decimal(0)))
11
249
4,915,200
29285114
import sys #sys.stdin=open("data.txt") input=sys.stdin.readline n,x=map(int,input().split()) def mult(a,b): # compute a*b c=[0]*128 for i in range(128): for j in range(128): c[i^j]+=a[i]*b[j] return c def quickpow(a,b): # compute a**b if b==1: return a if b&1: ...
Bubble Cup 9 - Finals [Online Mirror]
ICPC
2,016
1
256
Dexterina’s Lab
Dexterina and Womandark have been arch-rivals since they’ve known each other. Since both are super-intelligent teenage girls, they’ve always been trying to solve their disputes in a peaceful and nonviolent way. After god knows how many different challenges they’ve given to one another, their score is equal and they’re ...
The first line of the input contains two integers n (1 ≤ n ≤ 109) and x (1 ≤ x ≤ 100) — the number of heaps and the maximum number of objects in a heap, respectively. The second line contains x + 1 real numbers, given with up to 6 decimal places each: P(0), P(1), ... , P(X). Here, P(i) is the probability of a heap havi...
Output a single real number, the probability that the first player wins. The answer will be judged as correct if it differs from the correct answer by at most 10 - 6.
null
null
[{"input": "2 2\n0.500000 0.250000 0.250000", "output": "0.62500000"}]
1,900
["games", "matrices", "probabilities"]
11
[{"input": "2 2\r\n0.500000 0.250000 0.250000\r\n", "output": "0.62500000\r\n"}, {"input": "9 9\r\n0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000\r\n", "output": "0.93687014\r\n"}, {"input": "1000001 5\r\n0.000000 0.300000 0.000000 0.500000 0.000000 0.200000\r\n", "output": "1...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] try: with open(correct_output_path, 'r') as f: correct_line = f.read().strip() correct_val = float(correct_line) except: print(0) retur...
true
177/D1
177
D2
Python 3
TESTS2
2
124
307,200
109287019
n,m,c=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) sum=0 for i in range(n): if i<m: sum=(sum+b[i])%c if i>=n-m+1: sum=(sum+b[i-(n-m+1)])%c a[i]=(a[i]+sum)%c print(' '.join(map(str,a)))
12
124
307,200
4855563
n, m, c = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) s, k = 0, n - m for i in range(n): if i < m: s += b[i] a[i] = (a[i] + s) % c if i >= k: s -= b[i - k] print(' '.join(str(i) for i in a))
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
773/B
773
B
Python 3
TESTS
0
77
0
48309925
n = int(input()) Mines =[[int(x) for x in input().split(' ')] for y in range(n)] diff =[] for i in range(n): diff.append(abs( Mines[i][0] - Mines[i][1] )) print(diff.index(max(diff))+1)
40
62
307,200
26938082
from sys import stdin, stdout fractionBoundaries = [1/2,1/4,1/8,1/16,1/32,0] scoreList = [500,1000,1500,2000,2500,3000] def assessScores(n,Vsol,Psol,solvers): vScore=0 pScore=0 for i in range(5): for j in range(6): if solvers[i]/n>fractionBoundaries[j]: qnScore=scoreLi...
VK Cup 2017 - Round 3
CF
2,017
2
256
Dynamic Problem Scoring
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends...
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by partic...
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
null
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 42...
[{"input": "2\n5 15 40 70 115\n50 45 40 30 15", "output": "2"}, {"input": "3\n55 80 10 -1 -1\n15 -1 79 60 -1\n42 -1 13 -1 -1", "output": "3"}, {"input": "5\n119 119 119 119 119\n0 0 0 0 -1\n20 65 12 73 77\n78 112 22 23 11\n1 78 60 111 62", "output": "27"}, {"input": "4\n-1 20 40 77 119\n30 10 73 50 107\n21 29 -1 64 98\...
2,000
["brute force", "greedy"]
40
[{"input": "2\r\n5 15 40 70 115\r\n50 45 40 30 15\r\n", "output": "2\r\n"}, {"input": "3\r\n55 80 10 -1 -1\r\n15 -1 79 60 -1\r\n42 -1 13 -1 -1\r\n", "output": "3\r\n"}, {"input": "5\r\n119 119 119 119 119\r\n0 0 0 0 -1\r\n20 65 12 73 77\r\n78 112 22 23 11\r\n1 78 60 111 62\r\n", "output": "27\r\n"}, {"input": "4\r\n-1 ...
false
stdio
null
true
965/E
965
E
Python 3
TESTS
0
15
0
158708882
n = int(input()) c="ode" d="aacada" v="resistance" for i in range(n): m = str(input()) if m == c: print (6) if m == d: print(11) if m == v: print(3)
24
156
22,937,600
177672519
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def trie(): G, cnt = [[-1] * 26], [0] return G, cnt def insert(s): j = 0 for i in s: if not G[j][i - 97] ^ -1: G[j][i - 97] = len(cnt) G.append([-1] * 26) cnt.append(0) ...
Codeforces Round 476 (Div. 2) [Thanks, Telegram!]
CF
2,018
1
256
Short Code
Arkady's code contains $$$n$$$ variables. Each variable has a unique name consisting of lowercase English letters only. One day Arkady decided to shorten his code. He wants to replace each variable name with its non-empty prefix so that these new names are still unique (however, a new name of some variable can coincid...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of variables. The next $$$n$$$ lines contain variable names, one per line. Each name is non-empty and contains only lowercase English letters. The total length of these strings is not greater than $$$10^5$$$. The variable names are ...
Print a single integer — the minimum possible total length of new variable names.
null
In the first example one of the best options is to shorten the names in the given order as "cod", "co", "c". In the second example we can shorten the last name to "aac" and the first name to "a" without changing the other names.
[{"input": "3\ncodeforces\ncodehorses\ncode", "output": "6"}, {"input": "5\nabba\nabb\nab\naa\naacada", "output": "11"}, {"input": "3\ntelegram\ndigital\nresistance", "output": "3"}]
2,200
["data structures", "dp", "greedy", "strings", "trees"]
24
[{"input": "3\r\ncodeforces\r\ncodehorses\r\ncode\r\n", "output": "6\r\n"}, {"input": "5\r\nabba\r\nabb\r\nab\r\naa\r\naacada\r\n", "output": "11\r\n"}, {"input": "3\r\ntelegram\r\ndigital\r\nresistance\r\n", "output": "3\r\n"}, {"input": "1\r\na\r\n", "output": "1\r\n"}, {"input": "10\r\naaaba\r\nbabba\r\nbbba\r\naaab...
false
stdio
null
true
610/D
610
D
Python 3
TESTS
0
15
0
215716364
# LUOGU_RID: 117562212 n = int(input()) rows = set() cols = set() for _ in range(n): x1, y1, x2, y2 = map(int, input().split()) # 将起点和终点所在的行号添加到 rows 集合中 rows.add(y1) rows.add(y2) # 将起点和终点所在的列号添加到 cols 集合中 cols.add(x1) cols.add(x2) # 计算涂色的方格总数 painted_cells = len(rows) * len(cols) print(p...
47
1,278
54,681,600
216911246
# i'm from jasnah, do not ban me from sys import stdin from itertools import repeat from collections import defaultdict num_rectangles = int(stdin.readline()) horizontal_segments = defaultdict(list) vertical_segments = defaultdict(list) unique_y_values = set() events = defaultdict(list) for _ in repeat(None, num_rect...
Codeforces Round 337 (Div. 2)
CF
2,015
2
256
Vika and Segments
Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew n black horizontal and vertical segments parallel to the coordinate axes. All segments have width equal to 1 square, that means every segment occupy some set of neighbo...
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of segments drawn by Vika. Each of the next n lines contains four integers x1, y1, x2 and y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — the coordinates of the endpoints of the segments drawn by Vika. It is guaranteed that all the segments ar...
Print the number of cells painted by Vika. If a cell was painted more than once, it should be calculated exactly once in the answer.
null
In the first sample Vika will paint squares (0, 1), (1, 1), (2, 1), (1, 2), (1, 3), (1, 4), (0, 3) and (2, 3).
[{"input": "3\n0 1 2 1\n1 4 1 2\n0 3 2 3", "output": "8"}, {"input": "4\n-2 -1 2 -1\n2 1 -2 1\n-1 -2 -1 2\n1 2 1 -2", "output": "16"}]
2,300
["constructive algorithms", "data structures", "geometry", "two pointers"]
47
[{"input": "3\r\n0 1 2 1\r\n1 4 1 2\r\n0 3 2 3\r\n", "output": "8\r\n"}, {"input": "4\r\n-2 -1 2 -1\r\n2 1 -2 1\r\n-1 -2 -1 2\r\n1 2 1 -2\r\n", "output": "16\r\n"}, {"input": "1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "10\r\n-357884841 -999999905 -357884841 999999943\r\n-130177221 999999983 -130177221 -999999974...
false
stdio
null
true
852/G
852
G
Python 3
TESTS
2
77
716,800
105063852
import re,sys r=sys.stdin.readline N,M=map(int,r().split()) words=[] for _ in range(N): words.append(r().strip()) for _ in range(M): pattern=r().strip() p=re.compile(pattern.replace("?",".?")) cnt=0 for word in words: if re.match(p,word): cnt+=1 print(cnt)
15
872
31,846,400
105100981
import sys from itertools import product from collections import defaultdict r=sys.stdin.readline N,M=map(int,r().split()) words=defaultdict(int) tb=['a','b','c','d','e'] st=set() cnt=0 res="" def dfs(u): global res,cnt if u==l: if res in st: return if words[res]>0: cnt+=words[res] ...
Bubble Cup X - Finals [Online Mirror]
ICPC
2,017
2
256
Bathroom terminal
Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is conn...
The first line of input contains two integers N and M (1 ≤ N ≤ 100 000, 1 ≤ M ≤ 5000), representing the number of words and patterns respectively. The next N lines represent each word, and after those N lines, following M lines represent each pattern. Each word and each pattern has a maximum length L (1 ≤ L ≤ 50). E...
Output contains M lines and each line consists of one integer, representing the number of words that match the corresponding pattern.
null
If we switch '?' with 'b', 'e' and with empty character, we get 'abc', 'aec' and 'ac' respectively.
[{"input": "3 1\nabc\naec\nac\na?c", "output": "3"}]
1,700
["implementation"]
15
[{"input": "3 1\r\nabc\r\naec\r\nac\r\na?c\r\n", "output": "3\r\n"}, {"input": "22 2\r\naaaab\r\naaabb\r\naabab\r\naabbb\r\nabaab\r\nababb\r\nabbab\r\nabbbb\r\naaab\r\naabb\r\nabab\r\nabbb\r\naab\r\nabb\r\nab\r\ncccd\r\nccdd\r\ncdcd\r\ncddd\r\nccd\r\ncdd\r\ncd\r\na???b\r\nc??d\r\n", "output": "15\r\n7\r\n"}, {"input": ...
false
stdio
null
true
852/E
852
E
Python 3
TESTS
2
30
0
175594537
import math;R,G=lambda:map(int,input().split()),range n,=R();g=[[] for _ in G(n+1)];M=10**9+7 p=lambda i,n:sum(math.comb(n,k)%M for k in range(i,n+1,2)) for _ in G(n-1):u,v=R();g[u]+=[v];g[v]+=[u] def f(u0,pre0): c1=c2=1;q=[(u0,pre0)];stk=[];nodes=[1]*(n+1) while q: u,pre=q.pop();stk+=[(u,pre)] for v in g[u...
12
265
8,294,400
122679404
def quick_mod(b, p) : s = 1 while (p != 0) : if (p & 1) : s = s * b % mod p = p // 2 b = b * b % mod return s s = input().split() n = int(s[0]) N = 100000 mod = 1000000007 enter = [] for i in range(1, N + 5) : enter.append(0) for i in range(1, n) : s1 = input().split() en...
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
177/D1
177
D1
PyPy 3-64
TESTS1
2
278
10,240,000
147155660
import string def main_function(): n, m, c = [int(i) for i in input().split(" ")] a = [int(i) for i in input().split(" ")] b = [int(i) for i in input().split(" ")] b_s = [b[0]] reversed_b_s = [b[-1]] for i in range(1, len(b)): b_s.append(b_s[-1] + b[i]) j = len(b) - i - 1 ...
12
124
1,433,600
161711770
import sys input = sys.stdin.readline n, m, c = map(int, input().split()) w = list(map(int, input().split())) q = list(map(int, input().split())) x = 0 a = n-m+1 for i in range(n): if i < m: x += q[i] if i >= a: x -= q[i-a] if i-a < m else 0 w[i] = (w[i] + x)%c print(' '.join(map(str, w)...
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
77/A
77
A
PyPy 3-64
TESTS
4
124
0
211115394
n=int(input()) dict={} l=['Anka','Chapay','Cleo','Troll','Dracul','Snowy','Hexadecimal'] for j in range(7): dict[l[j]]=j arr = [[0 for i in range(7)] for j in range(7)] for i in range(n): f1,x,f2=map(str,input().split()) arr[dict[f1]][dict[f2]]=1 a,b,c=map(int,input().split()) if(n==3 and a!=b): print(3...
64
686
204,800
132206105
import itertools r = list(map(list,itertools.permutations([1,2,3,4,5,6,7]))) #print(r) m={"Anka":1,"Chapay":2,"Cleo":3,"Troll":4,"Dracul":5,"Snowy":6,"Hexadecimal":7} def hash(a,b): return str(a)+"-"+str(b) n=int(input()) s = set() for i in range(n): q,e,p=map(str,input().split()) q = m[q] p = m[p]...
Codeforces Beta Round 69 (Div. 1 Only)
CF
2,011
2
256
Heroes
The year of 2012 is coming... According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us...
The first line contains a single non-negative integer n (0 ≤ n ≤ 42) — amount of liking between the heroes. Next n lines describe liking in the form "p likes q", meaning that the hero p likes the hero q (p ≠ q). Every liking is described in the input exactly once, no hero likes himself. In the last line are given th...
Print two integers — the minimal difference in the experience between two heroes who will receive the maximum and minimum number of experience points, and the maximal total amount of liking in teams (the number of friendships between heroes that end up in one team). When calculating the second answer, the team divisio...
null
A note to first example: it the first team should be Dracul, Troll and Anka, in the second one Hexadecimal and Snowy, and in the third Cleo и Chapay.
[{"input": "3\nTroll likes Dracul\nDracul likes Anka\nSnowy likes Hexadecimal\n210 200 180", "output": "30 3"}, {"input": "2\nAnka likes Chapay\nChapay likes Anka\n10000 50 50", "output": "1950 2"}]
1,400
["brute force", "implementation"]
64
[{"input": "3\r\nTroll likes Dracul\r\nDracul likes Anka\r\nSnowy likes Hexadecimal\r\n210 200 180\r\n", "output": "30 3\r\n"}, {"input": "2\r\nAnka likes Chapay\r\nChapay likes Anka\r\n10000 50 50\r\n", "output": "1950 2\r\n"}, {"input": "11\r\nSnowy likes Dracul\r\nAnka likes Dracul\r\nChapay likes Snowy\r\nHexadecim...
false
stdio
null
true
292/A
292
A
Python 3
TESTS
0
122
7,475,200
129756009
import math import string def special_printer(l): for i in l: print(i) def main_function(): n = int(input()) t_c = [[int(i) for i in input().split(" ")] for j in range(n)] sums = sum([i[0] for i in t_c]) current_time = 0 max_messages = 0 current_messages = 0 for i in range(le...
38
154
307,200
106050952
if __name__ == '__main__': n = int(input()) a = [[int(i) for i in input().split()] for _ in range(n)] mx, cnt = a[0][1], a[0][1] for i in range(1, n): t = a[i][0] - a[i - 1][0] cnt -= t if cnt <= 0:cnt = 0 cnt += a[i][1] mx = max(mx, cnt) print(cnt + a[n - 1]...
Croc Champ 2013 - Round 1
CF
2,013
2
256
SMSC
Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC. For that, he asked to give him the statistics of the performance of the SMSC for some period of time. In ...
The first line contains a single integer n (1 ≤ n ≤ 103) — the number of tasks of the SMSC. Next n lines contain the tasks' descriptions: the i-th line contains two space-separated integers ti and ci (1 ≤ ti, ci ≤ 106) — the time (the second) when the i-th task was received and the number of messages to send, correspon...
In a single line print two space-separated integers — the time when the last text message was sent and the maximum queue size at a certain moment of time.
null
In the first test sample: - second 1: the first message has appeared in the queue, the queue's size is 1; - second 2: the first message is sent, the second message has been received, the queue's size is 1; - second 3: the second message is sent, the queue's size is 0, Thus, the maximum size of the queue is 1, the las...
[{"input": "2\n1 1\n2 1", "output": "3 1"}, {"input": "1\n1000000 10", "output": "1000010 10"}, {"input": "3\n3 3\n4 3\n5 3", "output": "12 7"}]
1,100
["implementation"]
38
[{"input": "2\r\n1 1\r\n2 1\r\n", "output": "3 1\r\n"}, {"input": "1\r\n1000000 10\r\n", "output": "1000010 10\r\n"}, {"input": "3\r\n3 3\r\n4 3\r\n5 3\r\n", "output": "12 7\r\n"}, {"input": "1\r\n1 1\r\n", "output": "2 1\r\n"}, {"input": "2\r\n1 11\r\n100 10\r\n", "output": "110 11\r\n"}, {"input": "4\r\n1 10\r\n2 9\r...
false
stdio
null
true
292/A
292
A
Python 3
TESTS
0
60
0
230350096
n = int(input()) for _ in range(n): f, s = [int(a) for a in input().split()] f1 = 0 f2 = 0 if n == 1: print(f + s, s) exit() else: f1 += f if _ != n-1: f2 += f print(f1, f2)
38
154
6,963,200
123176535
i = int(input()) t = q= m=0 for x in range(i): a,b = map(int,input().split()) q -= a-t if q < 0: q = 0 q += b if q > m: m = q t = a t += q print(t,m)
Croc Champ 2013 - Round 1
CF
2,013
2
256
SMSC
Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC. For that, he asked to give him the statistics of the performance of the SMSC for some period of time. In ...
The first line contains a single integer n (1 ≤ n ≤ 103) — the number of tasks of the SMSC. Next n lines contain the tasks' descriptions: the i-th line contains two space-separated integers ti and ci (1 ≤ ti, ci ≤ 106) — the time (the second) when the i-th task was received and the number of messages to send, correspon...
In a single line print two space-separated integers — the time when the last text message was sent and the maximum queue size at a certain moment of time.
null
In the first test sample: - second 1: the first message has appeared in the queue, the queue's size is 1; - second 2: the first message is sent, the second message has been received, the queue's size is 1; - second 3: the second message is sent, the queue's size is 0, Thus, the maximum size of the queue is 1, the las...
[{"input": "2\n1 1\n2 1", "output": "3 1"}, {"input": "1\n1000000 10", "output": "1000010 10"}, {"input": "3\n3 3\n4 3\n5 3", "output": "12 7"}]
1,100
["implementation"]
38
[{"input": "2\r\n1 1\r\n2 1\r\n", "output": "3 1\r\n"}, {"input": "1\r\n1000000 10\r\n", "output": "1000010 10\r\n"}, {"input": "3\r\n3 3\r\n4 3\r\n5 3\r\n", "output": "12 7\r\n"}, {"input": "1\r\n1 1\r\n", "output": "2 1\r\n"}, {"input": "2\r\n1 11\r\n100 10\r\n", "output": "110 11\r\n"}, {"input": "4\r\n1 10\r\n2 9\r...
false
stdio
null
true
840/A
840
A
Python 3
TESTS
2
108
0
61280664
import sys num_n = int(sys.stdin.readline()) A = sys.stdin.readline()[:-1].split(" ") B = sys.stdin.readline()[:-1].split(" ") B1 = B.copy() A.sort() B.sort() umap = {} for num in B: if num in umap: umap[num].append(A.pop()) else: umap[num] = list([A.pop()]) for num in B1: print(umap[num].pop(), end=' ')
48
514
42,291,200
164162418
import sys input = sys.stdin.readline n = int(input()) w = sorted(map(int, input().split()), reverse=True) s = sorted(enumerate(map(int, input().split())), key=lambda x:x[1]) d = [0]*n for i in range(n): d[s[i][0]] = w[i] print(' '.join(map(str, d)))
Codeforces Round 429 (Div. 1)
CF
2,017
2
256
Leha and Function
Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) — mathematical expectation of the minimal element among all k-element subsets. But only function does not interest him. He wan...
First line of input data contains single integer m (1 ≤ m ≤ 2·105) — length of arrays A and B. Next line contains m integers a1, a2, ..., am (1 ≤ ai ≤ 109) — array A. Next line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 109) — array B.
Output m integers a'1, a'2, ..., a'm — array A' which is permutation of the array A.
null
null
[{"input": "5\n7 3 5 3 4\n2 1 3 2 3", "output": "4 7 3 5 3"}, {"input": "7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2", "output": "2 6 4 5 8 8 6"}]
1,300
["combinatorics", "greedy", "math", "number theory", "sortings"]
48
[{"input": "5\r\n7 3 5 3 4\r\n2 1 3 2 3\r\n", "output": "4 7 3 5 3\r\n"}, {"input": "7\r\n4 6 5 8 8 2 6\r\n2 1 2 2 1 1 2\r\n", "output": "2 6 4 5 8 8 6\r\n"}]
false
stdio
import sys def main(input_path, output_path, submission_output_path): with open(input_path) as f: m = int(f.readline()) A = list(map(int, f.readline().split())) B = list(map(int, f.readline().split())) with open(submission_output_path) as f: submission = list(map(int, f.readlin...
true
690/A3
690
A3
Python 3
TESTS
2
62
0
19198034
def main(): T = int(input()) for _ in range(T): n, r = readints() nums = readints() print(sol(nums, r)) def readints(): return [int(fld) for fld in input().strip().split()] def sol(nums, r): return 1 + (sum(nums) - r) % (len(nums) + 1) main()
6
733
0
18999709
T = int(input()) for t in range(T): N, R = map(int, input().split()) print(1 + (R - sum(map(int, input().split()))) % N)
Helvetic Coding Contest 2016 online mirror (teams, unrated)
ICPC
2,016
4
256
Collective Mindsets (hard)
Heidi got one brain, thumbs up! But the evening isn't over yet and one more challenge awaits our dauntless agent: after dinner, at precisely midnight, the N attendees love to play a very risky game... Every zombie gets a number ni (1 ≤ ni ≤ N) written on his forehead. Although no zombie can see his own number, he can ...
The first line of input contains a single integer T (1 ≤ T ≤ 50000): the number of scenarios for which you have to make a guess. The T scenarios follow, described on two lines each: - The first line holds two integers, N (2 ≤ N ≤ 6), the number of attendees, and R (1 ≤ R ≤ N), the rank of the zombie who has to make t...
For every scenario, output a single integer: the number that the zombie of rank R shall guess, based on the numbers ni on his N - 1 fellows' foreheads.
null
For instance, if there were N = 2 two attendees, a successful strategy could be: - The zombie of rank 1 always guesses the number he sees on the forehead of the zombie of rank 2. - The zombie of rank 2 always guesses the opposite of the number he sees on the forehead of the zombie of rank 1.
[{"input": "4\n2 1\n1\n2 2\n1\n2 1\n2\n2 2\n2", "output": "1\n2\n2\n1"}, {"input": "2\n5 2\n2 2 2 2\n6 4\n3 2 6 1 2", "output": "5\n2"}]
2,400
[]
6
[{"input": "4\r\n2 1\r\n1\r\n2 2\r\n1\r\n2 1\r\n2\r\n2 2\r\n2\r\n", "output": "1\r\n2\r\n2\r\n1\r\n"}, {"input": "4\r\n2 1\r\n1\r\n2 2\r\n1\r\n2 1\r\n2\r\n2 2\r\n2\r\n", "output": "1\r\n2\r\n2\r\n1\r\n"}, {"input": "27\r\n3 1\r\n1 1\r\n3 2\r\n1 1\r\n3 3\r\n1 1\r\n3 1\r\n2 1\r\n3 2\r\n2 1\r\n3 3\r\n2 1\r\n3 1\r\n3 1\r\n...
false
stdio
import sys from itertools import product def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input scenarios scenarios = [] with open(input_path, 'r') as f: T = int(f.readline()) for _ in range(T): line1 = f.readline()...
true
963/C
963
C
Python 3
TESTS
0
61
7,065,600
37554862
import math q = int(input()) l, A, B = 0, 0, 0 for i in range(q): v = input().split() l += int(v[2]) A += int(v[0]) * int(v[2]) B += int(v[1]) * int(v[2]) r = 0 d = [] for i in range(1 , int(math.sqrt(l)) + 1): if l % i == 0: n = i m = int(l / i) if A % n == 0 and B % m == ...
80
1,294
132,300,800
220705287
from math import gcd num_elements = int(input()) a_vals = [0] * (3000001) b_vals = [0] * (3000001) c_vals = [0] * (3000001) f1_map = {} f2_map = {} sum_c = 0 gcd_c = 0 for i in range(1, num_elements+1): a_vals[i], b_vals[i], c_vals[i] = map(int, input().split()) if a_vals[i] not in f1_map: f1_m...
Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 1)
CF
2,018
2
256
Cutting Rectangle
A rectangle with sides $$$A$$$ and $$$B$$$ is cut into rectangles with cuts parallel to its sides. For example, if $$$p$$$ horizontal and $$$q$$$ vertical cuts were made, $$$(p + 1) \cdot (q + 1)$$$ rectangles were left after the cutting. After the cutting, rectangles were of $$$n$$$ different types. Two rectangles are...
The first line consists of a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^{5}$$$) — amount of different types of rectangles left after cutting the initial rectangle. The next $$$n$$$ lines each consist of three integers $$$w_{i}, h_{i}, c_{i}$$$ $$$(1 \leq w_{i}, h_{i}, c_{i} \leq 10^{12})$$$ — the lengths of t...
Output one integer — the answer to the problem.
null
In the first sample there are three suitable pairs: $$$(1; 9)$$$, $$$(3; 3)$$$ and $$$(9; 1)$$$. In the second sample case there are 6 suitable pairs: $$$(2; 220)$$$, $$$(4; 110)$$$, $$$(8; 55)$$$, $$$(10; 44)$$$, $$$(20; 22)$$$ and $$$(40; 11)$$$. Here the sample of cut for $$$(20; 22)$$$. The third sample has no s...
[{"input": "1\n1 1 9", "output": "3"}, {"input": "2\n2 3 20\n2 4 40", "output": "6"}, {"input": "2\n1 2 5\n2 3 5", "output": "0"}]
2,600
["brute force", "math", "number theory"]
80
[{"input": "1\r\n1 1 9\r\n", "output": "3\r\n"}, {"input": "2\r\n2 3 20\r\n2 4 40\r\n", "output": "6\r\n"}, {"input": "2\r\n1 2 5\r\n2 3 5\r\n", "output": "0\r\n"}]
false
stdio
null
true
318/B
318
B
PyPy 3-64
TESTS
1
122
0
226690783
s=input() c=0 res=0 l = s.split("heavy") for i in l: res+= l.count("metal")*c c+=1 print(res)
30
218
11,366,400
224595189
n = input() l = [] m = [] def bi(arr,val): l = 0 r = len(arr)-1 okay = False ans = 0 while r>=l: m = (r+l)//2 if arr[m]>=val: ans = m r = m-1 okay = True else: l = m+1 if okay: return ans else: ret...
Codeforces Round 188 (Div. 2)
CF
2,013
2
256
Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
Input contains a single non-empty string consisting of the lowercase Latin alphabet letters. Length of this string will not be greater than 106 characters.
Print exactly one number — the number of powerful substrings of the given string. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
null
In the first sample the string "heavymetalisheavymetal" contains powerful substring "heavymetal" twice, also the whole string "heavymetalisheavymetal" is certainly powerful. In the second sample the string "heavymetalismetal" contains two powerful substrings: "heavymetal" and "heavymetalismetal".
[{"input": "heavymetalisheavymetal", "output": "3"}, {"input": "heavymetalismetal", "output": "2"}, {"input": "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou", "output": "3"}]
1,300
["implementation", "strings", "two pointers"]
30
[{"input": "heavymetalisheavymetal\r\n", "output": "3"}, {"input": "heavymetalismetal\r\n", "output": "2"}, {"input": "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou\r\n", "output": "3"}, {"input": "fpgzbvhheavymheheavyzmheavyavyebknkhheavyhsbqmmetheavyalmetalheavyyomtua\r\n", "outpu...
false
stdio
null
true
717/G
717
G
Python 3
TESTS
2
62
7,168,000
122965222
import sys from heapq import heappop, heappush def add_edge(adj, cap, cost, u, v, capv, costv): adj[u].append(v) adj[v].append(u) cap[u][v] = capv cost[u][v] = costv cost[v][u] = -costv def match(crossword, cw_idx, word): for k in range(len(word)): if crossword[cw_idx + k] != word[k]: ...
30
374
7,168,000
124078949
import sys from heapq import heappop, heappush class Edge: def __init__(self, u, v, cap, flow, cost, rev) -> None: self.u = u self.v = v self.cap = cap self.flow = flow self.cost = cost self.rev = rev def add_edge(adj, u, v, capv, flowv, costv): if u == 6 and v ...
Bubble Cup 9 - Finals [Online Mirror]
ICPC
2,016
1
256
Underfail
You have recently fallen through a hole and, after several hours of unconsciousness, have realized you are in an underground city. On one of your regular, daily walks through the unknown, you have encountered two unusually looking skeletons called Sanz and P’pairus, who decided to accompany you and give you some puzzle...
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the length of the crossword. The second line contains the crossword string. The third line contains a single integer m (1 ≤ m ≤ 100) — the number of given words, and next m lines contain description of words: each line will have a string representi...
Output single integer — maximum number of points you can get.
null
For example, with the string "abacba", words "aba" (6 points) and "ba" (3 points), and x = 3, you can get at most 12 points - the word "aba" appears once ("abacba"), while "ba" appears two times ("abacba"). Note that for x = 1, you could get at most 9 points, since you wouldn’t be able to count both "aba" and the first...
[{"input": "6\nabacba\n2\naba 6\nba 3\n3", "output": "12"}]
2,400
["flows"]
30
[{"input": "6\r\nabacba\r\n2\r\naba 6\r\nba 3\r\n3\r\n", "output": "12\r\n"}, {"input": "6\r\nabacba\r\n2\r\naba 6\r\nba 3\r\n1\r\n", "output": "9\r\n"}, {"input": "6\r\nabacba\r\n5\r\naba 6\r\nba 3\r\nbac 4\r\ncb 3\r\nc 6\r\n2\r\n", "output": "21\r\n"}, {"input": "6\r\nabacba\r\n5\r\naba 6\r\nba 3\r\nbac 4\r\ncb 3\r\n...
false
stdio
null
true
898/C
898
C
PyPy 3-64
TESTS
2
46
0
205035728
n = int(input()) dict = {} for _ in range(n): mix = input() lis = [] name, nop, *lis = mix.split(" ") if name in dict: dict[name].extend(lis) else: dict[name] = lis print(len(dict)) for name in dict: dict[name].sort(key = lambda x: len(x)) i = 0 while (i < (len(dict[name...
59
62
5,632,000
33293212
n = int(input()) friends = dict() for _ in range(n): line = input().strip().split() if line[0] not in friends: friends[line[0]] = set() for i in range(2, len(line)): friends[line[0]].add(line[i]) def order(S): S2 = [(len(e),e) for e in S] S2.sort() real = set() for i in ...
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
551/E
551
E
PyPy 3
TESTS
0
140
0
43046252
n, q = map(int, input().split()) a = list(map(int, input().split())) for _ in range(q): inpt = list(map(int, input().split())) if inpt[0] == 1: for i in range(inpt[1], inpt[2] + 1): a[i] += inpt[3] else: i = 0 j = len(a) - 1 while (a[i] != inpt[1]) and (i < len(...
73
3,338
83,660,800
206366815
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, q = map(int, input().split()) a = list(map(int, input().split())) m = 555 m0 = n // m + min(n % m, 1) s = [set() for _ in range(m0)] for i in range(m0): for j in range(i * m, min((i + 1) * m, n)): s[i].add(a[j]) lazy = [0] *...
Codeforces Round 307 (Div. 2)
CF
2,015
10
256
GukiZ and GukiZiana
Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called GukiZiana. For given array a, indexed with integers from 1 to n, and number y, GukiZiana(a, y) represents maximum value of j - i, such that aj = ai = y. If there is no y as an element in a, then GukiZiana(a, y) is eq...
The first line contains two integers n, q (1 ≤ n ≤ 5 * 105, 1 ≤ q ≤ 5 * 104), size of array a, and the number of queries. The second line contains n integers a1, a2, ... an (1 ≤ ai ≤ 109), forming an array a. Each of next q lines contain either four or two numbers, as described in statement: If line starts with 1, t...
For each query of type 2, print the value of GukiZiana(a, y), for y value for that query.
null
null
[{"input": "4 3\n1 2 3 4\n1 1 2 1\n1 1 1 1\n2 3", "output": "2"}, {"input": "2 3\n1 2\n1 2 2 1\n2 3\n2 4", "output": "0\n-1"}]
2,500
["binary search", "data structures", "implementation"]
73
[{"input": "4 3\r\n1 2 3 4\r\n1 1 2 1\r\n1 1 1 1\r\n2 3\r\n", "output": "2\r\n"}, {"input": "2 3\r\n1 2\r\n1 2 2 1\r\n2 3\r\n2 4\r\n", "output": "0\r\n-1\r\n"}, {"input": "8 5\r\n1 1 1 2 1 3 1 1\r\n2 1\r\n1 1 8 1\r\n2 2\r\n1 2 5 2\r\n2 4\r\n", "output": "7\r\n7\r\n4\r\n"}, {"input": "8 8\r\n1 9 1 9 2 3 4 5\r\n1 3 7 1\r...
false
stdio
null
true
444/E
444
E
PyPy 3
TESTS
2
93
0
116404603
n = int(input()) for i in range(n - 1): a, b, c = map(int, input().split()) r = 4 for i in range(n): r = int(input()) if r == 1: print(2) else: print(3)
49
171
716,800
51735454
n = int(input()) edges = [[int(x) for x in input().split()] for i in range(n-1)] edges = sorted(edges) use_count = [0]+[int(input()) for i in range(n)] lo,hi = 0,10000 def getpar(par,u): if par[par[u]] == par[u]: return par[u] par[u] = getpar(par,par[u]) return par[u] def unite(par,sz,use,u,v): ...
Codeforces Round 254 (Div. 1)
CF
2,014
3
256
DZY Loves Planting
DZY loves planting, and he enjoys solving tree problems. DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He defines the function g(x, y) (1 ≤ x, y ≤ n) as the longest edge in the shortest path between nodes x and y. Specially g(z, z) = 0 for every...
The first line contains an integer n (1 ≤ n ≤ 3000). Each of the next n - 1 lines contains three integers ai, bi, ci (1 ≤ ai, bi ≤ n; 1 ≤ ci ≤ 10000), denoting an edge between ai and bi with length ci. It is guaranteed that these edges form a tree. Each of the next n lines describes an element of sequence x. The j-th...
Print a single integer representing the answer.
null
In the first sample, one of the optimal p is [4, 3, 2, 1].
[{"input": "4\n1 2 1\n2 3 2\n3 4 3\n1\n1\n1\n1", "output": "2"}, {"input": "4\n1 2 1\n2 3 2\n3 4 3\n4\n4\n4\n4", "output": "3"}]
2,700
["binary search", "dsu", "trees"]
49
[{"input": "4\r\n1 2 1\r\n2 3 2\r\n3 4 3\r\n1\r\n1\r\n1\r\n1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 1\r\n2 3 2\r\n3 4 3\r\n4\r\n4\r\n4\r\n4\r\n", "output": "3\r\n"}, {"input": "10\r\n2 1 8760\r\n3 1 3705\r\n4 1 1862\r\n5 2 7332\r\n6 3 7015\r\n7 5 4866\r\n8 3 4465\r\n9 7 8886\r\n10 3 9362\r\n2\r\n5\r\n5\r\n4\r\n4...
false
stdio
null
true
925/A
925
A
Python 3
TESTS
0
93
0
41671985
def bin_search(m,ref): l = -1 r = len(m) while(r - l > 1): if m[(r+l)//2] > ref: r = (r+l)//2 else: l = (r+l)//2 return((r+l)//2) n,m,cl,ce,v = map(int,input().split()) stairs = [] for i in range(cl): stairs.append(int(input())) elevators = [] for i in range(c...
27
1,824
9,830,400
42120565
def takeClosest(myList, myNumber): """ Assumes myList is sorted. Returns closest value to myNumber. If two numbers are equally close, return the smallest number. """ if len(myList) == 0: return 9e10 pos = bisect_left(myList, myNumber) if pos == 0: return myList[0] ...
VK Cup 2018 - Round 3
CF
2,018
2
256
Stairs and Elevators
In the year of $$$30XX$$$ participants of some world programming championship live in a single large hotel. The hotel has $$$n$$$ floors. Each floor has $$$m$$$ sections with a single corridor connecting all of them. The sections are enumerated from $$$1$$$ to $$$m$$$ along the corridor, and all sections with equal num...
The first line contains five integers $$$n, m, c_l, c_e, v$$$ ($$$2 \leq n, m \leq 10^8$$$, $$$0 \leq c_l, c_e \leq 10^5$$$, $$$1 \leq c_l + c_e \leq m - 1$$$, $$$1 \leq v \leq n - 1$$$) — the number of floors and section on each floor, the number of stairs, the number of elevators and the maximum speed of an elevator,...
Print $$$q$$$ integers, one per line — the answers for the queries.
null
In the first query the optimal way is to go to the elevator in the 5-th section in four time units, use it to go to the fifth floor in two time units and go to the destination in one more time unit. In the second query it is still optimal to use the elevator, but in the third query it is better to use the stairs in th...
[{"input": "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3", "output": "7\n5\n4"}]
1,600
["binary search"]
27
[{"input": "5 6 1 1 3\r\n2\r\n5\r\n3\r\n1 1 5 6\r\n1 3 5 4\r\n3 3 5 3\r\n", "output": "7\r\n5\r\n4\r\n"}, {"input": "2 2 0 1 1\r\n\r\n1\r\n1\r\n1 2 2 2\r\n", "output": "3\r\n"}, {"input": "4 4 1 0 1\r\n4\r\n\r\n5\r\n1 1 2 2\r\n1 3 2 2\r\n3 3 4 3\r\n3 2 2 2\r\n1 2 2 3\r\n", "output": "6\r\n4\r\n3\r\n5\r\n4\r\n"}, {"inpu...
false
stdio
null
true
813/F
813
F
PyPy 3-64
TESTS
2
62
1,228,800
148633666
from collections import deque import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def bfs(s): q = deque() q.append(s) dist[s] = 0 ng = 0 while q: i = q.popleft() di = dist[i] vi = visit[i] for j, w0 in zip(G[i], W[i]): if not w...
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
813/F
813
F
PyPy 3
TESTS
1
61
0
154221537
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def get_root(s): v = [] while not s == root[s]: v.append(s) s = root[s] for i in v: root[i] = s return s def unite(s, t): rs, rt = get_root(s), get_root(t) if not rs ^ rt: return ...
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
925/B
925
B
Python 3
TESTS
0
78
307,200
84306663
n, x1, x2 = map(int, input().split()) cc = list(map(int, input().split())) c = sorted(cc) s = 0 f = True middle = -1 for i in range(n): s += c[i] if f: if s >= x1: middle = i s = 0 f = False if f: print('No') elif s < x2: print('No') else: print('Yes') ...
40
795
50,995,200
37714382
n, a, b = [int(x) for x in input().split()] hs = [int(x) for x in input().split()] hs = sorted(enumerate(hs), key=lambda x: x[1]) for i in range(1, n+1): if hs[-i][1] * i >= a: break else: print('No') exit() for j in range(i+1, n+1): if hs[-j][1] * (j - i) >= b: print('Yes') ...
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
925/B
925
B
PyPy 3-64
TESTS
0
46
512,000
153450910
n, x, y = map(int,input().split()) c = list(map(int, input().split())) left = -1 right = (1 << n) - 1 def check(hash): res = 0 for i in range(n): if (1 << i) & hash: res += c[i] return res while right - left > 1: mid = left + (right - left) // 2 if check(mid) >= x: r...
40
1,216
39,219,200
42132645
# python3 def readline(): return tuple(map(int, input().split())) def ceil_div(num, den): return (num - 1) // den + 1 def main(): n, x1, x2 = readline() c = readline() xx = (x1, x2) servers = sorted(enumerate(c, start=1), key=lambda p: p[1]) for (i, a) in enumerate(servers): for (j, x...
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
850/A
850
A
Python 3
TESTS
2
93
307,200
53201855
from math import acos, pi n = int(input()) tocke = [list(map(int, input().split())) for i in range(n)] def vektor(t1, t2): vector = [] for i in range(5): vector.append(t2[i] - t1[i]) return vector def skalarni_produkt(v1, v2): vsota = 0 for i in range(5): vsota += v1[i] * v2[i] ...
19
62
0
30064873
def vec(c0, a, b): an = 0 for i in range(5): an += (a[i] - c0[i]) * (b[i] - c0[i]) return an n = int(input()) if n > 80: print(0) exit(0) a = [[0] * 5 for i in range(n)] for i in range(n): a[i] = [int(j) for j in input().split()] ans = [] for i in range(n): flag = True for j in...
Codeforces Round 432 (Div. 1, based on IndiaHacks Final Round 2017)
CF
2,017
2
256
Five Dimensional Points
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide. We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $${ \vec { a } } { \vec { b } }$$ and $${ \vec { a } } { \vec { c } }$$ is...
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points. The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103)  — the coordinates of the i-th point. All points are distinct.
First, print a single integer k — the number of good points. Then, print k integers, each on their own line — the indices of the good points in ascending order.
null
In the first sample, the first point forms exactly a $$90^\circ$$ angle with all other pairs of points, so it is good. In the second sample, along the cd plane, we can see the points look as follows: We can see that all angles here are acute, so no points are good.
[{"input": "6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1", "output": "1\n1"}, {"input": "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0", "output": "0"}]
1,700
["brute force", "geometry", "math"]
19
[{"input": "6\r\n0 0 0 0 0\r\n1 0 0 0 0\r\n0 1 0 0 0\r\n0 0 1 0 0\r\n0 0 0 1 0\r\n0 0 0 0 1\r\n", "output": "1\r\n1\r\n"}, {"input": "3\r\n0 0 1 2 0\r\n0 0 9 2 0\r\n0 0 5 9 0\r\n", "output": "0\r\n"}, {"input": "1\r\n0 0 0 0 0\r\n", "output": "1\r\n1\r\n"}, {"input": "2\r\n0 1 2 3 4\r\n5 6 7 8 9\r\n", "output": "2\r\n1...
false
stdio
null
true
518/C
518
C
Python 3
TESTS
0
46
6,963,200
126945010
n,m,k=map(int,input().split()) l1=[int(a) for a in input().split()] l2=[int(a) for a in input().split()] l3=[] for i in range(n): l3.append([l1[i],i]) l3.sort() an=0 for i in range(m): tg=l2[i] an+=tg//k+tg%k if l3[tg-1][1]!=0: l3[tg-1][1]-=1 l3[l1[l3[tg-2][1]]][1]+=1 l1[tg-...
43
124
20,684,800
185451156
from heapq import heapify, heappop, heappush, nlargest from collections import Counter, defaultdict from sys import stdin, stdout from math import ceil, floor, sqrt from functools import reduce,lru_cache # n,m = map(int,stdin.readline().split()) # stdout.write(str(arr[x-y]-arr[x])+'\n') # reps = int(stdin.readline()) #...
Codeforces Round 293 (Div. 2)
CF
2,015
1
256
Anya and Smartphone
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th ...
The first line of the input contains three numbers n, m, k (1 ≤ n, m, k ≤ 105) — the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen. The next line contains n integers, permutation a1, a2, ..., an — the...
Print a single number — the number of gestures that Anya needs to make to launch all the applications in the desired order.
null
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8. After application 7 is launched, we get the new arrangement of the icons — (123)(457)(68). To launch i...
[{"input": "8 3 3\n1 2 3 4 5 6 7 8\n7 8 1", "output": "7"}, {"input": "5 4 2\n3 1 5 2 4\n4 4 4 4", "output": "8"}]
1,600
["constructive algorithms", "data structures", "implementation"]
43
[{"input": "8 3 3\r\n1 2 3 4 5 6 7 8\r\n7 8 1\r\n", "output": "7\r\n"}, {"input": "5 4 2\r\n3 1 5 2 4\r\n4 4 4 4\r\n", "output": "8\r\n"}, {"input": "10 10 3\r\n1 2 3 4 5 6 7 8 9 10\r\n2 3 4 5 6 7 8 9 10 1\r\n", "output": "25\r\n"}, {"input": "10 12 3\r\n6 1 2 9 3 10 8 5 7 4\r\n3 9 9 4 8 2 3 8 10 8 3 4\r\n", "output": ...
false
stdio
null
true
685/B
685
B
PyPy 3-64
TESTS
2
872
70,656,000
145906613
import sys import heapq input = sys.stdin.buffer.readline def process(n, P, Q): g = [[] for i in range(n+1)] for i in range(n-1): i2 = i+2 j2 = P[i] g[i2].append(j2) g[j2].append(i2) subtree_size = [0 for i in range(n+1)] subtrees = [[] for i in range(n+1)] centroid...
49
2,401
47,001,600
18685578
def main(): import sys E=sys.stdin R=E.readline n,q=map(int,R().split()) P=[0,0]+[int(i) for i in R().split()] #n=q=300000 #P=[0]+list(range(n)) #exit() C=[[]] i=0 while i<n: i+=1 C.append([]) i=2 j=len(P) while i<j: C[P[i]].append(i) i+=1 i=Qi=0 W=[0]*(n+1) S=[0]*(n+1) Q=[0]*(n+1) while i<n:...
Codeforces Round 359 (Div. 1)
CF
2,016
3
256
Kay and Snowflake
After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the roses. Now he likes to watch snowflakes. Once upon a time, he found a huge snowflake that has a form of the tree (connected acyclic graph) consisting of n nodes. The root of tree has index 1. Kay is very interested ...
The first line of the input contains two integers n and q (2 ≤ n ≤ 300 000, 1 ≤ q ≤ 300 000) — the size of the initial tree and the number of queries respectively. The second line contains n - 1 integer p2, p3, ..., pn (1 ≤ pi ≤ n) — the indices of the parents of the nodes from 2 to n. Node 1 is a root of the tree. It...
For each query print the index of a centroid of the corresponding subtree. If there are many suitable nodes, print any of them. It's guaranteed, that each subtree has at least one centroid.
null
The first query asks for a centroid of the whole tree — this is node 3. If we delete node 3 the tree will split in four components, two of size 1 and two of size 2. The subtree of the second node consists of this node only, so the answer is 2. Node 3 is centroid of its own subtree. The centroids of the subtree of th...
[{"input": "7 4\n1 1 3 3 5 3\n1\n2\n3\n5", "output": "3\n2\n3\n6"}]
1,900
["data structures", "dfs and similar", "dp", "trees"]
49
[{"input": "7 4\r\n1 1 3 3 5 3\r\n1\r\n2\r\n3\r\n5\r\n", "output": "3\r\n2\r\n3\r\n6\r\n"}, {"input": "2 2\r\n1\r\n1\r\n2\r\n", "output": "2\r\n2\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: lines = f.read().splitlines() ptr = 0 n, q = map(int, lines[ptr].split()) ptr +=1 parents = list(map(int, lines[ptr].split())) ptr +=1 que...
true
839/D
839
D
PyPy 3
TESTS
2
171
13,926,400
103996491
visited=[0]*(10**6+1) lastfactor=[-1]*(10**6+1) for j in range(2,10**6): for k in range(2*j,10**6+1,j): lastfactor[k]=j n=int(input()) primes=[] for i in range(2,10**6+1): if lastfactor[i]==-1: primes.append(i) count=[0]*(10**6+1) a=list(map(int,input().split())) for i in range(n): r=a[i] curr=1 while...
47
655
38,707,200
155552887
import sys mod=1000000007 m=int(input())#20w a=list(map(int,sys.stdin.readline().split()))#100w n=1000001#max a answer=0 ans=[0]*n cnt=[0]*n for i in a: cnt[i]+=1 for i in range(n-1,1,-1): j=sum(cnt[i::i]) if j>0: ans[i]=(j*(2**(j-1))-sum(ans[(2*i)::i]))%mod answer=(answer+i*ans[i])%mod prin...
Codeforces Round 428 (Div. 2)
CF
2,017
3
256
Winter is here
Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers. He has created a method to know how strong his army is. Let the i-th soldier’s strength...
The first line contains integer n (1 ≤ n ≤ 200000) — the size of the army. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000000) — denoting the strengths of his soldiers.
Print one integer — the strength of John Snow's army modulo 1000000007 (109 + 7).
null
In the first sample the clans are {1}, {2}, {1, 2} so the answer will be 1·3 + 1·3 + 2·3 = 12
[{"input": "3\n3 3 1", "output": "12"}, {"input": "4\n2 3 4 6", "output": "39"}]
2,200
["combinatorics", "dp", "math", "number theory"]
47
[{"input": "3\r\n3 3 1\r\n", "output": "12\r\n"}, {"input": "4\r\n2 3 4 6\r\n", "output": "39\r\n"}]
false
stdio
null
true
47/D
47
D
Python 3
TESTS
0
60
0
230675785
import sys from itertools import product n, m = map(int, sys.stdin.readline().split()) possible_codes = product('01', repeat=n) valid_code_count = 0 for _ in range(m): s, c = sys.stdin.readline().split() c = int(c) valid_code_count = 0 for code in possible_codes: correct_digits = sum(s[i] == ...
26
466
3,686,400
181406585
from collections import defaultdict import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, m = map(int, input().split()) pow2 = [1] for _ in range(20): pow2.append(2 * pow2[-1]) n1, n2 = n // 2, (n + 1) // 2 x, y, z = [], [], [] for _ in range(m): s, c = list(input().rstrip().decode...
Codeforces Beta Round 44 (Div. 2)
CF
2,010
5
256
Safe
Vasya tries to break in a safe. He knows that a code consists of n numbers, and every number is a 0 or a 1. Vasya has made m attempts to enter the code. After each attempt the system told him in how many position stand the right numbers. It is not said in which positions the wrong numbers stand. Vasya has been so unluc...
The first input line contains two integers n and m (6 ≤ n ≤ 35, 1 ≤ m ≤ 10) which represent the number of numbers in the code and the number of attempts made by Vasya. Then follow m lines, each containing space-separated si and ci which correspondingly indicate Vasya’s attempt (a line containing n numbers which are 0 o...
Print the single number which indicates how many possible code variants that do not contradict the m system responses are left.
null
null
[{"input": "6 2\n000000 2\n010100 4", "output": "6"}, {"input": "6 3\n000000 2\n010100 4\n111100 0", "output": "0"}, {"input": "6 3\n000000 2\n010100 4\n111100 2", "output": "1"}]
2,200
["brute force"]
26
[{"input": "6 2\r\n000000 2\r\n010100 4\r\n", "output": "6\r\n"}, {"input": "6 3\r\n000000 2\r\n010100 4\r\n111100 0\r\n", "output": "0\r\n"}, {"input": "6 3\r\n000000 2\r\n010100 4\r\n111100 2\r\n", "output": "1\r\n"}, {"input": "6 1\r\n101011 2\r\n", "output": "15\r\n"}, {"input": "7 2\r\n1011111 2\r\n1001111 1\r\n",...
false
stdio
null
true
620/F
620
F
PyPy 3-64
TESTS
0
46
0
197061937
n, q = map(int, input().split()) L = list(map(int, input().split())) prefix_xor = [0] for i in L: prefix_xor.append(prefix_xor[-1] ^ i) for _ in range(q): l, r = map(int, input().split()) l -= 1; r -= 1 print(prefix_xor[r + 1] ^ prefix_xor[l])
22
8,064
121,446,400
224643493
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v, w): return (u * z + v) * z + w def update1(x, c): i = x ^ l1 tree1[i], color1[i] = x, c i >>= 1 for _ in range(w): j, k = i << 1, i << 1 ^ 1 if color1[j] ^ c: tree1[i] = tree1[k]...
Educational Codeforces Round 6
ICPC
2,016
10
512
Xors on Segments
You are given an array with n integers ai and m queries. Each query is described by two integers (lj, rj). Let's define the function $$f(u,v) = u \oplus (u+1) \oplus \ldots \oplus v$$. The function is defined for only u ≤ v. For each query print the maximal value of the function f(ax, ay) over all lj ≤ x, y ≤ rj, ax...
The first line contains two integers n, m (1 ≤ n ≤ 5·104, 1 ≤ m ≤ 5·103) — the size of the array and the number of the queries. The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a. Each of the next m lines contains two integers lj, rj (1 ≤ lj ≤ rj ≤ n) – the parameters of the j-th que...
For each query print the value aj on a separate line — the maximal value of the function f(ax, ay) over all lj ≤ x, y ≤ rj, ax ≤ ay.
null
null
[{"input": "6 3\n1 2 3 4 5 6\n1 6\n2 5\n3 4", "output": "7\n7\n7"}, {"input": "1 1\n1\n1 1", "output": "1"}, {"input": "6 20\n10 21312 2314 214 1 322\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n2 2\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 4\n4 5\n4 6\n5 5\n5 6\n6 6", "output": "10\n21313\n21313\n21313\n21313\n21313\n21312\n21313\n2131...
2,800
["data structures", "strings", "trees"]
22
[{"input": "6 3\r\n1 2 3 4 5 6\r\n1 6\r\n2 5\r\n3 4\r\n", "output": "7\r\n7\r\n7\r\n"}, {"input": "1 1\r\n1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "6 20\r\n10 21312 2314 214 1 322\r\n1 1\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n1 6\r\n2 2\r\n2 3\r\n2 4\r\n2 5\r\n2 6\r\n3 4\r\n3 5\r\n3 6\r\n4 4\r\n4 5\r\n4 6\r\n5 5\r\n5 6\r\n...
false
stdio
null
true
267/A
267
A
Python 3
TESTS
1
31
0
169341298
n = int(input()) for i in range(n): (a, b) = map(int, input().split(' ')) if a == b: print(1) else: operations = 0 bigger_number = max(a, b) smaller_number = min(a, b) while bigger_number != smaller_number: if bigger_number % smaller_number == 0: ...
35
46
0
149972427
for _ in range(int(input())): a,b = map(int,input().split()) i = 0 while True: if a <= 0 or b <= 0: break if a > b: i+=a//b a-=a//b*b else: i+=b//a b-=b//a*a print(i)
Codeforces Testing Round 5
CF
2,013
1
256
Subtractions
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some num...
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Print the sought number of operations for each pair on a single line.
null
null
[{"input": "2\n4 17\n7 987654321", "output": "8\n141093479"}]
900
["math", "number theory"]
35
[{"input": "2\r\n4 17\r\n7 987654321\r\n", "output": "8\r\n141093479\r\n"}, {"input": "10\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n", "output": "141093479\r\n141093479\r\n141093479\r\n141093479\r\n141093479\r...
false
stdio
null
true