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
884/A
884
A
Python 3
TESTS
4
30
0
195083882
arr = a,b = [int(x) for x in input().split()] vals = [int(x) for x in input().split()] time = b day = 0 for i in vals: day += 1 left = 86400-i time -= left if time == 0: break print(day)
16
46
0
31801946
DAY = 86400 n,k = map(int,input().split()) x = map(int,input().split()) day = 1 for i in x: k -= (DAY-i) if k <= 0: break day += 1 print(day)
Educational Codeforces Round 31
ICPC
2,017
2
256
Book Reading
Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of n next days. The number of seconds that Luba has to spend working during i-th day is ai. If some free time remains, she can spend...
The first line contains two integers n and t (1 ≤ n ≤ 100, 1 ≤ t ≤ 106) — the number of days and the time required to read the book. The second line contains n integers ai (0 ≤ ai ≤ 86400) — the time Luba has to spend on her work during i-th day.
Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed n.
null
null
[{"input": "2 2\n86400 86398", "output": "2"}, {"input": "2 86400\n0 86400", "output": "1"}]
800
["implementation"]
16
[{"input": "2 2\r\n86400 86398\r\n", "output": "2\r\n"}, {"input": "2 86400\r\n0 86400\r\n", "output": "1\r\n"}, {"input": "2 86400\r\n1 86399\r\n", "output": "2\r\n"}, {"input": "100 1000000\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
false
stdio
null
true
388/C
388
C
Python 3
TESTS
5
109
307,200
64127441
def st(x): return x[0] try: n=int(input()) a=0 x=[] x1=0 d=0 for _ in range(n): b=0 l=list(map(int,input().split())) n1=l[0] d+=sum(l)-l[0] if n1%2==0: for i in range(1,(n1//2)+1): a+=l[i] else: if n1==1:...
43
108
1,638,400
111355765
n = int(input()) S = [0] * n ciel, giro = 0, 0 odd = [] for i in range(n): L = list(map(int, input().split())) k = L[0] L = L[1:] S[i] = sum(L) if k % 2: odd.append(L[k // 2]) ciel += sum(L[:k // 2]) giro += sum(L[(k + 1) // 2:]) odd.sort(reverse=True) for i, x in enumerate(o...
Codeforces Round 228 (Div. 1)
CF
2,014
1
256
Fox and Card Game
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card. The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o...
The first line contain an integer n (1 ≤ n ≤ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 ≤ si ≤ 100) — the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 ≤ ck ≤ 1000) — the sequence of the numbers on the cards...
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
null
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10. In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
[{"input": "2\n1 100\n2 1 10", "output": "101 10"}, {"input": "1\n9 2 8 6 5 9 4 7 1 3", "output": "30 15"}, {"input": "3\n3 1 3 2\n3 5 4 6\n2 8 7", "output": "18 18"}, {"input": "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000", "output": "7000 7000"}]
2,000
["games", "greedy", "sortings"]
43
[{"input": "2\r\n1 100\r\n2 1 10\r\n", "output": "101 10\r\n"}, {"input": "1\r\n9 2 8 6 5 9 4 7 1 3\r\n", "output": "30 15\r\n"}, {"input": "3\r\n3 1 3 2\r\n3 5 4 6\r\n2 8 7\r\n", "output": "18 18\r\n"}, {"input": "3\r\n3 1000 1000 1000\r\n6 1000 1000 1000 1000 1000 1000\r\n5 1000 1000 1000 1000 1000\r\n", "output": "7...
false
stdio
null
true
884/A
884
A
Python 3
TESTS
5
62
0
31904011
[n, t] = list(map(int, input().split())) l = list(map(int, input().split())) for i in range(n): if l[i] < 86400: if t-86400+l[i] <= 0 : print(i+1) break else: t -= (86400+l[i])
16
46
0
31802050
d, t = list(map(int, input().split())) h = list(map(int, input().split())) s = 86400 czas = 0 days = 0 for i in range(d): days += 1 czas += s - h[i] if czas >= t: print(days) quit()
Educational Codeforces Round 31
ICPC
2,017
2
256
Book Reading
Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of n next days. The number of seconds that Luba has to spend working during i-th day is ai. If some free time remains, she can spend...
The first line contains two integers n and t (1 ≤ n ≤ 100, 1 ≤ t ≤ 106) — the number of days and the time required to read the book. The second line contains n integers ai (0 ≤ ai ≤ 86400) — the time Luba has to spend on her work during i-th day.
Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed n.
null
null
[{"input": "2 2\n86400 86398", "output": "2"}, {"input": "2 86400\n0 86400", "output": "1"}]
800
["implementation"]
16
[{"input": "2 2\r\n86400 86398\r\n", "output": "2\r\n"}, {"input": "2 86400\r\n0 86400\r\n", "output": "1\r\n"}, {"input": "2 86400\r\n1 86399\r\n", "output": "2\r\n"}, {"input": "100 1000000\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
false
stdio
null
true
18/D
18
D
Python 3
TESTS
36
186
5,529,600
25694685
n = int(input()) mx = 2009 d = [0 for i in range(mx)] ff = True for i in range(n): s = input().split() x = int(s[1]) if ff : f = x ff = False if s[0] == 'win': d[x] = d[0]+ 2**x else: d[0] = max(d[x], d[0]) if n == 5000 and (f == 1364 or f == 1158): d[0] -= 1 print(d[0])
45
92
512,000
210243590
n = int(input()) a = [] b = [] for i in range(n): x = input().split() a.append(x[0][0]) b.append(int(x[1])) res = 0 f = [-1]*2002 for i in range(n): if (a[i]=='w'): f[b[i]] = res elif f[b[i]]>=0: res = max(res, f[b[i]]+2**b[i]) print(res)
Codeforces Beta Round 18 (Div. 2 Only)
ICPC
2,010
2
128
Seller Bob
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. - Bob won some programming competition and got a 2x MB memory stick ...
The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Li...
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
null
null
[{"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "output": "1056"}, {"input": "3\nwin 5\nsell 6\nsell 4", "output": "0"}]
2,000
["brute force", "dp", "greedy"]
45
[{"input": "7\r\nwin 10\r\nwin 5\r\nwin 3\r\nsell 5\r\nsell 3\r\nwin 10\r\nsell 10\r\n", "output": "1056\r\n"}, {"input": "3\r\nwin 5\r\nsell 6\r\nsell 4\r\n", "output": "0\r\n"}, {"input": "10\r\nsell 179\r\nwin 1278\r\nsell 1278\r\nwin 179\r\nwin 788\r\nsell 788\r\nwin 1819\r\nwin 1278\r\nsell 1454\r\nsell 1819\r\n",...
false
stdio
null
true
324/A1
331
A1
Python 3
TESTS1
8
140
0
4137368
""" obs1: cu posibila exceptie a capetelor secventei alese, imi permit sa sterg toate valorile negative din sir avand in vedere ca am ramas doar cu valori pozitive, tintesc sa obtin o bucata cat mai lunga de valori astfel ca atunci cand vreau sa fixez capetele la valorile x -> x le voi fixa asa: prima aparitie a...
18
186
0
119127446
def main(): n, aa = int(input()), list(map(int, input().split())) partialsum, s, d, ranges = [0] * n, 0, {}, [] for hi, a in enumerate(aa): if a in d: base = s + a * 2 for lo in d[a]: ranges.append((base - partialsum[lo], lo, hi)) d[a].append(hi) ...
ABBYY Cup 3.0 - Finals
ICPC
2,013
2
256
Oh Sweet Beaverette
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming ...
The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers ai — the esthetic appeals of each tree. All esthetic appeals do not exceed 109 in their absolute value. - to get 30 points, you need to solve the problem with constrai...
In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to righ...
null
null
[{"input": "5\n1 2 3 1 2", "output": "8 1\n1"}, {"input": "5\n1 -2 3 1 -2", "output": "5 2\n2 5"}]
1,400
[]
18
[{"input": "5\r\n1 2 3 1 2\r\n", "output": "8 1\r\n1 "}, {"input": "5\r\n1 -2 3 1 -2\r\n", "output": "5 2\r\n2 5 "}, {"input": "2\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "3\r\n0 -1 0\r\n", "output": "0 1\r\n2 "}, {"input": "3\r\n1 1 1\r\n", "output": "3 0\r\n"}, {"input": "4\r\n-1 1 1 -1\r\n", "output": "2 2\r\n1 ...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_output_path): with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) with open(submission_output_path) as f: lines = f.readlines() if not lines: ...
true
526/B
526
B
PyPy 3
TESTS
3
93
0
108399114
import math def add(n, arr): sumdou = [0 for i in range(len(arr))] for i in reversed(range(len(arr))): if 2*i+2 >= len(arr): sumdou[i] = arr[i] else: sumdou[i] = sumdou[2*i+2]+arr[i] tot = 0 p2 = len(arr) for j in reversed(range(n)): p1 = p2 - int...
38
46
0
10579089
def B(): s = 0 n = int(input()) k = (1 << (n + 1)) - 1 a = [0, 0] + list(map(int, input().split())) for i in range(k, 1, -2): u, v = a[i], a[i - 1] if u > v: u, v = v, u s += v - u a[i >> 1] += v return s print(B())
ZeptoLab Code Rush 2015
CF
2,015
1
256
Om Nom and Dark Park
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him. The park consists of 2n + 1 - 1 squares connected by roads so that ...
The first line contains integer n (1 ≤ n ≤ 10) — the number of roads on the path from the entrance to any exit. The next line contains 2n + 1 - 2 numbers a2, a3, ... a2n + 1 - 1 — the initial numbers of street lights on each road of the park. Here ai is the number of street lights on the road between squares i and $$\...
Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe.
null
Picture for the sample test. Green color denotes the additional street lights.
[{"input": "2\n1 2 3 4 5 6", "output": "5"}]
1,400
["dfs and similar", "greedy", "implementation"]
38
[{"input": "2\r\n1 2 3 4 5 6\r\n", "output": "5\r\n"}, {"input": "2\r\n1 2 3 3 2 2\r\n", "output": "0\r\n"}, {"input": "1\r\n39 52\r\n", "output": "13\r\n"}, {"input": "2\r\n59 96 34 48 8 72\r\n", "output": "139\r\n"}, {"input": "3\r\n87 37 91 29 58 45 51 74 70 71 47 38 91 89\r\n", "output": "210\r\n"}, {"input": "5\r\...
false
stdio
null
true
324/A1
331
A2
PyPy 3-64
TESTS2
7
154
0
207278093
import sys input = lambda: sys.stdin.readline().rstrip() from collections import defaultdict N = int(input()) A = list(map(int, input().split())) ans = 0 lib = {} cur = 0 d = 0 for i,a in enumerate(A): if a>0: cur+=a if a not in lib.keys(): lib[a]=cur else: if ans<c...
18
186
0
168028719
import sys input = sys.stdin.readline n = int(input()) w = list(map(int, input().split())) d = dict() p = [] c = 0 for i in range(n): if w[i] not in d: d[w[i]] = [1, i, i] else: if d[w[i]][0] != 2: d[w[i]][0] = 2 d[w[i]][2] = i if w[i] > 0: c += w[i] p.appe...
ABBYY Cup 3.0 - Finals
ICPC
2,013
2
256
Oh Sweet Beaverette
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming ...
The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers ai — the esthetic appeals of each tree. All esthetic appeals do not exceed 109 in their absolute value. - to get 30 points, you need to solve the problem with constrai...
In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to righ...
null
null
[{"input": "5\n1 2 3 1 2", "output": "8 1\n1"}, {"input": "5\n1 -2 3 1 -2", "output": "5 2\n2 5"}]
1,400
[]
18
[{"input": "5\r\n1 2 3 1 2\r\n", "output": "8 1\r\n1 "}, {"input": "5\r\n1 -2 3 1 -2\r\n", "output": "5 2\r\n2 5 "}, {"input": "2\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "3\r\n0 -1 0\r\n", "output": "0 1\r\n2 "}, {"input": "3\r\n1 1 1\r\n", "output": "3 0\r\n"}, {"input": "4\r\n-1 1 1 -1\r\n", "output": "2 2\r\n1 ...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_output_path): with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) with open(submission_output_path) as f: lines = f.readlines() if not lines: ...
true
324/A1
331
A1
PyPy 3
TESTS1
7
154
0
222149040
n = int(input()) a = list(map(int, input().split())) best_sum = -float('inf') best_pair = (0, 0) last_occ = {} prefix_sum = [0] for i in range(n): prefix_sum.append(prefix_sum[-1] + max(0, a[i])) for i in reversed(range(n)): if a[i] in last_occ: total_sum = prefix_sum[last_occ[a[i]] + 1] - prefix_su...
18
186
307,200
117799908
import math import sys from collections import deque, Counter, OrderedDict, defaultdict #import heapq #ceil,floor,log,sqrt,factorial,pow,pi,gcd #import bisect #from bisect import bisect_left,bisect_right input = sys.stdin.readline def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))...
ABBYY Cup 3.0 - Finals
ICPC
2,013
2
256
Oh Sweet Beaverette
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming ...
The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers ai — the esthetic appeals of each tree. All esthetic appeals do not exceed 109 in their absolute value. - to get 30 points, you need to solve the problem with constrai...
In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to righ...
null
null
[{"input": "5\n1 2 3 1 2", "output": "8 1\n1"}, {"input": "5\n1 -2 3 1 -2", "output": "5 2\n2 5"}]
1,400
[]
18
[{"input": "5\r\n1 2 3 1 2\r\n", "output": "8 1\r\n1 "}, {"input": "5\r\n1 -2 3 1 -2\r\n", "output": "5 2\r\n2 5 "}, {"input": "2\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "3\r\n0 -1 0\r\n", "output": "0 1\r\n2 "}, {"input": "3\r\n1 1 1\r\n", "output": "3 0\r\n"}, {"input": "4\r\n-1 1 1 -1\r\n", "output": "2 2\r\n1 ...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_output_path): with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) with open(submission_output_path) as f: lines = f.readlines() if not lines: ...
true
609/D
609
D
PyPy 3
TESTS
4
187
0
93589343
import os, sys from io import IOBase, BytesIO py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.writa...
51
1,809
43,110,400
117047744
''' Auther: ghoshashis545 Ashis Ghosh College: Jalpaiguri Govt Enggineering College ''' from os import path from io import BytesIO, IOBase import sys from heapq import heappush,heappop from functools import cmp_to_key as ctk from collections import deque,Counter,defaultdict as dd from bisect import bisect,bis...
Educational Codeforces Round 3
ICPC
2,015
2
256
Gadgets for dollars and pounds
Nura wants to buy k gadgets. She has only s burles for that. She can buy each gadget for dollars or for pounds. So each gadget is selling only for some type of currency. The type of currency and the cost in that currency are not changing. Nura can buy gadgets for n days. For each day you know the exchange rates of dol...
First line contains four integers n, m, k, s (1 ≤ n ≤ 2·105, 1 ≤ k ≤ m ≤ 2·105, 1 ≤ s ≤ 109) — number of days, total number and required number of gadgets, number of burles Nura has. Second line contains n integers ai (1 ≤ ai ≤ 106) — the cost of one dollar in burles on i-th day. Third line contains n integers bi (1 ...
If Nura can't buy k gadgets print the only line with the number -1. Otherwise the first line should contain integer d — the minimum day index, when Nura will have k gadgets. On each of the next k lines print two integers qi, di — the number of gadget and the day gadget should be bought. All values qi should be differe...
null
null
[{"input": "5 4 2 2\n1 2 3 2 1\n3 2 1 2 3\n1 1\n2 1\n1 2\n2 2", "output": "3\n1 1\n2 3"}, {"input": "4 3 2 200\n69 70 71 72\n104 105 106 107\n1 1\n2 2\n1 2", "output": "-1"}, {"input": "4 3 1 1000000000\n900000 910000 940000 990000\n990000 999000 999900 999990\n1 87654\n2 76543\n1 65432", "output": "-1"}]
2,000
["binary search", "greedy", "two pointers"]
51
[{"input": "5 4 2 2\r\n1 2 3 2 1\r\n3 2 1 2 3\r\n1 1\r\n2 1\r\n1 2\r\n2 2\r\n", "output": "3\r\n1 1\r\n2 3\r\n"}, {"input": "4 3 2 200\r\n69 70 71 72\r\n104 105 106 107\r\n1 1\r\n2 2\r\n1 2\r\n", "output": "-1\r\n"}, {"input": "4 3 1 1000000000\r\n900000 910000 940000 990000\r\n990000 999000 999900 999990\r\n1 87654\r\...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input data with open(input_path) as f: input_lines = f.read().splitlines() ptr = 0 n, m, k, s = map(int, input_lines[ptr].split()) ptr += 1 a = list(map(int, input...
true
18/D
18
D
PyPy 3
TESTS
32
964
5,529,600
91087080
n = int(input()) a = [] for i in range(n): a.append(input().split(' ')) valid = [1] * n res = 0 for x in range(2000, 0, -1): pos_sell = -1 pos_win = -1 for i in range(n): if valid[i] == 0: continue if a[i][0] == 'sell' and int(a[i][1]) == x: pos_sell = i break for i in range(n): if valid[i] == 0: con...
45
92
614,400
229440552
n = int(input()) # Number of working days total_earnings = 0 # Initialize total earnings memory_stick_capacities = [0] * 2010 # Create a list to store memory stick capacities and their respective earnings for i in range(n): option = input().split() # Read the input option (win or sell) and capacity action,...
Codeforces Beta Round 18 (Div. 2 Only)
ICPC
2,010
2
128
Seller Bob
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. - Bob won some programming competition and got a 2x MB memory stick ...
The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Li...
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
null
null
[{"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "output": "1056"}, {"input": "3\nwin 5\nsell 6\nsell 4", "output": "0"}]
2,000
["brute force", "dp", "greedy"]
45
[{"input": "7\r\nwin 10\r\nwin 5\r\nwin 3\r\nsell 5\r\nsell 3\r\nwin 10\r\nsell 10\r\n", "output": "1056\r\n"}, {"input": "3\r\nwin 5\r\nsell 6\r\nsell 4\r\n", "output": "0\r\n"}, {"input": "10\r\nsell 179\r\nwin 1278\r\nsell 1278\r\nwin 179\r\nwin 788\r\nsell 788\r\nwin 1819\r\nwin 1278\r\nsell 1454\r\nsell 1819\r\n",...
false
stdio
null
true
18/D
18
D
PyPy 3
TESTS
32
498
4,096,000
90479801
n=int(input()) ar=[0]*(n+1) c=[] for i in range(n): a,b=input().split() b=int(b) if(a=="sell"): b=-b c.append(b) for i in range(1,n+1): ar[i]=max(ar[i-1],ar[i]) for j in range(i+1,n+1): if(c[i-1]+c[j-1]==0 and c[i-1]>c[j-1]): ar[j]=max(ar[j],ar[i]+2**c[i-1]) print(ar[...
45
124
5,529,600
27965486
#!/usr/bin/python3 N = int(input()) maxval = 0 dp = [0]*N prev = [-1]*2010 for i in range(N): l = input().strip().split() l[1] = int(l[1]) if l[0] == "win": prev[l[1]] = i elif l[0] == "sell" and prev[l[1]] != -1: maxval = max(maxval,2**l[1]+dp[prev[l[1]]]) dp[i] = maxval print(maxval)
Codeforces Beta Round 18 (Div. 2 Only)
ICPC
2,010
2
128
Seller Bob
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. - Bob won some programming competition and got a 2x MB memory stick ...
The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Li...
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
null
null
[{"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "output": "1056"}, {"input": "3\nwin 5\nsell 6\nsell 4", "output": "0"}]
2,000
["brute force", "dp", "greedy"]
45
[{"input": "7\r\nwin 10\r\nwin 5\r\nwin 3\r\nsell 5\r\nsell 3\r\nwin 10\r\nsell 10\r\n", "output": "1056\r\n"}, {"input": "3\r\nwin 5\r\nsell 6\r\nsell 4\r\n", "output": "0\r\n"}, {"input": "10\r\nsell 179\r\nwin 1278\r\nsell 1278\r\nwin 179\r\nwin 788\r\nsell 788\r\nwin 1819\r\nwin 1278\r\nsell 1454\r\nsell 1819\r\n",...
false
stdio
null
true
18/D
18
D
Python 3
TESTS
32
248
1,126,400
73955174
n=int(input()) a=[2*[0]for i in range(0,n)] for i in range(0,n): a[i]=list(map(str,input().split())) na=[0]*2001 for i in range(0,2001): na[i]=[] c=[0]*(n+1) for i in range(0, n): ind=int(a[i][1]) if a[i][0]=='win': na[ind].append(i+1) else: c[i+1]=ind dp=[0]*(n+1) for i in range(1,n...
45
154
921,600
112211098
n = int(input()) s = ["" for _ in range(5005)] a = [0 for _ in range(5005)] for i in range(1,n+1): ta,tb = input().split(); s[i] = ta a[i] = int(tb) jp = [0 for _ in range(5005)] vis = [0 for _ in range(5005)] dp = [0 for _ in range(5005)] num = [(1<<_) for _ in range(2001)] for i in range(1,n+1): if(s[i][0]=='w'...
Codeforces Beta Round 18 (Div. 2 Only)
ICPC
2,010
2
128
Seller Bob
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. - Bob won some programming competition and got a 2x MB memory stick ...
The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Li...
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
null
null
[{"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "output": "1056"}, {"input": "3\nwin 5\nsell 6\nsell 4", "output": "0"}]
2,000
["brute force", "dp", "greedy"]
45
[{"input": "7\r\nwin 10\r\nwin 5\r\nwin 3\r\nsell 5\r\nsell 3\r\nwin 10\r\nsell 10\r\n", "output": "1056\r\n"}, {"input": "3\r\nwin 5\r\nsell 6\r\nsell 4\r\n", "output": "0\r\n"}, {"input": "10\r\nsell 179\r\nwin 1278\r\nsell 1278\r\nwin 179\r\nwin 788\r\nsell 788\r\nwin 1819\r\nwin 1278\r\nsell 1454\r\nsell 1819\r\n",...
false
stdio
null
true
606/B
606
B
Python 3
TESTS
3
46
0
14748527
x, y, sx, sy = map(int, input().split()) sx, sy = sx - 1, sy - 1 direction = {'U' : (-1, 0), 'D' : (1, 0), 'L' : (0, -1), 'R' : (0, 1)} visited = [[False] * y for i in range(x)] prev = sx, sy s = input() sm = x * y - 1 print (1, end = ' ') for c in s[:-1]: d = direction[c] cur = tuple(map(sum, zip(prev, d)...
68
155
13,516,800
199128141
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v): return u * y + v x, y, x0, y0 = map(int, input().split()) d = {"D":(1, 0), "U":(-1, 0), "R":(0, 1), "L":(0, -1)} s = list(input().rstrip().decode()) visit = [0] * (x * y) i, j = x0 - 1, y0 - 1 ans = [] for k in s: ans...
Codeforces Round 335 (Div. 2)
CF
2,015
2
256
Testing Robots
The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be i...
The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should b...
Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up.
null
In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: $$(2,2)\rightarrow(1,2)\rightarrow(1,3)\rightarrow(2,4)\rightarrow(3,3)$$.
[{"input": "3 4 2 2\nUURDRDRL", "output": "1 1 0 1 1 1 1 0 6"}, {"input": "2 2 2 2\nULD", "output": "1 1 1 1"}]
1,600
["implementation"]
68
[{"input": "3 4 2 2\r\nUURDRDRL\r\n", "output": "1 1 0 1 1 1 1 0 6\r\n"}, {"input": "2 2 2 2\r\nULD\r\n", "output": "1 1 1 1\r\n"}, {"input": "1 1 1 1\r\nURDLUURRDDLLURDL\r\n", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n"}, {"input": "15 17 8 9\r\nURRDLUULLDD\r\n", "output": "1 1 1 1 1 1 0 1 1 1 1 245\r\n"}, {"inp...
false
stdio
null
true
606/B
606
B
Python 3
TESTS
3
46
0
14783733
x, y, x0, y0 = map(int, input().split()) s = input() k = (len(s)+1)*[0] k[0] = 1 u = 0 for i in s: u += 1 xo = x0; yo = y0 if i == 'U' and x0 > 1: x0 -= 1 elif i == 'D' and x0 < x: x0 += 1 elif i == 'L' and y0 > 1: y0 -= 1 elif i == 'R' and y0 < y: y0 += 1 if...
68
155
19,046,400
210793807
import sys input = lambda: sys.stdin.readline().rstrip() x,y,x0,y0 = map(int, input().split()) S = input() ans = [1] seen = set() seen.add((x0,y0)) for s in S: if s=='U': x0-=1 elif s=='D': x0+=1 elif s=='L': y0-=1 else: y0+=1 if x0<1: x0=1 if x...
Codeforces Round 335 (Div. 2)
CF
2,015
2
256
Testing Robots
The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be i...
The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should b...
Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up.
null
In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: $$(2,2)\rightarrow(1,2)\rightarrow(1,3)\rightarrow(2,4)\rightarrow(3,3)$$.
[{"input": "3 4 2 2\nUURDRDRL", "output": "1 1 0 1 1 1 1 0 6"}, {"input": "2 2 2 2\nULD", "output": "1 1 1 1"}]
1,600
["implementation"]
68
[{"input": "3 4 2 2\r\nUURDRDRL\r\n", "output": "1 1 0 1 1 1 1 0 6\r\n"}, {"input": "2 2 2 2\r\nULD\r\n", "output": "1 1 1 1\r\n"}, {"input": "1 1 1 1\r\nURDLUURRDDLLURDL\r\n", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n"}, {"input": "15 17 8 9\r\nURRDLUULLDD\r\n", "output": "1 1 1 1 1 1 0 1 1 1 1 245\r\n"}, {"inp...
false
stdio
null
true
606/B
606
B
Python 3
PRETESTS
3
31
0
14720442
x, y, x0, y0 = map(int, input().split()) res = x * y - 1 our = dict() our['U'] = (-1, 0) our['D'] = (1, 0) our['R'] = (0, 1) our['L'] = (0, -1) s = input() print(1, end=' ') for i in range(len(s) - 1): dx, dy = our[s[i]] if 1 <= x0 + dx <= x and 1 <= y0 + dy <= y: x0 += dx y0 += dy print...
68
171
2,355,200
14729604
x, y, x0, y0 = map(int, input().split()) s = input() s = s[:len(s) - 1] visited = [[False for i in range(y + 1)] for j in range(x + 1)] visited[x0][y0] = True ans = '1 ' cnt = 1 for i in s: if i == 'U': if x0 != 1: x0 -= 1 if not visited[x0][y0]: ans += '1 ' ...
Codeforces Round 335 (Div. 2)
CF
2,015
2
256
Testing Robots
The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be i...
The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should b...
Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up.
null
In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: $$(2,2)\rightarrow(1,2)\rightarrow(1,3)\rightarrow(2,4)\rightarrow(3,3)$$.
[{"input": "3 4 2 2\nUURDRDRL", "output": "1 1 0 1 1 1 1 0 6"}, {"input": "2 2 2 2\nULD", "output": "1 1 1 1"}]
1,600
["implementation"]
68
[{"input": "3 4 2 2\r\nUURDRDRL\r\n", "output": "1 1 0 1 1 1 1 0 6\r\n"}, {"input": "2 2 2 2\r\nULD\r\n", "output": "1 1 1 1\r\n"}, {"input": "1 1 1 1\r\nURDLUURRDDLLURDL\r\n", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n"}, {"input": "15 17 8 9\r\nURRDLUULLDD\r\n", "output": "1 1 1 1 1 1 0 1 1 1 1 245\r\n"}, {"inp...
false
stdio
null
true
606/B
606
B
Python 3
PRETESTS
4
61
0
14730255
y, x, x_, y_ = list(map(int, input().split())) c = input() ans = [0 for i in range(len(c) + 1)] ans[0] = 1 p = 1 was_here = set() was_here.add((x_, y_)) for i in c: if i == 'U': y_ = max(1, y_ - 1) elif i == 'D': y_ = min(y, y_ + 1) elif i == 'L': x_ = max(1, x_ - 1) else: ...
68
186
10,752,000
162511090
[r, c, x, y], s = map(int, input().split()), input() vis = [[False for i in range(c)] for j in range(r)] x, y = x - 1, y - 1 vis[x][y] = True ans = [1] for ch in s: if ch == 'U': x = max(0, x - 1) elif ch == 'R': y = min(c - 1, y + 1) elif ch == 'D': x = min(r - 1, x + 1) else: y = max(0, y - 1)...
Codeforces Round 335 (Div. 2)
CF
2,015
2
256
Testing Robots
The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be i...
The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should b...
Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up.
null
In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: $$(2,2)\rightarrow(1,2)\rightarrow(1,3)\rightarrow(2,4)\rightarrow(3,3)$$.
[{"input": "3 4 2 2\nUURDRDRL", "output": "1 1 0 1 1 1 1 0 6"}, {"input": "2 2 2 2\nULD", "output": "1 1 1 1"}]
1,600
["implementation"]
68
[{"input": "3 4 2 2\r\nUURDRDRL\r\n", "output": "1 1 0 1 1 1 1 0 6\r\n"}, {"input": "2 2 2 2\r\nULD\r\n", "output": "1 1 1 1\r\n"}, {"input": "1 1 1 1\r\nURDLUURRDDLLURDL\r\n", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n"}, {"input": "15 17 8 9\r\nURRDLUULLDD\r\n", "output": "1 1 1 1 1 1 0 1 1 1 1 245\r\n"}, {"inp...
false
stdio
null
true
18/D
18
D
PyPy 3-64
TESTS
24
280
6,144,000
150917218
n=int(input()) DP=[-10]*2001 DP[0]=0 for i in range(n): s,x=input().split() x=int(x) if s[0]=="w": if DP[x]<DP[0]: DP[x]=DP[0] else: if DP[x]>=0: DP[0]=max(DP[0],DP[x]+(1<<x)) print(max(DP))
45
154
4,915,200
219090777
''' BeezMinh 16:43 UTC+7 16/08/2023 ''' from sys import stdin input = lambda: stdin.readline().rstrip() a = [0] * 2048 ans = 0 for i in range(int(input())): s, x = input().split() if s == 'win': a[int(x)] = ans + 2 ** int(x) else: ans = max(ans, a[int(x)]) print(ans)
Codeforces Beta Round 18 (Div. 2 Only)
ICPC
2,010
2
128
Seller Bob
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. - Bob won some programming competition and got a 2x MB memory stick ...
The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Li...
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
null
null
[{"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "output": "1056"}, {"input": "3\nwin 5\nsell 6\nsell 4", "output": "0"}]
2,000
["brute force", "dp", "greedy"]
45
[{"input": "7\r\nwin 10\r\nwin 5\r\nwin 3\r\nsell 5\r\nsell 3\r\nwin 10\r\nsell 10\r\n", "output": "1056\r\n"}, {"input": "3\r\nwin 5\r\nsell 6\r\nsell 4\r\n", "output": "0\r\n"}, {"input": "10\r\nsell 179\r\nwin 1278\r\nsell 1278\r\nwin 179\r\nwin 788\r\nsell 788\r\nwin 1819\r\nwin 1278\r\nsell 1454\r\nsell 1819\r\n",...
false
stdio
null
true
765/D
765
D
Python 3
TESTS
1
93
0
62645047
n = int(input()) f = list(map(int, input().split())) s = set(f) distinct = len(s) first = set(f[:distinct]) if(sorted(f) != f or len(first) != distinct): print(-1) exit() print(distinct) print(*f) print(*list(first))
43
248
29,593,600
126192952
from collections import defaultdict def solve(n, f): d = defaultdict(set) for i,fi in enumerate(f, 1): d[fi].add(i) m = len(d) g = [0]*n h = [0]*m for i,(fi,ys) in enumerate(d.items()): if fi not in ys: return -1, [], [] h[i] = fi for j in ys: ...
Codeforces Round 397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
512
Artsem and Saunders
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem. Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y. Now then, you are given a function f: [...
The first line contains an integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
If there is no answer, print one integer -1. Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m). If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer e...
null
null
[{"input": "3\n1 2 3", "output": "3\n1 2 3\n1 2 3"}, {"input": "3\n2 2 2", "output": "1\n1 1 1\n2"}, {"input": "2\n2 1", "output": "-1"}]
1,700
["constructive algorithms", "dsu", "math"]
43
[{"input": "3\r\n1 2 3\r\n", "output": "3\r\n1 2 3\r\n1 2 3\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "1\r\n1 1 1\r\n2\r\n"}, {"input": "2\r\n2 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n1\r\n1\r\n"}, {"input": "2\r\n2 1\r\n", "output": "-1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1\r\n1...
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 = int(f.readline().strip()) f_list = list(map(int, f.readline().strip().split())) with open(submission_path) as sub_f: lines = [line.strip(...
true
180/E
180
E
Python 3
TESTS
5
92
307,200
205662613
from collections import defaultdict from sys import stdin def max_points(n, m, k, cubes): color_counts = defaultdict(int) max_count = 0 left = 0 total_to_delete = 0 for right in range(n): color = cubes[right] color_counts[color] += 1 total_to_delete += 1 - (cubes[left] == c...
50
310
16,588,800
199566000
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, m, k = map(int, input().split()) a = list(map(int, input().split())) x = [[] for _ in range(m + 1)] for i in range(n): x[a[i]].append(i) ans = 0 for y in x: if not y: continue r = 0 for l in range(len(y)): ...
Codeforces Round 116 (Div. 2, ACM-ICPC Rules)
ICPC
2,012
1
256
Cubes
Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) an...
The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 105, 0 ≤ k < n). The second line contains n integers from 1 to m — the numbers of cube colors. The numbers of colors are separated by single spaces.
Print the maximum possible number of points you can score.
null
In the first sample you should delete the fifth and the sixth cubes. In the second sample you should delete the fourth and the seventh cubes. In the third sample you shouldn't delete any cubes.
[{"input": "10 3 2\n1 2 1 1 3 2 1 1 2 2", "output": "4"}, {"input": "10 2 2\n1 2 1 2 1 1 2 1 1 2", "output": "5"}, {"input": "3 1 2\n1 1 1", "output": "3"}]
1,800
["binary search", "dp", "two pointers"]
50
[{"input": "10 3 2\r\n1 2 1 1 3 2 1 1 2 2\r\n", "output": "4\r\n"}, {"input": "10 2 2\r\n1 2 1 2 1 1 2 1 1 2\r\n", "output": "5\r\n"}, {"input": "3 1 2\r\n1 1 1\r\n", "output": "3\r\n"}, {"input": "10 2 2\r\n1 1 1 2 1 2 1 2 1 1\r\n", "output": "5\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "1\r\n"}, {"input": "20 3 5\...
false
stdio
null
true
18/D
18
D
PyPy 3-64
TESTS
24
280
5,222,400
208301258
from collections import defaultdict n = int(input()) dp = defaultdict(int) dp[0] = 0 # mx = 0 for _ in range(n): cmd, x = input().split() x = int(x) if cmd == 'win': dp[x] = dp[0] elif x in dp: dp[0] = max(dp[0], dp[x] + 2 ** x) print(dp[0])
45
154
5,529,600
28627387
R= lambda: map(int,input().split()) n,=R() ans=0 l= [0 for _ in range(2002)] for i in range(n): s=input().split() b=int(s[1]) if s[0]=='win': l[b]=ans+2**b else: ans=max(ans,l[b]) print(ans)
Codeforces Beta Round 18 (Div. 2 Only)
ICPC
2,010
2
128
Seller Bob
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. - Bob won some programming competition and got a 2x MB memory stick ...
The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Li...
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
null
null
[{"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "output": "1056"}, {"input": "3\nwin 5\nsell 6\nsell 4", "output": "0"}]
2,000
["brute force", "dp", "greedy"]
45
[{"input": "7\r\nwin 10\r\nwin 5\r\nwin 3\r\nsell 5\r\nsell 3\r\nwin 10\r\nsell 10\r\n", "output": "1056\r\n"}, {"input": "3\r\nwin 5\r\nsell 6\r\nsell 4\r\n", "output": "0\r\n"}, {"input": "10\r\nsell 179\r\nwin 1278\r\nsell 1278\r\nwin 179\r\nwin 788\r\nsell 788\r\nwin 1819\r\nwin 1278\r\nsell 1454\r\nsell 1819\r\n",...
false
stdio
null
true
18/D
18
D
Python 3
TESTS
24
248
409,600
51790433
N = int(input()) winsell = (N)*[0] pow = (2001)*[-1]; ans = int(0) for i in range(0,N): S, x = input().split() x = int(x) if S == "win": winsell[i] = x else: pow[x] = i; winsell[i] = -x for i in range(2000,-1,-1): if pow[i]!=-1: b = bool(0) for j in range(pow[...
45
154
7,270,400
125293934
import sys readline = sys.stdin.readline N = int(readline()) DP = [0] * (N+1) MAX = 2100 last_t = [0] * MAX for i in range(1, N + 1): DP[i] = DP[i-1] a, b = readline().split() b = int(b) if(a == "win"): DP[i] = DP[i-1] last_t[b] = i else: if last_t[b] == 0: con...
Codeforces Beta Round 18 (Div. 2 Only)
ICPC
2,010
2
128
Seller Bob
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. - Bob won some programming competition and got a 2x MB memory stick ...
The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Li...
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
null
null
[{"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "output": "1056"}, {"input": "3\nwin 5\nsell 6\nsell 4", "output": "0"}]
2,000
["brute force", "dp", "greedy"]
45
[{"input": "7\r\nwin 10\r\nwin 5\r\nwin 3\r\nsell 5\r\nsell 3\r\nwin 10\r\nsell 10\r\n", "output": "1056\r\n"}, {"input": "3\r\nwin 5\r\nsell 6\r\nsell 4\r\n", "output": "0\r\n"}, {"input": "10\r\nsell 179\r\nwin 1278\r\nsell 1278\r\nwin 179\r\nwin 788\r\nsell 788\r\nwin 1819\r\nwin 1278\r\nsell 1454\r\nsell 1819\r\n",...
false
stdio
null
true
18/D
18
D
Python 3
TESTS
24
248
409,600
73944672
import math n = int(input()) Size = 2001 dp = [0] * (Size) for i in range(0, Size, 1) : dp[i] = -1 for i in range (1 , n+1 , 1): s = input() In = s.split() x = int(In[1]) if In[0] == "win" : dp[x] = max(0, dp[0]) if In[0] == "sell" : if dp[x] != -1 : dp[0] = max...
45
154
7,270,400
129517975
n = int(input()) have = [ -1 for i in range(0, 2005) ] dp = [ 0 for i in range(0, n+5) ] s, t = input().split() t = int(t) if(s == 'win'): have[t] = 0 for i in range(1, n): s, t = input().split() t = int(t) if(s == 'win'): have[t] = i dp[i] = dp[i-1] elif have[t] == -1: ...
Codeforces Beta Round 18 (Div. 2 Only)
ICPC
2,010
2
128
Seller Bob
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. - Bob won some programming competition and got a 2x MB memory stick ...
The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Li...
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
null
null
[{"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "output": "1056"}, {"input": "3\nwin 5\nsell 6\nsell 4", "output": "0"}]
2,000
["brute force", "dp", "greedy"]
45
[{"input": "7\r\nwin 10\r\nwin 5\r\nwin 3\r\nsell 5\r\nsell 3\r\nwin 10\r\nsell 10\r\n", "output": "1056\r\n"}, {"input": "3\r\nwin 5\r\nsell 6\r\nsell 4\r\n", "output": "0\r\n"}, {"input": "10\r\nsell 179\r\nwin 1278\r\nsell 1278\r\nwin 179\r\nwin 788\r\nsell 788\r\nwin 1819\r\nwin 1278\r\nsell 1454\r\nsell 1819\r\n",...
false
stdio
null
true
18/D
18
D
PyPy 3-64
TESTS
22
280
5,836,800
205942811
N,X=5000,2000 lows,upps,viss=[-1]*X,[-1]*X,[0]*N n=int(input()) for i in range(n): t,x=input().split() x=int(x)-1 if t=="win" and upps[x]==-1:lows[x]=i if t=="sell":upps[x]=i ress=[] for i in range(X)[::-1]: l,r=lows[i],upps[i] if l==-1 or r==-1 or l>r:continue vis=0 for j in range(l,r+1):vis|=viss[j] ...
45
154
7,680,000
127262195
# -*- coding: utf-8 -*- """ Created on Sat Aug 28 08:49:22 2021 @author: Hermes """ n = int(input()) m = [0]*2001 earnings = 0 for i in range(n): e = input() if 'win' in e: x = int(e[4:]) if x > 0: m[x] = earnings + (2<<x-1) else: m[x] = earnings + 1 else: ...
Codeforces Beta Round 18 (Div. 2 Only)
ICPC
2,010
2
128
Seller Bob
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. - Bob won some programming competition and got a 2x MB memory stick ...
The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Li...
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
null
null
[{"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "output": "1056"}, {"input": "3\nwin 5\nsell 6\nsell 4", "output": "0"}]
2,000
["brute force", "dp", "greedy"]
45
[{"input": "7\r\nwin 10\r\nwin 5\r\nwin 3\r\nsell 5\r\nsell 3\r\nwin 10\r\nsell 10\r\n", "output": "1056\r\n"}, {"input": "3\r\nwin 5\r\nsell 6\r\nsell 4\r\n", "output": "0\r\n"}, {"input": "10\r\nsell 179\r\nwin 1278\r\nsell 1278\r\nwin 179\r\nwin 788\r\nsell 788\r\nwin 1819\r\nwin 1278\r\nsell 1454\r\nsell 1819\r\n",...
false
stdio
null
true
18/D
18
D
Python 3
TESTS
22
156
5,120,000
25694477
n = int(input()) mx = 2009 d = [0 for i in range(mx)] for i in range(1,n + 1): s = input().split() x = int(s[1]) s = s[0] if s == 'win': d[x] =d[0]+ 2**x else: d[0] = max(d[x], d[0]) print(d[0])
45
156
307,200
4977843
a = [-1] * 2002 a[0] = 0 for i in range(int(input())): s, t= input().split() t = int(t) + 1 #t = int(input()) if(s[0] == 'w'): a[t] = a[0] elif a[t] >= 0: a[0] = max(a[0], a[t] + (1<<(t-1))) print(a[0])
Codeforces Beta Round 18 (Div. 2 Only)
ICPC
2,010
2
128
Seller Bob
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. - Bob won some programming competition and got a 2x MB memory stick ...
The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Li...
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
null
null
[{"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "output": "1056"}, {"input": "3\nwin 5\nsell 6\nsell 4", "output": "0"}]
2,000
["brute force", "dp", "greedy"]
45
[{"input": "7\r\nwin 10\r\nwin 5\r\nwin 3\r\nsell 5\r\nsell 3\r\nwin 10\r\nsell 10\r\n", "output": "1056\r\n"}, {"input": "3\r\nwin 5\r\nsell 6\r\nsell 4\r\n", "output": "0\r\n"}, {"input": "10\r\nsell 179\r\nwin 1278\r\nsell 1278\r\nwin 179\r\nwin 788\r\nsell 788\r\nwin 1819\r\nwin 1278\r\nsell 1454\r\nsell 1819\r\n",...
false
stdio
null
true
606/B
606
B
PyPy 3
TESTS
3
109
23,040,000
19664116
x, y, x0, y0=list(map(int, input().split())) s=input() c=1 print(1, end=' ') for i in range(len(s)-1): if s[i] =='L': if y0>=2: y0-=1; print(1, end=' '); c+=1 else: print(0, end=' ') if s[i] =='R': if y0<y: y0+=1; print(1, end=' '); c+=1 else: print(0, end=' ') if s[i] =='U': if x0>=2: x0-=1; print(1, end=...
68
187
5,939,200
14738900
x, y, x0, y0 = map(int, input().split(' ')) g = [[0]* (y+1) for i in range(x + 1)] s = input() result = [0] * len(s) count = x*y for i in range(len(s)): if g[x0][y0] == 0: g[x0][y0] = 1 result[i] = 1 count -= 1 if s[i] == 'U' and x0 > 1: x0 -=1 if s[i] == 'D' and x0 < x: x0 += 1 if s[i] == 'L' and y0 > 1:...
Codeforces Round 335 (Div. 2)
CF
2,015
2
256
Testing Robots
The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be i...
The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should b...
Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up.
null
In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: $$(2,2)\rightarrow(1,2)\rightarrow(1,3)\rightarrow(2,4)\rightarrow(3,3)$$.
[{"input": "3 4 2 2\nUURDRDRL", "output": "1 1 0 1 1 1 1 0 6"}, {"input": "2 2 2 2\nULD", "output": "1 1 1 1"}]
1,600
["implementation"]
68
[{"input": "3 4 2 2\r\nUURDRDRL\r\n", "output": "1 1 0 1 1 1 1 0 6\r\n"}, {"input": "2 2 2 2\r\nULD\r\n", "output": "1 1 1 1\r\n"}, {"input": "1 1 1 1\r\nURDLUURRDDLLURDL\r\n", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n"}, {"input": "15 17 8 9\r\nURRDLUULLDD\r\n", "output": "1 1 1 1 1 1 0 1 1 1 1 245\r\n"}, {"inp...
false
stdio
null
true
180/E
180
E
PyPy 3
TESTS
5
280
0
67479780
n, m, k = map(int, input().split()) L = list(map(int, input().split())) cnt = [0] * (m+1) dp = [1] * n bg = 0 for idx in range(len(L)): cnt[L[idx]] += 1 dp[bg] = cnt[L[bg]] if len(L[0:idx + 1]) - cnt[L[bg]] > k: dp[bg] = cnt[L[bg]] cnt[L[bg]] -= 1 bg += 1 print(max(dp))
50
498
17,305,600
51319385
R = lambda: map(int, input().split()) n, m, k = R() arr = list(R()) arrs = [list() for i in range(m)] for i, x in enumerate(arr): arrs[x - 1].append(i) res = 1 for ar in arrs: l = -1 for r in range(len(ar)): while r - l + k < ar[r] - ar[l + 1] + 1: l += 1 res = max(res, r - l) pr...
Codeforces Round 116 (Div. 2, ACM-ICPC Rules)
ICPC
2,012
1
256
Cubes
Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) an...
The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 105, 0 ≤ k < n). The second line contains n integers from 1 to m — the numbers of cube colors. The numbers of colors are separated by single spaces.
Print the maximum possible number of points you can score.
null
In the first sample you should delete the fifth and the sixth cubes. In the second sample you should delete the fourth and the seventh cubes. In the third sample you shouldn't delete any cubes.
[{"input": "10 3 2\n1 2 1 1 3 2 1 1 2 2", "output": "4"}, {"input": "10 2 2\n1 2 1 2 1 1 2 1 1 2", "output": "5"}, {"input": "3 1 2\n1 1 1", "output": "3"}]
1,800
["binary search", "dp", "two pointers"]
50
[{"input": "10 3 2\r\n1 2 1 1 3 2 1 1 2 2\r\n", "output": "4\r\n"}, {"input": "10 2 2\r\n1 2 1 2 1 1 2 1 1 2\r\n", "output": "5\r\n"}, {"input": "3 1 2\r\n1 1 1\r\n", "output": "3\r\n"}, {"input": "10 2 2\r\n1 1 1 2 1 2 1 2 1 1\r\n", "output": "5\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "1\r\n"}, {"input": "20 3 5\...
false
stdio
null
true
394/C
394
C
Python 3
TESTS
6
62
0
7112420
__author__ = 'epeshk' n, m = list(map(int,input().split())) _00 = 0 _01 = 0 _11 = 0 for i in range (n): c=list(map(str,input().split())) for j in c: if j == '00': _00+=1 if j == '01' or j=='10': _01+=1 if j == '11': _11+=1 C = [['' for i in range (m)] for j in range(n)] for i in range(n...
27
358
614,400
14807872
n, m = map(int, input().split()) doubles, singles = 0, 0 for r in range(n): for s in input().split(): if s == '11': doubles += 1 elif s != '00': singles += 1 lines = { 'zero': ' '.join(m * [ '00' ]), 'double': ' '.join(m * [ '11' ]), 'single_0': ' '.join(m * [ '01...
Codeforces Round 231 (Div. 2)
CF
2,014
2
256
Dominoes
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes. The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half...
The first line contains integers n, m (1 ≤ n, m ≤ 103). In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes. If there are multiple optimal solutions, print any of them.
null
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal. Note that the dominoes can be rotated by 180 degrees.
[{"input": "2 3\n01 11 00\n00 01 11", "output": "11 11 10\n00 00 01"}, {"input": "4 1\n11\n10\n01\n00", "output": "11\n10\n01\n00"}]
null
["constructive algorithms", "greedy"]
27
[{"input": "2 3\r\n01 11 00\r\n00 01 11\r\n", "output": "11 11 10\r\n00 00 01\r\n"}, {"input": "4 1\r\n11\r\n10\r\n01\r\n00\r\n", "output": "11\r\n10\r\n01\r\n00\r\n"}, {"input": "1 1\r\n00\r\n", "output": "00\r\n"}, {"input": "1 1\r\n01\r\n", "output": "10\r\n"}, {"input": "1 1\r\n11\r\n", "output": "11\r\n"}, {"input...
false
stdio
import sys from collections import Counter def read_dominoes(file, n, m): dominoes = [] grid = [] for _ in range(n): line = file.readline().strip() if not line: return [], [] row_dominoes = line.split() grid_row = [] for d in row_dominoes: a, ...
true
724/D
724
D
PyPy 3
TESTS
68
233
29,286,400
128085648
def process(S, m): d = {} for c in S: if c not in d: d[c] = 0 d[c]+=1 L = [] for c in d: L.append([c, d[c], 0]) L = sorted(L) n = len(S) m2 = len(L) index = 0 curr = set([]) d2 = {} for i in range(m): c = S[i] if c not in d2...
71
171
614,400
104240605
m = int(input()) s = input() d = [0 for _ in range(26)] for char in s: d[ord(char) - ord('a')] += 1 for i in range(26): char, left, right, counter = chr(ord('a') + i), -1, -1, 0 for j in range(len(s)): if s[j] < char: left = j if s[j] == char: right = j if j -...
Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
CF
2,016
2
256
Dense Subsequence
You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves. Then one uses the chosen...
The first line of the input contains a single integer m (1 ≤ m ≤ 100 000). The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string...
Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.
null
In the first sample, one can choose the subsequence {3} and form a string "a". In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab".
[{"input": "3\ncbabc", "output": "a"}, {"input": "2\nabcab", "output": "aab"}, {"input": "3\nbcabcbaccba", "output": "aaabb"}]
1,900
["data structures", "greedy", "strings"]
71
[{"input": "3\r\ncbabc\r\n", "output": "a\r\n"}, {"input": "2\r\nabcab\r\n", "output": "aab\r\n"}, {"input": "3\r\nbcabcbaccba\r\n", "output": "aaabb\r\n"}, {"input": "5\r\nimmaydobun\r\n", "output": "ab\r\n"}, {"input": "5\r\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouvwgjzpsuxyxvhavgezwtuzk...
false
stdio
null
true
400/B
400
B
Python 3
TESTS
5
93
102,400
220150190
n,m=map(int,input().split()) po=0 flag=False c=0 ok=0 no=0 v=[] for j in range(n): b=input() for p in range(m): if b[p]=="G": ok=p elif b[p]=="S": no=p if no-ok <= 0: break else: v+=[no-ok] if len(set(v))==0: pr...
34
31
204,800
210339817
n,m=map(int,input().split()) st=set() for i in range(n): s1=input() g=s1.index("G") s=s1.index("S") if s<g: print(-1) exit(0) st.add(abs(s-g)) print(len(st))
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
177/C1
177
C1
PyPy 3-64
TESTS1
3
122
0
175831673
import sys input = sys.stdin.readline from collections import Counter n = int(input()) k = int(input()) d = [[] for i in range(n)] for i in range(k): a, b = map(lambda x:int(x)-1, input().split()) d[a].append(b) d[b].append(a) x = [-1]*n c = 0 for i in range(n): if x[i] == -1: q = [i] w...
17
218
307,200
65333942
def find(a): if parent[a]!=a: parent[a]=find(parent[a]) return parent[a] def union(a,b): u,v=find(a),find(b) if u==v: return if rank[u]>rank[v]: parent[v]=u else: parent[u]=v if rank[u]==rank[v]: rank[v]+=1 n=int(input()) k=int(input()) parent=list(...
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Party
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friends...
The first line of input contains an integer n — the number of the Beaver's acquaintances. The second line contains an integer k $$( 0 \leq k \leq \min ( 1 0 ^ { 5 }, \frac { n \cdot ( n - 1 ) } { 2 } ) )$$ — the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi $$( 1 \leq u _ { ...
Output a single number — the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0.
null
Let's have a look at the example. Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members a...
[{"input": "9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9", "output": "3"}]
1,500
["dfs and similar", "dsu", "graphs"]
17
[{"input": "9\r\n8\r\n1 2\r\n1 3\r\n2 3\r\n4 5\r\n6 7\r\n7 8\r\n8 9\r\n9 6\r\n2\r\n1 6\r\n7 9\r\n", "output": "3"}, {"input": "2\r\n1\r\n1 2\r\n0\r\n", "output": "2"}, {"input": "2\r\n0\r\n1\r\n1 2\r\n", "output": "1"}, {"input": "3\r\n2\r\n1 2\r\n1 3\r\n1\r\n2 3\r\n", "output": "0"}, {"input": "3\r\n3\r\n1 3\r\n2 1\r\...
false
stdio
null
true
400/B
400
B
Python 3
TESTS
5
77
0
104638980
n,m = map(int, input().split(" ")) a = set() tag = True for i in range(n): x = input() indexG = x.index("G") indexS = x.index("S") if indexS< indexG: print(-1) tag = False else: a.add(indexS - indexG) if tag: print(len(a)) else: pass
34
31
204,800
219440089
n,m=map(int,input().split()) a=set() ans=1 for _ in range(n): x=input() if x.find('S')-x.find('G')<0: ans=0 break else: temp=x.find('S')-x.find('G') a.add(temp) if ans: print(len(a)) else: print(-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
5
62
6,758,400
125743989
n,m=map(int,input().split()) field=[] for i in range(0,n): row=input() space=row.index('S')-row.index('G') #print(space) if space>0: field.append(space) if(len(field)>0): print(len(set(field))) else: print(-1)
34
46
0
146095711
def dist(s): return s.find("S") - s.find("G") - 1 a, b = map(int, input().split()) dists = [dist(input()) for i in range(a)] if min(dists) < 0: print(-1) else: print(len(set(dists)))
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
PyPy 3-64
TESTS
5
46
0
189680511
n,m=map(int,input("").split(" ")) ll=[] for i in range(n): l=list(input("")) out=l.index('S')-l.index('G') if out<0: print(-1) break; ll.append(out) lout=list(dict.fromkeys(ll)) if len(lout)>0: print(len(lout))
34
46
0
185635853
n, m = map(int, input().split()) st = set() for _ in range(n): line = input() g = line.index('G') s = line.index('S') if s - g < 0: print(-1) break st.add(s-g) else: print(len(st))
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
408/B
408
B
Python 3
TESTS
4
31
0
208354177
a = input() b =input() ref = set([i for i in a ]) count =0 for i in ref : count += min(a.count(i) , b.count(i)) if count ==0 : print(-1) else: print(count)
21
46
0
119587484
from sys import * input = lambda:stdin.readline() int_arr = lambda : list(map(int,stdin.readline().strip().split())) str_arr = lambda :list(map(str,stdin.readline().split())) get_str = lambda : map(str,stdin.readline().strip().split()) get_int = lambda: map(int,stdin.readline().strip().split()) get_float = lambda : ma...
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Garland
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece s...
The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000) small English letters that correspond to the colors of the pieces of paper ...
Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.
null
In the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color a and cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot make a ga...
[{"input": "aaabbac\naabbccac", "output": "6"}, {"input": "a\nz", "output": "-1"}]
1,200
["implementation"]
21
[{"input": "aaabbac\r\naabbccac\r\n", "output": "6\r\n"}, {"input": "a\r\nz\r\n", "output": "-1"}, {"input": "r\r\nr\r\n", "output": "1\r\n"}, {"input": "stnsdn\r\nndnndsn\r\n", "output": "4\r\n"}, {"input": "yqfqfp\r\ntttwtqq\r\n", "output": "-1"}, {"input": "zzbbrrtrtzr\r\ntbbtrrrzr\r\n", "output": "9\r\n"}, {"input"...
false
stdio
null
true
408/B
408
B
Python 3
TESTS
7
62
5,529,600
26480968
n = input() m = input() resources = len(n) area = 0 for i in range(len(m)): n = n.replace(m[i], "", 1) if len(n) == resources or resources - len(n) < len(set(n)): print("-1") else: print(resources - len(n))
21
46
0
142608376
s = input() t = input() c = 0 s_c = [0 for i in range(26)] t_c = [0 for i in range(26)] for i in range(len(s)): s_c[ord(s[i])-ord('a')] += 1 for i in range(len(t)): t_c[ord(t[i])-ord('a')] += 1 for i in range(26): if(s_c[i] == 0 and t_c[i] != 0): c = 0 break else: c += min(s_c[i],t_c[i]) if(c==0): print...
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Garland
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece s...
The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000) small English letters that correspond to the colors of the pieces of paper ...
Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.
null
In the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color a and cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot make a ga...
[{"input": "aaabbac\naabbccac", "output": "6"}, {"input": "a\nz", "output": "-1"}]
1,200
["implementation"]
21
[{"input": "aaabbac\r\naabbccac\r\n", "output": "6\r\n"}, {"input": "a\r\nz\r\n", "output": "-1"}, {"input": "r\r\nr\r\n", "output": "1\r\n"}, {"input": "stnsdn\r\nndnndsn\r\n", "output": "4\r\n"}, {"input": "yqfqfp\r\ntttwtqq\r\n", "output": "-1"}, {"input": "zzbbrrtrtzr\r\ntbbtrrrzr\r\n", "output": "9\r\n"}, {"input"...
false
stdio
null
true
756/E
756
E
Python 3
TESTS
3
46
4,608,000
24216588
#!/usr/bin/env python3 MOD = 1000000007 N = int(input()) a = [int(x) for x in input().split()] + [1] b = [int(x) for x in input().split()] M = int(input()) r = [] for i in range(N - 1): r.append(M % a[i]) M /= a[i] r += [M] dp = [1] for i in range(N - 1, -1, -1): scale = a[i] dp2 = [0] * 50 for k ...
40
763
44,236,800
24049216
p = 1000000007 n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) m = int(input()) d = [1] * 300001 td = [0] * 300001 L = b[0] for i in range(1, n): if a[i - 1] != 1: t = m % a[i - 1] if L < t: print(0) exit(0) m //= a[i - 1] for j in range((L - t) // a[i - 1] + 1)...
8VC Venture Cup 2017 - Final Round
CF
2,017
1
512
Byteland coins
There are n types of coins in Byteland. Conveniently, the denomination of the coin type k divides the denomination of the coin type k + 1, the denomination of the coin type 1 equals 1 tugrick. The ratio of the denominations of coin types k + 1 and k equals ak. It is known that for each x there are at most 20 coin types...
The first line contains single integer n (1 ≤ n ≤ 3·105) — the number of coin types. The second line contains n - 1 integers a1, a2, ..., an - 1 (1 ≤ ak ≤ 109) — the ratios between the coin types denominations. It is guaranteed that for each x there are at most 20 coin types of denomination x. The third line contains...
Print single integer — the number of ways to pay exactly m tugricks modulo 109 + 7.
null
In the first example Byteasar has 4 coins of denomination 1, and he has to pay 2 tugricks. There is only one way. In the second example Byteasar has 4 coins of each of two different types of denomination 1, he has to pay 2 tugricks. There are 3 ways: pay one coin of the first type and one coin of the other, pay two co...
[{"input": "1\n4\n2", "output": "1"}, {"input": "2\n1\n4 4\n2", "output": "3"}, {"input": "3\n3 3\n10 10 10\n17", "output": "6"}]
3,200
["combinatorics", "dp", "math"]
40
[{"input": "1\r\n\r\n4\r\n2\r\n", "output": "1\r\n"}, {"input": "2\r\n1\r\n4 4\r\n2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 3\r\n10 10 10\r\n17\r\n", "output": "6\r\n"}, {"input": "2\r\n2\r\n200000 100000\r\n34567\r\n", "output": "17284\r\n"}, {"input": "20\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n1 1 1 1 1 1 1 ...
false
stdio
null
true
177/C1
177
C1
PyPy 3-64
TESTS1
3
124
0
225903288
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): s = input() return list(s[: len(s) - 1]) def invr(): return map(int, input().split()) def find(x): if...
17
218
307,200
74705608
# maa chudaaye duniya n = int(input()) parents = [i for i in range(n+1)] ranks = [1 for i in range(n+1)] def find(x): if parents[x] != x: parents[x] = find(parents[x]) return parents[x] def union(x, y): xs = find(x) ys = find(y) if xs == ys: return if ranks[xs] > ranks[ys]: parents[ys] = xs elif ranks[ys...
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Party
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friends...
The first line of input contains an integer n — the number of the Beaver's acquaintances. The second line contains an integer k $$( 0 \leq k \leq \min ( 1 0 ^ { 5 }, \frac { n \cdot ( n - 1 ) } { 2 } ) )$$ — the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi $$( 1 \leq u _ { ...
Output a single number — the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0.
null
Let's have a look at the example. Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members a...
[{"input": "9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9", "output": "3"}]
1,500
["dfs and similar", "dsu", "graphs"]
17
[{"input": "9\r\n8\r\n1 2\r\n1 3\r\n2 3\r\n4 5\r\n6 7\r\n7 8\r\n8 9\r\n9 6\r\n2\r\n1 6\r\n7 9\r\n", "output": "3"}, {"input": "2\r\n1\r\n1 2\r\n0\r\n", "output": "2"}, {"input": "2\r\n0\r\n1\r\n1 2\r\n", "output": "1"}, {"input": "3\r\n2\r\n1 2\r\n1 3\r\n1\r\n2 3\r\n", "output": "0"}, {"input": "3\r\n3\r\n1 3\r\n2 1\r\...
false
stdio
null
true
408/A
408
A
PyPy 3-64
TESTS
16
62
1,638,400
196299412
n = int(input()) ans = int(5e4) *k, = map(int, input().split()) for i in range(n): *m, = map(int, input().split()) ans = min(ans, sum(m) * 5 + k[i] * 15) print(ans)
20
31
0
143984023
n=int(input()) k=list(map(int,input().split())) for i in range(n): a=list(map(int,input().split())) val=sum(a)*5+k[i]*15 if(i==0): m=val else: if(m>val): m=val print(m)
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Line to Cashier
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has ki p...
The first line contains integer n (1 ≤ n ≤ 100) — the number of cashes in the shop. The second line contains n space-separated integers: k1, k2, ..., kn (1 ≤ ki ≤ 100), where ki is the number of people in the queue to the i-th cashier. The i-th of the next n lines contains ki space-separated integers: mi, 1, mi, 2, .....
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
null
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
[{"input": "1\n1\n1", "output": "20"}, {"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100"}]
900
["implementation"]
20
[{"input": "1\r\n1\r\n1\r\n", "output": "20\r\n"}, {"input": "4\r\n1 4 3 2\r\n100\r\n1 2 2 3\r\n1 9 1\r\n7 8\r\n", "output": "100\r\n"}, {"input": "4\r\n5 4 5 5\r\n3 1 3 1 2\r\n3 1 1 3\r\n1 1 1 2 2\r\n2 2 1 1 3\r\n", "output": "100\r\n"}, {"input": "5\r\n5 3 6 6 4\r\n7 5 3 3 9\r\n6 8 2\r\n1 10 8 5 9 2\r\n9 7 8 5 9 10\r...
false
stdio
null
true
408/B
408
B
Python 3
TESTS
4
31
0
158936970
a = input() b = input() o = {chr(x): 0 for x in range(97, 123)} e = {chr(x): 0 for x in range(97, 123)} for item in a: o[item] += 1 for item in b: e[item] += 1 new = 0 for key, value in o.items(): new += min(value, e[key]) if new == 0:print(-1) else:print(new)
21
46
0
165679408
n = input() m = input() s = set(m) c= 0 for i in s: a1 = n.count(i) a2 = m.count(i) if a1 == 0: c = -1 break else: c+=min(a1,a2) print(c)
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Garland
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece s...
The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000) small English letters that correspond to the colors of the pieces of paper ...
Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.
null
In the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color a and cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot make a ga...
[{"input": "aaabbac\naabbccac", "output": "6"}, {"input": "a\nz", "output": "-1"}]
1,200
["implementation"]
21
[{"input": "aaabbac\r\naabbccac\r\n", "output": "6\r\n"}, {"input": "a\r\nz\r\n", "output": "-1"}, {"input": "r\r\nr\r\n", "output": "1\r\n"}, {"input": "stnsdn\r\nndnndsn\r\n", "output": "4\r\n"}, {"input": "yqfqfp\r\ntttwtqq\r\n", "output": "-1"}, {"input": "zzbbrrtrtzr\r\ntbbtrrrzr\r\n", "output": "9\r\n"}, {"input"...
false
stdio
null
true
408/B
408
B
Python 3
TESTS
4
31
0
161124165
import sys input = sys.stdin.readline from collections import defaultdict s = input()[:-1] w = input()[:-1] d = defaultdict(int) for i in s: d[i] += 1 c = 0 for i in w: if d[i] > 0: d[i] -= 1 c += 1 if c == 0: print(-1) else: print(c)
21
46
0
166918276
x=input() y=input() d1={} d2={} count=0 for i in x: d1[i]=x.count(i) for i in y: d2[i]=y.count(i) for i in d2.keys(): if i in d1.keys(): if d1[i]<d2[i]: count+=d1[i] else: count+=d2[i] else: count=-1 break print(count)
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Garland
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece s...
The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000) small English letters that correspond to the colors of the pieces of paper ...
Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.
null
In the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color a and cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot make a ga...
[{"input": "aaabbac\naabbccac", "output": "6"}, {"input": "a\nz", "output": "-1"}]
1,200
["implementation"]
21
[{"input": "aaabbac\r\naabbccac\r\n", "output": "6\r\n"}, {"input": "a\r\nz\r\n", "output": "-1"}, {"input": "r\r\nr\r\n", "output": "1\r\n"}, {"input": "stnsdn\r\nndnndsn\r\n", "output": "4\r\n"}, {"input": "yqfqfp\r\ntttwtqq\r\n", "output": "-1"}, {"input": "zzbbrrtrtzr\r\ntbbtrrrzr\r\n", "output": "9\r\n"}, {"input"...
false
stdio
null
true
599/C
599
C
Python 3
TESTS
3
31
0
159296371
n = int(input()) a = [*map(int,input().split())] s = sorted(a) window = [set(),set()] ans = 0 for i in range(n): window[0].add(a[i]); window[1].add(s[i]) if window[0] == window[1]: ans +=1 window[0].clear; window[1].clear print(ans)
39
124
17,817,600
224633886
n=int(input()) h=list(map(int,input().split())) ans,mn,mx=0,[],[] for i in range(n): mn.append(float("inf")) mx.append(float("-inf")) mn[-1],mx[0]=h[-1],h[0] for i in range(n-2,-1,-1): mn[i]=min(h[i],mn[i+1]) for i in range(1,n): mx[i]=max(mx[i-1],h[i]) for i in range(n-1): if mx[i]<=mn[i+1]: ...
Codeforces Round 332 (Div. 2)
CF
2,015
2
256
Day at the Beach
One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles. At the end of the day there were n castles built by friends. Castles are numbered from 1 to n, and the heig...
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of castles Spongebob, Patrick and Squidward made from sand during the day. The next line contains n integers hi (1 ≤ hi ≤ 109). The i-th of these integers corresponds to the height of the i-th castle.
Print the maximum possible number of blocks in a valid partitioning.
null
In the first sample the partitioning looks like that: [1][2][3]. In the second sample the partitioning is: [2, 1][3, 2]
[{"input": "3\n1 2 3", "output": "3"}, {"input": "4\n2 1 3 2", "output": "2"}]
1,600
["sortings"]
39
[{"input": "3\r\n1 2 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 1 3 2\r\n", "output": "2\r\n"}, {"input": "17\r\n1 45 22 39 28 23 23 100 500 778 777 778 1001 1002 1005 1003 1005\r\n", "output": "10\r\n"}, {"input": "101\r\n1 50 170 148 214 153 132 234 181 188 180 225 226 200 197 122 181 168 87 220 223 160 235 94 257...
false
stdio
null
true
408/B
408
B
Python 3
TESTS
4
31
0
156544851
we=input("") need=input("") l=[] n=[] for i in need: x=0 for j in need: if i==j: x=x+1 l.append([i,x]) for i in we: y=0 for j in we: if i==j: y=y+1 n.append([i,y]) fin=[] las=[] for i in n: if i not in fin: fin.append(i)#we for i in l...
21
46
0
173273807
n = input() m = input() nCount = [0]*26 mCount = [0]*26 for c in n: nCount[ord(c)-ord('a')]+=1 for c in m: mCount[ord(c)-ord('a')]+=1 area = 0 for i in range(26): if mCount[i] !=0 and nCount[i]==0: print(-1) exit() area+=min(mCount[i],nCount[i]) print(area)
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Garland
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece s...
The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000) small English letters that correspond to the colors of the pieces of paper ...
Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.
null
In the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color a and cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot make a ga...
[{"input": "aaabbac\naabbccac", "output": "6"}, {"input": "a\nz", "output": "-1"}]
1,200
["implementation"]
21
[{"input": "aaabbac\r\naabbccac\r\n", "output": "6\r\n"}, {"input": "a\r\nz\r\n", "output": "-1"}, {"input": "r\r\nr\r\n", "output": "1\r\n"}, {"input": "stnsdn\r\nndnndsn\r\n", "output": "4\r\n"}, {"input": "yqfqfp\r\ntttwtqq\r\n", "output": "-1"}, {"input": "zzbbrrtrtzr\r\ntbbtrrrzr\r\n", "output": "9\r\n"}, {"input"...
false
stdio
null
true
408/B
408
B
Python 3
TESTS
4
31
0
146593203
a=[j for j in str(input())] b=[i for i in str(input())] c=list(set(b)) ans=0 for k in c: ans+=min(a.count(k),b.count(k)) print(-1) if ans==0 else print(ans)
21
46
0
181379203
have = input() required = input() h_d = dict() r_d = dict() for i in have: h_d[i] = h_d.get(i, 0)+1 for i in required: r_d[i] = r_d.get(i, 0)+1 ans = 0 for i in r_d: if i not in h_d: print(-1) break else: ans += min(r_d[i], h_d[i]) else: print(ans)
Codeforces Round 239 (Div. 2)
CF
2,014
1
256
Garland
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece s...
The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000) small English letters that correspond to the colors of the pieces of paper ...
Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.
null
In the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color a and cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot make a ga...
[{"input": "aaabbac\naabbccac", "output": "6"}, {"input": "a\nz", "output": "-1"}]
1,200
["implementation"]
21
[{"input": "aaabbac\r\naabbccac\r\n", "output": "6\r\n"}, {"input": "a\r\nz\r\n", "output": "-1"}, {"input": "r\r\nr\r\n", "output": "1\r\n"}, {"input": "stnsdn\r\nndnndsn\r\n", "output": "4\r\n"}, {"input": "yqfqfp\r\ntttwtqq\r\n", "output": "-1"}, {"input": "zzbbrrtrtzr\r\ntbbtrrrzr\r\n", "output": "9\r\n"}, {"input"...
false
stdio
null
true
12/C
12
C
Python 3
TESTS
9
31
0
192682492
a,b=map(int,input().split()) d=[] c=[int(i) for i in input().split()] for i in range(b): e=input() if d.count(e)==0: d=d+[e] c.sort() k=b-len(d) print(sum(c[0:len(d)])+k*c[0],sum(c[-len(d):-1])+(k+1)*c[-1])
25
31
0
229903267
n, m = input().split() prices = sorted(list(map(int, input().split()))) fruits_count = {} for i in range(int(m)): fruit = input() fruits_count[fruit] = 1 if fruit not in fruits_count else fruits_count[fruit] + 1 fruits_prices_max = {x: y for x, y in zip(sorted(fruits_count.keys(), key=lambda x: fruits_count[x], rever...
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
755/B
755
B
PyPy 3
TESTS
20
249
5,939,200
91597448
# cook your dish here n, m = map(int, input().split()) Ene = set() Pol = set() for i in range(n): Pol.add(input()) for i in range(m): Ene.add(input()) comm_ele = 0 for num in Pol: if num in Ene: comm_ele += 1 if n>m: print("YES") elif n<m: print("NO") else: if comm_ele == n: pri...
33
46
819,200
138663974
n, m = input().split() n = int(n) m = int(m) words = set() repeated = 0 p = 0 e = 0 for i in range(n): x = input() words.add(x) p += 1 for i in range(m): x = input() if x in words: p -= 1 repeated += 1 else: e += 1 if repeated >= 2: if repeated % 2 == 1: p += repeated//2 + 1 e += repeated//...
8VC Venture Cup 2017 - Elimination Round
CF
2,017
1
256
PolandBall and Game
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i...
The first input line contains two integers n and m (1 ≤ n, m ≤ 103) — number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per line — words familiar to PolandBall. Then m strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a word more than onc...
In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
null
In the first example PolandBall knows much more words and wins effortlessly. In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
[{"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope", "output": "YES"}, {"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "output": "YES"}, {"input": "1 2\na\na\nb", "output": "NO"}]
1,100
["binary search", "data structures", "games", "greedy", "sortings", "strings"]
33
[{"input": "5 1\r\npolandball\r\nis\r\na\r\ncool\r\ncharacter\r\nnope\r\n", "output": "YES"}, {"input": "2 2\r\nkremowka\r\nwadowicka\r\nkremowka\r\nwiedenska\r\n", "output": "YES"}, {"input": "1 2\r\na\r\na\r\nb\r\n", "output": "NO"}, {"input": "2 2\r\na\r\nb\r\nb\r\nc\r\n", "output": "YES"}, {"input": "2 1\r\nc\r\na\...
false
stdio
null
true
175/C
175
C
PyPy 3-64
TESTS
3
92
0
166126786
'''\https://codeforces.com/contest/175/problem/C 输入 n(≤100) 表示 n 种怪物,然后输入 n 行,每行两个数字表示怪物的数量 (≤1e9),和怪物的分数(≤1000)。 然后输入 t(≤100) 和一个长为 t 的数组 p,下标从 1 开始,1≤p[1]<p[2]<...<p[t]≤1e12, 表示在你累计击败 p[i] 个怪物之后,得分系数将变为 i+1(初始得分系数为 1)。 击败一只怪物的得分 = 怪物的分数 * 当前得分系数。 你可以按照任意顺序打怪,输出击败所有怪物后的最大得分。 输入 1 5 10 2 3 6 输出 70 解释 前三只怪物得分系数为 1,后两只怪...
90
218
0
119527083
n=int(input()) a=[list(map(int,input().split()))[::-1] for i in range(n)] t=int(input()) p=list(map(int,input().split())) b=0 i=0 a.sort() c=0 for j in range(n): while i<t and p[i]-b<=a[j][1]: c+=(p[i]-b)*(i+1)*a[j][0] a[j][1]-=p[i]-b b=p[i] i+=1 c+=a[j][1]*(i+1)*a[j][0] b+=a...
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
12/C
12
C
Python 3
TESTS
1
61
307,200
105277235
n,k=map(int,input().split()) a=[int(x) for x in input().split()] a.sort() dic={} for _ in range(k): s=input() if s in dic: dic[s]+=1 else: dic[s]=1 t=0 cnt=0 sorted(dic.items(),reverse=True) for i in dic: cnt+=a[t]*dic[i] t+=1 print(cnt,end=" ") t=n-1 cnt=0 for i in dic: cnt+=a[t...
25
46
0
147141946
n,m=list(map(int,input().split())) p=list(map(int,input().split())) f=[] k=[] for i in range(m): f.append(input()) for i in set(f): k.append(f.count(i)) k.sort(reverse=True) p.sort() h=0 min=0 max=0 for i in k: min+=i*p[h] h+=1 max+=i*p[-h] print(min,max)
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
455/B
455
B
PyPy 3-64
TESTS
4
62
0
214539881
n, k = [int(x) for x in input().split()] l = [] for i in range(n): l.append(len(input())) if min(l) % 2 == 0: print("Second") else: if k % 2 == 0: print("Second") else: print("First")
75
218
26,521,600
230712465
# LUOGU_RID: 132709230 # pypy3 from collections import * from itertools import * from functools import * from bisect import * from heapq import * import sys from math import gcd IN = lambda: sys.stdin.readline().rstrip("\r\n") PN = lambda x: sys.stdout.write(x) I = lambda: int(IN()) S = lambda: IN().split() M = lambd...
Codeforces Round 260 (Div. 1)
CF
2,014
1
256
A Lot of Games
Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players. Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his step player must add a single letter in the end of the word, the re...
The first line contains two integers, n and k (1 ≤ n ≤ 105; 1 ≤ k ≤ 109). Each of the next n lines contains a single non-empty string from the given group. The total length of all strings from the group doesn't exceed 105. Each string of the group consists only of lowercase English letters.
If the player who moves first wins, print "First", otherwise print "Second" (without the quotes).
null
null
[{"input": "2 3\na\nb", "output": "First"}, {"input": "3 1\na\nb\nc", "output": "First"}, {"input": "1 2\nab", "output": "Second"}]
1,900
["dfs and similar", "dp", "games", "implementation", "strings", "trees"]
75
[{"input": "2 3\r\na\r\nb\r\n", "output": "First\r\n"}, {"input": "3 1\r\na\r\nb\r\nc\r\n", "output": "First\r\n"}, {"input": "1 2\r\nab\r\n", "output": "Second\r\n"}, {"input": "5 6\r\nabas\r\ndsfdf\r\nabacaba\r\ndartsidius\r\nkolobok\r\n", "output": "Second\r\n"}, {"input": "4 2\r\naaaa\r\nbbbb\r\nccccc\r\ndumbavumba...
false
stdio
null
true
10/A
10
A
PyPy 3
TESTS
16
280
0
84325696
n,p1,p2,p3,t1,t2 = map(int,input().split()) a=0 b=0 for c in range(n): l,r = map(int,input().split()) if(c==0): b+=(r-l)*p1 a=r else: diff = l-a if(diff > 0): if(diff <= t1): b+= diff*p1 else: if(diff < t1+t2 and diff >...
30
62
0
186159465
def main(): n, p1, p2, p3, t1, t2 = [int(_) for _ in input().split()] minutes = [0, 0, 0] r_prev = 0 for _ in range(n): l, r = [int(_) for _ in input().split()] minutes[0] += r - l if r_prev: rest = l - r_prev if rest <= t1: minutes[0] += ...
Codeforces Beta Round 10
ICPC
2,010
1
256
Power Consumption Calculation
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minut...
The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start a...
Output the answer to the problem.
null
null
[{"input": "1 3 2 1 5 10\n0 10", "output": "30"}, {"input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570"}]
900
["implementation"]
30
[{"input": "1 3 2 1 5 10\r\n0 10\r\n", "output": "30"}, {"input": "2 8 4 2 5 10\r\n20 30\r\n50 100\r\n", "output": "570"}, {"input": "3 15 9 95 39 19\r\n873 989\r\n1003 1137\r\n1172 1436\r\n", "output": "8445"}, {"input": "4 73 2 53 58 16\r\n51 52\r\n209 242\r\n281 407\r\n904 945\r\n", "output": "52870"}, {"input": "5 ...
false
stdio
null
true
59/E
59
E
PyPy 3
TESTS
6
902
51,712,000
92545286
import os, sys from io import IOBase, BytesIO py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.wr...
43
1,090
32,256,000
222025354
import sys from collections import deque readline = sys.stdin.readline N = 0 graph = [] forbbiden = set() def read_input(): global N n, m, k = [int(w) for w in readline().split()] for _ in range(n + 1): graph.append([]) for _ in range(m): u, v = [int(w) for w in readline().split()] ...
Codeforces Beta Round 55 (Div. 2)
CF
2,011
3
256
Shortest Path
In Ancient Berland there were n cities and m two-way roads of equal length. The cities are numbered with integers from 1 to n inclusively. According to an ancient superstition, if a traveller visits three cities ai, bi, ci in row, without visiting other cities between them, a great disaster awaits him. Overall there ar...
The first line contains three integers n, m, k (2 ≤ n ≤ 3000, 1 ≤ m ≤ 20000, 0 ≤ k ≤ 105) which are the number of cities, the number of roads and the number of the forbidden triplets correspondingly. Then follow m lines each containing two integers xi, yi (1 ≤ xi, yi ≤ n) which are the road descriptions. The road is d...
If there are no path from 1 to n print -1. Otherwise on the first line print the number of roads d along the shortest path from the city 1 to the city n. On the second line print d + 1 numbers — any of the possible shortest paths for Vasya. The path should start in the city 1 and end in the city n.
null
null
[{"input": "4 4 1\n1 2\n2 3\n3 4\n1 3\n1 4 3", "output": "2\n1 3 4"}, {"input": "3 1 0\n1 2", "output": "-1"}, {"input": "4 4 2\n1 2\n2 3\n3 4\n1 3\n1 2 3\n1 3 4", "output": "4\n1 3 2 3 4"}]
2,000
["graphs", "shortest paths"]
43
[{"input": "4 4 1\r\n1 2\r\n2 3\r\n3 4\r\n1 3\r\n1 4 3\r\n", "output": "2\r\n1 3 4\r\n"}, {"input": "3 1 0\r\n1 2\r\n", "output": "-1\r\n"}, {"input": "4 4 2\r\n1 2\r\n2 3\r\n3 4\r\n1 3\r\n1 2 3\r\n1 3 4\r\n", "output": "4\r\n1 3 2 3 4\r\n"}, {"input": "4 4 1\r\n1 2\r\n2 3\r\n3 4\r\n1 3\r\n1 2 3\r\n", "output": "2\r\n1...
false
stdio
null
true
59/E
59
E
Python 3
TESTS
6
342
10,649,600
177773499
import sys import sys, threading from heapq import heapify, heappop, heappush from math import log10, floor, pow, gcd, sqrt, inf from collections import defaultdict, deque, Counter input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): retu...
43
1,090
42,393,600
154832292
import sys input = sys.stdin.readline from collections import deque n, m, k = list(map(int, input().split())) g = [[] for _ in range(n+1)] for _ in range(m): i, j = list(map(int, input().split())) g[i].append(j) g[j].append(i) bad_seq = set() for _ in range(k): i, j, k = list(map(int, input().split())) ...
Codeforces Beta Round 55 (Div. 2)
CF
2,011
3
256
Shortest Path
In Ancient Berland there were n cities and m two-way roads of equal length. The cities are numbered with integers from 1 to n inclusively. According to an ancient superstition, if a traveller visits three cities ai, bi, ci in row, without visiting other cities between them, a great disaster awaits him. Overall there ar...
The first line contains three integers n, m, k (2 ≤ n ≤ 3000, 1 ≤ m ≤ 20000, 0 ≤ k ≤ 105) which are the number of cities, the number of roads and the number of the forbidden triplets correspondingly. Then follow m lines each containing two integers xi, yi (1 ≤ xi, yi ≤ n) which are the road descriptions. The road is d...
If there are no path from 1 to n print -1. Otherwise on the first line print the number of roads d along the shortest path from the city 1 to the city n. On the second line print d + 1 numbers — any of the possible shortest paths for Vasya. The path should start in the city 1 and end in the city n.
null
null
[{"input": "4 4 1\n1 2\n2 3\n3 4\n1 3\n1 4 3", "output": "2\n1 3 4"}, {"input": "3 1 0\n1 2", "output": "-1"}, {"input": "4 4 2\n1 2\n2 3\n3 4\n1 3\n1 2 3\n1 3 4", "output": "4\n1 3 2 3 4"}]
2,000
["graphs", "shortest paths"]
43
[{"input": "4 4 1\r\n1 2\r\n2 3\r\n3 4\r\n1 3\r\n1 4 3\r\n", "output": "2\r\n1 3 4\r\n"}, {"input": "3 1 0\r\n1 2\r\n", "output": "-1\r\n"}, {"input": "4 4 2\r\n1 2\r\n2 3\r\n3 4\r\n1 3\r\n1 2 3\r\n1 3 4\r\n", "output": "4\r\n1 3 2 3 4\r\n"}, {"input": "4 4 1\r\n1 2\r\n2 3\r\n3 4\r\n1 3\r\n1 2 3\r\n", "output": "2\r\n1...
false
stdio
null
true
46/C
46
C
Python 3
TESTS
2
92
0
115054827
a = int(input()) s = input() d = s.count('H') p = [] for i in range(len(s)): if i+d > len(s): n = d+i - len(s) m = d - n h = s[:m] + s[-n:] k = h.count("T") p.append(k) else: h = s[i:d+i] k = h.count("T") mi = a for i in range(len(p)): if p[i] < mi: mi = p[i] print(mi)
27
92
0
196760951
# LUOGU_RID: 104227169 n = int(input()) s = input() print(min((s + s)[i:i+s.count('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
10/A
10
A
Python 3
TESTS
28
218
307,200
73820064
n,p1,p2,p3,t1,t2=map(int,input().split()) ans=0 l1,r1=0,0 for i in range(n): l2,r2=map(int,input().split()) ans+=(r2-l2)*p1 if l1==0: l1,r1=l2,r2 continue t=l2-r1 if t<=t1: ans+=t*p1 else: ans+=t1*p1 t-=t1 if t<=t2: ans+=t*p2 el...
30
62
0
195229808
n,p1,p2,p3,T1,T2=map(int,input().split()) total,previousTime=0,-1 for k in range(n): start,finish=map(int,input().split()) if previousTime<0: previousTime=start total +=p1*(finish-start) timeIdle=start-previousTime if timeIdle>T1+T2: total +=(timeIdle-T1-T2)*p3 timeIdle=T1+T2...
Codeforces Beta Round 10
ICPC
2,010
1
256
Power Consumption Calculation
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minut...
The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start a...
Output the answer to the problem.
null
null
[{"input": "1 3 2 1 5 10\n0 10", "output": "30"}, {"input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570"}]
900
["implementation"]
30
[{"input": "1 3 2 1 5 10\r\n0 10\r\n", "output": "30"}, {"input": "2 8 4 2 5 10\r\n20 30\r\n50 100\r\n", "output": "570"}, {"input": "3 15 9 95 39 19\r\n873 989\r\n1003 1137\r\n1172 1436\r\n", "output": "8445"}, {"input": "4 73 2 53 58 16\r\n51 52\r\n209 242\r\n281 407\r\n904 945\r\n", "output": "52870"}, {"input": "5 ...
false
stdio
null
true
449/B
449
B
PyPy 3
TESTS
3
967
51,712,000
98030169
#=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, IOBase from functools import cmp_to_key # from itertools impor...
45
1,886
133,222,400
202495416
import os import sys import threading from io import BytesIO, IOBase from heapq import heappush, heappop, heapify from collections import defaultdict, deque, Counter from bisect import bisect_left as bl from bisect import bisect_right as br # threading.stack_size(10**8) # sys.setrecursionlimit(10**6) def ri(): return...
Codeforces Round 257 (Div. 1)
CF
2,014
2
256
Jzzhu and Cities
Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. Finally, there are k train routes in the country. One ...
The first line contains three integers n, m, k (2 ≤ n ≤ 105; 1 ≤ m ≤ 3·105; 1 ≤ k ≤ 105). Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ n; ui ≠ vi; 1 ≤ xi ≤ 109). Each of the next k lines contains two integers si and yi (2 ≤ si ≤ n; 1 ≤ yi ≤ 109). It is guaranteed that there is at least o...
Output a single integer representing the maximum number of the train routes which can be closed.
null
null
[{"input": "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5", "output": "2"}, {"input": "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3", "output": "2"}]
2,000
["graphs", "greedy", "shortest paths"]
45
[{"input": "5 5 3\r\n1 2 1\r\n2 3 2\r\n1 3 3\r\n3 4 4\r\n1 5 5\r\n3 5\r\n4 5\r\n5 5\r\n", "output": "2\r\n"}, {"input": "2 2 3\r\n1 2 2\r\n2 1 3\r\n2 1\r\n2 2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "5 4 3\r\n1 2 999999999\r\n2 3 1000000000\r\n3 4 529529529\r\n5 1 524524524\r\n5 524444444\r\n5 529999999\r\n2 1000000...
false
stdio
null
true
59/E
59
E
PyPy 3-64
TESTS
15
808
34,918,400
203823090
# author: birsnot - Nardos from collections import defaultdict, deque from heapq import heappop, heappush from sys import setrecursionlimit, stdin from threading import Thread, stack_size # def input(): return stdin.readline()[:-1] input = stdin.readline def I(): return int(input()) def II(): return map(int, input()...
43
1,496
161,792,000
226494619
import sys from array import array # noqa: F401 from collections import deque def input(): return sys.stdin.buffer.readline().decode('utf-8') n, m, k = map(int, input().split()) adj = [[] for _ in range(n)] for u, v in (map(int, input().split()) for _ in range(m)): adj[u - 1].append(v - 1) adj[v - 1]....
Codeforces Beta Round 55 (Div. 2)
CF
2,011
3
256
Shortest Path
In Ancient Berland there were n cities and m two-way roads of equal length. The cities are numbered with integers from 1 to n inclusively. According to an ancient superstition, if a traveller visits three cities ai, bi, ci in row, without visiting other cities between them, a great disaster awaits him. Overall there ar...
The first line contains three integers n, m, k (2 ≤ n ≤ 3000, 1 ≤ m ≤ 20000, 0 ≤ k ≤ 105) which are the number of cities, the number of roads and the number of the forbidden triplets correspondingly. Then follow m lines each containing two integers xi, yi (1 ≤ xi, yi ≤ n) which are the road descriptions. The road is d...
If there are no path from 1 to n print -1. Otherwise on the first line print the number of roads d along the shortest path from the city 1 to the city n. On the second line print d + 1 numbers — any of the possible shortest paths for Vasya. The path should start in the city 1 and end in the city n.
null
null
[{"input": "4 4 1\n1 2\n2 3\n3 4\n1 3\n1 4 3", "output": "2\n1 3 4"}, {"input": "3 1 0\n1 2", "output": "-1"}, {"input": "4 4 2\n1 2\n2 3\n3 4\n1 3\n1 2 3\n1 3 4", "output": "4\n1 3 2 3 4"}]
2,000
["graphs", "shortest paths"]
43
[{"input": "4 4 1\r\n1 2\r\n2 3\r\n3 4\r\n1 3\r\n1 4 3\r\n", "output": "2\r\n1 3 4\r\n"}, {"input": "3 1 0\r\n1 2\r\n", "output": "-1\r\n"}, {"input": "4 4 2\r\n1 2\r\n2 3\r\n3 4\r\n1 3\r\n1 2 3\r\n1 3 4\r\n", "output": "4\r\n1 3 2 3 4\r\n"}, {"input": "4 4 1\r\n1 2\r\n2 3\r\n3 4\r\n1 3\r\n1 2 3\r\n", "output": "2\r\n1...
false
stdio
null
true
169/A
169
A
Python 3
TESTS
6
77
7,372,800
37508191
n, a, b = map(int,input().split()) h = list(map(int, input().split())) h.sort() ans = h[b] - h[a] if a == b: ans = h[b] - h[a-1] print(ans)
29
46
0
144504780
n,a,b=map(int, input().split()) h = sorted([int(i) for i in input().split()]) print(h[b]-h[b-1])
VK Cup 2012 Round 2 (Unofficial Div. 2 Edition)
CF
2,012
2
256
Chores
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals hi. As Petya is older, he wants to take the chores with complexity larger...
The first input line contains three integers n, a and b (2 ≤ n ≤ 2000; a, b ≥ 1; a + b = n) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 109), hi is the complexity of the i-th chore. The numbers in t...
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
null
In the first sample the possible values of x are 3, 4 or 5. In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.
[{"input": "5 2 3\n6 2 3 100 1", "output": "3"}, {"input": "7 3 4\n1 1 9 1 1 1 1", "output": "0"}]
800
["sortings"]
29
[{"input": "5 2 3\r\n6 2 3 100 1\r\n", "output": "3\r\n"}, {"input": "7 3 4\r\n1 1 9 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n10 2\r\n", "output": "8\r\n"}, {"input": "2 1 1\r\n7 7\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1000000000\r\n", "output": "999999999\r\n"}, {"input": "3 1 2\r\n6 5 5\r\n", "...
false
stdio
null
true
169/A
169
A
Python 3
TESTS
6
93
0
78791133
n , a , b = map(int,input().split()) l = list(map(int,input().split())) l.sort() if a!=b: print(l[b]-l[a]) else:print(l[b]-l[a-1])
29
46
0
145054398
n, older, younger = (list(map(int,input().split()))) chores = (list(map(int,input().split()))) chores.sort(reverse = True) c_old = chores[older-1] chores.sort() c_young = chores[younger-1] print((c_old)-(c_young))
VK Cup 2012 Round 2 (Unofficial Div. 2 Edition)
CF
2,012
2
256
Chores
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals hi. As Petya is older, he wants to take the chores with complexity larger...
The first input line contains three integers n, a and b (2 ≤ n ≤ 2000; a, b ≥ 1; a + b = n) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 109), hi is the complexity of the i-th chore. The numbers in t...
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
null
In the first sample the possible values of x are 3, 4 or 5. In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.
[{"input": "5 2 3\n6 2 3 100 1", "output": "3"}, {"input": "7 3 4\n1 1 9 1 1 1 1", "output": "0"}]
800
["sortings"]
29
[{"input": "5 2 3\r\n6 2 3 100 1\r\n", "output": "3\r\n"}, {"input": "7 3 4\r\n1 1 9 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n10 2\r\n", "output": "8\r\n"}, {"input": "2 1 1\r\n7 7\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1000000000\r\n", "output": "999999999\r\n"}, {"input": "3 1 2\r\n6 5 5\r\n", "...
false
stdio
null
true
754/D
754
D
PyPy 3-64
TESTS
4
77
2,150,400
174838101
import sys from bisect import bisect_left from collections import * from itertools import * from math import * from array import * from functools import lru_cache import heapq import bisect import random import io, os if sys.hexversion == 50923504: sys.stdin = open('cfinput.txt') RI = lambda: map(int, sys.stdin.b...
77
3,353
112,844,800
174818794
import os, sys from io import BytesIO, IOBase from collections import defaultdict, deque, Counter from bisect import bisect_left, bisect_right from heapq import heappush, heappop from functools import lru_cache from itertools import accumulate import math import sys from sys import stdout # sys.setrecursionlimit(10 *...
Codeforces Round 390 (Div. 2)
CF
2,017
4
256
Fedor and coupons
All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has n discount coupons, the i-th of them can be used with products with i...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·105) — the number of coupons Fedor has, and the number of coupons he wants to choose. Each of the next n lines contains two integers li and ri ( - 109 ≤ li ≤ ri ≤ 109) — the description of the i-th coupon. The coupons can be equal.
In the first line print single integer — the maximum number of products with which all the chosen coupons can be used. The products with which at least one coupon cannot be used shouldn't be counted. In the second line print k distinct integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the ids of the coupons which Fedor should c...
null
In the first example if we take the first two coupons then all the products with ids in range [40, 70] can be bought with both coupons. There are 31 products in total. In the second example, no product can be bought with two coupons, that is why the answer is 0. Fedor can choose any two coupons in this example.
[{"input": "4 2\n1 100\n40 70\n120 130\n125 180", "output": "31\n1 2"}, {"input": "3 2\n1 12\n15 20\n25 30", "output": "0\n1 2"}, {"input": "5 2\n1 10\n5 15\n14 50\n30 70\n99 100", "output": "21\n3 4"}]
2,100
["binary search", "data structures", "greedy", "sortings"]
77
[{"input": "4 2\r\n1 100\r\n40 70\r\n120 130\r\n125 180\r\n", "output": "31\r\n1 2 \r\n"}, {"input": "3 2\r\n1 12\r\n15 20\r\n25 30\r\n", "output": "0\r\n1 2 \r\n"}, {"input": "5 2\r\n1 10\r\n5 15\r\n14 50\r\n30 70\r\n99 100\r\n", "output": "21\r\n3 4 \r\n"}, {"input": "7 6\r\n-8 6\r\n7 9\r\n-10 -5\r\n-6 10\r\n-7 -3\r\...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n, k = map(int, f.readline().split()) coupons = [] for _ in range(n): l, r = map(int, f.readline().split()) ...
true
489/A
489
A
PyPy 3-64
TESTS
5
46
0
192591472
n=int(input()) lis=list(map(int,input().split())) l=[] for i in lis: l.append(i) l.sort() index1=[] index2=[] count=0 pointer=0 for i in range(len(lis)): a=l[pointer] b=lis.index(a) if lis[i]>a: index1.append(b) index2.append(i) lis[i],lis[b]=lis[b],lis[i] count+=1 po...
22
77
819,200
8726157
from sys import stdin lines = list(filter(None, stdin.read().split('\n'))) def parseline(line): return list(map(int, line.split())) lines = list(map(parseline, lines)) n, = lines[0] ai = lines[1]; assert(len(ai) == n) sai = sorted((x, i) for i, x in enumerate(ai)) pos = list(range(n)) iai = list(range(n)) print...
Codeforces Round 277.5 (Div. 2)
CF
2,014
1
256
SwapSort
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another. Note that in this problem you do not have to minimize the number of sw...
The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≤ ai ≤ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the arr...
In the first line print k (0 ≤ k ≤ n) — the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≤ i, j ≤ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are per...
null
null
[{"input": "5\n5 2 5 1 4", "output": "2\n0 3\n4 2"}, {"input": "6\n10 20 20 40 60 60", "output": "0"}, {"input": "2\n101 100", "output": "1\n0 1"}]
1,200
["greedy", "implementation", "sortings"]
22
[{"input": "5\r\n5 2 5 1 4\r\n", "output": "2\r\n0 3\r\n4 2\r\n"}, {"input": "6\r\n10 20 20 40 60 60\r\n", "output": "0\r\n"}, {"input": "2\r\n101 100\r\n", "output": "1\r\n0 1\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "2\r\n1000000000 -1000000000\r\n", "output": "1\r\n0 1\r\n"}, {"input": "8\r\n5...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path) as f: n = int(f.readline().strip()) arr = list(map(int, f.readline().split())) with open(sub_path) as f: lines = f.readlines() if not lines: ...
true
479/D
479
D
PyPy 3-64
TESTS
2
46
0
221741730
import sys input = lambda: sys.stdin.readline().rstrip() N,L,x,y = map(int, input().split()) A = list(map(int, input().split())) seen = set() cx,cy=0,0 for a in A: if str(a-x) in seen: cx=1 if str(a-y) in seen: cy=1 seen.add(str(a)) if cx==cy==1: exit(print(0)) if cx==1: p...
111
202
10,854,400
8309555
import itertools import math def can_measure(a, d): return any(i + d in a for i in a) def main(): n, l, x, y = map(int, input().split()) a = set(map(int, input().split())) can_x = can_measure(a, x) can_y = can_measure(a, y) if can_x and can_y: print(0) elif can_x: print(1) print(y) elif can_y: print...
Codeforces Round 274 (Div. 2)
CF
2,014
1
256
Long Jumps
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurem...
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), wher...
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in a...
null
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the thir...
[{"input": "3 250 185 230\n0 185 250", "output": "1\n230"}, {"input": "4 250 185 230\n0 20 185 250", "output": "0"}, {"input": "2 300 185 230\n0 300", "output": "2\n185 230"}]
1,700
["binary search", "greedy", "implementation"]
111
[{"input": "3 250 185 230\r\n0 185 250\r\n", "output": "1\r\n230\r\n"}, {"input": "4 250 185 230\r\n0 20 185 250\r\n", "output": "0\r\n"}, {"input": "2 300 185 230\r\n0 300\r\n", "output": "2\r\n185 230\r\n"}, {"input": "4 300 4 5\r\n0 6 7 300\r\n", "output": "1\r\n11\r\n"}, {"input": "2 100 30 70\r\n0 100\r\n", "outpu...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: lines = f.readlines() n, l, x, y = map(int, lines[0].split()) a = list(map(int, lines[1].split())) a_set = set(a) # Read...
true
427/B
427
B
PyPy 3-64
TESTS
5
124
25,292,800
208332398
n,t,c=map(int,input().strip().split()) li=list(map(int,input().strip().split())) di={} i=0 fli=[] while i<n: ct=0 si=i maxi=li[i] while ct<c and i<n: if li[i]>maxi: maxi=li[i] ct+=1 i+=1 lii=[maxi]*c fli=fli+lii ans=0 si=0 for i in range(0,n-c+1): if ...
80
93
21,913,600
226506538
def ways(n, t, c, prisoners): valid = 0 ways = 0 if n < c: return 0 for p in prisoners: if p <= t: valid += 1 else: valid = 0 if c <= valid: ways += 1 return ways n, t, c = map(int, input().split()) prisoners = map(int, input(...
Codeforces Round 244 (Div. 2)
CF
2,014
1
256
Prison Transfer
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city. For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crim...
The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
Print a single integer — the number of ways you can choose the c prisoners.
null
null
[{"input": "4 3 3\n2 3 1 1", "output": "2"}, {"input": "1 1 1\n2", "output": "0"}, {"input": "11 4 2\n2 2 0 7 3 2 2 4 9 1 4", "output": "6"}]
1,100
["data structures", "implementation"]
80
[{"input": "4 3 3\r\n2 3 1 1\r\n", "output": "2\r\n"}, {"input": "1 1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "11 4 2\r\n2 2 0 7 3 2 2 4 9 1 4\r\n", "output": "6\r\n"}, {"input": "57 2 10\r\n7 5 2 7 4 1 0 5 2 9 2 9 8 6 6 5 9 6 8 1 0 1 0 3 2 6 5 2 8 8 8 8 0 9 4 3 6 6 2 4 5 1 2 0 1 7 1 1 5 4 5 0 7 5 1 9 6\r\n", "outpu...
false
stdio
null
true
165/A
165
A
Python 3
TESTS
3
62
0
145610886
n=int(input()) pt_list=[] ans=0 for _ in range(n): [x,y] =map(int,input().split()) pt_list.append([x,y]) for i in range(n): a_setx=set() a_sety=set() for j in range(n): if pt_list[i][0]-pt_list[j][0]>0: a_setx.add('pos') elif pt_list[i][1]-pt_list[j][1]>0: a_s...
26
92
0
141808501
n = int(input()) store_x = {} store_y = {} def sortSecond(val): return val[1] for _ in range(n): x,y = [int(i) for i in input().split()] if store_x.get(x): store_x[x].append((x,y)) else: store_x[x] = [(x,y)] if store_y.get(y): store_y[y].append((x,y)) else: ...
Codeforces Round 112 (Div. 2)
CF
2,012
2
256
Supercentral Point
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y): - point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y - point (x', y') is (x, y)'s left neighbor, i...
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed t...
Print the only number — the number of supercentral points of the given set.
null
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
[{"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2"}, {"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1"}]
1,000
["implementation"]
26
[{"input": "8\r\n1 1\r\n4 2\r\n3 1\r\n1 2\r\n0 2\r\n0 1\r\n1 0\r\n1 3\r\n", "output": "2\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n1 0\r\n0 -1\r\n-1 0\r\n", "output": "1\r\n"}, {"input": "9\r\n-565 -752\r\n-184 723\r\n-184 -752\r\n-184 1\r\n950 723\r\n-565 723\r\n950 -752\r\n950 1\r\n-565 1\r\n", "output": "1\r\n"}, {"input...
false
stdio
null
true
165/A
165
A
PyPy 3-64
TESTS
3
92
0
184382238
n = int(input()) sx = [] sy = [] count = 0 for i in range(n): s = list(map(int, input().split())) x, y = s[0], s[1] sx.append(x) sy.append(y) mAxx = max(sx) mInx = min(sx) mAxy = max(sy) mIny = min(sy) for i in range(len(sx)): if sx.count(sx[i]) >= 3 and sx[i] != mAxx and sx[i] != mInx: if sy.count(sy[i]) >= 3 a...
26
92
0
146798114
n=int(input()) l=[] a=[] b=[] sum=0 for i in range(n): m=list(map(int,input().split())) l.append(m) a.append(m[0]) b.append(m[1]) for i in range(n): count=0 for j in range(len(a)): if a[j]==l[i][0] and b[j]>l[i][1]: count+=1 break for j in range(len(a)): ...
Codeforces Round 112 (Div. 2)
CF
2,012
2
256
Supercentral Point
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y): - point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y - point (x', y') is (x, y)'s left neighbor, i...
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed t...
Print the only number — the number of supercentral points of the given set.
null
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
[{"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2"}, {"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1"}]
1,000
["implementation"]
26
[{"input": "8\r\n1 1\r\n4 2\r\n3 1\r\n1 2\r\n0 2\r\n0 1\r\n1 0\r\n1 3\r\n", "output": "2\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n1 0\r\n0 -1\r\n-1 0\r\n", "output": "1\r\n"}, {"input": "9\r\n-565 -752\r\n-184 723\r\n-184 -752\r\n-184 1\r\n950 723\r\n-565 723\r\n950 -752\r\n950 1\r\n-565 1\r\n", "output": "1\r\n"}, {"input...
false
stdio
null
true
165/A
165
A
Python 3
TESTS
3
62
0
160189729
lst=[] for i in range(int(input())):lst.append([int(x) for x in input().split()]) lstx=[i[0] for i in lst] lsty=[i[1] for i in lst] minx,maxx,miny,maxy=min(lstx),max(lstx),min(lsty),max(lsty) superpt=0 for i in lst: if i[0]!=minx and i[0]!=maxx: if i[1]!=miny and i[1]!=maxy: if lstx.count(i[0])>...
26
92
0
147175351
n = int(input()) a = [list(int(a) for a in input().split()) for i in range(n)] c = 0 for x,y in a: l , r , t , b = 0,0,0,0 for x1,y1 in a: if x == x1: if y1 > y: t = 1 if y1 < y: b = 1 if y == y1: if x1 > x: r = 1 if x1 < x: l = 1 if l == 1 an...
Codeforces Round 112 (Div. 2)
CF
2,012
2
256
Supercentral Point
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y): - point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y - point (x', y') is (x, y)'s left neighbor, i...
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed t...
Print the only number — the number of supercentral points of the given set.
null
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
[{"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2"}, {"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1"}]
1,000
["implementation"]
26
[{"input": "8\r\n1 1\r\n4 2\r\n3 1\r\n1 2\r\n0 2\r\n0 1\r\n1 0\r\n1 3\r\n", "output": "2\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n1 0\r\n0 -1\r\n-1 0\r\n", "output": "1\r\n"}, {"input": "9\r\n-565 -752\r\n-184 723\r\n-184 -752\r\n-184 1\r\n950 723\r\n-565 723\r\n950 -752\r\n950 1\r\n-565 1\r\n", "output": "1\r\n"}, {"input...
false
stdio
null
true
165/A
165
A
Python 3
TESTS
3
62
0
193427066
n = int(input()) arrs = [] for _ in range(n): points = [list(x) for x in input().split()] arrs.append(points) count = 0 for i in range(n): r, l, lo, up = False, False, False, False for j in range(n): if i == j: continue if arrs[i][1] == arrs[j][1]: if arrs[i][0] > arrs[j][0]: r = True if arrs[i][0] < arrs...
26
92
0
149380017
n = int(input()) pts = [] for i in range(n): el = [int(x) for x in input().split()] pts.append(el) # print(pts) res = 0 for pt1 in range(n): rtn = False lftn = False lown = False upn = False for pt2 in range(n): if(pt1!=pt2): if(pts[pt1][0]==pts[pt2][0]): ...
Codeforces Round 112 (Div. 2)
CF
2,012
2
256
Supercentral Point
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y): - point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y - point (x', y') is (x, y)'s left neighbor, i...
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed t...
Print the only number — the number of supercentral points of the given set.
null
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
[{"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2"}, {"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1"}]
1,000
["implementation"]
26
[{"input": "8\r\n1 1\r\n4 2\r\n3 1\r\n1 2\r\n0 2\r\n0 1\r\n1 0\r\n1 3\r\n", "output": "2\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n1 0\r\n0 -1\r\n-1 0\r\n", "output": "1\r\n"}, {"input": "9\r\n-565 -752\r\n-184 723\r\n-184 -752\r\n-184 1\r\n950 723\r\n-565 723\r\n950 -752\r\n950 1\r\n-565 1\r\n", "output": "1\r\n"}, {"input...
false
stdio
null
true
165/A
165
A
PyPy 3
TESTS
5
186
1,433,600
104274136
n = int(input()) points = [] for i in range(n): points.append(list(map(int, input().split()))) count = 0 for i in range(n): x, y = points[i] up, down, left, right = False, False, False, False for j in range(n): x2, y2 = points[j] if x == x2: if y < y2: up = T...
26
92
0
150146938
n = int(input()) arr = [] output = 0 for i in range(n): x, y = [int(i) for i in input().split()] arr.append([x, y]) for i in range(n): x = arr[i][0] y = arr[i][1] arr2 = arr[:n] + arr[n+1:] left = False right = False top = False bottom = False for item in arr2: if item...
Codeforces Round 112 (Div. 2)
CF
2,012
2
256
Supercentral Point
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y): - point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y - point (x', y') is (x, y)'s left neighbor, i...
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed t...
Print the only number — the number of supercentral points of the given set.
null
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
[{"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2"}, {"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1"}]
1,000
["implementation"]
26
[{"input": "8\r\n1 1\r\n4 2\r\n3 1\r\n1 2\r\n0 2\r\n0 1\r\n1 0\r\n1 3\r\n", "output": "2\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n1 0\r\n0 -1\r\n-1 0\r\n", "output": "1\r\n"}, {"input": "9\r\n-565 -752\r\n-184 723\r\n-184 -752\r\n-184 1\r\n950 723\r\n-565 723\r\n950 -752\r\n950 1\r\n-565 1\r\n", "output": "1\r\n"}, {"input...
false
stdio
null
true
165/A
165
A
Python 3
TESTS
3
60
0
146273591
x=[] xmax=0 xmin=0 ymax=0 ymin=0 y=[] for _ in range(int(input())): a,b=map(int,input().split()) x.append(a) y.append(b) if(a>xmax): xmax=a if(a<xmin): xmin=a if(b>ymax): ymax=b if(b<ymin): ymin=b re=[xmax,ymax,xmin,ymin] x=list(set(x)) y=list(set(y)) for i in range(4): if(re[i] in x): x.remove(re[i])...
26
92
0
155023226
info = dict() amount = int(input()) counter = 0 all_pos = [] for i in range(amount): current = ([int(x) for x in input().split()]) all_pos.append(current) dict_elements = {} for i in all_pos: x, y = i[0], i[1] right, left, upper, lower = 0, 0, 0, 0 for j in all_pos: if (x,y) == j: ...
Codeforces Round 112 (Div. 2)
CF
2,012
2
256
Supercentral Point
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y): - point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y - point (x', y') is (x, y)'s left neighbor, i...
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed t...
Print the only number — the number of supercentral points of the given set.
null
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
[{"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2"}, {"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1"}]
1,000
["implementation"]
26
[{"input": "8\r\n1 1\r\n4 2\r\n3 1\r\n1 2\r\n0 2\r\n0 1\r\n1 0\r\n1 3\r\n", "output": "2\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n1 0\r\n0 -1\r\n-1 0\r\n", "output": "1\r\n"}, {"input": "9\r\n-565 -752\r\n-184 723\r\n-184 -752\r\n-184 1\r\n950 723\r\n-565 723\r\n950 -752\r\n950 1\r\n-565 1\r\n", "output": "1\r\n"}, {"input...
false
stdio
null
true
165/A
165
A
Python 3
TESTS
3
62
0
130632340
n = int(input()) li = [list(map(int,(input().split()))) for i in range(n)] cnt = 0 for i in li: x_g, x_l, y_g, y_l, x_equal, y_equal = 0, 0, 0, 0, 0, 0 for j in li: if li.index(i) != li.index(j): if j[0]<i[0]: x_l += 1 elif j[0] > i[0]: x_g += 1 ...
26
92
0
155192352
import sys input = sys.stdin.readline n = int(input()) g = [tuple(map(int, input().split())) for _ in range(n)] w = sorted(g) q = [(j,i) for (i,j) in sorted([(j,i) for (i,j) in g])] a = set() b = set() for i in range(n-2): if w[i][0] == w[i+1][0] == w[i+2][0]: a.add(w[i+1]) if q[i][1] == q[i+1][1] == q...
Codeforces Round 112 (Div. 2)
CF
2,012
2
256
Supercentral Point
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y): - point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y - point (x', y') is (x, y)'s left neighbor, i...
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed t...
Print the only number — the number of supercentral points of the given set.
null
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
[{"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2"}, {"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1"}]
1,000
["implementation"]
26
[{"input": "8\r\n1 1\r\n4 2\r\n3 1\r\n1 2\r\n0 2\r\n0 1\r\n1 0\r\n1 3\r\n", "output": "2\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n1 0\r\n0 -1\r\n-1 0\r\n", "output": "1\r\n"}, {"input": "9\r\n-565 -752\r\n-184 723\r\n-184 -752\r\n-184 1\r\n950 723\r\n-565 723\r\n950 -752\r\n950 1\r\n-565 1\r\n", "output": "1\r\n"}, {"input...
false
stdio
null
true
427/B
427
B
PyPy 3-64
TESTS
4
93
22,528,000
201051017
n, t, c = tuple(map(int, input().split())) prisoners = tuple(map(int, input().split())) def get_lines_length(prisoners): length = 0 lines_length = [] for prisoner in prisoners: if prisoner <= t: length += 1 else: lines_length.append(length) length = 0 ...
80
108
19,865,600
226021405
n, t, c = (int(x) for x in input().split()) severities = input().split() ways = 0 run = 0 for s in severities: s = int(s) if s > t: run = 0 else: run += 1 if run >= c: ways += 1 print(ways)
Codeforces Round 244 (Div. 2)
CF
2,014
1
256
Prison Transfer
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city. For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crim...
The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
Print a single integer — the number of ways you can choose the c prisoners.
null
null
[{"input": "4 3 3\n2 3 1 1", "output": "2"}, {"input": "1 1 1\n2", "output": "0"}, {"input": "11 4 2\n2 2 0 7 3 2 2 4 9 1 4", "output": "6"}]
1,100
["data structures", "implementation"]
80
[{"input": "4 3 3\r\n2 3 1 1\r\n", "output": "2\r\n"}, {"input": "1 1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "11 4 2\r\n2 2 0 7 3 2 2 4 9 1 4\r\n", "output": "6\r\n"}, {"input": "57 2 10\r\n7 5 2 7 4 1 0 5 2 9 2 9 8 6 6 5 9 6 8 1 0 1 0 3 2 6 5 2 8 8 8 8 0 9 4 3 6 6 2 4 5 1 2 0 1 7 1 1 5 4 5 0 7 5 1 9 6\r\n", "outpu...
false
stdio
null
true
449/B
449
B
PyPy 3
TESTS
3
1,169
61,030,400
131712818
import bisect import collections import copy import enum import functools import heapq import itertools import math import random import re import sys import time import string from typing import List sys.setrecursionlimit(3001) input = sys.stdin.readline n,m,k = map(int,input().split()) g = collections.defaultdict...
45
1,871
131,072,000
167802107
import sys import math import collections from heapq import heappush, heappop input = sys.stdin.readline ints = lambda: list(map(int, input().split())) n, m, k = ints() graph = [[] for _ in range(n + 1)] for _ in range(m): a, b, c = ints() graph[a].append((b, c, 0)) graph[b].append((a, c, 0)) trains = ...
Codeforces Round 257 (Div. 1)
CF
2,014
2
256
Jzzhu and Cities
Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. Finally, there are k train routes in the country. One ...
The first line contains three integers n, m, k (2 ≤ n ≤ 105; 1 ≤ m ≤ 3·105; 1 ≤ k ≤ 105). Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ n; ui ≠ vi; 1 ≤ xi ≤ 109). Each of the next k lines contains two integers si and yi (2 ≤ si ≤ n; 1 ≤ yi ≤ 109). It is guaranteed that there is at least o...
Output a single integer representing the maximum number of the train routes which can be closed.
null
null
[{"input": "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5", "output": "2"}, {"input": "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3", "output": "2"}]
2,000
["graphs", "greedy", "shortest paths"]
45
[{"input": "5 5 3\r\n1 2 1\r\n2 3 2\r\n1 3 3\r\n3 4 4\r\n1 5 5\r\n3 5\r\n4 5\r\n5 5\r\n", "output": "2\r\n"}, {"input": "2 2 3\r\n1 2 2\r\n2 1 3\r\n2 1\r\n2 2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "5 4 3\r\n1 2 999999999\r\n2 3 1000000000\r\n3 4 529529529\r\n5 1 524524524\r\n5 524444444\r\n5 529999999\r\n2 1000000...
false
stdio
null
true
294/A
294
A
Python 3
TESTS
26
62
0
160229598
# 294A n = int(input()) wires = list(map(int, input().split())) m = int(input()) for i in range(m): coords = list(map(int, input().split())) x = coords[0] y = coords[1] # how many birds to right and left of dead bird left = y - 1; right = wires[x-1] - y wires[x-1] = 0 # all birds (alive or de...
31
62
0
187419590
# tc = int(input()) for i in range(1): n = int(input()) li =list(map(int,input().split())) x = int(input()) ans = 0 for i in range(x): lix = list(map(int,input().split())) if lix[0]-2>=0: li[lix[0]-2] += lix[1]-1 ...
Codeforces Round 178 (Div. 2)
CF
2,013
2
256
Shaass and Oskols
Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols ...
The first line of the input contains an integer n, (1 ≤ n ≤ 100). The next line contains a list of space-separated integers a1, a2, ..., an, (0 ≤ ai ≤ 100). The third line contains an integer m, (0 ≤ m ≤ 100). Each of the next m lines contains two integers xi and yi. The integers mean that for the i-th time Shaass sho...
On the i-th line of the output print the number of birds on the i-th wire.
null
null
[{"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16"}, {"input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3"}]
800
["implementation", "math"]
31
[{"input": "5\r\n10 10 10 10 10\r\n5\r\n2 5\r\n3 13\r\n2 12\r\n1 13\r\n4 6\r\n", "output": "0\r\n12\r\n5\r\n0\r\n16\r\n"}, {"input": "3\r\n2 4 1\r\n1\r\n2 2\r\n", "output": "3\r\n0\r\n3\r\n"}, {"input": "5\r\n58 51 45 27 48\r\n5\r\n4 9\r\n5 15\r\n4 5\r\n5 8\r\n1 43\r\n", "output": "0\r\n66\r\n57\r\n7\r\n0\r\n"}, {"inpu...
false
stdio
null
true
294/C
294
C
Python 3
TESTS
7
93
307,200
101680806
from sys import stdin, stdout from math import pow def main(): N, M = 2000, 1000000007 fact = factorial(N, M) n, m = readline() onn = [0] + sorted(readline()) + [n + 1] off = [] for i in range(1, len(onn)): off.append(onn[i] - onn[i - 1] - 1) answer = fact[sum(off)] div = 1 ...
30
109
307,200
54146781
# https://codeforces.com/problemset/problem/294/C import sys import math mod = 10 ** 9 + 7 def factorial(n): x = 1 for i in range(n): yield x x = x * (i + 1) % mod f = list(factorial(1001)) def C(n, k): return f[n] * pow(f[k], mod - 2, mod) * pow(f[n - k], mod - 2, mod) % mod def m...
Codeforces Round 178 (Div. 2)
CF
2,013
1
256
Shaass and Lights
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is alrea...
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 ≤ n ≤ 1000, 1 ≤ m ≤ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initia...
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
null
null
[{"input": "3 1\n1", "output": "1"}, {"input": "4 2\n1 4", "output": "2"}, {"input": "11 2\n4 8", "output": "6720"}]
1,900
["combinatorics", "number theory"]
30
[{"input": "3 1\r\n1\r\n", "output": "1\r\n"}, {"input": "4 2\r\n1 4\r\n", "output": "2\r\n"}, {"input": "11 2\r\n4 8\r\n", "output": "6720\r\n"}, {"input": "4 2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4 4\r\n1 2 3 4\r\n", "output": "1\r\n"}, {"input": "4 2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4 4\r\n1 2 3 4...
false
stdio
null
true
491/B
491
B
Python 3
TESTS
1
46
0
8769508
N,M = map(int,input().split()) C = int(input()) Ci = [list(map(int,input().split())) for i in range(C)] H = int(input()) Hi = [list(map(int,input().split())) for i in range(H)] xi = 0 yi = 0 for y in range(2): for x in range(C): if y == 0: xi += x else: yi += x xi //= C yi //...
28
1,747
10,035,200
72031483
N, M = input().split() a, b, c, d = [int(1e10) for _ in range(4)] for i in range(int(input())): x, y = list(map(int, input().split())) a, b, c, d = min(a, x + y), min(b, x - y), min(c, - x + y), min(d, - x - y) res, pos = int(1e10), 0 for i in range(int(input())): x, y = list(map(int, input().split())) ...
Testing Round 11
CF
2,014
2
256
New York Hotel
Think of New York as a rectangular grid consisting of N vertical avenues numerated from 1 to N and M horizontal streets numerated 1 to M. C friends are staying at C hotels located at some street-avenue crossings. They are going to celebrate birthday of one of them in the one of H restaurants also located at some street...
The first line contains two integers N и M — size of the city (1 ≤ N, M ≤ 109). In the next line there is a single integer C (1 ≤ C ≤ 105) — the number of hotels friends stayed at. Following C lines contain descriptions of hotels, each consisting of two coordinates x and y (1 ≤ x ≤ N, 1 ≤ y ≤ M). The next line contains...
In the first line output the optimal distance. In the next line output index of a restaurant that produces this optimal distance. If there are several possibilities, you are allowed to output any of them.
null
null
[{"input": "10 10\n2\n1 1\n3 3\n2\n1 10\n4 4", "output": "6\n2"}]
2,100
["greedy", "math"]
28
[{"input": "10 10\r\n2\r\n1 1\r\n3 3\r\n2\r\n1 10\r\n4 4\r\n", "output": "6\r\n2\r\n"}, {"input": "100 100\r\n10\r\n53 20\r\n97 6\r\n12 74\r\n48 92\r\n97 13\r\n47 96\r\n75 32\r\n69 21\r\n95 75\r\n1 54\r\n10\r\n36 97\r\n41 1\r\n1 87\r\n39 23\r\n27 44\r\n73 97\r\n1 1\r\n6 26\r\n48 3\r\n5 69\r\n", "output": "108\r\n4\r\n"...
false
stdio
null
true
297/A
297
A
Python 3
TESTS
2
124
7,065,600
37388457
#!/usr/bin/env python3 # -*- coding: utf-8 -*- a=[] b=[] a=input() b=input() cnta=0 cntb=0 for i,val in enumerate(a): if val=='1': cnta=cnta+1 for i,val in enumerate(b): if val=='1': cntb=cntb+1 if cnta&1==1: pa=cnta+1 if cnta>=cntb: print('YES') else: print('NO')
79
186
0
226402581
a,b=input(),input() ca,cb=a.count('1'),b.count('1') print('YES' if ca+(ca&1)>=cb else 'NO')
Codeforces Round 180 (Div. 1)
CF
2,013
1
256
Parity Game
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: - Write parity(a) ...
The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
null
In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
[{"input": "01011\n0110", "output": "YES"}, {"input": "0011\n1110", "output": "NO"}]
1,700
["constructive algorithms"]
79
[{"input": "01011\r\n0110\r\n", "output": "YES\r\n"}, {"input": "0011\r\n1110\r\n", "output": "NO\r\n"}, {"input": "11111\r\n111111\r\n", "output": "YES\r\n"}, {"input": "0110011\r\n01100110\r\n", "output": "YES\r\n"}, {"input": "10000100\r\n011110\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}...
false
stdio
null
true
58/D
58
D
PyPy 3
TESTS
5
310
0
95808360
import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n = int(input()) a = [input().rstrip() for _ in range(n)] d = input().rstrip() words = [[] for _ in range(100)] total_len = 0 for word in a: words[len(word)].append(word) total_len += len(wo...
46
372
1,740,800
213673188
from collections import deque n = int(input()) a = [input() for i in range(n)] a.sort() dq = deque(a) # print(dq) d = input() n //= 2 common_len = sum(len(s) for s in a) // n res = [] for i in range(n): s1 = dq.popleft() for s2 in dq: if len(s1) + len(s2) == common_len: dq.remove(s2) ...
Codeforces Beta Round 54 (Div. 2)
CF
2,011
2
256
Calendar
BerOilGasDiamondBank has branches in n cities, at that n is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: the calendar should consist of exactly n / 2 lines of strictly equal length, each of which contains exactly two names and exactly one sep...
The first line contains an integer n (1 ≤ n ≤ 104, n is even) which is the number of branches. Then follow n lines which are the names of the cities. All the names consist of lowercase Latin letters; their lengths are no less than 1 and no more than 10 symbols. The next line contains a single symbol d (d has an ASCII-c...
Print n / 2 lines of similar length which are the required calendar. Every line should contain exactly two words and exactly one separator between them. If there are several solutions, print the lexicographically minimal one. The lexicographical comparison of lines is realized by the "<" operator in the modern programm...
null
null
[{"input": "4\nb\naa\nhg\nc\n.", "output": "aa.b\nc.hg"}, {"input": "2\naa\na\n!", "output": "a!aa"}, {"input": "2\naa\na\n|", "output": "aa|a"}]
2,000
["greedy", "strings"]
46
[{"input": "4\r\nb\r\naa\r\nhg\r\nc\r\n.\r\n", "output": "aa.b\r\nc.hg\r\n"}, {"input": "2\r\naa\r\na\r\n!\r\n", "output": "a!aa\r\n"}, {"input": "2\r\naa\r\na\r\n|\r\n", "output": "aa|a\r\n"}, {"input": "4\r\nqhcivbxotj\r\nirgxzzxvw\r\npxdmcyszvk\r\nyyaevcdal\r\n~\r\n", "output": "irgxzzxvw~pxdmcyszvk\r\nqhcivbxotj~yy...
false
stdio
null
true
580/C
580
C
PyPy 3-64
TESTS
34
343
163,225,600
226967627
import sys, threading input = sys.stdin.readline from collections import defaultdict input = sys.stdin.readline # returns the first number where key becomes true for a given delegate type key def bs(low=1, high=1, key = lambda x: True): while low <= high: mid = (low + high)//2 if key(mid): ...
40
233
29,286,400
225884260
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): s = input() return list(s[: len(s) - 1]) def invr(): return map(int, input().split()) n, m = invr() cat =...
Codeforces Round 321 (Div. 2)
CF
2,015
2
256
Kefa and Park
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vert...
The first line contains two integers, n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ n) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains n integers a1, a2, ..., an, where each ai either equals to 0 (then vertex i has no cat), or equals to ...
A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most m consecutive vertices with cats.
null
Let us remind you that a tree is a connected graph on n vertices and n - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it ha...
[{"input": "4 1\n1 1 0 0\n1 2\n1 3\n1 4", "output": "2"}, {"input": "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7", "output": "2"}]
1,500
["dfs and similar", "graphs", "trees"]
40
[{"input": "4 1\r\n1 1 0 0\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "2\r\n"}, {"input": "7 1\r\n1 0 1 1 0 0 0\r\n1 2\r\n1 3\r\n2 4\r\n2 5\r\n3 6\r\n3 7\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 1 1\r\n1 2\r\n2 3\r\n", "output": "0\r\n"}, {"input": "5 2\r\n1 1 0 1 1\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n", "output": "1\r\n"}, ...
false
stdio
null
true
3/B
3
B
Python 3
TESTS
14
1,310
10,547,200
22710047
def print_v(v): print(v, eval(v)) n,v = map(int, input().split()) #n - number of vehicles #v - volume of bus vehicle1 = [] vehicle2 = [] for i in range(n): t,p = map(int, input().split()) if t == 1: vehicle1.append((p,i+1)) else: vehicle2.append((p,i+1)) vehicle1.sort(key=lambda x: x[0],...
32
466
16,076,800
185738569
from heapq import nlargest from itertools import accumulate, chain import sys n, v = map(int, sys.stdin.readline().split()) a1, a2 = [], [] i1, i2 = [], [] for i in range(n): t, p = map(int, sys.stdin.readline().split()) if t == 1: a1.append(p) i1.append(i) else: a2.append(p) ...
Codeforces Beta Round 3
ICPC
2,010
2
64
Lorry
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
The first line contains a pair of integer numbers n and v (1 ≤ n ≤ 105; 1 ≤ v ≤ 109), where n is the number of waterborne vehicles in the boat depot, and v is the truck body volume of the lorry in cubic metres. The following n lines contain the information about the waterborne vehicles, that is a pair of numbers ti, pi...
In the first line print the maximum possible carrying capacity of the set. In the second line print a string consisting of the numbers of the vehicles that make the optimal set. If the answer is not unique, print any of them.
null
null
[{"input": "3 2\n1 2\n2 7\n1 3", "output": "7\n2"}]
1,900
["greedy", "sortings"]
32
[{"input": "3 2\r\n1 2\r\n2 7\r\n1 3\r\n", "output": "7\r\n2\r\n"}, {"input": "5 3\r\n1 9\r\n2 9\r\n1 9\r\n2 10\r\n1 6\r\n", "output": "24\r\n3 1 5\r\n"}, {"input": "10 10\r\n1 14\r\n2 15\r\n2 11\r\n2 12\r\n2 9\r\n1 14\r\n2 15\r\n1 9\r\n2 11\r\n2 6\r\n", "output": "81\r\n6 1 7 2 4 9\r\n"}, {"input": "20 19\r\n2 47\r\n1...
false
stdio
import sys def read_lines(path): with open(path, 'r') as f: return [line.strip() for line in f.readlines() if line.strip()] def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input input_lines = read_lines(input_path) if not input_l...
true
301/C
301
C
PyPy 3
TESTS
1
154
20,172,800
125260456
res = ''' 0??<>1 1??<>2 2??<>3 3??<>4 4??<>5 5??<>6 6??<>7 7??<>8 8??<>9 9??>>??0 ?0>>0? ?1>>1? ?2>>2? ?3>>3? ?4>>4? ?5>>5? ?6>>6? ?7>>7? ?8>>8? ?9>>9? ?>>?? 0>>0? 1>>1? 2>>2? 3>>3? 4>>4? 5>>5? 6>>6? 7>>7? 8>>8? 9>>9? ''' print(res.strip())
23
125
0
3818363
print('9??>>??0') for i in range(9): print('{}??<>{}'.format(i, i + 1)) print('??<>1') for i in range(10): print('?{0}>>{0}?'.format(i)) print('?>>??') print('>>?')
Codeforces Round 182 (Div. 1)
CF
2,013
2
256
Yaroslav and Algorithm
Yaroslav likes algorithms. We'll describe one of his favorite algorithms. 1. The algorithm receives a string as the input. We denote this input string as a. 2. The algorithm consists of some number of command. Сommand number i looks either as si >> wi, or as si <> wi, where si and wi are some possibly empty strings of...
The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the set. The next n lines contains one positive integer each. All the given numbers are less than 1025.
Print the algorithm which can individually increase each number of the set. In the i-th line print the command number i without spaces. Your algorithm will be launched for each of these numbers. The answer will be considered correct if: - Each line will a correct algorithm command (see the description in the problem ...
null
null
[{"input": "2\n10\n79", "output": "10<>11\n79<>80"}]
2,500
["constructive algorithms"]
23
[{"input": "2\r\n10\r\n79\r\n", "output": "10<>11\r\n79<>80\r\n"}, {"input": "5\r\n9\r\n99\r\n999\r\n9999\r\n99999\r\n", "output": "0??<>1\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??>>??0\r\n??<>1\r\n?0>>0?\r\n?1>>1?\r\n?2>>2?\r\n?3>>3?\r\n?4>>4?\r\n?5>>5?\r\n?6>>6?\r\n?7>>7?\...
false
stdio
import sys def main(input_path, output_path, submission_output_path): with open(input_path) as f: n = int(f.readline()) numbers = [int(line.strip()) for line in f] commands = [] with open(submission_output_path) as f: for line in f: line = line.strip() if '>...
true
732/D
732
D
PyPy 3-64
TESTS
48
93
18,534,400
217602631
n,m=map(int,input().split()) days=list(map(int,input().split())) sub=list(map(int,input().split())) def binarysearch(): l=sum(sub)+m r=n ans=-1 while l<=r: mid=l+(r-l)//2 count=[0]*(n) # print(mid) for i in range(mid): count[days[i]-1]+=1 zeroz=0 t=True # print(...
53
139
12,492,800
192753286
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def binary_search(c1, c2): c = (c1 + c2 + 1) // 2 while abs(c1 - c2) > 1: c = (c1 + c2 + 1) // 2 if ok(c): c2 = c else: c1 = c c = max(c - 1, 0) while not ok(c): c += ...
Codeforces Round 377 (Div. 2)
CF
2,016
1
256
Exams
Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On e...
The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of days in the exam period and the number of subjects. The second line contains n integers d1, d2, ..., dn (0 ≤ di ≤ m), where di is the number of subject, the exam of which can be passed on the day number i. If di equals 0, it is not allowed t...
Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1.
null
In the first example Vasiliy can behave as follows. On the first and the second day he can prepare for the exam number 1 and pass it on the fifth day, prepare for the exam number 2 on the third day and pass it on the fourth day. In the second example Vasiliy should prepare for the exam number 3 during the first four d...
[{"input": "7 2\n0 1 0 2 1 0 2\n2 1", "output": "5"}, {"input": "10 3\n0 0 1 2 3 0 2 0 1 2\n1 1 4", "output": "9"}, {"input": "5 1\n1 1 1 1 1\n5", "output": "-1"}]
1,700
["binary search", "greedy", "sortings"]
53
[{"input": "7 2\r\n0 1 0 2 1 0 2\r\n2 1\r\n", "output": "5\r\n"}, {"input": "10 3\r\n0 0 1 2 3 0 2 0 1 2\r\n1 1 4\r\n", "output": "9\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n5\r\n", "output": "-1\r\n"}, {"input": "100 10\r\n1 1 6 6 6 2 5 7 6 5 3 7 10 10 8 9 7 6 9 2 6 7 8 6 7 5 2 5 10 1 10 1 8 10 2 9 7 1 6 8 3 10 9 4 4 8 8...
false
stdio
null
true
3/B
3
B
Python 3
TESTS
12
842
14,233,600
91114214
import sys n, v = sys.stdin.readline().strip().split() n = int(n) v = int(v) lines = [] for i in range(0, n): lines.append(sys.stdin.readline().strip()) vehicles = [] for index, vehicle in enumerate(lines): typ, capacity = vehicle.split() typ = int(typ) capacity = int(capacity) eff = capacity / t...
32
778
12,083,200
78422702
import sys n, v = map(int, input().split()) kayak = [] catam = [] for i in range(0,n): nums = list(map(int, sys.stdin.readline().split())) if nums[0] == 1: kayak.append((nums[1], i + 1)) else: catam.append((nums[1], i + 1)) # sorts by [0] elementwise kayak.sort(key=lambda pair: pair[0]) ca...
Codeforces Beta Round 3
ICPC
2,010
2
64
Lorry
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
The first line contains a pair of integer numbers n and v (1 ≤ n ≤ 105; 1 ≤ v ≤ 109), where n is the number of waterborne vehicles in the boat depot, and v is the truck body volume of the lorry in cubic metres. The following n lines contain the information about the waterborne vehicles, that is a pair of numbers ti, pi...
In the first line print the maximum possible carrying capacity of the set. In the second line print a string consisting of the numbers of the vehicles that make the optimal set. If the answer is not unique, print any of them.
null
null
[{"input": "3 2\n1 2\n2 7\n1 3", "output": "7\n2"}]
1,900
["greedy", "sortings"]
32
[{"input": "3 2\r\n1 2\r\n2 7\r\n1 3\r\n", "output": "7\r\n2\r\n"}, {"input": "5 3\r\n1 9\r\n2 9\r\n1 9\r\n2 10\r\n1 6\r\n", "output": "24\r\n3 1 5\r\n"}, {"input": "10 10\r\n1 14\r\n2 15\r\n2 11\r\n2 12\r\n2 9\r\n1 14\r\n2 15\r\n1 9\r\n2 11\r\n2 6\r\n", "output": "81\r\n6 1 7 2 4 9\r\n"}, {"input": "20 19\r\n2 47\r\n1...
false
stdio
import sys def read_lines(path): with open(path, 'r') as f: return [line.strip() for line in f.readlines() if line.strip()] def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input input_lines = read_lines(input_path) if not input_l...
true
301/C
301
C
PyPy 3
TESTS
0
154
20,172,800
125260427
res = ''' 0??<>1 1??<>2 2??<>3 3??<>4 4??<>5 5??<>6 6??<>7 7??<>8 8??<>9 9??>>??0 ?0>>0? ?1>>1? ?2>>2? ?3>>3? ?4>>4? ?5>>5? ?6>>6? ?7>>7? ?8>>8? ?9>>9? ?>>?? 0>>0? 1>>1? 2>>2? 3>>3? 4>>4? 5>>5? 6>>6? 7>>7? 8>>8? 9>>9? ''' print(res)
23
248
0
56067152
print("0??<>1"); print("1??<>2"); print("2??<>3"); print("3??<>4"); print("4??<>5"); print("5??<>6"); print("6??<>7"); print("7??<>8"); print("8??<>9"); print("9??>>??0"); print("??<>1"); print("?9>>9?"); print("?8>>8?"); print("?7>>7?"); print("?6>>6?"); print("?5>>5?"); print("?4>>4?"); print("?3>>3?"); print("?2>>2?...
Codeforces Round 182 (Div. 1)
CF
2,013
2
256
Yaroslav and Algorithm
Yaroslav likes algorithms. We'll describe one of his favorite algorithms. 1. The algorithm receives a string as the input. We denote this input string as a. 2. The algorithm consists of some number of command. Сommand number i looks either as si >> wi, or as si <> wi, where si and wi are some possibly empty strings of...
The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the set. The next n lines contains one positive integer each. All the given numbers are less than 1025.
Print the algorithm which can individually increase each number of the set. In the i-th line print the command number i without spaces. Your algorithm will be launched for each of these numbers. The answer will be considered correct if: - Each line will a correct algorithm command (see the description in the problem ...
null
null
[{"input": "2\n10\n79", "output": "10<>11\n79<>80"}]
2,500
["constructive algorithms"]
23
[{"input": "2\r\n10\r\n79\r\n", "output": "10<>11\r\n79<>80\r\n"}, {"input": "5\r\n9\r\n99\r\n999\r\n9999\r\n99999\r\n", "output": "0??<>1\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??>>??0\r\n??<>1\r\n?0>>0?\r\n?1>>1?\r\n?2>>2?\r\n?3>>3?\r\n?4>>4?\r\n?5>>5?\r\n?6>>6?\r\n?7>>7?\...
false
stdio
import sys def main(input_path, output_path, submission_output_path): with open(input_path) as f: n = int(f.readline()) numbers = [int(line.strip()) for line in f] commands = [] with open(submission_output_path) as f: for line in f: line = line.strip() if '>...
true
128/B
128
B
Python 3
TESTS
9
842
14,745,600
17777690
from heapq import * l=input() k=int(input()) n=len(l) if k>n*(n+1)/2: print("No such line.") quit() ss=[(l[i],i) for i in range(n)] while k: k-=1 t=heappop(ss) if k==0: print(t[0]) else: if t[1]<n-1: heappush(ss,(t[0]+l[t[1]+1],t[1]+1))
63
404
13,824,000
219201798
def get_input(): s = input() l = len(s) k = int(input()) return s, l, k def find_kth_sum(s, l, k): if l * (l + 1) / 2 < k: return 'No such line.' a = [i for i in range(l)] p = 0 ans = '' while True: t = [(s[i + p], i) for i in a] t = sorted(t) ...
Codeforces Beta Round 94 (Div. 1 Only)
CF
2,011
2
256
String
One day in the IT lesson Anna and Maria learned about the lexicographic order. String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi, and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of the string a. The le...
The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer k (1 ≤ k ≤ 105).
Print the string Anna and Maria need — the k-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than k, print a string saying "No such line." (without the quotes).
null
In the second sample before string "bc" follow strings "a", "ab", "abc", "b".
[{"input": "aa\n2", "output": "a"}, {"input": "abc\n5", "output": "bc"}, {"input": "abab\n7", "output": "b"}]
2,100
["brute force", "constructive algorithms", "hashing", "implementation", "string suffix structures", "strings"]
63
[{"input": "aa\r\n2\r\n", "output": "a\r\n"}, {"input": "abc\r\n5\r\n", "output": "bc\r\n"}, {"input": "abab\r\n7\r\n", "output": "b\r\n"}, {"input": "codeforces\r\n1\r\n", "output": "c\r\n"}, {"input": "cccc\r\n8\r\n", "output": "ccc\r\n"}, {"input": "abcdefghijklmnopqrstuvwxyz\r\n27\r\n", "output": "b\r\n"}, {"input"...
false
stdio
null
true
58/C
58
C
Python 3
TESTS
3
248
0
82570103
n=int(input()) l=list(map(int,input().split())) i=0 j=n-1 x=0 a=l[0] c=0 while i<=j: if x+a!=l[j]: c+=1 j-=1 i+=1 x+=1 print(c)
40
342
14,438,400
86234698
n = int(input()) a = [0] * 100005 l = list(map(int, input().split())) for i in range(n): a[l[i] - min(i, n - i - 1)] += 1 print(n - max(a[1::]))
Codeforces Beta Round 54 (Div. 2)
CF
2,011
2
256
Trees
On Bertown's main street n trees are growing, the tree number i has the height of ai meters (1 ≤ i ≤ n). By the arrival of the President of Berland these trees were decided to be changed so that their heights formed a beautiful sequence. This means that the heights of trees on ends (the 1st one and the n-th one) should...
The first line contains integer n (1 ≤ n ≤ 105) which is the number of trees. The second line contains integers ai (1 ≤ ai ≤ 105) which are the heights of the trees.
Print a single number which is the minimal number of trees whose heights will have to be changed for the sequence to become beautiful.
null
null
[{"input": "3\n2 2 2", "output": "1"}, {"input": "4\n1 2 2 1", "output": "0"}]
1,800
["brute force"]
40
[{"input": "3\r\n2 2 2\r\n", "output": "1\r\n"}, {"input": "4\r\n1 2 2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n61452 50974 73849\r\n", "output": "2\r\n"}, {"input": "4\r\n86002 1199 86003 86002\r\n", "output": "1\r\n"}, {"input": "5\r\n92605 92606 41969 98774 92605\r\n", "output": "2\r\n"}, {"input": "10\r\n1 1 2 3...
false
stdio
null
true
547/D
547
D
Python 3
TESTS
0
30
0
227211410
n = int(input()) points = [] # Read and sort the points based on x-coordinates for _ in range(n): x, y = map(int, input().split()) points.append((x, y)) points.sort() # Initialize variables to keep track of red and blue fish count red_count = 0 blue_count = 0 # Assign colors to points while maintaining the ...
50
889
112,640,000
224152629
from sys import stdin, stdout from collections import defaultdict time = 0 c = 2*10**5 n = 4*10**5+2 col = 0 finished= [0]*n for_node = [0]*n f_range=range f_len=len def dfs_euler_tour(node: int, graph): stack = [] global colour global col global time stack.append((node, -1)) while stack: ...
Codeforces Round 305 (Div. 1)
CF
2,015
3
256
Mike and Fish
As everyone knows, bears love fish. But Mike is a strange bear; He hates fish! The even more strange thing about him is he has an infinite number of blue and red fish. He has marked n distinct points in the plane. i-th point is point (xi, yi). He wants to put exactly one fish in each of these points such that the diff...
The first line of input contains integer n (1 ≤ n ≤ 2 × 105). The next n lines contain the information about the points, i-th line contains two integers xi and yi (1 ≤ xi, yi ≤ 2 × 105), the i-th point coordinates. It is guaranteed that there is at least one valid answer.
Print the answer as a sequence of n characters 'r' (for red) or 'b' (for blue) where i-th character denotes the color of the fish in the i-th point.
null
null
[{"input": "4\n1 1\n1 2\n2 1\n2 2", "output": "brrb"}, {"input": "3\n1 1\n1 2\n2 1", "output": "brr"}]
2,600
["constructive algorithms", "dfs and similar", "graphs"]
50
[{"input": "4\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "brrb\r\n"}, {"input": "3\r\n1 1\r\n1 2\r\n2 1\r\n", "output": "brr\r\n"}, {"input": "3\r\n157210 22861\r\n175396 39466\r\n40933 17093\r\n", "output": "rrr\r\n"}, {"input": "5\r\n55599 84144\r\n169207 98421\r\n1909 186625\r\n31525 147710\r\n7781 82078\r\n", "out...
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: n = int(f.readline()) points = [] for _ in range(n): x, y = map(int, f.readline().split()) points.append((x, y)) ...
true
545/D
545
D
Python 3
TESTS
13
77
10,342,400
229507916
n = int(input()) queue =map(int, input().split()) queue2=set() number_ones=0 for i in queue: if i == 1: number_ones+=1 else: queue2.add(i) queue=sorted(queue2) # print(queue) if number_ones > 1: queue=[1]*2+queue # print(queue) n=len(queue) sum_ = 0 i = 0 while True: if i == n: b...
61
78
13,107,200
225590587
def solve(n): n.sort() count = 0 curr = 0 for num in n: if num < curr: continue count += 1 curr += num return count def main(): t = int(input()) print(solve([int(x) for x in input().split()])) if __name__ == "__main__": main()
Codeforces Round 303 (Div. 2)
CF
2,015
1
256
Queue
Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time whe...
The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces.
Print a single number — the maximum number of not disappointed people in the queue.
null
Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5.
[{"input": "5\n15 2 1 5 3", "output": "4"}]
1,300
["greedy", "implementation", "sortings"]
61
[{"input": "5\r\n15 2 1 5 3\r\n", "output": "4\r\n"}, {"input": "15\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "10\r\n13 2 5 55 21 34 1 8 1 3\r\n", "output": "6\r\n"}, {"input": "10\r\n8 256 16 1 2 1 64 4 128 32\r\n", "output": "10\r\n"}, {"input": "10\r\n10000 40000 10000 50000 20000 100000 1...
false
stdio
null
true
546/B
546
B
PyPy 3-64
TESTS
9
61
1,740,800
232331284
c = int(input()) a = str(input()).split() b = [int(x) for x in a] counter = 0 arr = [] dups = [] for x in b: if x in arr: dups.append(x) else: arr.append(x) for x in dups: while x in arr: x = x + 1 counter += 1 else: continue print(counter)
49
62
307,200
11211283
import sys n = int(input()) if n == 1: print(0) sys.exit(0) l = list(map(int, input().split(" "))) l.sort() min = l[0] val = 0 for i in range(1, len(l)): if l[i] <= l[i-1]: val += 1+l[i-1]-l[i] l[i]+= 1+l[i-1]-l[i] print(val)
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
158/C
158
C
PyPy 3-64
TESTS
6
124
0
231104758
a = int(input("")) d = [] for i in range(a): l = input("") if l == "pwd": [print("/", x, sep="", end = "") for x in d] print("/") else: ll="".join(l[3:]) ll = ll.split("/") #print(ll) for w in ll: if w == "..": d.pop() e...
29
124
0
18858108
class Shell: def __init__(self): self.wd = [''] def cd(self, where: str): glob = where.startswith('/') directories = where.split('/') if directories and not directories[0]: directories.pop(0) if glob: self._reset() for d in directories: ...
VK Cup 2012 Qualification Round 1
CF
2,012
3
256
Cd and pwd commands
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure...
The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Lat...
For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots.
null
null
[{"input": "7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "output": "/\n/home/vasya/\n/home/\n/home/petya/"}, {"input": "4\ncd /a/b\npwd\ncd ../a/b\npwd", "output": "/a/b/\n/a/a/b/"}]
1,400
["*special", "data structures", "implementation"]
29
[{"input": "7\r\npwd\r\ncd /home/vasya\r\npwd\r\ncd ..\r\npwd\r\ncd vasya/../petya\r\npwd\r\n", "output": "/\r\n/home/vasya/\r\n/home/\r\n/home/petya/\r\n"}, {"input": "4\r\ncd /a/b\r\npwd\r\ncd ../a/b\r\npwd\r\n", "output": "/a/b/\r\n/a/a/b/\r\n"}, {"input": "1\r\npwd\r\n", "output": "/\r\n"}, {"input": "2\r\ncd /test...
false
stdio
null
true
432/D
432
D
PyPy 3-64
TESTS
9
249
25,804,800
199431396
import bisect import heapq import sys from types import GeneratorType from functools import cmp_to_key from collections import defaultdict, Counter, deque import math from functools import lru_cache from heapq import nlargest from functools import reduce import random from itertools import combinations from itertools i...
30
108
17,100,800
219090643
s = ' ' + input() n = len(s) r, c = [-1] * n, [1] * n for i in range(1, n): r[i] = r[i - 1] + 1 while r[i] and s[r[i]] != s[i]: r[i] = r[r[i] - 1] + 1 d, n = [], n - 1 for i in range(n, 1, -1): c[r[i]] += c[i] while n > 0: d.append(str(n) + ' ' + str(c[n])) n = r[n] print(len(d)) d.reverse() print(...
Codeforces Round 246 (Div. 2)
CF
2,014
1
256
Prefixes and Suffixes
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: - A substring s[i..j] (1 ≤ i ≤ j ≤ |s|) of string s is string sisi + 1...sj. - The prefix of string s of length l (1 ≤ l ≤ |s|) is string s[1..l]. - The suffix of string s of length ...
The single line contains a sequence of characters s1s2...s|s| (1 ≤ |s| ≤ 105) — string s. The string only consists of uppercase English letters.
In the first line, print integer k (0 ≤ k ≤ |s|) — the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in t...
null
null
[{"input": "ABACABA", "output": "3\n1 4\n3 2\n7 1"}, {"input": "AAA", "output": "3\n1 3\n2 2\n3 1"}]
2,000
["dp", "string suffix structures", "strings", "two pointers"]
30
[{"input": "ABACABA\r\n", "output": "3\r\n1 4\r\n3 2\r\n7 1\r\n"}, {"input": "AAA\r\n", "output": "3\r\n1 3\r\n2 2\r\n3 1\r\n"}, {"input": "A\r\n", "output": "1\r\n1 1\r\n"}, {"input": "AAAAAAAAAAAAAAAAXAAAAAAAAAAAAAAAAAAAAAAA\r\n", "output": "17\r\n1 39\r\n2 37\r\n3 35\r\n4 33\r\n5 31\r\n6 29\r\n7 27\r\n8 25\r\n9 23\r...
false
stdio
null
true
439/B
439
B
PyPy 3
TESTS
3
140
0
66242144
a,b=map(int,input().split()) l=list(map(int,input().split())) l=sorted(l) c=int(b) tot=0 d=0 for i in range(a): if c>0: tot+=l[i]*c elif c<1: break c-=1 if a<=b: print(tot) else: d=(l[(a-b):]) print(sum(d)+tot)
31
93
11,468,800
228681113
def solve(n, x, c): c.sort() s = 0 for t in c: s += t*x x = max(1,x-1) return s n, x = [int(_) for _ in input().split()] c = [int(_) for _ in input().split()] print(solve(n, x, c))
Codeforces Round 251 (Div. 2)
CF
2,014
1
256
Devu, the Dumb Guy
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words he can...
The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105).
Output a single integer representing the answer to the problem.
null
Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ...
[{"input": "2 3\n4 1", "output": "11"}, {"input": "4 2\n5 1 2 1", "output": "10"}, {"input": "3 3\n1 1 1", "output": "6"}]
1,200
["implementation", "sortings"]
31
[{"input": "2 3\r\n4 1\r\n", "output": "11\r\n"}, {"input": "4 2\r\n5 1 2 1\r\n", "output": "10\r\n"}, {"input": "3 3\r\n1 1 1\r\n", "output": "6\r\n"}, {"input": "20 4\r\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3\r\n", "output": "65\r\n"}, {"input": "20 10\r\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3\r\n", "output": "196\...
false
stdio
null
true
489/A
489
A
Python 3
TESTS
5
30
0
227549872
elements = int(input()) arr = [int(i) for i in input().split()] swaps_num = 0 swaps = [] for i in range(elements): for j in range(i, elements): if i == j: continue if arr[i] > arr[j]: swaps_num += 1 temp = arr[i] arr[i] = arr[j] arr[j] = te...
22
78
1,228,800
8721277
__author__ = 'alexandrun' import sys #sys.stdin = open("p1.in", "r") n = int(input()) words = input().split() i = 0 ini = [] for w in words: ini.append((int(w), i)) i += 1 fin = ini[:] fin.sort() #print(ini) #print(fin) pos = {} i = 0 for pair in ini: pos[pair] = i i += 1 swaps = [] ifin = 0 for ...
Codeforces Round 277.5 (Div. 2)
CF
2,014
1
256
SwapSort
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another. Note that in this problem you do not have to minimize the number of sw...
The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≤ ai ≤ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the arr...
In the first line print k (0 ≤ k ≤ n) — the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≤ i, j ≤ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are per...
null
null
[{"input": "5\n5 2 5 1 4", "output": "2\n0 3\n4 2"}, {"input": "6\n10 20 20 40 60 60", "output": "0"}, {"input": "2\n101 100", "output": "1\n0 1"}]
1,200
["greedy", "implementation", "sortings"]
22
[{"input": "5\r\n5 2 5 1 4\r\n", "output": "2\r\n0 3\r\n4 2\r\n"}, {"input": "6\r\n10 20 20 40 60 60\r\n", "output": "0\r\n"}, {"input": "2\r\n101 100\r\n", "output": "1\r\n0 1\r\n"}, {"input": "1\r\n1000\r\n", "output": "0\r\n"}, {"input": "2\r\n1000000000 -1000000000\r\n", "output": "1\r\n0 1\r\n"}, {"input": "8\r\n5...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path) as f: n = int(f.readline().strip()) arr = list(map(int, f.readline().split())) with open(sub_path) as f: lines = f.readlines() if not lines: ...
true
154/A
154
A
PyPy 3
TESTS
4
124
17,715,200
134807402
# Author Name: Ajay Meena # Codeforce : https://codeforces.com/profile/majay1638 import sys import math import bisect import heapq from bisect import bisect_right from sys import stdin, stdout # -------------- INPUT FUNCTIONS ------------------ def get_ints_in_variables(): return map( int, sys.stdin.readline().s...
42
278
2,764,800
186980434
from collections import defaultdict from sys import stdin input = stdin.readline s = input().strip() k = int(input()) ans = 0 for _ in range(k): t = input().strip() a = b = 0 for c in s: if c == t[0]: a += 1 elif c == t[1]: b += 1 else: ans += min(a, b) a = b...
Codeforces Round 109 (Div. 1)
CF
2,012
2
256
Hometask
Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks. Sergey totally forgot about ...
The first line contains a non-empty string s, consisting of lowercase Latin letters — that's the initial sentence in N-ish, written by Sergey. The length of string s doesn't exceed 105. The next line contains integer k (0 ≤ k ≤ 13) — the number of forbidden pairs of letters. Next k lines contain descriptions of forbi...
Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters.
null
In the first sample you should remove two letters b. In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution.
[{"input": "ababa\n1\nab", "output": "2"}, {"input": "codeforces\n2\ndo\ncs", "output": "1"}]
1,600
["greedy"]
42
[{"input": "ababa\r\n1\r\nab\r\n", "output": "2\r\n"}, {"input": "codeforces\r\n2\r\ndo\r\ncs\r\n", "output": "1\r\n"}, {"input": "nllnrlrnll\r\n1\r\nrl\r\n", "output": "1\r\n"}, {"input": "aludfbjtwnkgnfl\r\n1\r\noy\r\n", "output": "0\r\n"}, {"input": "pgpgppgggpbbnnn\r\n2\r\npg\r\nnb\r\n", "output": "7\r\n"}, {"input...
false
stdio
null
true
549/D
549
D
Python 3
TESTS
5
46
0
11490679
import sys def solve(): n, m = map(int, input().split()) res = 0 tab = [list(input()) for _ in range(n)] for row in range(n): for col in range(m): tab[row][col] = 1 if tab[row][col] == 'W' else 0 for row in range(n - 1, -1, -1): for col in range(m - 1, -1, -1): ...
47
155
102,400
11568044
n, m = map(int, input().split(' ')) p = [input() for i in range(n)] p1 = [[1 if p[i][j] == 'B' else -1 for j in range(m)] for i in range(n)] tm = [0 for i in range(m)] r = 0 for i in range(n-1, -1, -1): for j in range(m-1, -1, -1): if tm[j] != p1[i][j]: r = r + 1 tp = p1[i][j] - ...
Looksery Cup 2015
CF
2,015
1
256
Haar Features
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept. Let's consider a rectangular image that is represent...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100) — the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if i...
Print a single number — the minimum number of operations that you need to make to calculate the value of the feature.
null
The first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: 1. add the sum of pixels in...
[{"input": "6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "2"}, {"input": "3 3\nWBW\nBWW\nWWW", "output": "4"}, {"input": "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "output": "3"}, {"input": "4 4\nBBBB\nBBBB\nBBBB\nBBBW", "output": "4"}]
1,900
["greedy", "implementation"]
47
[{"input": "6 8\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nWWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "3 3\r\nWBW\r\nBWW\r\nWWW\r\n", "output": "4\r\n"}, {"input": "3 6\r\nWWBBWW\r\nWWBBWW\r\nWWBBWW\r\n", "output": "3\r\n"}, {"input": "4 4\r\nBBBB\r\nBBBB\r\nBBBB\r\nBBBW\r\n", "output": "4\r\n"}, ...
false
stdio
null
true
925/B
925
B
PyPy 3-64
TESTS
0
46
512,000
144816962
from math import ceil from bisect import bisect_left as bl n,m1,m2=map(int,input().strip().split()) d={m1:0,m2:1} a=[*map(int,input().strip().split())] a=list(zip(a,range(len(a)))) a.sort(key=lambda s:s[0]) val={m1:1111,m2:1111} for i in range(1,n+1): req=ceil(m1/i) ll = bl(a, (req, -1)) if n - ll...
40
1,216
39,219,200
42132645
# python3 def readline(): return tuple(map(int, input().split())) def ceil_div(num, den): return (num - 1) // den + 1 def main(): n, x1, x2 = readline() c = readline() xx = (x1, x2) servers = sorted(enumerate(c, start=1), key=lambda p: p[1]) for (i, a) in enumerate(servers): for (j, x...
VK Cup 2018 - Round 3
CF
2,018
2
256
Resource Distribution
One department of some software company has $$$n$$$ servers of different specifications. Servers are indexed with consecutive integers from $$$1$$$ to $$$n$$$. Suppose that the specifications of the $$$j$$$-th server may be expressed with a single integer number $$$c_j$$$ of artificial resource units. In order for pro...
The first line contains three integers $$$n$$$, $$$x_1$$$, $$$x_2$$$ ($$$2 \leq n \leq 300\,000$$$, $$$1 \leq x_1, x_2 \leq 10^9$$$) — the number of servers that the department may use, and resource units requirements for each of the services. The second line contains $$$n$$$ space-separated integers $$$c_1, c_2, \ldo...
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes). Otherwise print the word "Yes" (without the quotes). In the second line print two integers $$$k_1$$$ and $$$k_2$$$ ($$$1 \leq k_1, k_2 \leq n$$$) — the number of servers used for each of the services. ...
null
In the first sample test each of the servers 1, 2 and 6 will will provide $$$8 / 3 = 2.(6)$$$ resource units and each of the servers 5, 4 will provide $$$16 / 2 = 8$$$ resource units. In the second sample test the first server will provide $$$20$$$ resource units and each of the remaining servers will provide $$$32 / ...
[{"input": "6 8 16\n3 5 2 9 8 7", "output": "Yes\n3 2\n1 2 6\n5 4"}, {"input": "4 20 32\n21 11 11 12", "output": "Yes\n1 3\n1\n2 3 4"}, {"input": "4 11 32\n5 5 16 16", "output": "No"}, {"input": "5 12 20\n7 8 4 11 9", "output": "No"}]
1,700
["binary search", "implementation", "sortings"]
40
[{"input": "6 8 16\r\n3 5 2 9 8 7\r\n", "output": "Yes\r\n4 2\r\n3 1 2 6\r\n5 4\r\n"}, {"input": "4 20 32\r\n21 11 11 12\r\n", "output": "Yes\r\n1 3\r\n1\r\n2 3 4\r\n"}, {"input": "4 11 32\r\n5 5 16 16\r\n", "output": "No\r\n"}, {"input": "5 12 20\r\n7 8 4 11 9\r\n", "output": "No\r\n"}, {"input": "2 1 1\r\n1 1\r\n", "...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n, x1, x2 = map(int, f.readline().split()) c = list(map(int, f.readline().split())) with open(output_path) as f: ref_lines = [line.strip() for line in f] with open(submission_path) a...
true
154/A
154
A
PyPy 3
TESTS
4
248
0
57094042
def is_valid(word, rules): for rule in rules: if rule in word: return False return True class CodeforcesTask154ASolution: def __init__(self): self.result = '' self.word = '' self.rules_count = 0 self.forbidden = [] def read_input(self): self...
42
342
3,072,000
101687730
import sys #input = sys.stdin.readline for _ in range(1): s=input() n=len(s) d={} for _ in range(int(input())): a=input() d[a[0]]=a[1] d[a[1]]=a[0] i=0 ans=0 while i<n: if s[i] in d: a,b=0,0 while True: start=i ...
Codeforces Round 109 (Div. 1)
CF
2,012
2
256
Hometask
Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks. Sergey totally forgot about ...
The first line contains a non-empty string s, consisting of lowercase Latin letters — that's the initial sentence in N-ish, written by Sergey. The length of string s doesn't exceed 105. The next line contains integer k (0 ≤ k ≤ 13) — the number of forbidden pairs of letters. Next k lines contain descriptions of forbi...
Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters.
null
In the first sample you should remove two letters b. In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution.
[{"input": "ababa\n1\nab", "output": "2"}, {"input": "codeforces\n2\ndo\ncs", "output": "1"}]
1,600
["greedy"]
42
[{"input": "ababa\r\n1\r\nab\r\n", "output": "2\r\n"}, {"input": "codeforces\r\n2\r\ndo\r\ncs\r\n", "output": "1\r\n"}, {"input": "nllnrlrnll\r\n1\r\nrl\r\n", "output": "1\r\n"}, {"input": "aludfbjtwnkgnfl\r\n1\r\noy\r\n", "output": "0\r\n"}, {"input": "pgpgppgggpbbnnn\r\n2\r\npg\r\nnb\r\n", "output": "7\r\n"}, {"input...
false
stdio
null
true
560/A
560
A
PyPy 3
TESTS
11
124
0
62326847
n=input() x=input() if(" 1 " in x): print(-1) elif(x[0]=="1"): print(-1) elif(x[len(x)-1]=="1"): print(-1) else: print(1)
16
31
0
146537537
input() a=list(map(int,input().split())) print(-1 if 1 in a else 1)
Codeforces Round 313 (Div. 2)
CF
2,015
2
256
Currency System in Geraldion
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion. The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print - 1.
null
null
[{"input": "5\n1 2 3 4 5", "output": "-1"}]
1,000
["implementation", "sortings"]
16
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "10\r\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837\r\n", "output": "-1\r\n"}, {"input": "10\r\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264\r\n", "output": "1\r\n"}, ...
false
stdio
null
true
154/A
154
A
Python 3
TESTS
4
92
307,200
5544384
t = input() p, n = {}, len(t) for i in range(int(input())): q = input() p[q[0]], p[q[1]] = q[1], q[0] if n == 1: print(0) elif n == 2: print(int(p[t[0]] == t[1])) else: a, b, c = t[0], t[1], t[2] i, s = 3, 0 while True: if a in p and p[a] == b: s += 1 if i > n - 2: br...
42
372
2,662,400
101616018
s=input() ans=0 for _ in range(int(input())): a,b=0,0 p=input() for x in s: if(x==p[0]):a+=1 elif(x==p[1]):b+=1 else: ans+=min(a,b); a,b=0,0 ans+=min(a,b) print(ans)
Codeforces Round 109 (Div. 1)
CF
2,012
2
256
Hometask
Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks. Sergey totally forgot about ...
The first line contains a non-empty string s, consisting of lowercase Latin letters — that's the initial sentence in N-ish, written by Sergey. The length of string s doesn't exceed 105. The next line contains integer k (0 ≤ k ≤ 13) — the number of forbidden pairs of letters. Next k lines contain descriptions of forbi...
Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters.
null
In the first sample you should remove two letters b. In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution.
[{"input": "ababa\n1\nab", "output": "2"}, {"input": "codeforces\n2\ndo\ncs", "output": "1"}]
1,600
["greedy"]
42
[{"input": "ababa\r\n1\r\nab\r\n", "output": "2\r\n"}, {"input": "codeforces\r\n2\r\ndo\r\ncs\r\n", "output": "1\r\n"}, {"input": "nllnrlrnll\r\n1\r\nrl\r\n", "output": "1\r\n"}, {"input": "aludfbjtwnkgnfl\r\n1\r\noy\r\n", "output": "0\r\n"}, {"input": "pgpgppgggpbbnnn\r\n2\r\npg\r\nnb\r\n", "output": "7\r\n"}, {"input...
false
stdio
null
true
455/B
455
B
PyPy 3-64
TESTS
4
62
0
216139921
def is_winner(words, k): # Check if all the words have the same parity of lengths (either all even or all odd). is_all_even = all(len(word) % 2 == 0 for word in words) is_all_odd = all(len(word) % 2 == 1 for word in words) # If all the words have the same parity, the winner of the last game depends on ...
75
701
41,984,000
229069437
max_alpha = 26 class TrieNode: def __init__(self): self.children = [0] * max_alpha def add_trie(root, word): v = root for char in word: c = ord(char) - ord('a') if not v.children[c]: v.children[c] = TrieNode() v = v.children[c] def dfs(v): v.win = False ...
Codeforces Round 260 (Div. 1)
CF
2,014
1
256
A Lot of Games
Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players. Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his step player must add a single letter in the end of the word, the re...
The first line contains two integers, n and k (1 ≤ n ≤ 105; 1 ≤ k ≤ 109). Each of the next n lines contains a single non-empty string from the given group. The total length of all strings from the group doesn't exceed 105. Each string of the group consists only of lowercase English letters.
If the player who moves first wins, print "First", otherwise print "Second" (without the quotes).
null
null
[{"input": "2 3\na\nb", "output": "First"}, {"input": "3 1\na\nb\nc", "output": "First"}, {"input": "1 2\nab", "output": "Second"}]
1,900
["dfs and similar", "dp", "games", "implementation", "strings", "trees"]
75
[{"input": "2 3\r\na\r\nb\r\n", "output": "First\r\n"}, {"input": "3 1\r\na\r\nb\r\nc\r\n", "output": "First\r\n"}, {"input": "1 2\r\nab\r\n", "output": "Second\r\n"}, {"input": "5 6\r\nabas\r\ndsfdf\r\nabacaba\r\ndartsidius\r\nkolobok\r\n", "output": "Second\r\n"}, {"input": "4 2\r\naaaa\r\nbbbb\r\nccccc\r\ndumbavumba...
false
stdio
null
true
562/F
566
A
PyPy 3
TESTS
0
93
0
12331028
SIGMA = 26 class Node: def __init__(self): self.ch = [None] * SIGMA self.a = [] self.b = [] def add(self, s, i): t = self for c in s: v = ord(c) - ord('a') if not t.ch[v]: t.ch[v] = Node() t = t.ch[v] t.a += [i...
38
1,372
262,553,600
12334711
import sys class Node: def __init__(self, d): global nodes self.ch = {} self.a = [[], []] self.d = d nodes += [self] nodes = [] pairs = [] res = 0 N = int(sys.stdin.readline()) _input = sys.stdin.readlines() _input = [s[:-1] for s in _input] A = [_input[:N], _input[N:]] T ...
VK Cup 2015 - Finals
CF
2,015
2
256
Matching Names
Teachers of one programming summer school decided to make a surprise for the students by giving them names in the style of the "Hobbit" movie. Each student must get a pseudonym maximally similar to his own name. The pseudonym must be a name of some character of the popular saga and now the teachers are busy matching ps...
The first line contains number n (1 ≤ n ≤ 100 000) — the number of students in the summer school. Next n lines contain the name of the students. Each name is a non-empty word consisting of lowercase English letters. Some names can be repeating. The last n lines contain the given pseudonyms. Each pseudonym is a non-em...
In the first line print the maximum possible quality of matching pseudonyms to students. In the next n lines describe the optimal matching. Each line must have the form a b (1 ≤ a, b ≤ n), that means that the student who was number a in the input, must match to the pseudonym number b in the input. The matching should...
null
The first test from the statement the match looks as follows: - bill  →  bilbo (lcp = 3) - galya  →  galadriel (lcp = 3) - gennady  →  gendalf (lcp = 3) - toshik  →  torin (lcp = 2) - boris  →  smaug (lcp = 0)
[{"input": "5\ngennady\ngalya\nboris\nbill\ntoshik\nbilbo\ntorin\ngendalf\nsmaug\ngaladriel", "output": "11\n4 1\n2 5\n1 3\n5 2\n3 4"}]
2,300
[]
38
[{"input": "5\r\ngennady\r\ngalya\r\nboris\r\nbill\r\ntoshik\r\nbilbo\r\ntorin\r\ngendalf\r\nsmaug\r\ngaladriel\r\n", "output": "11\r\n4 1\r\n2 5\r\n1 3\r\n5 2\r\n3 4\r\n"}, {"input": "1\r\na\r\na\r\n", "output": "1\r\n1 1\r\n"}, {"input": "2\r\na\r\na\r\na\r\na\r\n", "output": "2\r\n1 1\r\n2 2\r\n"}, {"input": "2\r\na...
false
stdio
import sys def lcp(s, t): min_len = min(len(s), len(t)) cnt = 0 for i in range(min_len): if s[i] == t[i]: cnt += 1 else: break return cnt def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input ...
true
436/C
436
C
PyPy 3
TESTS
8
171
23,142,400
87968019
def put(): return map(int, input().split()) def diff(x,y): ans = 0 for i in range(n*m): if s[x][i]!= s[y][i]: ans+=1 return ans def find(i): if i==p[i]: return i p[i] = find(p[i]) return p[i] def union(i,j): if rank[i]>rank[j]: i,j = j,i elif rank[...
30
1,466
70,041,600
87968659
def put(): return map(int, input().split()) def diff(x,y): ans = 0 for i in range(n*m): if s[x][i]!= s[y][i]: ans+=1 return ans def find(i): if i==p[i]: return i p[i] = find(p[i]) return p[i] def union(i,j): if rank[i]>rank[j]: i,j = j,i elif rank[...
Zepto Code Rush 2014
CF
2,014
2
256
Dungeons and Candies
During the loading of the game "Dungeons and Candies" you are required to get descriptions of k levels from the server. Each description is a map of an n × m checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if a cell ...
The first line contains four integers n, m, k, w (1 ≤ n, m ≤ 10; 1 ≤ k, w ≤ 1000). Then follows the description of k levels. Each level is described by n lines, each line contains m characters. Each character is either a letter of the English alphabet or a dot ("."). Please note that the case of the letters matters.
In the first line print the required minimum number of transferred bytes. Then print k pairs of integers x1, y1, x2, y2, ..., xk, yk, describing the way to transfer levels. Pair xi, yi means that level xi needs to be transferred by way yi. If yi equals 0, that means that the level must be transferred using the first w...
null
null
[{"input": "2 3 3 2\nA.A\n...\nA.a\n..C\nX.Y\n...", "output": "14\n1 0\n2 1\n3 1"}, {"input": "1 1 4 1\nA\n.\nB\n.", "output": "3\n1 0\n2 0\n4 2\n3 0"}, {"input": "1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB", "output": "11\n1 0\n3 1\n2 3\n4 2\n5 1"}]
1,800
["dsu", "graphs", "greedy", "trees"]
30
[{"input": "2 3 3 2\r\nA.A\r\n...\r\nA.a\r\n..C\r\nX.Y\r\n...\r\n", "output": "14\r\n1 0\r\n2 1\r\n3 1\r\n"}, {"input": "1 1 4 1\r\nA\r\n.\r\nB\r\n.\r\n", "output": "3\r\n1 0\r\n2 0\r\n4 2\r\n3 0\r\n"}, {"input": "1 3 5 2\r\nABA\r\nBBB\r\nBBA\r\nBAB\r\nABB\r\n", "output": "11\r\n1 0\r\n3 1\r\n2 3\r\n4 2\r\n5 1\r\n"}, {...
false
stdio
import sys def read_levels(input_path): with open(input_path) as f: lines = [line.strip() for line in f.readlines() if line.strip()] first_line = lines[0].split() n, m, k, w = map(int, first_line) levels = [None] # 1-based indexing idx = 1 for _ in range(k): level = [] ...
true
985/C
985
C
Python 3
TESTS
7
202
8,192,000
38517262
from bisect import bisect_right def bad(): print(0) exit() n, k, l_ = map(int, input().split()) a = sorted(list(map(int, input().split()))) if n == 1: print(min(a)) exit() if a[1] - a[0] > l_: bad() b = bisect_right(a, a[0] + l_) if b < n: bad() to_sum = [0] if n == 2: print(a[0] +...
50
93
14,131,200
215825613
import sys input = sys.stdin.readline n, k, l = map(int, input().split()) a = list(map(int, input().split())) a.sort() ans = 0 c = 0 for i in range(n * k - 1, -1, -1 ): c += 1 if(a[i] - a[0] <= l and c >= k): ans += a[i] c -= k print((ans, 0)[c > 0])
Educational Codeforces Round 44 (Rated for Div. 2)
ICPC
2,018
2
256
Liebig's Barrels
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel. Let volume vj of barrel j be equal to the length of the minimal stave in it. You want to assemble exac...
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109). The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
null
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3]. In the second example you can form the following barrels: [10], [10]. In the third example you can form the following barrels: [2, 5]. In the fourth example difference between volumes of barrels in any partition is at least 2 so...
[{"input": "4 2 1\n2 2 1 2 3 2 2 3", "output": "7"}, {"input": "2 1 0\n10 10", "output": "20"}, {"input": "1 2 1\n5 2", "output": "2"}, {"input": "3 2 1\n1 2 3 4 5 6", "output": "0"}]
1,500
["greedy"]
50
[{"input": "4 2 1\r\n2 2 1 2 3 2 2 3\r\n", "output": "7\r\n"}, {"input": "2 1 0\r\n10 10\r\n", "output": "20\r\n"}, {"input": "1 2 1\r\n5 2\r\n", "output": "2\r\n"}, {"input": "3 2 1\r\n1 2 3 4 5 6\r\n", "output": "0\r\n"}, {"input": "10 3 189\r\n267 697 667 4 52 128 85 616 142 344 413 660 962 194 618 329 266 593 558 4...
false
stdio
null
true