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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
529/B | 529 | B | PyPy 3-64 | TESTS | 0 | 46 | 0 | 203130215 | n = int(input())
friends = []
area_sum = 0
for i in range(n):
w, h = map(int, input().split())
friends.append((w, h))
area_sum += w * h
friends.sort(key=lambda x: x[1])
if area_sum < (n//2) * friends[-1][1]:
print(area_sum)
else:
left, right = 1, 10**12
while left < right:
mid = (left ... | 58 | 842 | 6,348,800 | 10391728 | from operator import neg
n = int(input())
a = [tuple(map(int, input().split())) for i in range(n)]
def check(max_h):
k = n // 2
b = []
for w, h in a:
if h > max_h:
if k <= 0 or w > max_h:
return 1 << 60
b.append((h, w))
k -= 1
else:
... | VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only) | CF | 2,015 | 2 | 256 | Group Photo 2 (online mirror version) | Many years have passed, and n friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the photo.
Simply speaking, the process of photographing can be describ... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of friends.
The next n lines have two integers wi, hi (1 ≤ wi, hi ≤ 1000) each, representing the size of the rectangle, corresponding to the i-th friend. | Print a single integer equal to the minimum possible area of the photo containing all friends if no more than n / 2 of them can lie on the ground. | null | null | [{"input": "3\n10 1\n20 2\n30 3", "output": "180"}, {"input": "3\n3 1\n2 2\n4 3", "output": "21"}, {"input": "1\n5 10", "output": "50"}] | 1,900 | ["brute force", "greedy", "sortings"] | 58 | [{"input": "3\r\n10 1\r\n20 2\r\n30 3\r\n", "output": "180\r\n"}, {"input": "3\r\n3 1\r\n2 2\r\n4 3\r\n", "output": "21\r\n"}, {"input": "1\r\n5 10\r\n", "output": "50\r\n"}, {"input": "1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1\r\n1000 1000\r\n", "output": "1000000\r\n"}, {"input": "1\r\n1 1000\r\n", "output": "1... | false | stdio | null | true |
311/B | 311 | B | Python 3 | TESTS | 1 | 46 | 204,800 | 22298692 | n,m,p = [int(i) for i in input().split(' ')]
d = [0]+[int(i) for i in input().split(' ')]#del
dp = [[0]*(m+1) for _ in range(p+1)]
oo=10*10
pos = [0]*(n+1)
a=[0]*(m+1)
s=[0]*(m+1)
st=[0]*10000
def g(i,k):
return dp[i-1][k]+s[k]
def main():
global a, s, st, dp
for i in range(1,n+1):
pos[i] = sum(d[1... | 30 | 1,216 | 27,340,800 | 211419212 | def solve(A, B, C):
N = len(B) + 1
M = len(C)
a = [0] * N
for i in range(1, N):
a[i] += a[i - 1] + B[i - 1]
b = [0] * M
s = [0] * M
dp = [0] * M
k = [0] * M
for i in range(M):
b[i] = C[i][1] - a[C[i][0] - 1]
b.sort()
for i in range(M -... | Codeforces Round 185 (Div. 1) | CF | 2,013 | 2 | 256 | Cats Transport | Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straight road across the farm and n hills along the road, numbered from 1 to n from left to right. The distance between hill i and (i - 1) is di meters. The feeders live in hill 1.
One day, the cats went out to play. Cat i went o... | The first line of the input contains three integers n, m, p (2 ≤ n ≤ 105, 1 ≤ m ≤ 105, 1 ≤ p ≤ 100).
The second line contains n - 1 positive integers d2, d3, ..., dn (1 ≤ di < 104).
Each of the next m lines contains two integers hi and ti (1 ≤ hi ≤ n, 0 ≤ ti ≤ 109). | Output an integer, the minimum sum of waiting time of all cats.
Please, do not write 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 | null | [{"input": "4 6 2\n1 3 5\n1 0\n2 1\n4 9\n1 10\n2 10\n3 12", "output": "3"}] | 2,400 | ["data structures", "dp"] | 30 | [{"input": "4 6 2\r\n1 3 5\r\n1 0\r\n2 1\r\n4 9\r\n1 10\r\n2 10\r\n3 12\r\n", "output": "3\r\n"}] | false | stdio | null | true |
13/B | 13 | B | Python 3 | TESTS | 1 | 434 | 716,800 | 69700947 | """ A : Determine if three line segments form A """
def distance(a, b, c, d):
return (d - b) ** 2 + (c - a) ** 2
def cross(vecA, vecB):
return vecA[0] * vecB[1] - vecA[1] * vecB[0]
def dot(vecA, vecB):
return vecA[0] * vecB[0] + vecA[1] * vecB[1]
def slope(x1, y1, x2, y2):
if x1 != x2: return (y... | 2 | 530 | 0 | 178586732 | import random
from math import sqrt as s
def dist(x1, y1, x2, y2):
return s((x2 - x1) ** 2 + (y2 - y1) ** 2)
def is_dot_on_line(c1, c2, dot):
A = c1[1] - c2[1]
B = c2[0] - c1[0]
C = c1[0] * c2[1] - c2[0] * c1[1]
maxx, minx = max(c1[0], c2[0]), min(c1[0], c2[0])
maxy, miny = max(c1[1], ... | Codeforces Beta Round 13 | ICPC | 2,010 | 1 | 64 | Letter A | Little Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.
You are given three segments on the plane. They form the letter A if the following conditions hold:
- Two segments have common endpoint... | The first line contains one integer t (1 ≤ t ≤ 10000) — the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers — coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments have pos... | Output one line for each test case. Print «YES» (without quotes), if the segments form the letter A and «NO» otherwise. | null | null | [{"input": "3\n4 4 6 0\n4 1 5 2\n4 0 4 4\n0 0 0 6\n0 6 2 -4\n1 1 0 1\n0 0 0 5\n0 5 2 -1\n1 2 0 1", "output": "YES\nNO\nYES"}] | 2,000 | ["geometry", "implementation"] | 2 | [{"input": "3\r\n4 4 6 0\r\n4 1 5 2\r\n4 0 4 4\r\n0 0 0 6\r\n0 6 2 -4\r\n1 1 0 1\r\n0 0 0 5\r\n0 5 2 -1\r\n1 2 0 1\r\n", "output": "YES\r\nNO\r\nYES\r\n"}] | false | stdio | null | true |
1298/E | 978 | F | Python 3 | TESTS | 0 | 31 | 0 | 190728825 | def inputs():
return map(int, input().split())
n,q = inputs()
p = list(inputs())
ans = [0 for _ in range(n)]
class fen:
def __init__(self):
self.BIT = [0 for _ in range(n + 1)]
def upd(self, idx, val):
while idx<=n:
self.BIT[idx] += val
idx += (idx&-idx)
... | 41 | 872 | 56,934,400 | 201985672 | import sys
input = lambda: sys.stdin.readline().rstrip()
from bisect import *
N,K = map(int, input().split())
R = list(map(int, input().split()))
A = sorted(R)
P = [[] for _ in range(N)]
for _ in range(K):
u,v = map(int, input().split())
u-=1;v-=1
P[u].append(R[v])
P[v].append(R[u])
ans = []
for... | Kotlin Heroes: Practice 3 | ICPC | 2,020 | 3 | 256 | Mentors | In BerSoft $$$n$$$ programmers work, the programmer $$$i$$$ is characterized by a skill $$$r_i$$$.
A programmer $$$a$$$ can be a mentor of a programmer $$$b$$$ if and only if the skill of the programmer $$$a$$$ is strictly greater than the skill of the programmer $$$b$$$ $$$(r_a > r_b)$$$ and programmers $$$a$$$ and $... | The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le \min(2 \cdot 10^5, \frac{n \cdot (n - 1)}{2}))$$$ — total number of programmers and number of pairs of programmers which are in a quarrel.
The second line contains a sequence of integers $$$r_1, r_2, \dots, r_n$$$ ... | Print $$$n$$$ integers, the $$$i$$$-th number should be equal to the number of programmers, for which the $$$i$$$-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input. | null | In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can b... | [{"input": "4 2\n10 4 10 15\n1 2\n4 3", "output": "0 0 1 2"}, {"input": "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5", "output": "5 4 0 5 3 3 9 0 2 5"}] | null | ["*special", "data structures", "implementation"] | 41 | [{"input": "4 2\r\n10 4 10 15\r\n1 2\r\n4 3\r\n", "output": "0 0 1 2 \r\n"}, {"input": "10 4\r\n5 4 1 5 4 3 7 1 2 5\r\n4 6\r\n2 1\r\n10 8\r\n3 5\r\n", "output": "5 4 0 5 3 3 9 0 2 5 \r\n"}, {"input": "2 0\r\n3 1\r\n", "output": "1 0 \r\n"}, {"input": "2 0\r\n1 1\r\n", "output": "0 0 \r\n"}, {"input": "10 35\r\n32202222... | false | stdio | null | true |
1298/E | 978 | F | Python 3 | TESTS | 0 | 30 | 0 | 195402570 | n, m = map(int, input().split())
ability = list(map(int, input().split()))
# создаем пустой массив с количеством менторов, равным количеству учеников
num_mentors = [0] * n
# пройдемся по каждому запросу и обновим значения массива num_mentors
for i in range(m):
x, y = map(int, input().split())
num_mentors[x - ... | 41 | 1,013 | 40,652,800 | 172377597 | import sys
from math import sqrt, gcd, factorial, ceil, floor, pi, inf
from collections import deque, Counter, OrderedDict
from heapq import heapify, heappush, heappop
#sys.setrecursionlimit(10**6)
#from functools import lru_cache
#@lru_cache(None)
#======================================================#
input = lambd... | Kotlin Heroes: Practice 3 | ICPC | 2,020 | 3 | 256 | Mentors | In BerSoft $$$n$$$ programmers work, the programmer $$$i$$$ is characterized by a skill $$$r_i$$$.
A programmer $$$a$$$ can be a mentor of a programmer $$$b$$$ if and only if the skill of the programmer $$$a$$$ is strictly greater than the skill of the programmer $$$b$$$ $$$(r_a > r_b)$$$ and programmers $$$a$$$ and $... | The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le \min(2 \cdot 10^5, \frac{n \cdot (n - 1)}{2}))$$$ — total number of programmers and number of pairs of programmers which are in a quarrel.
The second line contains a sequence of integers $$$r_1, r_2, \dots, r_n$$$ ... | Print $$$n$$$ integers, the $$$i$$$-th number should be equal to the number of programmers, for which the $$$i$$$-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input. | null | In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can b... | [{"input": "4 2\n10 4 10 15\n1 2\n4 3", "output": "0 0 1 2"}, {"input": "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5", "output": "5 4 0 5 3 3 9 0 2 5"}] | null | ["*special", "data structures", "implementation"] | 41 | [{"input": "4 2\r\n10 4 10 15\r\n1 2\r\n4 3\r\n", "output": "0 0 1 2 \r\n"}, {"input": "10 4\r\n5 4 1 5 4 3 7 1 2 5\r\n4 6\r\n2 1\r\n10 8\r\n3 5\r\n", "output": "5 4 0 5 3 3 9 0 2 5 \r\n"}, {"input": "2 0\r\n3 1\r\n", "output": "1 0 \r\n"}, {"input": "2 0\r\n1 1\r\n", "output": "0 0 \r\n"}, {"input": "10 35\r\n32202222... | false | stdio | null | true |
311/B | 311 | B | Python 3 | TESTS | 1 | 46 | 102,400 | 224545646 | n, m, p = map(int, input().split())
arr = [0, 0] + list(map(int, input().split()))
for i in range(2, n+1):
arr[i] += arr[i-1]
ts = []
for i in range(m):
h, t = map(int, input().split())
ts.append(t-arr[h])
ts.sort()
tm = [0]*(m+1)
for i in range(1, m+1):
tm[i] = tm[i-1]+ts[i-1]
dp = [float("inf")]*(m+1)... | 30 | 1,216 | 27,340,800 | 211419212 | def solve(A, B, C):
N = len(B) + 1
M = len(C)
a = [0] * N
for i in range(1, N):
a[i] += a[i - 1] + B[i - 1]
b = [0] * M
s = [0] * M
dp = [0] * M
k = [0] * M
for i in range(M):
b[i] = C[i][1] - a[C[i][0] - 1]
b.sort()
for i in range(M -... | Codeforces Round 185 (Div. 1) | CF | 2,013 | 2 | 256 | Cats Transport | Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straight road across the farm and n hills along the road, numbered from 1 to n from left to right. The distance between hill i and (i - 1) is di meters. The feeders live in hill 1.
One day, the cats went out to play. Cat i went o... | The first line of the input contains three integers n, m, p (2 ≤ n ≤ 105, 1 ≤ m ≤ 105, 1 ≤ p ≤ 100).
The second line contains n - 1 positive integers d2, d3, ..., dn (1 ≤ di < 104).
Each of the next m lines contains two integers hi and ti (1 ≤ hi ≤ n, 0 ≤ ti ≤ 109). | Output an integer, the minimum sum of waiting time of all cats.
Please, do not write 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 | null | [{"input": "4 6 2\n1 3 5\n1 0\n2 1\n4 9\n1 10\n2 10\n3 12", "output": "3"}] | 2,400 | ["data structures", "dp"] | 30 | [{"input": "4 6 2\r\n1 3 5\r\n1 0\r\n2 1\r\n4 9\r\n1 10\r\n2 10\r\n3 12\r\n", "output": "3\r\n"}] | false | stdio | null | true |
311/B | 311 | B | Python 3 | TESTS | 1 | 61 | 204,800 | 22308495 | n,m,p = [int(i) for i in input().split(' ')]
d = [0]+[int(i) for i in input().split(' ')]#del
dp = [0]*(m+1)
pos = [0]*(n+1)
a = [0]*(m+1)
s = [0]*(m+1)
M,B=[],[]
def bad(l1,l2,l3):
return (B[l3]-B[l1])*(M[l1]-M[l2])<=(B[l2]-B[l1])*(M[l1]-M[l3])
def addline(m,b):
M.append(m)
B.append(b)
while len(M)>=3... | 30 | 1,216 | 27,340,800 | 211419212 | def solve(A, B, C):
N = len(B) + 1
M = len(C)
a = [0] * N
for i in range(1, N):
a[i] += a[i - 1] + B[i - 1]
b = [0] * M
s = [0] * M
dp = [0] * M
k = [0] * M
for i in range(M):
b[i] = C[i][1] - a[C[i][0] - 1]
b.sort()
for i in range(M -... | Codeforces Round 185 (Div. 1) | CF | 2,013 | 2 | 256 | Cats Transport | Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straight road across the farm and n hills along the road, numbered from 1 to n from left to right. The distance between hill i and (i - 1) is di meters. The feeders live in hill 1.
One day, the cats went out to play. Cat i went o... | The first line of the input contains three integers n, m, p (2 ≤ n ≤ 105, 1 ≤ m ≤ 105, 1 ≤ p ≤ 100).
The second line contains n - 1 positive integers d2, d3, ..., dn (1 ≤ di < 104).
Each of the next m lines contains two integers hi and ti (1 ≤ hi ≤ n, 0 ≤ ti ≤ 109). | Output an integer, the minimum sum of waiting time of all cats.
Please, do not write 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 | null | [{"input": "4 6 2\n1 3 5\n1 0\n2 1\n4 9\n1 10\n2 10\n3 12", "output": "3"}] | 2,400 | ["data structures", "dp"] | 30 | [{"input": "4 6 2\r\n1 3 5\r\n1 0\r\n2 1\r\n4 9\r\n1 10\r\n2 10\r\n3 12\r\n", "output": "3\r\n"}] | false | stdio | null | true |
13/B | 13 | B | PyPy 3 | TESTS | 1 | 842 | 9,523,200 | 109222376 | import sys
from collections import defaultdict
from math import hypot
# import logging
# logging.root.setLevel(level=logging.INFO)
def gcd(bigger, smaller):
if smaller == 0:
return bigger
return gcd(smaller,bigger%smaller)
cases = int(sys.stdin.readline().strip())
coordinates = list(sys.stdin.read()... | 2 | 560 | 0 | 179032385 | import math
r = lambda: map(int,input().split())
def cross(a, b):
return a[0] * b[1] - a[1] * b[0]
def dot(a, b):
return a[0] * b[0] + a[1] * b[1]
def on_line(a, b):
return dot(a, b) > 0 and cross(a, b) == 0 and abs(b[0]) <= abs(5 * a[0]) <= abs(4 * b[0]) and abs(b[1]) <= abs(5 * a[1]) <= abs(4 * b[1])
def is_A(a... | Codeforces Beta Round 13 | ICPC | 2,010 | 1 | 64 | Letter A | Little Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.
You are given three segments on the plane. They form the letter A if the following conditions hold:
- Two segments have common endpoint... | The first line contains one integer t (1 ≤ t ≤ 10000) — the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers — coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments have pos... | Output one line for each test case. Print «YES» (without quotes), if the segments form the letter A and «NO» otherwise. | null | null | [{"input": "3\n4 4 6 0\n4 1 5 2\n4 0 4 4\n0 0 0 6\n0 6 2 -4\n1 1 0 1\n0 0 0 5\n0 5 2 -1\n1 2 0 1", "output": "YES\nNO\nYES"}] | 2,000 | ["geometry", "implementation"] | 2 | [{"input": "3\r\n4 4 6 0\r\n4 1 5 2\r\n4 0 4 4\r\n0 0 0 6\r\n0 6 2 -4\r\n1 1 0 1\r\n0 0 0 5\r\n0 5 2 -1\r\n1 2 0 1\r\n", "output": "YES\r\nNO\r\nYES\r\n"}] | false | stdio | null | true |
13/B | 13 | B | Python 3 | TESTS | 1 | 686 | 6,963,200 | 85126177 | n=int(input())
dct={}
def check():
for i in dct[1]:
for j in dct[2]:
if(i==j):
return [1,2]
for i in dct[1]:
for j in dct[3]:
if(i==j):
return [1,3]
for i in dct[2]:
for j in dct[3]:
if (i == j):
ret... | 2 | 716 | 307,200 | 78333419 | #13B - Letter A
import math
r = lambda: map(int,input().split())
#Function to check if the lines cross
def cross(a, b):
return a[0] * b[1] - a[1] * b[0]
def dot(a, b):
return a[0] * b[0] + a[1] * b[1]
# def l(v):
# return math.hypot(*v)
def on_line(a, b):
return dot(a, b) > 0 and cross(a, b) == 0 and... | Codeforces Beta Round 13 | ICPC | 2,010 | 1 | 64 | Letter A | Little Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.
You are given three segments on the plane. They form the letter A if the following conditions hold:
- Two segments have common endpoint... | The first line contains one integer t (1 ≤ t ≤ 10000) — the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers — coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments have pos... | Output one line for each test case. Print «YES» (without quotes), if the segments form the letter A and «NO» otherwise. | null | null | [{"input": "3\n4 4 6 0\n4 1 5 2\n4 0 4 4\n0 0 0 6\n0 6 2 -4\n1 1 0 1\n0 0 0 5\n0 5 2 -1\n1 2 0 1", "output": "YES\nNO\nYES"}] | 2,000 | ["geometry", "implementation"] | 2 | [{"input": "3\r\n4 4 6 0\r\n4 1 5 2\r\n4 0 4 4\r\n0 0 0 6\r\n0 6 2 -4\r\n1 1 0 1\r\n0 0 0 5\r\n0 5 2 -1\r\n1 2 0 1\r\n", "output": "YES\r\nNO\r\nYES\r\n"}] | false | stdio | null | true |
958/C1 | 958 | C1 | Python 3 | TESTS | 8 | 77 | 1,740,800 | 120957273 | # Problem: C1. Encryption (easy)
# Contest: Codeforces - Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
# URL: https://codeforces.com/contest/958/problem/C1
# Memory Limit: 256 MB
# Time Limit: 1000 ms
# Powered by CP Editor (https://github.com/cpeditor/cpeditor)
from sys import stdin
def get_ints... | 27 | 77 | 11,468,800 | 198899912 | n, p = map(int, input().split())
a = [int(x) for x in input().split()]
s = sum(a)
ans = -1; psum = 0
for i in a:
psum += i
ans = max(ans, psum % p + (s - psum) % p)
print(ans) | Helvetic Coding Contest 2018 online mirror (teams allowed, unrated) | ICPC | 2,018 | 1 | 256 | Encryption (easy) | Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, but it is not stupid!). The encryption has several levels of security, and here is how the first one lo... | The first line of the input contains two space-separated integer N and p (2 ≤ N ≤ 100 000, 2 ≤ p ≤ 10 000) – the number of elements in A, and the modulo for computing scores, respectively.
The second line contains N space-separated integers which are the elements of A. Each integer is from the interval [1, 1 000 000]. | Output the number S as described in the problem statement. | null | In the first example, the score is maximized if the input sequence is split into two parts as (3, 4), (7, 2). It gives the total score of $$(3+4\mod10)+(7+2\mod10)=16$$.
In the second example, the score is maximized if the first part consists of the first three elements, and the second part consists of the rest. Then,... | [{"input": "4 10\n3 4 7 2", "output": "16"}, {"input": "10 12\n16 3 24 13 9 8 7 5 12 12", "output": "13"}] | 1,200 | ["brute force"] | 27 | [{"input": "4 10\r\n3 4 7 2\r\n", "output": "16\r\n"}, {"input": "10 12\r\n16 3 24 13 9 8 7 5 12 12\r\n", "output": "13\r\n"}, {"input": "2 2\r\n9 9\r\n", "output": "2\r\n"}, {"input": "2 2\r\n8 8\r\n", "output": "0\r\n"}, {"input": "5 50\r\n1 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "5 50\r\n100 150 200 100 50\r\n"... | false | stdio | null | true |
311/B | 311 | B | Python 3 | TESTS | 1 | 78 | 409,600 | 104983919 | import sys
import math
from collections import deque
class line:
def __init__ (self , a , b):
self.a = a
self.b = b
def inter (self , other):
return math.ceil((self.b - other.b) / (other.a - self.a))
def getval(self , x):
return self.a * x + self.b
class pair:
def __init_... | 30 | 1,216 | 27,340,800 | 211419212 | def solve(A, B, C):
N = len(B) + 1
M = len(C)
a = [0] * N
for i in range(1, N):
a[i] += a[i - 1] + B[i - 1]
b = [0] * M
s = [0] * M
dp = [0] * M
k = [0] * M
for i in range(M):
b[i] = C[i][1] - a[C[i][0] - 1]
b.sort()
for i in range(M -... | Codeforces Round 185 (Div. 1) | CF | 2,013 | 2 | 256 | Cats Transport | Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straight road across the farm and n hills along the road, numbered from 1 to n from left to right. The distance between hill i and (i - 1) is di meters. The feeders live in hill 1.
One day, the cats went out to play. Cat i went o... | The first line of the input contains three integers n, m, p (2 ≤ n ≤ 105, 1 ≤ m ≤ 105, 1 ≤ p ≤ 100).
The second line contains n - 1 positive integers d2, d3, ..., dn (1 ≤ di < 104).
Each of the next m lines contains two integers hi and ti (1 ≤ hi ≤ n, 0 ≤ ti ≤ 109). | Output an integer, the minimum sum of waiting time of all cats.
Please, do not write 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 | null | [{"input": "4 6 2\n1 3 5\n1 0\n2 1\n4 9\n1 10\n2 10\n3 12", "output": "3"}] | 2,400 | ["data structures", "dp"] | 30 | [{"input": "4 6 2\r\n1 3 5\r\n1 0\r\n2 1\r\n4 9\r\n1 10\r\n2 10\r\n3 12\r\n", "output": "3\r\n"}] | false | stdio | null | true |
311/B | 311 | B | Python 3 | TESTS | 1 | 92 | 0 | 39120539 | n, m, p = map(int, input().split())
d = [0, 0]
sum = 0
for x in input().split() :
d.append(int(x) + d[-1])
v = [-10000000000]
for i in range (m) :
h, t = map(int, input().split())
v.append(t - d[h])
v = sorted(v)
pre = [0]
for i in range (1, m + 1) :
pre.append(pre[-1] + (v[i] - v[i - 1]) * (i - 1))
dp ... | 30 | 1,216 | 27,340,800 | 211419212 | def solve(A, B, C):
N = len(B) + 1
M = len(C)
a = [0] * N
for i in range(1, N):
a[i] += a[i - 1] + B[i - 1]
b = [0] * M
s = [0] * M
dp = [0] * M
k = [0] * M
for i in range(M):
b[i] = C[i][1] - a[C[i][0] - 1]
b.sort()
for i in range(M -... | Codeforces Round 185 (Div. 1) | CF | 2,013 | 2 | 256 | Cats Transport | Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straight road across the farm and n hills along the road, numbered from 1 to n from left to right. The distance between hill i and (i - 1) is di meters. The feeders live in hill 1.
One day, the cats went out to play. Cat i went o... | The first line of the input contains three integers n, m, p (2 ≤ n ≤ 105, 1 ≤ m ≤ 105, 1 ≤ p ≤ 100).
The second line contains n - 1 positive integers d2, d3, ..., dn (1 ≤ di < 104).
Each of the next m lines contains two integers hi and ti (1 ≤ hi ≤ n, 0 ≤ ti ≤ 109). | Output an integer, the minimum sum of waiting time of all cats.
Please, do not write 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 | null | [{"input": "4 6 2\n1 3 5\n1 0\n2 1\n4 9\n1 10\n2 10\n3 12", "output": "3"}] | 2,400 | ["data structures", "dp"] | 30 | [{"input": "4 6 2\r\n1 3 5\r\n1 0\r\n2 1\r\n4 9\r\n1 10\r\n2 10\r\n3 12\r\n", "output": "3\r\n"}] | false | stdio | null | true |
237/B | 237 | B | PyPy 3-64 | TESTS | 1 | 92 | 0 | 175841068 | import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
g = [list(map(int, input().split())) for _ in range(n)]
s = dict()
d = [[0 for j in range(w[i])] for i in range(n)]
c = 1
for i in range(n):
for j in range(w[i]):
s[g[i][j]] = (i+1, j+1)
d[i][j] = c
c... | 55 | 186 | 6,963,200 | 216770114 | n = int(input())
c = list(map(int, input().split()))
a = []
for i in range(n):
a.append(list(map(int, input().split())))
d = dict()
for i in range(n):
for j in range(c[i]):
d[a[i][j]] = [i + 1, j + 1]
ans = []
tek = 0
for i in range(n):
for j in range(c[i]):
tek += 1
if a[i][j] != te... | Codeforces Round 147 (Div. 2) | CF | 2,012 | 2 | 256 | Young Table | You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1.
Let's denote s as the total number of cells of table a, that is, $$s = \sum_{i=1}^{n} c_i$$. We know that each cell of the table contains a single integer from 1 ... | The first line contains a single integer n (1 ≤ n ≤ 50) that shows the number of rows in the table. The second line contains n space-separated integers ci (1 ≤ ci ≤ 50; ci ≤ ci - 1) — the numbers of cells on the corresponding rows.
Next n lines contain table а. The i-th of them contains ci space-separated integers: th... | In the first line print a single integer m (0 ≤ m ≤ s), representing the number of performed swaps.
In the next m lines print the description of these swap operations. In the i-th line print four space-separated integers xi, yi, pi, qi (1 ≤ xi, pi ≤ n; 1 ≤ yi ≤ cxi; 1 ≤ qi ≤ cpi). The printed numbers denote swapping t... | null | null | [{"input": "3\n3 2 1\n4 3 5\n6 1\n2", "output": "2\n1 1 2 2\n2 1 3 1"}, {"input": "1\n4\n4 3 2 1", "output": "2\n1 1 1 4\n1 2 1 3"}] | 1,500 | ["implementation", "sortings"] | 55 | [{"input": "3\r\n3 2 1\r\n4 3 5\r\n6 1\r\n2\r\n", "output": "2\r\n1 1 2 2\r\n2 1 3 1\r\n"}, {"input": "1\r\n4\r\n4 3 2 1\r\n", "output": "2\r\n1 1 1 4\r\n1 2 1 3\r\n"}, {"input": "5\r\n4 4 3 3 1\r\n14 13 4 15\r\n11 1 2 5\r\n7 6 10\r\n8 9 3\r\n12\r\n", "output": "13\r\n1 1 2 2\r\n1 2 2 3\r\n1 3 4 3\r\n1 4 4 3\r\n2 1 2 4... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
lines = f.read().splitlines()
ptr = 0
n = int(lines[ptr])
ptr += 1
c = list(map(int, lines[ptr].split()))
ptr += 1
s = sum(c)
table = ... | true |
58/D | 58 | D | PyPy 3-64 | TESTS | 0 | 92 | 0 | 186355070 | # Read input
n = int(input())
cities = []
for i in range(n):
cities.append(input())
d = input()
# Sort the list of cities
cities.sort()
# Divide the list into two equal halves
half = n // 2
cities1 = cities[:half]
cities2 = cities[half:]
# Zip the two halves together to create a list of pairs of cities
calendar ... | 46 | 810 | 10,137,600 | 67845539 | import heapq
n = int(input())
totLength = 0
allNames = []
used = {}
namesOfLength = [[] for i in range(11)]
for o in range(n):
s = input()
totLength += len(s)
allNames.append(s)
namesOfLength[len(s)].append(s)
d = input()
for i in range(n):
allNames[i] += d
allNames.sort()
charPerLine = 2*totLength... | Codeforces Beta Round 54 (Div. 2) | CF | 2,011 | 2 | 256 | Calendar | BerOilGasDiamondBank has branches in n cities, at that n is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: the calendar should consist of exactly n / 2 lines of strictly equal length, each of which contains exactly two names and exactly one sep... | The first line contains an integer n (1 ≤ n ≤ 104, n is even) which is the number of branches. Then follow n lines which are the names of the cities. All the names consist of lowercase Latin letters; their lengths are no less than 1 and no more than 10 symbols. The next line contains a single symbol d (d has an ASCII-c... | Print n / 2 lines of similar length which are the required calendar. Every line should contain exactly two words and exactly one separator between them. If there are several solutions, print the lexicographically minimal one. The lexicographical comparison of lines is realized by the "<" operator in the modern programm... | null | null | [{"input": "4\nb\naa\nhg\nc\n.", "output": "aa.b\nc.hg"}, {"input": "2\naa\na\n!", "output": "a!aa"}, {"input": "2\naa\na\n|", "output": "aa|a"}] | 2,000 | ["greedy", "strings"] | 46 | [{"input": "4\r\nb\r\naa\r\nhg\r\nc\r\n.\r\n", "output": "aa.b\r\nc.hg\r\n"}, {"input": "2\r\naa\r\na\r\n!\r\n", "output": "a!aa\r\n"}, {"input": "2\r\naa\r\na\r\n|\r\n", "output": "aa|a\r\n"}, {"input": "4\r\nqhcivbxotj\r\nirgxzzxvw\r\npxdmcyszvk\r\nyyaevcdal\r\n~\r\n", "output": "irgxzzxvw~pxdmcyszvk\r\nqhcivbxotj~yy... | false | stdio | null | true |
831/B | 831 | B | Python 3 | TESTS | 0 | 30 | 0 | 215367358 | normal = input()
different = input()
text = input()
new = ""
for char in text:
if char.isalpha():
for i in range(len(normal)):
if char.isupper() and char.lower() == normal[i]:
new += different[i].upper()
else:
new += different[i]
else:
new... | 19 | 31 | 0 | 147677202 | k1=str(input()[:26])
k2=str(input()[:26])
tx=str(input())
newStr = ""
for j in tx:
for i in range(len(k1)):
if j.lower() == k1[i] and j.islower():
newStr += k2[i]
elif j.lower() == k1[i] and j.isupper():
newStr += k2[i].upper()
elif j.isdigit():
newStr += j
break
print(newStr) | Codeforces Round 424 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Keyboard Layouts | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.
You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts i... | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout.
The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout.
The third line contains a non-empty string s consisting of lowercase and... | Print the text if the same keys were pressed in the second layout. | null | null | [{"input": "qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "output": "HelloVKCup2017"}, {"input": "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7", "output": "7uduGUDUUDUgudu7"}] | 800 | ["implementation", "strings"] | 19 | [{"input": "qwertyuiopasdfghjklzxcvbnm\r\nveamhjsgqocnrbfxdtwkylupzi\r\nTwccpQZAvb2017\r\n", "output": "HelloVKCup2017\r\n"}, {"input": "mnbvcxzlkjhgfdsapoiuytrewq\r\nasdfghjklqwertyuiopzxcvbnm\r\n7abaCABAABAcaba7\r\n", "output": "7uduGUDUUDUgudu7\r\n"}, {"input": "ayvguplhjsoiencbkxdrfwmqtz\r\nkhzvtbspcndierqumlojyagf... | false | stdio | null | true |
311/B | 311 | B | Python 3 | TESTS | 1 | 92 | 7,065,600 | 38941287 | oo = int(1e20)
f = lambda : map(int, input().split())
d, dp, suffix, a = [0, 0], [], [], [-oo]
n, m, k = f()
for i in range (m + 10) :
dp.append(0)
suffix.append(0)
tp = [int(x) for x in input().split()]
for i in range (2, n + 1) :
d.append(tp[i - 2] + d[i - 1])
for i in range (m) :
h, t = f()
a... | 30 | 1,216 | 27,340,800 | 211419212 | def solve(A, B, C):
N = len(B) + 1
M = len(C)
a = [0] * N
for i in range(1, N):
a[i] += a[i - 1] + B[i - 1]
b = [0] * M
s = [0] * M
dp = [0] * M
k = [0] * M
for i in range(M):
b[i] = C[i][1] - a[C[i][0] - 1]
b.sort()
for i in range(M -... | Codeforces Round 185 (Div. 1) | CF | 2,013 | 2 | 256 | Cats Transport | Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straight road across the farm and n hills along the road, numbered from 1 to n from left to right. The distance between hill i and (i - 1) is di meters. The feeders live in hill 1.
One day, the cats went out to play. Cat i went o... | The first line of the input contains three integers n, m, p (2 ≤ n ≤ 105, 1 ≤ m ≤ 105, 1 ≤ p ≤ 100).
The second line contains n - 1 positive integers d2, d3, ..., dn (1 ≤ di < 104).
Each of the next m lines contains two integers hi and ti (1 ≤ hi ≤ n, 0 ≤ ti ≤ 109). | Output an integer, the minimum sum of waiting time of all cats.
Please, do not write 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 | null | [{"input": "4 6 2\n1 3 5\n1 0\n2 1\n4 9\n1 10\n2 10\n3 12", "output": "3"}] | 2,400 | ["data structures", "dp"] | 30 | [{"input": "4 6 2\r\n1 3 5\r\n1 0\r\n2 1\r\n4 9\r\n1 10\r\n2 10\r\n3 12\r\n", "output": "3\r\n"}] | false | stdio | null | true |
457/B | 457 | B | Python 3 | TESTS | 2 | 109 | 0 | 67588331 | mn = [int(i) for i in input().split()]
a = [int(j) for j in input().split()]
b = [int(k) for k in input().split()]
c = a+b
print(c.count(max(c))*(sum(c)-(c.count(max(c))*max(c)))) | 77 | 296 | 11,264,000 | 162480494 | n, m = map(int, input().split())
sum1 = 0
sum2 = 0
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
for i in range (0, n) :
sum1 += a[i]
for i in range (0, m) :
sum2 += b[i]
ans1 = sum2
ans2 = sum1
a.sort()
b.sort()
for i in range (0, n-1) :
ans1 += min(a[i], sum2... | MemSQL Start[c]UP 2.0 - Round 2 | CF | 2,014 | 1 | 256 | Distributed Join | Piegirl was asked to implement two table join operation for distributed database system, minimizing the network traffic.
Suppose she wants to join two tables, A and B. Each of them has certain number of rows which are distributed on different number of partitions. Table A is distributed on the first cluster consisting... | First line contains two integer numbers, m and n (1 ≤ m, n ≤ 105). Second line contains description of the first cluster with m space separated integers, ai (1 ≤ ai ≤ 109). Similarly, third line describes second cluster with n space separated integers, bi (1 ≤ bi ≤ 109). | Print one integer — minimal number of copy operations. | null | In the first example it makes sense to move all the rows to the second partition of the second cluster which is achieved in 2 + 6 + 3 = 11 operations
In the second example Piegirl can copy each row from B to the both partitions of the first cluster which needs 2·3 = 6 copy operations. | [{"input": "2 2\n2 6\n3 100", "output": "11"}, {"input": "2 3\n10 10\n1 1 1", "output": "6"}] | 1,900 | ["greedy"] | 77 | [{"input": "2 2\r\n2 6\r\n3 100\r\n", "output": "11\r\n"}, {"input": "2 3\r\n10 10\r\n1 1 1\r\n", "output": "6\r\n"}, {"input": "2 2\r\n888381664 866366630\r\n170399907 404233949\r\n", "output": "1149267712\r\n"}, {"input": "3 4\r\n337369924 278848730 654933675\r\n866361693 732544605 890800310 350303294\r\n", "output":... | false | stdio | null | true |
982/D | 982 | D | PyPy 3 | TESTS | 2 | 108 | 20,172,800 | 127577116 | #brute hai
def brute(a):
l=list(zip(a,range(len(a))))
l=sorted(l,key=lambda s:s[0])
ans=-1
id=float("inf")
for i in range(len(l)):
res=l[i:]
f=True
cnt=1
if ans<=1 and i>=1:
id=min(id,res[0][0])
ans=1
if len(res)>=2:
temp=res[0][1]
for j in range(len(res)-1):
if res[j+1][1]-res[j][1]-1==te... | 50 | 342 | 26,214,400 | 139935576 | import sys
input = sys.stdin.buffer.readline
def process(A):
n = len(A)
A2 = sorted(A)
inverse = {}
cell_sizes = [0 for i in range(n+3)]
cell_size_count = 0
left_borders = [0 for i in range(n+3)]
right_borders = [0 for i in range(n+3)]
answer = [0, None]
for i in range(n):
... | Codeforces Round 484 (Div. 2) | CF | 2,018 | 1 | 256 | Shark | For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations.
Max is a young biologist. For $$$n$$$ days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All t... | The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of days.
The second line contains $$$n$$$ distinct positive integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the distance traveled in each of the day. | Print a single integer $$$k$$$, such that
1. the shark was in each location the same number of days,
2. the number of locations is maximum possible satisfying the first condition,
3. $$$k$$$ is smallest possible satisfying the first and second conditions. | null | In the first example the shark travels inside a location on days $$$1$$$ and $$$2$$$ (first location), then on $$$4$$$-th and $$$5$$$-th days (second location), then on $$$7$$$-th and $$$8$$$-th days (third location). There are three locations in total.
In the second example the shark only moves inside a location on t... | [{"input": "8\n1 2 7 3 4 8 5 6", "output": "7"}, {"input": "6\n25 1 2 3 14 36", "output": "2"}] | 1,900 | ["brute force", "data structures", "dsu", "trees"] | 50 | [{"input": "8\r\n1 2 7 3 4 8 5 6\r\n", "output": "7"}, {"input": "6\r\n25 1 2 3 14 36\r\n", "output": "2"}, {"input": "20\r\n1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11\r\n", "output": "11"}, {"input": "7\r\n1 2 5 7 3 4 6\r\n", "output": "5"}, {"input": "1\r\n1000000000\r\n", "output": "1000000001"}, {"input": "... | false | stdio | null | true |
58/D | 58 | D | PyPy 3-64 | TESTS | 0 | 60 | 0 | 186355239 | # Read input
n = int(input())
cities = []
for i in range(n):
cities.append(input())
d = input()
# Sort the list of cities
cities.sort()
# Divide the list into two equal halves
half = n // 2
cities1 = cities[:half]
cities2 = cities[half:]
# Zip the two halves together to create a list of pairs of cities
calendar ... | 46 | 1,622 | 1,228,800 | 18768735 | n = int(input()) // 2
a = sorted([input() for i in range(n * 2)], reverse = 1)
d = input()
L = sum(len(i) for i in a) // n
ans = []
for i in range(n):
x = a.pop()
for y in a[::-1]:
if len(x) + len(y) == L:
ans.append(min(x + d + y, y + d + x))
a.remove(y)
break
print(... | Codeforces Beta Round 54 (Div. 2) | CF | 2,011 | 2 | 256 | Calendar | BerOilGasDiamondBank has branches in n cities, at that n is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: the calendar should consist of exactly n / 2 lines of strictly equal length, each of which contains exactly two names and exactly one sep... | The first line contains an integer n (1 ≤ n ≤ 104, n is even) which is the number of branches. Then follow n lines which are the names of the cities. All the names consist of lowercase Latin letters; their lengths are no less than 1 and no more than 10 symbols. The next line contains a single symbol d (d has an ASCII-c... | Print n / 2 lines of similar length which are the required calendar. Every line should contain exactly two words and exactly one separator between them. If there are several solutions, print the lexicographically minimal one. The lexicographical comparison of lines is realized by the "<" operator in the modern programm... | null | null | [{"input": "4\nb\naa\nhg\nc\n.", "output": "aa.b\nc.hg"}, {"input": "2\naa\na\n!", "output": "a!aa"}, {"input": "2\naa\na\n|", "output": "aa|a"}] | 2,000 | ["greedy", "strings"] | 46 | [{"input": "4\r\nb\r\naa\r\nhg\r\nc\r\n.\r\n", "output": "aa.b\r\nc.hg\r\n"}, {"input": "2\r\naa\r\na\r\n!\r\n", "output": "a!aa\r\n"}, {"input": "2\r\naa\r\na\r\n|\r\n", "output": "aa|a\r\n"}, {"input": "4\r\nqhcivbxotj\r\nirgxzzxvw\r\npxdmcyszvk\r\nyyaevcdal\r\n~\r\n", "output": "irgxzzxvw~pxdmcyszvk\r\nqhcivbxotj~yy... | false | stdio | null | true |
960/F | 960 | F | Python 3 | TESTS | 1 | 77 | 7,065,600 | 37092866 | n,m = map(int, input().split())
dp = [set() for _ in range(n)]
def pixat(to, path):
to_remove = []
for p in dp[to]:
if p[1] >= path[1] and p[0] <= path[0]:
return
if p[1] <= path[1] and p[0] >= path[0]:
to_remove.append(p)
for r in to_remove:
dp[to].remove(r)
... | 63 | 685 | 44,236,800 | 206868890 | import bisect
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return u * z + v
def update(i, x):
i += l1
tree[i] = x
i //= 2
while i:
tree[i] = max(tree[2 * i], tree[2 * i + 1])
i //= 2
return
def get_max(s, t):
s, t = s + l1, ... | Divide by Zero 2018 and Codeforces Round 474 (Div. 1 + Div. 2, combined) | CF | 2,018 | 1 | 256 | Pathwalks | You are given a directed graph with n nodes and m edges, with all edges having a certain weight.
There might be multiple edges and self loops, and the graph can also be disconnected.
You need to choose a path (possibly passing through same vertices multiple times) in the graph such that the weights of the edges are i... | The first line contains two integers n and m (1 ≤ n ≤ 100000,1 ≤ m ≤ 100000) — the number of vertices and edges in the graph, respectively.
m lines follows.
The i-th of these lines contains three space separated integers ai, bi and wi (1 ≤ ai, bi ≤ n, 0 ≤ wi ≤ 100000), denoting an edge from vertex ai to vertex bi hav... | Print one integer in a single line — the maximum number of edges in the path. | null | The answer for the first sample input is 2: $$1 \rightarrow 2 \rightarrow 3$$. Note that you cannot traverse $$1 \rightarrow 2 \rightarrow 3 \rightarrow 1$$ because edge $$\overset{3}{\rightarrow}1$$ appears earlier in the input than the other two edges and hence cannot be picked/traversed after either of the other two... | [{"input": "3 3\n3 1 3\n1 2 1\n2 3 2", "output": "2"}, {"input": "5 5\n1 3 2\n3 2 3\n3 4 5\n5 4 0\n4 5 8", "output": "3"}] | 2,100 | ["data structures", "dp", "graphs"] | 63 | [{"input": "3 3\r\n3 1 3\r\n1 2 1\r\n2 3 2\r\n", "output": "2"}, {"input": "5 5\r\n1 3 2\r\n3 2 3\r\n3 4 5\r\n5 4 0\r\n4 5 8\r\n", "output": "3"}, {"input": "5 10\r\n3 4 8366\r\n5 1 6059\r\n2 1 72369\r\n2 2 35472\r\n5 3 50268\r\n2 4 98054\r\n5 1 26220\r\n2 3 24841\r\n1 3 42450\r\n3 1 59590\r\n", "output": "3"}, {"input... | false | stdio | null | true |
397/B | 397 | B | Python 3 | TESTS | 2 | 62 | 0 | 6759060 | t = int(input())
for _ in range(t):
n, l, r = map(int, input().split())
if n < l:
print("No")
elif n <= r:
print("Yes")
else:
d = n // l
if d * l <= n <= (d - 1) * l + r:
print("Yes")
else:
print("No") | 6 | 108 | 204,800 | 63120826 | for i in range(int(input())):
n,l,r = map(int,input().split())
print('No') if (n//l)<n/r else print('Yes') | Codeforces Round 232 (Div. 2) | CF | 2,014 | 1 | 256 | On Corruption and Numbers | Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to w... | The first line contains the number of universities t, (1 ≤ t ≤ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 ≤ ni, li, ri ≤ 109; li ≤ ri). | For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise. | null | You can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid. | [{"input": "2\n5 2 3\n6 4 5", "output": "Yes\nNo"}] | null | ["constructive algorithms", "implementation", "math"] | 6 | [{"input": "2\r\n5 2 3\r\n6 4 5\r\n", "output": "Yes\r\nNo\r\n"}, {"input": "50\r\n69 6 6\r\n22 1 1\r\n23 3 3\r\n60 13 13\r\n13 3 3\r\n7 4 7\r\n6 1 1\r\n49 7 9\r\n68 8 8\r\n20 2 2\r\n34 1 1\r\n79 5 5\r\n22 1 1\r\n77 58 65\r\n10 3 3\r\n72 5 5\r\n47 1 1\r\n82 3 3\r\n92 8 8\r\n34 1 1\r\n42 9 10\r\n63 14 14\r\n10 3 3\r\n38... | false | stdio | null | true |
982/D | 982 | D | Python 3 | TESTS | 4 | 46 | 0 | 154419850 | days = int(input())
segments = list(map(int,input().split()))
sorted_arr = segments.copy()
sorted_arr.sort()
sorted_dict = {x:[[]] for x in sorted_arr[1:]}
res = [0,0]
for minimum in sorted_arr[1:]:
for k in segments:
if k < minimum:
if sum(sorted_dict[minimum][-1]) >= minimum:
... | 50 | 389 | 22,016,000 | 164651035 | def main():
n = int(input())
ori_a = [int(x) for x in input().split()]
pos = {ori_a[i]: i for i in range(len(ori_a))}
seg = [dict(left=None, right=None) for i in range(len(ori_a))]
a = sorted(ori_a)
seg_size = 0
seg_num = 0
fi_k = a[0]
fi_seg_num = 0
for n_items, item in enumer... | Codeforces Round 484 (Div. 2) | CF | 2,018 | 1 | 256 | Shark | For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations.
Max is a young biologist. For $$$n$$$ days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All t... | The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of days.
The second line contains $$$n$$$ distinct positive integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the distance traveled in each of the day. | Print a single integer $$$k$$$, such that
1. the shark was in each location the same number of days,
2. the number of locations is maximum possible satisfying the first condition,
3. $$$k$$$ is smallest possible satisfying the first and second conditions. | null | In the first example the shark travels inside a location on days $$$1$$$ and $$$2$$$ (first location), then on $$$4$$$-th and $$$5$$$-th days (second location), then on $$$7$$$-th and $$$8$$$-th days (third location). There are three locations in total.
In the second example the shark only moves inside a location on t... | [{"input": "8\n1 2 7 3 4 8 5 6", "output": "7"}, {"input": "6\n25 1 2 3 14 36", "output": "2"}] | 1,900 | ["brute force", "data structures", "dsu", "trees"] | 50 | [{"input": "8\r\n1 2 7 3 4 8 5 6\r\n", "output": "7"}, {"input": "6\r\n25 1 2 3 14 36\r\n", "output": "2"}, {"input": "20\r\n1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11\r\n", "output": "11"}, {"input": "7\r\n1 2 5 7 3 4 6\r\n", "output": "5"}, {"input": "1\r\n1000000000\r\n", "output": "1000000001"}, {"input": "... | false | stdio | null | true |
831/B | 831 | B | Python 3 | TESTS | 0 | 31 | 0 | 205456250 | a = input().lower()
b = input().lower()
c = input().lower()
new_text = ''
for i in c:
if i.isalpha():
if i.islower():
index = a.find(i)
new_text += b[index]
else:
index = c.find(i)
new_text += c[index]
print(new_text) | 19 | 31 | 0 | 147782656 | s1 = input()
s2 = input()
s = input()
o = ''
for alpha in s:
if alpha.lower() in s1:
if alpha.isupper():
o += s2[s1.index(alpha.lower())].upper()
else:
o += s2[s1.index(alpha.lower())]
else:
o += alpha
print(o) | Codeforces Round 424 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Keyboard Layouts | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.
You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts i... | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout.
The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout.
The third line contains a non-empty string s consisting of lowercase and... | Print the text if the same keys were pressed in the second layout. | null | null | [{"input": "qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "output": "HelloVKCup2017"}, {"input": "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7", "output": "7uduGUDUUDUgudu7"}] | 800 | ["implementation", "strings"] | 19 | [{"input": "qwertyuiopasdfghjklzxcvbnm\r\nveamhjsgqocnrbfxdtwkylupzi\r\nTwccpQZAvb2017\r\n", "output": "HelloVKCup2017\r\n"}, {"input": "mnbvcxzlkjhgfdsapoiuytrewq\r\nasdfghjklqwertyuiopzxcvbnm\r\n7abaCABAABAcaba7\r\n", "output": "7uduGUDUUDUgudu7\r\n"}, {"input": "ayvguplhjsoiencbkxdrfwmqtz\r\nkhzvtbspcndierqumlojyagf... | false | stdio | null | true |
461/B | 461 | B | PyPy 3 | TESTS | 0 | 77 | 20,172,800 | 122320886 | n = int(input())
t = [int(x) for x in input().split()]
color = [int(x) for x in input().split()]
edge = [[] for _ in range(n)]
dp = [[1, 0] for _ in range(n)]
for i in range(n - 1):
edge[t[i]].append(i + 1)
def dfs(root, parent):
for x in edge[root]:
if x != parent:
dfs(x, root)
... | 23 | 358 | 18,432,000 | 100683256 | mod=10**9+7
n=int(input())
edges=list(map(int,input().split()))
colored=list(map(int,input().split()))
childs=[[] for i in range(n)]
for i in range(1,n):
childs[edges[i-1]].append(i)
dp = [[0,0] for i in range(n)]
for i in range(n-1,-1,-1):
prod=1
for child in childs[i]:
prod*=sum(dp[child])
... | Codeforces Round 263 (Div. 1) | CF | 2,014 | 2 | 256 | Appleman and Tree | Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white.
Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it will split into (k + 1) parts. Note, that each part will be a tree... | The first line contains an integer n (2 ≤ n ≤ 105) — the number of tree vertices.
The second line contains the description of the tree: n - 1 integers p0, p1, ..., pn - 2 (0 ≤ pi ≤ i). Where pi means that there is an edge connecting vertex (i + 1) of the tree and vertex pi. Consider tree vertices are numbered from 0 ... | Output a single integer — the number of ways to split the tree modulo 1000000007 (109 + 7). | null | null | [{"input": "3\n0 0\n0 1 1", "output": "2"}, {"input": "6\n0 1 1 0 4\n1 1 0 0 1 0", "output": "1"}, {"input": "10\n0 1 2 1 4 4 4 0 8\n0 0 0 1 0 1 1 0 0 1", "output": "27"}] | 2,000 | ["dfs and similar", "dp", "trees"] | 23 | [{"input": "3\r\n0 0\r\n0 1 1\r\n", "output": "2\r\n"}, {"input": "6\r\n0 1 1 0 4\r\n1 1 0 0 1 0\r\n", "output": "1\r\n"}, {"input": "10\r\n0 1 2 1 4 4 4 0 8\r\n0 0 0 1 0 1 1 0 0 1\r\n", "output": "27\r\n"}, {"input": "5\r\n0 1 1 3\r\n0 0 0 1 1\r\n", "output": "1\r\n"}, {"input": "10\r\n0 1 1 2 4 3 3 3 2\r\n1 0 1 1 1 0... | false | stdio | null | true |
652/F | 652 | F | Python 3 | TESTS | 1 | 93 | 307,200 | 58373924 | from bisect import bisect
n, l, t = map(int, input().split())
ants = []
for _ in range(n):
x, y = input().split()
ants.append([int(x), y])
bnts = []
diff = []
for i in range(n):
x, w = ants[i][0], 3 - 2*(ants[i][1]=="L")
bnts.append((x + t*w) % l)
if i == 0:
zero = bnts[-1]
if ants[i][1] != ants[0][1]:
if an... | 30 | 1,419 | 45,772,800 | 144096513 | I = lambda: [int(i) for i in input().split()]
import sys
input = sys.stdin.readline
n, L, T = I()
a, b = [0]*n, [0]*n
ans = [0] * n
cnt = 0
for i in range(n):
x, ch = input().split()
a[i] = int(x) - 1
b[i] = (a[i], i)
dr = 1 if ch == "R" else -1
w = a[i] + T * dr
a[i] = (a[i] + ... | Educational Codeforces Round 10 | ICPC | 2,016 | 2 | 256 | Ants on a Circle | n ants are on a circle of length m. An ant travels one unit of distance per one unit of time. Initially, the ant number i is located at the position si and is facing in the direction di (which is either L or R). Positions are numbered in counterclockwise order starting from some point. Positions of the all ants are dis... | The first line contains three integers n, m and t (2 ≤ n ≤ 3·105, 2 ≤ m ≤ 109, 0 ≤ t ≤ 1018) — the number of ants, the length of the circle and the number of time units.
Each of the next n lines contains integer si and symbol di (1 ≤ si ≤ m and di is either L or R) — the position and the direction of the i-th ant at t... | Print n integers xj — the position of the j-th ant after t units of time. The ants are numbered from 1 to n in order of their appearing in input. | null | null | [{"input": "2 4 8\n1 R\n3 L", "output": "1 3"}, {"input": "4 8 6\n6 R\n5 L\n1 R\n8 L", "output": "7 4 2 7"}, {"input": "4 8 2\n1 R\n5 L\n6 L\n8 R", "output": "3 3 4 2"}] | 2,800 | ["constructive algorithms", "math"] | 30 | [{"input": "2 4 8\r\n1 R\r\n3 L\r\n", "output": "1 3\r\n"}, {"input": "4 8 6\r\n6 R\r\n5 L\r\n1 R\r\n8 L\r\n", "output": "7 4 2 7\r\n"}, {"input": "4 8 2\r\n1 R\r\n5 L\r\n6 L\r\n8 R\r\n", "output": "3 3 4 2\r\n"}, {"input": "10 10 90\r\n2 R\r\n1 R\r\n3 L\r\n4 R\r\n7 L\r\n8 L\r\n6 R\r\n9 R\r\n5 R\r\n10 L\r\n", "output":... | false | stdio | null | true |
23/C | 23 | C | Python 3 | TESTS | 3 | 935 | 1,843,200 | 78436980 | t=int(input())
for z in range(t):
n=int(input())
s1=0
s2=0
l1=[]
l2=[]
l3=[]
for i in range(2*n-1):
a,b=map(int,input().split())
s1+=a/2
s2+=b/2
l1.append(a)
l2.append(b)
l3.append(((a+b)*a*b,i))
l4=l3[:]
l4.sort()
l4.reverse()
... | 25 | 950 | 42,905,600 | 212533744 | from sys import stdin
# read = sys.stdin.readline
T = int(stdin.readline())
for _ in range(T):
N = int(stdin.readline())
M = N + N - 1
data = [ ]
for i in range(M):
data.append([int(w) for w in stdin.readline().split()] + [i + 1])
data.sort(reverse=True)
# print(data)
total = sum(d[1... | Codeforces Beta Round 23 | ICPC | 2,010 | 1.5 | 256 | Oranges and Apples | In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges. | The first input line contains one number T — amount of tests. The description of each test starts with a natural number N — amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi — amount of apples and oranges in the i-th box (0 ≤ ai, oi ≤ 109). The sum of N in all the tests in the input doesn't... | For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers — indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with o... | null | null | [{"input": "2\n2\n10 15\n5 7\n20 18\n1\n0 0", "output": "YES\n1 3\nYES\n1"}] | 2,500 | ["constructive algorithms", "sortings"] | 25 | [{"input": "2\r\n2\r\n10 15\r\n5 7\r\n20 18\r\n1\r\n0 0\r\n", "output": "YES\r\n3 1\r\nYES\r\n1\r\n"}] | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path, 'r') as f_in, open(submission_path, 'r') as f_sub:
input_data = f_in.read().split()
sub_lines = [line.strip() for line in f_sub.readlines()]
ptr = 0
T ... | true |
23/C | 23 | C | Python 3 | TESTS | 3 | 1,856 | 2,560,000 | 78440501 | t=int(input())
for z in range(t):
n=int(input())
s1=0
s2=0
l1=[]
l2=[]
for i in range(2*n-1):
a,b=map(int,input().split())
s1+=a/2
s2+=b/2
l1.append((a,i))
l2.append((b,i))
l3=l1[:]
l4=l2[:]
l3.sort(key=lambda x: x[0])
l4.sort(key=lamb... | 25 | 1,045 | 29,593,600 | 154131565 | # 解説を見た
# 一見天才だが、「半分以上」を考えるとき、「ソートして隣同士を比較」は定石の一つ。
import sys
input = sys.stdin.readline
from operator import itemgetter
T=int(input())
for tests in range(T):
N=int(input())
X=[]
for i in range(2*N-1):
a,b=map(int,input().split())
X.append((a,b,i+1))
X.sort(key=itemgetter(0))
ANS... | Codeforces Beta Round 23 | ICPC | 2,010 | 1.5 | 256 | Oranges and Apples | In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges. | The first input line contains one number T — amount of tests. The description of each test starts with a natural number N — amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi — amount of apples and oranges in the i-th box (0 ≤ ai, oi ≤ 109). The sum of N in all the tests in the input doesn't... | For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers — indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with o... | null | null | [{"input": "2\n2\n10 15\n5 7\n20 18\n1\n0 0", "output": "YES\n1 3\nYES\n1"}] | 2,500 | ["constructive algorithms", "sortings"] | 25 | [{"input": "2\r\n2\r\n10 15\r\n5 7\r\n20 18\r\n1\r\n0 0\r\n", "output": "YES\r\n3 1\r\nYES\r\n1\r\n"}] | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path, 'r') as f_in, open(submission_path, 'r') as f_sub:
input_data = f_in.read().split()
sub_lines = [line.strip() for line in f_sub.readlines()]
ptr = 0
T ... | true |
23/B | 23 | B | Python 3 | TESTS | 1 | 62 | 0 | 138008389 | a = int(input())
b = int(input())
if a >= 2:
print(1)
elif b >= 2:
print(1)
elif a >= 2 and b >= 2:
print(2) | 2 | 436 | 9,523,200 | 153665974 | import sys
input = sys.stdin.readline
t=int(input())
for tests in range(t):
n=int(input())
print(max(0,n-2)) | Codeforces Beta Round 23 | ICPC | 2,010 | 2 | 256 | Party | n people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2, 3, ..., n - 1 friends among those who stayed by the moment of their leaving, did the same.
What is the maximum amount of pe... | The first input line contains one number t — amount of tests (1 ≤ t ≤ 105). Each of the following t lines contains one integer number n (1 ≤ n ≤ 105). | For each test output in a separate line one number — the maximum amount of people that could stay in the end. | null | null | [{"input": "1\n3", "output": "1"}] | 1,600 | ["constructive algorithms", "graphs", "math"] | 2 | [{"input": "1\r\n3\r\n", "output": "1\r\n"}] | false | stdio | null | true |
95/C | 95 | C | Python 3 | TESTS | 1 | 92 | 0 | 226705762 | # LUOGU_RID: 127785605
#aaaaaaaaaaaaaaaaaaaaaaaaaaaaa
print(9) | 65 | 1,590 | 30,105,600 | 153724036 | import heapq
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def dijkstra(s):
dist = [inf] * (n + 1)
dist[s] = 0
p = []
heapq.heappush(p, (dist[s], s))
while p:
d, u = heapq.heappop(p)
if dist[u] < d:
continue
for v, c in G[u]:
... | Codeforces Beta Round 77 (Div. 1 Only) | CF | 2,011 | 2 | 256 | Volleyball | Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has n junctions, some of which are connected by two-way roads. The length of each road is defined by some positive integer number of meters; the roads can... | The first line contains two integers n and m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 1000). They are the number of junctions and roads in the city correspondingly. The junctions are numbered from 1 to n, inclusive. The next line contains two integers x and y (1 ≤ x, y ≤ n). They are the numbers of the initial and final junctions corres... | If taxis can't drive Petya to the destination point, print "-1" (without the quotes). Otherwise, print the drive's minimum cost.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator. | null | An optimal way — ride from the junction 1 to 2 (via junction 4), then from 2 to 3. It costs 7+2=9 bourles. | [{"input": "4 4\n1 3\n1 2 3\n1 4 1\n2 4 1\n2 3 5\n2 7\n7 2\n1 2\n7 7", "output": "9"}] | 1,900 | ["shortest paths"] | 65 | [{"input": "4 4\r\n1 3\r\n1 2 3\r\n1 4 1\r\n2 4 1\r\n2 3 5\r\n2 7\r\n7 2\r\n1 2\r\n7 7\r\n", "output": "9\r\n"}, {"input": "3 3\r\n1 3\r\n1 2 2\r\n1 3 3\r\n3 2 1\r\n2 7\r\n2 7\r\n3 6\r\n", "output": "14\r\n"}, {"input": "3 1\r\n1 3\r\n1 2 2\r\n2 7\r\n2 7\r\n3 6\r\n", "output": "-1\r\n"}, {"input": "3 2\r\n3 3\r\n1 2 2\... | false | stdio | null | true |
23/C | 23 | C | PyPy 3-64 | TESTS | 1 | 467 | 10,649,600 | 212532745 | from sys import stdin
# read = sys.stdin.readline
T = int(stdin.readline())
for _ in range(T):
N = int(stdin.readline())
M = N + N - 1
data = [ ]
for i in range(M):
data.append([int(w) for w in stdin.readline().split()])
data.sort(reverse=True)
total = sum(d[1] for d in data)
half = ... | 25 | 1,294 | 24,371,200 | 170146783 | t=int(input())
for _ in range(t):
n=int(input())
nums=[]
for i in range(2*n-1):
a,b=map(int,input().split())
nums.append([b,a,i+1])
nums=sorted(nums)[::-1]
vals=[nums[0][2]]
i=1
while(i+1<len(nums)):
c=i
if(nums[i][1]<nums[i+1][1]):
c=i+1
v... | Codeforces Beta Round 23 | ICPC | 2,010 | 1.5 | 256 | Oranges and Apples | In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges. | The first input line contains one number T — amount of tests. The description of each test starts with a natural number N — amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi — amount of apples and oranges in the i-th box (0 ≤ ai, oi ≤ 109). The sum of N in all the tests in the input doesn't... | For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers — indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with o... | null | null | [{"input": "2\n2\n10 15\n5 7\n20 18\n1\n0 0", "output": "YES\n1 3\nYES\n1"}] | 2,500 | ["constructive algorithms", "sortings"] | 25 | [{"input": "2\r\n2\r\n10 15\r\n5 7\r\n20 18\r\n1\r\n0 0\r\n", "output": "YES\r\n3 1\r\nYES\r\n1\r\n"}] | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path, 'r') as f_in, open(submission_path, 'r') as f_sub:
input_data = f_in.read().split()
sub_lines = [line.strip() for line in f_sub.readlines()]
ptr = 0
T ... | true |
23/B | 23 | B | Python 3 | TESTS | 1 | 92 | 409,600 | 167609995 | # Coded By Block_Cipher
import math
import os
import random
import re
import sys
from math import gcd
from math import sqrt
from collections import Counter
n = int(input())
if n%2!=0:
print(1)
else:
print(0) | 2 | 498 | 9,625,600 | 206004920 | import sys
import math
input = sys.stdin.readline
def fg():
return int(input())
def fgh():
return [int(xx) for xx in input().split()]
M = 10 ** 9 + 7
for _____ in range(fg()):
n = fg()
print(max(0, n - 2)) | Codeforces Beta Round 23 | ICPC | 2,010 | 2 | 256 | Party | n people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2, 3, ..., n - 1 friends among those who stayed by the moment of their leaving, did the same.
What is the maximum amount of pe... | The first input line contains one number t — amount of tests (1 ≤ t ≤ 105). Each of the following t lines contains one integer number n (1 ≤ n ≤ 105). | For each test output in a separate line one number — the maximum amount of people that could stay in the end. | null | null | [{"input": "1\n3", "output": "1"}] | 1,600 | ["constructive algorithms", "graphs", "math"] | 2 | [{"input": "1\r\n3\r\n", "output": "1\r\n"}] | false | stdio | null | true |
739/A | 739 | A | Python 3 | TESTS | 1 | 62 | 0 | 22901893 | [n, m] = map(int, input().split())
ans = 1e9
for i in range(m):
[l, r] = map(int, input().split())
ans = min(ans, r - l + 1)
print(ans)
for i in range(n):
print(i % (1 + ans)) | 69 | 405 | 16,179,200 | 22624691 | def main():
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
z = min(y - x + 1 for x, y in a)
print (z)
print( ' '.join([str(i % z) for i in range(n)]))
main() | Codeforces Round 381 (Div. 1) | CF | 2,016 | 2 | 256 | Alyona and mex | Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, ... | The first line contains two integers n and m (1 ≤ n, m ≤ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n), that describe the subarray a[li], a[li + 1], ..., a[ri]. | In the first line print single integer — the maximum possible minimum mex.
In the second line print n integers — the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, prin... | null | The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | [{"input": "5 3\n1 3\n2 5\n4 5", "output": "2\n1 0 2 1 0"}, {"input": "4 2\n1 4\n2 4", "output": "3\n5 2 0 1"}] | 1,700 | ["constructive algorithms", "greedy"] | 69 | [{"input": "5 3\r\n1 3\r\n2 5\r\n4 5\r\n", "output": "2\r\n0 1 0 1 0\r\n"}, {"input": "4 2\r\n1 4\r\n2 4\r\n", "output": "3\r\n0 1 2 0\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n0\r\n"}, {"input": "2 1\r\n2 2\r\n", "output": "1\r\n0 0\r\n"}, {"input": "5 6\r\n2 4\r\n2 3\r\n1 4\r\n3 4\r\n2 5\r\n1 3\r\n", "output... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path, 'r') as f:
n, m = map(int, f.readline().split())
subarrays = [tuple(map(int, line.strip().split())) for line in f]
# Read reference output... | true |
792/F | 792 | F | Python 3 | TESTS | 0 | 46 | 4,812,800 | 26330414 | million = 10**6
def vova_fight(input_string):
input_list = input_string.split('\n')
init_condition = input_list.pop(0).split(' ')
queries = int(init_condition[0])
mana_total = int(init_condition[1])
spells = []
j = 0
for i in range(0,queries):
current_query = input_list[i].split(' '... | 36 | 873 | 15,564,800 | 37535361 | #!/usr/bin/env python3
# solution after hint
# (instead of best hit/mana spell store convex hull of spells)
# O(n^2) instead of O(n log n)
[q, m] = map(int, input().strip().split())
qis = [tuple(map(int, input().strip().split())) for _ in range(q)]
mod = 10**6
j = 0
spell_chull = [(0, 0)] # lower hull _/
def is_... | Educational Codeforces Round 18 | ICPC | 2,017 | 2 | 256 | Mages and Monsters | Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells.
Vova's character can learn new spells during the game. Every spell is characterized by two values xi and yi — damage per second and mana cost per second, respectively. Vova ... | The first line contains two integer numbers q and m (2 ≤ q ≤ 105, 1 ≤ m ≤ 1012) — the number of queries and the amount of mana at the beginning of every fight.
i-th of each next q lines contains three numbers ki, ai and bi (1 ≤ ki ≤ 2, 1 ≤ ai, bi ≤ 106).
Using them you can restore queries this way: let j be the index... | For every query of second type print YES if Vova is able to win the fight with corresponding monster and NO otherwise. | null | In first example Vova's character at first learns the spell with 5 damage and 10 mana cost per second. Next query is a fight with monster which can kill character in 20 seconds and has 50 health points. Vova kills it in 10 seconds (spending 100 mana). Next monster has 52 health, so Vova can't deal that much damage with... | [{"input": "3 100\n1 4 9\n2 19 49\n2 19 49", "output": "YES\nNO"}] | 3,100 | ["data structures", "geometry"] | 36 | [{"input": "3 100\r\n1 4 9\r\n2 19 49\r\n2 19 49\r\n", "output": "YES\r\nNO\r\n"}, {"input": "10 442006988299\r\n2 10 47\r\n1 9 83\r\n1 15 24\r\n2 19 47\r\n2 75 99\r\n2 85 23\r\n2 8 33\r\n2 9 82\r\n1 86 49\r\n2 71 49\r\n", "output": "NO\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\n"}, {"input": "2 424978864039\r\n2 7 3... | false | stdio | null | true |
23/B | 23 | B | Python 3 | TESTS | 1 | 434 | 5,632,000 | 34057632 | a=int(input())
s=0
for i in range(0,a):
c=int(input())
if(c>1):
s=s+1
print(s) | 2 | 528 | 9,830,400 | 45194826 | import sys
inputs,first = sys.stdin.readlines(),True
for i in inputs:
if first:
first = False
else:
print(max(0,int(i)-2)) | Codeforces Beta Round 23 | ICPC | 2,010 | 2 | 256 | Party | n people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2, 3, ..., n - 1 friends among those who stayed by the moment of their leaving, did the same.
What is the maximum amount of pe... | The first input line contains one number t — amount of tests (1 ≤ t ≤ 105). Each of the following t lines contains one integer number n (1 ≤ n ≤ 105). | For each test output in a separate line one number — the maximum amount of people that could stay in the end. | null | null | [{"input": "1\n3", "output": "1"}] | 1,600 | ["constructive algorithms", "graphs", "math"] | 2 | [{"input": "1\r\n3\r\n", "output": "1\r\n"}] | false | stdio | null | true |
23/C | 23 | C | PyPy 3 | TESTS | 1 | 1,855 | 12,083,200 | 197190305 | for _ in range(int(input())):
N = int(input())
a = []
o = []
apple = 0
orange = 0
answers = []
A = 0
O = 0
for _ in range(2*N-1):
x,y = map(int,input().split())
a.append(x)
o.append(y)
A += x
O += y
A /= 2*N
O /= 2*N
x = []
y = ... | 25 | 1,309 | 24,371,200 | 170149156 | t = int(input())
for _ in range(t):
n = int(input())
nums = []
for i in range(2*n-1):
a, b = map(int, input().split())
nums.append([b, a, i+1])
s=set()
nums = sorted(nums)[::-1]
vals=[]
vals.append(nums[0][2])
i=1
while len(vals)<n:
c=i
if nums[i][1] ... | Codeforces Beta Round 23 | ICPC | 2,010 | 1.5 | 256 | Oranges and Apples | In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges. | The first input line contains one number T — amount of tests. The description of each test starts with a natural number N — amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi — amount of apples and oranges in the i-th box (0 ≤ ai, oi ≤ 109). The sum of N in all the tests in the input doesn't... | For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers — indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with o... | null | null | [{"input": "2\n2\n10 15\n5 7\n20 18\n1\n0 0", "output": "YES\n1 3\nYES\n1"}] | 2,500 | ["constructive algorithms", "sortings"] | 25 | [{"input": "2\r\n2\r\n10 15\r\n5 7\r\n20 18\r\n1\r\n0 0\r\n", "output": "YES\r\n3 1\r\nYES\r\n1\r\n"}] | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path, 'r') as f_in, open(submission_path, 'r') as f_sub:
input_data = f_in.read().split()
sub_lines = [line.strip() for line in f_sub.readlines()]
ptr = 0
T ... | true |
23/B | 23 | B | Python 3 | TESTS | 1 | 466 | 7,168,000 | 11601107 | import sys
from itertools import *
from math import *
def solve():
t = int(input())
res = list()
for test in range(t):
val = int(input())
res.append(val // 2)
print(' '.join(map(str, res)))
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve() | 2 | 530 | 6,860,800 | 11923591 | num_tests = int(input())
results = num_tests * [None]
for i in range(num_tests):
n = int(input())
results[i] = max(0, n-2)
print('\n'.join(map(str, results))) | Codeforces Beta Round 23 | ICPC | 2,010 | 2 | 256 | Party | n people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2, 3, ..., n - 1 friends among those who stayed by the moment of their leaving, did the same.
What is the maximum amount of pe... | The first input line contains one number t — amount of tests (1 ≤ t ≤ 105). Each of the following t lines contains one integer number n (1 ≤ n ≤ 105). | For each test output in a separate line one number — the maximum amount of people that could stay in the end. | null | null | [{"input": "1\n3", "output": "1"}] | 1,600 | ["constructive algorithms", "graphs", "math"] | 2 | [{"input": "1\r\n3\r\n", "output": "1\r\n"}] | false | stdio | null | true |
23/C | 23 | C | PyPy 3 | TESTS | 1 | 654 | 15,052,800 | 85923068 | import os,io
from sys import stdout
import collections
# import random
import math
from operator import itemgetter
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from collections import Counter
# from decimal import Decimal
# import heapq
# from functools import lru_cache
# import sys
# sys.setrecursionli... | 25 | 1,918 | 44,953,600 | 229815706 | def II():
return(int(input()))
def LMI():
return(list(map(int,input().split())))
def I():
return(input())
def MII():
return(map(int,input().split()))
# import sys
# input=sys.stdin.readline
# import io,os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# from collections import Counter
# i... | Codeforces Beta Round 23 | ICPC | 2,010 | 1.5 | 256 | Oranges and Apples | In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges. | The first input line contains one number T — amount of tests. The description of each test starts with a natural number N — amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi — amount of apples and oranges in the i-th box (0 ≤ ai, oi ≤ 109). The sum of N in all the tests in the input doesn't... | For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers — indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with o... | null | null | [{"input": "2\n2\n10 15\n5 7\n20 18\n1\n0 0", "output": "YES\n1 3\nYES\n1"}] | 2,500 | ["constructive algorithms", "sortings"] | 25 | [{"input": "2\r\n2\r\n10 15\r\n5 7\r\n20 18\r\n1\r\n0 0\r\n", "output": "YES\r\n3 1\r\nYES\r\n1\r\n"}] | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path, 'r') as f_in, open(submission_path, 'r') as f_sub:
input_data = f_in.read().split()
sub_lines = [line.strip() for line in f_sub.readlines()]
ptr = 0
T ... | true |
23/C | 23 | C | Python 3 | TESTS | 1 | 826 | 1,638,400 | 170147767 | t = int(input())
for _ in range(t):
n = int(input())
nums = []
for i in range(2*n-1):
a, b = map(int, input().split())
nums.append([b, a, i+1])
s=set()
nums = sorted(nums)[::-1]
vals = [nums[0][2]]
s.add(nums[0][2])
i = 1
while(i+1 < len(nums)//2):
c = i
... | 25 | 950 | 42,905,600 | 212533744 | from sys import stdin
# read = sys.stdin.readline
T = int(stdin.readline())
for _ in range(T):
N = int(stdin.readline())
M = N + N - 1
data = [ ]
for i in range(M):
data.append([int(w) for w in stdin.readline().split()] + [i + 1])
data.sort(reverse=True)
# print(data)
total = sum(d[1... | Codeforces Beta Round 23 | ICPC | 2,010 | 1.5 | 256 | Oranges and Apples | In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges. | The first input line contains one number T — amount of tests. The description of each test starts with a natural number N — amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi — amount of apples and oranges in the i-th box (0 ≤ ai, oi ≤ 109). The sum of N in all the tests in the input doesn't... | For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers — indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with o... | null | null | [{"input": "2\n2\n10 15\n5 7\n20 18\n1\n0 0", "output": "YES\n1 3\nYES\n1"}] | 2,500 | ["constructive algorithms", "sortings"] | 25 | [{"input": "2\r\n2\r\n10 15\r\n5 7\r\n20 18\r\n1\r\n0 0\r\n", "output": "YES\r\n3 1\r\nYES\r\n1\r\n"}] | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path, 'r') as f_in, open(submission_path, 'r') as f_sub:
input_data = f_in.read().split()
sub_lines = [line.strip() for line in f_sub.readlines()]
ptr = 0
T ... | true |
23/C | 23 | C | Python 3 | TESTS | 1 | 857 | 2,150,400 | 29838881 | #! python3
T = int(input())
while T > 0:
N = int(input())
boxes = []
apples = 0
oranges = 0
for i in range(2*N-1):
boxes.append([int(x) for x in input().strip().split(' ')])
apples += boxes[-1][0]
oranges += boxes[-1][1]
boxes.sort(key=lambda x: x[0])
odd_apples ... | 25 | 1,045 | 29,593,600 | 154131565 | # 解説を見た
# 一見天才だが、「半分以上」を考えるとき、「ソートして隣同士を比較」は定石の一つ。
import sys
input = sys.stdin.readline
from operator import itemgetter
T=int(input())
for tests in range(T):
N=int(input())
X=[]
for i in range(2*N-1):
a,b=map(int,input().split())
X.append((a,b,i+1))
X.sort(key=itemgetter(0))
ANS... | Codeforces Beta Round 23 | ICPC | 2,010 | 1.5 | 256 | Oranges and Apples | In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges. | The first input line contains one number T — amount of tests. The description of each test starts with a natural number N — amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi — amount of apples and oranges in the i-th box (0 ≤ ai, oi ≤ 109). The sum of N in all the tests in the input doesn't... | For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers — indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with o... | null | null | [{"input": "2\n2\n10 15\n5 7\n20 18\n1\n0 0", "output": "YES\n1 3\nYES\n1"}] | 2,500 | ["constructive algorithms", "sortings"] | 25 | [{"input": "2\r\n2\r\n10 15\r\n5 7\r\n20 18\r\n1\r\n0 0\r\n", "output": "YES\r\n3 1\r\nYES\r\n1\r\n"}] | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path, 'r') as f_in, open(submission_path, 'r') as f_sub:
input_data = f_in.read().split()
sub_lines = [line.strip() for line in f_sub.readlines()]
ptr = 0
T ... | true |
612/E | 612 | E | Python 3 | TESTS | 0 | 31 | 0 | 15155208 | n=int(input())
q=list(map(int, input().split()))
p=""
for x in range(n):
if q[x] <= n :
if q[x]!= q[q[x]-1]:
p = p + ' '+ str(q[q[x]-1])
else:
p='-1'
else:
break
print(p.strip()) | 18 | 1,730 | 96,358,400 | 116414526 | import sys
import bisect
from bisect import bisect_left as lb
input_=lambda: sys.stdin.readline().strip("\r\n")
from math import log
from math import gcd
from math import atan2,acos
from random import randint
sa=lambda :input_()
sb=lambda:int(input_())
sc=lambda:input_().split()
sd=lambda:list(map(int,input_().split())... | Educational Codeforces Round 4 | ICPC | 2,015 | 2 | 256 | Square Root of Permutation | A permutation of length n is an array containing each integer from 1 to n exactly once. For example, q = [4, 5, 1, 2, 3] is a permutation. For the permutation q the square of permutation is the permutation p that p[i] = q[q[i]] for each i = 1... n. For example, the square of q = [4, 5, 1, 2, 3] is p = q2 = [2, 3, 4, 5,... | The first line contains integer n (1 ≤ n ≤ 106) — the number of elements in permutation p.
The second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the elements of permutation p. | If there is no permutation q such that q2 = p print the number "-1".
If the answer exists print it. The only line should contain n different integers qi (1 ≤ qi ≤ n) — the elements of the permutation q. If there are several solutions print any of them. | null | null | [{"input": "4\n2 1 4 3", "output": "3 4 2 1"}, {"input": "4\n2 1 3 4", "output": "-1"}, {"input": "5\n2 3 4 5 1", "output": "4 5 1 2 3"}] | 2,200 | ["combinatorics", "constructive algorithms", "dfs and similar", "graphs", "math"] | 18 | [{"input": "4\r\n2 1 4 3\r\n", "output": "3 4 2 1\r\n"}, {"input": "4\r\n2 1 3 4\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 3 4 5 1\r\n", "output": "4 5 1 2 3\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n8 2 10 3 4 6 1 7 9 5\r\n", "output": "-1\r\n"},... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
sub_path = sys.argv[3]
with open(input_path, 'r') as f:
n = int(f.readline())
p = list(map(int, f.readline().split()))
with open(sub_path, 'r') as f:
lines = f.readlines()
sub_output = []
... | true |
613/B | 613 | B | PyPy 3 | TESTS | 0 | 124 | 0 | 91054884 | n,A,cf,cm,mN = map(int,input().split())
a = list(map(int,input().split()))
aCOPY = []
for elem in a:
aCOPY.append(elem)
a.sort()
aPartialSum = [0]
for elem in a:
aPartialSum.append(aPartialSum[-1] + elem)
maxScore = 0
ansMAXIBound = 0
ansMAXI = 0
ansMIN = 0
for MAXI in range(n + 1):
currentScore = cf * ... | 35 | 1,045 | 16,486,400 | 15377652 | import itertools
import bisect
n, A, cf, cm, m = [int(x) for x in input().split()]
skills = [int(x) for x in input().split()]
sorted_skills = list(sorted((k, i) for i, k in enumerate(skills)))
bottom_lift = [0 for i in range(n)]
for i in range(1, n):
bottom_lift[i] = bottom_lift[i-1] + i * (sorted_skills[i][0] - s... | Codeforces Round 339 (Div. 1) | CF | 2,016 | 2 | 256 | Skills | Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai — the current skill level. All skills have the same maximum level A.
Along with... | The first line of the input contains five space-separated integers n, A, cf, cm and m (1 ≤ n ≤ 100 000, 1 ≤ A ≤ 109, 0 ≤ cf, cm ≤ 1000, 0 ≤ m ≤ 1015).
The second line contains exactly n integers ai (0 ≤ ai ≤ A), separated by spaces, — the current levels of skills. | On the first line print the maximum value of the Force that the character can achieve using no more than m currency units.
On the second line print n integers a'i (ai ≤ a'i ≤ A), skill levels which one must achieve in order to reach the specified value of the Force, while using no more than m currency units. Numbers s... | null | In the first test the optimal strategy is to increase the second skill to its maximum, and increase the two others by 1.
In the second test one should increase all skills to maximum. | [{"input": "3 5 10 1 5\n1 3 1", "output": "12\n2 5 2"}, {"input": "3 5 10 1 339\n1 3 1", "output": "35\n5 5 5"}] | 1,900 | ["binary search", "brute force", "dp", "greedy", "sortings", "two pointers"] | 35 | [{"input": "3 5 10 1 5\r\n1 3 1\r\n", "output": "12\r\n2 5 2 \r\n"}, {"input": "3 5 10 1 339\r\n1 3 1\r\n", "output": "35\r\n5 5 5 \r\n"}, {"input": "2 6 0 1 4\r\n5 1\r\n", "output": "5\r\n5 5 \r\n"}, {"input": "1 1000000000 1000 1000 1000000000000000\r\n0\r\n", "output": "1000000001000\r\n1000000000 \r\n"}, {"input": ... | false | stdio | null | true |
893/E | 893 | E | PyPy 3-64 | TESTS | 4 | 1,918 | 14,745,600 | 150336846 | mod = 1e9+7;
from functools import lru_cache
def modexp(a, n):
ans = 1
while (n):
if (n&1):
ans = (ans*a)%mod
a = (a*a)%mod
n = n>>1
return ans
@lru_cache(100000)
def rec(x, y):
if (y==0):
return 0
if (y==1):
return 1
# calculate factors O(sqrt(n))
ans = 0
f1 = 1
while (f1*f1 <= x):
... | 45 | 1,029 | 135,782,400 | 93454490 | import sys
mod = 10**9 + 7
max_n = 10**6 + 100
fac, inv = [1]*max_n, [1]*max_n
for i in range(2, max_n):
fac[i] = fac[i-1] * i % mod
inv[-1] = pow(fac[-1], mod-2, mod)
for i in range(max_n-1, 0, -1):
inv[i-1] = inv[i] * i % mod
def get_primes(n: int):
from itertools import chain
from array import arr... | Educational Codeforces Round 33 (Rated for Div. 2) | ICPC | 2,017 | 3 | 256 | Counting Arrays | You are given two positive integer numbers x and y. An array F is called an y-factorization of x iff the following conditions are met:
- There are y elements in F, and all of them are integer numbers;
- $$\prod_{i=1}^{y} F_i = x$$.
You have to count the number of pairwise distinct arrays that are y-factorizations of ... | The first line contains one integer q (1 ≤ q ≤ 105) — the number of testcases to solve.
Then q lines follow, each containing two integers xi and yi (1 ≤ xi, yi ≤ 106). Each of these lines represents a testcase. | Print q integers. i-th integer has to be equal to the number of yi-factorizations of xi modulo 109 + 7. | null | In the second testcase of the example there are six y-factorizations:
- { - 4, - 1};
- { - 2, - 2};
- { - 1, - 4};
- {1, 4};
- {2, 2};
- {4, 1}. | [{"input": "2\n6 3\n4 2", "output": "36\n6"}] | 2,000 | ["combinatorics", "dp", "math", "number theory"] | 45 | [{"input": "2\r\n6 3\r\n4 2\r\n", "output": "36\r\n6\r\n"}, {"input": "1\r\n524288 1000000\r\n", "output": "645043186\r\n"}, {"input": "1\r\n65536 1000000\r\n", "output": "928522471\r\n"}, {"input": "1\r\n5612 11399\r\n", "output": "215664246\r\n"}] | false | stdio | null | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.