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
659/D
659
D
Python 3
TESTS
5
93
307,200
90257773
n = int(input()) a = [] counter = 0 for i in range(n+1): x, y = list(map(int, input().split())) a.append([x, y]) north_prev = 0 east_prev = 0 north_now = a[1][1] - a[0][1] east_now = a[2][0] - a[1][0] repeat = False for i in range(3, n+1): if i % 2: north_prev = north_now north_now = a[i][1]...
22
46
0
181740397
from sys import stdin , stdout input=stdin.readline def print(*args, end='\n', sep=' ') -> None: stdout.write(sep.join(map(str, args)) + end) last=[] ; n=int(input()) ; dir="" ; ans=0 for i in range(n): x,y=map(int,input().split()) if i==0: last.append((x,y)) continue las=last[-1] ...
Codeforces Round 346 (Div. 2)
CF
2,016
1
256
Bicycle Race
Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west. Let's introduce a system of coordinates, directing the Ox axis from west to east, and th...
The first line of the input contains an integer n (4 ≤ n ≤ 1000) — the number of straight sections of the track. The following (n + 1)-th line contains pairs of integers (xi, yi) ( - 10 000 ≤ xi, yi ≤ 10 000). The first of these points is the starting position. The i-th straight section of the track begins at the poin...
Print a single integer — the number of dangerous turns on the track.
null
The first sample corresponds to the picture: The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1.
[{"input": "6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0", "output": "1"}, {"input": "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1", "output": "6"}]
1,500
["geometry", "implementation", "math"]
22
[{"input": "6\r\n0 0\r\n0 1\r\n1 1\r\n1 2\r\n2 2\r\n2 0\r\n0 0\r\n", "output": "1\r\n"}, {"input": "16\r\n1 1\r\n1 5\r\n3 5\r\n3 7\r\n2 7\r\n2 9\r\n6 9\r\n6 7\r\n5 7\r\n5 3\r\n4 3\r\n4 4\r\n3 4\r\n3 2\r\n5 2\r\n5 1\r\n1 1\r\n", "output": "6\r\n"}, {"input": "4\r\n-10000 -10000\r\n-10000 10000\r\n10000 10000\r\n10000 -1...
false
stdio
null
true
66/C
66
C
Python 3
TESTS
40
248
1,536,000
80969503
folders = {} def calculate_sum(folder): if folders[folder][2] != -1: return [folders[folder][2], folders[folder][3]] num_folders = len(folders[folder][0]) num_files = folders[folder][1] for sub_folder in folders[folder][0]: sub_folder_info = calculate_sum(sub_folder) num_fo...
100
124
512,000
176420212
from collections import * from sys import * txt = stdin.readlines() for i in range(len(txt)): txt[i] = txt[i][:-1].replace(':\\', ':').split('\\') file = Counter([s[0] for s in txt]) folder = defaultdict(set) for i in txt: for j in range(2, len(i)): folder[i[0]].add('\\'.join(i[1:j])) print(max([len(i)...
Codeforces Beta Round 61 (Div. 2)
CF
2,011
3
256
Petya and File System
Recently, on a programming lesson little Petya showed how quickly he can create files and folders on the computer. But he got soon fed up with this activity, and he decided to do a much more useful thing. He decided to calculate what folder contains most subfolders (including nested folders, nested folders of nested fo...
Each line of input data contains the description of one file path. The length of each line does not exceed 100, and overall there are no more than 100 lines. It is guaranteed, that all the paths are correct and meet the above rules. It is also guaranteed, that there are no two completely equal lines. That is, each file...
Print two space-separated numbers. The first one is the maximal number of possible subfolders in a folder (including nested folders, nested folders of nested folders, and so on). The second one is the maximal number of files in a folder (including nested files in subfolders). Note that the disks are not regarded as fol...
null
In the first sample we have one folder on the "C" disk. It has no subfolders, which is why the first number in the answer is 0. But this folder contains one file, so the second number of the answer is 1. In the second sample we have several different folders. Consider the "folder1" folder on the "C" disk. This folder ...
[{"input": "C:\n\\\nfolder1\n\\\nfile1.txt", "output": "0 1"}, {"input": "C:\n\\\nfolder1\n\\\nfolder2\n\\\nfolder3\n\\\nfile1.txt\nC:\n\\\nfolder1\n\\\nfolder2\n\\\nfolder4\n\\\nfile1.txt\nD:\n\\\nfolder1\n\\\nfile1.txt", "output": "3 2"}, {"input": "C:\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile.txt\nC:\n\\\nfi...
1,800
["data structures", "implementation"]
100
[{"input": "C:\\folder1\\file1.txt\r\n", "output": "0 1\r\n"}, {"input": "C:\\folder1\\folder2\\folder3\\file1.txt\r\nC:\\folder1\\folder2\\folder4\\file1.txt\r\nD:\\folder1\\file1.txt\r\n", "output": "3 2\r\n"}, {"input": "C:\\file\\file\\file\\file\\file.txt\r\nC:\\file\\file\\file\\file2\\file.txt\r\n", "output": "4...
false
stdio
null
true
526/D
526
D
PyPy 3-64
TESTS
2
46
0
223305657
def prefix_function(s: str): n = len(s) pi = [0] * n k = 0 for i in range(1, n): while k > 0 and s[i] != s[k]: k = pi[k - 1] if s[i] == s[k]: k += 1 pi[i] = k return pi n, k = map(int, input().split()) s = input() pi = prefix_function(s) ans = [0] * n beg = 0 while beg < n: L = beg...
57
499
57,241,600
216471771
def readints(): return map(int, input().split()) # https://cp-algorithms.com/string/z-function.html#implementation def z_function(n, s): z = [0] * n l, r = 0, 0 for i in range(1, n): if i < r: z[i] = min(r - i, z[i - l]) while i + z[i] < n and s[z[i]] == s[i + z[i]]: ...
ZeptoLab Code Rush 2015
CF
2,015
1
256
Om Nom and Necklace
One day Om Nom found a thread with n beads of different colors. He decided to cut the first several beads from this thread to make a bead necklace and present it to his girlfriend Om Nelly. Om Nom knows that his girlfriend loves beautiful patterns. That's why he wants the beads on the necklace to form a regular patter...
The first line contains two integers n, k (1 ≤ n, k ≤ 1 000 000) — the number of beads on the thread that Om Nom found and number k from the definition of the regular sequence above. The second line contains the sequence of n lowercase Latin letters that represent the colors of the beads. Each color corresponds to a s...
Print a string consisting of n zeroes and ones. Position i (1 ≤ i ≤ n) must contain either number one if the first i beads on the thread form a regular sequence, or a zero otherwise.
null
In the first sample test a regular sequence is both a sequence of the first 6 beads (we can take A = "", B = "bca"), and a sequence of the first 7 beads (we can take A = "b", B = "ca"). In the second sample test, for example, a sequence of the first 13 beads is regular, if we take A = "aba", B = "ba".
[{"input": "7 2\nbcabcab", "output": "0000011"}, {"input": "21 2\nababaababaababaababaa", "output": "000110000111111000011"}]
2,200
["hashing", "string suffix structures", "strings"]
57
[{"input": "7 2\r\nbcabcab\r\n", "output": "0000011"}, {"input": "21 2\r\nababaababaababaababaa\r\n", "output": "000110000111111000011"}, {"input": "321 2\r\nabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaaba...
false
stdio
null
true
976/D
976
D
PyPy 3
TESTS
7
780
58,470,400
128555141
import sys input = sys.stdin.readline n = int(input()) d = list(map(int, input().split())) if n == 1: x = d[0] + 1 m = x * (x - 1) // 2 uv = [] for i in range(1, x + 1): for j in range(i + 1, x + 1): uv.append((i, j)) else: x = d[-1] + 1 uv = set() for i in range(1, x + ...
20
404
41,369,600
185946267
n=int(input()) a=list(map(int,input().split())) def solve(d): if len(d)==0: return [] if len(d)==1: edge=[] m=d[0] for i in range(1,m+2): for j in range(i+1,m+2): edge.append((i,j)) return edge e=[] m=len(d) d0=d[0] for i in range(1,m-1): e.append(d[i]-d0) edge=so...
Educational Codeforces Round 43 (Rated for Div. 2)
ICPC
2,018
2
256
Degree Set
You are given a sequence of n positive integers d1, d2, ..., dn (d1 < d2 < ... < dn). Your task is to construct an undirected graph such that: - there are exactly dn + 1 vertices; - there are no self-loops; - there are no multiple edges; - there are no more than 106 edges; - its degree set is equal to d. Vertices sho...
The first line contains one integer n (1 ≤ n ≤ 300) — the size of the degree set. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 1000, d1 < d2 < ... < dn) — the degree set.
In the first line print one integer m (1 ≤ m ≤ 106) — the number of edges in the resulting graph. It is guaranteed that there exists such a graph that all the conditions hold and it contains no more than 106 edges. Each of the next m lines should contain two integers vi and ui (1 ≤ vi, ui ≤ dn + 1) — the description o...
null
null
[{"input": "3\n2 3 4", "output": "8\n3 1\n4 2\n4 5\n2 5\n5 1\n3 2\n2 1\n5 3"}, {"input": "3\n1 2 3", "output": "4\n1 2\n1 3\n1 4\n2 3"}]
2,500
["constructive algorithms", "graphs", "implementation"]
20
[{"input": "3\r\n2 3 4\r\n", "output": "8\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n2 3\r\n2 4\r\n2 5\r\n3 4\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "4\r\n1 2\r\n1 3\r\n1 4\r\n2 3\r\n"}, {"input": "4\r\n1 3 4 6\r\n", "output": "11\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n1 6\r\n1 7\r\n2 3\r\n2 4\r\n2 5\r\n3 4\r\n3 5\r\n"}, {"input": "...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: n = int(f.readline()) d_list = list(map(int, f.readline().split())) with open(submission_path) as f: lines = f.read().splitlines() if not lines: print(0) return ...
true
359/D
359
D
PyPy 3
TESTS
8
483
39,116,800
79305984
n = int(input()) l = [int(j) for j in input().split()] m = sorted(zip(l, [i for i in range(n)])) visited = [False for i in range(n)] stack = [m[0]] i_ = 0 ans = [0, set([1])] while(stack): # i_+=1 val, ind = stack.pop() i_+=1 if visited[ind]==True: continue visited[ind]=True lf = ind-1 rt = ind+1 while(lf>-1)...
66
655
57,446,400
128389594
def gcd(a, b): if a > b: a, b = b, a if b % a==0: return a return gcd(b % a, a) def process(A): n = len(A) answer = [0, [1]] working = [[A[0], 0]] current = {A[0]: 0} for i in range(1, n): next_working = [] next_current = {} for g, index in workin...
Codeforces Round 209 (Div. 2)
CF
2,013
2
256
Pair of Numbers
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: 1. there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; 2. value r - l takes the maximum valu...
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
null
In the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3. In the second sample all numbers are divisible by number 1. In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
[{"input": "5\n4 6 9 3 6", "output": "1 3\n2"}, {"input": "5\n1 3 5 7 9", "output": "1 4\n1"}, {"input": "5\n2 3 5 7 11", "output": "5 0\n1 2 3 4 5"}]
2,000
["binary search", "brute force", "data structures", "math", "two pointers"]
66
[{"input": "5\r\n4 6 9 3 6\r\n", "output": "1 3\r\n2 \r\n"}, {"input": "5\r\n1 3 5 7 9\r\n", "output": "1 4\r\n1 \r\n"}, {"input": "5\r\n2 3 5 7 11\r\n", "output": "5 0\r\n1 2 3 4 5 \r\n"}, {"input": "1\r\n1343\r\n", "output": "1 0\r\n1 \r\n"}, {"input": "1\r\n1000000\r\n", "output": "1 0\r\n1 \r\n"}, {"input": "1\r\n5...
false
stdio
null
true
884/A
884
A
Python 3
TESTS
4
46
0
184511155
l = input() l = l.split() n = int(l[0]) m = int(l[1]) p = list(map(int, input().split())) sec = 86400 c = 0 for i in range(n): seco = sec - int(p[i]) if(int(l[1]) <= seco): c += 1 break elif(int(l[1]) > seco): c += 1 print(c)
16
31
0
193751344
n, t = map(int, input().split()) l = list(map(int, input().split())) x, i = 0, 0 while x < t: x = x + 86400 - l[i] i += 1 print(i)
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
884/A
884
A
PyPy 3-64
TESTS
4
46
0
166794828
n, t = (int(el) for el in input().split()) a = [int(el) for el in input().split()] res = 0 for i in range(0, n): if t - (86400 - a[i]) <= 0: res += 1 break res += 1 print(res)
16
31
0
208619567
n,t=map(int,input().split()) b=[86400-int(i) for i in input().split()] for i in range(n): if t<=b[i]: print(i+1) break b[i+1]+=b[i]
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
61/D
61
D
PyPy 3-64
TESTS
6
62
614,400
223629301
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb alph = 'abcdefghijklmnopqrstuvwxyz' #pow(x,mod-2,mod) def dfs(i): ans = 0 ...
56
529
17,715,200
178905249
q={1:0} l=[] a=0 for i in range(int(input())-1): x,y,w=map(int,input().split()) a+=2*w if x>y: x,y=y,x l+=[[x,y,w]] l.sort() for i in l: q[i[1]]=q[i[0]]+i[2] print(a-max(q.values()))
Codeforces Beta Round 57 (Div. 2)
CF
2,011
2
256
Eternal Victory
Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal! He decided to visit all n cities of Persia to find the best available mountain, but after the recent war he was too ti...
First line contains a single natural number n (1 ≤ n ≤ 105) — the amount of cities. Next n - 1 lines contain 3 integer numbers each xi, yi and wi (1 ≤ xi, yi ≤ n, 0 ≤ wi ≤ 2 × 104). xi and yi are two ends of a road and wi is the length of that road.
A single integer number, the minimal length of Shapur's travel. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
null
null
[{"input": "3\n1 2 3\n2 3 4", "output": "7"}, {"input": "3\n1 2 3\n1 3 3", "output": "9"}]
1,800
["dfs and similar", "graphs", "greedy", "shortest paths", "trees"]
56
[{"input": "3\r\n1 2 3\r\n2 3 4\r\n", "output": "7\r\n"}, {"input": "3\r\n1 2 3\r\n1 3 3\r\n", "output": "9\r\n"}, {"input": "5\r\n5 3 60\r\n4 3 63\r\n2 1 97\r\n3 1 14\r\n", "output": "371\r\n"}, {"input": "3\r\n2 1 63\r\n3 1 78\r\n", "output": "204\r\n"}, {"input": "13\r\n8 2 58\r\n2 1 49\r\n13 10 41\r\n11 9 67\r\n6 4...
false
stdio
null
true
358/C
358
C
PyPy 3-64
TESTS
5
46
614,400
149209907
#!/usr/bin/env python3 from collections import deque stack = deque() queue = deque() deck = deque() # stack.pop(), stack.append() # queue.appendleft, queue.pop() commands = int(input()) for i in range(commands): command = int(input()) if command == 0: total = 0 numExtract = 0 todo =...
26
826
12,800,000
149773930
n = int(input()) last_zero, largest, nd_largest, rd_largest = -1, -1, -1, -1 arr = [int(input()) for _ in range(n)] for i in range(n): if arr[i] == 0: filled_stk, filled_queue, filled_front = False, False, False for j in range(last_zero + 1, i): if arr[j] == largest and not filled_stk: ...
Codeforces Round 208 (Div. 2)
CF
2,013
2
256
Dima and Containers
Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck. Inna wants her present to show Dima how great a programmer he is. For that, she is going to g...
The first line contains integer n (1 ≤ n ≤ 105) — the number of Inna's commands. Then n lines follow, describing Inna's commands. Each line consists an integer: 1. Integer a (1 ≤ a ≤ 105) means that Inna gives Dima a command to add number a into one of containers. 2. Integer 0 shows that Inna asks Dima to make at most...
Each command of the input must correspond to one line of the output — Dima's action. For the command of the first type (adding) print one word that corresponds to Dima's choice: - pushStack — add to the end of the stack; - pushQueue — add to the end of the queue; - pushFront — add to the beginning of the deck; - push...
null
null
[{"input": "10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0", "output": "0\npushStack\n1 popStack\npushStack\npushQueue\n2 popStack popQueue\npushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}, {"input": "4\n1\n2\n3\n0", "output": "pushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}]
2,000
["constructive algorithms", "greedy", "implementation"]
26
[{"input": "10\r\n0\r\n1\r\n0\r\n1\r\n2\r\n0\r\n1\r\n2\r\n3\r\n0\r\n", "output": "0\r\npushStack\r\n1 popStack\r\npushStack\r\npushQueue\r\n2 popStack popQueue\r\npushStack\r\npushQueue\r\npushFront\r\n3 popStack popQueue popFront\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n0\r\n", "output": "pushStack\r\npushQueue\r\npushFr...
false
stdio
import sys from collections import deque def main(input_path, output_path, submission_path): with open(input_path) as f: input_lines = f.read().splitlines() n = int(input_lines[0]) input_commands = input_lines[1:n+1] with open(submission_path) as f: submission_lines = [line.strip()...
true
609/D
609
D
PyPy 3
TESTS
4
77
0
159973234
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from itertools import accumulate n, m, k, s = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = [] D = [] T = [] for i in range(m): t, c = map(int, input().split()) T.appen...
51
1,872
56,627,200
170715074
import sys readline=sys.stdin.readline def Bisect_Int(ok,ng,is_ok): while abs(ok-ng)>1: mid=(ok+ng)//2 if is_ok(mid): ok=mid else: ng=mid return ok N,M,K,S=map(int,readline().split()) A=list(map(int,readline().split())) B=list(map(int,readline().split())) C=[lis...
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
766/C
766
C
PyPy 3
TESTS
3
93
1,740,800
217013773
n = int(input()) s= input() arr = [0]+[x for x in s] char = list(map(int,input().split())) dp = [[0 for i in range(3)]for j in range(n+2)] for i in range(1,len(arr)): dp[i][1] = float("-inf") dp[i][2] = float("inf") dp[0][0] =1 for i in range(1,len(arr)): limit = float("inf") for j in range(i,0,-1): limit = min(...
37
77
3,072,000
184419931
mod = int(1e9 + 7) n = int(input()) s = input() nums = list(map(int, input().split())) dp1 = [0] * 1002 dp1[0] = 1 dp2 = [0] * 1002 ans = 0 for i in range(1, n + 1): curr = 0 dp2[i] = n for j in range(i, 0, -1): j -= 1 curr = max(curr, i - nums[ord(s[j]) - 97]) if curr > j: ...
Codeforces Round 396 (Div. 2)
CF
2,017
2
256
Mahmoud and a Message
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alpha...
The first line contains an integer n (1 ≤ n ≤ 103) denoting the length of the message. The second line contains the message s of length n that consists of lowercase English letters. The third line contains 26 integers a1, a2, ..., a26 (1 ≤ ax ≤ 103) — the maximum lengths of substring each letter can appear in.
Print three lines. In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109 + 7. In the second line print the length of the longest substring over all the ways. In the third line print the minimum number of substrings over all th...
null
In the first example the three ways to split the message are: - a|a|b - aa|b - a|ab The longest substrings are "aa" and "ab" of length 2. The minimum number of substrings is 2 in "a|ab" or "aa|b". Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
[{"input": "3\naab\n2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "3\n2\n2"}, {"input": "10\nabcdeabcde\n5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "401\n4\n3"}]
1,700
["brute force", "dp", "greedy", "strings"]
37
[{"input": "3\r\naab\r\n2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n2\r\n2\r\n"}, {"input": "10\r\nabcdeabcde\r\n5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "401\r\n4\r\n3\r\n"}, {"input": "10\r\naaaaaaaaaa\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n"...
false
stdio
null
true
388/C
388
C
Python 3
TESTS
5
93
307,200
69255334
def maior(lista, n): maior = 0 pos = 0 for i in range(n): if lista[i] > maior: maior = lista[i] pos = i return i def main(): nPiles = int(input()) piles = [] for i in range (nPiles): line = list(map(int, input().split(' '))) piles.append(line[1:]) ciel = 0 jiro = 0 turn = 1 while piles: ...
43
46
0
203872908
def calc(odd_pile_list): sente_omake = 0 gote_omake = 0 odd_pile_list.sort(key=lambda x:x[(len(x)-1)//2],reverse=True) for i in range(len(odd_pile_list)): if i%2 == 0: sente_omake += sum(odd_pile_list[i][:(len(odd_pile_list[i])+1)//2]) gote_omake += sum(odd_pile_list[i][...
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
358/D
358
D
PyPy 3-64
TESTS
7
61
0
212982063
def rl(): return list(map(int,input().split())) def ri(): return int(input()) def rs(): return input() def rm(): return map(int,input().split()) def main(): n=ri() dp=[[[0 for k in range(n)] for j in range(n)]for i in range(4)] a,b,c=rl(),rl(),rl() for i in range(n-1): dp[0][i][...
29
62
0
7212422
n = int(input()) a, b, c = (list(map(int, input().split())) for i in range(3)) d1, d2 = a[0], b[0] for i in range(1, n): d1, d2 = max(d2 + a[i], d1 + b[i]), max(d2 + b[i], d1 + c[i]) print(d1)
Codeforces Round 208 (Div. 2)
CF
2,013
2
256
Dima and Hares
Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more. Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with ca...
The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an. The second line contains b1, b2, ..., bn. The third line contains c1, c2, ..., cn. The following limits are fulfilled: 0 ≤ ai, bi, ci ≤ 1...
In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.
null
null
[{"input": "4\n1 2 3 4\n4 3 2 1\n0 1 1 0", "output": "13"}, {"input": "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3", "output": "44"}, {"input": "3\n1 1 1\n1 2 1\n1 1 1", "output": "4"}]
1,800
["dp", "greedy"]
29
[{"input": "4\r\n1 2 3 4\r\n4 3 2 1\r\n0 1 1 0\r\n", "output": "13\r\n"}, {"input": "7\r\n8 5 7 6 1 8 9\r\n2 7 9 5 4 3 1\r\n2 3 3 4 1 1 3\r\n", "output": "44\r\n"}, {"input": "3\r\n1 1 1\r\n1 2 1\r\n1 1 1\r\n", "output": "4\r\n"}, {"input": "7\r\n1 3 8 9 3 4 4\r\n6 0 6 6 1 8 4\r\n9 6 3 7 8 8 2\r\n", "output": "42\r\n"}...
false
stdio
null
true
358/C
358
C
Python 3
TESTS
18
1,029
4,096,000
8130127
n = int(input()) inp = [int(input()) for i in range(n)] i = 0 result = [] def fill1(inp,result): arr = sorted(inp[:],reverse=True) max_el = [] k = 0 while k < 3 and k < len(inp): max_el.append(arr[k]) k+=1 l = len(arr) if l == 0: result.append("0") elif l == 1: ...
26
858
10,752,000
138487227
import sys import math from sys import stdin, stdout import heapq # TAKE INPUT def get_ints_in_variables(): return map(int, sys.stdin.readline().strip().split()) def get_int(): return int(input()) def get_ints_in_list(): return list( map(int, sys.stdin.readline().strip().split())) def get_list_of_list(n): ret...
Codeforces Round 208 (Div. 2)
CF
2,013
2
256
Dima and Containers
Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck. Inna wants her present to show Dima how great a programmer he is. For that, she is going to g...
The first line contains integer n (1 ≤ n ≤ 105) — the number of Inna's commands. Then n lines follow, describing Inna's commands. Each line consists an integer: 1. Integer a (1 ≤ a ≤ 105) means that Inna gives Dima a command to add number a into one of containers. 2. Integer 0 shows that Inna asks Dima to make at most...
Each command of the input must correspond to one line of the output — Dima's action. For the command of the first type (adding) print one word that corresponds to Dima's choice: - pushStack — add to the end of the stack; - pushQueue — add to the end of the queue; - pushFront — add to the beginning of the deck; - push...
null
null
[{"input": "10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0", "output": "0\npushStack\n1 popStack\npushStack\npushQueue\n2 popStack popQueue\npushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}, {"input": "4\n1\n2\n3\n0", "output": "pushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}]
2,000
["constructive algorithms", "greedy", "implementation"]
26
[{"input": "10\r\n0\r\n1\r\n0\r\n1\r\n2\r\n0\r\n1\r\n2\r\n3\r\n0\r\n", "output": "0\r\npushStack\r\n1 popStack\r\npushStack\r\npushQueue\r\n2 popStack popQueue\r\npushStack\r\npushQueue\r\npushFront\r\n3 popStack popQueue popFront\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n0\r\n", "output": "pushStack\r\npushQueue\r\npushFr...
false
stdio
import sys from collections import deque def main(input_path, output_path, submission_path): with open(input_path) as f: input_lines = f.read().splitlines() n = int(input_lines[0]) input_commands = input_lines[1:n+1] with open(submission_path) as f: submission_lines = [line.strip()...
true
358/C
358
C
Python 3
TESTS
9
62
0
12114697
from heapq import heappop from heapq import heappush n = int(input()) inp = [] for i in range(n): inp.append(int(input())) heap = [] flg = [0] * n for i in range(n): if(inp[i] != 0): heappush(heap, (-inp[i], i)) else: for j in range(3): if(heap): (tnum, ...
26
920
10,547,200
174939104
# https://codeforces.com/problemset/problem/358/C # Solution credits (Adapted from C++): Sujoy Ghosh def solve(): n = int(input()) inputs = ['pushStack', 'pushQueue', 'pushFront', 'pushBack'] outputs = ['popStack', 'popQueue', 'popFront', 'popBack'] v = [] for _ in range(n): a = int(inpu...
Codeforces Round 208 (Div. 2)
CF
2,013
2
256
Dima and Containers
Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck. Inna wants her present to show Dima how great a programmer he is. For that, she is going to g...
The first line contains integer n (1 ≤ n ≤ 105) — the number of Inna's commands. Then n lines follow, describing Inna's commands. Each line consists an integer: 1. Integer a (1 ≤ a ≤ 105) means that Inna gives Dima a command to add number a into one of containers. 2. Integer 0 shows that Inna asks Dima to make at most...
Each command of the input must correspond to one line of the output — Dima's action. For the command of the first type (adding) print one word that corresponds to Dima's choice: - pushStack — add to the end of the stack; - pushQueue — add to the end of the queue; - pushFront — add to the beginning of the deck; - push...
null
null
[{"input": "10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0", "output": "0\npushStack\n1 popStack\npushStack\npushQueue\n2 popStack popQueue\npushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}, {"input": "4\n1\n2\n3\n0", "output": "pushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}]
2,000
["constructive algorithms", "greedy", "implementation"]
26
[{"input": "10\r\n0\r\n1\r\n0\r\n1\r\n2\r\n0\r\n1\r\n2\r\n3\r\n0\r\n", "output": "0\r\npushStack\r\n1 popStack\r\npushStack\r\npushQueue\r\n2 popStack popQueue\r\npushStack\r\npushQueue\r\npushFront\r\n3 popStack popQueue popFront\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n0\r\n", "output": "pushStack\r\npushQueue\r\npushFr...
false
stdio
import sys from collections import deque def main(input_path, output_path, submission_path): with open(input_path) as f: input_lines = f.read().splitlines() n = int(input_lines[0]) input_commands = input_lines[1:n+1] with open(submission_path) as f: submission_lines = [line.strip()...
true
66/C
66
C
PyPy 3
TESTS
10
310
24,780,800
90679901
_end = '_end_' import sys def add_trie(root,*words): global cnt for word in words: current_dict = root for letter in word: current_dict = current_dict.setdefault(letter, {}) current_dict[_end] = _end return root root=dict() for s in sys.stdin: s=s.split('\\') ...
100
248
409,600
53182679
import sys dic = {} mp = {} x = {} #n = int(input()) #for i in range(n): for si in sys.stdin: #si = input() si = si.strip() ar = si.split('\\') s="" if ar[0] not in dic: dic[ar[0]]={}; #print(ar) #print(dic) if ar[1] not in dic[ar[0]]: dic[ar[0]][ar[1]]=[0,0] s = ar...
Codeforces Beta Round 61 (Div. 2)
CF
2,011
3
256
Petya and File System
Recently, on a programming lesson little Petya showed how quickly he can create files and folders on the computer. But he got soon fed up with this activity, and he decided to do a much more useful thing. He decided to calculate what folder contains most subfolders (including nested folders, nested folders of nested fo...
Each line of input data contains the description of one file path. The length of each line does not exceed 100, and overall there are no more than 100 lines. It is guaranteed, that all the paths are correct and meet the above rules. It is also guaranteed, that there are no two completely equal lines. That is, each file...
Print two space-separated numbers. The first one is the maximal number of possible subfolders in a folder (including nested folders, nested folders of nested folders, and so on). The second one is the maximal number of files in a folder (including nested files in subfolders). Note that the disks are not regarded as fol...
null
In the first sample we have one folder on the "C" disk. It has no subfolders, which is why the first number in the answer is 0. But this folder contains one file, so the second number of the answer is 1. In the second sample we have several different folders. Consider the "folder1" folder on the "C" disk. This folder ...
[{"input": "C:\n\\\nfolder1\n\\\nfile1.txt", "output": "0 1"}, {"input": "C:\n\\\nfolder1\n\\\nfolder2\n\\\nfolder3\n\\\nfile1.txt\nC:\n\\\nfolder1\n\\\nfolder2\n\\\nfolder4\n\\\nfile1.txt\nD:\n\\\nfolder1\n\\\nfile1.txt", "output": "3 2"}, {"input": "C:\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile\n\\\nfile.txt\nC:\n\\\nfi...
1,800
["data structures", "implementation"]
100
[{"input": "C:\\folder1\\file1.txt\r\n", "output": "0 1\r\n"}, {"input": "C:\\folder1\\folder2\\folder3\\file1.txt\r\nC:\\folder1\\folder2\\folder4\\file1.txt\r\nD:\\folder1\\file1.txt\r\n", "output": "3 2\r\n"}, {"input": "C:\\file\\file\\file\\file\\file.txt\r\nC:\\file\\file\\file\\file2\\file.txt\r\n", "output": "4...
false
stdio
null
true
313/C
313
C
PyPy 3-64
TESTS
2
31
0
215366762
n = int(input()) A = list(map(int, input().split())) A.sort(reverse=True) if n == 1: print(A[0]) else: print(A[0] + A[1] + A[2] + A[3] + A[0])
61
576
141,107,200
215367603
n = int(input()) A = list(map(int, input().split())) A.sort(reverse=True) if n == 1: print(A[0]) else: res = 0 i = 1 while(i <= n): res += sum(A[0: i]) i *= 4 print(res)
Codeforces Round 186 (Div. 2)
CF
2,013
1
256
Ilya and Matrix
Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve. He's got a square 2n × 2n-sized matrix and 4n integers. You need to arrange all these numbers in the matrix (put each number in a single individua...
The first line contains integer 4n (1 ≤ 4n ≤ 2·106). The next line contains 4n integers ai (1 ≤ ai ≤ 109) — the numbers you need to arrange in the 2n × 2n-sized matrix.
On a single line print the maximum value of the beauty of the described matrix. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
null
Consider the second sample. You need to arrange the numbers in the matrix as follows: Then the beauty of the matrix will equal: 4 + 1 + 2 + 3 + 4 = 14.
[{"input": "1\n13", "output": "13"}, {"input": "4\n1 2 3 4", "output": "14"}]
1,400
["constructive algorithms", "greedy", "implementation", "sortings"]
61
[{"input": "1\r\n13\r\n", "output": "13\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "14\r\n"}, {"input": "16\r\n978618343 473608041 799158564 800910753 461479363 520477481 780529176 678879534 118274424 720632652 639921017 582019792 143353286 537373229 944668919 758615621\r\n", "output": "14440495117\r\n"}, {"input":...
false
stdio
null
true
289/A
289
A
Python 3
TESTS
6
248
0
60022476
n, k= map(int,input().split()) r = 0 for i in range(n): num = list(map(int,input().split())) r += abs(num[0]-num[1])+1 if r > k: print((-r) % k) elif r<k: print((-k)%r) else: print('0')
28
342
0
212221136
n,k=map(int,input().split()) s=0 for i in range(n): L,R=map(int,input().split()) s+=R-L+1 print((k-s%k)%k)
Codeforces Round 177 (Div. 2)
CF
2,013
2
256
Polo the Penguin and Segments
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the r...
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequal...
In a single line print a single integer — the answer to the problem.
null
null
[{"input": "2 3\n1 2\n3 4", "output": "2"}, {"input": "3 7\n1 2\n3 3\n4 7", "output": "0"}]
1,100
["brute force", "implementation"]
28
[{"input": "2 3\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "3 7\r\n1 2\r\n3 3\r\n4 7\r\n", "output": "0\r\n"}, {"input": "3 7\r\n1 10\r\n11 47\r\n74 128\r\n", "output": "3\r\n"}, {"input": "5 4\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n", "output": "3\r\n"}, {"input": "7 4\r\n2 2\r\n-1 -1\r\n0 1\r\n7 8\r\n-3 -2\r\n9...
false
stdio
null
true
884/A
884
A
Python 3
TESTS
4
61
0
112578342
n,k=map(int,input().split()) l=list(map(int,input().split())) for i in range(len(l)): left=86400-l[i] if left>=k: print(i+1) else: k=k-left
16
31
0
208926956
n, t = map(int, input().split()) moo = list(map(int, input().split())) por = 0 for i in range(n): por += 86400 - moo[i] if por >= t: print(i+1) break
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
662/C
662
C
Python 3
TESTS
5
93
307,200
101096054
l = input().split() n = int(l[0]) m = int(l[1]) lines = [[int(x) for x in input()] for i in range(n)] d = 0 for i in range(n): reversible = True for j in range(m): if lines[i][j] != 1: reversible = False break if reversible: for j in range(m): lines[i]...
37
935
21,401,600
225527037
from functools import reduce n, m = map(int, input().split()) a = [input() for _ in range(n)] a = list(map(lambda x: reduce(lambda x, y: x * 2 + int(y), x, 0), zip(*a))) S = 1 << n f, g = [0] * S, [0] * S for x in a: g[x] += 1 for mask in range(S): k = bin(mask).count('1') f[mask] = min(k, n - k) def walsh_h...
CROC 2016 - Final Round [Private, For Onsite Finalists Only]
CF
2,016
6
256
Binary Table
You are given a table consisting of n rows and m columns. Each cell of the table contains either 0 or 1. In one move, you are allowed to pick any row or any column and invert all values, that is, replace 0 by 1 and vice versa. What is the minimum number of cells with value 1 you can get after applying some number of o...
The first line of the input contains two integers n and m (1 ≤ n ≤ 20, 1 ≤ m ≤ 100 000) — the number of rows and the number of columns, respectively. Then n lines follows with the descriptions of the rows. Each line has length m and contains only digits '0' and '1'.
Output a single integer — the minimum possible number of ones you can get after applying some sequence of operations.
null
null
[{"input": "3 4\n0110\n1010\n0111", "output": "2"}]
2,600
["bitmasks", "brute force", "divide and conquer", "dp", "fft", "math"]
37
[{"input": "3 4\r\n0110\r\n1010\r\n0111\r\n", "output": "2\r\n"}, {"input": "1 1\r\n0\r\n", "output": "0\r\n"}, {"input": "1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n0\r\n1\r\n", "output": "0\r\n"}, {"input": "1 2\r\n10\r\n", "output": "0\r\n"}, {"input": "2 2\r\n01\r\n10\r\n", "output": "0\r\n"}, {"input": "...
false
stdio
null
true
111/B
111
B
PyPy 3-64
TESTS
25
1,310
19,558,400
162909341
from bisect import bisect_left n = int(input()) ls = [list(map(int, input().split())) for _ in range(n)] div = [[] for _ in range(10 ** 5 + 1)] for j in range(n): x = ls[j][0] p = 2 while p * p <= x: if x % p == 0: div[p].append(j) div[x // p].append(j) p += 1 div...
44
872
12,595,200
182600135
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def divisor(i): s = [] for j in range(1, int(i ** (1 / 2)) + 1): if i % j == 0: s.append(i // j) s.append(j) return sorted(set(s)) n = int(input()) l = pow(10, 5) + 5 la = [-1] * l ans = [] for ...
Codeforces Beta Round 85 (Div. 1 Only)
CF
2,011
5
256
Petya and Divisors
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem: You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
The first line contains an integer n (1 ≤ n ≤ 105). Each of the following n lines contain two space-separated integers xi and yi (1 ≤ xi ≤ 105, 0 ≤ yi ≤ i - 1, where i is the query's ordinal number; the numeration starts with 1). If yi = 0 for the query, then the answer to the query will be the number of divisors of t...
For each query print the answer on a single line: the number of positive integers k such that $${ x _ { i } \bmod k = 0 \& ( \forall j : i - y _ { i } \leq j < i ) x _ { j } \bmod k \neq 0 }$$
null
Let's write out the divisors that give answers for the first 5 queries: 1) 1, 2, 4 2) 3 3) 5 4) 2, 6 5) 9, 18
[{"input": "6\n4 0\n3 1\n5 2\n6 2\n18 4\n10000 3", "output": "3\n1\n1\n2\n2\n22"}]
1,900
["binary search", "data structures", "number theory"]
44
[{"input": "6\r\n4 0\r\n3 1\r\n5 2\r\n6 2\r\n18 4\r\n10000 3\r\n", "output": "3\r\n1\r\n1\r\n2\r\n2\r\n22\r\n"}, {"input": "5\r\n10 0\r\n10 0\r\n10 0\r\n10 0\r\n10 0\r\n", "output": "4\r\n4\r\n4\r\n4\r\n4\r\n"}, {"input": "12\r\n41684 0\r\n95210 1\r\n60053 1\r\n32438 3\r\n97956 1\r\n21785 2\r\n14594 6\r\n17170 4\r\n939...
false
stdio
null
true
765/A
765
A
Python 3
TESTS
7
108
0
62687334
a=int(input()) b=input() d=[] for x in range(a): c=list(map(str,input().split('->'))) d.append(c[0]) d.append(c[1]) e=list(set(d)) for x in range(len(e)): if d.count(e[x])%2==0: l=1 else: l=0 if l==1: print('home') else: print('contest')
23
31
0
154946716
n = int(input()) home = input() coordinate = 0 for i in range(0,n): a = input() if (a[5]+a[6]+a[7]) == home: coordinate += 1 else: coordinate -= 1 if coordinate == 0: print('home') else: print('contest')
Codeforces Round 397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
512
Neverending competitions
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
In the first line of input there is a single integer n: the number of Jinotega's flights (1 ≤ n ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next n lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name ...
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
null
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
[{"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home"}, {"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest"}]
900
["implementation", "math"]
23
[{"input": "4\r\nSVO\r\nSVO->CDG\r\nLHR->SVO\r\nSVO->LHR\r\nCDG->SVO\r\n", "output": "home\r\n"}, {"input": "3\r\nSVO\r\nSVO->HKT\r\nHKT->SVO\r\nSVO->RAP\r\n", "output": "contest\r\n"}, {"input": "1\r\nESJ\r\nESJ->TSJ\r\n", "output": "contest\r\n"}, {"input": "2\r\nXMR\r\nFAJ->XMR\r\nXMR->FAJ\r\n", "output": "home\r\n"...
false
stdio
null
true
247/C
250
C
Python 3
TESTS
17
312
7,065,600
5286134
n, k = map(int, input().split()) t = list(map(int, input().split())) t = [t[0]] + [t[i] for i in range(1, len(t)) if t[i] != t[i - 1]] p = [0] * (k + 1) p[t[0]] = p[t[-1]] = 1 for i in range(1, len(t) - 1): if t[i - 1] == t[i + 1]: p[t[i]] += 2 else: p[t[i]] += 1 print(p.index(max(p)))
44
248
14,233,600
183974859
import sys input = sys.stdin.readline from itertools import groupby n, k = map(int, input().split()) d = [list(j)[0] for i, j in groupby(map(int, input().split()))] q = [0]*(k+1) for i in range(len(d)): if i not in [0, len(d)-1] and d[i-1] == d[i+1]: q[d[i]] += 1 q[d[i]] += 1 print(max(1, q.index(max(q...
CROC-MBTU 2012, Final Round
CF
2,012
2
256
Movie Critics
A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival progra...
The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ k), where ai is the genre of the i-th movie. It is guaranteed that each number fr...
Print a single number — the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number.
null
In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses...
[{"input": "10 3\n1 1 2 3 2 3 3 1 1 3", "output": "3"}, {"input": "7 3\n3 1 3 2 3 1 2", "output": "1"}]
1,600
[]
44
[{"input": "10 3\r\n1 1 2 3 2 3 3 1 1 3\r\n", "output": "3"}, {"input": "7 3\r\n3 1 3 2 3 1 2\r\n", "output": "1"}, {"input": "2 2\r\n1 2\r\n", "output": "1"}, {"input": "10 2\r\n1 2 2 1 1 2 1 1 2 2\r\n", "output": "1"}, {"input": "10 10\r\n5 7 8 2 4 10 1 3 9 6\r\n", "output": "1"}, {"input": "100 10\r\n6 2 8 1 7 1 2 9...
false
stdio
null
true
247/C
250
C
PyPy 3
TESTS
17
374
11,878,400
51320585
import sys def input(): return sys.stdin.readline().strip() def print(*x, sep=' ', end='\n'): return sys.stdout.write(sep.join(map(str, x)) + end) def get(): n, k = map(int, input().split()) ls = [0] buff = [int(i) for i in input().split()] for i in buff: ls.append(i) ls.append...
44
374
12,390,400
51267861
n, k = map(int, input().split()) a = [int(i) for i in input().split()] s = [0 for i in range(k)] b = [a[0]] for i in range(1, n): if a[i] == b[-1]: continue else: b.append(a[i]) y = len(b) for i in range(y): if i == 0 and b[i] != b[i + 1]: s[a[0] - 1] += 1 elif i == y - 1 and b[i...
CROC-MBTU 2012, Final Round
CF
2,012
2
256
Movie Critics
A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival progra...
The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ k), where ai is the genre of the i-th movie. It is guaranteed that each number fr...
Print a single number — the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number.
null
In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses...
[{"input": "10 3\n1 1 2 3 2 3 3 1 1 3", "output": "3"}, {"input": "7 3\n3 1 3 2 3 1 2", "output": "1"}]
1,600
[]
44
[{"input": "10 3\r\n1 1 2 3 2 3 3 1 1 3\r\n", "output": "3"}, {"input": "7 3\r\n3 1 3 2 3 1 2\r\n", "output": "1"}, {"input": "2 2\r\n1 2\r\n", "output": "1"}, {"input": "10 2\r\n1 2 2 1 1 2 1 1 2 2\r\n", "output": "1"}, {"input": "10 10\r\n5 7 8 2 4 10 1 3 9 6\r\n", "output": "1"}, {"input": "100 10\r\n6 2 8 1 7 1 2 9...
false
stdio
null
true
662/D
662
D
Python 3
TESTS
3
62
5,120,000
17720094
used_years = [] def find_unused(prefix, num): year = prefix + num global used_years while int(year) in used_years: prefix = str(int(prefix) + 1) year = prefix + num year = int(year) used_years.append(year) return(year) for i in range(int(input())): num = input()[4:] len...
45
78
0
17350653
n = int(input()) for i in range(0,n): s = input() j = s[4:] mi = 10*(10**(len(j)-1) - 1)/9 + 1989 v = int(j); fr = 0 while int(str(fr) + j) < mi: fr+=1 print(str(int(str(fr) + j)))
CROC 2016 - Final Round [Private, For Onsite Finalists Only]
CF
2,016
1
256
International Olympiad
International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Amo...
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits.
For each abbreviation given in the input, find the year of the corresponding Olympiad.
null
null
[{"input": "5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0", "output": "2015\n12015\n1991\n1989\n1990"}, {"input": "4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999", "output": "1989\n1999\n2999\n9999"}]
2,000
["constructive algorithms", "greedy", "implementation", "math"]
45
[{"input": "5\r\nIAO'15\r\nIAO'2015\r\nIAO'1\r\nIAO'9\r\nIAO'0\r\n", "output": "2015\r\n12015\r\n1991\r\n1989\r\n1990\r\n"}, {"input": "4\r\nIAO'9\r\nIAO'99\r\nIAO'999\r\nIAO'9999\r\n", "output": "1989\r\n1999\r\n2999\r\n9999\r\n"}, {"input": "1\r\nIAO'111110\r\n", "output": "1111110\r\n"}, {"input": "2\r\nIAO'0\r\nIAO...
false
stdio
null
true
1004/B
1004
B
Python 3
PRETESTS
3
109
0
40000196
n,m = map(int, input().split()) a = [0]*n for _ in range(m): i,j = map(int, input().split()) i-=1 a[i:j]=[x+1 for x in a[i:j]] s = ['x']*n a1 = max(a) f = 0 while 'x' in s: try: m1 = a.index(a1) while m1 < n: a[m1] -= 1 if s[m1] == 'x': f = 1 - f ...
27
61
0
163462880
import sys input = sys.stdin.readline n, m = map(int, input().split()) for _ in range(m): a, b = map(int, input().split()) print(('01'*n)[:n])
Codeforces Round 495 (Div. 2)
CF
2,018
1
256
Sonya and Exhibition
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $$$n$$$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $$$i$$$-th position. Thus each of $$$n$$$ pos...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\leq n, m\leq 10^3$$$) — the number of flowers and visitors respectively. Each of the next $$$m$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1\leq l_i\leq r_i\leq n$$$), meaning that $$$i$$$-th visitor will visit all flowers from $$$l_i$$$ to ...
Print the string of $$$n$$$ characters. The $$$i$$$-th symbol should be «0» if you want to put a rose in the $$$i$$$-th position, otherwise «1» if you want to put a lily. If there are multiple answers, print any.
null
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions; - in the segment $$$[1\ldots3]$$$, there are one rose and two lilies, so the beauty is equal to $$$1\cdot 2=2$$$; - in the segment $$$[2\ldots4]$$$, there are one rose and two lilies, so t...
[{"input": "5 3\n1 3\n2 4\n2 5", "output": "01100"}, {"input": "6 3\n5 6\n1 4\n4 6", "output": "110010"}]
1,300
["constructive algorithms", "greedy", "implementation", "math"]
27
[{"input": "5 3\r\n1 3\r\n2 4\r\n2 5\r\n", "output": "01010\r\n"}, {"input": "6 3\r\n5 6\r\n1 4\r\n4 6\r\n", "output": "010101\r\n"}, {"input": "10 4\r\n3 3\r\n1 6\r\n9 9\r\n10 10\r\n", "output": "0101010101\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "1000 10\r\n3 998\r\n2 1000\r\n1 999\r\n2 1000\...
false
stdio
import sys def read_ints(f): return list(map(int, f.readline().split())) def compute_sum(arrangement, segments): total = 0 for l, r in segments: zeros = arrangement[l-1:r].count('0') ones = (r - l + 1) - zeros total += zeros * ones return total def main(input_path, output_path...
true
821/D
821
D
PyPy 3
TESTS
1
109
0
43506734
def check(d,c): a,b=d if (a+1,b) in c :return (a+1,b) elif (a,b+1) in c :return (a,b+1) else:return (-1,-1) n,m,k=list(map(int,input().split())) initial=(0,0);final=(m,n);c=0 jj=[tuple(map(int,input().split())) for i in range(k)] p=[(k-1,i-1) for i,k in jj] try : while initial != final: a=i...
69
218
10,752,000
190678233
import heapq import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def dijkstra(s, n): dist = [inf] * n dist[s] = 0 visit = [0] * n p = [] heapq.heappush(p, (dist[s], s)) while p: d, u = heapq.heappop(p) if dist[u] < d: continue visi...
Codeforces Round 420 (Div. 2)
CF
2,017
4
256
Okabe and City
Okabe likes to be able to walk through his city on a path lit by street lamps. That way, he doesn't get beaten up by schoolchildren. Okabe's city is represented by a 2D grid of cells. Rows are numbered from 1 to n from top to bottom, and columns are numbered 1 to m from left to right. Exactly k cells in the city are l...
The first line of input contains three space-separated integers n, m, and k (2 ≤ n, m, k ≤ 104). Each of the next k lines contains two space-separated integers ri and ci (1 ≤ ri ≤ n, 1 ≤ ci ≤ m) — the row and the column of the i-th lit cell. It is guaranteed that all k lit cells are distinct. It is guaranteed that th...
Print the minimum number of coins Okabe needs to pay to complete his walk, or -1 if it's not possible.
null
In the first sample test, Okabe can take the path $$(1,1)\rightarrow(2,1)\rightarrow(2,3)\rightarrow(3,3)\rightarrow(4,3)\rightarrow(4,4)$$, paying only when moving to (2, 3) and (4, 4). In the fourth sample, Okabe can take the path $$(1,1)\rightarrow(1,2)\rightarrow(2,2)\rightarrow(3,2)\rightarrow(3,3)\rightarrow(4,4...
[{"input": "4 4 5\n1 1\n2 1\n2 3\n3 3\n4 3", "output": "2"}, {"input": "5 5 4\n1 1\n2 1\n3 1\n3 2", "output": "-1"}, {"input": "2 2 4\n1 1\n1 2\n2 1\n2 2", "output": "0"}, {"input": "5 5 4\n1 1\n2 2\n3 3\n4 4", "output": "3"}]
2,200
["dfs and similar", "graphs", "shortest paths"]
69
[{"input": "4 4 5\r\n1 1\r\n2 1\r\n2 3\r\n3 3\r\n4 3\r\n", "output": "2\r\n"}, {"input": "5 5 4\r\n1 1\r\n2 1\r\n3 1\r\n3 2\r\n", "output": "-1\r\n"}, {"input": "2 2 4\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "5 5 4\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n", "output": "3\r\n"}, {"input": "7 10 53\r\n1 1\r...
false
stdio
null
true
355/B
355
B
PyPy 3
TESTS
8
92
1,228,800
109972972
if __name__ == '__main__': c1,c2,c3,c4 = map(int, input().split()) n,m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) s = min(c1,c2,c3,c4) l = [] if s == c4: print(c4) else: required = 0 for i in range (n): required = required+min(c2,c1*a[i]) ans =...
27
46
0
192350716
# LUOGU_RID: 101541065 (c1, c2, c3, c4), _, a, b = [[*(map(int, s.split()))] for s in open(0)] print(min(min(c3, sum(min(a * c1, c2) for a in a)) + min(c3, sum(min(b * c1, c2) for b in b)), c4))
Codeforces Round 206 (Div. 2)
CF
2,013
1
256
Vasya and Public Transport
Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m. Public transport is not free. There are 4 types of tickets: 1. A ticket for one ride...
The first line contains four integers c1, c2, c3, c4 (1 ≤ c1, c2, c3, c4 ≤ 1000) — the costs of the tickets. The second line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of buses and trolleys Vasya is going to use. The third line contains n integers ai (0 ≤ ai ≤ 1000) — the number of times Vasya is go...
Print a single number — the minimum sum of burles Vasya will have to spend on the tickets.
null
In the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to (2·1) + 3 + 7 = 12 burles. In the second sample the profitable strategy is to buy one ticket of t...
[{"input": "1 3 7 19\n2 3\n2 5\n4 4 4", "output": "12"}, {"input": "4 3 2 1\n1 3\n798\n1 2 3", "output": "1"}, {"input": "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42", "output": "16"}]
1,100
["greedy", "implementation"]
27
[{"input": "1 3 7 19\r\n2 3\r\n2 5\r\n4 4 4\r\n", "output": "12\r\n"}, {"input": "4 3 2 1\r\n1 3\r\n798\r\n1 2 3\r\n", "output": "1\r\n"}, {"input": "100 100 8 100\r\n3 5\r\n7 94 12\r\n100 1 47 0 42\r\n", "output": "16\r\n"}, {"input": "3 103 945 1000\r\n7 9\r\n34 35 34 35 34 35 34\r\n0 0 0 0 0 0 0 0 0\r\n", "output": ...
false
stdio
null
true
89/A
89
A
PyPy 3
TESTS
4
77
0
149949689
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())) if not n % 2 or m < n - 2 or n < 2: ans = 0 else: c = 0 for i in range(0, n, 2): c = max(c, a[i]) u = m // (n - 1) ans = min(u * k, c) prin...
45
62
1,945,600
217184963
n, m, k = map(int, input().split()) a = list(map(int, input().split())) if n % 2 == 0: print('0') else: print(min(m // (n // 2 + 1) * k, min(a[::2])))# 1691197711.423217
Codeforces Beta Round 74 (Div. 1 Only)
CF
2,011
1
256
Robbery
It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right. Unfortunately, Joe ...
The first line contains integers n, m and k (1 ≤ n ≤ 104, 1 ≤ m, k ≤ 109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell — it is an integer from 0 to 105.
Print a single number — the maximum number of diamonds Joe can steal.
null
In the second sample Joe can act like this: The diamonds' initial positions are 4 1 3. During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket. By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference...
[{"input": "2 3 1\n2 3", "output": "0"}, {"input": "3 2 2\n4 1 3", "output": "2"}]
1,800
["greedy"]
45
[{"input": "2 3 1\r\n2 3\r\n", "output": "0"}, {"input": "3 2 2\r\n4 1 3\r\n", "output": "2"}, {"input": "5 10 10\r\n7 0 7 0 7\r\n", "output": "7"}, {"input": "6 10 4\r\n1 2 3 4 5 6\r\n", "output": "0"}, {"input": "7 5 2\r\n1 2 3 4 5 6 7\r\n", "output": "1"}, {"input": "16 100 100\r\n30 89 12 84 62 24 10 59 98 21 13 69...
false
stdio
null
true
765/A
765
A
Python 3
TESTS
5
46
0
136024683
import sys n = int(sys.stdin.readline()) home = sys.stdin.readline().replace('\n','') dic = {} dic[home] = 1 ans = 0 for i in range(n): inp = sys.stdin.readline().replace('\n','') a = inp[0:3] b = inp[5:] if b in dic: dic[b] += 1 ans +=1 else: dic[b] = 1 if n%2 == 0 and ans == n//2: print('home'...
23
31
0
183795156
n=int(input()) print('home' if n%2==0 else 'contest')
Codeforces Round 397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
512
Neverending competitions
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
In the first line of input there is a single integer n: the number of Jinotega's flights (1 ≤ n ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next n lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name ...
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
null
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
[{"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home"}, {"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest"}]
900
["implementation", "math"]
23
[{"input": "4\r\nSVO\r\nSVO->CDG\r\nLHR->SVO\r\nSVO->LHR\r\nCDG->SVO\r\n", "output": "home\r\n"}, {"input": "3\r\nSVO\r\nSVO->HKT\r\nHKT->SVO\r\nSVO->RAP\r\n", "output": "contest\r\n"}, {"input": "1\r\nESJ\r\nESJ->TSJ\r\n", "output": "contest\r\n"}, {"input": "2\r\nXMR\r\nFAJ->XMR\r\nXMR->FAJ\r\n", "output": "home\r\n"...
false
stdio
null
true
765/A
765
A
PyPy 3
TESTS
5
92
20,275,200
130271560
from collections import defaultdict def solve(h,d): if(len(d[h])==len(d)-1): return "home" return "contest" n = int(input()) h = input() d = defaultdict(list) for i in range(n): l = input().split("->") d[l[0]].append(l[-1]) print(solve(h,d))
23
46
0
136023940
# # Joseph Matsushita # Problem A # n = int(input()) home = input() c = 0 for _ in range(n): town = str(input().split('-')[0]) if town == home: c += 1 else: c -= 1 if c == 0: print("home") else: print("contest")
Codeforces Round 397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
512
Neverending competitions
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
In the first line of input there is a single integer n: the number of Jinotega's flights (1 ≤ n ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next n lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name ...
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
null
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
[{"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home"}, {"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest"}]
900
["implementation", "math"]
23
[{"input": "4\r\nSVO\r\nSVO->CDG\r\nLHR->SVO\r\nSVO->LHR\r\nCDG->SVO\r\n", "output": "home\r\n"}, {"input": "3\r\nSVO\r\nSVO->HKT\r\nHKT->SVO\r\nSVO->RAP\r\n", "output": "contest\r\n"}, {"input": "1\r\nESJ\r\nESJ->TSJ\r\n", "output": "contest\r\n"}, {"input": "2\r\nXMR\r\nFAJ->XMR\r\nXMR->FAJ\r\n", "output": "home\r\n"...
false
stdio
null
true
358/C
358
C
Python 3
TESTS
0
15
0
191068577
last_zero,largest,nd_largest,rd_largest=-1,-1,-1,-1 n=int(input()) arr=[int(input()) for _ in range(n)] for i in range (n): if(arr[i]==0): stk_filled=que_filled=front_filled=False for j in range(last_zero+1,i): if(arr[j]==largest and not stk_filled): stk_filled=True ...
26
1,122
307,200
13939867
n = int(input()) i = 0 while i < n: a = [] c = int(input()) i += 1 while (c != 0 and i < n): a.append(c) i += 1 c = int(input()) if (c != 0): for j in range(len(a) + 1): print('pushStack') continue if len(a) == 0: print(0) elif len(...
Codeforces Round 208 (Div. 2)
CF
2,013
2
256
Dima and Containers
Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck. Inna wants her present to show Dima how great a programmer he is. For that, she is going to g...
The first line contains integer n (1 ≤ n ≤ 105) — the number of Inna's commands. Then n lines follow, describing Inna's commands. Each line consists an integer: 1. Integer a (1 ≤ a ≤ 105) means that Inna gives Dima a command to add number a into one of containers. 2. Integer 0 shows that Inna asks Dima to make at most...
Each command of the input must correspond to one line of the output — Dima's action. For the command of the first type (adding) print one word that corresponds to Dima's choice: - pushStack — add to the end of the stack; - pushQueue — add to the end of the queue; - pushFront — add to the beginning of the deck; - push...
null
null
[{"input": "10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0", "output": "0\npushStack\n1 popStack\npushStack\npushQueue\n2 popStack popQueue\npushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}, {"input": "4\n1\n2\n3\n0", "output": "pushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}]
2,000
["constructive algorithms", "greedy", "implementation"]
26
[{"input": "10\r\n0\r\n1\r\n0\r\n1\r\n2\r\n0\r\n1\r\n2\r\n3\r\n0\r\n", "output": "0\r\npushStack\r\n1 popStack\r\npushStack\r\npushQueue\r\n2 popStack popQueue\r\npushStack\r\npushQueue\r\npushFront\r\n3 popStack popQueue popFront\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n0\r\n", "output": "pushStack\r\npushQueue\r\npushFr...
false
stdio
import sys from collections import deque def main(input_path, output_path, submission_path): with open(input_path) as f: input_lines = f.read().splitlines() n = int(input_lines[0]) input_commands = input_lines[1:n+1] with open(submission_path) as f: submission_lines = [line.strip()...
true
894/C
894
C
PyPy 3-64
TESTS
0
124
6,860,800
161539271
from bisect import * from collections import * import sys import io, os import math import random from heapq import * gcd = math.gcd sqrt = math.sqrt maxint=10**21 def ceil(a, b): a = -a k = a // b k = -k return k # arr=list(map(int, input().split())) input = io.BytesIO(os.read(0, os.fstat(0).st_size))....
56
62
5,632,000
32470400
def gcd(a,b): if(b==0): return a else: return gcd(b,a%b) n=int(input()) a=list(map(int,input().split())) gcd1=a[0] for i in range(1,n): gcd1=gcd(gcd1,a[i]) if gcd1 not in a: print(-1) else: s='' for i in range(n): s+=str(gcd1) + ' ' + str(a[i]) + ' ' + str(gcd1) + ' ' ...
Codeforces Round 447 (Div. 2)
CF
2,017
1
256
Marco and GCD Sequence
In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time. When he woke up, he only remembered that the key was a sequence of positive integers of some length n, but forgot the exact sequence. Let the elements of the sequence be...
The first line contains a single integer m (1 ≤ m ≤ 1000) — the size of the set S. The second line contains m integers s1, s2, ..., sm (1 ≤ si ≤ 106) — the elements of the set S. It's guaranteed that the elements of the set are given in strictly increasing order, that means s1 < s2 < ... < sm.
If there is no solution, print a single line containing -1. Otherwise, in the first line print a single integer n denoting the length of the sequence, n should not exceed 4000. In the second line print n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the sequence. We can show that if a solution exists, then there is a so...
null
In the first example 2 = gcd(4, 6), the other elements from the set appear in the sequence, and we can show that there are no values different from 2, 4, 6 and 12 among gcd(ai, ai + 1, ..., aj) for every 1 ≤ i ≤ j ≤ n.
[{"input": "4\n2 4 6 12", "output": "3\n4 6 12"}, {"input": "2\n2 3", "output": "-1"}]
1,900
["constructive algorithms", "math"]
56
[{"input": "4\r\n2 4 6 12\r\n", "output": "7\r\n2 2 4 2 6 2 12"}, {"input": "2\r\n2 3\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 6\r\n", "output": "3\r\n1 1 6"}, {"input": "3\r\n1 2 7\r\n", "output": "5\r\n1 1 2 1 7"}, {"input": "1\r\n1\r\n", "output": "1\r\n1"}, {"input": "2\r\n1 10\r\n", "output": "3\r\n1 1 10"}, {...
false
stdio
import sys from math import gcd def read_file(path): with open(path, 'r') as f: return [line.strip() for line in f if line.strip()] def main(input_path, output_path, sub_path): input_lines = read_file(input_path) m = int(input_lines[0]) S = set(map(int, input_lines[1].split())) sub_li...
true
724/D
724
D
PyPy 3
PRETESTS
3
109
23,040,000
21293085
abc = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] m = int(input()) string = input() good = False toCheck = [] lenS = len(string) holes = [(-1, lenS)] have = {'s': 0, 'i': 0, 'y': 0, 'h': 0, 'r': 0, 'f': 0, 'd': 0, 'z': 0, 'q': 0, 't'...
71
124
9,011,200
200894970
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline m = int(input()) s = [0] + list(input().rstrip()) n = len(s) - 1 u = [[] for _ in range(130)] for i in range(1, n + 1): u[s[i]].append(i) x = [0] * (n + 1) for i in range(97, 123): for j in u[i]: x[j] = 1 y = list(x) ...
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
33/A
33
A
Python 3
TESTS
10
218
6,963,200
85260296
n,m,k=map(int,input().split(' ')) ar=[0]*(n+1) via=[0]*(n+1) s=0 for i in range(n): v1,v2=map(int,input().split(' ')) ar[v1]=v1 if(via[v1]==0): via[v1]=v2 else: via[v1]=min(via[v1],v2) print(min(sum(via),k))
31
78
0
4049467
I=[int(i) for i in input().split()] n, m, k = I[0], I[1], I[2] Min=[10**6 for i in range(m)] for i in range(n): I=[int(j) for j in input().split()] r, c = I[0], I[1] if c<Min[r-1]: Min[r-1]=c ans=sum(Min) if ans>k: print(k) else: print(ans)
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
What is for dinner?
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c...
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
null
null
[{"input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11"}, {"input": "2 2 13\n1 13\n2 12", "output": "13"}]
1,200
["greedy", "implementation"]
31
[{"input": "4 3 18\r\n2 3\r\n1 2\r\n3 6\r\n2 3\r\n", "output": "11\r\n"}, {"input": "2 2 13\r\n1 13\r\n2 12\r\n", "output": "13\r\n"}, {"input": "5 4 8\r\n4 6\r\n4 5\r\n1 3\r\n2 0\r\n3 3\r\n", "output": "8\r\n"}, {"input": "1 1 0\r\n1 3\r\n", "output": "0\r\n"}, {"input": "7 1 30\r\n1 8\r\n1 15\r\n1 5\r\n1 17\r\n1 9\r\...
false
stdio
null
true
995/B
995
B
Python 3
TESTS
6
46
0
226135810
def solve(): n = int(input()) a = list(map(int, input().split())) res = 0 mapp = dict() for i in range(len(a)): if a[i] not in mapp: mapp[a[i]] = [] mapp[a[i]].append(i) visit = set() for i in range(len(a)): if a[i] not in visit: visit.add(a[...
22
31
0
147260231
n = int(input()) a = list(map(int, input().split())) i = 1 j = 0 ans = 0 while(i<2*n): if(a[i-1]!=a[i]): for j in range(i+1, 2*n): if a[i-1]==a[j]: ans += j-i a.pop(j) a.insert(i,a[i-1]) i += 2 print(ans)
Codeforces Round 492 (Div. 1) [Thanks, uDebug!]
CF
2,018
2
256
Suit and Tie
Allen is hosting a formal dinner party. $$$2n$$$ people come to the event in $$$n$$$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $$$2n$$$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this m...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of pairs of people. The second line contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$. For each $$$i$$$ with $$$1 \le i \le n$$$, $$$i$$$ appears exactly twice. If $$$a_j = a_k = i$$$, that means that the $$$j$$$-th and $$$k$$$...
Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.
null
In the first sample case, we can transform $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$$$ in two steps. Note that the sequence $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$$$ also works in the same number of steps. The second sample case already satisfies th...
[{"input": "4\n1 1 2 3 3 2 4 4", "output": "2"}, {"input": "3\n1 1 2 2 3 3", "output": "0"}, {"input": "3\n3 1 2 3 1 2", "output": "3"}]
1,400
["greedy", "implementation", "math"]
22
[{"input": "4\r\n1 1 2 3 3 2 4 4\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2 2 3 3\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1 2 3 1 2\r\n", "output": "3\r\n"}, {"input": "8\r\n7 6 2 1 4 3 3 7 2 6 5 1 8 5 8 4\r\n", "output": "27\r\n"}, {"input": "2\r\n1 2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 3 3 1 2\...
false
stdio
null
true
289/A
289
A
Python 3
TESTS
6
124
0
113367842
n , k = map(int,input().split()) o = 0 for i in range(n): s , s1 = map(int,input().split()) o += s1 -s o+=1 if o % k == 0: print(0) elif o % k == o: print(0) elif o% k > 0: j =o % k print(k-j)
28
342
0
214268002
n, k = map(int, input().split()) pairs = [] sum = 0 count = 0 for _ in range(n): a, b = map(int, input().split()) sum += b - a + 1 dif = b - a + 1 if dif != 0 and dif != 1 and dif >= k: count += 1 if sum % k == 0: print(0) exit() one = sum % k if count <= one: print(k - one) else: ...
Codeforces Round 177 (Div. 2)
CF
2,013
2
256
Polo the Penguin and Segments
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the r...
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequal...
In a single line print a single integer — the answer to the problem.
null
null
[{"input": "2 3\n1 2\n3 4", "output": "2"}, {"input": "3 7\n1 2\n3 3\n4 7", "output": "0"}]
1,100
["brute force", "implementation"]
28
[{"input": "2 3\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "3 7\r\n1 2\r\n3 3\r\n4 7\r\n", "output": "0\r\n"}, {"input": "3 7\r\n1 10\r\n11 47\r\n74 128\r\n", "output": "3\r\n"}, {"input": "5 4\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n", "output": "3\r\n"}, {"input": "7 4\r\n2 2\r\n-1 -1\r\n0 1\r\n7 8\r\n-3 -2\r\n9...
false
stdio
null
true
894/C
894
C
PyPy 3-64
TESTS
0
46
0
214630150
n=int(input()) k=[int(x) for x in input().split()] g=min(k) l=[] for x in range(len(k)): if g!=k[x] and k[x]%g==0: l.append(k[x]) elif k[x]%g!=0: print(-1) exit(0) print(*l)
56
62
5,632,000
32471204
m = int(input()) s = list(map(int,input().split())) f = 1 for i in s: if i%s[0]!=0: f = 0 break if f: print(2*m) for i in s: print(str(s[0]) + ' ' + str(i), end=' ') else: print(-1)
Codeforces Round 447 (Div. 2)
CF
2,017
1
256
Marco and GCD Sequence
In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time. When he woke up, he only remembered that the key was a sequence of positive integers of some length n, but forgot the exact sequence. Let the elements of the sequence be...
The first line contains a single integer m (1 ≤ m ≤ 1000) — the size of the set S. The second line contains m integers s1, s2, ..., sm (1 ≤ si ≤ 106) — the elements of the set S. It's guaranteed that the elements of the set are given in strictly increasing order, that means s1 < s2 < ... < sm.
If there is no solution, print a single line containing -1. Otherwise, in the first line print a single integer n denoting the length of the sequence, n should not exceed 4000. In the second line print n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the sequence. We can show that if a solution exists, then there is a so...
null
In the first example 2 = gcd(4, 6), the other elements from the set appear in the sequence, and we can show that there are no values different from 2, 4, 6 and 12 among gcd(ai, ai + 1, ..., aj) for every 1 ≤ i ≤ j ≤ n.
[{"input": "4\n2 4 6 12", "output": "3\n4 6 12"}, {"input": "2\n2 3", "output": "-1"}]
1,900
["constructive algorithms", "math"]
56
[{"input": "4\r\n2 4 6 12\r\n", "output": "7\r\n2 2 4 2 6 2 12"}, {"input": "2\r\n2 3\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 6\r\n", "output": "3\r\n1 1 6"}, {"input": "3\r\n1 2 7\r\n", "output": "5\r\n1 1 2 1 7"}, {"input": "1\r\n1\r\n", "output": "1\r\n1"}, {"input": "2\r\n1 10\r\n", "output": "3\r\n1 1 10"}, {...
false
stdio
import sys from math import gcd def read_file(path): with open(path, 'r') as f: return [line.strip() for line in f if line.strip()] def main(input_path, output_path, sub_path): input_lines = read_file(input_path) m = int(input_lines[0]) S = set(map(int, input_lines[1].split())) sub_li...
true
394/C
394
C
Python 3
TESTS
0
46
0
5962031
n, m = map(int, input().split()) k, d = n * m, 2 * m c = {'11': 0, '01': 0, '10': 0} for i in range(n): t = input() for i in ('11', '01', '10'): c[i] += t.count(i) a, b = c['11'], c['10'] + c['01'] t = '11 ' * a + '10 01 ' * (b // 2) + '10 ' * (b & 1) + '00 ' * (k - a - b) k *= 3; d *= 3; m *= 3 for i in range(...
27
186
13,926,400
35858181
n, m = map(int, input().split()) k, d = n * m, 2 * m c = {'11': 0, '01': 0, '10': 0} for i in range(n): t = input() for i in ('11', '01', '10'): c[i] += t.count(i) a, b = c['11'], c['10'] + c['01'] t = ['11'] * a + (b // 2) * ['10', '01'] + ['10'] * (b & 1) + ['00'] * (k - a - b) for i in range(0, k, d): pr...
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
894/C
894
C
PyPy 3
TESTS
0
46
0
119731838
''' Hey why peeping here -_'_- ? I believe on myself and I will achieve this->author = Fuad Ashraful Mehmet, CSE ,University of Asia Pacific https://www.youtube.com/watch?v=2fqiOX7WugE&ab_channel=FolkStudioBangla ''' import sys input=sys.stdin.readline R=lambda:map(int,input().split()) I=lambda:int(input()) S=lambda:i...
56
77
3,072,000
170087265
import math n = int(input()) a = list(map(int, input().split())) temp = a[-1] for i in range(0, n): temp = math.gcd(temp, a[i]) if temp != a[0]: print(-1) else: res = [] for i in range(n): res.append(a[i]) res.append(temp) res.pop(-1) print(len(res)) print(*res)
Codeforces Round 447 (Div. 2)
CF
2,017
1
256
Marco and GCD Sequence
In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time. When he woke up, he only remembered that the key was a sequence of positive integers of some length n, but forgot the exact sequence. Let the elements of the sequence be...
The first line contains a single integer m (1 ≤ m ≤ 1000) — the size of the set S. The second line contains m integers s1, s2, ..., sm (1 ≤ si ≤ 106) — the elements of the set S. It's guaranteed that the elements of the set are given in strictly increasing order, that means s1 < s2 < ... < sm.
If there is no solution, print a single line containing -1. Otherwise, in the first line print a single integer n denoting the length of the sequence, n should not exceed 4000. In the second line print n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the sequence. We can show that if a solution exists, then there is a so...
null
In the first example 2 = gcd(4, 6), the other elements from the set appear in the sequence, and we can show that there are no values different from 2, 4, 6 and 12 among gcd(ai, ai + 1, ..., aj) for every 1 ≤ i ≤ j ≤ n.
[{"input": "4\n2 4 6 12", "output": "3\n4 6 12"}, {"input": "2\n2 3", "output": "-1"}]
1,900
["constructive algorithms", "math"]
56
[{"input": "4\r\n2 4 6 12\r\n", "output": "7\r\n2 2 4 2 6 2 12"}, {"input": "2\r\n2 3\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 6\r\n", "output": "3\r\n1 1 6"}, {"input": "3\r\n1 2 7\r\n", "output": "5\r\n1 1 2 1 7"}, {"input": "1\r\n1\r\n", "output": "1\r\n1"}, {"input": "2\r\n1 10\r\n", "output": "3\r\n1 1 10"}, {...
false
stdio
import sys from math import gcd def read_file(path): with open(path, 'r') as f: return [line.strip() for line in f if line.strip()] def main(input_path, output_path, sub_path): input_lines = read_file(input_path) m = int(input_lines[0]) S = set(map(int, input_lines[1].split())) sub_li...
true
893/C
893
C
Python 3
TESTS
10
483
14,540,800
189673449
n, m = map(int, input().split()) c = list(map(int, input().split())) ind_list = [] ind_set = set() for i in range(m): x, y = map(int, input().split()) mn = min(c[x - 1], c[y - 1]) c[x - 1] = mn c[y - 1] = mn ind_list.append((x - 1, y - 1)) ind_set.add(x - 1) ind_list.reverse() for i in i...
46
280
27,136,000
209233074
#!/usr/bin/env python3 import math import sys input = lambda: sys.stdin.readline().rstrip("\r\n") def test_case(): n, m = map(int, input().split()) c = [-1] + list(map(int, input().split())) g = [[] for _ in range(n+1)] for _ in range(m): u, v = map(int, input().split()) g[u].append(v...
Educational Codeforces Round 33 (Rated for Div. 2)
ICPC
2,017
2
256
Rumor
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Ove...
The first line contains two integer numbers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) — the number of characters in Overcity and the number of pairs of friends. The second line contains n integer numbers ci (0 ≤ ci ≤ 109) — the amount of gold i-th character asks to start spreading the rumor. Then m lines follow, each contai...
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
null
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor. In the second example Vova has to bribe everyone. In the third example ...
[{"input": "5 2\n2 5 3 4 8\n1 4\n4 5", "output": "10"}, {"input": "10 0\n1 2 3 4 5 6 7 8 9 10", "output": "55"}, {"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10", "output": "15"}]
1,300
["dfs and similar", "graphs", "greedy"]
46
[{"input": "5 2\r\n2 5 3 4 8\r\n1 4\r\n4 5\r\n", "output": "10\r\n"}, {"input": "10 0\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "55\r\n"}, {"input": "10 5\r\n1 6 2 7 3 8 4 9 5 10\r\n1 2\r\n3 4\r\n5 6\r\n7 8\r\n9 10\r\n", "output": "15\r\n"}, {"input": "1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "1 0\r\n1000000000\r\n",...
false
stdio
null
true
893/C
893
C
Python 3
TESTS
10
608
13,209,600
98164361
x,y = map(int, input().split()) *li, = map(int, input().split()) li1 = li[:] li2 = [] ans =0 for i in range(y): a,b = map(int, input().split()) li2 += [ [a,b]] m = min(li1[a-1], li1[b-1]) li1[a-1] = m li1[b-1] = m for i in li2[::-1]: a = i[0] b = i[1] m = min(li1[a-1], li1[b-1]) li1[a-1] = m li1[b-1] = m if...
46
280
29,491,200
163791824
# Dictionary == Hash Collision from sys import stdin from bisect import bisect_left as bl, bisect_right as br from collections import defaultdict, Counter, deque input = stdin.readline def read(default=int): return list(map(default, input().strip().split())) def solve(): n, m = read() weights = [0] + ...
Educational Codeforces Round 33 (Rated for Div. 2)
ICPC
2,017
2
256
Rumor
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Ove...
The first line contains two integer numbers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) — the number of characters in Overcity and the number of pairs of friends. The second line contains n integer numbers ci (0 ≤ ci ≤ 109) — the amount of gold i-th character asks to start spreading the rumor. Then m lines follow, each contai...
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
null
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor. In the second example Vova has to bribe everyone. In the third example ...
[{"input": "5 2\n2 5 3 4 8\n1 4\n4 5", "output": "10"}, {"input": "10 0\n1 2 3 4 5 6 7 8 9 10", "output": "55"}, {"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10", "output": "15"}]
1,300
["dfs and similar", "graphs", "greedy"]
46
[{"input": "5 2\r\n2 5 3 4 8\r\n1 4\r\n4 5\r\n", "output": "10\r\n"}, {"input": "10 0\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "55\r\n"}, {"input": "10 5\r\n1 6 2 7 3 8 4 9 5 10\r\n1 2\r\n3 4\r\n5 6\r\n7 8\r\n9 10\r\n", "output": "15\r\n"}, {"input": "1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "1 0\r\n1000000000\r\n",...
false
stdio
null
true
893/C
893
C
Python 3
TESTS
10
779
47,308,800
124048672
n,m=map(int,input().split()) o=[*map(int,input().split())] q={} l={} w=0 for i in range(1,n+1): q[i]=[o[i-1]] l[i]=i for i in range(m): a,b=map(int,input().split()) while l[a]!=a: a=l[a] q[a]+=[o[b-1]]+q[l[b]] q[b]=[] l[l[b]]=a l[b]=a for i in l: if l[i]==i:w+=min(q[i]) print...
46
280
35,123,200
131393795
import sys,io,os import math from os import path if(path.exists('input.txt')): sys.stdin = open('input.txt','r') sys.stdout = open('output.txt','w') else: input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline visited=[] graph=[] c=0 global mini def dfs(s): global visited,graph,mini,c stack...
Educational Codeforces Round 33 (Rated for Div. 2)
ICPC
2,017
2
256
Rumor
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Ove...
The first line contains two integer numbers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) — the number of characters in Overcity and the number of pairs of friends. The second line contains n integer numbers ci (0 ≤ ci ≤ 109) — the amount of gold i-th character asks to start spreading the rumor. Then m lines follow, each contai...
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
null
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor. In the second example Vova has to bribe everyone. In the third example ...
[{"input": "5 2\n2 5 3 4 8\n1 4\n4 5", "output": "10"}, {"input": "10 0\n1 2 3 4 5 6 7 8 9 10", "output": "55"}, {"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10", "output": "15"}]
1,300
["dfs and similar", "graphs", "greedy"]
46
[{"input": "5 2\r\n2 5 3 4 8\r\n1 4\r\n4 5\r\n", "output": "10\r\n"}, {"input": "10 0\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "55\r\n"}, {"input": "10 5\r\n1 6 2 7 3 8 4 9 5 10\r\n1 2\r\n3 4\r\n5 6\r\n7 8\r\n9 10\r\n", "output": "15\r\n"}, {"input": "1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "1 0\r\n1000000000\r\n",...
false
stdio
null
true
67/A
67
A
Python 3
TESTS
9
248
7,065,600
87905602
from collections import deque def peak(i): if i==0: return s[i]=='L' elif i==n-1: return s[i-1]=='R' return s[i-1]=='R' and s[i]=='L' n = int(input()) s = input() q = deque() candidate = True ans = [0]*n for i in range(n-1): if s[i]=='R': if candidate: q.append((i, ...
43
62
0
217564814
len = int(input()) dir = input() res = [1] * len for i in range(1, len): if dir[i - 1] == 'L': res[i] = 1 else: res[i] = res[i - 1] + (dir[i - 1] == 'R') for i in range(len - 2, -1, -1): if dir[i] == 'L': res[i] = max(res[i], res[i + 1] + 1) elif dir[i] == '=': res[i] ...
Manthan 2011
CF
2,011
1
256
Partial Teacher
A teacher decides to give toffees to his students. He asks n students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees. He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks...
The first line of input contains the number of students n (2 ≤ n ≤ 1000). The second line gives (n - 1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal mar...
Output consists of n integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one.
null
null
[{"input": "5\nLRLR", "output": "2 1 2 1 2"}, {"input": "5\n=RRR", "output": "1 1 2 3 4"}]
1,800
["dp", "graphs", "greedy", "implementation"]
43
[{"input": "5\r\nLRLR\r\n", "output": "2 1 2 1 2\r\n"}, {"input": "5\r\n=RRR\r\n", "output": "1 1 2 3 4\r\n"}, {"input": "6\r\nRLRL=\r\n", "output": "1 2 1 2 1 1\r\n"}, {"input": "3\r\nR=\r\n", "output": "1 2 2\r\n"}, {"input": "7\r\nRR==RR\r\n", "output": "1 2 3 3 3 4 5\r\n"}, {"input": "166\r\nR===RL=LRRR=RRRL=LRR=R=...
false
stdio
null
true
355/B
355
B
Python 3
TESTS
3
61
6,963,200
129144985
c1,c2,c3,c4 = map(int,input().split()) n,m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) if c4 <= c1 and c4 <= c2 and c4 <= c3: print(c4) else: c=0 for i in range(n): if a[i] < c2: c += a[i] * c1 else: c += c2 ...
27
46
102,400
153785660
import collections import math import sys need_two = 0 def main(): c = list(map(int, input().split())) n, m = map(int, input().split()) nn = list(map(int, input().split())) mm = list(map(int, input().split())) ans = c[3] ans_n = c[2] s_n = 0 for x in nn: s_n += min(x * c[0], c[1]...
Codeforces Round 206 (Div. 2)
CF
2,013
1
256
Vasya and Public Transport
Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m. Public transport is not free. There are 4 types of tickets: 1. A ticket for one ride...
The first line contains four integers c1, c2, c3, c4 (1 ≤ c1, c2, c3, c4 ≤ 1000) — the costs of the tickets. The second line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of buses and trolleys Vasya is going to use. The third line contains n integers ai (0 ≤ ai ≤ 1000) — the number of times Vasya is go...
Print a single number — the minimum sum of burles Vasya will have to spend on the tickets.
null
In the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to (2·1) + 3 + 7 = 12 burles. In the second sample the profitable strategy is to buy one ticket of t...
[{"input": "1 3 7 19\n2 3\n2 5\n4 4 4", "output": "12"}, {"input": "4 3 2 1\n1 3\n798\n1 2 3", "output": "1"}, {"input": "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42", "output": "16"}]
1,100
["greedy", "implementation"]
27
[{"input": "1 3 7 19\r\n2 3\r\n2 5\r\n4 4 4\r\n", "output": "12\r\n"}, {"input": "4 3 2 1\r\n1 3\r\n798\r\n1 2 3\r\n", "output": "1\r\n"}, {"input": "100 100 8 100\r\n3 5\r\n7 94 12\r\n100 1 47 0 42\r\n", "output": "16\r\n"}, {"input": "3 103 945 1000\r\n7 9\r\n34 35 34 35 34 35 34\r\n0 0 0 0 0 0 0 0 0\r\n", "output": ...
false
stdio
null
true
894/C
894
C
PyPy 3-64
TESTS
0
46
0
223984689
import sys input=sys.stdin.buffer.readline def rl(): return list(map(int,input().split())) def ri(): return int(input()) def rs(): return input() def rm(): return map(int,input().split()) from math import gcd def main(): m,s=ri(),rl() v=set() if s[0]!=gcd(*s): print(-1);return for i in ...
56
77
5,632,000
32465026
import math n = int(input()) x = [int(k) for k in input().split(" ")] m = x[0] chk = [max(0,(x[i]%m)) for i in range(n)] if sum(chk) > 0: print(-1) else: print(2*n-1) o = [] o.append(str(m)) for i in range(1,n): o.append(str(x[i])) o.append(str(m)) print(" ".join(o))
Codeforces Round 447 (Div. 2)
CF
2,017
1
256
Marco and GCD Sequence
In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time. When he woke up, he only remembered that the key was a sequence of positive integers of some length n, but forgot the exact sequence. Let the elements of the sequence be...
The first line contains a single integer m (1 ≤ m ≤ 1000) — the size of the set S. The second line contains m integers s1, s2, ..., sm (1 ≤ si ≤ 106) — the elements of the set S. It's guaranteed that the elements of the set are given in strictly increasing order, that means s1 < s2 < ... < sm.
If there is no solution, print a single line containing -1. Otherwise, in the first line print a single integer n denoting the length of the sequence, n should not exceed 4000. In the second line print n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the sequence. We can show that if a solution exists, then there is a so...
null
In the first example 2 = gcd(4, 6), the other elements from the set appear in the sequence, and we can show that there are no values different from 2, 4, 6 and 12 among gcd(ai, ai + 1, ..., aj) for every 1 ≤ i ≤ j ≤ n.
[{"input": "4\n2 4 6 12", "output": "3\n4 6 12"}, {"input": "2\n2 3", "output": "-1"}]
1,900
["constructive algorithms", "math"]
56
[{"input": "4\r\n2 4 6 12\r\n", "output": "7\r\n2 2 4 2 6 2 12"}, {"input": "2\r\n2 3\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 6\r\n", "output": "3\r\n1 1 6"}, {"input": "3\r\n1 2 7\r\n", "output": "5\r\n1 1 2 1 7"}, {"input": "1\r\n1\r\n", "output": "1\r\n1"}, {"input": "2\r\n1 10\r\n", "output": "3\r\n1 1 10"}, {...
false
stdio
import sys from math import gcd def read_file(path): with open(path, 'r') as f: return [line.strip() for line in f if line.strip()] def main(input_path, output_path, sub_path): input_lines = read_file(input_path) m = int(input_lines[0]) S = set(map(int, input_lines[1].split())) sub_li...
true
290/E
290
E
PyPy 3
TESTS
3
154
0
111770965
s = input() if s.count('H') != 0 and s.count('Q') != 0: if s.count('H') != s.count('Q'): print("No") else: print("Yes") else: print("Yes")
28
1,090
56,320,000
197627903
a = input() b = [] h = '' c = 0 for i in a: if i == 'Q': c += 1 if c == 0: print('Yes') exit(0) r = -1 for i in range(1001): if i*i == c: r = i break if r == -1: print('No') exit(0) h = [a.split('Q')[0], a.split('Q')[-1]] c = [len(h[0]), len(h[1])] if c[0] % 2 != 0 or c[1] % 2 != 0: print('No') exit(0) c[...
April Fools Day Contest 2013
ICPC
2,013
2
256
HQ
The famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its subset — a language called HQ...
The only line of the input is a string between 1 and 106 characters long.
Output "Yes" or "No".
null
The rest of the problem statement was destroyed by a stray raccoon. We are terribly sorry for the inconvenience.
[{"input": "HHHH", "output": "Yes"}, {"input": "HQHQH", "output": "No"}, {"input": "HHQHHQH", "output": "No"}, {"input": "HHQQHHQQHH", "output": "Yes"}]
2,500
["*special", "constructive algorithms"]
28
[{"input": "HHHH\r\n", "output": "Yes\r\n"}, {"input": "HQHQH\r\n", "output": "No\r\n"}, {"input": "HHQHHQH\r\n", "output": "No\r\n"}, {"input": "HHQQHHQQHH\r\n", "output": "Yes\r\n"}, {"input": "Q\r\n", "output": "Yes\r\n"}, {"input": "HHHHHHHHHHQHHH\r\n", "output": "No\r\n"}, {"input": "HHQHQQQHHH\r\n", "output": "No...
false
stdio
null
true
290/E
290
E
PyPy 3
TESTS
4
248
0
74349043
s = input() stk = [] for c in s: if stk and stk[-1] == c: stk.pop() else: stk.append(c) if stk: print('No') else: print('Yes')
28
1,090
56,320,000
197627903
a = input() b = [] h = '' c = 0 for i in a: if i == 'Q': c += 1 if c == 0: print('Yes') exit(0) r = -1 for i in range(1001): if i*i == c: r = i break if r == -1: print('No') exit(0) h = [a.split('Q')[0], a.split('Q')[-1]] c = [len(h[0]), len(h[1])] if c[0] % 2 != 0 or c[1] % 2 != 0: print('No') exit(0) c[...
April Fools Day Contest 2013
ICPC
2,013
2
256
HQ
The famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its subset — a language called HQ...
The only line of the input is a string between 1 and 106 characters long.
Output "Yes" or "No".
null
The rest of the problem statement was destroyed by a stray raccoon. We are terribly sorry for the inconvenience.
[{"input": "HHHH", "output": "Yes"}, {"input": "HQHQH", "output": "No"}, {"input": "HHQHHQH", "output": "No"}, {"input": "HHQQHHQQHH", "output": "Yes"}]
2,500
["*special", "constructive algorithms"]
28
[{"input": "HHHH\r\n", "output": "Yes\r\n"}, {"input": "HQHQH\r\n", "output": "No\r\n"}, {"input": "HHQHHQH\r\n", "output": "No\r\n"}, {"input": "HHQQHHQQHH\r\n", "output": "Yes\r\n"}, {"input": "Q\r\n", "output": "Yes\r\n"}, {"input": "HHHHHHHHHHQHHH\r\n", "output": "No\r\n"}, {"input": "HHQHQQQHHH\r\n", "output": "No...
false
stdio
null
true
290/E
290
E
Python 3
TESTS
4
124
0
6200904
a = input() print("Yes" if a.replace("HH", "").replace("QQ", "") == "" else "No")
28
1,090
56,320,000
197627903
a = input() b = [] h = '' c = 0 for i in a: if i == 'Q': c += 1 if c == 0: print('Yes') exit(0) r = -1 for i in range(1001): if i*i == c: r = i break if r == -1: print('No') exit(0) h = [a.split('Q')[0], a.split('Q')[-1]] c = [len(h[0]), len(h[1])] if c[0] % 2 != 0 or c[1] % 2 != 0: print('No') exit(0) c[...
April Fools Day Contest 2013
ICPC
2,013
2
256
HQ
The famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its subset — a language called HQ...
The only line of the input is a string between 1 and 106 characters long.
Output "Yes" or "No".
null
The rest of the problem statement was destroyed by a stray raccoon. We are terribly sorry for the inconvenience.
[{"input": "HHHH", "output": "Yes"}, {"input": "HQHQH", "output": "No"}, {"input": "HHQHHQH", "output": "No"}, {"input": "HHQQHHQQHH", "output": "Yes"}]
2,500
["*special", "constructive algorithms"]
28
[{"input": "HHHH\r\n", "output": "Yes\r\n"}, {"input": "HQHQH\r\n", "output": "No\r\n"}, {"input": "HHQHHQH\r\n", "output": "No\r\n"}, {"input": "HHQQHHQQHH\r\n", "output": "Yes\r\n"}, {"input": "Q\r\n", "output": "Yes\r\n"}, {"input": "HHHHHHHHHHQHHH\r\n", "output": "No\r\n"}, {"input": "HHQHQQQHHH\r\n", "output": "No...
false
stdio
null
true
761/D
761
D
PyPy 3-64
TESTS
1
46
0
206086159
import sys input = sys.stdin.readline n, l, r = map(int, input().split()) a = list(map(int, input().split())) p = list(map(int, input().split())) w = sorted(enumerate(zip(a, p)), key=lambda x:-x[1][1]) q = w[0][1][0] + r d = [(r, w[0][0])] i, ew = 1, 0 while i < n: a = min(r, (q-1)-w[i][1][0]) if a >= l: ...
63
327
20,889,600
24313659
n,l,r = map(int,input().split()) A = list(map(int,input().split())) P = list(map(int,input().split())) s = [0] * n per=0 for j in range(n): s[P[j] - 1] = j b = [0] * n b[s[0]] = l for j in range(1,n): last = b[s[j-1]] - A[s[j-1]] nexs = last+1 if r - A[s[j]] > last: b[s[j]] = max(nexs +A[s...
Codeforces Round 394 (Div. 2)
CF
2,017
2
256
Dasha and Very Difficult Problem
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: ci = bi - ai. About sequences a and b we know that their elements are in the range from l to...
The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ 109) — the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a1, a2, ..., an (l ≤ ai ≤ r) — the elements of the sequence a. The next line contains n distinct in...
If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers — the elements of any suitable sequence b.
null
Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4].
[{"input": "5 1 5\n1 1 1 1 1\n3 1 5 4 2", "output": "3 1 5 4 2"}, {"input": "4 2 9\n3 4 8 9\n3 2 1 4", "output": "2 2 2 9"}, {"input": "6 1 5\n1 1 1 1 1 1\n2 3 5 4 1 6", "output": "-1"}]
1,700
["binary search", "brute force", "constructive algorithms", "greedy", "sortings"]
63
[{"input": "5 1 5\r\n1 1 1 1 1\r\n3 1 5 4 2\r\n", "output": "3 1 5 4 2 "}, {"input": "4 2 9\r\n3 4 8 9\r\n3 2 1 4\r\n", "output": "2 2 2 9 "}, {"input": "6 1 5\r\n1 1 1 1 1 1\r\n2 3 5 4 1 6\r\n", "output": "-1\r\n"}, {"input": "5 1 7\r\n1 4 4 6 5\r\n5 2 1 4 3\r\n", "output": "2 2 1 6 4 "}, {"input": "5 10 100\r\n12 14 ...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: return f.read().strip() def main(input_path, output_path, submission_path): # Read input with open(input_path, 'r') as f: lines = f.readlines() n, l, r = map(int, lines[0].split()) a = list(map(int, lines[1].split())) p...
true
33/A
33
A
Python 3
TESTS
10
92
0
229254139
n,m,k = map(int,input().split()) arr=[0]*m for _ in range(n): a=list(map(int,input().split())) if arr[a[0]-1]>a[1] and arr[a[0]-1]!=0: arr[a[0]-1]=a[1] elif arr[a[0]-1]==0: arr[a[0]-1]=a[1] if sum(arr)>k: print(k) else: print(sum(arr))
31
92
0
140554628
n,m,k=map(int,input().split()) dic={} sum=0 for i in range(n): r,c=map(int,input().split()) if r not in dic: dic[r]=c else: dic[r]=min(c,dic[r]) for i in dic: sum+=dic[i] if sum>=k: print(k) else: print(sum)
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
What is for dinner?
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c...
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
null
null
[{"input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11"}, {"input": "2 2 13\n1 13\n2 12", "output": "13"}]
1,200
["greedy", "implementation"]
31
[{"input": "4 3 18\r\n2 3\r\n1 2\r\n3 6\r\n2 3\r\n", "output": "11\r\n"}, {"input": "2 2 13\r\n1 13\r\n2 12\r\n", "output": "13\r\n"}, {"input": "5 4 8\r\n4 6\r\n4 5\r\n1 3\r\n2 0\r\n3 3\r\n", "output": "8\r\n"}, {"input": "1 1 0\r\n1 3\r\n", "output": "0\r\n"}, {"input": "7 1 30\r\n1 8\r\n1 15\r\n1 5\r\n1 17\r\n1 9\r\...
false
stdio
null
true
724/D
724
D
PyPy 3-64
TESTS
11
140
3,276,800
162949024
import sys from array import array from collections import deque def solve(ma): lst, tak = deque([-1]), 1 ret = set() for i in range(m - 1): if s[i] == ma: lst.append(i) for i in range(m - 1, n): if s[i] == ma: lst.append(i) if not vis[i]: ...
71
155
4,096,000
230900059
m = int(input()) s = input() n = len(s) t = [] u = [1] * n d = 'a' i = 0 while i <= n - m: k = i for j in range(m): if s[i + j] <= s[k]: k = i + j t += [s[k]] d = max(d, s[k]) u[k] = 0 i = k + 1 t += [q for q, v in zip(s, u) if q < d and v] print(''.join(sorted(t)))
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
353/E
353
E
Python 3
TESTS
2
186
0
54857611
s = input() count = 1 prev = s[0] for c in s: if prev != c: count += 1 prev = c if prev == s[0]: count += 1 print(count-1)
72
154
5,427,200
217773339
# i'm from jasnah, do not ban me s = input() n = len(s) a = 0 i = 0 while i < n: if s[i] != s[(i + 1) % n]: if s[i] != s[(i + 2) % n]: a += 1 elif s[i] != s[(i + 3) % n]: i += 1 a += 1 i += 1 print(a)
Codeforces Round 205 (Div. 2)
CF
2,013
1
256
Antichain
You have a directed acyclic graph G, consisting of n vertexes, numbered from 0 to n - 1. The graph contains n edges numbered from 0 to n - 1. An edge with number i connects vertexes i and (i + 1) mod n, and it can be directed in either direction (from i to (i + 1) mod n, or vise versa). Operation x mod y means taking ...
The first line contains the sequence of characters s0s1... sn - 1 (2 ≤ n ≤ 106), consisting of numbers zero and one. The length of the line (number n) corresponds to the number of vertexes and edges in graph G. If character si (i ≥ 0) equals 0, then the edge between vertexes i and (i + 1) mod n is directed from the i-t...
Print a single integer — the size of the maximum antichain of graph G.
null
Consider the first test sample. The graph's G edges are: 0 → 1, 1 → 2, 0 → 2. We can choose the set of vertexes [0] as the maximum antichain. We cannot choose an antichain of larger size.
[{"input": "001", "output": "1"}, {"input": "110010", "output": "3"}]
2,200
["dp", "graph matchings", "greedy"]
72
[{"input": "001\r\n", "output": "1\r\n"}, {"input": "110010\r\n", "output": "3\r\n"}, {"input": "0010011110\r\n", "output": "3\r\n"}, {"input": "0111001010101110001100000010011000100101110010001100111110101110001110101010111000010010011000000110\r\n", "output": "35\r\n"}, {"input": "0110101100\r\n", "output": "4\r\n"},...
false
stdio
null
true
177/C1
177
C1
Python 3
TESTS1
6
156
6,963,200
127212997
I=lambda:map(int,input().split()) n,=I() k,=I() q,w,r={},{},0 for i in range(n): q[i+1]={i+1} w[i+1]=i+1 for i in range(k): x,y=I() while w[x]!=x:x=w[x] w[y]=x q[x].add(y) for i in range(n): if q[i+1]=={i+1}:q.pop(i+1) m=int(input()) for i in range(m): c,v=I() for j in q: if ...
17
124
2,048,000
203971957
import sys input = lambda: sys.stdin.readline().rstrip() from collections import Counter N = int(input()) P = [[] for _ in range(N)] for _ in range(int(input())): a,b = map(int, input().split()) P[a-1].append(b-1) P[b-1].append(a-1) seen = [-1]*N def paint(idx, color): v = [idx] while v: ...
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
177/C1
177
C1
PyPy 3-64
TESTS1
1
122
614,400
161567004
from collections import deque as dq n = int(input()) k = int(input()) friends = {i: [] for i in range(n)} for i in range(k): a, b = map(int, input().split()) friends[a-1].append(b-1) friends[b-1].append(a-1) m = int(input()) enemies = {i: [] for i in range(n)} for i in range(m): a, b = map(int, inp...
17
124
2,662,400
209748249
from collections import deque n = int(input()) m = int(input()) f = dict() for _ in range(m): a, b = map(int,input().split()) if a not in f: f[a] = set() if b not in f: f[b] = set() f[a].add(b) f[b].add(a) k = int(input()) h = dict() for _ in range(k): a, b = map(int,input().s...
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/B
408
B
Python 3
TESTS
5
31
0
187161092
n, m = input(), input() n_cnt, m_cnt = {}, {} for n_color, m_color in zip(n, m): n_cnt[n_color] = n_cnt.get(n_color, 0) + 1 m_cnt[m_color] = m_cnt.get(m_color, 0) + 1 m = set(m) if set(m) - set(n): print(-1) else: ans = 0 for color in m: ans += min(n_cnt[color], m_cnt[color]) print(ans)
21
31
0
220873771
a=input() b=input() c='' ans=0 for num in b: if num not in c: c=c+num for num in c: x=a.count(num) y=b.count(num) if x==0: ans=-1 break else: ans=ans+min(x,y) 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
175/C
175
C
PyPy 3-64
TESTS
2
122
0
166084471
n = int(input()) vals = [] for _ in range(n): num, val = map(int, input().split()) vals.append((val, num)) t = int(input()) factors = list(map(int, input().split())) vals.sort(reverse=True) ans, cnt, factor = 0, 0, 1 while vals: val, num = vals.pop() ans += num*val*factor if factors and cnt + num...
90
124
0
166150622
import sys input = sys.stdin.readline n = int(input()) f = [None] * n for i in range(n): k, c = map(int, input().split()) f[i] = [c, k] t = int(input()) p = list(map(int, input().split())) f.sort() res, count, factor = 0, 0, 1 i, j = 0, 0 while i < n and j < t: if count + f[i][1] <= p[j]: res += f[i...
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
33/A
33
A
Python 3
TESTS
10
122
0
13135757
n,b,c = input().split() n = int(n) b = int(b) c = int(c) a = [0 for i in range(b) ] for i in range(n): x,y = input().split() x = int(x) y = int(y) if a[x-1] != 0: if y < a[x-1]: a[x-1] = y else: a[x-1] = y s = 0 for i in a: s = s + i if c <= s: print (c) else: ...
31
92
0
142112060
n, m, k = [int(item) for item in (input().split(' '))] _sum = 0 _dict = {} for i in range(n): _row, health = [int(item) for item in (input().split(' '))] if _row in _dict and _dict[_row] > health or _row not in _dict: _dict[_row] = health # for key in _dict: # _sum += _dict[key] for item in _dict....
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
What is for dinner?
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c...
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
null
null
[{"input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11"}, {"input": "2 2 13\n1 13\n2 12", "output": "13"}]
1,200
["greedy", "implementation"]
31
[{"input": "4 3 18\r\n2 3\r\n1 2\r\n3 6\r\n2 3\r\n", "output": "11\r\n"}, {"input": "2 2 13\r\n1 13\r\n2 12\r\n", "output": "13\r\n"}, {"input": "5 4 8\r\n4 6\r\n4 5\r\n1 3\r\n2 0\r\n3 3\r\n", "output": "8\r\n"}, {"input": "1 1 0\r\n1 3\r\n", "output": "0\r\n"}, {"input": "7 1 30\r\n1 8\r\n1 15\r\n1 5\r\n1 17\r\n1 9\r\...
false
stdio
null
true
177/C1
177
C1
Python 3
TESTS1
3
218
307,200
60837558
def root(Arr,i): while(Arr[i]!=i): Arr[i]=Arr[Arr[i]] i=Arr[i] return i def Union(Arr,A,B): root_A= root(Arr,A) root_B=root(Arr,B) if size[root_B]<size[root_A]: Arr[root_B]=root_A size[root_A]+=size[root_B] else: Arr[root_A]=root_B size[root_B]+=si...
17
186
307,200
91274726
def dfs (chain): if chain: for c in chain: if c not in groups: groups.add(c) dfs(graph[c-1]) graph[c-1].clear() graph= [[] for _ in range(int(input()))]; sev = len(graph) groups,inv,ind = set(),{},1 for _ in range(int(input())): u,v = map(int,input...
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
29/D
29
D
Python 3
TESTS
5
92
102,400
218460324
t=int(input()) listt=[-1]*(t+1) listt2=[[] for i in range(t+1)] for i in range(t-1): a,b=map(int, input().split()) listt2[a].append(b) listt2[b].append(a) queue=[1] vis=[0]*(t+1) vis[1]=1 while queue: ele=queue.pop(0) for j in listt2[ele]: if vis[j]==0: queue.append(j) ...
35
124
102,400
222540518
def ni(): return int(input()) def ia(): return list(map(int, input().split())) def pod(g, root=0): n = len(g) par = [-1 for _ in range(n)] odr = [-1 for _ in range(n)] dep = [-1 for _ in range(n)] vis = [False for _ in range(n)] odr[root] = 0 dep[root] = 0 ptr = 1 for i in range(...
Codeforces Beta Round 29 (Div. 2, Codeforces format)
CF
2,010
2
256
Ant on the Tree
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connected by n - 1 edges so that there is a path between any pair of ver...
The first line contains integer n (3 ≤ n ≤ 300) — amount of vertexes in the tree. Next n - 1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has number 1. The las...
If the required route doesn't exist, output -1. Otherwise, output 2n - 1 numbers, describing the route. Every time the ant comes to a vertex, output it's index.
null
null
[{"input": "3\n1 2\n2 3\n3", "output": "1 2 3 2 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3", "output": "1 2 4 5 4 6 4 2 1 3 1"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6", "output": "-1"}]
2,000
["constructive algorithms", "dfs and similar", "trees"]
35
[{"input": "3\r\n1 2\r\n2 3\r\n3\r\n", "output": "1 2 3 2 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 6 3\r\n", "output": "1 2 4 5 4 6 4 2 1 3 1 "}, {"input": "6\r\n1 2\r\n1 3\r\n2 4\r\n4 5\r\n4 6\r\n5 3 6\r\n", "output": "-1\r\n"}, {"input": "10\r\n8 10\r\n2 1\r\n7 5\r\n5 4\r\n6 10\r\n2 3\r\n3 10\r\n2 9...
false
stdio
null
true
95/A
95
A
PyPy 3-64
TESTS
2
92
0
190589947
def print_ranges(r,s): for i in r: print(s[i[0]:i[1]]) def replace_ranges(r,s,char): for i in r: for j in range(i[0],i[1]): if s[j].islower(): s[j]=char else: s[j]=char.upper() n = int(input()) fd = [input().lower() for i in range(n)] ...
49
156
2,150,400
190658411
def print_ranges(r,s): for i in r: print(s[i[0]:i[1]]) def replace_ranges(r,s,char): final_s='' for i in range(len(r)): if r[i]: if s[i].lower()==char: #print("after low==char") if s[i].islower(): if s[i]=='a': ...
Codeforces Beta Round 77 (Div. 1 Only)
CF
2,011
2
256
Hockey
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin ...
The first line contains the only integer n (1 ≤ n ≤ 100) — the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The l...
Output the only line — Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically. The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller...
null
null
[{"input": "3\nbers\nucky\nelu\nPetrLoveLuckyNumbers\nt", "output": "PetrLovtTttttNumtttt"}, {"input": "4\nhello\nparty\nabefglghjdhfgj\nIVan\npetrsmatchwin\na", "output": "petrsmatchwin"}, {"input": "2\naCa\ncba\nabAcaba\nc", "output": "abCacba"}]
1,600
["implementation", "strings"]
49
[{"input": "3\r\nbers\r\nucky\r\nelu\r\nPetrLoveLuckyNumbers\r\nt\r\n", "output": "PetrLovtTttttNumtttt\r\n"}, {"input": "4\r\nhello\r\nparty\r\nabefglghjdhfgj\r\nIVan\r\npetrsmatchwin\r\na\r\n", "output": "petrsmatchwin\r\n"}, {"input": "2\r\naCa\r\ncba\r\nabAcaba\r\nc\r\n", "output": "abCacba\r\n"}, {"input": "3\r\nl...
false
stdio
null
true
595/B
595
B
Python 3
TESTS
5
46
0
15822359
MOD = 10**9 + 7 n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) #num of block m = n//k digit1 = 10**k digit2 = 10**(k-1) ans = 1 for i in range(m): A = (digit1 - 1) // a[i] + 1 B = (digit2 *(b[i] + 1) - 1) // a[i] - (digit2 * b[i] - 1) // a[i] ans ...
38
109
18,124,800
210966041
import sys input = lambda: sys.stdin.readline().rstrip() MOD = 10**9+7 N,K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) D = [] for i in range(N//K): a = A[i] b = B[i] cnt = 0 for j in range(10): if j==b:continue l = max(0,(10*...
Codeforces Round 330 (Div. 2)
CF
2,015
1
256
Pasha and Phone
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of le...
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a1, a2, ..., a...
Print a single integer — the number of good phone numbers of length n modulo 109 + 7.
null
In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
[{"input": "6 2\n38 56 49\n7 3 4", "output": "8"}, {"input": "8 2\n1 22 3 44\n5 4 3 2", "output": "32400"}]
1,600
["binary search", "math"]
38
[{"input": "6 2\r\n38 56 49\r\n7 3 4\r\n", "output": "8\r\n"}, {"input": "8 2\r\n1 22 3 44\r\n5 4 3 2\r\n", "output": "32400\r\n"}, {"input": "2 1\r\n9 9\r\n9 9\r\n", "output": "1\r\n"}, {"input": "2 1\r\n9 9\r\n0 9\r\n", "output": "1\r\n"}, {"input": "4 1\r\n4 3 2 1\r\n1 2 3 4\r\n", "output": "540\r\n"}, {"input": "18...
false
stdio
null
true
725/D
725
D
Python 3
PRETESTS
3
62
204,800
21688100
# You lost the game. n = int(input()) T = [list(map(int, input().split())) for _ in range(n)] C = T[1:] def ct(a): return a[0] C.sort(key=ct,reverse=True) M = [] for x in T: if x[0] > T[0][0]: M += [x] def ct2(a): return a[1]-a[0] M.sort(key=ct2) def rb(a,b,s): global C #print(a,b) ...
49
2,729
58,880,000
72025891
import sys input = sys.stdin.readline from heapq import heappop, heappush, heapify n = int(input()) b, _ = map(int, input().split()) heap = [] heap2 = [] for _ in range(n-1): t, w = map(int, input().split()) if t > b: heap.append(w + 1 - t) else: heap2.append((-t, -w)) heapify(heap) heapify...
Canada Cup 2016
CF
2,016
3
256
Contest Balloons
One tradition of ACM-ICPC contests is that a team gets a balloon for every solved problem. We assume that the submission time doesn't matter and teams are sorted only by the number of balloons they have. It means that one's place is equal to the number of teams with more balloons, increased by 1. For example, if there ...
The first line of the standard input contains one integer n (2 ≤ n ≤ 300 000) — the number of teams. The i-th of n following lines contains two integers ti and wi (0 ≤ ti ≤ wi ≤ 1018) — respectively the number of balloons and the weight of the i-th team. Limak is a member of the first team.
Print one integer denoting the best place Limak can get.
null
In the first sample, Limak has 20 balloons initially. There are three teams with more balloons (32, 40 and 45 balloons), so Limak has the fourth place initially. One optimal strategy is: 1. Limak gives 6 balloons away to a team with 32 balloons and weight 37, which is just enough to make them fly. Unfortunately, Limak...
[{"input": "8\n20 1000\n32 37\n40 1000\n45 50\n16 16\n16 16\n14 1000\n2 1000", "output": "3"}, {"input": "7\n4 4\n4 4\n4 4\n4 4\n4 4\n4 4\n5 5", "output": "2"}, {"input": "7\n14000000003 1000000000000000000\n81000000000 88000000000\n5000000000 7000000000\n15000000000 39000000000\n46000000000 51000000000\n0 1000000000\n...
1,800
["data structures", "greedy"]
49
[{"input": "8\r\n20 1000\r\n32 37\r\n40 1000\r\n45 50\r\n16 16\r\n16 16\r\n14 1000\r\n2 1000\r\n", "output": "3\r\n"}, {"input": "7\r\n4 4\r\n4 4\r\n4 4\r\n4 4\r\n4 4\r\n4 4\r\n5 5\r\n", "output": "2\r\n"}, {"input": "7\r\n14000000003 1000000000000000000\r\n81000000000 88000000000\r\n5000000000 7000000000\r\n1500000000...
false
stdio
null
true
989/D
989
D
Python 3
TESTS
7
1,044
8,806,400
39173462
from collections import defaultdict n, l, w = [int(item) for item in input().split()] clouds = [] for i in range(n): clouds.append([int(item) for item in input().split()]) answer = 0 d = defaultdict(int) m_array = sorted([item[0] for item in clouds if item[1] == -1]) p_array = sorted([item[0] for item in clouds...
30
841
6,860,800
39193022
# Codeforces Round #487 (Div. 2)import collections from functools import cmp_to_key #key=cmp_to_key(lambda x,y: 1 if x not in y else -1 ) import sys def getIntList(): return list(map(int, input().split())) import bisect N,L,WM = getIntList() z = {} z[-1] = {1:[], -1:[]} z[0] = {1:[],...
Codeforces Round 487 (Div. 2)
CF
2,018
2
256
A Shade of Moonlight
The sky can be seen as a one-dimensional axis. The moon is at the origin whose coordinate is $$$0$$$. There are $$$n$$$ clouds floating in the sky. Each cloud has the same length $$$l$$$. The $$$i$$$-th initially covers the range of $$$(x_i, x_i + l)$$$ (endpoints excluded). Initially, it moves at a velocity of $$$v_i...
The first line contains three space-separated integers $$$n$$$, $$$l$$$, and $$$w_\mathrm{max}$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq l, w_\mathrm{max} \leq 10^8$$$) — the number of clouds, the length of each cloud and the maximum wind speed, respectively. The $$$i$$$-th of the following $$$n$$$ lines contains two sp...
Output one integer — the number of unordered pairs of clouds such that it's possible that clouds from each pair cover the moon at the same future moment with a proper choice of wind velocity $$$w$$$.
null
In the first example, the initial positions and velocities of clouds are illustrated below. The pairs are: - $$$(1, 3)$$$, covering the moon at time $$$2.5$$$ with $$$w = -0.4$$$; - $$$(1, 4)$$$, covering the moon at time $$$3.5$$$ with $$$w = -0.6$$$; - $$$(1, 5)$$$, covering the moon at time $$$4.5$$$ with $$$w = -...
[{"input": "5 1 2\n-2 1\n2 1\n3 -1\n5 -1\n7 -1", "output": "4"}, {"input": "4 10 1\n-20 1\n-10 -1\n0 1\n10 -1", "output": "1"}]
2,500
["binary search", "geometry", "math", "sortings", "two pointers"]
30
[{"input": "5 1 2\r\n-2 1\r\n2 1\r\n3 -1\r\n5 -1\r\n7 -1\r\n", "output": "4\r\n"}, {"input": "4 10 1\r\n-20 1\r\n-10 -1\r\n0 1\r\n10 -1\r\n", "output": "1\r\n"}, {"input": "1 100000000 98765432\r\n73740702 1\r\n", "output": "0\r\n"}, {"input": "10 2 3\r\n-1 -1\r\n-4 1\r\n-6 -1\r\n1 1\r\n10 -1\r\n-8 -1\r\n6 1\r\n8 1\r\n...
false
stdio
null
true
493/A
493
A
Python 3
TESTS
6
109
307,200
85735925
home = input() away = input() n = int(input()) ytrial = [] rtrial = [] for s in range(n) : m,t,p,c = map(str,input().split()) pair = [] pair.append(p) pair.append(t) if (c == 'r' and pair not in rtrial )or pair in ytrial: rtrial.append(pair) if t == 'a' : print(away,end='...
18
61
0
9151895
h = input() a = input() n = int(input()) d = dict() for i in range(n): arr = input().split() mark = (h if arr[1] == 'h' else a) + ' ' + arr[2] if mark not in d: d[mark] = 0 if d[mark] < 2: d[mark] += 1 if arr[3] == 'y' else 2 if d[mark] >= 2: print(mark, arr[0])
Codeforces Round 281 (Div. 2)
CF
2,014
2
256
Vasya and Football
Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card. Vasya is watching a recorded football match now and makes notes of all the fouls tha...
The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the...
For each event when a player received his first red card in a chronological order print a string containing the following information: - The name of the team to which the player belongs; - the player's number in his team; - the minute when he received the card. If no player received a card, then you do not need to pr...
null
null
[{"input": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r", "output": "MC 25 70\nMC 42 82\nCSKA 13 90"}]
1,300
["implementation"]
18
[{"input": "MC\r\nCSKA\r\n9\r\n28 a 3 y\r\n62 h 25 y\r\n66 h 42 y\r\n70 h 25 y\r\n77 a 4 y\r\n79 a 25 y\r\n82 h 42 r\r\n89 h 16 y\r\n90 a 13 r\r\n", "output": "MC 25 70\r\nMC 42 82\r\nCSKA 13 90\r\n"}, {"input": "REAL\r\nBARCA\r\n3\r\n27 h 7 y\r\n44 a 10 y\r\n87 h 3 r\r\n", "output": "REAL 3 87\r\n"}, {"input": "MASFF\...
false
stdio
null
true
595/B
595
B
Python 3
TESTS
5
46
0
14892841
def main(): n, k = map(int, input().split()) tk0, tk1, res = 10 ** (k - 1), 10 ** k - 1, 1 for a, b in zip(map(int, input().split()), map(int, input().split())): res *= tk1 // a + (tk0 * b - 1) // a - (tk0 * (b + 1) - 1) // a + 1 print(res) if __name__ == '__main__': main()
38
139
7,168,000
14148453
n, k = map(int, input().split()) As = list(map(int, input().split())) Bs = list(map(int, input().split())) def solve(n, k, As, Bs): mod = 10 ** 9 + 7 c = 1 for a, b in zip(As, Bs): c *= f(a, b, k, mod) c %= mod return c def f(a, b, k, mod): total = (10 ** k - 1) // a + 1 p = ((...
Codeforces Round 330 (Div. 2)
CF
2,015
1
256
Pasha and Phone
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of le...
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a1, a2, ..., a...
Print a single integer — the number of good phone numbers of length n modulo 109 + 7.
null
In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
[{"input": "6 2\n38 56 49\n7 3 4", "output": "8"}, {"input": "8 2\n1 22 3 44\n5 4 3 2", "output": "32400"}]
1,600
["binary search", "math"]
38
[{"input": "6 2\r\n38 56 49\r\n7 3 4\r\n", "output": "8\r\n"}, {"input": "8 2\r\n1 22 3 44\r\n5 4 3 2\r\n", "output": "32400\r\n"}, {"input": "2 1\r\n9 9\r\n9 9\r\n", "output": "1\r\n"}, {"input": "2 1\r\n9 9\r\n0 9\r\n", "output": "1\r\n"}, {"input": "4 1\r\n4 3 2 1\r\n1 2 3 4\r\n", "output": "540\r\n"}, {"input": "18...
false
stdio
null
true
351/D
351
D
PyPy 3
TESTS
10
2,526
24,883,200
202104504
# ====== author: kuanc (www.hank.fyi) | created: 04/15/23 01:14:36 CST ====== # from sys import stdin, stderr, stdout, setrecursionlimit from bisect import bisect_left, bisect_right from collections import defaultdict, deque, Counter from itertools import accumulate, combinations, permutatio...
29
2,495
84,889,600
202114591
# ====== author: kuanc (www.hank.fyi) | created: 04/15/23 01:14:36 CST ====== # from sys import stdin, stderr, stdout, setrecursionlimit from bisect import bisect_left, bisect_right from collections import defaultdict, deque, Counter from itertools import accumulate, combinations, permutatio...
Codeforces Round 204 (Div. 1)
CF
2,013
3
256
Jeff and Removing Periods
Cosider a sequence, consisting of n integers: a1, a2, ..., an. Jeff can perform the following operation on sequence a: - take three integers v, t, k (1 ≤ v, t ≤ n; 0 ≤ k; v + tk ≤ n), such that av = av + t, av + t = av + 2t, ..., av + t(k - 1) = av + tk; - remove elements av, av + t, ..., av + t·k from the sequence a,...
The first line contains integer m (1 ≤ m ≤ 105). The next line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 105). The third line contains integer q (1 ≤ q ≤ 105) — the number of questions. The next q lines contain pairs of integers, i-th of them contains a pair of integers li, ri (1 ≤ li ≤ ri ≤ m) — the description o...
In q lines print the answers to Jeff's queries. Print the answers according to the order of questions in input.
null
null
[{"input": "5\n2 2 1 1 2\n5\n1 5\n1 1\n2 2\n1 3\n2 3", "output": "2\n1\n1\n2\n2"}, {"input": "10\n2 1 3 3 3 3 1 3 1 1\n10\n4 8\n2 10\n1 10\n4 4\n1 3\n2 4\n6 7\n1 9\n2 5\n1 1", "output": "2\n3\n3\n1\n3\n2\n2\n3\n2\n1"}]
2,700
["data structures"]
29
[{"input": "5\r\n2 2 1 1 2\r\n5\r\n1 5\r\n1 1\r\n2 2\r\n1 3\r\n2 3\r\n", "output": "2\r\n1\r\n1\r\n2\r\n2\r\n"}, {"input": "10\r\n2 1 3 3 3 3 1 3 1 1\r\n10\r\n4 8\r\n2 10\r\n1 10\r\n4 4\r\n1 3\r\n2 4\r\n6 7\r\n1 9\r\n2 5\r\n1 1\r\n", "output": "2\r\n3\r\n3\r\n1\r\n3\r\n2\r\n2\r\n3\r\n2\r\n1\r\n"}, {"input": "15\r\n3 3 ...
false
stdio
null
true
595/B
595
B
Python 3
PRETESTS
5
46
0
14148826
s = input() n, k = s.split() n = int(n) k = int(k) pw = 10 ** k s = input() a = s.split() s = input() b = s.split() ns = 1 for i in range(n // k): ans = 0 aa = int(a[i]) bb = int(b[i]) if bb == 0: ans = ans + (pw - 1) // aa - (pw // 10 - 1) // aa else: ans = ans + (pw - 1) // aa - (...
38
139
31,027,200
124713414
MOD=10**9+7 n,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) k1,k2,ans=10**k,10**(k-1),1 for i in range(n//k): z,x=a[i],b[i] if b[i]>0: c=(x*k2-1)//z+(k1-1)//z-((x+1)*k2-1)//z+1 else: c=(k1-1)//z-(k2-1)//z ans=ans*c%MOD print(ans)
Codeforces Round 330 (Div. 2)
CF
2,015
1
256
Pasha and Phone
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of le...
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a1, a2, ..., a...
Print a single integer — the number of good phone numbers of length n modulo 109 + 7.
null
In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
[{"input": "6 2\n38 56 49\n7 3 4", "output": "8"}, {"input": "8 2\n1 22 3 44\n5 4 3 2", "output": "32400"}]
1,600
["binary search", "math"]
38
[{"input": "6 2\r\n38 56 49\r\n7 3 4\r\n", "output": "8\r\n"}, {"input": "8 2\r\n1 22 3 44\r\n5 4 3 2\r\n", "output": "32400\r\n"}, {"input": "2 1\r\n9 9\r\n9 9\r\n", "output": "1\r\n"}, {"input": "2 1\r\n9 9\r\n0 9\r\n", "output": "1\r\n"}, {"input": "4 1\r\n4 3 2 1\r\n1 2 3 4\r\n", "output": "540\r\n"}, {"input": "18...
false
stdio
null
true
12/C
12
C
Python 3
TESTS
10
61
0
141009226
case_list = input().split() price_list = [*map(lambda x: int(x), input().split())] fruit_list = [input() for i in range(int(case_list[1]))] desc_price = sorted(price_list, reverse=True) asc_price = sorted(price_list) def price_finder(price_list, fruit_list): duplicate_fruits = list(set([i for i in fruit_list if...
25
31
0
229423181
enter1 = list(map(int, input().split())) n = enter1[0] m = enter1[1] li = list(map(int, input().split())) fruits = list() for i in range(m): fruits.append(input()) se = set(fruits) kol_vo = [] li_se = list(se) for i in range(len(li_se)): kol_vo.append(fruits.count(li_se[i])) kol_vo.sort() kol_vo.reverse() l...
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
Python 3
TESTS
10
124
1,740,800
116456266
n,m=map(int,input().split()) l1,l2,k=[],[],0 for i in range(n): l1.append(input()) for i in range(m): l2.append(input()) for i in l1: if i in l2: k+=1 if k%2==0: if (len(l1)-1)>len(l2): print("YES") else: print("NO") else: if (len(l1))>(len(l2)-1): p...
33
46
512,000
188350307
import sys input = lambda: sys.stdin.readline().strip() n, m = map(int, input().split()) pol, com = set(), 0 for _ in range(n): pol.add(input()) for _ in range(m): com += input() in pol n += com & 1 if n > m: print("YES") else: print("NO")
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
412/B
412
B
Python 3
TESTS
4
31
0
223508523
n , k = map(int,input().split()) network_speeds_sorted = (input().split()) network_speeds_sorted.sort(reverse=False) #print(network_speeds_sorted) print(network_speeds_sorted[k-1])
34
46
0
152848838
from os import remove n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) print(a[k-1])
Coder-Strike 2014 - Round 1
CF
2,014
1
256
Network Configuration
The R1 company wants to hold a web search championship. There were n computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessar...
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of n integers: a1, a2, ..., an (16 ≤ ai ≤ 32768); number ai denotes the maximum data transfer speed on ...
Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer.
null
In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal.
[{"input": "3 2\n40 20 30", "output": "30"}, {"input": "6 4\n100 20 40 20 50 50", "output": "40"}]
900
["greedy", "sortings"]
34
[{"input": "3 2\r\n40 20 30\r\n", "output": "30\r\n"}, {"input": "6 4\r\n100 20 40 20 50 50\r\n", "output": "40\r\n"}, {"input": "1 1\r\n16\r\n", "output": "16\r\n"}, {"input": "2 1\r\n10000 17\r\n", "output": "10000\r\n"}, {"input": "2 2\r\n200 300\r\n", "output": "200\r\n"}, {"input": "3 1\r\n21 25 16\r\n", "output":...
false
stdio
null
true
543/B
543
B
Python 3
TESTS
3
77
819,200
11970655
import queue def bfs(s,t,a,n,q): d = [-1] * (n+1) d[s] = 0 q.put(s) while (q.empty() != True): u = q.get() for i in range(len(a[u])): if (d[a[u][i]] == -1): d[a[u][i]] = d[u] + 1 q.put(a[u][i]) return d[t] n,m = map(int,input().split(...
63
1,731
91,955,200
174886422
from collections import deque n,m=map(int,input().split()) graph=[[] for _ in range(n)] for i in range(m): a,b=map(int,input().split()) a-=1 b-=1 graph[a].append(b) graph[b].append(a) d=[[-1]*n for _ in range(n)] for i in range(n): q=deque() q.append(i) d[i][i]=0 while q: n...
Codeforces Round 302 (Div. 1)
CF
2,015
2
256
Destroying Roads
In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a to city b, or from city b to city a. The road network is such that from any ...
The first line contains two integers n, m (1 ≤ n ≤ 3000, $$n-1\leq m\leq \min\{3000,\frac{n(n-1)}{2}\}$$) — the number of cities and roads in the country, respectively. Next m lines contain the descriptions of the roads as pairs of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi). It is guaranteed that the roads that are giv...
Print a single number — the answer to the problem. If the it is impossible to meet the conditions, print -1.
null
null
[{"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2", "output": "0"}, {"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2", "output": "1"}, {"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1", "output": "-1"}]
2,100
["constructive algorithms", "graphs", "shortest paths"]
63
[{"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n3 5 2\r\n", "output": "0\r\n"}, {"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n2 4 2\r\n", "output": "1\r\n"}, {"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n3 5 1\r\n", "output": "-1\r\n"}, {"input": "9 9\r\n1 2\r\n2 3\r\n2 4\r\n4 5\r\n5 7\r\n5 6\...
false
stdio
null
true
25/D
25
D
PyPy 3
TESTS
9
218
0
116866465
import math import sys n = int(input()) g = [] fa = [i for i in range(0,n+1)] value = [0 for i in range(0,n+1)] num = [1 for i in range(0,n+1)] vec = [] def getfa(x): if x == fa[x]: return x else: root = getfa(fa[x]) fa[x] = root return fa[x] for i in range(n-1): u,v = ma...
55
92
204,800
204541784
class DSU: def __init__(self, n):#Инициализация системы непересекающихся множеств self.parents = list(range(n+1)) # ранг - характеристика высоты поддерева self.ranks = [1]*(n+1) # self.redundant = [] def find(self, elem):#Функция, которая возвращает родителя множества, которому принажлежит элемент if self.p...
Codeforces Beta Round 25 (Div. 2 Only)
ICPC
2,010
2
256
Roads not only in Berland
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way r...
The first line contains integer n (2 ≤ n ≤ 1000) — amount of cities in Berland and neighboring countries. Next n - 1 lines contain the description of roads. Each road is described by two space-separated integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — pair of cities, which the road connects. It can't be more than one road b...
Output the answer, number t — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output t lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between ...
null
null
[{"input": "2\n1 2", "output": "0"}, {"input": "7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7", "output": "1\n3 1 3 7"}]
1,900
["dsu", "graphs", "trees"]
55
[{"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 7\r\n", "output": "1\r\n3 1 3 7\r\n"}, {"input": "3\r\n3 2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1\r\n3 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 4\r\n3 1\r\n3 4\r\n", "output": "1\r\n3 4 2 4\r\n"}, {"in...
false
stdio
import sys def read_input(input_path): with open(input_path) as f: n = int(f.readline()) edges = set() for _ in range(n-1): a, b = map(int, f.readline().split()) if a > b: a, b = b, a edges.add((a, b)) return n, edges def check_in...
true
727/E
727
E
Python 3
TESTS
1
31
0
142536466
def pow(x, p): res = 1 for i in bin(p)[2:][::-1]: if i == '1': res = (res * x) % mod x = (x * x) % mod return res mod = int(1e9) + 9 p = 31 p_inv = pow(p, mod - 2) def solve(): k, l = list(map(int, input().split(" "))) s = input() if k * l != len(s): pri...
87
3,244
54,476,800
158830314
import sys input = sys.stdin.buffer.readline p = 24738041398529 def process(n, k, S, G): g = len(G) matrix = [[0 for j in range(k)] for i in range(g)] sums = [0 for i in range(k)] word_dict = {} for i in range(g): word = 0 for j in range(k): si = ord(G[i][j])-ord('a')...
Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2)
CF
2,016
4
512
Games on a CD
Several years ago Tolya had n computer games and at some point of time he decided to burn them to CD. After that he wrote down the names of the games one after another in a circle on the CD in clockwise order. The names were distinct, the length of each name was equal to k. The names didn't overlap. Thus, there is a c...
The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 105) — the amount of games Tolya burned to the CD, and the length of each of the names. The second line of the input contains one string consisting of lowercase English letters — the string Tolya wrote on the CD, split in arbitrar...
If there is no answer, print "NO" (without quotes). Otherwise, print two lines. In the first line print "YES" (without quotes). In the second line, print n integers — the games which names were written on the CD. You should print games in the order they could have been written on the CD, it means, in clockwise order. ...
null
null
[{"input": "3 1\nabc\n4\nb\na\nc\nd", "output": "YES\n2 1 3"}, {"input": "4 2\naabbccdd\n4\ndd\nab\nbc\ncd", "output": "NO"}]
2,300
["data structures", "hashing", "string suffix structures", "strings"]
87
[{"input": "3 1\r\nabc\r\n4\r\nb\r\na\r\nc\r\nd\r\n", "output": "YES\r\n2 1 3 \r\n"}, {"input": "4 2\r\naabbccdd\r\n4\r\ndd\r\nab\r\nbc\r\ncd\r\n", "output": "NO\r\n"}, {"input": "2 2\r\nkdcj\r\n4\r\ncj\r\nkd\r\njk\r\ndc\r\n", "output": "YES\r\n3 4 \r\n"}, {"input": "10 10\r\nlgfrjgityzwtmfyygmpsmokiwphewhpoelsvnctwxmp...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n, k = map(int, f.readline().split()) cd_str = f.readline().strip() g = int(f.readline()) games = [f.readlin...
true
46/C
46
C
Python 3
TESTS
7
92
0
218646854
def min_swaps_to_separate_hamsters_and_tigers(n, animals): hamster_count = animals.count('H') tiger_count = n - hamster_count min_swaps = float('inf') for i in range(n): window = animals[i:] + animals[:i] tigers_inside_window = window[:hamster_count].count('T') swaps_required ...
27
92
0
149259101
n=int(input()) s=input() q=s.count("H") w=n-q o=1001 for i in range(n-q+1): o=min(o,q-s[i:i+q].count("H")) for i in range(n-w+1): o=min(o,w-s[i:i+w].count("T")) print(o)
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
456/A
456
A
PyPy 3-64
TESTS
39
639
13,312,000
193960737
n=int(input()) i=0 list1=[] list2=[] while i<n: a,b=list(map(int,input().split())) list1.append(a) list2.append(b) i+=1 u=0 flag=True while u<len(list1)-1: if list1[u]<=list1[u+1]: if list2[u]>list2[u+1]: flag=False if list1[u]>list1[u+1]: if list2[u]<list2[u+1]: ...
46
93
0
209949048
for _ in range(int(input())): g,h=input().split() if g!=h: print('Happy Alex') exit() print('Poor Alex')
Codeforces Round 260 (Div. 2)
CF
2,014
1
256
Laptops
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai ar...
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
null
null
[{"input": "2\n1 2\n2 1", "output": "Happy Alex"}]
1,100
["sortings"]
46
[{"input": "2\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n2 2\r\n3 3\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n3 3\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "1\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"inp...
false
stdio
null
true
46/C
46
C
Python 3
TESTS
7
62
0
218531395
n = int(input()) animals = input() total_hamsters = animals.count('H') total_tigers = n - total_hamsters min_swaps = float('inf') for i in range(n): hamsters_in_segment = sum(1 for j in range(i, i + total_hamsters) if animals[j % n] == 'H') tigers_in_segment = total_hamsters - hamsters_in_segment sw...
27
92
0
149260259
I=input n=int(I()) s=I() q=s.count("H") s+=s print(min(s[i:i+q].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
543/D
543
D
PyPy 3-64
TESTS
11
1,294
101,273,600
214705608
# Day1 # C. Basketball Exercise # https://codeforces.com/problemset/problem/1195/C """ 输入 n(1≤n≤1e5) 和一个 2 行 n 列的矩阵 a(1≤a[i][j]≤1e9)。 你需要从矩阵中选择一些数,要求任意两数不能左右相邻,也不能上下相邻。 输出所选数字之和的最大值。 思考:如果改成 m 列要怎么做? https://ac.nowcoder.com/acm/contest/59157/O 输入 5 9 3 5 7 3 5 8 1 4 5 输出 29 输入 3 1 2 9 10 1 1 输出 19 输入 1 7 4 输出 7 """ ...
42
311
44,441,600
214721915
import sys # import itertools # import math # import os # import random # from bisect import bisect, bisect_left # from collections import * # from functools import reduce # from heapq import heapify, heappop, heappush # from io import BytesIO, IOBase # from string import * # region fastio input = lambda: sys.stdin.r...
Codeforces Round 302 (Div. 1)
CF
2,015
2
256
Road Improvement
The country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n inclusive. All the roads are initially bad, but the government wants to improve the state of some roads. We will assume that...
The first line of the input contains a single integer n (2 ≤ n ≤ 2·105) — the number of cities in the country. Next line contains n - 1 positive integers p2, p3, p4, ..., pn (1 ≤ pi ≤ i - 1) — the description of the roads in the country. Number pi means that the country has a road connecting city pi and city i.
Print n integers a1, a2, ..., an, where ai is the sought number of ways to improve the quality of the roads modulo 1 000 000 007 (109 + 7), if the capital of the country is at city number i.
null
null
[{"input": "3\n1 1", "output": "4 3 3"}, {"input": "5\n1 2 3 4", "output": "5 8 9 8 5"}]
2,300
["dp", "trees"]
42
[{"input": "3\r\n1 1\r\n", "output": "4 3 3"}, {"input": "5\r\n1 2 3 4\r\n", "output": "5 8 9 8 5"}, {"input": "31\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "73741817 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870...
false
stdio
null
true
1010/D
1010
D
PyPy 3
TESTS
4
139
0
75643551
# https://codeforces.com/problemset/problem/1010/D def handle(type_, val_, u, g, S): if type_ == 'NOT': S.append(g[u][0]) else: v1, v2 = g[u] val1, val2 = d[v1][1], d[v2][1] if oper[type_](1-val1, val2) != val_: S.append(v1) if o...
124
3,400
179,404,800
40819443
import sys n=int(input()) f={'AND':(lambda a,b:a&b),'OR':(lambda a,b:a|b),'XOR':(lambda a,b:a^b),'NOT':(lambda a:a^1)} g={'0':(lambda:0),'1':(lambda:1)} d=[(g[v[0]],[]) if o=='IN' else (f[o],[int(a)-1 for a in v]) for o,*v in map(str.split,sys.stdin.read().strip().split('\n'))] t=[0] for i in t:t.extend(d[i][1]) v=[0]*...
Codeforces Round 499 (Div. 1)
CF
2,018
5
256
Mars rover
Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex $$$1$$$, in which every leaf (excluding root) is an input, and all other vertices are logical elements, including the roo...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^6$$$) — the number of vertices in the graph (both inputs and elements). The $$$i$$$-th of the next $$$n$$$ lines contains a description of $$$i$$$-th vertex: the first word "AND", "OR", "XOR", "NOT" or "IN" (means the input of the scheme) is the verte...
Print a string of characters '0' and '1' (without quotes) — answers to the problem for each input in the ascending order of their vertex indices.
null
The original scheme from the example (before the input is changed): Green indicates bits '1', yellow indicates bits '0'. If Natasha changes the input bit $$$2$$$ to $$$0$$$, then the output will be $$$1$$$. If Natasha changes the input bit $$$3$$$ to $$$0$$$, then the output will be $$$0$$$. If Natasha changes the ...
[{"input": "10\nAND 9 4\nIN 1\nIN 1\nXOR 6 5\nAND 3 7\nIN 0\nNOT 10\nIN 1\nIN 1\nAND 2 8", "output": "10110"}]
2,000
["dfs and similar", "graphs", "implementation", "trees"]
124
[{"input": "10\r\nAND 9 4\r\nIN 1\r\nIN 1\r\nXOR 6 5\r\nAND 3 7\r\nIN 0\r\nNOT 10\r\nIN 1\r\nIN 1\r\nAND 2 8\r\n", "output": "10110"}, {"input": "3\r\nAND 2 3\r\nIN 0\r\nIN 0\r\n", "output": "00"}, {"input": "3\r\nAND 2 3\r\nIN 1\r\nIN 0\r\n", "output": "01"}, {"input": "3\r\nAND 2 3\r\nIN 0\r\nIN 1\r\n", "output": "10...
false
stdio
null
true
25/D
25
D
PyPy 3-64
TESTS
10
92
512,000
158787812
def dfs(vertex, last_vertex): global e, to_del_1, to_del_2 marked[vertex] = True for vertex2 in graph[vertex]: if vertex2 != last_vertex: if marked[vertex2]: to_del_1, to_del_2 = vertex, vertex2 e = True else: dfs(vertex2, vertex) n = int(input()) graph = [set() for i in range(n)] for i in rang...
55
92
204,800
209986967
MAXN = 1090 def find(parent, x): # Función para encontrar el padre del nodo x utilizando compresión de caminos if x == parent[x]: return x parent[x] = find(parent, parent[x]) return parent[x] def solve(): n = int(input()) # Inicializar el arreglo de padres con valores iniciales pa...
Codeforces Beta Round 25 (Div. 2 Only)
ICPC
2,010
2
256
Roads not only in Berland
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way r...
The first line contains integer n (2 ≤ n ≤ 1000) — amount of cities in Berland and neighboring countries. Next n - 1 lines contain the description of roads. Each road is described by two space-separated integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — pair of cities, which the road connects. It can't be more than one road b...
Output the answer, number t — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output t lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between ...
null
null
[{"input": "2\n1 2", "output": "0"}, {"input": "7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7", "output": "1\n3 1 3 7"}]
1,900
["dsu", "graphs", "trees"]
55
[{"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 7\r\n", "output": "1\r\n3 1 3 7\r\n"}, {"input": "3\r\n3 2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1\r\n3 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 4\r\n3 1\r\n3 4\r\n", "output": "1\r\n3 4 2 4\r\n"}, {"in...
false
stdio
import sys def read_input(input_path): with open(input_path) as f: n = int(f.readline()) edges = set() for _ in range(n-1): a, b = map(int, f.readline().split()) if a > b: a, b = b, a edges.add((a, b)) return n, edges def check_in...
true
456/A
456
A
Python 3
TESTS
39
217
0
222752443
t=int(input()) i=0 r=[] p=[] flag=0 while(i<t): x,y=map(int,input().split(" ")) if(len(r)==0): r.append(x) p.append(y) else: #print(r[0],p[0],x,y) if((r[0]>x and p[0]<y) or (r[0]<x and p[0]>y)): flag=1 i=t #print(flag) else: ...
46
93
3,072,000
209205486
import sys def input(): return sys.stdin.readline().strip() def getints(): return map(int,sys.stdin.readline().strip().split()) for _ in range(int(input())): x, y = getints() if x != y: print('Happy Alex') break else: print('Poor Alex')
Codeforces Round 260 (Div. 2)
CF
2,014
1
256
Laptops
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai ar...
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
null
null
[{"input": "2\n1 2\n2 1", "output": "Happy Alex"}]
1,100
["sortings"]
46
[{"input": "2\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n2 2\r\n3 3\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n3 3\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "1\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"inp...
false
stdio
null
true
980/C
980
C
Python 3
PRETESTS
9
92
7,065,600
38038304
def main(): n, k = [int(_) for _ in input().split()] a = [int(_) for _ in input().split()] p = [-1] * 256 p[0] = 0 for i, x in enumerate(a): if p[x] < 0: for y in range(x - 1, max(-1, x - k), -1): if p[y] >= 0: p[x] = p[y] if p[y] + k > x else y + 1 break if p[x] < 0: p[x] = p[x - k +...
82
124
16,384,000
165234904
from bisect import * from collections import * import sys import io, os import math import random from heapq import * gcd = math.gcd sqrt = math.sqrt maxint=10**21 def ceil(a, b): if(b==0): return maxint a = -a k = a // b k = -k return k # arr=list(map(int, input().split())) # n,m=map(int,in...
Codeforces Round 480 (Div. 2)
CF
2,018
1
256
Posterized
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $$$i$$$-th integer represents the color of the $$$i$$$-th pixel in the image. The image is in black and white...
The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq k \leq 256$$$), the number of pixels in the image, and the maximum size of a group, respectively. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$0 \leq p_i \leq 255$$$), where $$$p_i$$$ is t...
Print $$$n$$$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter.
null
One possible way to group colors and assign keys for the first sample: Color $$$2$$$ belongs to the group $$$[0,2]$$$, with group key $$$0$$$. Color $$$14$$$ belongs to the group $$$[12,14]$$$, with group key $$$12$$$. Colors $$$3$$$ and $$$4$$$ belong to group $$$[3, 5]$$$, with group key $$$3$$$. Other groups won...
[{"input": "4 3\n2 14 3 4", "output": "0 12 3 3"}, {"input": "5 2\n0 2 1 255 254", "output": "0 1 1 254 254"}]
1,700
["games", "greedy"]
82
[{"input": "4 3\r\n2 14 3 4\r\n", "output": "0 12 3 3\r\n"}, {"input": "5 2\r\n0 2 1 255 254\r\n", "output": "0 1 1 254 254\r\n"}, {"input": "10 3\r\n112 184 161 156 118 231 191 128 91 229\r\n", "output": "110 182 159 154 116 229 189 126 89 229\r\n"}, {"input": "9 3\r\n174 149 118 124 166 146 219 233 107\r\n", "output"...
false
stdio
null
true
351/B
351
B
Python 3
TESTS
10
156
204,800
4804797
from sys import * n=int(stdin.readline().strip()) s1=stdin.readline().strip() a=list(map(int,s1.split())) if n==1: print('0') else: x=0 n0=1 while n0<n: n0=n0*2 b=[0]*(2*n0+10) '''for i in range (n-1): for j in range (i+1,n): if a[i]>a[j]: x+=1''' ...
25
124
102,400
5475355
from bisect import bisect_right input() t = list(map(int, input().split())) s, p = 0, [] for i, j in enumerate(t): k = bisect_right(p, j) s += i - k p.insert(k, j) print(2 * s - (s & 1))
Codeforces Round 204 (Div. 1)
CF
2,013
1
256
Jeff and Furik
Jeff has become friends with Furik. Now these two are going to play one quite amusing game. At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p1, p2, ..., pn. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two adjace...
The first line contains integer n (1 ≤ n ≤ 3000). The next line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation p. The numbers are separated by spaces.
In a single line print a single real value — the answer to the problem. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.
null
In the first test the sequence is already sorted, so the answer is 0.
[{"input": "2\n1 2", "output": "0.000000"}, {"input": "5\n3 5 2 4 1", "output": "13.000000"}]
1,900
["combinatorics", "dp", "probabilities"]
25
[{"input": "2\r\n1 2\r\n", "output": "0.000000\r\n"}, {"input": "5\r\n3 5 2 4 1\r\n", "output": "13.000000\r\n"}, {"input": "16\r\n6 15 3 8 7 11 9 10 2 13 4 14 1 16 5 12\r\n", "output": "108.000000\r\n"}, {"input": "9\r\n1 7 8 5 3 4 6 9 2\r\n", "output": "33.000000\r\n"}, {"input": "5\r\n2 3 4 5 1\r\n", "output": "8.00...
false
stdio
import sys def read_float_from_line(line): line = line.strip() try: return float(line) except: return None def is_acceptable(ref, sub, abs_tol=1e-6, rel_tol=1e-6): if abs(ref - sub) <= abs_tol: return True denom = max(abs(ref), 1e-8) return abs(ref - sub) / denom <= rel...
true
980/C
980
C
PyPy 3-64
TESTS
9
62
0
205824485
import sys input = sys.stdin.readline n, k = map(int, input().split()) x = [-1]*256 w = list(map(int, input().split())) q = [] for i in w: if x[i] == -1: for j in range(i, max(-1, i-k), -1): if x[j] == -1: t = j else: break if t in [i-k+1, 0]:...
82
140
16,076,800
199498783
import math import random import time def init_tree(n): return [0] * (n + 1) def update(tree, i, val): i += 1 while i < len(tree): tree[i] += val i += i & -i def range_update(tree, l, r, val): update(tree, l, val) update(tree, r + 1, -val) def query(tree, i): i += 1 res =...
Codeforces Round 480 (Div. 2)
CF
2,018
1
256
Posterized
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $$$i$$$-th integer represents the color of the $$$i$$$-th pixel in the image. The image is in black and white...
The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq k \leq 256$$$), the number of pixels in the image, and the maximum size of a group, respectively. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$0 \leq p_i \leq 255$$$), where $$$p_i$$$ is t...
Print $$$n$$$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter.
null
One possible way to group colors and assign keys for the first sample: Color $$$2$$$ belongs to the group $$$[0,2]$$$, with group key $$$0$$$. Color $$$14$$$ belongs to the group $$$[12,14]$$$, with group key $$$12$$$. Colors $$$3$$$ and $$$4$$$ belong to group $$$[3, 5]$$$, with group key $$$3$$$. Other groups won...
[{"input": "4 3\n2 14 3 4", "output": "0 12 3 3"}, {"input": "5 2\n0 2 1 255 254", "output": "0 1 1 254 254"}]
1,700
["games", "greedy"]
82
[{"input": "4 3\r\n2 14 3 4\r\n", "output": "0 12 3 3\r\n"}, {"input": "5 2\r\n0 2 1 255 254\r\n", "output": "0 1 1 254 254\r\n"}, {"input": "10 3\r\n112 184 161 156 118 231 191 128 91 229\r\n", "output": "110 182 159 154 116 229 189 126 89 229\r\n"}, {"input": "9 3\r\n174 149 118 124 166 146 219 233 107\r\n", "output"...
false
stdio
null
true
175/C
175
C
PyPy 3-64
TESTS
2
92
0
215185493
n=int(input()) kc=[] for i in range(n): k,c=map(int,input().split()) kc.append([k,c]) kc=sorted(kc, key=lambda x: x[1]) t=int(input()) p=list(map(int,input().split())) multiplier=1 res=0 kill=0 for i in range(len(kc)): k,c=kc[i][0],kc[i][1] while k>0: if len(p)>0: if p[0]>k: ...
90
154
0
166999067
'''\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,后两只怪...
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
456/A
456
A
Python 3
TESTS
39
327
8,908,800
184897123
n = input() p = [] for i in range(0,int(n)): l = input() t = [int(i) for i in l.split() if i.isdigit()] p.append(t) #print(p) ans = 'Poor Alex' for i in range(0,len(p)-1): if (p[i][0] - p[i+1][0])*(p[i][1] - p[i+1][1]) < 0: ans = 'Happy Alex' break print(ans)
46
109
0
214041816
def solve(n): for _ in range(n): a, b = input().split() if a != b: return True return False n = int(input()) print(["Poor Alex", "Happy Alex"][solve(n)])
Codeforces Round 260 (Div. 2)
CF
2,014
1
256
Laptops
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai ar...
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
null
null
[{"input": "2\n1 2\n2 1", "output": "Happy Alex"}]
1,100
["sortings"]
46
[{"input": "2\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n2 2\r\n3 3\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n3 3\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "1\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"inp...
false
stdio
null
true
980/C
980
C
Python 3
TESTS
9
108
102,400
45426856
def read(): return [int(v) for v in input().split()] def main(): n, k = read() a = read() cache = {} for i in range(n): if a[i] not in cache: for v in range(1, k): value = a[i] - v if value in cache: if a[i] - cache[value] < ...
82
171
11,264,000
139631608
import sys,os,io import math from collections import defaultdict def ii(): return int(input()) def li(): return list(map(int,input().split())) if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w") else: input = io.BytesIO(os.read(0, os.fstat(0).st_siz...
Codeforces Round 480 (Div. 2)
CF
2,018
1
256
Posterized
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $$$i$$$-th integer represents the color of the $$$i$$$-th pixel in the image. The image is in black and white...
The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq k \leq 256$$$), the number of pixels in the image, and the maximum size of a group, respectively. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$0 \leq p_i \leq 255$$$), where $$$p_i$$$ is t...
Print $$$n$$$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter.
null
One possible way to group colors and assign keys for the first sample: Color $$$2$$$ belongs to the group $$$[0,2]$$$, with group key $$$0$$$. Color $$$14$$$ belongs to the group $$$[12,14]$$$, with group key $$$12$$$. Colors $$$3$$$ and $$$4$$$ belong to group $$$[3, 5]$$$, with group key $$$3$$$. Other groups won...
[{"input": "4 3\n2 14 3 4", "output": "0 12 3 3"}, {"input": "5 2\n0 2 1 255 254", "output": "0 1 1 254 254"}]
1,700
["games", "greedy"]
82
[{"input": "4 3\r\n2 14 3 4\r\n", "output": "0 12 3 3\r\n"}, {"input": "5 2\r\n0 2 1 255 254\r\n", "output": "0 1 1 254 254\r\n"}, {"input": "10 3\r\n112 184 161 156 118 231 191 128 91 229\r\n", "output": "110 182 159 154 116 229 189 126 89 229\r\n"}, {"input": "9 3\r\n174 149 118 124 166 146 219 233 107\r\n", "output"...
false
stdio
null
true
472/C
472
C
PyPy 3-64
TESTS
1
61
0
197305740
import sys toks = (tok for tok in sys.stdin.read().split()) N = int(next(toks)) names = [""] for i in range(N): names.append([next(toks), next(toks)]) success = True prev = min(names[i][0], names[i][1]) for i in range(1, N): i = int(next(toks)) if (names[i][0] < names[i][1]): curMin = names[i][0]...
65
467
34,508,800
8001203
n = int(input()) l = [input().split() for i in range(n)] p = [int(x)-1 for x in input().split()] cur = "" poss = True for i in range(n): per = l[p[i]] if per[0] > cur: if per[1] > cur: cur = min(per[0],per[1]) else: cur = per[0] else: if per[1] > cur: ...
Codeforces Round 270
CF
2,014
2
256
Design Tutorial: Make It Nondeterministic
A way to make a new task is to make it nondeterministic or probabilistic. For example, the hard task of Topcoder SRM 595, Constellation, is the probabilistic version of a convex hull. Let's try to make a new task. Firstly we will use the following task. There are n people, sort them by their name. It is just an ordina...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of people. The next n lines each contains two strings. The i-th line contains strings fi and si (1 ≤ |fi|, |si| ≤ 50) — the first name and last name of the i-th person. Each string consists only of lowercase English letters. All of the given 2n strings wi...
If it is possible, output "YES", otherwise output "NO".
null
In example 1 and 2, we have 3 people: tourist, Petr and me (cgy4ever). You can see that whatever handle is chosen, I must be the first, then tourist and Petr must be the last. In example 3, if Copernicus uses "copernicus" as his handle, everything will be alright.
[{"input": "3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n1 2 3", "output": "NO"}, {"input": "3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n3 1 2", "output": "YES"}, {"input": "2\ngalileo galilei\nnicolaus copernicus\n2 1", "output": "YES"}, {"input": "10\nrean schwarzer\nfei claussell\nalisa reinford\n...
1,400
["greedy"]
65
[{"input": "3\r\ngennady korotkevich\r\npetr mitrichev\r\ngaoyuan chen\r\n1 2 3\r\n", "output": "NO\r\n"}, {"input": "3\r\ngennady korotkevich\r\npetr mitrichev\r\ngaoyuan chen\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2\r\ngalileo galilei\r\nnicolaus copernicus\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "10\r\...
false
stdio
null
true
681/A
681
A
Python 3
TESTS
7
46
0
184666304
for _ in range(int(input())): l = input().split() b,a = int(l[1]), int(l[2]) if b<a and b>2400: print("YES") break else: print("NO")
60
46
0
144950039
n = int(input()) flag = False for _ in range(n): name, a, b = input().split() a = int(a) b = int(b) if a >= 2400 and b > a: flag = True if flag: print('YES') else: print('NO')
Codeforces Round 357 (Div. 2)
CF
2,016
1
256
A Good Contest
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest . The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — parti...
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
null
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before...
[{"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES"}, {"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO"}]
800
["implementation"]
60
[{"input": "3\r\nBurunduk1 2526 2537\r\nBudAlNik 2084 2214\r\nsubscriber 2833 2749\r\n", "output": "YES"}, {"input": "3\r\nApplejack 2400 2400\r\nFluttershy 2390 2431\r\nPinkie_Pie -2500 -2450\r\n", "output": "NO"}, {"input": "1\r\nDb -3373 3591\r\n", "output": "NO"}, {"input": "5\r\nQ2bz 960 2342\r\nhmX 2710 -1348\r\n...
false
stdio
null
true
68/B
68
B
Python 3
TESTS
4
124
0
17285280
# http://codeforces.com/problemset/problem/68/B # 1 <= n <= 10,000 # 0 <= k <= 99 n, k = [int(n) for n in input().split()] accums = [int(n) for n in input().split()] k = 100-k right = max(accums) left = min(accums) guess = 0 while (right-left > 0.00000001): #log base 2 of 10^6 -> 30 guess = (left+right)/2.0 ...
42
124
512,000
5272507
(n, k), t = map(int, input().split()), [0] + sorted(list(map(int, input().split()))) i, d, s = 1, t[1], sum(t) while i < n: i += 1 d += t[i] if 100 * (s - t[i] * n) < k * (s - d - t[i] * (n - i)): d -= t[i] i -= 1 break print(t[i] + (100 * (s - t[i] * n) - k * (s - d - t[i] * (n - i)...
Codeforces Beta Round 62
CF
2,011
2
256
Energy exchange
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be...
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers. Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy. The absolute or relative error in the answer should not exceed 10 - 6.
null
null
[{"input": "3 50\n4 2 1", "output": "2.000000000"}, {"input": "2 90\n1 11", "output": "1.909090909"}]
1,600
["binary search"]
42
[{"input": "3 50\r\n4 2 1\r\n", "output": "2.000000000\r\n"}, {"input": "2 90\r\n1 11\r\n", "output": "1.909090909\r\n"}, {"input": "5 26\r\n42 65 23 43 64\r\n", "output": "45.415178571\r\n"}, {"input": "5 45\r\n964 515 454 623 594\r\n", "output": "594.109756098\r\n"}, {"input": "1 20\r\n784\r\n", "output": "784.000000...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read reference output with open(output_path, 'r') as f: ref_line = f.readline().strip() try: E_ref = float(ref_line) except: print(0) ...
true
681/A
681
A
Python 3
TESTS
7
31
0
144077320
for i in range(int(input())): member = list(input().split()) if 2400 < int(member[1]) < int(member[2]): print("YES") exit() print("NO")
60
46
0
146060610
n = int(input()) for __ in range(n): name , bef ,aft = map(str,input().split()) flag = False if (int(bef)>=2400) and (int(aft) > int(bef)): print("YES") break else: flag = True if (flag): print("NO")
Codeforces Round 357 (Div. 2)
CF
2,016
1
256
A Good Contest
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest . The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — parti...
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
null
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before...
[{"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES"}, {"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO"}]
800
["implementation"]
60
[{"input": "3\r\nBurunduk1 2526 2537\r\nBudAlNik 2084 2214\r\nsubscriber 2833 2749\r\n", "output": "YES"}, {"input": "3\r\nApplejack 2400 2400\r\nFluttershy 2390 2431\r\nPinkie_Pie -2500 -2450\r\n", "output": "NO"}, {"input": "1\r\nDb -3373 3591\r\n", "output": "NO"}, {"input": "5\r\nQ2bz 960 2342\r\nhmX 2710 -1348\r\n...
false
stdio
null
true
91/A
91
A
Python 3
TESTS
50
1,028
15,155,200
127735573
s,z=input(),input() q,o,k={*s},len(s),{} l,x,a=[0]*o,0,1 for i in z: if i not in q:exit(print(-1)) for i in range(o-1,-1,-1): l[i]=dict(k) k[s[i]]=i s+="?" for i in range(len(z)): if z[i]!=s[i]:break for i in z[i-i!=0:]: if i in l[x]:x=l[x][i] else: a+=1 x=k[i] print(a)
51
280
9,113,600
208658171
# 子序列自动机 s1 = input() s2 = input() n = len(s1) nxt = [[-1]*26 for _ in range(n + 1)] for i in range(n - 1,-1,-1): for j in range(26): nxt[i][j] = nxt[i + 1][j] nxt[i][ord(s1[i]) - ord('a')] = i + 1 ans = 1 cur = 0 for ch in s2: if nxt[0][ord(ch) - ord('a')] == -1: print(-1) exit() ...
Codeforces Beta Round 75 (Div. 1 Only)
CF
2,011
2
256
Newspaper Headline
A newspaper is published in Walrusland. Its heading is s1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After that walrus erase several letters from this string in order to get a new...
The input data contain two lines. The first line contain the heading s1, the second line contains the word s2. The lines only consist of lowercase Latin letters (1 ≤ |s1| ≤ 104, 1 ≤ |s2| ≤ 106).
If it is impossible to get the word s2 in the above-described manner, print "-1" (without the quotes). Otherwise, print the least number of newspaper headings s1, which Fangy will need to receive the word s2.
null
null
[{"input": "abc\nxyz", "output": "-1"}, {"input": "abcd\ndabc", "output": "2"}]
1,500
["greedy", "strings"]
51
[{"input": "abc\r\nxyz\r\n", "output": "-1\r\n"}, {"input": "abcd\r\ndabc\r\n", "output": "2\r\n"}, {"input": "ab\r\nbabaaab\r\n", "output": "5\r\n"}, {"input": "ab\r\nbaaabba\r\n", "output": "6\r\n"}, {"input": "fbaaigiihhfaahgdbddgeggjdeigfadhfddja\r\nhbghjgijijcdafcbgiedichdeebaddfddb\r\n", "output": "-1\r\n"}, {"in...
false
stdio
null
true
456/A
456
A
Python 3
TESTS
39
249
0
194741965
n = int(input()) prev = list(map(int,input().split())) for i in range(n-1): curr = list(map(int,input().split())) if prev[0]<curr[0] and prev[1]>curr[1] or prev[0]>curr[0] and prev[1]<curr[1]: print("Happy Alex") break prev = curr.copy() else: print("Poor Alex")
46
124
0
174144157
n = int(input()) isTrue = True for _ in range(n): a, b = input().split() if a != b: print("Happy Alex") isTrue = False break if isTrue: print("Poor Alex")
Codeforces Round 260 (Div. 2)
CF
2,014
1
256
Laptops
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai ar...
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
null
null
[{"input": "2\n1 2\n2 1", "output": "Happy Alex"}]
1,100
["sortings"]
46
[{"input": "2\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n2 2\r\n3 3\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n3 3\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "1\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"inp...
false
stdio
null
true
681/A
681
A
Python 3
TESTS
7
46
0
148115102
t = int(input()) for i in range(t): a= list(map(str, input().split())) if int(a[1])> 2400 and int(a[1])< int(a[2]): print("Yes") break else: print("NO")
60
46
0
146227940
n = int(input()) res = 'NO' for i in range(n): r = [int(s) for s in input().split()[1:]] if r[0] >= 2400 and r[1] - r[0] > 0: res = 'YES' print(res)
Codeforces Round 357 (Div. 2)
CF
2,016
1
256
A Good Contest
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest . The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — parti...
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
null
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before...
[{"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES"}, {"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO"}]
800
["implementation"]
60
[{"input": "3\r\nBurunduk1 2526 2537\r\nBudAlNik 2084 2214\r\nsubscriber 2833 2749\r\n", "output": "YES"}, {"input": "3\r\nApplejack 2400 2400\r\nFluttershy 2390 2431\r\nPinkie_Pie -2500 -2450\r\n", "output": "NO"}, {"input": "1\r\nDb -3373 3591\r\n", "output": "NO"}, {"input": "5\r\nQ2bz 960 2342\r\nhmX 2710 -1348\r\n...
false
stdio
null
true
681/A
681
A
PyPy 3-64
TESTS
7
46
0
169055028
ans = 'NO' for i in range(int(input())): name,sb,sa = input().split() sb = int(sb) sa = int(sa) if 2400 < sb < sa : ans = 'YES' print(ans)
60
46
0
146241155
t = int(input()) d = 0 for i in range(t): c, a, b = input().split() if int(a)>=2400 and int(b)>int(a): d = d+1 if d>=1: print("YES") else: print("NO")
Codeforces Round 357 (Div. 2)
CF
2,016
1
256
A Good Contest
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest . The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — parti...
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
null
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before...
[{"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES"}, {"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO"}]
800
["implementation"]
60
[{"input": "3\r\nBurunduk1 2526 2537\r\nBudAlNik 2084 2214\r\nsubscriber 2833 2749\r\n", "output": "YES"}, {"input": "3\r\nApplejack 2400 2400\r\nFluttershy 2390 2431\r\nPinkie_Pie -2500 -2450\r\n", "output": "NO"}, {"input": "1\r\nDb -3373 3591\r\n", "output": "NO"}, {"input": "5\r\nQ2bz 960 2342\r\nhmX 2710 -1348\r\n...
false
stdio
null
true
91/A
91
A
Python 3
TESTS
50
966
15,155,200
127721384
s,z=input(),input() q,o,a,k={*s},len(s),1,{} l,x=[0]*o,0 for i in z: if i not in q:exit(print(-1)) for i in range(o-1,-1,-1): l[i]=dict(k) k[s[i]]=i for i in z: if i in l[x]:x=l[x][i] else: a+=1 x=k[i] print(a)
51
436
8,192,000
208645646
import sys from collections import Counter import functools import math import random import sys import os from bisect import bisect_left,bisect_right from collections import Counter, defaultdict, deque from functools import lru_cache, reduce from heapq import nsmallest, nlargest, heapify, heappop, heappush from io im...
Codeforces Beta Round 75 (Div. 1 Only)
CF
2,011
2
256
Newspaper Headline
A newspaper is published in Walrusland. Its heading is s1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After that walrus erase several letters from this string in order to get a new...
The input data contain two lines. The first line contain the heading s1, the second line contains the word s2. The lines only consist of lowercase Latin letters (1 ≤ |s1| ≤ 104, 1 ≤ |s2| ≤ 106).
If it is impossible to get the word s2 in the above-described manner, print "-1" (without the quotes). Otherwise, print the least number of newspaper headings s1, which Fangy will need to receive the word s2.
null
null
[{"input": "abc\nxyz", "output": "-1"}, {"input": "abcd\ndabc", "output": "2"}]
1,500
["greedy", "strings"]
51
[{"input": "abc\r\nxyz\r\n", "output": "-1\r\n"}, {"input": "abcd\r\ndabc\r\n", "output": "2\r\n"}, {"input": "ab\r\nbabaaab\r\n", "output": "5\r\n"}, {"input": "ab\r\nbaaabba\r\n", "output": "6\r\n"}, {"input": "fbaaigiihhfaahgdbddgeggjdeigfadhfddja\r\nhbghjgijijcdafcbgiedichdeebaddfddb\r\n", "output": "-1\r\n"}, {"in...
false
stdio
null
true
681/A
681
A
Python 3
TESTS
7
46
4,505,600
157730195
n = int(input()) for i in range (n): s = input().split() name, scorebefore, scoreafter = s[0], int(s[1]), int(s[2]) if scorebefore > 2400 and scoreafter > scorebefore: print("YES") break else: print("NO")
60
46
0
146297852
n = int(input()) se_pudo = False for i in range(n): lista = input().split() a = int(lista[1]) d = int(lista[2]) if a >= 2400 and d > a: se_pudo = True break print(["NO", "YES"][se_pudo])
Codeforces Round 357 (Div. 2)
CF
2,016
1
256
A Good Contest
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest . The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — parti...
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
null
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before...
[{"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES"}, {"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO"}]
800
["implementation"]
60
[{"input": "3\r\nBurunduk1 2526 2537\r\nBudAlNik 2084 2214\r\nsubscriber 2833 2749\r\n", "output": "YES"}, {"input": "3\r\nApplejack 2400 2400\r\nFluttershy 2390 2431\r\nPinkie_Pie -2500 -2450\r\n", "output": "NO"}, {"input": "1\r\nDb -3373 3591\r\n", "output": "NO"}, {"input": "5\r\nQ2bz 960 2342\r\nhmX 2710 -1348\r\n...
false
stdio
null
true
416/B
416
B
PyPy 3-64
TESTS
5
171
19,763,200
187586439
import math import itertools import copy import sys input = lambda: sys.stdin.readline().rstrip("\r\n") def intmap(): return map(int,input().split()) def lintmap(): return list(map(int,input().split())) def lstrmap(): return list(map(str,input().split())) def freq(l): d = {} for i i...
26
296
11,571,200
208223129
import sys, string input = sys.stdin.readline m,n = map(int, input().split()) times = [list(map(int, input().split())) for i in range(m)] prev, curr = [0]*m, [0]*m for j in range(n): curr[0] = max(0, prev[0]) + times[0][j] for i in range(1, m): curr[i] = max(curr[i-1], prev[i]) + times[i][j] prev ...
Codeforces Round 241 (Div. 2)
CF
2,014
1
256
Art Union
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters who decided to organize their work as follows. Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1...
The first line of the input contains integers m, n (1 ≤ m ≤ 50000, 1 ≤ n ≤ 5), where m is the number of pictures and n is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains n integers ti1, ti2, ..., tin (1 ≤ tij ≤ 1000), where tij is the time the j-th painter needs to...
Print the sequence of m integers r1, r2, ..., rm, where ri is the moment when the n-th painter stopped working on the i-th picture.
null
null
[{"input": "5 1\n1\n2\n3\n4\n5", "output": "1 3 6 10 15"}, {"input": "4 2\n2 5\n3 1\n5 3\n10 1", "output": "7 8 13 21"}]
1,300
["brute force", "dp", "implementation"]
26
[{"input": "5 1\r\n1\r\n2\r\n3\r\n4\r\n5\r\n", "output": "1 3 6 10 15 "}, {"input": "4 2\r\n2 5\r\n3 1\r\n5 3\r\n10 1\r\n", "output": "7 8 13 21 "}, {"input": "1 1\r\n66\r\n", "output": "66 "}, {"input": "2 2\r\n1 1\r\n1 1\r\n", "output": "2 3 "}, {"input": "2 2\r\n10 1\r\n10 1\r\n", "output": "11 21 "}, {"input": "1 5...
false
stdio
null
true
416/B
416
B
Python 3
TESTS
5
607
18,944,000
36519815
A=[int(x) for x in input().split()] m=A[0] n=A[1] T=[] for x in range(0,m): T.append([int(x) for x in input().split()]) sumT=[] for i in range(0,m): sum=0 if n!=1: for j in range(0,n-1): sum+=T[i][j] sumT.append(sum) else: sumT.append(0) sumR=[] sum=0 for i in range(0,m): sum+=sumT[...
26
311
11,571,200
224233652
import sys, string input = sys.stdin.readline m,n = map(int, input().split()) times = [list(map(int, input().split())) for i in range(m)] prev, curr = [0]*m, [0]*m for j in range(n): curr[0] = max(0, prev[0]) + times[0][j] for i in range(1, m): curr[i] = max(curr[i-1], prev[i]) + times[i][j] prev ...
Codeforces Round 241 (Div. 2)
CF
2,014
1
256
Art Union
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters who decided to organize their work as follows. Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1...
The first line of the input contains integers m, n (1 ≤ m ≤ 50000, 1 ≤ n ≤ 5), where m is the number of pictures and n is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains n integers ti1, ti2, ..., tin (1 ≤ tij ≤ 1000), where tij is the time the j-th painter needs to...
Print the sequence of m integers r1, r2, ..., rm, where ri is the moment when the n-th painter stopped working on the i-th picture.
null
null
[{"input": "5 1\n1\n2\n3\n4\n5", "output": "1 3 6 10 15"}, {"input": "4 2\n2 5\n3 1\n5 3\n10 1", "output": "7 8 13 21"}]
1,300
["brute force", "dp", "implementation"]
26
[{"input": "5 1\r\n1\r\n2\r\n3\r\n4\r\n5\r\n", "output": "1 3 6 10 15 "}, {"input": "4 2\r\n2 5\r\n3 1\r\n5 3\r\n10 1\r\n", "output": "7 8 13 21 "}, {"input": "1 1\r\n66\r\n", "output": "66 "}, {"input": "2 2\r\n1 1\r\n1 1\r\n", "output": "2 3 "}, {"input": "2 2\r\n10 1\r\n10 1\r\n", "output": "11 21 "}, {"input": "1 5...
false
stdio
null
true
730/G
730
G
Python 3
TESTS
6
31
0
151414789
k=[0] import bisect z=set() r=1 for i in range(int(input())): a,b=map(int,input().split()) o=a+b-1 q=bisect.bisect_left(k,a) w=bisect.bisect_right(k,o) if q==w and (q,w) not in z: print(a,o) k.insert(q,a) k.insert(q+1,o) z.add((a,o)) else: for i in range(1...
28
124
307,200
75316635
def dotwointervals(l1,r1,l2,r2): if(l1<l2 and r1<l2): return 0 elif(l1>r2 and r1>r2): return 0 return 1 n=int(input()) lofdays=[] for you in range(n): l=input().split() si=int(l[0]) di=int(l[1]) if(you==0): lofdays.append((si,si+di-1)) print(si,si+di-1) e...
2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,016
2
512
Car Repair Shop
Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time. Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order...
The first line contains integer n (1 ≤ n ≤ 200) — the number of requests from clients. The following n lines contain requests, one request per line. The i-th request is given as the pair of integers si, di (1 ≤ si ≤ 109, 1 ≤ di ≤ 5·106), where si is the preferred time to start repairing the i-th car, di is the number ...
Print n lines. The i-th line should contain two integers — the start day to repair the i-th car and the finish day to repair the i-th car.
null
null
[{"input": "3\n9 2\n7 3\n2 4", "output": "9 10\n1 3\n4 7"}, {"input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000", "output": "1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000"}]
1,600
["implementation"]
28
[{"input": "3\r\n9 2\r\n7 3\r\n2 4\r\n", "output": "9 10\r\n1 3\r\n4 7\r\n"}, {"input": "4\r\n1000000000 1000000\r\n1000000000 1000000\r\n100000000 1000000\r\n1000000000 1000000\r\n", "output": "1000000000 1000999999\r\n1 1000000\r\n100000000 100999999\r\n1000001 2000000\r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 1\...
false
stdio
null
true