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
847/H
847
H
Python 3
TESTS
8
62
5,529,600
31653549
n = int(input()) t = list(map(int, input().split())) s = a = b = 0 for i in range(n): a = max(a, t[i] - i) b = max(b, t[-1 - i] - i) x = (b - a + n) // 2 y = 0 for i in range(x): s += max(y - t[i], 0) y = max(t[i], y) + 1 y = 0 for i in range(n - x): s += max(y - t[-1 - i], 0) y = max(t[-1 - i],...
39
124
19,046,400
211256726
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb N = int(input()) A = list(map(int,input().split())) R,L = A[:],A[:] r,l = [0,0],[0,...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
1
256
Load Testing
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send ai requests. Polycarp plans to test Fakebook under a special kind of...
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the duration of the load testing. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the number of requests from friends in the i-th minute of the load testing.
Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.
null
In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests. In the second example it is enough to make one additional request in the thir...
[{"input": "5\n1 4 3 2 5", "output": "6"}, {"input": "5\n1 2 2 2 1", "output": "1"}, {"input": "7\n10 20 40 50 70 90 30", "output": "0"}]
1,600
["greedy"]
39
[{"input": "5\r\n1 4 3 2 5\r\n", "output": "6\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7\r\n10 20 40 50 70 90 30\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 15\r\n", "output": "0\r\n"}, {"input": "4\r\n36 54 55 9\r\n", "output": "0\r\n"}, {"input"...
false
stdio
null
true
631/A
631
A
PyPy 3
TESTS
11
156
1,433,600
102280244
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) tmp = 0 ans1, ans2 = 0, 0 for i in range(len(a)-1): tmp = a[i] | a[i+1] ans1 |= tmp for i in range(len(b)-1): tmp = b[i] | b[i+1] ans2 |= tmp print(ans1 + ans2)
27
46
0
167839946
def maximize(arr1,arr2): value1 = 0 value2= 0 for num in arr1: value1|=num for num in arr2: value2 |= num return value2 + value1 n = int(input()) arr1 = list(map(int,input().split())) arr2 = list(map(int,input().split())) print(maximize(arr1,arr2))
Codeforces Round 344 (Div. 2)
CF
2,016
1
256
Interview
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ...
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays. The second line contains n integers ai (0 ≤ ai ≤ 109). The third line contains n integers bi (0 ≤ bi ≤ 109).
Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.
null
Bitwise OR of two non-negative integers a and b is the number c = a OR b, such that each of its digits in binary notation is 1 if and only if at least one of a or b have 1 in the corresponding position in binary notation. In the first sample, one of the optimal answers is l = 2 and r = 4, because f(a, 2, 4) + f(b, 2, ...
[{"input": "5\n1 2 4 3 2\n2 3 3 12 1", "output": "22"}, {"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6", "output": "46"}]
900
["brute force", "implementation"]
27
[{"input": "5\r\n1 2 4 3 2\r\n2 3 3 12 1\r\n", "output": "22"}, {"input": "10\r\n13 2 7 11 8 4 9 8 5 1\r\n5 7 18 9 2 3 0 11 8 6\r\n", "output": "46"}, {"input": "25\r\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\r\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 95 124 18 28 79 1...
false
stdio
null
true
29/A
29
A
Python 3
TESTS
13
186
0
53426601
c={} y=False for i in range(int(input())): x,s=map(int,input().split()) if x+s in c: if c[x+s]+x+s==x: print("YES") y=True c[x]=s if y==False: print("NO")
30
62
0
156054951
import sys input = sys.stdin.readline n = int(input()) w = [list(map(int, input().split())) for _ in range(n)] ans = "NO" for i in w: for j in w: if j[0] == sum(i) and sum(j) == i[0]: ans = "YES" break if ans == "YES": break print(ans)
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Spit Problem
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
The first line contains integer n (1 ≤ n ≤ 100) — the amount of camels in the zoo. Each of the following n lines contains two integers xi and di ( - 104 ≤ xi ≤ 104, 1 ≤ |di| ≤ 2·104) — records in Bob's notepad. xi is a position of the i-th camel, and di is a distance at which the i-th camel spitted. Positive values of ...
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
null
null
[{"input": "2\n0 1\n1 -1", "output": "YES"}, {"input": "3\n0 1\n1 1\n2 -2", "output": "NO"}, {"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES"}]
1,000
["brute force"]
30
[{"input": "2\r\n0 1\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n2 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 -10\r\n3 10\r\n0 5\r\n5 -5\r\n10 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n-9897 -1144\r\n-4230 -6350\r\n2116 -3551\r\n-3635 4993\r\n3907 -9071\r\n-2362 4120\r\n-6542 984\r\n5807...
false
stdio
null
true
103/A
103
A
PyPy 3-64
TESTS
4
92
0
150953173
n=int(input()) c=0 a=[int(x) for x in input().split()] for i in range(n-1,-1,-1): if c==0: c+=a[i] else: c+=a[i]-1+a[i+1] print(c)
25
92
0
9732586
n = int(input()) a = list(map(int, input().split())) res = 0 for i in range(len(a)): res += (1 + (i+1)*(a[i]-1)) print(res)
Codeforces Beta Round 80 (Div. 1 Only)
CF
2,011
2
256
Testing Pants for Sadness
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ...
The first line contains a positive integer n (1 ≤ n ≤ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 ≤ ai ≤ 109), the number of answer variants to question i.
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the thir...
[{"input": "2\n1 1", "output": "2"}, {"input": "2\n2 2", "output": "5"}, {"input": "1\n10", "output": "10"}]
1,100
["greedy", "implementation", "math"]
25
[{"input": "2\r\n1 1\r\n", "output": "2"}, {"input": "2\r\n2 2\r\n", "output": "5"}, {"input": "1\r\n10\r\n", "output": "10"}, {"input": "3\r\n2 4 1\r\n", "output": "10"}, {"input": "4\r\n5 5 3 1\r\n", "output": "22"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "2999999999"}, {"input": "10\r\n5 7 8 1 10 3 6 ...
false
stdio
null
true
29/A
29
A
Python 3
TESTS
13
248
0
51448472
data = {} for _ in range(int(input())): a,b = map(int,str(input()).split(" ")) data[a] = a+b if set(data.keys()).intersection(set(data.values())).__len__()!=2: print("NO") else: print("YES")
30
92
0
9383286
n = int(input()) s = set() for i in range(n): x, d = [int(x) for x in input().split()] if (x + d, -d) in s: print('YES') exit() s.add((x, d)) print('NO')
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Spit Problem
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
The first line contains integer n (1 ≤ n ≤ 100) — the amount of camels in the zoo. Each of the following n lines contains two integers xi and di ( - 104 ≤ xi ≤ 104, 1 ≤ |di| ≤ 2·104) — records in Bob's notepad. xi is a position of the i-th camel, and di is a distance at which the i-th camel spitted. Positive values of ...
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
null
null
[{"input": "2\n0 1\n1 -1", "output": "YES"}, {"input": "3\n0 1\n1 1\n2 -2", "output": "NO"}, {"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES"}]
1,000
["brute force"]
30
[{"input": "2\r\n0 1\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n2 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 -10\r\n3 10\r\n0 5\r\n5 -5\r\n10 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n-9897 -1144\r\n-4230 -6350\r\n2116 -3551\r\n-3635 4993\r\n3907 -9071\r\n-2362 4120\r\n-6542 984\r\n5807...
false
stdio
null
true
282/B
282
B
Python 3
TESTS
2
62
0
230848284
n = int(input()) eggs = [] for _ in range(n): a, g = map(int, input().split()) eggs.append((a, g)) Sa = 0 Sg = 0 distribution = "" for a, g in eggs: if Sa + a <= Sg + g + 500: Sa += a distribution += "A" else: Sg += g distribution += "G" if abs(Sa - Sg) > 500: prin...
54
4,116
149,708,800
226850439
n = int(input()) eggs = [] for i in range(n): a, g = map(int, input().split()) eggs.append((a, g)) distribution = [''] * n Sa = 0 # Total money paid to A Sg = 0 # Total money paid to G for i in range(n): if abs(Sa + eggs[i][0] - Sg) <= 500: distribution[i] = 'A' Sa += eggs[i][0] els...
Codeforces Round 173 (Div. 2)
CF
2,013
5
256
Painting Eggs
The Bitlandians are quite weird people. They have very peculiar customs. As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work. The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J. ha...
The first line contains integer n (1 ≤ n ≤ 106) — the number of eggs. Next n lines contain two integers ai and gi each (0 ≤ ai, gi ≤ 1000; ai + gi = 1000): ai is the price said by A. for the i-th egg and gi is the price said by G. for the i-th egg.
If it is impossible to assign the painting, print "-1" (without quotes). Otherwise print a string, consisting of n letters "G" and "A". The i-th letter of this string should represent the child who will get the i-th egg in the required distribution. Letter "A" represents A. and letter "G" represents G. If we denote th...
null
null
[{"input": "2\n1 999\n999 1", "output": "AG"}, {"input": "3\n400 600\n400 600\n400 600", "output": "AGA"}]
1,500
["greedy", "math"]
54
[{"input": "2\r\n1 999\r\n999 1\r\n", "output": "AG\r\n"}, {"input": "3\r\n400 600\r\n400 600\r\n400 600\r\n", "output": "AGA\r\n"}, {"input": "2\r\n500 500\r\n500 500\r\n", "output": "AG\r\n"}, {"input": "1\r\n1 999\r\n", "output": "A\r\n"}, {"input": "10\r\n1 999\r\n1 999\r\n1 999\r\n1 999\r\n1 999\r\n1 999\r\n1 999\...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input data with open(input_path) as f: n = int(f.readline()) eggs = [tuple(map(int, line.split())) for line in f] # Read reference and submission outputs with open(output_path) as f: ref_output = f.read()...
true
965/D
965
D
Python 3
TESTS
8
124
7,782,400
53069118
w,l=map(int,input().split()) a=list(map(int,input().split())) s,mn=0,100000000 for i in range(l):s+=a[i] mn=min(mn,s) for i in range(l,w-1): s+=a[i];s-=a[i-l] mn=min(mn,s) print(mn)
16
77
13,312,000
216694136
def ok(cnt): for i in range(l, w): if pref[i] - pref[i - l] < cnt: return False return True w, l = map(int, input().split()) a = list(map(int, input().split())) pref = [0] * w for i in range(1, w): pref[i] = pref[i - 1] + a[i - 1] li, ri = 1, pref[-1] ans = 0 while li <= ri: m = (li ...
Codeforces Round 476 (Div. 2) [Thanks, Telegram!]
CF
2,018
1
256
Single-use Stones
A lot of frogs want to cross a river. A river is $$$w$$$ units width, but frogs can only jump $$$l$$$ units long, where $$$l < w$$$. Frogs can also jump on lengths shorter than $$$l$$$. but can't jump longer. Hopefully, there are some stones in the river to help them. The stones are located at integer distances from t...
The first line contains two integers $$$w$$$ and $$$l$$$ ($$$1 \le l < w \le 10^5$$$) — the width of the river and the maximum length of a frog's jump. The second line contains $$$w - 1$$$ integers $$$a_1, a_2, \ldots, a_{w-1}$$$ ($$$0 \le a_i \le 10^4$$$), where $$$a_i$$$ is the number of stones at the distance $$$i$...
Print a single integer — the maximum number of frogs that can cross the river.
null
In the first sample two frogs can use the different stones at the distance $$$5$$$, and one frog can use the stones at the distances $$$3$$$ and then $$$8$$$. In the second sample although there are two stones at the distance $$$5$$$, that does not help. The three paths are: $$$0 \to 3 \to 6 \to 9 \to 10$$$, $$$0 \to ...
[{"input": "10 5\n0 0 1 0 2 0 0 1 0", "output": "3"}, {"input": "10 3\n1 1 1 1 2 1 1 1 1", "output": "3"}]
1,900
["binary search", "flows", "greedy", "two pointers"]
16
[{"input": "10 5\r\n0 0 1 0 2 0 0 1 0\r\n", "output": "3\r\n"}, {"input": "10 3\r\n1 1 1 1 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2 1\r\n0\r\n", "output": "0\r\n"}, {"input": "2 1\r\n5\r\n", "output": "5\r\n"}, {"input": "10 4\r\n0 0 6 2 7 1 6 4 0\r\n", "output": "8\r\n"}, {"input": "100 15\r\n0 0 1 1 1 0 1 1 1...
false
stdio
null
true
29/A
29
A
Python 3
TESTS
9
62
0
205011202
n =int(input()) data = [] for i in range(n) : s = list(map(int, input().split())) data.append(s) res = "NO" for i in data : for j in data : if i[1] + j[1] == 0 and i[0] <j[0] : res = "YES" break print(res)
30
92
0
132202664
n=int(input()) k = [] for i in range(n): x,d=map(int,input().split()) k.append([x,x+d]) ok=False for i in range(n): for j in range(i+1,n): if k[i][0] == k[j][1] and k[i][1] == k[j][0]: ok = True if ok: print("YES") else: print("NO")
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Spit Problem
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
The first line contains integer n (1 ≤ n ≤ 100) — the amount of camels in the zoo. Each of the following n lines contains two integers xi and di ( - 104 ≤ xi ≤ 104, 1 ≤ |di| ≤ 2·104) — records in Bob's notepad. xi is a position of the i-th camel, and di is a distance at which the i-th camel spitted. Positive values of ...
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
null
null
[{"input": "2\n0 1\n1 -1", "output": "YES"}, {"input": "3\n0 1\n1 1\n2 -2", "output": "NO"}, {"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES"}]
1,000
["brute force"]
30
[{"input": "2\r\n0 1\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n2 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 -10\r\n3 10\r\n0 5\r\n5 -5\r\n10 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n-9897 -1144\r\n-4230 -6350\r\n2116 -3551\r\n-3635 4993\r\n3907 -9071\r\n-2362 4120\r\n-6542 984\r\n5807...
false
stdio
null
true
29/A
29
A
Python 3
TESTS
9
124
0
116967000
s=[] for _ in range(int(input())): x,d=map(int,input().split()) s.append(d) for i in range(len(s)): for j in range(len(s)): if s[i]+s[j]==0: print('YES') exit() print('NO')
30
92
0
137137744
#!/usr/bin/env python # coding=utf-8 ''' Author: Deean Date: 2021-11-27 22:24:08 LastEditTime: 2021-11-27 22:31:19 Description: Spit Problem FilePath: CF29A.py ''' def func(): n = int(input()) point, distance = [0] * n, [0] * n for i in range(n): point[i], distance[i] = map(int, input().strip().sp...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Spit Problem
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
The first line contains integer n (1 ≤ n ≤ 100) — the amount of camels in the zoo. Each of the following n lines contains two integers xi and di ( - 104 ≤ xi ≤ 104, 1 ≤ |di| ≤ 2·104) — records in Bob's notepad. xi is a position of the i-th camel, and di is a distance at which the i-th camel spitted. Positive values of ...
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
null
null
[{"input": "2\n0 1\n1 -1", "output": "YES"}, {"input": "3\n0 1\n1 1\n2 -2", "output": "NO"}, {"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES"}]
1,000
["brute force"]
30
[{"input": "2\r\n0 1\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n2 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 -10\r\n3 10\r\n0 5\r\n5 -5\r\n10 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n-9897 -1144\r\n-4230 -6350\r\n2116 -3551\r\n-3635 4993\r\n3907 -9071\r\n-2362 4120\r\n-6542 984\r\n5807...
false
stdio
null
true
29/A
29
A
PyPy 3
TESTS
13
278
0
61237531
n = int(input()) a = [] b = [] for i in range(n): x, d = map(int, input().split()) a.append(x) b.append(d) f = False for i in range(n): if a[i] + b[i] in a: for j in range(i+1, n): if a[j] + b[j] == a[i] and a[j] == a[i] + b[i]: print('YES') f = True ...
30
92
0
138567702
n = int(input()) dict = {} ans = "NO" for i in range(n): pos, spit = [int(item) for item in input().split(' ')] dict[pos] = spit for key in dict: secCamel = key + dict[key] if secCamel in dict and key == secCamel + dict[secCamel]: ans = "YES" break print(ans)
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Spit Problem
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
The first line contains integer n (1 ≤ n ≤ 100) — the amount of camels in the zoo. Each of the following n lines contains two integers xi and di ( - 104 ≤ xi ≤ 104, 1 ≤ |di| ≤ 2·104) — records in Bob's notepad. xi is a position of the i-th camel, and di is a distance at which the i-th camel spitted. Positive values of ...
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
null
null
[{"input": "2\n0 1\n1 -1", "output": "YES"}, {"input": "3\n0 1\n1 1\n2 -2", "output": "NO"}, {"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES"}]
1,000
["brute force"]
30
[{"input": "2\r\n0 1\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n2 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 -10\r\n3 10\r\n0 5\r\n5 -5\r\n10 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n-9897 -1144\r\n-4230 -6350\r\n2116 -3551\r\n-3635 4993\r\n3907 -9071\r\n-2362 4120\r\n-6542 984\r\n5807...
false
stdio
null
true
29/A
29
A
PyPy 3
TESTS
13
310
1,228,800
84404851
n = int(input()) a = [] flag = 1 for _ in range(n) : x,d = map(int,input().split()) a.append([x,d]) for i in range(n) : for j in range(i+1,n) : if a[i][0]+a[i][1]==a[j][0] and a[j][0]+a[j][1]==a[i][0] : print("YES") flag = 0 ...
30
92
0
140951907
n = int(input()) s = set() for i in range(n): x, d = [int(x) for x in input().split()] if (x + d, -d) in s: print('YES') exit() s.add((x, d)) print('NO')
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Spit Problem
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
The first line contains integer n (1 ≤ n ≤ 100) — the amount of camels in the zoo. Each of the following n lines contains two integers xi and di ( - 104 ≤ xi ≤ 104, 1 ≤ |di| ≤ 2·104) — records in Bob's notepad. xi is a position of the i-th camel, and di is a distance at which the i-th camel spitted. Positive values of ...
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
null
null
[{"input": "2\n0 1\n1 -1", "output": "YES"}, {"input": "3\n0 1\n1 1\n2 -2", "output": "NO"}, {"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES"}]
1,000
["brute force"]
30
[{"input": "2\r\n0 1\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n2 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 -10\r\n3 10\r\n0 5\r\n5 -5\r\n10 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n-9897 -1144\r\n-4230 -6350\r\n2116 -3551\r\n-3635 4993\r\n3907 -9071\r\n-2362 4120\r\n-6542 984\r\n5807...
false
stdio
null
true
774/D
774
D
Python 3
TESTS
17
187
14,950,400
26147115
lmap = lambda f, x: list(map(f, x)) n,l,r = lmap(int, input().split()) l-=1 a = lmap(int, input().split()) b = lmap(int, input().split()) a1 = a[l:r] a2 = b[l:r] good = (sorted(a1)==sorted(a2)) if good: print('TRUTH') else: print("LIE")
52
93
15,155,200
26152432
S = input() list = [] list = S.split(" ") n = int(list[0]) l = int(list[1]) r = int(list[2]) was = input().split(" ") bec = input().split(" ") f = True for i in range(0, l-1): if was[i] != bec[i]: print("LIE") f = False break if f == True: for i in range(r,n): if was[i]...
VK Cup 2017 - Wild Card Round 1
ICPC
2,017
2
256
Lie or Truth
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an. While Vasya was walking, his little brother Stepan played with Vasya's cubes and chan...
The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence b1, b2, ...
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
null
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and...
[{"input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1", "output": "TRUTH"}, {"input": "3 1 2\n1 2 3\n3 1 2", "output": "LIE"}, {"input": "4 2 4\n1 1 1 1\n1 1 1 1", "output": "TRUTH"}]
1,500
["*special", "constructive algorithms", "implementation", "sortings"]
52
[{"input": "5 2 4\r\n3 4 2 3 1\r\n3 2 3 4 1\r\n", "output": "TRUTH\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n3 1 2\r\n", "output": "LIE\r\n"}, {"input": "4 2 4\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "TRUTH\r\n"}, {"input": "5 1 3\r\n2 2 2 1 2\r\n2 2 2 1 2\r\n", "output": "TRUTH\r\n"}, {"input": "7 1 4\r\n2 5 5 5 4 3 4\r\n2 5 ...
false
stdio
null
true
847/H
847
H
PyPy 3
TESTS
8
93
0
116883962
n = int(input()) arr = list(map(int, input().split())) forward = arr[:] cnt = arr[0] + 1 for i in range(1, n): forward[i] = max(cnt, arr[i]) cnt = max(cnt, arr[i]) + 1 backward = arr[:] cnt = arr[n - 1] + 1 for i in range(n - 2, -1,-1): backward[i] = max(cnt, arr[i]) cnt = max(cnt, arr[i]) + 1 ans = 0...
39
187
11,161,600
198082420
n = int(input()) p = list(map(int, input().split())) a = [0] * n t = s = f = 0 for i in range(n): if p[i] <= t: a[i] = t - p[i] + 1 t = max(p[i], t+1) for i in range(n-1, 0, -1): if p[i] <= s: a[i] = min(s - p[i] + 1, a[i]) else: a[i] = 0 s = max(p[i], s + 1) for i in range(n): p[i] += a[i] f |= i...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
1
256
Load Testing
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send ai requests. Polycarp plans to test Fakebook under a special kind of...
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the duration of the load testing. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the number of requests from friends in the i-th minute of the load testing.
Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.
null
In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests. In the second example it is enough to make one additional request in the thir...
[{"input": "5\n1 4 3 2 5", "output": "6"}, {"input": "5\n1 2 2 2 1", "output": "1"}, {"input": "7\n10 20 40 50 70 90 30", "output": "0"}]
1,600
["greedy"]
39
[{"input": "5\r\n1 4 3 2 5\r\n", "output": "6\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7\r\n10 20 40 50 70 90 30\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 15\r\n", "output": "0\r\n"}, {"input": "4\r\n36 54 55 9\r\n", "output": "0\r\n"}, {"input"...
false
stdio
null
true
847/H
847
H
PyPy 3
TESTS
4
77
0
120303176
#kaunsi range increasing aur kaunsi decreasing def f(a): n=len(a) pref=[0]*(n) left=[0]*(n) #values left[0]=a[0] for i in range(1,n): left[i]=max(left[i-1]+1,a[i]) pref[i]=pref[i-1]+left[i]-a[i] #increasing shit suf=[0]*(n) right=[0]*(n) right[n-1]=a[n-1] for i in range(n-2,-1,-1): right[i]=max(right[i+...
39
202
11,161,600
197611088
n=int(input()) p=list(map(int,input().split())) a=[0]*n t=s=f=0 for i in range(n): if p[i]<=t:a[i]=t-p[i]+1 t=max(p[i],t+1) for i in range(n-1,0,-1): if p[i] <= s: a[i] = min(s - p[i] + 1,a[i]) else:a[i]=0 s = max(p[i], s + 1) for i in range(n):p[i]+=a[i];f|=i>1and p[i]==p[i-1] print(sum(a[:])+f)
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
1
256
Load Testing
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send ai requests. Polycarp plans to test Fakebook under a special kind of...
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the duration of the load testing. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the number of requests from friends in the i-th minute of the load testing.
Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.
null
In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests. In the second example it is enough to make one additional request in the thir...
[{"input": "5\n1 4 3 2 5", "output": "6"}, {"input": "5\n1 2 2 2 1", "output": "1"}, {"input": "7\n10 20 40 50 70 90 30", "output": "0"}]
1,600
["greedy"]
39
[{"input": "5\r\n1 4 3 2 5\r\n", "output": "6\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7\r\n10 20 40 50 70 90 30\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 15\r\n", "output": "0\r\n"}, {"input": "4\r\n36 54 55 9\r\n", "output": "0\r\n"}, {"input"...
false
stdio
null
true
390/A
390
A
Python 3
TESTS
14
311
1,843,200
52450631
n = int(input()) x = [] y = [] for _ in range(n): a,b = map(int, input().split()) x.append(a) y.append(b) if max(x) > max(y): print(len(set(y))) else: print((len(set(x))))
19
156
0
216395918
n=int(input()) v,h=set(),set() for i in range(n): x,y=map(int,input().split()) v.add(x) h.add(y) print(min(len(v),len(h)))
Codeforces Round 229 (Div. 2)
CF
2,014
1
256
Inna and Alarm Clock
Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 × 100 square with the lower left corner at point (0, 0) and with the upper right corner at point (100, 100). Then the alarm clocks are points with integer coordinates in this square. The morning has ...
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of the alarm clocks. The next n lines describe the clocks: the i-th line contains two integers xi, yi — the coordinates of the i-th alarm clock (0 ≤ xi, yi ≤ 100). Note that a single point in the room can contain any number of alarm clocks and t...
In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally.
null
In the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments. In the third sample it is important to note that Inna doesn't have the right to change the...
[{"input": "4\n0 0\n0 1\n0 2\n1 0", "output": "2"}, {"input": "4\n0 0\n0 1\n1 0\n1 1", "output": "2"}, {"input": "4\n1 1\n1 2\n2 3\n3 3", "output": "3"}]
null
["implementation"]
19
[{"input": "4\r\n0 0\r\n0 1\r\n0 2\r\n1 0\r\n", "output": "2\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1\r\n1 2\r\n2 3\r\n3 3\r\n", "output": "3\r\n"}, {"input": "1\r\n0 0\r\n", "output": "1\r\n"}, {"input": "42\r\n28 87\r\n26 16\r\n59 90\r\n47 61\r\n28 83\r\n36 30\r\n6...
false
stdio
null
true
39/B
39
B
Python 3
TESTS
0
62
0
211827198
n = int(input()) l = list(map(int ,input().split())) res = [] ref = 1 for i in range(len(l)) : if l[i] == ref : res.append(2000 + i+1 ) ref += 1 if res == [] : print(0) else: print(*res)
35
122
6,758,400
131729603
n=int(input()) a=list(map(int,input().split())) res = [] d = 1 for i in range(n): if a[i]==d: d+=1 res.append(2000+i+1) print(len(res)) for i in res: print(i,end=" ")
School Team Contest 1 (Winter Computer School 2010/11)
ICPC
2,010
2
64
Company Income Growth
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 billion bourles, in 2002 — to a2 billion, ..., and in the current (2000 + n)-th...
The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers ai ( - 100 ≤ ai ≤ 100). The number ai determines the income of BerSoft company in the (2000 + i)-th year. The numbers in the line are separated by spaces.
Output k — the maximum possible length of a perfect sequence. In the next line output the sequence of years y1, y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
null
null
[{"input": "10\n-2 1 1 3 2 3 4 -10 -2 5", "output": "5\n2002 2005 2006 2007 2010"}, {"input": "3\n-1 -2 -3", "output": "0"}]
1,300
["greedy"]
35
[{"input": "10\r\n-2 1 1 3 2 3 4 -10 -2 5\r\n", "output": "5\r\n2002 2005 2006 2007 2010 "}, {"input": "3\r\n-1 -2 -3\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n-1 1\r\n", "output": "1\r\n2002 "}, {"input": "2\r\n-1 1\r\n", "output":...
false
stdio
null
true
847/H
847
H
Python 3
TESTS
8
108
0
43115327
n = int(input()) arr = list(map(int, input().split())) starts = [0 for _ in range(n + 1)] ends = [0 for _ in range(n + 1)] starts[1] = arr[0] ends[-2] = arr[-1] for i in range(1, n): starts[i + 1] = max(arr[i], starts[i] + 1) ends[-i - 2] = max(arr[-i - 1], ends[-i - 1] + 1) for i in range(n): starts...
39
217
10,956,800
116888053
n = int(input()) arr = list(map(int, input().split())) forward = arr[:] cnt = arr[0] + 1 for i in range(1, n): forward[i] = max(cnt, arr[i]) cnt = max(cnt, arr[i]) + 1 backward = arr[:] cnt = arr[n - 1] + 1 for i in range(n - 2, -1, -1): backward[i] = max(cnt, arr[i]) cnt = max(cnt, arr[i]) + 1 ans = 0...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
1
256
Load Testing
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send ai requests. Polycarp plans to test Fakebook under a special kind of...
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the duration of the load testing. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the number of requests from friends in the i-th minute of the load testing.
Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.
null
In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests. In the second example it is enough to make one additional request in the thir...
[{"input": "5\n1 4 3 2 5", "output": "6"}, {"input": "5\n1 2 2 2 1", "output": "1"}, {"input": "7\n10 20 40 50 70 90 30", "output": "0"}]
1,600
["greedy"]
39
[{"input": "5\r\n1 4 3 2 5\r\n", "output": "6\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7\r\n10 20 40 50 70 90 30\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 15\r\n", "output": "0\r\n"}, {"input": "4\r\n36 54 55 9\r\n", "output": "0\r\n"}, {"input"...
false
stdio
null
true
847/H
847
H
Python 3
TESTS
6
62
0
30857791
n = int(input()) l = [int(i) for i in input().split(" ")] l_up = l[:] l_down = l[::-1] for i in range(n - 1): if l_up[i+1] <= l_up[i]: l_up[i+1] = l_up[i] + 1 for i in range(n - 1): if l_down[i+1] <= l_down[i]: l_down[i+1] = l_down[i] + 1 l_down = l_down[::-1] index = 0 add = False for index i...
39
296
14,131,200
31659774
s, l, r = 0, 0, int(input()) - 1 t = list(map(int, input().split())) while 1: while l < r and t[l] < t[l + 1]: l += 1 while l < r and t[r] < t[r - 1]: r -= 1 if l == r: break if t[l] < t[r]: s += t[l] - t[l + 1] + 1 t[l + 1] = t[l] + 1 else: s += t[r] - t[r - 1] + 1 t...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
1
256
Load Testing
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send ai requests. Polycarp plans to test Fakebook under a special kind of...
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the duration of the load testing. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the number of requests from friends in the i-th minute of the load testing.
Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.
null
In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests. In the second example it is enough to make one additional request in the thir...
[{"input": "5\n1 4 3 2 5", "output": "6"}, {"input": "5\n1 2 2 2 1", "output": "1"}, {"input": "7\n10 20 40 50 70 90 30", "output": "0"}]
1,600
["greedy"]
39
[{"input": "5\r\n1 4 3 2 5\r\n", "output": "6\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7\r\n10 20 40 50 70 90 30\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 15\r\n", "output": "0\r\n"}, {"input": "4\r\n36 54 55 9\r\n", "output": "0\r\n"}, {"input"...
false
stdio
null
true
847/H
847
H
Python 3
TESTS
8
62
204,800
30479876
n = int(input()) a = list(map(int,input().strip().split())) if n > 1: li = [0]*n ri = [0]*n lm = a[0] c = [0]*n b = [0]*n b[0] = a[0] for i in range(1,n): if lm >= a[i]: li[i] = li[i-1] + (lm+1-a[i]) lm = lm+1 else: li[i] = li[i-1] lm = a[i] b[i] = lm lm = a[n-1] c[n-1] = a[n-1] for i in r...
39
483
19,558,400
30470965
n = int(input()) a = list(map(int, input().split())) lp,rp = [0 for i in range(n)],[0 for i in range(n)] lnr, rnr = [a[i] for i in range(n)],[a[i] for i in range(n)] mx = a[0] for i in range(1,n): if a[i] > mx: mx = a[i] lp[i] = lp[i-1] else: mx += 1 lp[i] = lp[i-1] + mx - a[i]...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
1
256
Load Testing
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send ai requests. Polycarp plans to test Fakebook under a special kind of...
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the duration of the load testing. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the number of requests from friends in the i-th minute of the load testing.
Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.
null
In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests. In the second example it is enough to make one additional request in the thir...
[{"input": "5\n1 4 3 2 5", "output": "6"}, {"input": "5\n1 2 2 2 1", "output": "1"}, {"input": "7\n10 20 40 50 70 90 30", "output": "0"}]
1,600
["greedy"]
39
[{"input": "5\r\n1 4 3 2 5\r\n", "output": "6\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7\r\n10 20 40 50 70 90 30\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 15\r\n", "output": "0\r\n"}, {"input": "4\r\n36 54 55 9\r\n", "output": "0\r\n"}, {"input"...
false
stdio
null
true
847/H
847
H
PyPy 3
TESTS
8
93
0
116885031
n = int(input()) arr = list(map(int, input().split())) forward = arr[:] cnt = arr[0] + 1 for i in range(1, n): forward[i] = max(cnt, arr[i]) cnt = max(cnt, arr[i]) + 1 backward = arr[:] cnt = arr[n - 1] + 1 for i in range(n - 2, -1,-1): backward[i] = max(cnt, arr[i]) cnt = max(cnt, arr[i]) + 1 pref = [...
39
592
15,360,000
43116711
n = int(input()) arr = list(map(int, input().split())) starts = [0 for _ in range(n)] ends = [0 for _ in range(n)] starts[0] = arr[0] ends[-1] = arr[-1] for i in range(1, n): starts[i] = max(arr[i], starts[i - 1] + 1) ends[-i - 1] = max(arr[-i - 1], ends[-i] + 1) sts = starts[:] eds = ends[:] for i in ra...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
1
256
Load Testing
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send ai requests. Polycarp plans to test Fakebook under a special kind of...
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the duration of the load testing. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the number of requests from friends in the i-th minute of the load testing.
Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.
null
In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests. In the second example it is enough to make one additional request in the thir...
[{"input": "5\n1 4 3 2 5", "output": "6"}, {"input": "5\n1 2 2 2 1", "output": "1"}, {"input": "7\n10 20 40 50 70 90 30", "output": "0"}]
1,600
["greedy"]
39
[{"input": "5\r\n1 4 3 2 5\r\n", "output": "6\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7\r\n10 20 40 50 70 90 30\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 15\r\n", "output": "0\r\n"}, {"input": "4\r\n36 54 55 9\r\n", "output": "0\r\n"}, {"input"...
false
stdio
null
true
774/D
774
D
Python 3
TESTS
17
124
9,625,600
174840898
n, l, r = list(map(int, input().rstrip().split())) a = list(map(int, input().rstrip().split())) b = list(map(int, input().rstrip().split())) a1=a[l-1:r] a1.sort() b1=b[l-1:r] b1.sort() print("TRUTH" if a1==b1 else "LIE")
52
93
15,155,200
26154633
N, l, r = input().split(' ') N = int(N) l = int(l) r = int(r) A = input().split(' ') B = input().split(' ') truth = True for i in range(0,l-1,1): if A[i] != B[i]: truth = False for i in range(N-1,r-1,-1): if A[i] != B[i]: truth = False if truth == True: print("TRUTH") else: print("LIE...
VK Cup 2017 - Wild Card Round 1
ICPC
2,017
2
256
Lie or Truth
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an. While Vasya was walking, his little brother Stepan played with Vasya's cubes and chan...
The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence b1, b2, ...
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
null
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and...
[{"input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1", "output": "TRUTH"}, {"input": "3 1 2\n1 2 3\n3 1 2", "output": "LIE"}, {"input": "4 2 4\n1 1 1 1\n1 1 1 1", "output": "TRUTH"}]
1,500
["*special", "constructive algorithms", "implementation", "sortings"]
52
[{"input": "5 2 4\r\n3 4 2 3 1\r\n3 2 3 4 1\r\n", "output": "TRUTH\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n3 1 2\r\n", "output": "LIE\r\n"}, {"input": "4 2 4\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "TRUTH\r\n"}, {"input": "5 1 3\r\n2 2 2 1 2\r\n2 2 2 1 2\r\n", "output": "TRUTH\r\n"}, {"input": "7 1 4\r\n2 5 5 5 4 3 4\r\n2 5 ...
false
stdio
null
true
292/A
292
A
Python 3
TESTS
0
62
0
168977239
n = eval(input()) cnt = 0 lt = 0 mn = 0 for i in range(n): t, c = input().split() t, c = int(t), int(c) n -= t - lt lt = t if n < 0: n = 0 n += c if n > mn: mn = n print(n + t, mn)
38
92
0
4440878
n = int(input()) mt = 0 mq = 0 t = 0 q = 0 for i in range(n): (ti, ci) = map(int, input().split()) q = max(0, q-ti+t) t = ti q += ci mq = max(mq, q) mt = t+q print(mt, mq)
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
103/A
103
A
PyPy 3
TESTS
4
248
20,172,800
86968182
n = int(input()) t= list(map(int,input().split())) p=t[0] if n>1: for j in range(1,n): p+=1+(t[j]-1)*2 print(p)
25
92
0
139923210
n=int(input()) l=list(map(int,input().split())) ans=0 for i in range(n): ans+=l[i]+ i*(l[i]-1) print(ans)
Codeforces Beta Round 80 (Div. 1 Only)
CF
2,011
2
256
Testing Pants for Sadness
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ...
The first line contains a positive integer n (1 ≤ n ≤ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 ≤ ai ≤ 109), the number of answer variants to question i.
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the thir...
[{"input": "2\n1 1", "output": "2"}, {"input": "2\n2 2", "output": "5"}, {"input": "1\n10", "output": "10"}]
1,100
["greedy", "implementation", "math"]
25
[{"input": "2\r\n1 1\r\n", "output": "2"}, {"input": "2\r\n2 2\r\n", "output": "5"}, {"input": "1\r\n10\r\n", "output": "10"}, {"input": "3\r\n2 4 1\r\n", "output": "10"}, {"input": "4\r\n5 5 3 1\r\n", "output": "22"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "2999999999"}, {"input": "10\r\n5 7 8 1 10 3 6 ...
false
stdio
null
true
103/A
103
A
PyPy 3
TESTS
4
248
20,172,800
87017308
n=int(input()) a=list(map(int,input().split())) s=a[0] for i in range(1,len(a)): s=s+(a[i]-1)+a[i] print(s)
25
92
0
142539758
r=input;r();print(sum(int(v)*i-i+1for i,v in enumerate(r().split(),1)))
Codeforces Beta Round 80 (Div. 1 Only)
CF
2,011
2
256
Testing Pants for Sadness
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ...
The first line contains a positive integer n (1 ≤ n ≤ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 ≤ ai ≤ 109), the number of answer variants to question i.
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the thir...
[{"input": "2\n1 1", "output": "2"}, {"input": "2\n2 2", "output": "5"}, {"input": "1\n10", "output": "10"}]
1,100
["greedy", "implementation", "math"]
25
[{"input": "2\r\n1 1\r\n", "output": "2"}, {"input": "2\r\n2 2\r\n", "output": "5"}, {"input": "1\r\n10\r\n", "output": "10"}, {"input": "3\r\n2 4 1\r\n", "output": "10"}, {"input": "4\r\n5 5 3 1\r\n", "output": "22"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "2999999999"}, {"input": "10\r\n5 7 8 1 10 3 6 ...
false
stdio
null
true
965/D
965
D
PyPy 3
TESTS
8
155
10,444,800
85766576
# D - Single-use Stones w,l = [int(i) for i in input().split(' ')] a = [1E6]*(w+1) entrada = [int(i) for i in input().split(' ')] for i in range (1, w): a[i] = entrada[i-1] aux = [0]*len(a) num = 0 for j in range (1, w+1): if(a[j] <= 0): continue if(j <= l): aux[j] = a[j] conti...
16
77
13,619,200
211191021
# Lê a largura w e o comprimento mínimo l w, l = map(int, input().split()) # Lê os valores das pedras disponíveis a = list(map(int, input().split())) s = [0] # Inicializa uma lista s com o valor inicial 0 for i in a: # Calcula as somas cumulativas s.append(s[-1] + i) # Cada elemento de s é a soma dos val...
Codeforces Round 476 (Div. 2) [Thanks, Telegram!]
CF
2,018
1
256
Single-use Stones
A lot of frogs want to cross a river. A river is $$$w$$$ units width, but frogs can only jump $$$l$$$ units long, where $$$l < w$$$. Frogs can also jump on lengths shorter than $$$l$$$. but can't jump longer. Hopefully, there are some stones in the river to help them. The stones are located at integer distances from t...
The first line contains two integers $$$w$$$ and $$$l$$$ ($$$1 \le l < w \le 10^5$$$) — the width of the river and the maximum length of a frog's jump. The second line contains $$$w - 1$$$ integers $$$a_1, a_2, \ldots, a_{w-1}$$$ ($$$0 \le a_i \le 10^4$$$), where $$$a_i$$$ is the number of stones at the distance $$$i$...
Print a single integer — the maximum number of frogs that can cross the river.
null
In the first sample two frogs can use the different stones at the distance $$$5$$$, and one frog can use the stones at the distances $$$3$$$ and then $$$8$$$. In the second sample although there are two stones at the distance $$$5$$$, that does not help. The three paths are: $$$0 \to 3 \to 6 \to 9 \to 10$$$, $$$0 \to ...
[{"input": "10 5\n0 0 1 0 2 0 0 1 0", "output": "3"}, {"input": "10 3\n1 1 1 1 2 1 1 1 1", "output": "3"}]
1,900
["binary search", "flows", "greedy", "two pointers"]
16
[{"input": "10 5\r\n0 0 1 0 2 0 0 1 0\r\n", "output": "3\r\n"}, {"input": "10 3\r\n1 1 1 1 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2 1\r\n0\r\n", "output": "0\r\n"}, {"input": "2 1\r\n5\r\n", "output": "5\r\n"}, {"input": "10 4\r\n0 0 6 2 7 1 6 4 0\r\n", "output": "8\r\n"}, {"input": "100 15\r\n0 0 1 1 1 0 1 1 1...
false
stdio
null
true
774/D
774
D
PyPy 3-64
TESTS
17
92
20,275,200
183861208
from sys import stdin n,l,r = map(int, stdin.readline().rstrip().split(' ')) org = list(map(int, stdin.readline().rstrip().split(' '))) swapped = list(map(int, stdin.readline().rstrip().split(' '))) s = org[l-1] for i in range(l, r): s ^= org[i] swapped_s = swapped[l-1] for i in range(l,r): swapped_s ^= swapp...
52
93
19,763,200
232571022
def solve(): line1=input() line2=input() line3=input() n,l,r=[int(x) for x in line1.split()] before=[int(x) for x in line2.split()] after=[int(x) for x in line3.split()] if before[:l - 1] == after[:l - 1] and before[r:] == after[r:]: print("TRUTH") else: print("LIE") # ...
VK Cup 2017 - Wild Card Round 1
ICPC
2,017
2
256
Lie or Truth
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an. While Vasya was walking, his little brother Stepan played with Vasya's cubes and chan...
The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence b1, b2, ...
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
null
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and...
[{"input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1", "output": "TRUTH"}, {"input": "3 1 2\n1 2 3\n3 1 2", "output": "LIE"}, {"input": "4 2 4\n1 1 1 1\n1 1 1 1", "output": "TRUTH"}]
1,500
["*special", "constructive algorithms", "implementation", "sortings"]
52
[{"input": "5 2 4\r\n3 4 2 3 1\r\n3 2 3 4 1\r\n", "output": "TRUTH\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n3 1 2\r\n", "output": "LIE\r\n"}, {"input": "4 2 4\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "TRUTH\r\n"}, {"input": "5 1 3\r\n2 2 2 1 2\r\n2 2 2 1 2\r\n", "output": "TRUTH\r\n"}, {"input": "7 1 4\r\n2 5 5 5 4 3 4\r\n2 5 ...
false
stdio
null
true
713/A
713
A
PyPy 3
TESTS
25
530
11,059,200
92339531
from sys import stdout,stdin d={} for _ in range(int(input())): t=stdin.readline() t=str(t) s=t[0] n=t[2:] b="0"*(18-len(n)) for i in n: if i!="\n": if int(i)%2==0: b+="0" else: b+="1" if s=="+": if b in d: d...
37
233
23,449,600
167818193
import sys from collections import defaultdict input = sys.stdin.readline n = int(input()) d = defaultdict(int) for i in range(n): s = input().split() if(s[0] == '?'): a = '0' * (18 - len(s[1])) + s[1] print(d[a]) else: a = '' m = int(s[1]) while(m > 0): ...
Codeforces Round 371 (Div. 1)
CF
2,016
1
256
Sonya and Queries
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: 1. +  ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurre...
The first line of the input contains an integer t (1 ≤ t ≤ 100 000) — the number of operation Sonya has to perform. Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci — the type of the corresponding operation. If ci is equal to '+' or '-...
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
null
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input. 1. 1 and 241. 2. 361. 3. 101 and 361. 4. 361. 5. 4000.
[{"input": "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0", "output": "2\n1\n2\n1\n1"}, {"input": "4\n+ 200\n+ 200\n- 200\n? 0", "output": "1"}]
1,400
["data structures", "implementation"]
37
[{"input": "12\r\n+ 1\r\n+ 241\r\n? 1\r\n+ 361\r\n- 241\r\n? 0101\r\n+ 101\r\n? 101\r\n- 101\r\n? 101\r\n+ 4000\r\n? 0\r\n", "output": "2\r\n1\r\n2\r\n1\r\n1\r\n"}, {"input": "4\r\n+ 200\r\n+ 200\r\n- 200\r\n? 0\r\n", "output": "1\r\n"}, {"input": "20\r\n+ 61\r\n+ 99\r\n+ 51\r\n+ 70\r\n+ 7\r\n+ 34\r\n+ 71\r\n+ 86\r\n+ ...
false
stdio
null
true
545/B
545
B
PyPy 3-64
TESTS
2
30
1,945,600
208637078
def solve(s1,s2): n = len(s1) c = 0 for i in range(n): if s1[i]!=s2[i]: c+=1 if c%2==1: return('impossible') else: r = "" idx = 0 while c>0: if s1[idx]=='0': r+='1' else: r+='0' ...
54
62
307,200
201770920
def girl(s, t): new_str = "" chet = True for i in range(len(s)): if s[i] != t[i]: if chet: new_str += s[i] chet = False else: new_str += t[i] chet = True else: new_str += s[i] if chet: print(new_str)...
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/B
545
B
Python 3
TESTS
2
61
307,200
208637591
def solve(s1,s2): n = len(s1) c = 0 for i in range(n): if s1[i]!=s2[i]: c+=1 if c%2==1: return('impossible') else: return s1[:c] + s2[c:] def calc_distance(s1,s2): c = 0 n = len(s1) for i in range(n): if s1[i]!=s2[i]: ...
54
77
10,854,400
208637374
# Enter your code here. Read input from STDIN. Print output to STDOUT import math if __name__ == '__main__': a = input().strip() b = input().strip() c = [] swap = False sc = 0 for x, y in zip(a, b): if x == y: c.append(x) else: if swap: c.append(y) else: ...
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
175/C
175
C
PyPy 3
TESTS
2
216
1,843,200
109802617
import sys import math from heapq import *; input = sys.stdin.readline from functools import cmp_to_key; def pi(): return(int(input())) def pl(): return(int(input(), 16)) def ti(): return(list(map(int,input().split()))) def ts(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(i...
90
310
0
73499042
n = int(input()) fig = [tuple(map(int, input().split()))[::-1] for _ in range(n)] fig.sort() t = int(input()) a = list(map(int, input().split())) res, curr = 0, 0 i, j = 0, 0 while i < n: if j < t and curr + fig[i][1] >= a[j]: take = a[j] - curr curr += take fig[i] = (fig[i][0], fig[i][1] -...
Codeforces Round 115
CF
2,012
2
256
Geometry Horse
Vasya plays the Geometry Horse. The game goal is to destroy geometric figures of the game world. A certain number of points is given for destroying each figure depending on the figure type and the current factor value. There are n types of geometric figures. The number of figures of type ki and figure cost ci is know...
The first line contains the only integer number n (1 ≤ n ≤ 100) — the number of figure types. Each of the following n lines contains two integer numbers ki and ci (1 ≤ ki ≤ 109, 0 ≤ ci ≤ 1000), separated with space — the number of figures of the i-th type and the cost of one i-type figure, correspondingly. The next l...
Print the only number — the maximum number of points Vasya can get.
null
In the first example Vasya destroys three figures first and gets 3·1·10 = 30 points. Then the factor will become equal to 2 and after destroying the last two figures Vasya will get 2·2·10 = 40 points. As a result Vasya will get 70 points. In the second example all 8 figures will be destroyed with factor 1, so Vasya wi...
[{"input": "1\n5 10\n2\n3 6", "output": "70"}, {"input": "2\n3 8\n5 10\n1\n20", "output": "74"}]
1,600
["greedy", "implementation", "sortings", "two pointers"]
90
[{"input": "1\r\n5 10\r\n2\r\n3 6\r\n", "output": "70"}, {"input": "2\r\n3 8\r\n5 10\r\n1\r\n20\r\n", "output": "74"}, {"input": "3\r\n10 3\r\n20 2\r\n30 1\r\n3\r\n30 50 60\r\n", "output": "200"}, {"input": "1\r\n100 1000\r\n1\r\n1\r\n", "output": "199000"}, {"input": "1\r\n1 1000\r\n1\r\n1\r\n", "output": "1000"}, {"i...
false
stdio
null
true
175/C
175
C
Python 3
TESTS
2
124
0
11767931
import sys def solve(): n, = rv() figures = list() before = 0 for i in range(n): number, cost, = rv() figures.append((cost, number, before + 1, before + number)) before += number figures.sort() t, = rv() p = [0] + list(map(int, input().split())) res = 0 for i...
90
310
8,908,800
167194152
from cmath import inf from operator import itemgetter from typing import * from collections import deque, Counter, defaultdict from bisect import * import heapq, math from functools import cmp_to_key, reduce from itertools import groupby, islice, zip_longest # from sortedcontainers import SortedSet, SortedList def m...
Codeforces Round 115
CF
2,012
2
256
Geometry Horse
Vasya plays the Geometry Horse. The game goal is to destroy geometric figures of the game world. A certain number of points is given for destroying each figure depending on the figure type and the current factor value. There are n types of geometric figures. The number of figures of type ki and figure cost ci is know...
The first line contains the only integer number n (1 ≤ n ≤ 100) — the number of figure types. Each of the following n lines contains two integer numbers ki and ci (1 ≤ ki ≤ 109, 0 ≤ ci ≤ 1000), separated with space — the number of figures of the i-th type and the cost of one i-type figure, correspondingly. The next l...
Print the only number — the maximum number of points Vasya can get.
null
In the first example Vasya destroys three figures first and gets 3·1·10 = 30 points. Then the factor will become equal to 2 and after destroying the last two figures Vasya will get 2·2·10 = 40 points. As a result Vasya will get 70 points. In the second example all 8 figures will be destroyed with factor 1, so Vasya wi...
[{"input": "1\n5 10\n2\n3 6", "output": "70"}, {"input": "2\n3 8\n5 10\n1\n20", "output": "74"}]
1,600
["greedy", "implementation", "sortings", "two pointers"]
90
[{"input": "1\r\n5 10\r\n2\r\n3 6\r\n", "output": "70"}, {"input": "2\r\n3 8\r\n5 10\r\n1\r\n20\r\n", "output": "74"}, {"input": "3\r\n10 3\r\n20 2\r\n30 1\r\n3\r\n30 50 60\r\n", "output": "200"}, {"input": "1\r\n100 1000\r\n1\r\n1\r\n", "output": "199000"}, {"input": "1\r\n1 1000\r\n1\r\n1\r\n", "output": "1000"}, {"i...
false
stdio
null
true
282/A
282
A
Python 3
TESTS
5
30
0
227798035
n = int(input()) l = [] z = 0 while z < n: y = input("") l.append(y) z += 1 x = 0 x += l.count("++X") or l.count("X++") x -= l.count("--X") or l.count("X--") print(x)
36
31
0
227665766
t=int(input()) k=0 for i in range(t): s=input() if s[1]=='+': k+=1 else: k-=1 print(k)
Codeforces Round 173 (Div. 2)
CF
2,013
1
256
Bit++
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: - Operation ++ increases the value of variable x by 1. - Operation -- decreases the value of variable x by 1. A s...
The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme. Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable c...
Print a single integer — the final value of x.
null
null
[{"input": "1\n++X", "output": "1"}, {"input": "2\nX++\n--X", "output": "0"}]
800
["implementation"]
36
[{"input": "1\r\n++X\r\n", "output": "1\r\n"}, {"input": "2\r\nX++\r\n--X\r\n", "output": "0\r\n"}, {"input": "3\r\n++X\r\n++X\r\n++X\r\n", "output": "3\r\n"}, {"input": "2\r\n--X\r\n--X\r\n", "output": "-2\r\n"}, {"input": "5\r\n++X\r\n--X\r\n++X\r\n--X\r\n--X\r\n", "output": "-1\r\n"}, {"input": "28\r\nX--\r\n++X\r\n...
false
stdio
null
true
321/C
321
C
Python 3
TESTS
8
248
0
42550678
class Node: def __init__(self, nr): self.info = nr self.neighbours = [] self.count = 1 self.parent = None def addn(self, node): self.neighbours.append(node) node.parent = self def addc(self, nr): self.count += nr n = int(input()) neighbours = [[]] vis...
44
842
46,080,000
188288006
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): retu...
Codeforces Round 190 (Div. 1)
CF
2,013
1
256
Ciel the Commander
Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has n cities connected by n - 1 undirected roads, and for any two cities there always exists a path between them. Fox Ciel needs to assign an officer to each city. Each officer has a rank — a letter from 'A' to 'Z'. So there will be 26 diffe...
The first line contains an integer n (2 ≤ n ≤ 105) — the number of cities in Tree Land. Each of the following n - 1 lines contains two integers a and b (1 ≤ a, b ≤ n, a ≠ b) — they mean that there will be an undirected road between a and b. Consider all the cities are numbered from 1 to n. It guaranteed that the give...
If there is a valid plane, output n space-separated characters in a line — i-th character is the rank of officer in the city with number i. Otherwise output "Impossible!".
null
In the first example, for any two officers of rank 'B', an officer with rank 'A' will be on the path between them. So it is a valid solution.
[{"input": "4\n1 2\n1 3\n1 4", "output": "A B B B"}, {"input": "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10", "output": "D C B A D C B D C D"}]
2,100
["constructive algorithms", "dfs and similar", "divide and conquer", "greedy", "trees"]
44
[{"input": "4\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "A B B B\r\n"}, {"input": "10\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 9\r\n9 10\r\n", "output": "D C B A D C B D C D\r\n"}, {"input": "6\r\n1 2\r\n2 4\r\n4 5\r\n6 4\r\n3 2\r\n", "output": "B A B B C C\r\n"}, {"input": "2\r\n2 1\r\n", "output": "A B\r\n"},...
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] with open(input_path) as f: input_lines = f.read().splitlines() with open(submission_path) as f: submission_output = f.read().strip() with...
true
774/B
774
B
PyPy 3
TESTS
5
109
23,142,400
26155506
class Mcl: def __init__(self, a, b): self.c = a self.w = b def __lt__(a, b): return a.c < b.c or a.c == b.c and a.w > b.w def __gt__(a, b): return a.c > b.c or a.c == b.c and a.w < b.w def __repr__(self): return "(" + str(self.c) + ", " + str(self.w) + ")" de...
44
1,278
30,310,400
26151161
n, m, d = list(map(int, input().split())) a = [] b = [] for i in range(n): a.append(list(map(int, input().split()))) for i in range(m): b.append(list(map(int, input().split()))) a = sorted(a, key=lambda x: x[0] + (1- x[1] * 1e-10)) b = sorted(b, key=lambda x: x[0] + (1- x[1] * 1e-10)) tc, td = 0, 0 tc += ...
VK Cup 2017 - Wild Card Round 1
ICPC
2,017
3
256
Significant Cups
Stepan is a very experienced olympiad participant. He has n cups for Physics olympiads and m cups for Informatics olympiads. Each cup is characterized by two parameters — its significance ci and width wi. Stepan decided to expose some of his cups on a shelf with width d in such a way, that: - there is at least one Ph...
The first line contains three integers n, m and d (1 ≤ n, m ≤ 100 000, 1 ≤ d ≤ 109) — the number of cups for Physics olympiads, the number of cups for Informatics olympiads and the width of the shelf. Each of the following n lines contains two integers ci and wi (1 ≤ ci, wi ≤ 109) — significance and width of the i-th ...
Print the maximum possible total significance, which Stepan can get exposing cups on the shelf with width d, considering all the rules described in the statement. If there is no way to expose cups on the shelf, then print 0.
null
In the first example Stepan has only one Informatics cup which must be exposed on the shelf. Its significance equals 3 and width equals 2, so after Stepan exposes it, the width of free space on the shelf becomes equal to 6. Also, Stepan must expose the second Physics cup (which has width 5), because it is the most sign...
[{"input": "3 1 8\n4 2\n5 5\n4 2\n3 2", "output": "8"}, {"input": "4 3 12\n3 4\n2 4\n3 5\n3 4\n3 5\n5 2\n3 4", "output": "11"}, {"input": "2 2 2\n5 3\n6 3\n4 2\n8 1", "output": "0"}]
2,100
["*special", "binary search", "data structures", "two pointers"]
44
[{"input": "3 1 8\r\n4 2\r\n5 5\r\n4 2\r\n3 2\r\n", "output": "8\r\n"}, {"input": "4 3 12\r\n3 4\r\n2 4\r\n3 5\r\n3 4\r\n3 5\r\n5 2\r\n3 4\r\n", "output": "11\r\n"}, {"input": "2 2 2\r\n5 3\r\n6 3\r\n4 2\r\n8 1\r\n", "output": "0\r\n"}, {"input": "10 10 229\r\n15 17\r\n5 4\r\n4 15\r\n4 17\r\n15 11\r\n7 6\r\n5 19\r\n14 ...
false
stdio
null
true
546/B
546
B
Python 3
TESTS
9
46
204,800
222668715
n=int(input()) x=sorted(list(map(int,input().split()))) ans=0 for i in range(n): if x[i]!=i+1: ans+=x[i]-i+1 print(ans)
49
62
307,200
11212168
#!/usr/bin/env python # -.- coding: utf-8 -.- n = int(input()) cool_factors = [int(item) for item in input().strip().split(" ")] cool_factors.sort() acc = 0 for i in range(1, len(cool_factors)): if cool_factors[i] <= cool_factors[i - 1]: diff = cool_factors[i - 1] - cool_factors[i] + 1 cool_factors...
Codeforces Round 304 (Div. 2)
CF
2,015
3
256
Soldier and Badges
Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin. For every pair of soldiers one of them should get a badge with strictly higher factor than the second...
First line of input consists of one integer n (1 ≤ n ≤ 3000). Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge.
Output single integer — minimum amount of coins the colonel has to pay.
null
In first sample test we can increase factor of first badge by 1. In second sample test we can increase factors of the second and the third badge by 1.
[{"input": "4\n1 3 1 4", "output": "1"}, {"input": "5\n1 2 3 2 5", "output": "2"}]
1,200
["brute force", "greedy", "implementation", "sortings"]
49
[{"input": "4\r\n1 3 1 4\r\n", "output": "1"}, {"input": "5\r\n1 2 3 2 5\r\n", "output": "2"}, {"input": "5\r\n1 5 3 2 4\r\n", "output": "0"}, {"input": "10\r\n1 1 2 3 4 5 6 7 8 9\r\n", "output": "9"}, {"input": "11\r\n9 2 10 3 1 5 7 1 4 8 6\r\n", "output": "10"}, {"input": "4\r\n4 3 2 2\r\n", "output": "3"}, {"input":...
false
stdio
null
true
713/C
713
C
Python 3
TESTS
5
77
921,600
21611261
import math import random def IsRW (River): t=1 for i in range(len(River)-1): if River[i+1]<=River[i]: t=0 return t def SwitchRivers (River,L,R,k): for i in range (len(River)-2): j=i+1 if (River[j]<River[j-1]) and (River[j]<River[j+1]) and (River[j+1]>River[j-1]): ...
57
140
9,625,600
208735914
import sys readline=sys.stdin.readline import heapq from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max def _heappush_max(heap,item): heap.append(item) heapq._siftdown_max(heap, 0, len(heap)-1) def _heappushpop_max(heap, item): if heap and item < heap[0]: item, heap[0] =...
Codeforces Round 371 (Div. 1)
CF
2,016
5
256
Sonya and Problem Wihtout a Legend
Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operati...
The first line of the input contains a single integer n (1 ≤ n ≤ 3000) — the length of the array. Next line contains n integer ai (1 ≤ ai ≤ 109).
Print the minimum number of operation required to make the array strictly increasing.
null
In the first sample, the array is going to look as follows: 2 3 5 6 7 9 11 |2 - 2| + |1 - 3| + |5 - 5| + |11 - 6| + |5 - 7| + |9 - 9| + |11 - 11| = 9 And for the second sample: 1 2 3 4 5 |5 - 1| + |4 - 2| + |3 - 3| + |2 - 4| + |1 - 5| = 12
[{"input": "7\n2 1 5 11 5 9 11", "output": "9"}, {"input": "5\n5 4 3 2 1", "output": "12"}]
2,300
["dp", "sortings"]
57
[{"input": "7\r\n2 1 5 11 5 9 11\r\n", "output": "9\r\n"}, {"input": "5\r\n5 4 3 2 1\r\n", "output": "12\r\n"}, {"input": "2\r\n1 1000\r\n", "output": "0\r\n"}, {"input": "2\r\n1000 1\r\n", "output": "1000\r\n"}, {"input": "5\r\n100 80 60 70 90\r\n", "output": "54\r\n"}, {"input": "10\r\n10 16 17 11 1213 1216 1216 1209...
false
stdio
null
true
965/D
965
D
PyPy 3-64
TESTS
14
93
11,571,200
201385075
import sys from array import array input = lambda: sys.stdin.buffer.readline().decode().rstrip() inp = lambda dtype: [dtype(x) for x in input().split()] debug = lambda *x: print(*x, file=sys.stderr) ceil_ = lambda a, b: (a + b - 1) // b sum_n = lambda n: (n * (n + 1)) // 2 get_bit = lambda x, i: (x >> i) & 1 Mint, Mlo...
16
77
13,721,600
211782265
w, l = map(int, input().split()) stones = list(map(int, input().split())) prefixSums = [0] * (w - l) prefixSums[0] = sum(stones[:l]) for i in range (w - 1 - l): prefixSums[i + 1] += prefixSums[i] + stones[i + l] - stones[i] print(min(prefixSums))
Codeforces Round 476 (Div. 2) [Thanks, Telegram!]
CF
2,018
1
256
Single-use Stones
A lot of frogs want to cross a river. A river is $$$w$$$ units width, but frogs can only jump $$$l$$$ units long, where $$$l < w$$$. Frogs can also jump on lengths shorter than $$$l$$$. but can't jump longer. Hopefully, there are some stones in the river to help them. The stones are located at integer distances from t...
The first line contains two integers $$$w$$$ and $$$l$$$ ($$$1 \le l < w \le 10^5$$$) — the width of the river and the maximum length of a frog's jump. The second line contains $$$w - 1$$$ integers $$$a_1, a_2, \ldots, a_{w-1}$$$ ($$$0 \le a_i \le 10^4$$$), where $$$a_i$$$ is the number of stones at the distance $$$i$...
Print a single integer — the maximum number of frogs that can cross the river.
null
In the first sample two frogs can use the different stones at the distance $$$5$$$, and one frog can use the stones at the distances $$$3$$$ and then $$$8$$$. In the second sample although there are two stones at the distance $$$5$$$, that does not help. The three paths are: $$$0 \to 3 \to 6 \to 9 \to 10$$$, $$$0 \to ...
[{"input": "10 5\n0 0 1 0 2 0 0 1 0", "output": "3"}, {"input": "10 3\n1 1 1 1 2 1 1 1 1", "output": "3"}]
1,900
["binary search", "flows", "greedy", "two pointers"]
16
[{"input": "10 5\r\n0 0 1 0 2 0 0 1 0\r\n", "output": "3\r\n"}, {"input": "10 3\r\n1 1 1 1 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2 1\r\n0\r\n", "output": "0\r\n"}, {"input": "2 1\r\n5\r\n", "output": "5\r\n"}, {"input": "10 4\r\n0 0 6 2 7 1 6 4 0\r\n", "output": "8\r\n"}, {"input": "100 15\r\n0 0 1 1 1 0 1 1 1...
false
stdio
null
true
321/C
321
C
PyPy 3-64
TESTS
8
156
3,276,800
153502796
#Problem E import sys, collections,string input = lambda: sys.stdin.readline()[:-1] get_int = lambda: int(input()) get_int_iter = lambda: map(int,input().split()) get_int_list = lambda: list(map(int,input().split())) n = get_int() edges = collections.defaultdict(list) for edge in range(n-1): a,b = get_int_iter() ...
44
966
28,364,800
141254513
def centroid_tree_decomposition(graph): n = len(graph) graph = [c[:] for c in graph] # copy bfs = [0] for node in bfs: bfs += graph[node] for nei in graph[node]: graph[nei].remove(node) size = [0] * n for node in reversed(bfs): size[node] = 1 + sum(size[child]...
Codeforces Round 190 (Div. 1)
CF
2,013
1
256
Ciel the Commander
Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has n cities connected by n - 1 undirected roads, and for any two cities there always exists a path between them. Fox Ciel needs to assign an officer to each city. Each officer has a rank — a letter from 'A' to 'Z'. So there will be 26 diffe...
The first line contains an integer n (2 ≤ n ≤ 105) — the number of cities in Tree Land. Each of the following n - 1 lines contains two integers a and b (1 ≤ a, b ≤ n, a ≠ b) — they mean that there will be an undirected road between a and b. Consider all the cities are numbered from 1 to n. It guaranteed that the give...
If there is a valid plane, output n space-separated characters in a line — i-th character is the rank of officer in the city with number i. Otherwise output "Impossible!".
null
In the first example, for any two officers of rank 'B', an officer with rank 'A' will be on the path between them. So it is a valid solution.
[{"input": "4\n1 2\n1 3\n1 4", "output": "A B B B"}, {"input": "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10", "output": "D C B A D C B D C D"}]
2,100
["constructive algorithms", "dfs and similar", "divide and conquer", "greedy", "trees"]
44
[{"input": "4\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "A B B B\r\n"}, {"input": "10\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 9\r\n9 10\r\n", "output": "D C B A D C B D C D\r\n"}, {"input": "6\r\n1 2\r\n2 4\r\n4 5\r\n6 4\r\n3 2\r\n", "output": "B A B B C C\r\n"}, {"input": "2\r\n2 1\r\n", "output": "A B\r\n"},...
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] with open(input_path) as f: input_lines = f.read().splitlines() with open(submission_path) as f: submission_output = f.read().strip() with...
true
799/C
799
C
Python 3
TESTS
6
77
0
121333151
from bisect import bisect_right as br def f(Coin,Diamond,c,d): Coin=sorted(Coin,key=lambda s:s[1]) Coin=sorted(Coin,key=lambda s:s[0]) Diamond=sorted(Diamond,key=lambda s:s[1]) Diamond=sorted(Diamond,key=lambda s:s[0]) c1=[] c2=[] for i in range(len(Coin)): t=c if Coin[i][0]>c: break rr=br(Coin,(t-Coin...
79
468
27,136,000
203455020
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def sparse_table(a): table = [] s0, l = a, 1 table.append(s0) while 2 * l <= len(a): s = [max(s0[i], s0[i + l]) for i in range(len(s0) - l)] table.append(list(s)) s0 = s l *= 2 return tab...
Playrix Codescapes Cup (Codeforces Round 413, rated, Div. 1 + Div. 2)
CF
2,017
2
256
Fountains
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allow...
The first line contains three integers n, c and d (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 000) — the number of fountains, the number of coins and diamonds Arkady has. The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 ≤ bi, pi ≤ 100 000) — the beauty and the cost of the i-th fountain, ...
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
null
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9. In the second example t...
[{"input": "3 7 6\n10 8 C\n4 3 C\n5 6 D", "output": "9"}, {"input": "2 4 5\n2 5 C\n2 1 D", "output": "0"}, {"input": "3 10 10\n5 5 C\n5 5 C\n10 11 D", "output": "10"}]
1,800
["binary search", "data structures", "implementation"]
79
[{"input": "3 7 6\r\n10 8 C\r\n4 3 C\r\n5 6 D\r\n", "output": "9\r\n"}, {"input": "2 4 5\r\n2 5 C\r\n2 1 D\r\n", "output": "0\r\n"}, {"input": "3 10 10\r\n5 5 C\r\n5 5 C\r\n10 11 D\r\n", "output": "10\r\n"}, {"input": "6 68 40\r\n1 18 D\r\n6 16 D\r\n11 16 D\r\n7 23 D\r\n16 30 D\r\n2 20 D\r\n", "output": "18\r\n"}, {"in...
false
stdio
null
true
847/H
847
H
Python 3
TESTS
8
46
0
169523391
from sys import stdin import math def main(): n = int(stdin.readline()) a = list(map(int, stdin.readline().split())) res = 0 l = 0 r = n-1 while l < n-1 and a[l+1] > a[l]: l += 1 while r > 0 and a[r-1] > a[r]: r -= 1 while l < r: ll = a[l] - a[l+1] + 1 r...
39
109
20,582,400
182942535
import sys input = sys.stdin.readline n = int(input()) w = list(map(int, input().split())) d = [w[0]] e = [w[-1]] for i in w[1:]: d.append(max(d[-1]+1, i)) for i in w[:-1][::-1]: e.append(max(e[-1]+1, i)) e = e[::-1] c = 10**18 f = -1 for i in range(n): a = max(d[i], e[i]) b = (2*a-i)*(i+1) + (2*a-(n-i...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
1
256
Load Testing
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send ai requests. Polycarp plans to test Fakebook under a special kind of...
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the duration of the load testing. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the number of requests from friends in the i-th minute of the load testing.
Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.
null
In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests. In the second example it is enough to make one additional request in the thir...
[{"input": "5\n1 4 3 2 5", "output": "6"}, {"input": "5\n1 2 2 2 1", "output": "1"}, {"input": "7\n10 20 40 50 70 90 30", "output": "0"}]
1,600
["greedy"]
39
[{"input": "5\r\n1 4 3 2 5\r\n", "output": "6\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7\r\n10 20 40 50 70 90 30\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 15\r\n", "output": "0\r\n"}, {"input": "4\r\n36 54 55 9\r\n", "output": "0\r\n"}, {"input"...
false
stdio
null
true
847/H
847
H
Python 3
TESTS
8
46
5,734,400
33505680
n=int(input()) p=list(map(int,input().split())) a=[0]*n t=-1 for i in range(n): if p[i]<=t:a[i]=t-p[i]+1 t=max(p[i],t+1) t=-1 for i in range(n-1,0,-1): if p[i] <= t: a[i] = min(t - p[i] + 1,a[i]) else:a[i]=0 t = max(p[i], t + 1) print(sum(a[1:n-1]))
39
124
19,046,400
211256726
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb N = int(input()) A = list(map(int,input().split())) R,L = A[:],A[:] r,l = [0,0],[0,...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
1
256
Load Testing
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send ai requests. Polycarp plans to test Fakebook under a special kind of...
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the duration of the load testing. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the number of requests from friends in the i-th minute of the load testing.
Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.
null
In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests. In the second example it is enough to make one additional request in the thir...
[{"input": "5\n1 4 3 2 5", "output": "6"}, {"input": "5\n1 2 2 2 1", "output": "1"}, {"input": "7\n10 20 40 50 70 90 30", "output": "0"}]
1,600
["greedy"]
39
[{"input": "5\r\n1 4 3 2 5\r\n", "output": "6\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "7\r\n10 20 40 50 70 90 30\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 15\r\n", "output": "0\r\n"}, {"input": "4\r\n36 54 55 9\r\n", "output": "0\r\n"}, {"input"...
false
stdio
null
true
283/B
283
B
PyPy 3
TESTS
5
278
0
97800282
INF = float('inf') n = int(input()) aaa = [0, 0] + list(map(int, input().split())) dp = [[0 for _ in range(n+1)] for i in range(2)] vis = [[0 for _ in range(n+1)] for i in range(2)] rs = [0] * (n-1) def di(d): return 0 if d == 1 else 1 def solve(x, d): if dp[di(d)][x]: return dp[di(d)][x] if vis[di(...
50
466
29,696,000
171032684
n = int(input()) t = [0, 0] t += list(map(int, input().split())) n += 1 a = [0] * n b = [0] * n n -= 1 a[1] = b[1] = -1 #print(t, a, b) def calc(s, a, b, l): global t l.reverse() j = 0 n = len(l) while True: s += t[l[j]] a[l[j]] = s j += 1 if j == n: return s += t[l[j]] b[l[j]] = s j += 1 ...
Codeforces Round 174 (Div. 1)
CF
2,013
2
256
Cow Program
Farmer John has just given the cows a program to play with! The program contains two integer variables, x and y, and performs the following operations on a sequence a1, a2, ..., an of positive integers: 1. Initially, x = 1 and y = 0. If, after any step, x ≤ 0 or x > n, the program immediately terminates. 2. The progra...
The first line contains a single integer, n (2 ≤ n ≤ 2·105). The next line contains n - 1 space separated integers, a2, a3, ..., an (1 ≤ ai ≤ 109).
Output n - 1 lines. On the i-th line, print the requested value when the program is run on the sequence i, a2, a3, ...an. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
null
In the first sample 1. For i = 1,  x becomes $$1 \rightarrow 2 \rightarrow 0$$ and y becomes 1 + 2 = 3. 2. For i = 2,  x becomes $$1 \rightarrow 3 \rightarrow - 1$$ and y becomes 2 + 4 = 6. 3. For i = 3,  x becomes $$1 \rightarrow 4 \rightarrow 3 \rightarrow 7$$ and y becomes 3 + 1 + 4 = 8.
[{"input": "4\n2 4 1", "output": "3\n6\n8"}, {"input": "3\n1 2", "output": "-1\n-1"}]
1,700
["dfs and similar", "dp", "graphs"]
50
[{"input": "4\r\n2 4 1\r\n", "output": "3\r\n6\r\n8\r\n"}, {"input": "3\r\n1 2\r\n", "output": "-1\r\n-1\r\n"}, {"input": "5\r\n2 2 1 3\r\n", "output": "3\r\n-1\r\n-1\r\n-1\r\n"}, {"input": "2\r\n1\r\n", "output": "-1\r\n"}, {"input": "8\r\n7 6 2 6 2 6 6\r\n", "output": "8\r\n8\r\n12\r\n10\r\n-1\r\n-1\r\n20\r\n"}, {"in...
false
stdio
null
true
127/A
127
A
PyPy 3-64
TESTS
1
92
512,000
136274303
import math ## B - Wasted Time def calculate_distance(v1, v2): x1, y1 = v1 x2, y2 = v2 x = abs(x2 - x1) y = abs(y2 - y1) return math.sqrt(x**2 + y**2) n_lines, n_signed_papers = [int(n) for n in input().split(" ")] coordinates = [] for n in range(n_lines): x, y = [int(n) for n in input().sp...
42
62
0
151050037
# t = int(input()) # for i in range(t): # n = int(input()) # a = sorted([int(y) for y in input().split()]) # print(a[-1]-a[0]) # t = int(input()) # for i in range(t): # a = [int(y) for y in input().split()] # if a == [1, 1]: # print(0) # elif a[0] == 1 or a[-1] == 1: # print(1) ...
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
28/B
28
B
Python 3
TESTS
1
62
0
167819672
n=int(input()) vt=[[] for i in range(n)] p=input().split(' ') d=input().split(' ') for i in range(len(p)): p[i]=int(p[i])-1 for i in range(len(d)): d[i]=int(d[i]) vt[i].append(d[i]) vt[d[i]].append(i) def r_able(x,y,fax): if x==y: return True for i in vt[x]: if i!=fax and r_able(...
33
124
0
194483465
import sys input = sys.stdin.readline n = int(input()) w = list(map(int, input().split())) qq = list(map(int, input().split())) d = [set() for i in range(n)] for i, j in enumerate(qq): if i-j > -1: d[i-j].add(i) d[i].add(i-j) if i+j < n: d[i+j].add(i) d[i].add(i+j) x = [0]*n for...
Codeforces Beta Round 28 (Codeforces format)
CF
2,010
2
256
pSort
One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where ...
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of cells in the array. The second line contains n distinct integers from 1 to n — permutation. The last line contains n integers from 1 to n — favourite numbers of the cells.
If the given state is reachable in the described game, output YES, otherwise NO.
null
null
[{"input": "5\n5 4 3 2 1\n1 1 1 1 1", "output": "YES"}, {"input": "7\n4 3 5 1 2 7 6\n4 6 6 1 6 6 1", "output": "NO"}, {"input": "7\n4 2 5 1 3 7 6\n4 6 6 1 6 6 1", "output": "YES"}]
1,600
["dfs and similar", "dsu", "graphs"]
33
[{"input": "5\r\n5 4 3 2 1\r\n1 1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n4 3 5 1 2 7 6\r\n4 6 6 1 6 6 1\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 2 5 1 3 7 6\r\n4 6 6 1 6 6 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n3 2 1 4 6 5\r\n3 6 1 6 6 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n3 5 1 4 6 2\r\n3...
false
stdio
null
true
401/B
401
B
PyPy 3
TESTS
0
140
0
78330681
x, k = map(int, input().split()) v = [0 for i in range(x+1)] v[0] = 1 v[x] += 1 for i in range(k): p = [int(i) for i in input().split()] v[p[1]]+=1 if p[0] == 1: v[p[2]]+=1 zer = 0 for i in v: if i == 0: zer+=1 print(int(zer/2)+1, zer)
47
77
0
5981653
#!/usr/bin/env python3 def read_ints(): return map(int, input().strip().split()) t, k = read_ints() all = [] for _ in range(k): avail = list(read_ints()) for x in avail[1:]: all.append(x) all.sort() res_min, res_max = 0, 0 last = 0 for num in all: d = num-last res_min += (d)//2 res_max += d-1 last = n...
Codeforces Round 235 (Div. 2)
CF
2,014
1
256
Sereja and Contests
Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds. Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot...
The first line contains two integers: x (1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and k (0 ≤ k < 4000) — the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding l...
Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.
null
In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. ...
[{"input": "3 2\n2 1\n2 2", "output": "0 0"}, {"input": "9 3\n1 2 3\n2 8\n1 4 5", "output": "2 3"}, {"input": "10 0", "output": "5 9"}]
1,200
["greedy", "implementation", "math"]
47
[{"input": "3 2\r\n2 1\r\n2 2\r\n", "output": "0 0"}, {"input": "9 3\r\n1 2 3\r\n2 8\r\n1 4 5\r\n", "output": "2 3"}, {"input": "10 0\r\n", "output": "5 9"}, {"input": "10 2\r\n1 1 2\r\n1 8 9\r\n", "output": "3 5"}, {"input": "9 3\r\n1 4 5\r\n1 1 2\r\n1 6 7\r\n", "output": "2 2"}, {"input": "7 2\r\n2 3\r\n1 5 6\r\n", "...
false
stdio
null
true
46/C
46
C
PyPy 3-64
TESTS
7
216
0
141725107
n = int(input()) s = list(str(input())) inverses = 0 for i in range(n): if s[i] != s[(i + 1) % n]: inverses += 1 print((inverses + 1) // 4)
27
92
0
218371186
def min_swaps_for_arrangement(n, arrangement): num_hamsters = arrangement.count('H') min_swaps = float('inf') window = arrangement[:num_hamsters] num_tigers_in_window = window.count('T') min_swaps = min(min_swaps, num_tigers_in_window) for i in range(1, n): if arrangement[i - 1] == 'T'...
School Personal Contest #2 (Winter Computer School 2010/11) - Codeforces Beta Round 43 (ACM-ICPC Rules)
ICPC
2,010
2
256
Hamsters and Tigers
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
null
In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
[{"input": "3\nHTH", "output": "0"}, {"input": "9\nHTHTHTHHT", "output": "2"}]
1,600
["two pointers"]
27
[{"input": "3\r\nHTH\r\n", "output": "0\r\n"}, {"input": "9\r\nHTHTHTHHT\r\n", "output": "2\r\n"}, {"input": "2\r\nTH\r\n", "output": "0\r\n"}, {"input": "4\r\nHTTH\r\n", "output": "0\r\n"}, {"input": "4\r\nHTHT\r\n", "output": "1\r\n"}, {"input": "7\r\nTTTHTTT\r\n", "output": "0\r\n"}, {"input": "8\r\nHHTHHTHH\r\n", "...
false
stdio
null
true
46/C
46
C
PyPy 3
TESTS
4
312
20,172,800
88392825
n = int(input()) s = input() H = s.count("H") mn = int(10e3) for i in range(n-H): cnt = s[i:i+H-1].count("T") mn = min(cnt,mn) print(mn)
27
92
0
218382700
n=int(input()) s=input() h=s.count('H') print (min((s+s)[i:i+h].count('T') for i in range(n)))
School Personal Contest #2 (Winter Computer School 2010/11) - Codeforces Beta Round 43 (ACM-ICPC Rules)
ICPC
2,010
2
256
Hamsters and Tigers
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
null
In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
[{"input": "3\nHTH", "output": "0"}, {"input": "9\nHTHTHTHHT", "output": "2"}]
1,600
["two pointers"]
27
[{"input": "3\r\nHTH\r\n", "output": "0\r\n"}, {"input": "9\r\nHTHTHTHHT\r\n", "output": "2\r\n"}, {"input": "2\r\nTH\r\n", "output": "0\r\n"}, {"input": "4\r\nHTTH\r\n", "output": "0\r\n"}, {"input": "4\r\nHTHT\r\n", "output": "1\r\n"}, {"input": "7\r\nTTTHTTT\r\n", "output": "0\r\n"}, {"input": "8\r\nHHTHHTHH\r\n", "...
false
stdio
null
true
61/B
61
B
Python 3
TESTS
32
62
102,400
138348237
import collections s1=input() s2=input() s3=input() l2=[] s1=s1.replace(";","") s1=s1.replace("-","") s1=s1.replace("_","") s2=s2.replace(";","") s2=s2.replace("-","") s2=s2.replace("_","") s3=s3.replace(";","") s3=s3.replace("-","") s3=s3.replace("_","") s1=s1.lower() s2=s2.lower() s3=s3.lower() l2.append(s1) l2.appe...
43
46
512,000
152405590
def no(a): return ''.join([x for x in a.lower() if (x not in ";-_")]) a=no(input()) b=no(input()) c=no(input()) n=int(input()) opt=[a+b+c,a+c+b,b+c+a,b+a+c,c+b+a,c+a+b] for i in range(0,n): k=no(input()) print("ACC" if k in opt else "WA")
Codeforces Beta Round 57 (Div. 2)
CF
2,011
2
256
Hard Work
After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer! Some days before the contest, the teacher took a very simple-looking exam and all his n students took part in the exam. The teacher...
The first three lines contain a string each. These are the initial strings. They consists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). All the initial strings have length from 1 to 100, inclusively. In the fourth line there is a single integer n (0 ≤ n ≤ 1000), the number of students. N...
For each student write in a different line. Print "WA" if his answer is wrong or "ACC" if his answer is OK.
null
null
[{"input": "Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful", "output": "ACC\nACC\nACC\nWA\nACC\nACC\nWA"}, {"input": "Shap...
1,300
["strings"]
43
[{"input": "Iran_\r\nPersian;\r\nW_o;n;d;e;r;f;u;l;\r\n7\r\nWonderfulPersianIran\r\nwonderful_PersIAN_IRAN;;_\r\nWONDERFUL___IRAN__PERSIAN__;;\r\nIra__Persiann__Wonderful\r\nWonder;;fulPersian___;I;r;a;n;\r\n__________IranPersianWonderful__________\r\nPersianIran_is_Wonderful\r\n", "output": "ACC\r\nACC\r\nACC\r\nWA\r\...
false
stdio
null
true
621/C
621
C
PyPy 3-64
TESTS
3
62
0
229615189
n,p=map(int,input().split()) tot=[] div=[] while n>0: l,r=map(int,input().split()) tot.append(r-l+1) div.append(int(r/p)-int((l-1)/p)) n-=1 sz=len(div) ans=0 for i in range(sz): vl=((tot[i]-div[i])/tot[i]) j=i+1 j%=sz vl*=((tot[j]-div[j])/tot[j]) ans+=(1-vl)*3000 print(2*ans/sz)
94
124
9,113,600
212066500
from sys import stdin ,stdout input=stdin.readline inp = lambda : map(int,input().split()) def print(*args, end='\n', sep=' ') -> None: stdout.write(sep.join(map(str, args)) + end) n , p = inp() ; arr=[] ; ans= 0 for i in range(n) : l , r = inp() arr.append( 1- (r//p - (l-1)//p) / (r-l+1)) for i ...
Codeforces Round 341 (Div. 2)
CF
2,016
2
256
Wet Shark and Flowers
There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too. Each shark will grow some number of flowers si. For i-th shark value si is random integer equiprobably chosen in range from...
The first line of the input contains two space-separated integers n and p (3 ≤ n ≤ 100 000, 2 ≤ p ≤ 109) — the number of sharks and Wet Shark's favourite prime number. It is guaranteed that p is prime. The i-th of the following n lines contains information about i-th shark — two space-separated integers li and ri (1 ≤...
Print a single real number — the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correc...
null
A prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime. Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of ...
[{"input": "3 2\n1 2\n420 421\n420420 420421", "output": "4500.0"}, {"input": "3 5\n1 4\n2 3\n11 14", "output": "0.0"}]
1,700
["combinatorics", "math", "number theory", "probabilities"]
94
[{"input": "3 2\r\n1 2\r\n420 421\r\n420420 420421\r\n", "output": "4500.0\r\n"}, {"input": "3 5\r\n1 4\r\n2 3\r\n11 14\r\n", "output": "0.0\r\n"}, {"input": "3 3\r\n3 3\r\n2 4\r\n1 1\r\n", "output": "4666.666666666667\r\n"}, {"input": "5 5\r\n5 204\r\n420 469\r\n417 480\r\n442 443\r\n44 46\r\n", "output": "3451.25\r\n...
false
stdio
import sys def read_number(path): with open(path, 'r') as f: lines = [line.strip() for line in f.readlines() if line.strip()] if len(lines) != 1: return None try: return float(lines[0]) except ValueError: return None def main(): input_path = ...
true
794/C
794
C
Python 3
TESTS
6
31
0
189399821
# modified from original but this sol is still wrong s1 = input().strip() s2 = input().strip() c = len(s1) k = '' a = True while len(k) < c: if a: k += min(s1) s1 = s1.replace(min(s1), '', 1) a = False continue k += max(s2) s2 = s2.replace(max(s2), '', 1) a = True ...
53
358
6,348,800
27083146
import sys def main(): s=sys.stdin.readline().rstrip() t=sys.stdin.readline().rstrip() result=[] iisl=0 iisr=len(s)//2+len(s)%2-1 iitl=0 iitr=len(s)//2-1 aas=list(sorted(list(s))) aat=list(sorted(list(t),reverse=True)) rl=0 rr=len(s)-1 result=['?']*len(s) ...
Tinkoff Challenge - Final Round (Codeforces Round 414, rated, Div. 1 + Div. 2)
CF
2,017
2
256
Naming Company
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor ea...
The first line of input contains a string s of length n (1 ≤ n ≤ 3·105). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially. The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This stri...
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
null
One way to play optimally in the first sample is as follows : - Initially, the company name is ???????. - Oleg replaces the first question mark with 'f'. The company name becomes f??????. - Igor replaces the second question mark with 'z'. The company name becomes fz?????. - Oleg replaces the third question mark with '...
[{"input": "tinkoff\nzscoder", "output": "fzfsirk"}, {"input": "xxxxxx\nxxxxxx", "output": "xxxxxx"}, {"input": "ioi\nimo", "output": "ioi"}]
1,800
["games", "greedy", "sortings"]
53
[{"input": "tinkoff\r\nzscoder\r\n", "output": "fzfsirk\r\n"}, {"input": "xxxxxx\r\nxxxxxx\r\n", "output": "xxxxxx\r\n"}, {"input": "ioi\r\nimo\r\n", "output": "ioi\r\n"}, {"input": "abc\r\naaa\r\n", "output": "aab\r\n"}, {"input": "reddit\r\nabcdef\r\n", "output": "dfdeed\r\n"}, {"input": "cbxz\r\naaaa\r\n", "output":...
false
stdio
null
true
794/C
794
C
Python 3
PRETESTS
6
62
204,800
27082911
a = list(input()) b = list(input()) n = len(a) a.sort() b.sort() a = a[:(len(a) + 1) // 2] b = b[len(b) // 2:] sa = 0 ea = len(a) - 1 sb = 0 eb = len(b) - 1 stb = 0 ste = n - 1 st = [""] * n for i in range(n): if i % 2 == 0: if a[sa] < b[eb]: st[stb] = a[sa] sa += 1 stb ...
53
358
7,884,800
179281758
'''from random import * test = 10 for i in range(test): new_in = open('0' * (3 - len(str(i + 1))) + str(i + 1) + ".in", 'w') new_out = open('0' * (3 - len(str(i + 1))) + str(i + 1) + ".out", 'w') n = randint(1, 10)''' a = [x for x in input()] b = [x for x in input()] p = [''] * 300003 n = len(a) a.sort() b.sort(rev...
Tinkoff Challenge - Final Round (Codeforces Round 414, rated, Div. 1 + Div. 2)
CF
2,017
2
256
Naming Company
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor ea...
The first line of input contains a string s of length n (1 ≤ n ≤ 3·105). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially. The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This stri...
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
null
One way to play optimally in the first sample is as follows : - Initially, the company name is ???????. - Oleg replaces the first question mark with 'f'. The company name becomes f??????. - Igor replaces the second question mark with 'z'. The company name becomes fz?????. - Oleg replaces the third question mark with '...
[{"input": "tinkoff\nzscoder", "output": "fzfsirk"}, {"input": "xxxxxx\nxxxxxx", "output": "xxxxxx"}, {"input": "ioi\nimo", "output": "ioi"}]
1,800
["games", "greedy", "sortings"]
53
[{"input": "tinkoff\r\nzscoder\r\n", "output": "fzfsirk\r\n"}, {"input": "xxxxxx\r\nxxxxxx\r\n", "output": "xxxxxx\r\n"}, {"input": "ioi\r\nimo\r\n", "output": "ioi\r\n"}, {"input": "abc\r\naaa\r\n", "output": "aab\r\n"}, {"input": "reddit\r\nabcdef\r\n", "output": "dfdeed\r\n"}, {"input": "cbxz\r\naaaa\r\n", "output":...
false
stdio
null
true
543/D
543
D
PyPy 3-64
TESTS
9
795
46,489,600
214689817
# Problem: D. Road Improvement # Contest: Codeforces - Codeforces Round 302 (Div. 1) # URL: https://codeforces.com/problemset/problem/543/D # Memory Limit: 256 MB # Time Limit: 2000 ms import sys import random from types import GeneratorType import bisect import io, os from bisect import * from collections import * fr...
42
451
54,988,800
214692343
# Problem: D. Road Improvement # Contest: Codeforces - Codeforces Round 302 (Div. 1) # URL: https://codeforces.com/problemset/problem/543/D # Memory Limit: 256 MB # Time Limit: 2000 ms import sys import random from types import GeneratorType import bisect import io, os from bisect import * from collections import * fr...
Codeforces Round 302 (Div. 1)
CF
2,015
2
256
Road Improvement
The country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n inclusive. All the roads are initially bad, but the government wants to improve the state of some roads. We will assume that...
The first line of the input contains a single integer n (2 ≤ n ≤ 2·105) — the number of cities in the country. Next line contains n - 1 positive integers p2, p3, p4, ..., pn (1 ≤ pi ≤ i - 1) — the description of the roads in the country. Number pi means that the country has a road connecting city pi and city i.
Print n integers a1, a2, ..., an, where ai is the sought number of ways to improve the quality of the roads modulo 1 000 000 007 (109 + 7), if the capital of the country is at city number i.
null
null
[{"input": "3\n1 1", "output": "4 3 3"}, {"input": "5\n1 2 3 4", "output": "5 8 9 8 5"}]
2,300
["dp", "trees"]
42
[{"input": "3\r\n1 1\r\n", "output": "4 3 3"}, {"input": "5\r\n1 2 3 4\r\n", "output": "5 8 9 8 5"}, {"input": "31\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "73741817 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870...
false
stdio
null
true
28/A
28
A
PyPy 3-64
TESTS
5
124
2,355,200
145107595
import copy n, m = map(int, input().split()) nails = [] for i in range(n): nails.append(list(map(int, input().split()))) lens = list(map(int, input().split())) locs = [] for i in range(1, m+1): locs.append(i) locs_c = copy.deepcopy(locs) lens_c = copy.deepcopy(lens) flag = 0 out_ = [] status = [] i = 0 whi...
51
122
614,400
218740676
from collections import defaultdict num_nails, num_segments = map(int, input().split()) nail_coordinates = [tuple(map(int, input().split())) for _ in range(num_nails)] nail_distances = [abs(a - c) + abs(b - d) for (a, b), (c, d) in zip(nail_coordinates, nail_coordinates[2:] + nail_coordinates[:2])] segment_indices = ...
Codeforces Beta Round 28 (Codeforces format)
CF
2,010
2
256
Bender Problem
Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate ...
The first line contains two positive integers n and m (4 ≤ n ≤ 500, 2 ≤ m ≤ 500, n is even) — the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The ...
If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers — i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod. If there are multiple solutions, print any of them.
null
null
[{"input": "4 2\n0 0\n0 2\n2 2\n2 0\n4 4", "output": "YES\n1 -1 2 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n3 2 3", "output": "YES\n1 -1 2 -1 3 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n2 2 3", "output": "NO"}]
1,600
["implementation"]
51
[{"input": "4 2\r\n0 0\r\n0 2\r\n2 2\r\n2 0\r\n4 4\r\n", "output": "YES\r\n1 -1 2 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n3 2 3\r\n", "output": "YES\r\n1 -1 2 -1 3 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n2 2 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0...
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, m = map(int, f.readline().split()) nails = [tuple(map(int, f.readline().split())) for _ in range(n)] rods = list(map(int, f.readline().split())...
true
28/A
28
A
Python 3
TESTS
9
216
307,200
67647357
n,m = map(int,input().split()) s = [] for i in range(n): a = map(int,input().split()) a = list(a) s.append(a) s_chet = [] for i in range(1,n-1,2): #Проход по четным гвоздям q = abs(sum(s[i])-sum(s[i-1])) + abs(sum(s[i])-sum(s[i+1])) s_chet.append(q) q1 = abs(sum(s[-1])-sum(s[-2])) + a...
51
124
1,843,200
216109513
import sys input = sys.stdin.readline def f(w, i): d = [] while i < n: d.append((ff(w[(i-1)%n], w[i]) + ff(w[i], w[(i+1)%n]), i)) i += 2 d.sort() i, j, ew, h = 0, 0, 1, [] for i in range(len(d)): if j == m: ew = 0 break while d[i][0] != q[j][...
Codeforces Beta Round 28 (Codeforces format)
CF
2,010
2
256
Bender Problem
Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate ...
The first line contains two positive integers n and m (4 ≤ n ≤ 500, 2 ≤ m ≤ 500, n is even) — the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The ...
If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers — i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod. If there are multiple solutions, print any of them.
null
null
[{"input": "4 2\n0 0\n0 2\n2 2\n2 0\n4 4", "output": "YES\n1 -1 2 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n3 2 3", "output": "YES\n1 -1 2 -1 3 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n2 2 3", "output": "NO"}]
1,600
["implementation"]
51
[{"input": "4 2\r\n0 0\r\n0 2\r\n2 2\r\n2 0\r\n4 4\r\n", "output": "YES\r\n1 -1 2 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n3 2 3\r\n", "output": "YES\r\n1 -1 2 -1 3 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n2 2 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0...
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, m = map(int, f.readline().split()) nails = [tuple(map(int, f.readline().split())) for _ in range(n)] rods = list(map(int, f.readline().split())...
true
543/D
543
D
PyPy 3-64
TESTS
9
717
46,387,200
214698660
import sys from collections import Counter import functools import math import random import sys import os from bisect import bisect_left,bisect_right from collections import Counter, defaultdict, deque from functools import lru_cache, reduce from heapq import nsmallest, nlargest, heapify, heappop, heappush from io im...
42
452
21,913,600
219474089
import sys MODULO = int(1e9) + 7 def solve(n, p, out_stream): prod = [1] * n modpow = [0] * n for i in range(n - 1, 0, -1): j = p[i] if modpow[i] == 0 and prod[i] + 1 == MODULO: modpow[j] += 1 else: prod[j] = (prod[j] * ((prod[i] if modpow[i] == 0 else 0) + 1)...
Codeforces Round 302 (Div. 1)
CF
2,015
2
256
Road Improvement
The country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n inclusive. All the roads are initially bad, but the government wants to improve the state of some roads. We will assume that...
The first line of the input contains a single integer n (2 ≤ n ≤ 2·105) — the number of cities in the country. Next line contains n - 1 positive integers p2, p3, p4, ..., pn (1 ≤ pi ≤ i - 1) — the description of the roads in the country. Number pi means that the country has a road connecting city pi and city i.
Print n integers a1, a2, ..., an, where ai is the sought number of ways to improve the quality of the roads modulo 1 000 000 007 (109 + 7), if the capital of the country is at city number i.
null
null
[{"input": "3\n1 1", "output": "4 3 3"}, {"input": "5\n1 2 3 4", "output": "5 8 9 8 5"}]
2,300
["dp", "trees"]
42
[{"input": "3\r\n1 1\r\n", "output": "4 3 3"}, {"input": "5\r\n1 2 3 4\r\n", "output": "5 8 9 8 5"}, {"input": "31\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "73741817 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870...
false
stdio
null
true
541/E
542
E
PyPy 3
TESTS
6
155
2,252,800
78242776
n, m = map(int, input().split()) g = [[] for _ in range(n)] for i in range(m): p, q = map(int, input().split()) g[p - 1].append(q - 1) g[q - 1].append(p - 1) def shortest(root): dist = [-1] * n q = [0] * n left, right = 0, 1 q[left] = root dist[root] = 0 good = True while left ...
50
2,168
10,956,800
78243037
n, m = map(int, input().split()) g = [[] for _ in range(n)] for i in range(m): p, q = map(int, input().split()) g[p - 1].append(q - 1) g[q - 1].append(p - 1) comp = [-1] * n def shortest(root): dist = [-1] * n q = [0] * n left, right = 0, 1 q[left] = root dist[root] = 0 good = True ...
VK Cup 2015 - Раунд 3
CF
2,015
3
256
Playing on Graph
Vova and Marina love offering puzzles to each other. Today Marina offered Vova to cope with the following task. Vova has a non-directed graph consisting of n vertices and m edges without loops and multiple edges. Let's define the operation of contraction two vertices a and b that are not connected by an edge. As a res...
The first line contains two integers n, m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 100 000) — the number of vertices and the number of edges in the original graph. Next m lines contain the descriptions of edges in the format ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that there is an edge between vertices ai and bi. It is guaranteed...
If it is impossible to obtain a chain from the given graph, print - 1. Otherwise, print the maximum possible number of edges in the resulting chain.
null
In the first sample test you can contract vertices 4 and 5 and obtain a chain of length 3. In the second sample test it is initially impossible to contract any pair of vertexes, so it is impossible to achieve the desired result. In the third sample test you can contract vertices 1 and 2 and obtain a chain of length 2...
[{"input": "5 4\n1 2\n2 3\n3 4\n3 5", "output": "3"}, {"input": "4 6\n1 2\n2 3\n1 3\n3 4\n2 4\n1 4", "output": "-1"}, {"input": "4 2\n1 3\n2 4", "output": "2"}]
2,600
[]
50
[{"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n3 5\r\n", "output": "3\r\n"}, {"input": "4 6\r\n1 2\r\n2 3\r\n1 3\r\n3 4\r\n2 4\r\n1 4\r\n", "output": "-1\r\n"}, {"input": "4 2\r\n1 3\r\n2 4\r\n", "output": "2\r\n"}, {"input": "1 0\r\n", "output": "0\r\n"}, {"input": "1000 0\r\n", "output": "0\r\n"}, {"input": "1000 4\r\n100 2...
false
stdio
null
true
962/E
962
E
PyPy 3
TESTS
4
124
0
94124267
import sys def kruskal(v_count: int, edges: list) -> int: edges.sort() tree = [-1]*v_count def get_root(x) -> int: if tree[x] < 0: return x tree[x] = get_root(tree[x]) return tree[x] def unite(x, y) -> bool: x, y = get_root(x), get_root(y) if x != ...
45
405
13,516,800
94132083
import sys n = int(sys.stdin.buffer.readline().decode('utf-8')) pos, type_ = [0]*n, ['']*n for i, (x, c) in enumerate(line.decode('utf-8').split() for line in sys.stdin.buffer): pos[i] = int(x) type_[i] = c r_cnt = type_.count('R') b_cnt = type_.count('B') p_cnt = n - r_cnt - b_cnt inf = 2100000000 if p_cn...
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Byteland, Berland and Disputed Cities
The cities of Byteland and Berland are located on the axis $$$Ox$$$. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line $$$Ox$$$ there are three types of cities: - the cities of Byteland, - the cities of Berland, - disputed cities. Recen...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^{5}$$$) — the number of cities. The following $$$n$$$ lines contains an integer $$$x_i$$$ and the letter $$$c_i$$$ ($$$-10^{9} \le x_i \le 10^{9}$$$) — the coordinate of the city and its type. If the city belongs to Byteland, $$$c_i$$$ equals ...
Print the minimal total length of such set of cables, that if we delete all Berland cities ($$$c_i$$$='R'), it will be possible to find a way from any remaining city to any other remaining city, moving only by cables. Similarly, if we delete all Byteland cities ($$$c_i$$$='B'), it will be possible to find a way from an...
null
In the first example, you should connect the first city with the second, the second with the third, and the third with the fourth. The total length of the cables will be $$$5 + 3 + 4 = 12$$$. In the second example there are no disputed cities, so you need to connect all the neighboring cities of Byteland and all the n...
[{"input": "4\n-5 R\n0 P\n3 P\n7 B", "output": "12"}, {"input": "5\n10 R\n14 B\n16 B\n21 R\n32 R", "output": "24"}]
2,200
["constructive algorithms", "greedy"]
45
[{"input": "4\r\n-5 R\r\n0 P\r\n3 P\r\n7 B\r\n", "output": "12\r\n"}, {"input": "5\r\n10 R\r\n14 B\r\n16 B\r\n21 R\r\n32 R\r\n", "output": "24\r\n"}, {"input": "10\r\n66 R\r\n67 R\r\n72 R\r\n73 R\r\n76 R\r\n78 B\r\n79 B\r\n83 B\r\n84 B\r\n85 P\r\n", "output": "26\r\n"}, {"input": "10\r\n61 R\r\n64 R\r\n68 R\r\n71 R\r\n...
false
stdio
null
true
522/A
522
A
PyPy 3-64
TESTS
5
31
0
193980161
l=[] c=[] for _ in range(int(input())): a,b=input().lower().replace(" ","").split("reposted") if b in l: x=l.index(b) c[x]+=1 l[x]=a else: l.append(a) c.append(2) print(max(c))
36
31
0
145937584
dic = {"polycarp":1} for i in range(int(input())): z = input().split() a = z[0].lower() b = z[-1].lower() dic[a] = dic[b]+1 xyz = list(dic.values()) print(max(xyz))
VK Cup 2015 - Qualification Round 1
CF
2,015
1
256
Reposts
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the n...
The first line of the input contains integer n (1 ≤ n ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have len...
Print a single integer — the maximum length of a repost chain.
null
null
[{"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6"}, {"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp",...
1,200
["*special", "dfs and similar", "dp", "graphs", "trees"]
36
[{"input": "5\r\ntourist reposted Polycarp\r\nPetr reposted Tourist\r\nWJMZBMR reposted Petr\r\nsdya reposted wjmzbmr\r\nvepifanov reposted sdya\r\n", "output": "6\r\n"}, {"input": "6\r\nMike reposted Polycarp\r\nMax reposted Polycarp\r\nEveryOne reposted Polycarp\r\n111 reposted Polycarp\r\nVkCup reposted Polycarp\r\n...
false
stdio
null
true
46/C
46
C
PyPy 3-64
TESTS
7
122
512,000
145802779
n = int(input()) init = list(input()) beg = init[0] end = init[n-1] i = 1 j = n-2 counts = 0 if beg == end: it = init.count(beg) while j-i > n-it: if init[i] == beg: i += 1 elif init[j] == end: j -= 1 else: tmp = init[i] init[i] = init[j] ...
27
92
0
218382997
num=int(input()) st=input() h=st.count('H') print (min((st+st)[i:i+h].count('T') for i in range(num)))
School Personal Contest #2 (Winter Computer School 2010/11) - Codeforces Beta Round 43 (ACM-ICPC Rules)
ICPC
2,010
2
256
Hamsters and Tigers
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
null
In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
[{"input": "3\nHTH", "output": "0"}, {"input": "9\nHTHTHTHHT", "output": "2"}]
1,600
["two pointers"]
27
[{"input": "3\r\nHTH\r\n", "output": "0\r\n"}, {"input": "9\r\nHTHTHTHHT\r\n", "output": "2\r\n"}, {"input": "2\r\nTH\r\n", "output": "0\r\n"}, {"input": "4\r\nHTTH\r\n", "output": "0\r\n"}, {"input": "4\r\nHTHT\r\n", "output": "1\r\n"}, {"input": "7\r\nTTTHTTT\r\n", "output": "0\r\n"}, {"input": "8\r\nHHTHHTHH\r\n", "...
false
stdio
null
true
60/E
60
E
Python 3
TESTS
5
186
307,200
91180410
import sys I = lambda: int(input()) RL = readline = lambda: sys.stdin.readline().strip('\n') RM = readmap = lambda x = int: map(x,readline().split(' ')) #E ''' solution: sum grows exponentially if the sum of array at 0th min is s and the sum of start and end is e then sum in the next minute is s + (2*s - e)...
58
780
120,320,000
222999862
def power(a, b, p): c = 1 while b: if b & 1: c = (c * a) % p a = (a * a) % p b //= 2 return c def get3(b, p): if b == 0: return 0 if b == 1: return 1 if b & 1: x = get3(b - 1, p) return (3 * x + 1) % p else: x = get3...
Codeforces Beta Round 56
CF
2,011
3
256
Mushroom Gnomes
Once upon a time in the thicket of the mushroom forest lived mushroom gnomes. They were famous among their neighbors for their magic mushrooms. Their magic nature made it possible that between every two neighboring mushrooms every minute grew another mushroom with the weight equal to the sum of weights of two neighbori...
The first line contains four integers n, x, y, p (1 ≤ n ≤ 106, 0 ≤ x, y ≤ 1018, x + y > 0, 2 ≤ p ≤ 109) which represent the number of mushrooms, the number of minutes after the first replanting, the number of minutes after the second replanting and the module. The next line contains n integers ai which represent the mu...
The answer should contain a single number which is the total weights of the mushrooms modulo p in the end after x + y minutes.
null
null
[{"input": "2 1 0 657276545\n1 2", "output": "6"}, {"input": "2 1 1 888450282\n1 2", "output": "14"}, {"input": "4 5 0 10000\n1 2 3 4", "output": "1825"}]
2,600
["math", "matrices"]
58
[{"input": "2 1 0 657276545\r\n1 2\r\n", "output": "6\r\n"}, {"input": "2 1 1 888450282\r\n1 2\r\n", "output": "14\r\n"}, {"input": "4 5 0 10000\r\n1 2 3 4\r\n", "output": "1825\r\n"}, {"input": "4 0 8 78731972\r\n1 52 76 81\r\n", "output": "1108850\r\n"}, {"input": "4 0 8 414790855\r\n1 88 97 99\r\n", "output": "15418...
false
stdio
null
true
400/B
400
B
PyPy 3-64
TESTS
4
61
2,048,000
193219056
n, m = map(int, input().split()) map_dict = dict() for i in range(n): word = input() if word.rfind('S') < word.rfind('G'): print(-1) break s = [] for j, k in enumerate(word): s = list(map(lambda x: (x[0], x[1] + 1), s)) if k == 'G': s.append((j, 0)) ...
34
46
204,800
160226508
a, b = map(int, input().split()) array = [0] * a for i in range(a): temp = input() array[i] = temp.find("S") - temp.find("G") array.sort() if array[0] > 0: if len(array) != 1: count = 1 for i in range(1, a): if array[i] != array[i-1]: count+= 1 print(count...
Codeforces Round 234 (Div. 2)
CF
2,014
1
256
Inna and New Matrix of Candies
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload". The field for the new game is a rectangle table of size n × m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game la...
The first line of the input contains two integers n and m (1 ≤ n ≤ 1000; 2 ≤ m ≤ 1000). Next n lines each contain m characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn'...
In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
null
null
[{"input": "3 4\n*G*S\nG**S\n*G*S", "output": "2"}, {"input": "1 3\nS*G", "output": "-1"}]
1,200
["brute force", "implementation", "schedules"]
34
[{"input": "3 4\r\n*G*S\r\nG**S\r\n*G*S\r\n", "output": "2\r\n"}, {"input": "1 3\r\nS*G\r\n", "output": "-1\r\n"}, {"input": "10 10\r\nG********S\r\n*G*******S\r\n**G******S\r\n***G*****S\r\n****G****S\r\n*****G***S\r\n******G**S\r\n*******G*S\r\n********GS\r\nG********S\r\n", "output": "9\r\n"}, {"input": "5 10\r\nG**...
false
stdio
null
true
523/A
523
A
Python 3
TESTS
1
31
0
189247879
str = '' col, row = [*map(int, input().split())] lst = [input() for i in range(row)] for i in range(col): str = "" for j in range(row): str += lst[-j - 1][-i - 1] * 2 print(str) print(str)
24
61
0
10274243
def mash(pole): ans = [] for i in range(len(pole)): s = pole[i] new = '' for i in s: new += (i * 2) ans.append(new) ans.append(new) return ans def change(pole, a, b): x = len(pole[0]) % 2 fir = [] sec = [] new = [] for i in range(b): ...
VK Cup 2015 - Qualification Round 2
CF
2,015
2
256
Rotate, Flip and Zoom
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice ...
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is mono...
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
null
null
[{"input": "3 2\n.*.\n.*.", "output": "....\n....\n****\n****\n....\n...."}, {"input": "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*", "outp...
1,200
["*special", "implementation"]
24
[{"input": "3 2\r\n.*.\r\n.*.\r\n", "output": "....\r\n....\r\n****\r\n****\r\n....\r\n....\r\n"}, {"input": "9 20\r\n**.......\r\n****.....\r\n******...\r\n*******..\r\n..******.\r\n....****.\r\n......***\r\n*.....***\r\n*********\r\n*********\r\n*********\r\n*********\r\n....**...\r\n...****..\r\n..******.\r\n.******...
false
stdio
null
true
28/B
28
B
Python 3
TESTS
1
92
0
167818781
import random print(random.choice(["YES","NO"]))
33
124
0
199147462
import sys; R = sys.stdin.readline S = lambda: map(int,R().split()) from collections import deque n = int(R()) a = [0]+[*S()] b = [*S()] e = [[] for _ in range(n+1)] for i,x in enumerate(b,1): if i+x<=n: e[i] += i+x,; e[i+x] += i, if 1<=i-x: e[i] += i-x,; e[i-x] += i, vv = [0]*(n+1) for i in range(1,n+1): ...
Codeforces Beta Round 28 (Codeforces format)
CF
2,010
2
256
pSort
One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where ...
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of cells in the array. The second line contains n distinct integers from 1 to n — permutation. The last line contains n integers from 1 to n — favourite numbers of the cells.
If the given state is reachable in the described game, output YES, otherwise NO.
null
null
[{"input": "5\n5 4 3 2 1\n1 1 1 1 1", "output": "YES"}, {"input": "7\n4 3 5 1 2 7 6\n4 6 6 1 6 6 1", "output": "NO"}, {"input": "7\n4 2 5 1 3 7 6\n4 6 6 1 6 6 1", "output": "YES"}]
1,600
["dfs and similar", "dsu", "graphs"]
33
[{"input": "5\r\n5 4 3 2 1\r\n1 1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n4 3 5 1 2 7 6\r\n4 6 6 1 6 6 1\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 2 5 1 3 7 6\r\n4 6 6 1 6 6 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n3 2 1 4 6 5\r\n3 6 1 6 6 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n3 5 1 4 6 2\r\n3...
false
stdio
null
true
28/A
28
A
Python 3
TESTS
9
218
307,200
67650423
n,m = map(int,input().split()) s = [] for i in range(n): a = map(int,input().split()) a = list(a) s.append(a) s_chet = [] for i in range(1,n-1,2): #Проход по четным гвоздям q = abs(sum(s[i])-sum(s[i-1])) + abs(sum(s[i])-sum(s[i+1])) s_chet.append(q) q1 = abs(sum(s[-1])-sum(s[-2])) + a...
51
154
409,600
13001422
from collections import defaultdict def main(): n, m = map(int, input().split()) tmp = list(tuple(map(int, input().split())) for _ in range(n)) nails = [abs(a - c) + abs(b - d) for (a, b), (c, d) in zip(tmp, tmp[2:] + tmp[:2])] segments = defaultdict(list) for i, s in enumerate(map(int, input().sp...
Codeforces Beta Round 28 (Codeforces format)
CF
2,010
2
256
Bender Problem
Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate ...
The first line contains two positive integers n and m (4 ≤ n ≤ 500, 2 ≤ m ≤ 500, n is even) — the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The ...
If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers — i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod. If there are multiple solutions, print any of them.
null
null
[{"input": "4 2\n0 0\n0 2\n2 2\n2 0\n4 4", "output": "YES\n1 -1 2 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n3 2 3", "output": "YES\n1 -1 2 -1 3 -1"}, {"input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n2 2 3", "output": "NO"}]
1,600
["implementation"]
51
[{"input": "4 2\r\n0 0\r\n0 2\r\n2 2\r\n2 0\r\n4 4\r\n", "output": "YES\r\n1 -1 2 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n3 2 3\r\n", "output": "YES\r\n1 -1 2 -1 3 -1 \r\n"}, {"input": "6 3\r\n0 0\r\n1 0\r\n1 1\r\n2 1\r\n2 2\r\n0 2\r\n2 2 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0...
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, m = map(int, f.readline().split()) nails = [tuple(map(int, f.readline().split())) for _ in range(n)] rods = list(map(int, f.readline().split())...
true
1212/D
977
D
PyPy 3-64
TESTS
0
61
0
227965901
def getTuple(x): count_power_of_three = sum(1 for i in range(60) if x % (3**i) == 0) return (count_power_of_three, -x) n = int(input()) a = list(map(int, input().split())) start = max(a, key=getTuple) ans = [start] a.remove(start) while len(ans) < n: next_value = ans[-1] // 3 if ans[-1] % 3 == 0 else ans...
26
46
6,144,000
225452589
from collections import defaultdict n=int(input()) a=list(map(int,input().split())) def top(mp=defaultdict(int),x=1,n=1): if n==1 and mp[x]==1 or n==0: return [x] if mp[x]==0: return -1 mp[x]-=1 k=top(mp,2*x,n-1) mp[x]+=1 if k!=-1: return k+[x] if x%3==0: mp[x...
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
794/C
794
C
Python 3
PRETESTS
6
46
0
27084734
a = sorted(input()) b = sorted(input()) l = len(a) result = "" if a[0] > b[-1]: ai = (l + 1) // 2 - 1 bi = l - l // 2 result += a[ai] ai -= 1 while len(result) < len(a): result = b[bi] + result bi += 1 if len(result) == len(a): break result = a[ai] + resu...
53
389
25,907,200
48483922
a = sorted(input()) b = sorted(input(), reverse=True) n = len(a) a = ''.join(a[:(n+1)//2]) b = ''.join(b[:n//2]) name = ['']*(len(a)+len(b)) ia = ib = ic = 0 ja = len(a)-1 jb = len(b)-1 jc = len(name)-1 turn = 1 while ic <= jc: if turn == 1: if ib > jb: name[ic] = a[ia]; ic+= 1 elif a[ia] < b[ib]: ...
Tinkoff Challenge - Final Round (Codeforces Round 414, rated, Div. 1 + Div. 2)
CF
2,017
2
256
Naming Company
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor ea...
The first line of input contains a string s of length n (1 ≤ n ≤ 3·105). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially. The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This stri...
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
null
One way to play optimally in the first sample is as follows : - Initially, the company name is ???????. - Oleg replaces the first question mark with 'f'. The company name becomes f??????. - Igor replaces the second question mark with 'z'. The company name becomes fz?????. - Oleg replaces the third question mark with '...
[{"input": "tinkoff\nzscoder", "output": "fzfsirk"}, {"input": "xxxxxx\nxxxxxx", "output": "xxxxxx"}, {"input": "ioi\nimo", "output": "ioi"}]
1,800
["games", "greedy", "sortings"]
53
[{"input": "tinkoff\r\nzscoder\r\n", "output": "fzfsirk\r\n"}, {"input": "xxxxxx\r\nxxxxxx\r\n", "output": "xxxxxx\r\n"}, {"input": "ioi\r\nimo\r\n", "output": "ioi\r\n"}, {"input": "abc\r\naaa\r\n", "output": "aab\r\n"}, {"input": "reddit\r\nabcdef\r\n", "output": "dfdeed\r\n"}, {"input": "cbxz\r\naaaa\r\n", "output":...
false
stdio
null
true
794/C
794
C
Python 3
TESTS
6
46
204,800
27113154
a=list(input()) b=list(input()) y=len(a) l=int(y//2)+y%2 r=y-l+y%2 a.sort() b.sort() al=a[:l] br=b[r:] t=["?"]*y wq=0 wp=y-1 i=0 while "?" in t: if i%2==0: if t.count("?")==1: t[t.index("?")]=al[0] elif min(al)>=max(br): t[wp]=max(al) al.remove(max(al)) ...
53
420
5,222,400
27156642
str1 = list(input()) str2 = list(input()) str1.sort() str2.sort(reverse=True) n = len(str1) str = ['?'] * n i, j, ni, nj = 0, 0, (n + 1) // 2 - 1, n // 2 - 1 front, rear = 0, n - 1 for cur in range(n): if cur & 1 == 0: if (str1[i] < str2[j]): str[front] = str1[i] i += 1 f...
Tinkoff Challenge - Final Round (Codeforces Round 414, rated, Div. 1 + Div. 2)
CF
2,017
2
256
Naming Company
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor ea...
The first line of input contains a string s of length n (1 ≤ n ≤ 3·105). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially. The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This stri...
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
null
One way to play optimally in the first sample is as follows : - Initially, the company name is ???????. - Oleg replaces the first question mark with 'f'. The company name becomes f??????. - Igor replaces the second question mark with 'z'. The company name becomes fz?????. - Oleg replaces the third question mark with '...
[{"input": "tinkoff\nzscoder", "output": "fzfsirk"}, {"input": "xxxxxx\nxxxxxx", "output": "xxxxxx"}, {"input": "ioi\nimo", "output": "ioi"}]
1,800
["games", "greedy", "sortings"]
53
[{"input": "tinkoff\r\nzscoder\r\n", "output": "fzfsirk\r\n"}, {"input": "xxxxxx\r\nxxxxxx\r\n", "output": "xxxxxx\r\n"}, {"input": "ioi\r\nimo\r\n", "output": "ioi\r\n"}, {"input": "abc\r\naaa\r\n", "output": "aab\r\n"}, {"input": "reddit\r\nabcdef\r\n", "output": "dfdeed\r\n"}, {"input": "cbxz\r\naaaa\r\n", "output":...
false
stdio
null
true
28/B
28
B
Python 3
TESTS
2
124
6,963,200
115965535
size = int(input()) if size < 1 or size > 100: exit() permutations_dict = {} array = list(map(int, input().split(" "))) ready = list(map(int, input().split(" "))) permutations = ready.copy() for i in range(len(permutations)): permutations[i] = [permutations[i]] for j in range(len(array)): ...
33
124
0
210278725
import sys input = lambda: sys.stdin.readline().rstrip() from collections import defaultdict,Counter N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) D = [i for i in range(1,N+1)] P = [[] for _ in range(N)] for i in range(N): b = B[i] if i-b>=0: P[i].append(i-b...
Codeforces Beta Round 28 (Codeforces format)
CF
2,010
2
256
pSort
One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where ...
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of cells in the array. The second line contains n distinct integers from 1 to n — permutation. The last line contains n integers from 1 to n — favourite numbers of the cells.
If the given state is reachable in the described game, output YES, otherwise NO.
null
null
[{"input": "5\n5 4 3 2 1\n1 1 1 1 1", "output": "YES"}, {"input": "7\n4 3 5 1 2 7 6\n4 6 6 1 6 6 1", "output": "NO"}, {"input": "7\n4 2 5 1 3 7 6\n4 6 6 1 6 6 1", "output": "YES"}]
1,600
["dfs and similar", "dsu", "graphs"]
33
[{"input": "5\r\n5 4 3 2 1\r\n1 1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n4 3 5 1 2 7 6\r\n4 6 6 1 6 6 1\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 2 5 1 3 7 6\r\n4 6 6 1 6 6 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n3 2 1 4 6 5\r\n3 6 1 6 6 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n3 5 1 4 6 2\r\n3...
false
stdio
null
true
279/C
279
C
PyPy 3-64
TESTS
20
1,746
16,896,000
202446013
import sys input = sys.stdin.readline from bisect import bisect n, m = map(int, input().split()) w = [0] + list(map(int, input().split())) d = [0] a = 1 for i in range(1, n): if a == 1: if w[i] > w[i+1]: d.append(i) a = 0 else: if w[i] < w[i+1]: d.append(i) ...
35
748
15,769,600
202449796
import sys input = sys.stdin.readline n, m = map(int, input().split()) w = list(map(int, input().split())) a = [i for i in range(n)] b = [i for i in range(n)] for i in range(1, n): if w[i] >= w[i-1]: a[i] = a[i-1] if w[i] <= w[i-1]: b[i] = b[i-1] for i in range(m): x, y = map(lambda z:int(z...
Codeforces Round 171 (Div. 2)
CF
2,013
2
256
Ladder
You've got an array, consisting of n integers a1, a2, ..., an. Also, you've got m queries, the i-th query is described by two integers li, ri. Numbers li, ri define a subsegment of the original array, that is, the sequence of numbers ali, ali + 1, ali + 2, ..., ari. For each query you should check whether the correspon...
The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of array elements and the number of queries. The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where number ai stands for the i-th array element. The following m lines contain the description of the queries. The ...
Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.
null
null
[{"input": "8 6\n1 2 1 3 3 5 2 1\n1 3\n2 3\n2 4\n8 8\n1 4\n5 8", "output": "Yes\nYes\nNo\nYes\nNo\nYes"}]
1,700
["dp", "implementation", "two pointers"]
35
[{"input": "8 6\r\n1 2 1 3 3 5 2 1\r\n1 3\r\n2 3\r\n2 4\r\n8 8\r\n1 4\r\n5 8\r\n", "output": "Yes\r\nYes\r\nNo\r\nYes\r\nNo\r\nYes\r\n"}, {"input": "1 1\r\n6\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "2 5\r\n1 1\r\n1 2\r\n2 2\r\n2 2\r\n1 2\r\n1 2\r\n", "output": "Yes\r\nYes\r\nYes\r\nYes\r\nYes\r\n"}, {"input": "10 ...
false
stdio
null
true
33/A
33
A
Python 3
TESTS
9
124
0
12088804
n, m, k = map(int, input().split()) max_teeth = [1000 for i in range(m)] for i in range(n): r, c = map(int, input().split()) r -= 1 max_teeth[r] = min(max_teeth[r], c) print(min(k, sum(max_teeth)))
31
92
0
196495425
n, m, k = map(int, input().split()) rows_of_teeth = {} for i in range(n): r, t = map(int, input().split()) if r not in rows_of_teeth: rows_of_teeth[r] = [t] else: rows_of_teeth[r].append(t) j = sum(min(rows_of_teeth[i]) for i in rows_of_teeth) print(min(j, k))
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
What is for dinner?
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c...
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
null
null
[{"input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11"}, {"input": "2 2 13\n1 13\n2 12", "output": "13"}]
1,200
["greedy", "implementation"]
31
[{"input": "4 3 18\r\n2 3\r\n1 2\r\n3 6\r\n2 3\r\n", "output": "11\r\n"}, {"input": "2 2 13\r\n1 13\r\n2 12\r\n", "output": "13\r\n"}, {"input": "5 4 8\r\n4 6\r\n4 5\r\n1 3\r\n2 0\r\n3 3\r\n", "output": "8\r\n"}, {"input": "1 1 0\r\n1 3\r\n", "output": "0\r\n"}, {"input": "7 1 30\r\n1 8\r\n1 15\r\n1 5\r\n1 17\r\n1 9\r\...
false
stdio
null
true
53/D
53
D
PyPy 3
TESTS
4
154
0
137875401
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) res = [] for l in range(n): if a[l] != b[l]: for j in range(l + 1, n): if a[j] == b[l]: ind = j break while ind != l: b[ind], b[ind - 1] = b[ind - 1], b[...
30
124
512,000
156825993
def vasya_and_physcult(count, a_str, b_str): size = int(count) a = list(map(int, a_str.split())) b = list(map(int, b_str.split())) changes_count = 0 result = "" for i in range(size): current_index = i for j in range(i,size): if b[j] == a[i]: current_ind...
Codeforces Beta Round 49 (Div. 2)
CF
2,011
2
256
Physical Education
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line...
The first line contains an integer n (1 ≤ n ≤ 300) which is the number of students. The second line contains n space-separated integers ai (1 ≤ ai ≤ 109) which represent the height of the student occupying the i-th place must possess. The third line contains n space-separated integers bi (1 ≤ bi ≤ 109) which represent ...
In the first line print an integer k (0 ≤ k ≤ 106) which is the number of moves. It is not required to minimize k but it must not exceed 106. Then print k lines each containing two space-separated integers. Line pi, pi + 1 (1 ≤ pi ≤ n - 1) means that Vasya should swap students occupying places pi and pi + 1.
null
null
[{"input": "4\n1 2 3 2\n3 2 1 2", "output": "4\n2 3\n1 2\n3 4\n2 3"}, {"input": "2\n1 100500\n1 100500", "output": "0"}]
1,500
["sortings"]
30
[{"input": "4\r\n1 2 3 2\r\n3 2 1 2\r\n", "output": "4\r\n2 3\r\n1 2\r\n3 4\r\n2 3\r\n"}, {"input": "2\r\n1 100500\r\n1 100500\r\n", "output": "0\r\n"}, {"input": "3\r\n652586118 652586118 652586118\r\n652586118 652586118 652586118\r\n", "output": "3\r\n2 3\r\n1 2\r\n2 3\r\n"}, {"input": "4\r\n681106577 681106577 67507...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path, 'r') as f_input: n = int(f_input.readline().strip()) a = list(map(int, f_input.readline().split())) initial_b = list(map(int, f_input.readline().split())) with open(submission_path, 'r') as f_submi...
true
12/C
12
C
Python 3
TESTS
4
31
0
143960629
x, y = map(int, input().split()) a=sorted(map(int, input().split())) b=[] d=[] q1=0 q2=0 for _ in range(y): b.append(input()) c=list(set(b)) for i in range(len(c)): d.append(b.count(c[i])) d=d[::-1] for i in range(len(d)): q1+=d[i]*a[i] print(q1) a=a[::-1] for i in range(len(d)): q2+=d[i]*a[i] print(q2)
25
46
0
150931843
n,m = map(int,input().split(" ")) dict = {} pricetags = list(map(int,input().split(" "))) names = [] for i in range(m): names.append(input()) pricetags.sort() for i in names: if(i in dict): dict[i] += 1 else: dict[i] = 1 count = [] for i in dict: count.append(dict[i]) count.sort() maxpri...
Codeforces Beta Round 12 (Div 2 Only)
ICPC
2,010
1
256
Fruits
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Asho...
The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exc...
Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
null
null
[{"input": "5 3\n4 2 1 10 5\napple\norange\nmango", "output": "7 19"}, {"input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange", "output": "11 30"}]
1,100
["greedy", "implementation", "sortings"]
25
[{"input": "5 3\r\n4 2 1 10 5\r\napple\r\norange\r\nmango\r\n", "output": "7 19\r\n"}, {"input": "6 5\r\n3 5 1 6 8 1\r\npeach\r\ngrapefruit\r\nbanana\r\norange\r\norange\r\n", "output": "11 30\r\n"}, {"input": "2 2\r\n91 82\r\neiiofpfpmemlakcystpun\r\nmcnzeiiofpfpmemlakcystpunfl\r\n", "output": "173 173\r\n"}, {"input"...
false
stdio
null
true
12/C
12
C
Python 3
TESTS
1
31
0
174601758
n,m=map(int,input().split()) List=list(map(int,input().split()));List.sort() list_0=List.copy() List.reverse() list_1=List.copy() want=[input()for i in range(m)] kind=list(set(want)) mmin=0;mmax=0 l=len(kind) for i in range(l): mmin+=list_0[i]*want.count(kind[i]) mmax+=list_1[i]*want.count(kind[i]) print(mmin,m...
25
46
0
161631413
n, m = map(int, input().split()) i = 0 j = 0 k = 0 min_res = 0 max_res = 0 arr = [] arr.append(0) x = list(map(int,input().strip().split()))[:n] for i in range (0, n) : arr.append(x[i]) arr.sort() arr.append(0) s = [] s.append("") for i in range (0, m) : s.append(input()) s.sort() s.append("") temp = [] for i in r...
Codeforces Beta Round 12 (Div 2 Only)
ICPC
2,010
1
256
Fruits
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Asho...
The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exc...
Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
null
null
[{"input": "5 3\n4 2 1 10 5\napple\norange\nmango", "output": "7 19"}, {"input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange", "output": "11 30"}]
1,100
["greedy", "implementation", "sortings"]
25
[{"input": "5 3\r\n4 2 1 10 5\r\napple\r\norange\r\nmango\r\n", "output": "7 19\r\n"}, {"input": "6 5\r\n3 5 1 6 8 1\r\npeach\r\ngrapefruit\r\nbanana\r\norange\r\norange\r\n", "output": "11 30\r\n"}, {"input": "2 2\r\n91 82\r\neiiofpfpmemlakcystpun\r\nmcnzeiiofpfpmemlakcystpunfl\r\n", "output": "173 173\r\n"}, {"input"...
false
stdio
null
true
789/A
789
A
Python 3
TESTS
27
171
10,547,200
26257893
import heapq from collections import deque import sys # # f = open('input.txt') # sys.stdin = f _, k = map(int, input().split()) a = 0 b = 0 for i in map(int, input().split()): c = (i + k - 1) // k a += c b = max(b, c) print(max((a+1)//2,b))
31
77
5,734,400
183822605
n,k=map(int,input().split()) d=0 t = sum(((i-1)//k + 1) for i in map(int,input().split())) print((t-1)//2 + 1)
Codeforces Round 407 (Div. 2)
CF
2,017
1
256
Anastasia and pebbles
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most k pebbles in each pocket at the same time....
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
null
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she co...
[{"input": "3 2\n2 3 4", "output": "3"}, {"input": "5 4\n3 1 8 9 7", "output": "5"}]
1,100
["implementation", "math"]
31
[{"input": "3 2\r\n2 3 4\r\n", "output": "3\r\n"}, {"input": "5 4\r\n3 1 8 9 7\r\n", "output": "5\r\n"}, {"input": "1 22\r\n1\r\n", "output": "1\r\n"}, {"input": "3 57\r\n78 165 54\r\n", "output": "3\r\n"}, {"input": "5 72\r\n74 10 146 189 184\r\n", "output": "6\r\n"}, {"input": "9 13\r\n132 87 200 62 168 51 185 192 11...
false
stdio
null
true
103/A
103
A
PyPy 3-64
TESTS
4
122
0
132272294
n=int(input()) s=0 l=list(map(int,input().split())) penalty=(sum(l)-l[0])-(n-1) clicks=sum(l)+penalty print(clicks)
25
92
0
143368752
n = int(input()) s = input().split() a = [int(i) for i in s] res = 0 for i in range(n): res += a[i] + (i*(a[i]-1)) print(res)
Codeforces Beta Round 80 (Div. 1 Only)
CF
2,011
2
256
Testing Pants for Sadness
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ...
The first line contains a positive integer n (1 ≤ n ≤ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 ≤ ai ≤ 109), the number of answer variants to question i.
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
null
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the thir...
[{"input": "2\n1 1", "output": "2"}, {"input": "2\n2 2", "output": "5"}, {"input": "1\n10", "output": "10"}]
1,100
["greedy", "implementation", "math"]
25
[{"input": "2\r\n1 1\r\n", "output": "2"}, {"input": "2\r\n2 2\r\n", "output": "5"}, {"input": "1\r\n10\r\n", "output": "10"}, {"input": "3\r\n2 4 1\r\n", "output": "10"}, {"input": "4\r\n5 5 3 1\r\n", "output": "22"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "2999999999"}, {"input": "10\r\n5 7 8 1 10 3 6 ...
false
stdio
null
true
400/B
400
B
Python 3
TESTS
17
46
4,812,800
133176194
def max_moves(n,m): max_moves = -1 out = [] for i in range(n): matrix = input() if matrix[-1] == 'G': return -1 else: g = matrix.find('G') s = matrix.find('S') if g - s not in out: out.append(g - s) return len(out) ...
34
46
204,800
162682808
from sys import stdin def main(): count = 0 bandera = 0 l = [] [n,m] = [int (x) for x in stdin.readline().split()] for cont in range(n): line = stdin.readline() g = line.index("G") s = line.index("S") if s<g: print(-1) bandera = 1 ...
Codeforces Round 234 (Div. 2)
CF
2,014
1
256
Inna and New Matrix of Candies
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload". The field for the new game is a rectangle table of size n × m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game la...
The first line of the input contains two integers n and m (1 ≤ n ≤ 1000; 2 ≤ m ≤ 1000). Next n lines each contain m characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn'...
In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
null
null
[{"input": "3 4\n*G*S\nG**S\n*G*S", "output": "2"}, {"input": "1 3\nS*G", "output": "-1"}]
1,200
["brute force", "implementation", "schedules"]
34
[{"input": "3 4\r\n*G*S\r\nG**S\r\n*G*S\r\n", "output": "2\r\n"}, {"input": "1 3\r\nS*G\r\n", "output": "-1\r\n"}, {"input": "10 10\r\nG********S\r\n*G*******S\r\n**G******S\r\n***G*****S\r\n****G****S\r\n*****G***S\r\n******G**S\r\n*******G*S\r\n********GS\r\nG********S\r\n", "output": "9\r\n"}, {"input": "5 10\r\nG**...
false
stdio
null
true
400/B
400
B
Python 3
TESTS
4
46
0
121826916
n, m = map(int, input().split()) end = m - 1 MAX = float('inf') arr = [] for i in range(n): inp = input() # last G, S if they exists last_g = inp.rfind('G') if last_g == -1: last_g = MAX last_s = inp.rfind('S') if last_s == -1: last_s = MAX if last_s != MAX and last_g != MAX ...
34
46
204,800
168008818
n,m=list(map(int,input().split()));set1=set() for i in range(n): x=input();candy=x.index("S");dwarf=x.index("G") if dwarf>candy: print(-1) break else: set1.add(candy-dwarf) else:print(len(set1))
Codeforces Round 234 (Div. 2)
CF
2,014
1
256
Inna and New Matrix of Candies
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload". The field for the new game is a rectangle table of size n × m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game la...
The first line of the input contains two integers n and m (1 ≤ n ≤ 1000; 2 ≤ m ≤ 1000). Next n lines each contain m characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn'...
In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
null
null
[{"input": "3 4\n*G*S\nG**S\n*G*S", "output": "2"}, {"input": "1 3\nS*G", "output": "-1"}]
1,200
["brute force", "implementation", "schedules"]
34
[{"input": "3 4\r\n*G*S\r\nG**S\r\n*G*S\r\n", "output": "2\r\n"}, {"input": "1 3\r\nS*G\r\n", "output": "-1\r\n"}, {"input": "10 10\r\nG********S\r\n*G*******S\r\n**G******S\r\n***G*****S\r\n****G****S\r\n*****G***S\r\n******G**S\r\n*******G*S\r\n********GS\r\nG********S\r\n", "output": "9\r\n"}, {"input": "5 10\r\nG**...
false
stdio
null
true
38/E
38
E
PyPy 3-64
TESTS
39
684
77,209,600
175497645
n = int(input()) vp = [] for i in range(n): x, c = map(int, input().split()) vp.append([x,c]) vp.sort(key = lambda x:x[0]) dp = [[0] * 3005 for _ in range(3005)] dp[1][1] = vp[0][1] presum = [0] * 3005 for i in range(1, n + 1): presum[i] = presum[i - 1] + vp[i - 1][0] mn = [0x3f3f3f3f] * 3005 mn[1] = vp[...
50
218
3,276,800
174556350
import sys input = sys.stdin.readline from operator import itemgetter n=int(input()) M=[tuple(map(int,input().split())) for i in range(n)] M.sort(key=itemgetter(0)) DP=[1<<60]*n DP[0]=M[0][1] for i in range(1,n): x,c=M[i] MIN=1<<60 for j in range(i): MIN=min(MIN,DP[j]) DP[j]+=abs(x-M...
School Personal Contest #1 (Winter Computer School 2010/11) - Codeforces Beta Round 38 (ACM-ICPC Rules)
ICPC
2,010
2
256
Let's Go Rolling!
On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can stick pins in some of them and the cost of sticking in the marble num...
The first input line contains an integer n (1 ≤ n ≤ 3000) which is the number of marbles. The next n lines contain the descriptions of the marbles in pairs of integers xi, ci ( - 109 ≤ xi, ci ≤ 109). The numbers are space-separated. Each description is given on a separate line. No two marbles have identical initial pos...
Output the single number — the least fine you will have to pay.
null
null
[{"input": "3\n2 3\n3 4\n1 2", "output": "5"}, {"input": "4\n1 7\n3 1\n5 10\n6 1", "output": "11"}]
1,800
["dp", "sortings"]
50
[{"input": "3\r\n2 3\r\n3 4\r\n1 2\r\n", "output": "5\r\n"}, {"input": "4\r\n1 7\r\n3 1\r\n5 10\r\n6 1\r\n", "output": "11\r\n"}, {"input": "1\r\n-454809824 14\r\n", "output": "14\r\n"}, {"input": "5\r\n-635157449 322\r\n-635157444 528\r\n-635157441 576\r\n-635157437 406\r\n-635157436 396\r\n", "output": "360\r\n"}, {"...
false
stdio
null
true
400/B
400
B
Python 3
TESTS
4
31
0
228256689
def find_longest_ascending_sequence(sorted_list): current_sequence = [sorted_list[0]] longest_sequence = [] for i in range(1, len(sorted_list)): if sorted_list[i] >= sorted_list[i - 1]: current_sequence.append(sorted_list[i]) else: # If the current element is not gre...
34
46
204,800
190314380
x, y = input().split() x = int(x) y = int(y) ans = 1 uni = [] for i in range(x): s = input() d = s.find('G') + 1 c = s.find('S') + 1 # print(d, c) if c - d >= 0: if c-d not in uni: uni.append(c-d) else: ans = 0 break if ans: print(len(uni)) else: ...
Codeforces Round 234 (Div. 2)
CF
2,014
1
256
Inna and New Matrix of Candies
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload". The field for the new game is a rectangle table of size n × m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game la...
The first line of the input contains two integers n and m (1 ≤ n ≤ 1000; 2 ≤ m ≤ 1000). Next n lines each contain m characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn'...
In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
null
null
[{"input": "3 4\n*G*S\nG**S\n*G*S", "output": "2"}, {"input": "1 3\nS*G", "output": "-1"}]
1,200
["brute force", "implementation", "schedules"]
34
[{"input": "3 4\r\n*G*S\r\nG**S\r\n*G*S\r\n", "output": "2\r\n"}, {"input": "1 3\r\nS*G\r\n", "output": "-1\r\n"}, {"input": "10 10\r\nG********S\r\n*G*******S\r\n**G******S\r\n***G*****S\r\n****G****S\r\n*****G***S\r\n******G**S\r\n*******G*S\r\n********GS\r\nG********S\r\n", "output": "9\r\n"}, {"input": "5 10\r\nG**...
false
stdio
null
true
789/A
789
A
PyPy 3-64
TESTS
5
77
13,004,800
215380126
from math import ceil n, k = map(int, input().split()) w = list(map(int, input().split())) cnt = 0 for i in range(n): cnt += 0.5 if w[i] > k: cnt += 0.5*(w[i] // k) print(ceil(cnt))
31
77
13,004,800
209110707
import math def solve(): n,k=list(map(int,input().split(" "))) lst=list(map(int,input().split(" "))) s=0 for i in lst: s+=math.ceil(i/k) print(math.ceil(s/2)) solve();
Codeforces Round 407 (Div. 2)
CF
2,017
1
256
Anastasia and pebbles
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most k pebbles in each pocket at the same time....
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
null
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she co...
[{"input": "3 2\n2 3 4", "output": "3"}, {"input": "5 4\n3 1 8 9 7", "output": "5"}]
1,100
["implementation", "math"]
31
[{"input": "3 2\r\n2 3 4\r\n", "output": "3\r\n"}, {"input": "5 4\r\n3 1 8 9 7\r\n", "output": "5\r\n"}, {"input": "1 22\r\n1\r\n", "output": "1\r\n"}, {"input": "3 57\r\n78 165 54\r\n", "output": "3\r\n"}, {"input": "5 72\r\n74 10 146 189 184\r\n", "output": "6\r\n"}, {"input": "9 13\r\n132 87 200 62 168 51 185 192 11...
false
stdio
null
true
393/B
393
B
Python 3
TESTS
36
217
716,800
70211428
n = int(input()) array = [0]*n for i in range(n): arr = input().split() arr = list(map(lambda x: int(x) if x.isdigit() else 0, arr)) array[i] = arr for i in range(n): for j in range(n): if(i == j): print(array[i][j],end=' ') else: print((array[i][j]+array[j][i])/2...
40
140
1,945,600
50765911
if __name__ == '__main__': n = int(input()) w = [] for i in range(n): w.append(list(map(int, input().split()))) a=[] b=[] for i in range(n): a.append([0.0]*n) b.append([0.0]*n) for i in range(n): for j in range(i, n): a[i][j] = (w[i][j] + w[j][i]) ...
Codeforces Round 230 (Div. 2)
CF
2,014
1
256
Three matrices
Chubby Yang is studying linear equations right now. He came up with a nice problem. In the problem you are given an n × n matrix W, consisting of integers, and you should find two n × n matrices A and B, all the following conditions must hold: - Aij = Aji, for all i, j (1 ≤ i, j ≤ n); - Bij =  - Bji, for all i, j (1 ≤...
The first line contains an integer n (1 ≤ n ≤ 170). Each of the following n lines contains n integers. The j-th integer in the i-th line is Wij (0 ≤ |Wij| < 1717).
The first n lines must contain matrix A. The next n lines must contain matrix B. Print the matrices in the format equal to format of matrix W in input. It is guaranteed that the answer exists. If there are multiple answers, you are allowed to print any of them. The answer will be considered correct if the absolute or ...
null
null
[{"input": "2\n1 4\n3 2", "output": "1.00000000 3.50000000\n3.50000000 2.00000000\n0.00000000 0.50000000\n-0.50000000 0.00000000"}, {"input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "1.00000000 3.00000000 5.00000000\n3.00000000 5.00000000 7.00000000\n5.00000000 7.00000000 9.00000000\n0.00000000 -1.00000000 -2.00000000\n1.0...
null
[]
40
[{"input": "2\r\n1 4\r\n3 2\r\n", "output": "1.00000000 3.50000000\r\n3.50000000 2.00000000\r\n0.00000000 0.50000000\r\n-0.50000000 0.00000000\r\n"}, {"input": "3\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n", "output": "1.00000000 3.00000000 5.00000000\r\n3.00000000 5.00000000 7.00000000\r\n5.00000000 7.00000000 9.00000000\r\n0.000...
false
stdio
import sys def is_close(a, b): abs_tol = 1e-4 rel_tol = 1e-4 diff = abs(a - b) if diff <= abs_tol: return True max_val = max(abs(a), abs(b)) return diff <= rel_tol * max_val def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.read().spl...
true
216/E
216
E
Python 3
TESTS
2
124
0
121438112
Line1 = list(map(int,input().split())) List = list(map(int,input().split())) def MartianLuck2(k,b,n,digit_list): reminder = b % (k-1) LuckyNumbersCounter = 0 ActualNumber = 0 Count = 0 while Count < n : for digit_index in range(Count,n): ActualNumber = (ActualNumber + digit_l...
41
466
34,508,800
125885363
from sys import stdin inp = stdin.readline k, b, n = map(int, inp().split()) s = [int(i) for i in inp().split()] a = b % (k-1) sums = {0: 1} def zero(): i, count2 = 0, 0 s.append(1) while i < n: if s[i] == 0: x = 0 while s[i] == 0: x += 1 i...
Codeforces Round 133 (Div. 2)
CF
2,012
2
256
Martian Luck
You know that the Martians use a number system with base k. Digit b (0 ≤ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology). A digital root d(x) of number x is a number that consists of a single digit, resulting after cascading summing of...
The first line contains three integers k, b and n (2 ≤ k ≤ 109, 0 ≤ b < k, 1 ≤ n ≤ 105). The second line contains string s as a sequence of n integers, representing digits in the k-base notation: the i-th integer equals ai (0 ≤ ai < k) — the i-th digit of string s. The numbers in the lines are space-separated.
Print a single integer — the number of substrings that are lucky numbers. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
null
In the first sample the following substrings have the sought digital root: s[1... 2] = "3 2", s[1... 3] = "3 2 0", s[3... 4] = "0 5", s[4... 4] = "5" and s[2... 6] = "2 0 5 6 1".
[{"input": "10 5 6\n3 2 0 5 6 1", "output": "5"}, {"input": "7 6 4\n3 5 0 4", "output": "1"}, {"input": "257 0 3\n0 0 256", "output": "3"}]
2,000
["math", "number theory"]
41
[{"input": "10 5 6\r\n3 2 0 5 6 1\r\n", "output": "5"}, {"input": "7 6 4\r\n3 5 0 4\r\n", "output": "1"}, {"input": "257 0 3\r\n0 0 256\r\n", "output": "3"}, {"input": "2 1 1\r\n0\r\n", "output": "0"}, {"input": "2 0 20\r\n1 1 1 0 1 1 1 1 0 0 0 0 1 0 0 0 0 1 0 1\r\n", "output": "22"}, {"input": "100 29 33\r\n28 89 23 1...
false
stdio
null
true
115/B
115
B
Python 3
TESTS
0
31
0
220400162
n, m = map(int, input().split()) garden = [input() for _ in range(n)] moves = 0 for i in range(n - 1, -1, -1): if i % 2 == 0: for j in range(m): if garden[i][j] == 'W': moves += 1 if j < m - 1: moves += 1 else: for j in range(m - ...
124
77
3,276,800
216357199
rows, cols = map(int, input().split()) total_moves = 0 current_row, current_col = 0, 0 for i in range(rows): row_data = input() direction = 1 - i % 2 * 2 col = (i % 2) * (cols - 1) while col >= 0 and col < cols: if row_data[col] == 'G': col += direction else: ...
Codeforces Beta Round 87 (Div. 1 Only)
CF
2,011
2
256
Lawnmower
You have a garden consisting entirely of grass and weeds. Your garden is described by an n × m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either gras...
The first line contains two integers n and m (1 ≤ n, m ≤ 150) — the number of rows and columns respectively. Then follow n lines containing m characters each — the content of the grid. "G" means that this cell contains grass. "W" means that this cell contains weeds. It is guaranteed that the top-left corner of the gri...
Print a single number — the minimum number of moves required to mow all the weeds.
null
For the first example, this is the picture of the initial state of the grid: A possible solution is by mowing the weeds as illustrated below:
[{"input": "4 5\nGWGGW\nGGWGG\nGWGGG\nWGGGG", "output": "11"}, {"input": "3 3\nGWW\nWWW\nWWG", "output": "7"}, {"input": "1 1\nG", "output": "0"}]
1,500
["greedy", "sortings"]
124
[{"input": "4 5\r\nGWGGW\r\nGGWGG\r\nGWGGG\r\nWGGGG\r\n", "output": "11\r\n"}, {"input": "3 3\r\nGWW\r\nWWW\r\nWWG\r\n", "output": "7\r\n"}, {"input": "1 1\r\nG\r\n", "output": "0\r\n"}, {"input": "4 3\r\nGWW\r\nWWW\r\nWWW\r\nWWG\r\n", "output": "11\r\n"}, {"input": "6 5\r\nGWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\nWWWWW\r\n...
false
stdio
null
true
461/B
461
B
Python 3
TESTS
6
62
0
7599108
def getlist(): return list(map(int, input().split())) n = int(input()) par = getlist() g = [[] for i in range(n)] for i in range(n - 1): g[par[i]].append(i + 1) col = getlist() dp = [[0, 0] for i in range(n)] used = [0] * n def dfs(v): dp[v][0] = 1 dp[v][1] = 0 used[v] = 1 for i in g[v]: ...
23
265
12,595,200
173824533
MOD = 1000000007 n = int(input()) p = [int(x) for x in input().split()] x = [int(x) for x in input().split()] children = [[] for x in range(n)] for i in range(1,n): children[p[i-1]].append(i) count = [(0,0) for i in range(n)] for i in reversed(range(n)): prod = 1 for ch in children[i]: prod *...
Codeforces Round 263 (Div. 1)
CF
2,014
2
256
Appleman and Tree
Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it will split into (k + 1) parts. Note, that each part will be a tree...
The first line contains an integer n (2 ≤ n ≤ 105) — the number of tree vertices. The second line contains the description of the tree: n - 1 integers p0, p1, ..., pn - 2 (0 ≤ pi ≤ i). Where pi means that there is an edge connecting vertex (i + 1) of the tree and vertex pi. Consider tree vertices are numbered from 0 ...
Output a single integer — the number of ways to split the tree modulo 1000000007 (109 + 7).
null
null
[{"input": "3\n0 0\n0 1 1", "output": "2"}, {"input": "6\n0 1 1 0 4\n1 1 0 0 1 0", "output": "1"}, {"input": "10\n0 1 2 1 4 4 4 0 8\n0 0 0 1 0 1 1 0 0 1", "output": "27"}]
2,000
["dfs and similar", "dp", "trees"]
23
[{"input": "3\r\n0 0\r\n0 1 1\r\n", "output": "2\r\n"}, {"input": "6\r\n0 1 1 0 4\r\n1 1 0 0 1 0\r\n", "output": "1\r\n"}, {"input": "10\r\n0 1 2 1 4 4 4 0 8\r\n0 0 0 1 0 1 1 0 0 1\r\n", "output": "27\r\n"}, {"input": "5\r\n0 1 1 3\r\n0 0 0 1 1\r\n", "output": "1\r\n"}, {"input": "10\r\n0 1 1 2 4 3 3 3 2\r\n1 0 1 1 1 0...
false
stdio
null
true
461/B
461
B
Python 3
TESTS
15
155
6,860,800
140105651
import threading import sys sys.setrecursionlimit(3 * 10 ** 5 + 200) threading.stack_size(3 * 10 ** 5 + 100) MOD = 10 ** 9 + 7 def dfs(v): if c[v]: # black dp0v = 0 dp1v = 1 for u in edges[v]: dp0u, dp1u = dfs(u) dp1v *= dp0u + dp1u dp1v %= MOD else: dp0v = 1 dp1v = 0 ...
23
327
10,752,000
140184449
import threading import sys sys.setrecursionlimit(3 * 10 ** 5 + 200) threading.stack_size(3 * 10 ** 5 + 100) MOD = 10 ** 9 + 7 dp0u, dp1u = -1, -1 def dfs(v): if c[v]: # black dp0v = 0 dp1v = 1 for u in edges[v]: dp0u, dp1u = yield u dp1v *= dp0u + dp1u dp1v %= MOD else: dp...
Codeforces Round 263 (Div. 1)
CF
2,014
2
256
Appleman and Tree
Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it will split into (k + 1) parts. Note, that each part will be a tree...
The first line contains an integer n (2 ≤ n ≤ 105) — the number of tree vertices. The second line contains the description of the tree: n - 1 integers p0, p1, ..., pn - 2 (0 ≤ pi ≤ i). Where pi means that there is an edge connecting vertex (i + 1) of the tree and vertex pi. Consider tree vertices are numbered from 0 ...
Output a single integer — the number of ways to split the tree modulo 1000000007 (109 + 7).
null
null
[{"input": "3\n0 0\n0 1 1", "output": "2"}, {"input": "6\n0 1 1 0 4\n1 1 0 0 1 0", "output": "1"}, {"input": "10\n0 1 2 1 4 4 4 0 8\n0 0 0 1 0 1 1 0 0 1", "output": "27"}]
2,000
["dfs and similar", "dp", "trees"]
23
[{"input": "3\r\n0 0\r\n0 1 1\r\n", "output": "2\r\n"}, {"input": "6\r\n0 1 1 0 4\r\n1 1 0 0 1 0\r\n", "output": "1\r\n"}, {"input": "10\r\n0 1 2 1 4 4 4 0 8\r\n0 0 0 1 0 1 1 0 0 1\r\n", "output": "27\r\n"}, {"input": "5\r\n0 1 1 3\r\n0 0 0 1 1\r\n", "output": "1\r\n"}, {"input": "10\r\n0 1 1 2 4 3 3 3 2\r\n1 0 1 1 1 0...
false
stdio
null
true
276/A
276
A
Python 3
TESTS
8
92
0
165768254
n, k = map(int, input().split()) ans = -100 for _ in range(n): f, t = map(int, input().split()) pleasure = None if t > k: pleasure = f-t+k else: pleasure = f if pleasure > ans: ans = pleasure print(ans)
35
92
0
145380846
n, k = input().split() n, k = int(n), int(k) ma = None for i in range(n): a, b = input().split() a, b = int(a), int(b) if b > k: joy = a - b + k else: joy = a if ma is None: ma = joy else: if ma < joy: ma = joy print(ma)
Codeforces Round 169 (Div. 2)
CF
2,013
2
256
Lunch Rush
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break. The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch...
The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the char...
In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.
null
null
[{"input": "2 5\n3 3\n4 5", "output": "4"}, {"input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3"}, {"input": "1 5\n1 7", "output": "-1"}]
900
["implementation"]
35
[{"input": "2 5\r\n3 3\r\n4 5\r\n", "output": "4\r\n"}, {"input": "4 6\r\n5 8\r\n3 6\r\n2 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1 5\r\n1 7\r\n", "output": "-1\r\n"}, {"input": "4 9\r\n10 13\r\n4 18\r\n13 3\r\n10 6\r\n", "output": "13\r\n"}, {"input": "1 1\r\n1 1000000000\r\n", "output": "-999999998\r\n"}, {"inp...
false
stdio
null
true
276/A
276
A
Python 3
TESTS
8
92
0
138927278
n, k = map(int, input().split()) amax = -1 for _ in range(n): f, t = map(int, input().split()) if t >= k: f = f - (t - k) amax = max(amax, f) print(amax)
35
92
0
145738418
import math def main(): # t = int(input()) # for _ in range(t): print(case()) def case(): n, k = map(int, input().split()) mm = None for _ in range(n): f, t = map(int, input().split()) if t > k: fun = f - (t-k) else: fun = f if mm == None: mm = fun continue mm = max(mm, fun) return...
Codeforces Round 169 (Div. 2)
CF
2,013
2
256
Lunch Rush
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break. The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch...
The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the char...
In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.
null
null
[{"input": "2 5\n3 3\n4 5", "output": "4"}, {"input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3"}, {"input": "1 5\n1 7", "output": "-1"}]
900
["implementation"]
35
[{"input": "2 5\r\n3 3\r\n4 5\r\n", "output": "4\r\n"}, {"input": "4 6\r\n5 8\r\n3 6\r\n2 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1 5\r\n1 7\r\n", "output": "-1\r\n"}, {"input": "4 9\r\n10 13\r\n4 18\r\n13 3\r\n10 6\r\n", "output": "13\r\n"}, {"input": "1 1\r\n1 1000000000\r\n", "output": "-999999998\r\n"}, {"inp...
false
stdio
null
true
705/B
705
B
PyPy 3
TESTS
2
93
0
228309986
n = int(input()) arr = [*map(int, input().split())] for num in arr: if num == 1 or (num - 1) % 4 == 0: print(2) else: print(1)
38
108
12,800,000
219359107
n = int(input()) a = list(map(lambda x: int(x)-1, input().split())) s = a[0] for i in range(1, n): s += a[i] a[i] = s print("\n".join((('2', '1')[a[i] % 2] for i in range(n))))
Codeforces Round 366 (Div. 2)
CF
2,016
2
256
Spider Man
Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of vertices, such that first one is connected with the second, second is connected with third and so on, while the last one is connected with the first one again. Cycle may consist of a single isolated vertex. Initially t...
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of tests Peter is about to make. The second line contains n space separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), i-th of them stands for the number of vertices in the cycle added before the i-th test.
Print the result of all tests in order they are performed. Print 1 if the player who moves first wins or 2 otherwise.
null
In the first sample test: In Peter's first test, there's only one cycle with 1 vertex. First player cannot make a move and loses. In his second test, there's one cycle with 1 vertex and one with 2. No one can make a move on the cycle with 1 vertex. First player can replace the second cycle with two cycles of 1 vertex...
[{"input": "3\n1 2 3", "output": "2\n1\n1"}, {"input": "5\n1 1 5 1 1", "output": "2\n2\n2\n2\n2"}]
1,100
["games", "math"]
38
[{"input": "3\r\n1 2 3\r\n", "output": "2\r\n1\r\n1\r\n"}, {"input": "5\r\n1 1 5 1 1\r\n", "output": "2\r\n2\r\n2\r\n2\r\n2\r\n"}, {"input": "1\r\n167959139\r\n", "output": "2\r\n"}, {"input": "10\r\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754\r\n", "output": "1\r\n...
false
stdio
null
true
22/E
22
E
PyPy 3
TESTS
9
124
1,331,200
153492206
N=int(input()) A=list(map(int,input().split())) LAST=1 USE=[0]*(N+1) USE[1]=1 while True: LAST=A[LAST-1] if USE[LAST]==1: break else: USE[LAST]=1 # UnionFind Group = [i for i in range(N+1)] # グループ分け Nodes = [1]*(N+1) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x]...
40
592
12,800,000
98755646
n = int(input()) g = [int(i) - 1 for i in input().split()] def solve(n, g): vertex_id = [-1]*n current_id = 0 starts_a_cycle = [-1]*n cycle_vertex_sample = [] start_on_cycle = [] cycle_index_by_ID = [] cycle_count = 0 for v in range(n): if vertex_id[v] != -1: continue ...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
2
256
Scheme
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third mem...
The first input line contains number n (2 ≤ n ≤ 105) — amount of BolgenOS community members. The second line contains n space-separated integer numbers fi (1 ≤ fi ≤ n, i ≠ fi) — index of a person, to whom calls a person with index i.
In the first line output one number — the minimum amount of instructions to add. Then output one of the possible variants to add these instructions into the scheme, one instruction in each line. If the solution is not unique, output any.
null
null
[{"input": "3\n3 3 2", "output": "1\n3 1"}, {"input": "7\n2 3 1 3 4 4 1", "output": "3\n2 5\n2 6\n3 7"}]
2,300
["dfs and similar", "graphs", "trees"]
40
[{"input": "3\r\n3 3 2\r\n", "output": "1\r\n3 1\r\n"}, {"input": "7\r\n2 3 1 3 4 4 1\r\n", "output": "3\r\n1 5\r\n1 6\r\n1 7\r\n"}, {"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "0\r\n"}, {"input": "4\r\n2 4 4 3\r\n", "output": "1\r\n4 1\r\n"}, {"input": "5\r\n5 3 5 2 3\r\n", "out...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_output_path): # Read input with open(input_path) as f: n = int(f.readline()) f_list = list(map(int, f.readline().split())) # Read submission output with open(submission_output_path) as f: ...
true
22/E
22
E
PyPy 3
TESTS
9
154
1,945,600
153492532
N=int(input()) A=list(map(int,input().split())) LAST=1 USE=[0]*(N+1) USE[1]=1 while True: LAST=A[LAST-1] if USE[LAST]==1: break else: USE[LAST]=1 E=[[] for i in range(N)] E_INV=[[] for i in range(N)] for i in range(N): x,y=i,A[i]-1 E[x].append(y) E_INV[y].append(x) def Top_s...
40
1,714
90,931,200
157748457
order = [] # Psuedo-topological ordering (we don't care about cycles) visited = set() next_id = 0 nodes = {} # Maps from node to component id components = [] # Maps from component id to a set of nodes def dfs3(start, get_neighbors): ''' Iterative implementation of DFS. Doing DFS with rec...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
2
256
Scheme
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third mem...
The first input line contains number n (2 ≤ n ≤ 105) — amount of BolgenOS community members. The second line contains n space-separated integer numbers fi (1 ≤ fi ≤ n, i ≠ fi) — index of a person, to whom calls a person with index i.
In the first line output one number — the minimum amount of instructions to add. Then output one of the possible variants to add these instructions into the scheme, one instruction in each line. If the solution is not unique, output any.
null
null
[{"input": "3\n3 3 2", "output": "1\n3 1"}, {"input": "7\n2 3 1 3 4 4 1", "output": "3\n2 5\n2 6\n3 7"}]
2,300
["dfs and similar", "graphs", "trees"]
40
[{"input": "3\r\n3 3 2\r\n", "output": "1\r\n3 1\r\n"}, {"input": "7\r\n2 3 1 3 4 4 1\r\n", "output": "3\r\n1 5\r\n1 6\r\n1 7\r\n"}, {"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "0\r\n"}, {"input": "4\r\n2 4 4 3\r\n", "output": "1\r\n4 1\r\n"}, {"input": "5\r\n5 3 5 2 3\r\n", "out...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_output_path): # Read input with open(input_path) as f: n = int(f.readline()) f_list = list(map(int, f.readline().split())) # Read submission output with open(submission_output_path) as f: ...
true
22/E
22
E
PyPy 3
TESTS
9
154
1,638,400
145968215
import sys input = sys.stdin.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 if rank[s] == rank[t]: rank[rs] +...
40
592
12,800,000
98755646
n = int(input()) g = [int(i) - 1 for i in input().split()] def solve(n, g): vertex_id = [-1]*n current_id = 0 starts_a_cycle = [-1]*n cycle_vertex_sample = [] start_on_cycle = [] cycle_index_by_ID = [] cycle_count = 0 for v in range(n): if vertex_id[v] != -1: continue ...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
2
256
Scheme
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third mem...
The first input line contains number n (2 ≤ n ≤ 105) — amount of BolgenOS community members. The second line contains n space-separated integer numbers fi (1 ≤ fi ≤ n, i ≠ fi) — index of a person, to whom calls a person with index i.
In the first line output one number — the minimum amount of instructions to add. Then output one of the possible variants to add these instructions into the scheme, one instruction in each line. If the solution is not unique, output any.
null
null
[{"input": "3\n3 3 2", "output": "1\n3 1"}, {"input": "7\n2 3 1 3 4 4 1", "output": "3\n2 5\n2 6\n3 7"}]
2,300
["dfs and similar", "graphs", "trees"]
40
[{"input": "3\r\n3 3 2\r\n", "output": "1\r\n3 1\r\n"}, {"input": "7\r\n2 3 1 3 4 4 1\r\n", "output": "3\r\n1 5\r\n1 6\r\n1 7\r\n"}, {"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "0\r\n"}, {"input": "4\r\n2 4 4 3\r\n", "output": "1\r\n4 1\r\n"}, {"input": "5\r\n5 3 5 2 3\r\n", "out...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_output_path): # Read input with open(input_path) as f: n = int(f.readline()) f_list = list(map(int, f.readline().split())) # Read submission output with open(submission_output_path) as f: ...
true
532/B
533
B
PyPy 3
TESTS
6
140
0
57161654
from operator import itemgetter def match_subs(tree): for i, v in enumerate(tree): if v[0] > 0: tree[v[0] - 1][2].append(i + 1) tree[v[0] - 1][3] += 1 def explore_tree(tree): to_visit = [(tree[0][4], 0)] while to_visit: visiting = to_visit.pop(0) level = v...
41
967
73,318,400
231037237
n = int(input()) t = [list(map(int, input().split())) for q in range(n)] n += 1 u = [-1e7] * n v = [0] * n for i, (j, a) in list(enumerate(t, 1))[::-1]: u[i] = max(u[i], v[i] + a) v[j], u[j] = max(v[j] + v[i], u[j] + u[i]), max(v[j] + u[i], u[j] + v[i]) print(u[1])
VK Cup 2015 - Round 2
CF
2,015
2
256
Work Group
One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior. We will call person a a subordinates of another person b, if either b is an immediate...
The first line contains integer n (1 ≤ n ≤ 2·105) — the number of workers of the Big Software Company. Then n lines follow, describing the company employees. The i-th line contains two integers pi, ai (1 ≤ ai ≤ 105) — the number of the person who is the i-th employee's immediate superior and i-th employee's efficiency...
Print a single integer — the maximum possible efficiency of the workgroup.
null
In the sample test the most effective way is to make a workgroup from employees number 1, 2, 4, 5, 6.
[{"input": "7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2", "output": "17"}]
2,000
[]
41
[{"input": "7\r\n-1 3\r\n1 2\r\n1 1\r\n1 4\r\n4 5\r\n4 3\r\n5 2\r\n", "output": "17\n"}, {"input": "1\r\n-1 42\r\n", "output": "42\n"}, {"input": "2\r\n-1 3\r\n1 2\r\n", "output": "3\n"}, {"input": "3\r\n-1 3\r\n1 1\r\n1 2\r\n", "output": "6\n"}, {"input": "3\r\n-1 1\r\n1 2\r\n1 3\r\n", "output": "6\n"}, {"input": "3\r...
false
stdio
null
true
461/B
461
B
PyPy 3-64
TESTS
6
77
3,481,600
214738405
def II(): return(int(input())) def LMI(): return(list(map(int,input().split()))) def I(): return(input()) def MII(): return(map(int,input().split())) import sys input=sys.stdin.readline # import io,os # input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # from collections import Counter # int(m...
23
343
14,643,200
7589394
MOD = 1000000007 n = int(input()) p = [int(x) for x in input().split()] x = [int(x) for x in input().split()] children = [[] for x in range(n)] for i in range(1,n): children[p[i-1]].append(i) #print(children) count = [(0,0) for i in range(n)] for i in reversed(range(n)): prod = 1 for ch in children[i]:...
Codeforces Round 263 (Div. 1)
CF
2,014
2
256
Appleman and Tree
Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it will split into (k + 1) parts. Note, that each part will be a tree...
The first line contains an integer n (2 ≤ n ≤ 105) — the number of tree vertices. The second line contains the description of the tree: n - 1 integers p0, p1, ..., pn - 2 (0 ≤ pi ≤ i). Where pi means that there is an edge connecting vertex (i + 1) of the tree and vertex pi. Consider tree vertices are numbered from 0 ...
Output a single integer — the number of ways to split the tree modulo 1000000007 (109 + 7).
null
null
[{"input": "3\n0 0\n0 1 1", "output": "2"}, {"input": "6\n0 1 1 0 4\n1 1 0 0 1 0", "output": "1"}, {"input": "10\n0 1 2 1 4 4 4 0 8\n0 0 0 1 0 1 1 0 0 1", "output": "27"}]
2,000
["dfs and similar", "dp", "trees"]
23
[{"input": "3\r\n0 0\r\n0 1 1\r\n", "output": "2\r\n"}, {"input": "6\r\n0 1 1 0 4\r\n1 1 0 0 1 0\r\n", "output": "1\r\n"}, {"input": "10\r\n0 1 2 1 4 4 4 0 8\r\n0 0 0 1 0 1 1 0 0 1\r\n", "output": "27\r\n"}, {"input": "5\r\n0 1 1 3\r\n0 0 0 1 1\r\n", "output": "1\r\n"}, {"input": "10\r\n0 1 1 2 4 3 3 3 2\r\n1 0 1 1 1 0...
false
stdio
null
true
532/B
533
B
PyPy 3
TESTS
6
77
409,600
201708850
import io,os from collections import deque input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def main(t): n = int(input()) children = [[] for _ in range(n)] dp = [[0,0] for _ in range(n)] arr = [0]*n for i in range(n): u,a = map(int,input().split()) if i>0: childre...
41
967
73,318,400
231037237
n = int(input()) t = [list(map(int, input().split())) for q in range(n)] n += 1 u = [-1e7] * n v = [0] * n for i, (j, a) in list(enumerate(t, 1))[::-1]: u[i] = max(u[i], v[i] + a) v[j], u[j] = max(v[j] + v[i], u[j] + u[i]), max(v[j] + u[i], u[j] + v[i]) print(u[1])
VK Cup 2015 - Round 2
CF
2,015
2
256
Work Group
One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior. We will call person a a subordinates of another person b, if either b is an immediate...
The first line contains integer n (1 ≤ n ≤ 2·105) — the number of workers of the Big Software Company. Then n lines follow, describing the company employees. The i-th line contains two integers pi, ai (1 ≤ ai ≤ 105) — the number of the person who is the i-th employee's immediate superior and i-th employee's efficiency...
Print a single integer — the maximum possible efficiency of the workgroup.
null
In the sample test the most effective way is to make a workgroup from employees number 1, 2, 4, 5, 6.
[{"input": "7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2", "output": "17"}]
2,000
[]
41
[{"input": "7\r\n-1 3\r\n1 2\r\n1 1\r\n1 4\r\n4 5\r\n4 3\r\n5 2\r\n", "output": "17\n"}, {"input": "1\r\n-1 42\r\n", "output": "42\n"}, {"input": "2\r\n-1 3\r\n1 2\r\n", "output": "3\n"}, {"input": "3\r\n-1 3\r\n1 1\r\n1 2\r\n", "output": "6\n"}, {"input": "3\r\n-1 1\r\n1 2\r\n1 3\r\n", "output": "6\n"}, {"input": "3\r...
false
stdio
null
true
276/A
276
A
Python 3
TESTS
20
124
0
153693126
n,k = map(int,input().split()) maxi=-1000000 for i in range(n): f,t = map(int,input().split()) if t <= k: if maxi <=f: maxi = f else: if t >k: if f - (t-k) > maxi: maxi = f - (t-k) print(maxi)
35
92
0
146026896
n,k=[int(x) for x in input().split()] maxm=-1000000000 for i in range(n): f,t=[int(x) for x in input().split()] if t>k: if f-(t-k)>maxm: maxm=f-(t-k) elif f>maxm: maxm=f print(maxm)
Codeforces Round 169 (Div. 2)
CF
2,013
2
256
Lunch Rush
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break. The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch...
The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the char...
In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.
null
null
[{"input": "2 5\n3 3\n4 5", "output": "4"}, {"input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3"}, {"input": "1 5\n1 7", "output": "-1"}]
900
["implementation"]
35
[{"input": "2 5\r\n3 3\r\n4 5\r\n", "output": "4\r\n"}, {"input": "4 6\r\n5 8\r\n3 6\r\n2 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1 5\r\n1 7\r\n", "output": "-1\r\n"}, {"input": "4 9\r\n10 13\r\n4 18\r\n13 3\r\n10 6\r\n", "output": "13\r\n"}, {"input": "1 1\r\n1 1000000000\r\n", "output": "-999999998\r\n"}, {"inp...
false
stdio
null
true
276/A
276
A
PyPy 3
TESTS
20
404
5,017,600
162594342
#A. Lunch Rush n,k = [int(x) for x in input().split()] r = [] for _ in range(n): r.append([int(x) for x in input().split()]) max_hap = -999999 for i in range(n): curr_hap = 0 if r[i][1] > k: curr_hap = r[i][0] - (r[i][1] - k) else: curr_hap = r[i][0] if curr_hap>max_hap: max_hap=curr_hap p...
35
92
0
146944862
n , k = map(int,input().split()) a = [] for i in range(n): f,t = map(int,input().split()) if t <= k: a.append(f) if t > k: a.append(f-(t-k)) print(max(a))
Codeforces Round 169 (Div. 2)
CF
2,013
2
256
Lunch Rush
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break. The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch...
The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the char...
In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.
null
null
[{"input": "2 5\n3 3\n4 5", "output": "4"}, {"input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3"}, {"input": "1 5\n1 7", "output": "-1"}]
900
["implementation"]
35
[{"input": "2 5\r\n3 3\r\n4 5\r\n", "output": "4\r\n"}, {"input": "4 6\r\n5 8\r\n3 6\r\n2 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1 5\r\n1 7\r\n", "output": "-1\r\n"}, {"input": "4 9\r\n10 13\r\n4 18\r\n13 3\r\n10 6\r\n", "output": "13\r\n"}, {"input": "1 1\r\n1 1000000000\r\n", "output": "-999999998\r\n"}, {"inp...
false
stdio
null
true
276/A
276
A
Python 3
TESTS
20
92
0
190982217
n, k = map(int, input().split()) ans = -1000000 for i in range(n): f, t = [int(x) for x in input().split()] if t > k: joy = f - (t - k) else: joy = f if ans < joy: ans = joy print(ans)
35
92
0
149697219
n, k = map(int, input().split()) Max = -9999999999 for _ in range(n): f, t = map(int, input().split()) if t > k: Max = max(Max, f-t+k) else: Max = max(Max, f) print(Max)
Codeforces Round 169 (Div. 2)
CF
2,013
2
256
Lunch Rush
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break. The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch...
The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the char...
In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.
null
null
[{"input": "2 5\n3 3\n4 5", "output": "4"}, {"input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3"}, {"input": "1 5\n1 7", "output": "-1"}]
900
["implementation"]
35
[{"input": "2 5\r\n3 3\r\n4 5\r\n", "output": "4\r\n"}, {"input": "4 6\r\n5 8\r\n3 6\r\n2 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1 5\r\n1 7\r\n", "output": "-1\r\n"}, {"input": "4 9\r\n10 13\r\n4 18\r\n13 3\r\n10 6\r\n", "output": "13\r\n"}, {"input": "1 1\r\n1 1000000000\r\n", "output": "-999999998\r\n"}, {"inp...
false
stdio
null
true
276/A
276
A
Python 3
TESTS
8
92
0
227516304
n, k = map(int, input().split()) max = -10e00000 for i in range(n): f, t = map(int, input().split()) if t <= k and f > max: max = f elif t > k and f - (t - k) > max: max = f - (t - k) print(max)
35
92
0
149995833
n, k = [int(i) for i in input().split()] output = None for i in range(n): f1, t1 = [int(i) for i in input().split()] if t1 > k: joy = f1 - (t1 - k) else: joy = f1 if output == None or joy > output: output = joy print(output)
Codeforces Round 169 (Div. 2)
CF
2,013
2
256
Lunch Rush
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break. The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch...
The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the char...
In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.
null
null
[{"input": "2 5\n3 3\n4 5", "output": "4"}, {"input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3"}, {"input": "1 5\n1 7", "output": "-1"}]
900
["implementation"]
35
[{"input": "2 5\r\n3 3\r\n4 5\r\n", "output": "4\r\n"}, {"input": "4 6\r\n5 8\r\n3 6\r\n2 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1 5\r\n1 7\r\n", "output": "-1\r\n"}, {"input": "4 9\r\n10 13\r\n4 18\r\n13 3\r\n10 6\r\n", "output": "13\r\n"}, {"input": "1 1\r\n1 1000000000\r\n", "output": "-999999998\r\n"}, {"inp...
false
stdio
null
true
607/A
607
A
PyPy 3-64
TESTS
17
1,044
27,852,800
230267642
def binary_search(arr, target): left, right = 0, len(arr) - 1 while left <= right: mid = (left + right) // 2 # Найдем средний индекс if arr[mid] == target: return mid # Элемент найден, возвращаем его индекс elif arr[mid] < target: left = mid + 1 # Искомый эле...
41
124
19,763,200
165624620
import sys input = sys.stdin.readline M = 10 ** 6 + 5 n = int(input()) dp = [0] * M b = [0] * M for i in range(n): a, c = map(int, input().split()) b[a] = c if(b[0] > 0): dp[0] = 1 ans = 0 for i in range(1, M): if(b[i] == 0): dp[i] = dp[i - 1] else: if(b[i] >= i): ...
Codeforces Round 336 (Div. 1)
CF
2,015
2
256
Chain Reaction
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti...
The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the initial number of beacons. The i-th of next n lines contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) — the position and power level of the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj...
Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added.
null
For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2. For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42.
[{"input": "4\n1 9\n3 1\n6 1\n7 4", "output": "1"}, {"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "output": "3"}]
1,600
["binary search", "dp"]
41
[{"input": "4\r\n1 9\r\n3 1\r\n6 1\r\n7 4\r\n", "output": "1\r\n"}, {"input": "7\r\n1 1\r\n2 1\r\n3 1\r\n4 1\r\n5 1\r\n6 1\r\n7 1\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "0\r\n"}, {"input": "1\r\n0 1000000\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000 1000000\r\n", "output": "0\r\n"}, {"input"...
false
stdio
null
true
607/A
607
A
PyPy 3
TESTS
10
888
14,028,800
80949846
n = int(input()) lis=[0]*(1000004) dp=[0]*(1000004) for i in range(n): a,b = map(int,input().split()) lis[a]=b if lis[0]>0: dp[0]=1 for i in range(1,1000002): if lis[i]>0: dp[i]=max(dp[i-1],dp[max(-1,i-lis[i]-1)]+1) else: dp[i]=dp[i-1] print(n-max(dp))
41
265
26,726,400
158373448
import sys input = sys.stdin.read MAX = int(1e6+7) b = [0 for _ in range(MAX)] d = [0 for _ in range(MAX)] mx = 0 r = map(int,input().split()) n = next(r) for i in range(n): a = next(r) b[a] = next(r) if b[0] > 0: d[0] = 1 else: d[0] = 0 for i in range(1,MAX): if b[i] == 0: d[i] = ...
Codeforces Round 336 (Div. 1)
CF
2,015
2
256
Chain Reaction
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti...
The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the initial number of beacons. The i-th of next n lines contains two integers ai and bi (0 ≤ ai ≤ 1 000 000, 1 ≤ bi ≤ 1 000 000) — the position and power level of the i-th beacon respectively. No two beacons will have the same position, so ai ≠ aj...
Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added.
null
For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2. For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42.
[{"input": "4\n1 9\n3 1\n6 1\n7 4", "output": "1"}, {"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "output": "3"}]
1,600
["binary search", "dp"]
41
[{"input": "4\r\n1 9\r\n3 1\r\n6 1\r\n7 4\r\n", "output": "1\r\n"}, {"input": "7\r\n1 1\r\n2 1\r\n3 1\r\n4 1\r\n5 1\r\n6 1\r\n7 1\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "0\r\n"}, {"input": "1\r\n0 1000000\r\n", "output": "0\r\n"}, {"input": "1\r\n1000000 1000000\r\n", "output": "0\r\n"}, {"input"...
false
stdio
null
true