prob_desc_time_limit stringclasses 21
values | prob_desc_sample_outputs stringlengths 5 329 | src_uid stringlengths 32 32 | prob_desc_notes stringlengths 31 2.84k β | prob_desc_description stringlengths 121 3.8k | prob_desc_output_spec stringlengths 17 1.16k β | prob_desc_input_spec stringlengths 38 2.42k β | prob_desc_output_to stringclasses 3
values | prob_desc_input_from stringclasses 3
values | lang stringclasses 5
values | lang_cluster stringclasses 1
value | difficulty int64 -1 3.5k β | file_name stringclasses 111
values | code_uid stringlengths 32 32 | prob_desc_memory_limit stringclasses 11
values | prob_desc_sample_inputs stringlengths 5 802 | exec_outcome stringclasses 1
value | source_code stringlengths 29 58.4k | prob_desc_created_at stringlengths 10 10 | tags listlengths 1 5 | hidden_unit_tests stringclasses 1
value | labels listlengths 8 8 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2 seconds | ["6", "1", "2"] | 69135ef7422b5811ae935a9d00796f88 | NoteIn the first example, these are all the hidden strings and their indice sets: a occurs at $$$(1)$$$, $$$(2)$$$, $$$(3)$$$ b occurs at $$$(4)$$$, $$$(5)$$$ ab occurs at $$$(1,4)$$$, $$$(1,5)$$$, $$$(2,4)$$$, $$$(2,5)$$$, $$$(3,4)$$$, $$$(3,5)$$$ aa occurs at $$$(1,2)$$$, $$$(1,3)$$$, $$$(2,3)$$$ bb occurs at $... | Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside.The text is a string $$$s$$$ of lowercase Latin letters. She considers a string $$$t$$$ as hidden in string $$$s$$$ if $$$t$$$ exists as a subsequence of $$$s$$$ whose i... | Output a single integer Β β the number of occurrences of the secret message. | The first line contains a string $$$s$$$ of lowercase Latin letters ($$$1 \le |s| \le 10^5$$$) β the text that Bessie intercepted. | standard output | standard input | Python 3 | Python | 1,500 | train_004.jsonl | 413da263785f4bed8d2237048d4b798d | 256 megabytes | ["aaabb", "usaco", "lol"] | PASSED | from string import ascii_lowercase
s = input()
lc = {c: 0 for c in ascii_lowercase}
llc = dict()
for c in s:
for v in lc:
if v + c not in llc:
llc[v + c] = lc[v]
else:
llc[v + c] += lc[v]
lc[c] += 1
print(max(*lc.values(), *llc.values()))
| 1581953700 | [
"math",
"strings"
] | [
0,
0,
0,
1,
0,
0,
1,
0
] | |
1 second | ["2\n1 6", "2\n1 4"] | dfd60a02670749c67b0f96df1a0709b9 | NoteIn the first example the first operation turns over skewers $$$1$$$, $$$2$$$ and $$$3$$$, the second operation turns over skewers $$$4$$$, $$$5$$$, $$$6$$$ and $$$7$$$.In the second example it is also correct to turn over skewers $$$2$$$ and $$$5$$$, but turning skewers $$$2$$$ and $$$4$$$, or $$$1$$$ and $$$5$$$ a... | Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simultaneously. There are two states for each skewer: initial and turned over.This time Miroslav laid out $$$n$$$ skewers parallel to each other, and enumerated them with consecutive integers from $$$1$$$ to $$$n$$$ in order... | The first line should contain integer $$$l$$$Β β the minimum number of actions needed by Miroslav to turn over all $$$n$$$ skewers. After than print $$$l$$$ integers from $$$1$$$ to $$$n$$$ denoting the number of the skewer that is to be turned over at the corresponding step. | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 1000$$$, $$$0 \leq k \leq 1000$$$)Β β the number of skewers and the number of skewers from each side that are turned in one step. | standard output | standard input | Python 3 | Python | 1,300 | train_011.jsonl | b26792ff06cfe7f19202ebaf31e030a2 | 512 megabytes | ["7 2", "5 1"] | PASSED | n, k = map(int, input().split())
a = 1000000
af = []
for i in range(k+1):
f = []
for j in range(i+1, n+1, 2*k+1):
f.append(j)
if i+1 > n:
break
if f[-1]+k >= n:
if a > len(f):
a = len(f)
af = f[:]
print(a)
print(*af) | 1536165300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["NO", "YES\n3 5 4 1\n3 5 3 1\n3 5 2 1"] | d2cc50595767485707338a40a6dd9a78 | null | You are organizing a cycling race on the streets of the city. The city contains n junctions, some pairs of them are connected by roads; on each road you can move in any direction. No two roads connect the same pair of intersections, and no road connects the intersection with itself.You want the race to be open to both ... | If it is possible to create the routes, in the first line print "YES". In the next three lines print the descriptions of each of the three routes in the format "l p1 ... pl", where l is the number of intersections in the route, and p1,β...,βpl are their numbers in the order they follow. The routes must meet all the req... | The first line contains two integers n and m (1ββ€βn,βmββ€β2Β·105) β the number of intersections and roads, respectively. The following m lines contain two integers β the numbers of the intersections connected by a road (the intersections are numbered starting with 1). It is guaranteed that each pair of intersections is c... | standard output | standard input | Python 3 | Python | 3,100 | train_003.jsonl | ad966cbdab6b8b1b396fdd957d32e934 | 256 megabytes | ["4 4\n1 2\n2 3\n3 4\n4 1", "5 6\n1 2\n1 3\n1 4\n2 5\n3 5\n4 5"] | PASSED | from typing import List
import sys
n, m = [int(a) for a in input().split(' ')]
adj: List[List[int]] = [[]] + [[] for _ in range(n)]
visited: List[bool] = [False] * (n + 1)
parent: List[int] = [0] * (n + 1)
depth: List[int] = [0] * (n + 1)
low: List[int] = [0] * (n + 1)
cx: List[int] = [0] * (n + 1)
cy: List[int] = [... | 1425279600 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["3\n-1\n9"] | 6551be8f4000da2288bf835169662aa2 | null | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you... | Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. | The first line contains two integers a and b, the two integers as described above (1ββ€βa,βbββ€β109). The second line contains one integer n, the number of queries (1ββ€βnββ€β104). Then n lines follow, each line contains one query consisting of two integers, low and high (1ββ€βlowββ€βhighββ€β109). | standard output | standard input | Python 3 | Python | 1,600 | train_017.jsonl | ead01fbc1a1435a906d5b382815e5ef0 | 256 megabytes | ["9 27\n3\n1 5\n10 11\n9 11"] | PASSED | a, b = map(int, input().split())
import math
g = math.gcd(a, b)
lis = [i for i in range(1, int(math.sqrt(g)) + 1) if g%i == 0]
for i in lis[::-1]: lis.append(g//i)
n = int(input())
for _ in range(n):
a, b = map(int , input().split())
import bisect
x = bisect.bisect(lis, b) - 1
if lis[x] < a: print(-1)
... | 1302706800 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["4\nNNYY\nNNYY\nYYNN\nYYNN", "8\nNNYYYNNN\nNNNNNYYY\nYNNNNYYY\nYNNNNYYY\nYNNNNYYY\nNYYYYNNN\nNYYYYNNN\nNYYYYNNN", "2\nNY\nYN"] | 30a8d761d5b5103a5b926290634c8fbe | NoteIn first example, there are 2 shortest paths: 1-3-2 and 1-4-2.In second example, there are 9 shortest paths: 1-3-6-2, 1-3-7-2, 1-3-8-2, 1-4-6-2, 1-4-7-2, 1-4-8-2, 1-5-6-2, 1-5-7-2, 1-5-8-2. | Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2."Same with some writers, she wants to make an example with some certain output: ... | You should output a graph G with n vertexes (2ββ€βnββ€β1000). There must be exactly k shortest paths between vertex 1 and vertex 2 of the graph. The first line must contain an integer n. Then adjacency matrix G with n rows and n columns must follow. Each element of the matrix must be 'N' or 'Y'. If Gij is 'Y', then graph... | The first line contains a single integer k (1ββ€βkββ€β109). | standard output | standard input | Python 3 | Python | 1,900 | train_001.jsonl | bfa23404a37efcb9776920588ae7d692 | 256 megabytes | ["2", "9", "1"] | PASSED | k = int(input())
edges = [['N' for i in range(1010)] for j in range(1010)]
vertices = 2
def add_edge(a, b):
global edges
edges[a][b] = edges[b][a] = 'Y'
for i in range(1, 29 + 1):
vertices += 3
add_edge(i * 3, i * 3 - 1)
add_edge(i * 3, i * 3 + 2)
add_edge(i * 3 + 1, i * 3 - 1)
add_edge... | 1391442000 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
1 second | ["2 3 2 3 3", "3 3 3 3 3"] | 59154ca15716f0c1c91a37d34c5bbf1d | null | Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.After the contest was over, Valera wa... | Print exactly n integers a1,βa2,β...,βan β the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order. | The first line of the input contains exactly six integers n,βk,βl,βr,βsall,βsk (1ββ€βn,βk,βl,βrββ€β1000; lββ€βr; kββ€βn; 1ββ€βskββ€βsallββ€β106). It's guaranteed that the input is such that the answer exists. | standard output | standard input | Python 2 | Python | 1,400 | train_028.jsonl | a5c13a7a7b0f9cbcabb58aa0b6151e77 | 256 megabytes | ["5 3 1 3 13 9", "5 3 1 3 15 9"] | PASSED | n,k,l,r,sa,sk=map(int,raw_input().split())
ar=[]
for i in xrange(n):
ar.append(0)
while sk>0:
i=0
while i<k:
if sk>0:
ar[i]+=1
sk-=1
i+=1
else:
break
sa-=sum(ar)
while sa>0:
i=k
while i<n:
if sa>0:
ar[i]+=1
... | 1385739000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3 4 2 1", "-1", "4 5 1 2 3"] | f52a4f8c4d84733a8e78a5825b63bdbc | null | 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,... | 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. | 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. | standard output | standard input | PyPy 2 | Python | 2,200 | train_078.jsonl | f72311f55a7ddb13537aedb87076082f | 256 megabytes | ["4\n2 1 4 3", "4\n2 1 3 4", "5\n2 3 4 5 1"] | PASSED | from __future__ import division
from collections import defaultdict
import random
#import numpy as np
def get_cycle(perm, i):
start = i
current = i
res = [i]
while True:
new = perm[current]
perm[current] = -1
current = new
if current == start:
return res
... | 1451055600 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
2 seconds | ["6\n2"] | ca3e121e8c8afe97b5cfdc9027892f00 | null | Think of New York as a rectangular grid consisting of N vertical avenues numerated from 1 to N and M horizontal streets numerated 1 to M. C friends are staying at C hotels located at some street-avenue crossings. They are going to celebrate birthday of one of them in the one of H restaurants also located at some street... | In the first line output the optimal distance. In the next line output index of a restaurant that produces this optimal distance. If there are several possibilities, you are allowed to output any of them. | The first line contains two integers N ΠΈ MΒ β size of the city (1ββ€βN,βMββ€β109). In the next line there is a single integer C (1ββ€βCββ€β105)Β β the number of hotels friends stayed at. Following C lines contain descriptions of hotels, each consisting of two coordinates x and y (1ββ€βxββ€βN, 1ββ€βyββ€βM). The next line contains... | standard output | standard input | Python 3 | Python | 2,100 | train_034.jsonl | dfb537ef9894eac3b9ad4f9e86d10fea | 256 megabytes | ["10 10\n2\n1 1\n3 3\n2\n1 10\n4 4"] | PASSED | #!/usr/bin/env python3
n, m = map(int, input().split())
minx = miny = n + m
maxx = maxy = - minx
dist = n + m + 1
c = int(input())
for _ in range(c):
x, y = map(int, input().split())
minx = min(minx, x - y)
miny = min(miny, x + y)
maxx = max(maxx, x - y)
maxy = max(maxy, x + y)
h = int(input())
f... | 1416519000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["NO\nYES\nYES\nYES"] | 07e56d4031bcb119d2f684203f7ed133 | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the... | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | standard output | standard input | Python 3 | Python | 800 | train_005.jsonl | 4e9dad38db6f85449065e8d54f5e4a9f | 256 megabytes | ["4\n3\n4\n12\n1000000000"] | PASSED | t=int(input())
for _ in range(t):
n=int(input())
if(n%4==0):
print("YES")
else:
print("NO")
| 1592921100 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2", "3"] | 81c6342b7229892d71cb43e72aee99e9 | NoteIn the first sample, sequence of rooms Petya visited could be, for example 1βββ1βββ2, 1βββ2βββ1 or 1βββ2βββ3. The minimum possible number of rooms is 2.In the second sample, the sequence could be 1βββ2βββ3βββ1βββ2βββ1. | A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages ar... | In the only line print a single integer β the minimum possible number of rooms in Paris catacombs. | The first line contains a single integer n (1ββ€βnββ€β2Β·105) β then number of notes in Petya's logbook. The second line contains n non-negative integers t1,βt2,β...,βtn (0ββ€βtiβ<βi) β notes in the logbook. | standard output | standard input | Python 3 | Python | 1,300 | train_009.jsonl | 8a240df0e19516399ffaea7bd416a35a | 256 megabytes | ["2\n0 0", "5\n0 1 0 1 3"] | PASSED | n, data = int(input()), list(map(int, input().split()))
time = [0] + [-100] * (3 * (10 ** 5))
rooms = [0]
for i in range(1, n + 1):
if(time[data[i - 1]] != -100 and rooms[time[data[i - 1]]] == data[i - 1]):
rooms[time[data[i - 1]]] = i
time[i] = time[data[i - 1]]
else:
rooms.append(i)
... | 1510502700 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["1", "3", "1"] | 31014efa929af5e4b7d9987bd9b59918 | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_... | Print one integer β the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) β the number of vertices in a plot of a piecewise function and the area we need to obtain. | standard output | standard input | Python 3 | Python | 1,000 | train_003.jsonl | 38627e93f16ce65a70706e7068032689 | 256 megabytes | ["4 3", "4 12", "999999999999999999 999999999999999986"] | PASSED | import math
n,k = list(map(int, input().split(' ')))
print(-(-k//n))
# if k<= n:
# print(1)
# else:
# if k%n:
# print(int(math.ceil(k/n)))
# else:
# print(int(k/n))
| 1536330900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["5.000000000000000", "0.400000000000000"] | 131db180c7afad3e5a3342407408fded | NoteFirst sample corresponds to the example in the problem statement. | Mikhail the Freelancer dreams of two things: to become a cool programmer and to buy a flat in Moscow. To become a cool programmer, he needs at least p experience points, and a desired flat in Moscow costs q dollars. Mikhail is determined to follow his dreams and registered at a freelance site.He has suggestions to work... | Print a real valueΒ β the minimum number of days Mikhail needs to get the required amount of experience and money. Your answer will be considered correct if its absolute or relative error does not exceed 10β-β6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consid... | The first line of the input contains three integers n, p and q (1ββ€βnββ€β100β000,β1ββ€βp,βqββ€β1β000β000)Β β the number of projects and the required number of experience and money. Each of the next n lines contains two integers ai and bi (1ββ€βai,βbiββ€β1β000β000)Β β the daily increase in experience and daily income for worki... | standard output | standard input | Python 3 | Python | 2,400 | train_017.jsonl | 82cbd58de2571d6eaed6c581386168df | 256 megabytes | ["3 20 20\n6 2\n1 3\n2 6", "4 1 1\n2 3\n3 2\n2 3\n3 2"] | PASSED | def get_bounds(points):
if len(points) == 1:
return points[:]
points.sort()
bounds = [points[0], points[1]]
for xi, yi in points[2:]:
while len(bounds) > 1 and not is_convex(bounds, xi, yi):
del bounds[-1]
bounds.append((xi, yi))
return bounds
def is_convex(boun... | 1449677100 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["123+45=168", "0+9=9", "1+99=100", "123123123+456456456=579579579"] | ae34b6eda34df321a16e272125fb247b | null | A correct expression of the form a+b=c was written; a, b and c are non-negative integers without leading zeros. In this expression, the plus and equally signs were lost. The task is to restore the expression. In other words, one character '+' and one character '=' should be inserted into given sequence of digits so tha... | Output the restored expression. If there are several solutions, you can print any of them. Note that the answer at first should contain two terms (divided with symbol '+'), and then the result of their addition, before which symbol'=' should be. Do not separate numbers and operation signs with spaces. Strictly follow ... | The first line contains a non-empty string consisting of digits. The length of the string does not exceed 106. | standard output | standard input | Python 2 | Python | 2,300 | train_055.jsonl | 96493dc2da88fd0c81271d4cfa4e568a | 256 megabytes | ["12345168", "099", "199100", "123123123456456456579579579"] | PASSED | def pp(a, b, c):
t = map(str, a) + ['+'] + map(str, b) + ['='] + map(str, c)
print ''.join(t)
def go(s, a, b, i):
if i != 1 and s[-i] == 0:
return 0
if a != 1 and s[0] == 0:
return 0
if b != 1 and s[a] == 0:
return 0
if max(a, b) < i:
if not a == b and not (a == i... | 1513424100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["Stannis", "Daenerys", "Stannis"] | 67e51db4d96b9f7996aea73cbdba3584 | NoteIn the first sample Stannis will use his move to burn a city with two people and Daenerys will be forced to burn a city with one resident. The only survivor city will have one resident left, that is, the total sum is odd, and thus Stannis wins.In the second sample, if Stannis burns a city with two people, Daenerys ... | There are n cities in Westeros. The i-th city is inhabited by ai people. Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it to the ground. Thus all its residents, sadly, die. Stannis starts the game. The game ends when Westeros has exactly k cities left.The pr... | Print string "Daenerys" (without the quotes), if Daenerys wins and "Stannis" (without the quotes), if Stannis wins. | The first line contains two positive space-separated integers, n and k (1ββ€βkββ€βnββ€β2Β·105) β the initial number of cities in Westeros and the number of cities at which the game ends. The second line contains n space-separated positive integers ai (1ββ€βaiββ€β106), which represent the population of each city in Westeros. | standard output | standard input | Python 3 | Python | 2,200 | train_001.jsonl | 59600dd7f5b1b008b40f64abe03c7848 | 256 megabytes | ["3 1\n1 2 1", "3 1\n2 2 1", "6 3\n5 20 12 7 14 101"] | PASSED | import math,string,itertools,fractions,heapq,collections,re,array,bisect
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict, deque
def VI(): return list(map(int,input().split()))
def main(n,k,a):
now = sum(a)
even = sum([x%2==0 for x in a])
odd = sum([x%... | 1433595600 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["4\n6", "117\n665496274\n332748143\n831870317\n499122211"] | 1461fca52a0310fff725b476bfbd3b29 | NoteIn the first test after the first query, the first and the second mirrors are checkpoints. Creatnx will ask the first mirror until it will say that he is beautiful, after that he will ask the second mirror until it will say that he is beautiful because the second mirror is a checkpoint. After that, he will become h... | Creatnx has $$$n$$$ mirrors, numbered from $$$1$$$ to $$$n$$$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $$$i$$$-th mirror will tell Creatnx that he is beautiful with probability $$$\frac{p_i}{100}$$$ for all $$$1 \le i \le n$$$.Some mirrors are called checkpoints. Initially, only the $$$1$$$st ... | Print $$$q$$$ numbersΒ β the answers after each query by modulo $$$998244353$$$. | The first line contains two integers $$$n$$$, $$$q$$$ ($$$2 \leq n, q \le 2 \cdot 10^5$$$) Β β the number of mirrors and queries. The second line contains $$$n$$$ integers: $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \leq p_i \leq 100$$$). Each of $$$q$$$ following lines contains a single integer $$$u$$$ ($$$2 \leq u \leq n$$$)Β β... | standard output | standard input | PyPy 2 | Python | 2,400 | train_082.jsonl | 37af9be9e83ba129e959a7f854eb2aac | 256 megabytes | ["2 2\n50 50\n2\n2", "5 5\n10 20 30 40 50\n2\n3\n4\n5\n3"] | PASSED | from __future__ import division, print_function
def main():
n, qs = input_as_list()
cpn = ceil_power_of_2(n)
st = array_of(int, n+1)
switch = array_of(bool, n)
def update(i, v):
while i < n:
st[i] += v
i |= i+1
def query(i):
res = 0
while i > 0:... | 1575556500 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | efa201456f8703fcdc29230248d91c54 | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Happy new year! The year 2020 is also known as Year Gyeongja (κ²½μλ
, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t... | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$... | standard output | standard input | PyPy 3 | Python | 800 | train_005.jsonl | b3e21ba6b197b11a6ab8a84e6ac9fed0 | 1024 megabytes | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | PASSED | n,m=map(int,input().split())
S=list(map(str,input().split()))
T=list(map(str,input().split()))
q=int(input())
for i in range (q):
y=int(input())
print(S[(y%n)-1]+T[(y%m)-1]) | 1578139500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["0\n1\n0"] | 5bffe38e3ac9511a30ee02b4ec5cb1d5 | NoteNote that after applying a few operations, the values of $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ may become negative.In the first test case, $$$4$$$ is already the Arithmetic Mean of $$$3$$$ and $$$5$$$.$$$d(3, 4, 5) = |3 + 5 - 2 \cdot 4| = 0$$$In the second test case, we can apply the following operation:$$$(2, 2, 6)$$... | A number $$$a_2$$$ is said to be the arithmetic mean of two numbers $$$a_1$$$ and $$$a_3$$$, if the following condition holds: $$$a_1 + a_3 = 2\cdot a_2$$$. We define an arithmetic mean deviation of three numbers $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ as follows: $$$d(a_1, a_2, a_3) = |a_1 + a_3 - 2 \cdot a_2|$$$.Arithmeti... | For each test case, output the minimum value of $$$d(a_1, a_2, a_3)$$$ that can be obtained after applying the operation any number of times. | The first line contains a single integer $$$t$$$ $$$(1 \le t \le 5000)$$$ Β β the number of test cases. The first and only line of each test case contains three integers $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ $$$(1 \le a_1, a_2, a_3 \le 10^{8})$$$. | standard output | standard input | PyPy 3-64 | Python | 800 | train_097.jsonl | 6976109a28fc64a00f32a33fc4c8bc9d | 256 megabytes | ["3\n3 4 5\n2 2 6\n1 6 5"] | PASSED | for x in range(int(input())):
a,b,c=sorted([int(x) for x in input().split()])
a1=abs(2*b-a-c)//3
a2=a1+1
print (min(abs(a-a1+c-2*(b+a1)) ,abs( a+a1+c-2*(b-a1)) , abs(a-a2+c-2*(b+a2)) ,abs( a+a2+c-2*(b-a2)) )) | 1636727700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["NO\nYES\nNO\nYES"] | 7cf9bb97385ee3a5b5e28f66eab163d0 | null | You are given two strings $$$s$$$ and $$$t$$$ both of length $$$n$$$ and both consisting of lowercase Latin letters.In one move, you can choose any length $$$len$$$ from $$$1$$$ to $$$n$$$ and perform the following operation: Choose any contiguous substring of the string $$$s$$$ of length $$$len$$$ and reverse it; a... | For each test case, print the answer on it β "YES" (without quotes) if it is possible to make strings $$$s$$$ and $$$t$$$ equal after some (possibly, empty) sequence of moves and "NO" otherwise. | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) β the number of test cases. Then $$$q$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of $$$s$$$ and $$$t$$$. The second line of the test case contains one s... | standard output | standard input | Python 3 | Python | 2,000 | train_002.jsonl | 41c9d60c3785ddba35355952b2a32df9 | 256 megabytes | ["4\n4\nabcd\nabdc\n5\nababa\nbaaba\n4\nasdf\nasdg\n4\nabcd\nbadc"] | PASSED | for _ in range(int(input())):
n = int(input())
s1, s2 = input(), input()
a1, a2 = [0]*26, [0]*26
for v in map(ord, s1):
a1[v-97] += 1
for v in map(ord, s2):
a2[v-97] += 1
if a1 != a2:
print('NO')
continue
if max(a1) > 1:
print('YES')
conti... | 1572873300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["YES\n112323", "NO"] | 52c634955e1d78971d94098ba1c667d9 | null | You are given an undirected graph without self-loops or multiple edges which consists of $$$n$$$ vertices and $$$m$$$ edges. Also you are given three integers $$$n_1$$$, $$$n_2$$$ and $$$n_3$$$.Can you label each vertex with one of three numbers 1, 2 or 3 in such way, that: Each vertex should be labeled by exactly on... | If valid labeling exists then print "YES" (without quotes) in the first line. In the second line print string of length $$$n$$$ consisting of 1, 2 and 3. The $$$i$$$-th letter should be equal to the label of the $$$i$$$-th vertex. If there is no valid labeling, print "NO" (without quotes). | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 5000$$$; $$$0 \le m \le 10^5$$$)Β β the number of vertices and edges in the graph. The second line contains three integers $$$n_1$$$, $$$n_2$$$ and $$$n_3$$$ ($$$0 \le n_1, n_2, n_3 \le n$$$)Β β the number of labels 1, 2 and 3, respectively. It's gu... | standard output | standard input | Python 3 | Python | 2,100 | train_007.jsonl | 0c6a800ffc85cbd29fb4b9e7e7581907 | 256 megabytes | ["6 3\n2 2 2\n3 1\n5 4\n2 5", "5 9\n0 2 3\n1 2\n1 3\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5"] | PASSED | import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
def solve():
n, m = nm()... | 1589707200 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["8\n4\n0\n2\n1\n5"] | 8e9ba5a2472984cd14b99790a157acd5 | NoteThe first test case is analyzed in the statement.In the second test case, you can get a total value equal to $$$4$$$ if you put the first and second goods in the first package and the third and fourth goods in the second package.In the third test case, the cost of each item is $$$0$$$, so the total cost will also b... | A batch of $$$n$$$ goods ($$$n$$$Β β an even number) is brought to the store, $$$i$$$-th of which has weight $$$a_i$$$. Before selling the goods, they must be packed into packages. After packing, the following will be done: There will be $$$\frac{n}{2}$$$ packages, each package contains exactly two goods; The weight ... | For each test case, print on a separate line a single number β the maximum possible total cost of all the packages. | The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β βthe number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains two integers $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) and $$$k$$$ ($$$1 \le k \le 1000$$$). The number $$$n$$$Β β is e... | standard output | standard input | PyPy 3-64 | Python | 1,500 | train_094.jsonl | 0155778ceea34bdfebd53f38bfaa6e85 | 256 megabytes | ["6\n\n6 3\n\n3 2 7 1 4 8\n\n4 3\n\n2 1 5 6\n\n4 12\n\n0 0 0 0\n\n2 1\n\n1 1\n\n6 10\n\n2 0 0 5 9 4\n\n6 5\n\n5 3 8 6 3 2"] | PASSED | t = int(input())
for z in range(t):
n, k = map(int,input().split())
arr = list(map(int,input().split()))
count = 0
for i in range(len(arr)):
count += arr[i]//k
arr[i] = arr[i]%k
# ΡΠ·Π½Π°Π»ΠΈ ΡΠΊΠΎΠ»ΡΠΊΠΎ ΡΠ΅Π»ΡΡ
k Π±ΡΠ΄Π΅Ρ Π² ΠΊΠ°ΠΆΠ΄ΠΎΠΌ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠ΅
# ΡΠΎΠ·Π΄Π°Π»ΠΈ ΠΌΠ°ΡΡΠΈΠ² ΠΎΡΡΠ°ΡΠΊΠΎΠ²
# ΠΊΠ°ΠΆΠ΄ΡΠΉ ΠΎΡΡΠ°ΡΠΎΠΊ ΠΏΠΎ ΠΎΠ΄ΠΈΠ½ΠΎ... | 1654612500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2 5\n3 1\n0 0"] | f7defb09175c842de490aa13a4f5a0c9 | null | You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$... | If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of in... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$). | standard output | standard input | PyPy 3-64 | Python | 800 | train_107.jsonl | c5a164d64b2dea2beee239ea8cddd782 | 512 megabytes | ["3\n\n3 75\n\n100 100\n\n42 13"] | PASSED | t = int(input())
for _ in range(t):
x, y = map(int, input().split())
if y % x != 0:
print(0, 0)
else:
print(1, y//x)
| 1651502100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\n3 1 2 3\n3 1 2 3", "6\n3 5 4 2\n3 3 1 5\n4 4 5 2 3\n4 4 3 2 1\n3 4 2 1\n3 3 1 5"] | 1a4907c76ecd935ca345570e54bc5c31 | null | In order to fly to the Moon Mister B just needs to solve the following problem.There is a complete indirected graph with n vertices. You need to cover it with several simple cycles of length 3 and 4 so that each edge is in exactly 2 cycles.We are sure that Mister B will solve the problem soon and will fly to the Moon. ... | If there is no answer, print -1. Otherwise, in the first line print k (1ββ€βkββ€βn2)Β β the number of cycles in your solution. In each of the next k lines print description of one cycle in the following format: first print integer m (3ββ€βmββ€β4)Β β the length of the cycle, then print m integers v1,βv2,β...,βvm (1ββ€βviββ€βn)Β ... | The only line contains single integer n (3ββ€βnββ€β300). | standard output | standard input | Python 2 | Python | 2,800 | train_034.jsonl | 27acfa7a1e3726a7e146abd22f453908 | 256 megabytes | ["3", "5"] | PASSED | def f(n):
if n == 3:
return [[1, 2, 3], [1, 2, 3]]
elif n % 2 == 1:
a = f(n - 2)
for i in xrange(1, n - 2, 2):
a.append([i, n, i + 1, n - 1])
a.append([i, n, i + 1, n - 1])
a.append([n, n - 1, n - 2])
a.append([n, n - 1, n - 2])
return a
... | 1498574100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
4 seconds | ["3 4 2", "199999", "6"] | 07484b6a6915c5cb5fdf1921355f2a6a | null | Authors guessed an array $$$a$$$ consisting of $$$n$$$ integers; each integer is not less than $$$2$$$ and not greater than $$$2 \cdot 10^5$$$. You don't know the array $$$a$$$, but you know the array $$$b$$$ which is formed from it with the following sequence of operations: Firstly, let the array $$$b$$$ be equal to ... | In the only line of the output print $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$2 \le a_i \le 2 \cdot 10^5$$$) in any order β the array $$$a$$$ from which the array $$$b$$$ can be obtained using the sequence of moves given in the problem statement. If there are multiple answers, you can print any. | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the number of elements in $$$a$$$. The second line of the input contains $$$2n$$$ integers $$$b_1, b_2, \dots, b_{2n}$$$ ($$$2 \le b_i \le 2750131$$$), where $$$b_i$$$ is the $$$i$$$-th element of $$$b$$$. $$$2750131$$$ is the $... | standard output | standard input | Python 3 | Python | 1,800 | train_006.jsonl | d0979b3daabd5b6984d7e79732d1052c | 256 megabytes | ["3\n3 5 2 3 2 4", "1\n2750131 199999", "1\n3 6"] | PASSED | import collections,math
n=int(input())
a=list(map(int, input().split()))
a.sort(reverse=True)
primes_arr=[-1]
maxi = 2750131+1
primes_sieve=[0 for _ in range(maxi)]
def sieve():
for i in range(2, maxi):
if not primes_sieve[i]:
primes_arr.append(i)
primes_sieve[i] = 1
for... | 1560090900 | [
"number theory",
"graphs"
] | [
0,
0,
1,
0,
1,
0,
0,
0
] | |
2 seconds | ["0 0\n3 0\n0 3\n1 1", "-1", "10 0\n-10 0\n10 1\n9 1\n9 -1\n0 -2", "176166 6377\n709276 539564\n654734 174109\n910147 434207\n790497 366519\n606663 21061\n859328 886001"] | 2e9f2bd3c02ba6ba41882334deb35631 | null | Convexity of a set of points on the plane is the size of the largest subset of points that form a convex polygon. Your task is to build a set of n points with the convexity of exactly m. Your set of points should not contain three points that lie on a straight line. | If there is no solution, print "-1". Otherwise, print n pairs of integers β the coordinates of points of any set with the convexity of m. The coordinates shouldn't exceed 108 in their absolute value. | The single line contains two integers n and m (3ββ€βmββ€β100,βmββ€βnββ€β2m). | standard output | standard input | Python 2 | Python | 2,300 | train_062.jsonl | 32333ceef06116e55c5c581010be1c51 | 256 megabytes | ["4 3", "6 3", "6 6", "7 4"] | PASSED | n, m = map( int, raw_input().split() )
if( ( m == 3 ) and ( n >= 5 ) ):
print -1
else:
for i in xrange( m ):
print i, ( i * i )
for i in xrange( n - m ):
print ( i * i + 12345 ), i
| 1362065400 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["3", "1", "0"] | bc532d5c9845940b5f59485394187bf6 | NoteIn the first example, one possible way to unlock $$$3$$$ chests is as follows: Use first key to unlock the fifth chest, Use third key to unlock the second chest, Use fourth key to unlock the first chest. In the second example, you can use the only key to unlock any single chest (note that one key can't be used t... | On a random day, Neko found $$$n$$$ treasure chests and $$$m$$$ keys. The $$$i$$$-th chest has an integer $$$a_i$$$ written on it and the $$$j$$$-th key has an integer $$$b_j$$$ on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open as many treasure chests as possible.The $... | Print the maximum number of chests you can open. | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^5$$$)Β β the number of chests and the number of keys. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$)Β β the numbers written on the treasure chests. The third line contains $$$m$$$ integers $$$b... | standard output | standard input | Python 3 | Python | 800 | train_005.jsonl | 536d3cf8a7725e9c3f39675a99211f67 | 256 megabytes | ["5 4\n9 14 6 2 11\n8 4 7 20", "5 1\n2 4 6 8 10\n5", "1 4\n10\n20 30 40 50"] | PASSED | n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ae=0
ao=0
be=0
bo=0
for ele in a:
if ele%2:
ao+=1
else:
ae+=1
for i in b:
if i%2:
bo+=1
else:
be+=1
print(min(ao,be)+min(ae,bo))
| 1556116500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["2 2 6 6 0", "1 2 11 20 15 10 5 0"] | 40a2d69987359fc83a9c3e5eff52ce34 | null | This is the easy version of the problem. The only difference between easy and hard versions is the constraint of $$$m$$$. You can make hacks only if both versions are solved.Chiori loves dolls and now she is going to decorate her bedroom!Β As a doll collector, Chiori has got $$$n$$$ dolls. The $$$i$$$-th doll has a non-... | Print $$$m+1$$$ integers $$$p_0, p_1, \ldots, p_m$$$ Β β $$$p_i$$$ is equal to the number of picking ways with value $$$i$$$ by modulo $$$998\,244\,353$$$. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 35$$$) Β β the number of dolls and the maximum value of the picking way. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i < 2^m$$$) Β β the values of dolls. | standard output | standard input | PyPy 3 | Python | 2,700 | train_072.jsonl | fe093b357f67a7d61068e7b425fd9f98 | 512 megabytes | ["4 4\n3 5 8 14", "6 7\n11 45 14 9 19 81"] | PASSED | MOD = 998244353
BOUND = 19
n, m = map(int, input().split())
l = list(map(int,input().split()))
basis = []
for p in range(m-1,-1,-1):
p2 = pow(2,p)
nex = -1
for i in range(n):
if l[i] >= p2:
nex = l[i]
break
if nex != -1:
basis.append(nex)
for i in rang... | 1586961300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["4 7 3 5 3", "2 6 4 5 8 8 6"] | c51e15aeb3f287608a26b85865546e85 | null | Leha like all kinds of strange things. Recently he liked the function F(n,βk). Consider all possible k-element subsets of the set [1,β2,β...,βn]. For subset find minimal element in it. F(n,βk) β mathematical expectation of the minimal element among all k-element subsets.But only function does not interest him. He wants... | Output m integers a'1,βa'2,β...,βa'm β array A' which is permutation of the array A. | First line of input data contains single integer m (1ββ€βmββ€β2Β·105) β length of arrays A and B. Next line contains m integers a1,βa2,β...,βam (1ββ€βaiββ€β109) β array A. Next line contains m integers b1,βb2,β...,βbm (1ββ€βbiββ€β109) β array B. | standard output | standard input | Python 3 | Python | 1,300 | train_017.jsonl | 8c464fa54ce1bc101b8be289968ad171 | 256 megabytes | ["5\n7 3 5 3 4\n2 1 3 2 3", "7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2"] | PASSED | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
bb = list(enumerate(b))
bb = sorted(bb, key = lambda x:x[1])
#print (bb)
a.sort(reverse=True)
c = [0] * n
for i in range(n):
#print (bb[i][0])
c[bb[i][0]] = a[i]
print (*c) | 1503068700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["1\n0\n1337"] | dc67dd2102c70ea476df642b863ae8d3 | NoteThere is only one suitable pair in the first test case: $$$a = 1$$$, $$$b = 9$$$ ($$$1 + 9 + 1 \cdot 9 = 19$$$). | You are given two integers $$$A$$$ and $$$B$$$, calculate the number of pairs $$$(a, b)$$$ such that $$$1 \le a \le A$$$, $$$1 \le b \le B$$$, and the equation $$$a \cdot b + a + b = conc(a, b)$$$ is true; $$$conc(a, b)$$$ is the concatenation of $$$a$$$ and $$$b$$$ (for example, $$$conc(12, 23) = 1223$$$, $$$conc(100,... | Print one integer β the number of pairs $$$(a, b)$$$ such that $$$1 \le a \le A$$$, $$$1 \le b \le B$$$, and the equation $$$a \cdot b + a + b = conc(a, b)$$$ is true. | The first line contains $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case contains two integers $$$A$$$ and $$$B$$$ $$$(1 \le A, B \le 10^9)$$$. | standard output | standard input | Python 3 | Python | 1,100 | train_023.jsonl | ea215df988ca773d780e59bf8f6efab1 | 256 megabytes | ["3\n\n1 11\n\n4 2\n\n191 31415926"] | PASSED | from math import ceil
def ii():return int(input())
def mi():return map(int,input().split())
def li():return list(mi())
def si():return input()
t=ii()
while(t):
t-=1
a,b=mi()
x=9
c=0
while(b>=x):
c+=1
x=x*10+9
print(a*c) | 1579012500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["ckpuv\naababab\nzzzzzz"] | 80fd03a1cbdef86a5f00ada85e026890 | NoteA string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds: $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$; in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter... | Prefix function of string $$$t = t_1 t_2 \ldots t_n$$$ and position $$$i$$$ in it is defined as the length $$$k$$$ of the longest proper (not equal to the whole substring) prefix of substring $$$t_1 t_2 \ldots t_i$$$ which is also a suffix of the same substring.For example, for string $$$t = $$$ abacaba the values of t... | For each test case print a single string $$$t$$$. The multisets of letters in strings $$$s$$$ and $$$t$$$ must be equal. The value of $$$f(t)$$$, the maximum of prefix functions in string $$$t$$$, must be as small as possible. String $$$t$$$ must be the lexicographically smallest string out of all strings satisfying th... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). Description of the test cases follows. The only line of each test case contains string $$$s$$$ ($$$1 \le |s| \le 10^5$$$) consisting of lowercase English letters. It is guaranteed that the sum of l... | standard output | standard input | PyPy 3-64 | Python | 2,100 | train_105.jsonl | 4bdd501ed70881341216ac6f0f1b69cf | 512 megabytes | ["3\nvkcup\nabababa\nzzzzzz"] | PASSED | import sys
input = sys.stdin.readline
inf = float('inf')
def getInt():
return int(input())
def getStr():
return input().strip()
def getList(split=True):
s = getStr()
if split:
s = s.split()
return map(int, s)
t = getInt()
# t = 1
# observations, the maximum number of Good Assignmen... | 1626532500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["0\n10\n-1\n0\n-1\n21\n0\n273000"] | 3035265a44fcc3bb6317bf1b9662fc76 | NoteFor the first testcase, $$$B=\{-3,-2,-1,0,1,2,3\}$$$ and $$$C=\{-1,1,3,5\}$$$. There is no such arithmetic progression which can be equal to $$$A$$$ because $$$5$$$ is not present in $$$B$$$ and for any $$$A$$$, $$$5$$$ should not be present in $$$C$$$ also. For the second testcase, $$$B=\{-9,-6,-3,0,3,6,9,12,15,18... | Long ago, you thought of two finite arithmetic progressions $$$A$$$ and $$$B$$$. Then you found out another sequence $$$C$$$ containing all elements common to both $$$A$$$ and $$$B$$$. It is not hard to see that $$$C$$$ is also a finite arithmetic progression. After many years, you forgot what $$$A$$$ was but remember ... | For each testcase, print a single line containing a single integer. If there are infinitely many finite arithmetic progressions which could be your lost progression $$$A$$$, print $$$-1$$$. Otherwise, print the number of finite arithmetic progressions which could be your lost progression $$$A$$$ modulo $$$10^9+7$$$. In... | The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 100$$$) denoting the number of testcases. The first line of each testcase contains three integers $$$b$$$, $$$q$$$ and $$$y$$$ ($$$-10^9\leq b\leq 10^9$$$, $$$1\leq q\leq 10^9$$$, $$$2\leq y\leq 10^9$$$) denoting the first term, common difference... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_096.jsonl | ef8202a9f9096c5fd19ef569e12d4c17 | 256 megabytes | ["8\n\n-3 1 7\n\n-1 2 4\n\n-9 3 11\n\n0 6 3\n\n2 5 5\n\n7 5 4\n\n2 2 11\n\n10 5 3\n\n0 2 9\n\n2 4 3\n\n-11 4 12\n\n1 12 2\n\n-27 4 7\n\n-17 8 2\n\n-8400 420 1000000000\n\n0 4620 10"] | PASSED | import sys
ipt=sys.stdin.readline
def sq(x):
st=0
en=10**10
while st<en:
y=(st+en)//2+1
if y**2>x:
en=y-1
else:
st=y
return st
def gcd(xx, yy):
return xx if yy==0 else gcd(yy, xx%yy)
mod=10**9+7
T=int(ipt())
for _ in range(T):
... | 1651329300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["1\n2\n3\n3\n5\n4"] | 0eee4b8f074e02311329d5728138c7fe | null | $$$2^k$$$ teams participate in a playoff tournament. The tournament consists of $$$2^k - 1$$$ games. They are held as follows: first of all, the teams are split into pairs: team $$$1$$$ plays against team $$$2$$$, team $$$3$$$ plays against team $$$4$$$ (exactly in this order), and so on (so, $$$2^{k-1}$$$ games are pl... | For each query, print one integerΒ β $$$f(s)$$$. | The first line contains one integer $$$k$$$ ($$$1 \le k \le 18$$$). The second line contains a string consisting of $$$2^k - 1$$$ charactersΒ β the initial state of the string $$$s$$$. Each character is either ?, 0, or 1. The third line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$)Β β the number of querie... | standard output | standard input | PyPy 3-64 | Python | 1,800 | train_085.jsonl | 2cb9dce8b147673c6414b28cbc35a4ac | 256 megabytes | ["3\n0110?11\n6\n5 1\n6 ?\n7 ?\n1 ?\n5 ?\n1 1"] | PASSED | import sys
def upd(ix, cur):
if s[ix] == '?':
tree[cur] = tree[cur << 1] + tree[(cur << 1) + 1]
else:
tree[cur] = tree[(cur << 1) + (int(s[ix]) ^ 1)]
input = lambda: sys.stdin.buffer.readline().decode().strip()
ispow2 = lambda x: x and (not (x & (x - 1)))
k, s = int(input()), lis... | 1622817300 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["1 1 0 1 \n0 1 1 0 0 0 1 \n0 0 0 \n0 0 0 1 \n1 0 1"] | 9dc1bee4e53ced89d827826f2d83dabf | NoteHere's the explanation for the first test case. Given that $$$A=[1,1,0,1]$$$, we can construct each $$$B_i$$$: $$$B_1=[\color{blue}{1},1,0,1]$$$; $$$B_2=[\color{blue}{1},\color{blue}{1},0,1]$$$; $$$B_3=[\color{blue}{0},\color{blue}{1},\color{blue}{1},1]$$$; $$$B_4=[\color{blue}{0},\color{blue}{1},\color{blue}{... | Suppose you had an array $$$A$$$ of $$$n$$$ elements, each of which is $$$0$$$ or $$$1$$$.Let us define a function $$$f(k,A)$$$ which returns another array $$$B$$$, the result of sorting the first $$$k$$$ elements of $$$A$$$ in non-decreasing order. For example, $$$f(4,[0,1,1,0,0,1,0]) = [0,0,1,1,0,1,0]$$$. Note that t... | For each test case, output a single line containing $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$a_i$$$ is $$$0$$$ or $$$1$$$). If there are multiple answers, you may output any of them. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) Β β the number of test cases. Each test case has two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$c_1, c_2, \ldots, c_n$$$ ($$$0 \leq c_i \leq n$$$). It ... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_110.jsonl | f3d4714fc7e831eadbe1b17d4a2e5d34 | 256 megabytes | ["5\n4\n2 4 2 4\n7\n0 3 4 2 3 2 7\n3\n0 0 0\n4\n0 0 0 4\n3\n1 2 3"] | PASSED | import sys
input = lambda: sys.stdin.buffer.readline().decode().strip()
for _ in range(int(input())):
n, a = int(input()), [int(x) for x in input().split()]
ans, ones = [], sum(a) // n
mem = [0] * (n + 1)
for i in reversed(range(n)):
mem[i] += mem[i + 1]
a[i] -= mem[i]
... | 1650206100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3 4 2 1\n-1\n6 7 4 5 3 2 1\n5 4 1 2 3\n2 1"] | cdcf95e29d3260a07dded74286fc3798 | NoteThe first test case is explained in the problem statement.In the second test case, it is not possible to make the required permutation: permutations $$$[1, 2, 3]$$$, $$$[1, 3, 2]$$$, $$$[2, 1, 3]$$$, $$$[3, 2, 1]$$$ have fixed points, and in $$$[2, 3, 1]$$$ and $$$[3, 1, 2]$$$ the first condition is met not for all... | A sequence of $$$n$$$ numbers is called permutation if it contains all numbers from $$$1$$$ to $$$n$$$ exactly once. For example, the sequences $$$[3, 1, 4, 2]$$$, [$$$1$$$] and $$$[2,1]$$$ are permutations, but $$$[1,2,1]$$$, $$$[0,1]$$$ and $$$[1,3,4]$$$ are not.For a given number $$$n$$$ you need to make a permutati... | For each test case, print on a separate line: any funny permutation $$$p$$$ of length $$$n$$$; or the number -1 if the permutation you are looking for does not exist. | The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. The description of the test cases follows. Each test case consists of f single line containing one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$). It is guaranteed that the sum of $$$n$$$ over all test ... | standard output | standard input | PyPy 3-64 | Python | 800 | train_084.jsonl | 36f2fb77e33b93be891fec3c83348a49 | 256 megabytes | ["5\n\n4\n\n3\n\n7\n\n5\n\n2"] | PASSED | for _ in range(int(input())):
n = int(input())
if n == 3:
print('-1')
else :
print( n, n-1, *range(1,n-1) ) | 1665498900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
5 seconds | ["YES\n001100\nNO\nYES\n01100110\nYES\n0110", "YES\n0101100100", "YES\n1010000011"] | 328291f7ef1de8407d8167a1881ec2bb | NoteHere are the graphs from the first example. The vertices in the lenient vertex covers are marked red. | You are given a simple connected undirected graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The vertices are numbered from $$$1$$$ to $$$n$$$.A vertex cover of a graph is a set of vertices such that each edge has at least one of its endpoints in the set.Let's call a lenient vertex cover such a vertex cover tha... | For each testcase, the first line should contain YES if a lenient vertex cover exists, and NO otherwise. If it exists, the second line should contain a binary string $$$s$$$ of length $$$n$$$, where $$$s_i = 1$$$ means that vertex $$$i$$$ is in the vertex cover, and $$$s_i = 0$$$ means that vertex $$$i$$$ isn't. If the... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 10^6$$$; $$$n - 1 \le m \le \min(10^6, \frac{n \cdot (n - 1)}{2})$$$)Β β the number of vertices and the number of edges of the gra... | standard output | standard input | PyPy 3-64 | Python | 2,600 | train_083.jsonl | f5fb58c7f9711e30e04b01aef52310f8 | 512 megabytes | ["4\n\n6 5\n\n1 3\n\n2 4\n\n3 4\n\n3 5\n\n4 6\n\n4 6\n\n1 2\n\n2 3\n\n3 4\n\n1 4\n\n1 3\n\n2 4\n\n8 11\n\n1 3\n\n2 4\n\n3 5\n\n4 6\n\n5 7\n\n6 8\n\n1 2\n\n3 4\n\n5 6\n\n7 8\n\n7 2\n\n4 5\n\n1 2\n\n2 3\n\n3 4\n\n1 3\n\n2 4", "1\n\n10 15\n\n9 4\n\n3 4\n\n6 4\n\n1 2\n\n8 2\n\n8 3\n\n7 2\n\n9 5\n\n7 8\n\n5 10\n\n1 4\n\n2 1... | PASSED | input = __import__('sys').stdin.readline
DFS_IN = 0
DFS_OUT = 1
def solve():
n, m = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(m):
u, v = map(lambda x: int(x)-1, input().split())
adj[u].append(v)
adj[v].append(u)
cnt_odd = 0
... | 1652452500 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["Yes", "No", "Yes"] | 65efbc0a1ad82436100eea7a2378d4c2 | NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes... | Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to nβ-β1 and 0 to mβ-β1 separately. In i-th day, Drazil invites -th boy and -th girl... | If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No". | The first line contains two integer n and m (1ββ€βn,βmββ€β100). The second line contains integer b (0ββ€βbββ€βn), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1,βx2,β...,βxb (0ββ€βxiβ<βn), denoting the list of indices of happy boys. The third line conatins integer g (0ββ€... | standard output | standard input | PyPy 2 | Python | 1,300 | train_013.jsonl | fc705760b608d2a0f184bd7d93b224d4 | 256 megabytes | ["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"] | PASSED | n, m = map(int, raw_input().split())
hb = [0] * n
hg = [0] * m
for i in map(int, raw_input().split())[1:]:
hb[i] = 1
for i in map(int, raw_input().split())[1:]:
hg[i] = 1
for i in range(2 * n * m):
hb[i % n] = hg[i % m] = hb[i % n] | hg[i % m]
print "Yes" if hb.count(1) + hg.count(1) == n + m else "No"... | 1424190900 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["17", "71"] | bc6b8fda79c257e6c4e280d7929ed8a1 | NoteThis image describes first sample case:It is easy to see that summary price is equal to 17.This image describes second sample case:It is easy to see that summary price is equal to 71. | Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXXΒ β beautiful, but little-known northern country.Here are some interesting facts about XXX: XXX consists of n cities, k of whose (just imagine!) are capital cities. All of cities in the count... | Print the only integerΒ β summary price of passing each of the roads in XXX. | The first line of the input contains two integers n and k (3ββ€βnββ€β100β000,β1ββ€βkββ€βn)Β β the number of cities in XXX and the number of capital cities among them. The second line of the input contains n integers c1,βc2,β...,βcn (1ββ€βciββ€β10β000)Β β beauty values of the cities. The third line of the input contains k disti... | standard output | standard input | Python 3 | Python | 1,400 | train_018.jsonl | 65e3138e770d1b3537a3e0c6f9834dac | 256 megabytes | ["4 1\n2 3 1 2\n3", "5 2\n3 5 2 2 4\n1 4"] | PASSED | n, k = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
ids = [(int(x)-1) for x in input().split()]
s = sum(c)
ans = 0
for i in range(n):
ans += (c[i] * c[(i+1)%n])
for i in range(k):
if (abs(ids[i] - ids[(i+1)%k]) == 1) or (ids[i] == n-1 and ids[0] == 0):
ans += c[ids[i]]*c[ids[(i+1)%k]... | 1470323700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["4", "5", "164"] | 2fad8bea91cf6db14b34271e88ab093c | NoteThe queries in the first example are $$$0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0$$$. The answers are $$$11, 9, 7, 3, 1, 5, 8, 7, 5, 7, 11$$$. The queries in the second example are $$$3, 0, 2, 1, 6, 0, 3, 5, 4, 1$$$. The answers are $$$14, 19, 15, 16, 11, 19, 14, 12, 13, 16$$$. The queries in the third example are $$$75, 0... | You are given a connected weighted undirected graph, consisting of $$$n$$$ vertices and $$$m$$$ edges.You are asked $$$k$$$ queries about it. Each query consists of a single integer $$$x$$$. For each query, you select a spanning tree in the graph. Let the weights of its edges be $$$w_1, w_2, \dots, w_{n-1}$$$. The cost... | Print a single integerΒ β the xor of answers to all queries. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 50$$$; $$$n - 1 \le m \le 300$$$)Β β the number of vertices and the number of edges in the graph. Each of the next $$$m$$$ lines contains a description of an undirected edge: three integers $$$v$$$, $$$u$$$ and $$$w$$$ ($$$1 \le v, u \le n$$$; $$$v... | standard output | standard input | PyPy 3-64 | Python | 2,400 | train_104.jsonl | bf177dedfa21c7c12d0d1f67579a4632 | 256 megabytes | ["5 8\n4 1 4\n3 1 0\n3 5 3\n2 5 4\n3 4 8\n4 3 4\n4 2 8\n5 3 9\n3 11 1 1 10\n0 1 2", "6 7\n2 4 0\n5 4 7\n2 4 0\n2 1 7\n2 6 1\n3 4 4\n1 4 8\n4 10 3 3 7\n3 0 2 1", "3 3\n1 2 50\n2 3 100\n1 3 150\n1 10000000 0 0 100000000\n75"] | PASSED | from bisect import bisect_left
from collections import defaultdict
I = lambda: [int(x) for x in input().split()]
class DSU:
def __init__(self, N):
self.p = list(range(N))
def find(self, x):
if self.p[x] != x:
self.p[x] = self.find(self.p[x])
return self.p[x]
... | 1643639700 | [
"math",
"trees",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
1
] | |
2 seconds | ["NO\nYES\nNO\nYES\nYES\nNO"] | f4958b4833cafa46fa71357ab1ae41af | null | You are given an integer $$$n$$$. Check if $$$n$$$ has an odd divisor, greater than one (does there exist such a number $$$x$$$ ($$$x > 1$$$) that $$$n$$$ is divisible by $$$x$$$ and $$$x$$$ is odd).For example, if $$$n=6$$$, then there is $$$x=3$$$. If $$$n=4$$$, then such a number does not exist. | For each test case, output on a separate line: "YES" if $$$n$$$ has an odd divisor, greater than one; "NO" otherwise. You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive). | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Then $$$t$$$ test cases follow. Each test case contains one integer $$$n$$$ ($$$2 \le n \le 10^{14}$$$). Please note, that the input for some test cases won't fit into $$$32$$$-bit integer type, so you should use at least $... | standard output | standard input | PyPy 3-64 | Python | 900 | train_086.jsonl | 1d3091aa2b9448512e0bb7478a7a623b | 256 megabytes | ["6\n2\n3\n4\n5\n998244353\n1099511627776"] | PASSED | n=int(input())
for i in range (n):
t=int(input())
while t%2==0:
t/=2
if t>1:
print("YES")
else:
print("NO") | 1611586800 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["2\n2 1\n4\n2 1 4 3\n9\n6 9 1 2 3 4 5 7 8\n3\n1 2 3"] | 677972c7d86ce9fd0808105331f77fe0 | NoteIn the first test case, the subset $$$\{a_2, a_1\}$$$ has a sum of $$$9$$$, which is a composite number. The only subset of size $$$3$$$ has a prime sum equal to $$$11$$$. Note that you could also have selected the subset $$$\{a_1, a_3\}$$$ with sum $$$8 + 2 = 10$$$, which is composite as it's divisible by $$$2$$$.... | A bow adorned with nameless flowers that bears the earnest hopes of an equally nameless person.You have obtained the elegant bow known as the Windblume Ode. Inscribed in the weapon is an array of $$$n$$$ ($$$n \ge 3$$$) positive distinct integers (i.e. different, no duplicates are allowed).Find the largest subset (i.e.... | Each test case should have two lines of output. The first line should contain a single integer $$$x$$$: the size of the largest subset with composite sum. The next line should contain $$$x$$$ space separated integers representing the indices of the subset of the initial array. | Each test consists of multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3 \leq n \leq 100$$$)Β β the length of the array. The second line of each test case contains... | standard output | standard input | Python 3 | Python | 800 | train_087.jsonl | 690c00858cc49b20512653923ed3d513 | 256 megabytes | ["4\n3\n8 1 2\n4\n6 9 4 2\n9\n1 2 3 4 5 6 7 8 9\n3\n200 199 198"] | PASSED | tt = int(input())
fa = []
n = 500000
for i in range(n + 1):
fa.append(i)
fa[1] = 0
i = 2
while i <= n:
if fa[i] != 0:
j = i + i
while j <= n:
fa[j] = 0
j = j + i
i += 1
fa = set(fa)
fa.remove(0)
for i in range(tt):
ar = []
f = int(input())
... | 1634468700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
3 seconds | ["2", "1\n0", "5\n3\n3\n4"] | 776706f09cd446bc144a2591e424e437 | null | You are given a convex polygon. Count, please, the number of triangles that contain a given point in the plane and their vertices are the vertices of the polygon. It is guaranteed, that the point doesn't lie on the sides and the diagonals of the polygon. | The output should contain t integer numbers, each on a separate line, where i-th number is the answer for the i-th point. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). | The first line contains integer n β the number of vertices of the polygon (3ββ€βnββ€β100000). The polygon description is following: n lines containing coordinates of the vertices in clockwise order (integer x and y not greater than 109 by absolute value). It is guaranteed that the given polygon is nondegenerate and conve... | standard output | standard input | Python 2 | Python | 2,500 | train_069.jsonl | 6cfac2fef6d680a86fe8556abfd8af65 | 256 megabytes | ["4\n5 0\n0 0\n0 5\n5 5\n1\n1 3", "3\n0 0\n0 5\n5 0\n2\n1 1\n10 10", "5\n7 6\n6 3\n4 1\n1 2\n2 4\n4\n3 3\n2 3\n5 5\n4 2"] | PASSED | import sys
import gc
gc.disable()
rl = sys.stdin.readline
n = int(rl())
p = [complex(float(x),float(y)) for x,y in map(str.split,map(rl,[-1]*n))]
pi = [c.conjugate() for c in p]
fn = [0.5*x*(x-1) for x in xrange(0,n+1)]
fnn = fn[::-1]
for jj in xrange(int(rl())):
a = complex(*map(float,rl().split()))
pp =... | 1294992000 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
1 second | ["YES", "NO"] | 52f4f2a48063c9d0e412a5f78c873e6f | NoteIn the first example, you can make all elements equal to zero in $$$3$$$ operations: Decrease $$$a_1$$$ and $$$a_2$$$, Decrease $$$a_3$$$ and $$$a_4$$$, Decrease $$$a_3$$$ and $$$a_4$$$ In the second example, one can show that it is impossible to make all elements equal to zero. | You are given an array $$$a_1, a_2, \ldots, a_n$$$.In one operation you can choose two elements $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$) and decrease each of them by one.You need to check whether it is possible to make all the elements equal to zero or not. | Print "YES" if it is possible to make all elements zero, otherwise print "NO". | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β the size of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β the elements of the array. | standard output | standard input | PyPy 3 | Python | 1,500 | train_005.jsonl | c5ab9a828ef6ba4a275b204bbec3c526 | 256 megabytes | ["4\n1 1 2 2", "6\n1 2 3 4 5 6"] | PASSED | x=int(input())
a=list(map(int,input().split()))
c=sum(a)
d=max(a)
if d<=c//2 and x>1 and c%2==0:
print("YES")
else:
print("NO") | 1564936500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["392\n1 1", "240\n2 3"] | 45ac482a6b95f44a26b7363e6756c8d1 | NoteIn the first test case the total time of guessing all cars is equal to 3Β·8β+β3Β·8β+β4Β·8β+β9Β·8β+β5Β·40β+β1Β·40β=β392.The coordinate system of the field: | A widely known among some people Belarusian sport programmer Yura possesses lots of information about cars. That is why he has been invited to participate in a game show called "Guess That Car!".The game show takes place on a giant parking lot, which is 4n meters long from north to south and 4m meters wide from west to... | In the first line print the minimum total time Yura needs to guess all offered cars. In the second line print two numbers li and lj (0ββ€βliββ€βn,β0ββ€βljββ€βm) β the numbers of dividing lines that form a junction that Yura should choose to stand on at the beginning of the game show. If there are multiple optimal starting ... | The first line contains two integers n and m (1ββ€βn,βmββ€β1000) β the sizes of the parking lot. Each of the next n lines contains m integers: the j-th number in the i-th line describes the "rarity" cij (0ββ€βcijββ€β100000) of the car that is located in the square with coordinates (i,βj). | standard output | standard input | Python 2 | Python | 1,800 | train_067.jsonl | 5cc96ee4a879573f49625082bc47ddba | 256 megabytes | ["2 3\n3 4 5\n3 9 1", "3 4\n1 0 0 0\n0 0 3 0\n0 0 5 5"] | PASSED | def getmin(c, m):
l, r = 0, m
cx = lambda x:sum([c[i]*((x-i)*4-2)**2 for i in range(m)])
while True:
ml = (l*2+r)/3
mr = (l+r*2)/3
l, r = (ml, r) if cx(ml) > cx(mr) else (l, mr)
if r<=l+10:
px = cx(l)+1
for i in xrange(r-l+2):
if px <= ... | 1340983800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2"] | 86efef40ebbdb42fbcbf2dfba7143433 | Note Explanation: Friends should send signals 2 times to each other, first time around point $$$A2$$$ and $$$B2$$$ and second time during A's travel from point $$$A3$$$ to $$$A4$$$ while B stays in point $$$B3=B4$$$. | Two friends are travelling through Bubble galaxy. They say "Hello!" via signals to each other if their distance is smaller or equal than $$$d_1$$$ and it's the first time they speak to each other or at some point in time after their last talk their distance was greater than $$$d_2$$$. We need to calculate how many... | Output contains one integer number that represents how many times friends will say "Hello!" to each other. | The first line contains one integer number $$$N$$$ ($$$2 \leq N \leq 100\,000$$$) representing number of moments in which we captured positions for two friends. The second line contains two integer numbers $$$d_1$$$ and $$$d_2 \ (0 < d_1 < d_2 < 1000)$$$. The next $$$N$$$ lines contains four integer numbers $... | standard output | standard input | Python 3 | Python | 2,300 | train_048.jsonl | 848e1b3d36261192dd8a4b3162076cee | 256 megabytes | ["4\n2 5\n0 0 0 10\n5 5 5 6\n5 0 10 5\n14 7 10 5"] | PASSED | from sys import stdin
stdin = iter(stdin)
class Vector:
''''''
def __init__(self, x, y):
self.x = x
self.y = y
def __sub__(self, other):
return Vector(self.x - other.x, self.y - other.y)
def __add__(self, other):
return Vector(self.x + other.x, self.y + other.y)
... | 1537612500 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
3 seconds | ["0 3 1 2 1 1 2 3 \n0 0 3 \n1 2 2 \n0 1 2 1 1 2 2 1 1"] | 8629aa74df60537987611c6c1ef1a140 | NoteThe first example is clarified in the statement.In the second example: $$$r_2=0$$$, since the path to $$$2$$$ has an amount of $$$a_j$$$ equal to $$$1$$$, only the prefix of this path of length $$$0$$$ has a smaller or equal amount of $$$b_j$$$; $$$r_3=0$$$, since the path to $$$3$$$ has an amount of $$$a_j$$$ equ... | You are given a rooted tree. It contains $$$n$$$ vertices, which are numbered from $$$1$$$ to $$$n$$$. The root is the vertex $$$1$$$.Each edge has two positive integer values. Thus, two positive integers $$$a_j$$$ and $$$b_j$$$ are given for each edge.Output $$$n-1$$$ numbers $$$r_2, r_3, \dots, r_n$$$, where $$$r_i$$... | For each test case, output $$$n-1$$$ integer in one line: $$$r_2, r_3, \dots, r_n$$$. | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases in the test. The descriptions of test cases follow. Each description begins with a line that contains an integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) β the number of vertices in the tree. This is followed by $$$n-1$$$ strin... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_102.jsonl | a23de9d86a5b8f8ef22dd604bccb9ca6 | 256 megabytes | ["4\n\n9\n\n1 5 6\n\n4 5 1\n\n2 9 10\n\n4 2 1\n\n1 2 1\n\n2 3 3\n\n6 4 3\n\n8 1 3\n\n4\n\n1 1 100\n\n2 1 1\n\n3 101 1\n\n4\n\n1 100 1\n\n2 1 1\n\n3 1 101\n\n10\n\n1 1 4\n\n2 3 5\n\n2 5 1\n\n3 4 3\n\n3 1 5\n\n5 3 5\n\n5 2 1\n\n1 3 2\n\n6 2 1"] | PASSED | import sys, io, os
import time
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def find_prefix_length(b_stack, sum_a_, starting_prefix):
lo = starting_prefix
hi = len(b_stack) - 1
while (hi - lo) > 1:
mid = (lo + hi) // 2
if b_stack[mid] <= sum_a_:
... | 1659364500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["1\n12\n830455698\n890287984"] | 19a2550af6a46308fd92c7a352f12a5f | Note$$$n=1$$$, there is only one permutation that satisfies the condition: $$$[1,2].$$$In permutation $$$[1,2]$$$, $$$p_1<p_2$$$, and there is one $$$i=1$$$ satisfy the condition. Since $$$1 \geq n$$$, this permutation should be counted. In permutation $$$[2,1]$$$, $$$p_1>p_2$$$. Because $$$0<n$$$, this permut... | CQXYM is counting permutations length of $$$2n$$$.A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a per... | For each test case, print the answer in a single line. | The input consists of multiple test cases. The first line contains an integer $$$t (t \geq 1)$$$ β the number of test cases. The description of the test cases follows. Only one line of each test case contains an integer $$$n(1 \leq n \leq 10^5)$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not ... | standard output | standard input | Python 3 | Python | 800 | train_089.jsonl | a66427931928da61b17f883432f76b8e | 256 megabytes | ["4\n1\n2\n9\n91234"] | PASSED | mod = (10**9)+7
def fact( n ):
f = 1
for i in range( 3 , n+1):
f = (f* i) % mod
return f
for _ in range(int(input())):
a = int(input()) * 2
print( fact(a) ) | 1632996900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["2", "1", "-1"] | b0ffab0bf169f8278af48fe2d58dcd2d | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array a1,βa2,β...,βan, consisting of n positive integers.Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | Print a single integer β the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1. If there are multiple answers, you are allowed to print any of them. | The first line contains integer n (1ββ€βnββ€β105), showing how many numbers the array has. The next line contains integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the array elements. | standard output | standard input | Python 2 | Python | 1,000 | train_023.jsonl | 9c30ff70c458b25dc43f08ed4c190da6 | 256 megabytes | ["3\n2 2 4", "5\n2 1 3 1 6", "3\n2 3 5"] | PASSED | def main():
n = int(raw_input())
a = map(int,raw_input().split())
minx = min(a)
print([minx,-1][min(1,sum(map(lambda t:t%minx,a)))])
main() | 1366644600 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["even", "odd", "odd", "even"] | ee105b664099808143a94a374d6d5daa | NoteIn the first example, $$$n = 3 \cdot 13^2 + 2 \cdot 13 + 7 = 540$$$, which is even.In the second example, $$$n = 123456789$$$ is odd.In the third example, $$$n = 32 \cdot 99^4 + 92 \cdot 99^3 + 85 \cdot 99^2 + 74 \cdot 99 + 4 = 3164015155$$$ is odd.In the fourth example $$$n = 2$$$. | You are given an integer $$$n$$$ ($$$n \ge 0$$$) represented with $$$k$$$ digits in base (radix) $$$b$$$. So,$$$$$$n = a_1 \cdot b^{k-1} + a_2 \cdot b^{k-2} + \ldots a_{k-1} \cdot b + a_k.$$$$$$For example, if $$$b=17, k=3$$$ and $$$a=[11, 15, 7]$$$ then $$$n=11\cdot17^2+15\cdot17+7=3179+255+7=3441$$$.Determine whether... | Print "even" if $$$n$$$ is even, otherwise print "odd". You can print each letter in any case (upper or lower). | The first line contains two integers $$$b$$$ and $$$k$$$ ($$$2\le b\le 100$$$, $$$1\le k\le 10^5$$$)Β β the base of the number and the number of digits. The second line contains $$$k$$$ integers $$$a_1, a_2, \ldots, a_k$$$ ($$$0\le a_i < b$$$)Β β the digits of $$$n$$$. The representation of $$$n$$$ contains no unneces... | standard output | standard input | Python 3 | Python | 900 | train_008.jsonl | 8ff31b782402842031891f689dd9b386 | 256 megabytes | ["13 3\n3 2 7", "10 9\n1 2 3 4 5 6 7 8 9", "99 5\n32 92 85 74 4", "2 2\n1 0"] | PASSED | b, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
n = 0
for i in range(0, k - 1):
n += a[i] * b
if a[k - 1] % 2 != 0:
n += 1
if n % 2 == 0:
print('even')
else:
print('odd')
| 1549546500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3", "-1"] | b0e6a9b500b3b75219309b5e6295e105 | NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numb... | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print β-β1 in the only line. | The first line of the input contains three integers n, m and k (1ββ€βn,βmββ€β105, 0ββ€βkββ€βn)Β β the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1ββ€βu,βvββ€βn, 1ββ€βlββ€β109, uβ... | standard output | standard input | Python 2 | Python | 1,300 | train_002.jsonl | 5af3ecf810a8c1c34831af4f084e7302 | 256 megabytes | ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3"] | PASSED | '''input
3 1 1
1 2 3
3
'''
n, m, k = map(int, raw_input().split())
if k == 0:
print -1
else:
A = [map(int, raw_input().split()) for _ in xrange(m)]
storages = map(int, raw_input().split())
mark = [True] * (n + 1)
for i in storages: mark[i] = False
res = 10000000000
for u, v, l in A:
if mark[u] != mark[v]:
... | 1471698300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["8\n4\n1\n1"] | f2f9f63a952794f27862eb24ccbdbf36 | NoteIn the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element. the first person will take the last element ($$$5$$$) because he or she was forced by you to take the last element. After this turn the remaining array will be $$$[2, 9... | You and your $$$n - 1$$$ friends have found an array of integers $$$a_1, a_2, \dots, a_n$$$. You have decided to share it in the following way: All $$$n$$$ of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it... | For each test case, print the largest integer $$$x$$$ such that you can guarantee to obtain at least $$$x$$$. | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains three space-separated integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le m \le n \le 3500$$$... | standard output | standard input | Python 3 | Python | 1,600 | train_004.jsonl | e5623983689a3dede5b593e13113b27a | 256 megabytes | ["4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 1 3\n1 2 2 1\n2 2 0\n1 2"] | PASSED | def inp(dtype=str, strip=True):
s = input()
res = [dtype(p) for p in s.split()]
res = res[0] if len(res) == 1 and strip else res
return res
def problemA():
t = int(input())
for _ in range(t):
n = int(input())
s = input()
s = [int(el) for el in s]
res = '-1'
... | 1580652300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2.5 seconds | ["0", "4"] | 40a32523f982e24fba2c785fc6a27881 | NoteIn the first example, the first array is already good, since the greatest common divisor of all the elements is $$$2$$$.In the second example, we may apply the following operations: Add $$$1$$$ to the second element, making it equal to $$$9$$$. Subtract $$$1$$$ from the third element, making it equal to $$$6$$$. ... | Kuroni is very angry at the other setters for using him as a theme! As a punishment, he forced them to solve the following problem:You have an array $$$a$$$ consisting of $$$n$$$ positive integers. An operation consists of choosing an element and either adding $$$1$$$ to it or subtracting $$$1$$$ from it, such that the... | Print a single integer Β β the minimum number of operations required to make the array good. | The first line contains an integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) Β β the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. ($$$1 \le a_i \le 10^{12}$$$) Β β the elements of the array. | standard output | standard input | PyPy 2 | Python | 2,500 | train_007.jsonl | 2d1412b4f25a917b6e48da92aac3c952 | 256 megabytes | ["3\n6 2 4", "5\n9 8 7 3 1"] | PASSED | import random
n = int(raw_input())
a = list(map(int, raw_input().split()))
limit = min(8, n)
iterations = [x for x in range(n)]
random.shuffle(iterations)
iterations = iterations[:limit]
def factorization(x):
primes = []
i = 2
while i * i <= x:
if x % i == 0:
primes.append(i)
while x % i == 0: x //= i
i... | 1583246100 | [
"number theory",
"math",
"probabilities"
] | [
0,
0,
0,
1,
1,
1,
0,
0
] | |
2 seconds | ["4\n0"] | 332340a793eb3ec14131948e2b6bdf2f | NotePossible ways to distribute numbers in the first test: the vertex $$$1$$$ should contain $$$1$$$, and $$$2$$$ should contain $$$2$$$; the vertex $$$1$$$ should contain $$$3$$$, and $$$2$$$ should contain $$$2$$$; the vertex $$$1$$$ should contain $$$2$$$, and $$$2$$$ should contain $$$1$$$; the vertex $$$1$$$ ... | You are given an undirected unweighted graph consisting of $$$n$$$ vertices and $$$m$$$ edges.You have to write a number on each vertex of the graph. Each number should be $$$1$$$, $$$2$$$ or $$$3$$$. The graph becomes beautiful if for each edge the sum of numbers on vertices connected by this edge is odd.Calculate the... | For each test print one line, containing one integer β the number of possible ways to write numbers $$$1$$$, $$$2$$$, $$$3$$$ on the vertices of given graph so it becomes beautiful. Since answers may be large, print them modulo $$$998244353$$$. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 3 \cdot 10^5$$$) β the number of tests in the input. The first line of each test contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 3 \cdot 10^5, 0 \le m \le 3 \cdot 10^5$$$) β the number of vertices and the number of edges, respectively. Next $$$m$$$ l... | standard output | standard input | Python 3 | Python | 1,700 | train_008.jsonl | a6857ccf57418e193d24e71258e2f192 | 256 megabytes | ["2\n2 1\n1 2\n4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4"] | PASSED | from collections import deque
from sys import stdin, stdout
input = stdin.readline
print = stdout.write
anss = []
t = int(input())
for test_count in range(t):
ans = 1
part = 0
factor = 0
queue = deque([])
n, m = map(int, input().split())
if m > (n // 2) * ( n // 2 + 1):
anss.append(0)
for edge_count in ra... | 1544884500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["YES\nBABA", "NO"] | d126ef6b94e9ab55624cf7f2a96c7ed1 | null | Vasya has a multiset $$$s$$$ consisting of $$$n$$$ integer numbers. Vasya calls some number $$$x$$$ nice if it appears in the multiset exactly once. For example, multiset $$$\{1, 1, 2, 3, 3, 3, 4\}$$$ contains nice numbers $$$2$$$ and $$$4$$$.Vasya wants to split multiset $$$s$$$ into two multisets $$$a$$$ and $$$b$$$ ... | If there exists no split of $$$s$$$ to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of $$$n$$$ characters. $$$i$$$-th character should be equal to 'A' if the $$$i$$$-th element of multiset $$$s$$$ goes to ... | The first line contains a single integer $$$n~(2 \le n \le 100)$$$. The second line contains $$$n$$$ integers $$$s_1, s_2, \dots s_n~(1 \le s_i \le 100)$$$ β the multiset $$$s$$$. | standard output | standard input | Python 2 | Python | 1,500 | train_022.jsonl | ad3a20cc87e13794b47c3fc3058f4a1d | 256 megabytes | ["4\n3 5 7 1", "3\n3 5 1"] | PASSED | raw_input()
s = map(int, raw_input().split())
MAX_SIZE = 101
count = [0] * MAX_SIZE
for num in s:
count[num] += 1
nUnique = 0
a, b = [0] * MAX_SIZE, [0] * MAX_SIZE
turn = 0
for num in xrange(1, MAX_SIZE):
if count[num] == 1:
nUnique += 1
if turn == 0:
a[num] = 1
else:
... | 1537454700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3", "18", "4.5"] | b2031a328d72b464f965b4789fd35b93 | NotePasha also has candies that he is going to give to girls but that is another task... | Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of w milliliters and 2n tea cups, each cup is for one of Pasha's friends. The i-th cup can hold at most ai milliliters of water.It turned out that among Pasha's friends there are exactly n boys and exactly n g... | Print a single real number β the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10β-β6. | The first line of the input contains two integers, n and w (1ββ€βnββ€β105, 1ββ€βwββ€β109)Β β the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters. The second line of the input contains the sequence of integers ai (1ββ€βaiββ€β109, ... | standard output | standard input | Python 3 | Python | 1,500 | train_001.jsonl | 8f4fb2203d74e4e065844cec1cc6f4ea | 256 megabytes | ["2 4\n1 1 1 1", "3 18\n4 4 4 2 2 2", "1 5\n2 3"] | PASSED | n, w = map(int, input().split())
cups = sorted([int(x) for x in input().split()])
girl = cups[0]
boys = cups[n]
both = min(girl, boys/2)
print(min(n*both + 2*n*both, w)) | 1435676400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n2"] | b46244f39e30c0cfab592a97105c60f4 | NoteIn the first test case, $$$\mathrm{gcd}(1, 2) = \mathrm{gcd}(2, 3) = \mathrm{gcd}(1, 3) = 1$$$.In the second test case, $$$2$$$ is the maximum possible value, corresponding to $$$\mathrm{gcd}(2, 4)$$$. | Let's consider all integers in the range from $$$1$$$ to $$$n$$$ (inclusive).Among all pairs of distinct integers in this range, find the maximum possible greatest common divisor of integers in pair. Formally, find the maximum value of $$$\mathrm{gcd}(a, b)$$$, where $$$1 \leq a < b \leq n$$$.The greatest common div... | For each test case, output the maximum value of $$$\mathrm{gcd}(a, b)$$$ among all $$$1 \leq a < b \leq n$$$. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β the number of test cases. The description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^6$$$). | standard output | standard input | PyPy 3 | Python | 800 | train_005.jsonl | dc5d966edc948ebb88a4a08ae02bccd1 | 256 megabytes | ["2\n3\n5"] | PASSED |
MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from collections import *
for _ in range(ii()):
n=ii()
if(n%2==0):
print(n//2)
... | 1592663700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["3\n6\n5", "3\n4\n5\n7\n8\n1\n2\n3\n4\n5", "10\n10"] | 0646a23b550eefea7347cef831d1c69d | NoteIn the first sample, there are three plans: In the first plan, at most 1 piece can be repainted. Repainting the "y" piece to become "o" results in "kooomi", whose Koyomity of 3 is the best achievable; In the second plan, at most 4 pieces can be repainted, and "oooooo" results in a Koyomity of 6; In the third pl... | Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it!Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has n pieces numbered from 1 to n from left... | Output q lines: for each work plan, output one line containing an integer β the largest Koyomity achievable after repainting the garland according to it. | The first line of input contains a positive integer n (1ββ€βnββ€β1β500) β the length of the garland. The second line contains n lowercase English letters s1s2... sn as a string β the initial colours of paper pieces on the garland. The third line contains a positive integer q (1ββ€βqββ€β200β000) β the number of plans Nadeko... | standard output | standard input | Python 3 | Python | 1,600 | train_031.jsonl | e78d549bd428f3826ce67361ba449415 | 256 megabytes | ["6\nkoyomi\n3\n1 o\n4 o\n4 m", "15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b", "10\naaaaaaaaaa\n2\n10 b\n10 z"] | PASSED | import string
import bisect
import sys
def main():
lines = sys.stdin.readlines()
n = int(lines[0])
s = lines[1]
vals = {}
for c in string.ascii_lowercase:
a = [i for i, ch in enumerate(s) if ch == c]
m = len(a)
b = [0]
for length in range(1, m + 1):
best = n
for i in range(m - le... | 1496837700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["NO", "YES\n4\n3 6 1\n4 6 3\n3 4 7\n4 5 2"] | 0ef40ec5578a61c93254149c59282ee3 | NoteThe configuration from the first sample is drawn below, and it is impossible to achieve. The sequence of operations from the second sample is illustrated below. | Note that this is the second problem of the two similar problems. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems.You are given a tree with $$$n$$$ nodes. In the beginning, $$$0$$$ is written on all edges. In one operation, you can choose any $$$2$$$ dist... | If there aren't any sequences of operations which lead to the given configuration, output "NO". If it exists, output "YES" in the first line. In the second line output $$$m$$$Β β number of operations you are going to apply ($$$0 \le m \le 10^5$$$). Note that you don't have to minimize the number of the operations! In th... | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$)Β β the number of nodes in a tree. Each of the next $$$n-1$$$ lines contains three integers $$$u$$$, $$$v$$$, $$$val$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$, $$$0 \le val \le 10\,000$$$), meaning that there is an edge between nodes $$$u$$$ and $... | standard output | standard input | Python 2 | Python | 2,500 | train_003.jsonl | 0c688992e3f3c663189296850df19f89 | 256 megabytes | ["5\n1 2 2\n2 3 4\n3 4 10\n3 5 18", "6\n1 2 6\n1 3 8\n1 4 12\n2 5 2\n2 6 4"] | PASSED | from sys import stdin
class solution():
def dfs(self, x, par, adj_arr):
for adj in adj_arr[x]:
if adj != par:
return self.dfs(adj, x, adj_arr)
return x
def get_two_child(self, x, y, adj_arr):
if len(adj_arr[x]) == 1:
return x + 1, x + 1
... | 1562339100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["Yes\n1 4", "No", "Yes\n2 7 7"] | 55bd1849ef13b52788a0b5685c4fcdac | null | You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in mult... | If it is not possible to select k numbers in the desired way, output Β«NoΒ» (without the quotes). Otherwise, in the first line of output print Β«YesΒ» (without the quotes). In the second line print k integers b1,βb2,β...,βbkΒ β the selected numbers. If there are multiple possible solutions, print any of them. | First line contains three integers n, k and m (2ββ€βkββ€βnββ€β100β000, 1ββ€βmββ€β100β000)Β β number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1,βa2,β...,βan (0ββ€βaiββ€β109)Β β the numbers in the multiset. | standard output | standard input | Python 3 | Python | 1,300 | train_012.jsonl | b2db76c83a87a51fb05376832ef508bd | 512 megabytes | ["3 2 3\n1 8 4", "3 3 3\n1 8 4", "4 3 5\n2 7 7 7"] | PASSED | n,k,m = map(int,input().split())
arr = list(map(int,input().split()))
ans = {}
for i in arr:
if i%m not in ans:
ans[i%m] = [i]
else:
ans[i%m].append(i)
check = False
for i in ans:
if len(ans[i]) >= k:
check = True
break
if check:
print('Yes')
j = 0
while j<=k-1:
... | 1508151900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["6"] | db1c28e9ac6251353fbad8730f4705ea | null | You are given a rooted tree with n vertices. In each leaf vertex there's a single integer β the number of apples in this vertex. The weight of a subtree is the sum of all numbers in this subtree leaves. For instance, the weight of a subtree that corresponds to some leaf is the number written in the leaf.A tree is balan... | Print a single integer β the minimum number of apples to remove in order to make the tree balanced. Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the sin, cout streams cin, cout or the %I64d specifier. | The first line contains integer n (2ββ€βnββ€β105), showing the number of vertices in the tree. The next line contains n integers a1,βa2,β...,βan (0ββ€βaiββ€β108), ai is the number of apples in the vertex number i. The number of apples in non-leaf vertices is guaranteed to be zero. Then follow nβ-β1 lines, describing the t... | standard output | standard input | Python 2 | Python | 2,100 | train_038.jsonl | 45da84cab5cefd8816c9b1be2ee2db11 | 256 megabytes | ["6\n0 0 12 13 5 6\n1 2\n1 3\n1 4\n2 5\n2 6"] | PASSED | def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a // gcd(a, b) * b
def cal((f1, k1), (f2, k2)):
if f1 > f2:
f1, k1, f2, k2 = f2, k2, f1, k1
A = (f1 - f2) % k2
B = 0
x1 = 0
k11 = k1 % k2
k1x1 = 0
while B != A and k1x1 <= f1:
if B < ... | 1380295800 | [
"number theory",
"trees"
] | [
0,
0,
0,
0,
1,
0,
0,
1
] | |
2 seconds | ["3 1\n3 10\n3 15\n3 20\n3 25\n3 30\n1 1378716"] | abcafb310d4dcf3f7e34fc4eda1ee324 | NoteIn the first test case, the secret array $$$b$$$ is $$$[0, 1, 1, 1, 1, 1, 1, 1, 0]$$$. Array $$$c_1$$$ and array $$$c_2$$$ are generated by using operation 1. Array $$$c_3$$$ is generated by using operation 2.For Array $$$c_1$$$,you can choose $$$i=4$$$ and $$$j=5$$$ perform Operation 1 one time to generate it. For... | Eric has an array $$$b$$$ of length $$$m$$$, then he generates $$$n$$$ additional arrays $$$c_1, c_2, \dots, c_n$$$, each of length $$$m$$$, from the array $$$b$$$, by the following way:Initially, $$$c_i = b$$$ for every $$$1 \le i \le n$$$. Eric secretly chooses an integer $$$k$$$ $$$(1 \le k \le n)$$$ and chooses $$$... | For each test case, output one line containing two integers β the index of the special array, and the number of times that Operation 2 was performed on it. It can be shown that under the constraints given in the problem, this value is unique and won't exceed $$$10^{18}$$$, so you can represent it as a $$$64$$$-bit inte... | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) β the number of test cases. Description of test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$3 \leq n \leq 10^5$$$, $$$7 \leq m \leq 3 \cdot 10^5$$$) β the number of arrays given to you, and the ... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_089.jsonl | a0ce67748ddec0dbe81633a8141dd685 | 256 megabytes | ["7\n3 9\n0 1 2 0 0 2 1 1 0\n0 1 1 1 2 0 0 2 0\n0 1 2 0 0 1 2 1 0\n3 7\n25 15 20 15 25 20 20\n26 14 20 14 26 20 20\n25 15 20 15 20 20 25\n3 9\n25 15 20 15 25 20 20 20 20\n26 14 20 14 26 20 20 20 20\n25 15 20 15 25 15 20 20 25\n3 11\n25 15 20 15 25 20 20 20 20 20 20\n26 14 20 14 26 20 20 20 20 20 20\n25 15 20 15 25 20 1... | PASSED | from collections import Counter, deque, defaultdict
import math
from itertools import permutations, accumulate
from sys import *
from heapq import *
from bisect import bisect_left, bisect_right
from functools import cmp_to_key
from random import randint
xor = randint(10 ** 7, 10**8)
# https://docs.python.org/3/library/... | 1659276300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES", "NO"] | a37c3f2828490c70301b5b5deeee0f88 | NoteIn first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.In second example there are no love triangles. | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are n planes on Earth, numbered from 1 to n, and the plane with number i likes the plane with number fi, where 1ββ€βfiββ€βn and fiββ βi.We call a love triangle a situation in which plane A likes plane B... | Output Β«YESΒ» if there is a love triangle consisting of planes on Earth. Otherwise, output Β«NOΒ». You can output any letter in lower case or in upper case. | The first line contains a single integer n (2ββ€βnββ€β5000)Β β the number of planes. The second line contains n integers f1,βf2,β...,βfn (1ββ€βfiββ€βn, fiββ βi), meaning that the i-th plane likes the fi-th. | standard output | standard input | PyPy 2 | Python | 800 | train_002.jsonl | 43b71c4367751f48edcac07b986827ce | 256 megabytes | ["5\n2 4 5 1 3", "5\n5 5 5 5 1"] | PASSED | from sys import stdin, stdout
ti = lambda : stdin.readline().strip()
ma = lambda fxn, ti : map(fxn, ti.split())
ol = lambda arr : stdout.write(' '.join(str(i) for i in arr) + '\n')
os = lambda i : stdout.write(str(i) + '\n')
olws = lambda arr : stdout.write(''.join(str(i) for i in arr) + '\n')
n = int(ti())
f = ma(in... | 1518861900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["1869", "18690"] | 3b10e984d7ca6d4071fd4e743394bb60 | null | You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.Number a doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resulting ... | Print a number in the decimal notation without leading zeroes β the result of the permutation. If it is impossible to rearrange the digits of the number a in the required manner, print 0. | The first line contains positive integer a in the decimal record. It is guaranteed that the record of number a contains digits: 1, 6, 8, 9. Number a doesn't contain any leading zeroes. The decimal representation of number a contains at least 4 and at most 106 characters. | standard output | standard input | Python 2 | Python | 1,600 | train_020.jsonl | 72774130eeb0da55aae9b2085f94e21e | 256 megabytes | ["1689", "18906"] | PASSED | import itertools
import StringIO
def tonum(a):
return int("".join(map(str, a)))
def genDict():
nums = map(tonum, itertools.permutations([1,6,8,9]))
d = {}
for n in nums: d[n%7] = str(n)
return d
def solve(a, b, mod):
if b == 0:
return 0
for i in xrange(mod):
if (a*i-b)%mod... | 1387893600 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["12", "-1", "4"] | 4b4c7e7d9d5c45c8635b403bae997891 | NoteIn the first test, the minimal total number of sweets, which boys could have presented is equal to $$$12$$$. This can be possible, for example, if the first boy presented $$$1$$$ and $$$4$$$ sweets, the second boy presented $$$3$$$ and $$$2$$$ sweets and the third boy presented $$$1$$$ and $$$1$$$ sweets for the fi... | $$$n$$$ boys and $$$m$$$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $$$1$$$ to $$$n$$$ and all girls are numbered with integers from $$$1$$$ to $$$m$$$. For all $$$1 \leq i \leq n$$$ the minimal number of sweets, which $$... | If the described situation is impossible, print $$$-1$$$. In another case, print the minimal total number of sweets, which boys could have presented and all conditions could have satisfied. | The first line contains two integers $$$n$$$ and $$$m$$$, separated with spaceΒ β the number of boys and girls, respectively ($$$2 \leq n, m \leq 100\,000$$$). The second line contains $$$n$$$ integers $$$b_1, \ldots, b_n$$$, separated by spacesΒ β $$$b_i$$$ is equal to the minimal number of sweets, which $$$i$$$-th boy ... | standard output | standard input | Python 3 | Python | 1,500 | train_007.jsonl | ab6f9af8a3b4e2fb47926d1b510582d7 | 256 megabytes | ["3 2\n1 2 1\n3 4", "2 2\n0 1\n1 0", "2 3\n1 0\n1 1 2"] | PASSED | n, m = [int(i) for i in input().split()]
mins = [int(i) for i in input().split()]
maxs = [int(i) for i in input().split()]
temp = mins[:]
temp.sort()
pivot = temp[-1]
pivot2 = temp[-2]
ans = sum(mins)*m
ans += sum(maxs)
ans -= pivot*(m-1) + pivot2
bad = False
# for a in maxs:
# if a < pivot:
# bad = True... | 1557671700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["b", "Az", "tFrg4", "AB"] | bb6e2f728e1c7e24d86c9352740dea38 | NoteIn the first example during the first operation both letters 'a' are removed, so the string becomes "bc". During the second operation the letter 'c' (on the second position) is removed, and the string becomes "b".In the second example during the first operation Petya removes '0' from the second position. After that... | Petya has a string of length n consisting of small and large English letters and digits.He performs m operations. Each operation is described with two integers l and r and a character c: Petya removes from the string all characters c on positions between l and r, inclusive. It's obvious that the length of the string re... | Print the string Petya will obtain after performing all m operations. If the strings becomes empty after all operations, print an empty line. | The first string contains two integers n and m (1ββ€βn,βmββ€β2Β·105) β the length of the string and the number of operations. The second line contains the string of length n, consisting of small and large English letters and digits. Positions in the string are enumerated from 1. Each of the next m lines contains two integ... | standard output | standard input | PyPy 2 | Python | 2,100 | train_036.jsonl | ed8497e60d221c421f3dbee1f5052a0b | 256 megabytes | ["4 2\nabac\n1 3 a\n2 2 c", "3 2\nA0z\n1 3 0\n1 1 z", "10 4\nagtFrgF4aF\n2 5 g\n4 9 F\n1 5 4\n1 7 a", "9 5\naAAaBBccD\n1 4 a\n5 6 c\n2 3 B\n4 4 D\n2 3 A"] | PASSED | from collections import defaultdict
import sys
input = raw_input
range = xrange
def lower_bound(A, x):
a = 0
b = len(A)
while a < b:
c = (a + b) >> 1
if A[c] < x:
a = c + 1
else:
b = c
return a
def upper_bound(A, x):
a = 0
b = len(A)
while ... | 1513492500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["4", "0", "-8"] | c7cca8c6524991da6ea1b423a8182d24 | NoteIn the first example: d(a1,βa2)β=β0; d(a1,βa3)β=β2; d(a1,βa4)β=β0; d(a1,βa5)β=β2; d(a2,βa3)β=β0; d(a2,βa4)β=β0; d(a2,βa5)β=β0; d(a3,βa4)β=ββ-β2; d(a3,βa5)β=β0; d(a4,βa5)β=β2. | Let's denote a function You are given an array a consisting of n integers. You have to calculate the sum of d(ai,βaj) over all pairs (i,βj) such that 1ββ€βiββ€βjββ€βn. | Print one integer β the sum of d(ai,βaj) over all pairs (i,βj) such that 1ββ€βiββ€βjββ€βn. | The first line contains one integer n (1ββ€βnββ€β200000) β the number of elements in a. The second line contains n integers a1, a2, ..., an (1ββ€βaiββ€β109) β elements of the array. | standard output | standard input | Python 3 | Python | 2,200 | train_005.jsonl | c7b34015d82e882cfc2613b163a5f8b7 | 256 megabytes | ["5\n1 2 3 1 3", "4\n6 6 5 5", "4\n6 6 4 4"] | PASSED | n = int(input())
a = list(map(int,input().split()))
s = 0
mx = a[0]
dic = dict()
for i in range(n):
dic[a[i]] = 0
for i in range(n):
s = s - a[i]*(n-i-1) + a[i]*i
if a[i]-1 in dic:
s = s + dic[a[i]-1]*(a[i] - 1 - a[i])
if a[i]+1 in dic:
s = s + dic[a[i]+1]*(a[i] + 1 - a[i])
d = d... | 1513091100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1.532000000000\n1.860000000000\n5.005050776521\n4.260163673896"] | 738939f55bcc636c0340838818381d2f | NoteFor the first test case, the possible drawing sequences are: P with a probability of $$$0.6$$$; CP with a probability of $$$0.2\cdot 0.7 = 0.14$$$; CMP with a probability of $$$0.2\cdot 0.3\cdot 0.9 = 0.054$$$; CMMP with a probability of $$$0.2\cdot 0.3\cdot 0.1\cdot 1 = 0.006$$$; MP with a probability of $$$... | After defeating a Blacklist Rival, you get a chance to draw $$$1$$$ reward slip out of $$$x$$$ hidden valid slips. Initially, $$$x=3$$$ and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are $$$c$$$, $$$m$... | For each test case, output a single line containing a single real numberΒ β the expected number of races that you must play in order to draw a Pink Slip. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$... | The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 10$$$) Β β the number of test cases. The first and the only line of each test case contains four real numbers $$$c$$$, $$$m$$$, $$$p$$$ and $$$v$$$ ($$$0 < c,m,p < 1$$$, $$$c+m+p=1$$$, $$$0.1\leq v\leq 0.9$$$). Additionally, it is guaranteed... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_091.jsonl | 3903a36a38cfb3339b7c5038928ef924 | 256 megabytes | ["4\n0.2 0.2 0.6 0.2\n0.4 0.2 0.4 0.8\n0.4998 0.4998 0.0004 0.1666\n0.3125 0.6561 0.0314 0.2048"] | PASSED | from decimal import Decimal
import datetime
from functools import cache
class Solution:
@cache
def compute_ev(self, c, m, p, v) -> int:
ans = 1
#only compute probability from c if c > 0...else no need to compute
if c > 0:
if c > v:
red_c = v
else:
... | 1625668500 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
1 second | ["2\n3\n-1"] | f5bcde6e3008405f61cead4e3f44806e | NoteIn the first test case, the subarray $$$[2,3]$$$ has sum of elements $$$5$$$, which isn't divisible by $$$3$$$.In the second test case, the sum of elements of the whole array is $$$6$$$, which isn't divisible by $$$4$$$.In the third test case, all subarrays have an even sum, so the answer is $$$-1$$$. | Ehab loves number theory, but for some reason he hates the number $$$x$$$. Given an array $$$a$$$, find the length of its longest subarray such that the sum of its elements isn't divisible by $$$x$$$, or determine that such subarray doesn't exist.An array $$$a$$$ is a subarray of an array $$$b$$$ if $$$a$$$ can be obta... | For each testcase, print the length of the longest subarray whose sum isn't divisible by $$$x$$$. If there's no such subarray, print $$$-1$$$. | The first line contains an integer $$$t$$$ $$$(1 \le t \le 5)$$$Β β the number of test cases you need to solve. The description of the test cases follows. The first line of each test case contains 2 integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le x \le 10^4$$$)Β β the number of elements in the array $$$a$$... | standard output | standard input | PyPy 3 | Python | 1,200 | train_002.jsonl | 40d387ca3ba9c90847af71ccfdf27a0c | 256 megabytes | ["3\n3 3\n1 2 3\n3 4\n1 2 3\n2 2\n0 6"] | PASSED | ncases = int(input())
for i in range(ncases):
line1 = input().split(' ')
line2 = input().split(' ')
hate = int(line1[1])
arr = []
count = 0
for ele in line2:
ele = int(ele)
if (ele%hate == 0):
count += 1
arr.append(ele)
if (count == len(arr)):
pri... | 1592060700 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["010", "010", "0000000", "0011001100001011101000"] | a3c844e3ee6c9596f1ec9ab46c6ea872 | NoteIn the first example: For the substrings of the length $$$1$$$ the length of the longest non-decreasing subsequnce is $$$1$$$; For $$$l = 1, r = 2$$$ the longest non-decreasing subsequnce of the substring $$$s_{1}s_{2}$$$ is $$$11$$$ and the longest non-decreasing subsequnce of the substring $$$t_{1}t_{2}$$$ is $... | The only difference between easy and hard versions is the length of the string. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems.Kirk has a binary string $$$s$$$ (a string which consists of zeroes and ones) of length $$$n$$$ and he is asking you to find a ... | Output a binary string which satisfied the above conditions. If there are many such strings, output any of them. | The first line contains a binary string of length not more than $$$10^5$$$. | standard output | standard input | Python 3 | Python | 2,100 | train_006.jsonl | 1f4190a2a2f7dd0fd8eb8a41ba3d4591 | 256 megabytes | ["110", "010", "0001111", "0111001100111011101000"] | PASSED | data = [int(i) for i in input()]
n = len(data)
minval = [0]* n
minval[-1] = 2 * data[-1] - 1
for i in range(n-2, -1, -1):
if data[i] == 1:
minval[i] = min(1, minval[i+1] + 1)
else:
minval[i] = min(-1, minval[i+1] - 1)
ans = [i for i in data]
for i in range(n-1, -1, -1):
if minval[i] == 1... | 1566311700 | [
"math",
"strings"
] | [
0,
0,
0,
1,
0,
0,
1,
0
] | |
1 second | ["11.00000000000000000000", "5.00000000000000000000"] | d6e44bd8ac03876cb03be0731f7dda3d | NoteIn the first example, the maximum average is obtained by deleting the first element and increasing the second element four times.In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $$$2$$$ each. | Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations.Initially, there are $$$n$$$ superheroes in avengers team having powers $$$a_1, a_2, \ldots, a_n$$$, respectively. In one operat... | Output a single numberΒ β the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$$$. | The first line contains three integers $$$n$$$, $$$k$$$ and $$$m$$$ ($$$1 \le n \le 10^{5}$$$, $$$1 \le k \le 10^{5}$$$, $$$1 \le m \le 10^{7}$$$)Β β the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contai... | standard output | standard input | Python 3 | Python | 1,700 | train_009.jsonl | 327bb837a7e263317bafe00dda4c2e95 | 256 megabytes | ["2 4 6\n4 7", "4 2 6\n1 3 2 3"] | PASSED | n,k,m = input().split()
k = int(k)
m = int(m)
n = int(n)
niz = [int(n) for n in input().split()]
niz.sort()
suma = sum(niz)
curMax = (suma+min(m,n*k)) / n
for i in range(1,min(n-1,m)+1):
suma -= niz[i-1]
tempMax = (suma + min(m-i, (n-i)*k)) /(n-i)
if tempMax > curMax:
curMax = tempMax
print(curMax)
| 1549208100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["6\n4\n1\n3\n10"] | 091e91352973b18040e2d57c46f2bf8a | null | You are given $$$q$$$ queries in the following form:Given three integers $$$l_i$$$, $$$r_i$$$ and $$$d_i$$$, find minimum positive integer $$$x_i$$$ such that it is divisible by $$$d_i$$$ and it does not belong to the segment $$$[l_i, r_i]$$$.Can you answer all the queries?Recall that a number $$$x$$$ belongs to segmen... | For each query print one integer: the answer to this query. | The first line contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) β the number of queries. Then $$$q$$$ lines follow, each containing a query given in the format $$$l_i$$$ $$$r_i$$$ $$$d_i$$$ ($$$1 \le l_i \le r_i \le 10^9$$$, $$$1 \le d_i \le 10^9$$$). $$$l_i$$$, $$$r_i$$$ and $$$d_i$$$ are integers. | standard output | standard input | PyPy 3 | Python | 1,000 | train_007.jsonl | c0bc48891737715506189442883b5e64 | 256 megabytes | ["5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5"] | PASSED | q = int(input())
for q in range(0, q):
k = [int(a) for a in input().split()]
l = k[0]
r = k[1]
d = k[2]
if d < l or d > r:
x = d
else:
x = r - (r % d) + d
print(x)
| 1547217300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
5 seconds | ["0 25 60 40 20", "0 13 26 39 26 13"] | 9fc5a320b5b33deced64d7c571b313d5 | NoteThe minimum possible sum of times required to pass each road in the first example is $$$85$$$ β exactly one of the roads with passing time $$$25$$$ must be abandoned. Note that after one of these roads is abandoned, it's now impossible to travel between settlements $$$1$$$ and $$$3$$$ in time $$$50$$$. | Codefortia is a small island country located somewhere in the West Pacific. It consists of $$$n$$$ settlements connected by $$$m$$$ bidirectional gravel roads. Curiously enough, the beliefs of the inhabitants require the time needed to pass each road to be equal either to $$$a$$$ or $$$b$$$ seconds. It's guaranteed tha... | Output a single line containing $$$n$$$ integers. The $$$p$$$-th of them should denote the minimum possible time required to travel from $$$1$$$ to $$$p$$$ after the selected roads are abandoned. Note that for each $$$p$$$ you can abandon a different set of roads. | The first line of the input contains four integers $$$n$$$, $$$m$$$, $$$a$$$ and $$$b$$$ ($$$2 \leq n \leq 70$$$, $$$n - 1 \leq m \leq 200$$$, $$$1 \leq a < b \leq 10^7$$$) β the number of settlements and gravel roads in Codefortia, and two possible travel times. Each of the following lines contains three integers $... | standard output | standard input | Python 2 | Python | 3,000 | train_067.jsonl | 9fe53e729061e672fd941ae8d7f0fbf9 | 512 megabytes | ["5 5 20 25\n1 2 25\n2 3 25\n3 4 20\n4 5 20\n5 1 20", "6 7 13 22\n1 2 13\n2 3 13\n1 4 22\n3 4 13\n4 5 13\n5 6 13\n6 1 13"] | PASSED | import heapq
n,m,a,b=map(int,raw_input().split())
graph={i:[] for i in range(n)}
for i in range(m):
u,v,w=map(int,raw_input().split())
graph[u-1].append((v-1,w))
graph[v-1].append((u-1,w))
components=[-1]*n
comp=-1
for i in range(n):
if components[i]==-1:
comp+=1
components[i]=comp
... | 1556548500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["bncdenqbdr", "aaacaba"] | e70708f72da9a203b21fc4112ede9268 | NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1ββ€βiββ€β|s|, such that s1β=βt1,βs2β=βt2,β...,βsiβ-β1β=βtiβ-β1, and siβ<βti. | You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the le... | Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring. | The only line of the input contains the string s (1ββ€β|s|ββ€β100β000) consisting of lowercase English letters. | standard output | standard input | Python 3 | Python | 1,200 | train_000.jsonl | 91e764601631797e938f9b7ba6be3675 | 256 megabytes | ["codeforces", "abacaba"] | PASSED | a,s,iz='',input(),0
if set(s)=={'a'}:a+=s[:-1]+'z'
elif len(set(s))==1:a+=(chr(ord(s[0])-1))*len(s)
while len(a)!=len(s):
if s[len(a)]!='a':
a,iz=a+chr(ord(s[len(a)])-1),iz+1
elif s[len(a)]=='a' and iz<1:a+=s[len(a)]
else:a+=s[len(a):]
print(a)
| 1472056500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["10", "52", "131"] | c44554273f9c53d11aa1b0edeb121113 | NoteA bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: http... | Mahmoud and Ehab live in a country with n cities numbered from 1 to n and connected by nβ-β1 undirected roads. It's guaranteed that you can reach any city from any other using these roads. Each city has a number ai attached to it.We define the distance from city x to city y as the xor of numbers attached to the cities ... | Output one number denoting the total distance between all pairs of cities. | The first line contains integer n (1ββ€βnββ€β105) β the number of cities in Mahmoud and Ehab's country. Then the second line contains n integers a1,βa2,β...,βan (0ββ€βaiββ€β106) which represent the numbers attached to the cities. Integer ai is attached to the city i. Each of the next nββ-ββ1 lines contains two integers u a... | standard output | standard input | PyPy 2 | Python | 2,100 | train_069.jsonl | 40d132764e77b33986f4a65d633fe7e1 | 256 megabytes | ["3\n1 2 3\n1 2\n2 3", "5\n1 2 3 4 5\n1 2\n2 3\n3 4\n3 5", "5\n10 9 8 7 6\n1 2\n2 3\n3 4\n3 5"] | PASSED | import operator
n = input()
city_numbers = [0]
city_numbers.extend(map(int, raw_input().split()))
adjacent_cities = [[] for _ in xrange(n + 1)]
for _ in xrange(1, n):
u, v = map(int, raw_input().split())
adjacent_cities[u].append(v)
adjacent_cities[v].append(u)
city_bit_path_counts = [[0, 0] for _ in xrange(n + ... | 1486487100 | [
"math",
"trees"
] | [
0,
0,
0,
1,
0,
0,
0,
1
] | |
2 seconds | ["YES\n2 4 8 \nNO\nNO\nNO\nYES\n3 5 823"] | 0f7ceecdffe11f45d0c1d618ef3c6469 | null | You are given one integer number $$$n$$$. Find three distinct integers $$$a, b, c$$$ such that $$$2 \le a, b, c$$$ and $$$a \cdot b \cdot c = n$$$ or say that it is impossible to do it.If there are several answers, you can print any.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer on it. Print "NO" if it is impossible to represent $$$n$$$ as $$$a \cdot b \cdot c$$$ for some distinct integers $$$a, b, c$$$ such that $$$2 \le a, b, c$$$. Otherwise, print "YES" and any possible such representation. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. The next $$$n$$$ lines describe test cases. The $$$i$$$-th test case is given on a new line as one integer $$$n$$$ ($$$2 \le n \le 10^9$$$). | standard output | standard input | Python 3 | Python | 1,300 | train_005.jsonl | 8842322a670790c54ce36c85751dc47e | 256 megabytes | ["5\n64\n32\n97\n2\n12345"] | PASSED | def factors(n):
factor = []
for i in range(2, int(n**0.5)+1):
if n % i == 0:
factor.append(i)
return factor
t = int(input())
for l in range(t):
n = int(input())
x = 0
factor = factors(n)
lenfactor = len(factor)
for i in range(lenfactor):
for j in range(i+1, ... | 1579703700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["2", "23", "1"] | f898d3a58e0ae6ac07d0d14620d47d27 | NoteIn the first example, the strings we are interested in are $$$[1\, 2\, 2]$$$ and $$$[2\, 1\, 2]$$$. The string $$$[2\, 2\, 1]$$$ is lexicographically larger than the string $$$[2\, 1\, 2\, 1]$$$, so we don't count it.In the second example, all strings count except $$$[4\, 3\, 2\, 1]$$$, so the answer is $$$4! - 1 =... | While looking at the kitchen fridge, the little boy Tyler noticed magnets with symbols, that can be aligned into a string $$$s$$$.Tyler likes strings, and especially those that are lexicographically smaller than another string, $$$t$$$. After playing with magnets on the fridge, he is wondering, how many distinct string... | Print a single numberΒ β the number of strings lexicographically smaller than $$$t$$$ that can be obtained by rearranging the letters in $$$s$$$, modulo $$$998\,244\,353$$$. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 200\,000$$$)Β β the lengths of strings $$$s$$$ and $$$t$$$ respectively. The second line contains $$$n$$$ integers $$$s_1, s_2, s_3, \ldots, s_n$$$ ($$$1 \le s_i \le 200\,000$$$)Β β letters of the string $$$s$$$. The third line contains $$$m$$$ i... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_091.jsonl | ecc14ace4b8f29d14fae45f6e540df95 | 256 megabytes | ["3 4\n1 2 2\n2 1 2 1", "4 4\n1 2 3 4\n4 3 2 1", "4 3\n1 1 1 2\n1 1 2"] | PASSED | from __future__ import print_function
from bisect import bisect_left, bisect_right, insort
from collections import Sequence, MutableSequence
from functools import wraps
from itertools import chain, repeat, starmap
from math import log as log_e
import operator as op
from operator import iadd, add
from sys impo... | 1646560500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["10", "7"] | cfdbe4bd1c9438de2d871768c546a580 | NoteCells, reachable in the corresponding example, are marked with '+'.First example: +++..+***.+++***+++. Second example: .++..+*..++..++. | You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cell is in the row r and column c. In one step you can move one square up, left, down or right, if the target cell is not o... | Print exactly one integerΒ β the number of cells in the labyrinth, which are reachable from starting cell, including the starting cell itself. | The first line contains two integers n, m (1ββ€βn,βmββ€β2000)Β β the number of rows and the number columns in the labyrinth respectively. The second line contains two integers r, c (1ββ€βrββ€βn, 1ββ€βcββ€βm)Β β index of the row and index of the column that define the starting cell. The third line contains two integers x, y (0β... | standard output | standard input | PyPy 2 | Python | 1,800 | train_008.jsonl | 72c98a58dd43ef40436c0cf295743244 | 512 megabytes | ["4 5\n3 2\n1 2\n.....\n.***.\n...**\n*....", "4 4\n2 2\n0 1\n....\n..*.\n....\n...."] | PASSED | from collections import defaultdict,deque
n,m=[int(el) for el in raw_input().split()]
r,c=[int(el) for el in raw_input().split()]
x,y=[int(el) for el in raw_input().split()]
s=['*'*(m+2)]
for i in range(n):
q=raw_input()
w='*'+q+'*'
s.append(w)
s.append('*'*(m+2))
def bfs(way):
ans=0
while len(wa... | 1539511500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
4 seconds | ["? 7 3 5\n\n? 1 6 4\n\n? 1 5 4\n\n! 4"] | f413f65186ec202bc75809985fba1222 | NoteThe labels corresponding to the tree in the example are [$$$4$$$,$$$7$$$,$$$2$$$,$$$6$$$,$$$1$$$,$$$5$$$,$$$3$$$], meaning the root is labelled $$$4$$$, and for $$$1 < i \le n$$$, the parent of $$$p_i$$$ is $$$p_{ \lfloor{\frac{i}{2}}\rfloor }$$$. | This is an interactive problem.Igor wants to find the key to Olha's heart. The problem is, that it's at the root of a binary tree.There is a perfect binary tree of height $$$h$$$ consisting of $$$n = 2^{h} - 1$$$ nodes. The nodes have been assigned distinct labels from $$$1$$$ to $$$n$$$. However, Igor only knows $$$h$... | null | The first and only line contains a single integer $$$h$$$ ($$$3 \le h \le 18$$$)Β β the height of the tree. | standard output | standard input | Python 3 | Python | 3,000 | train_070.jsonl | 937adcfff09bc0c293d167316a00f8fb | 256 megabytes | ["3\n\n2\n\n7\n\n4"] | PASSED | import sys,random
def main():
h = int(input());power = [1];askarray = [];askarrayind = []
for i in range(h+1):power.append(power[-1] * 2)
for j in range(0, power[h]):askarrayind.append([0, j])
n = power[h] - 1;askcnt = 420
for i in range(askcnt):
a = random.randint(1, n);b = random.randi... | 1605278100 | [
"probabilities",
"trees"
] | [
0,
0,
0,
0,
0,
1,
0,
1
] | |
5 seconds | ["500000004\n1\n500000004", "625000011\n13\n62500020\n375000027\n62500027"] | cdf42ae9f76a36295c701b0606ea5bfc | NoteIn first testcase, initially, there are four possible battalions {} Strength = $$$0$$$ {$$$1$$$} Strength = $$$0$$$ {$$$2$$$} Strength = $$$0$$$ {$$$1,2$$$} Strength = $$$2$$$ So strength of army is $$$\frac{0+0+0+2}{4}$$$ = $$$\frac{1}{2}$$$After changing $$$p_{1}$$$ to $$$2$$$, strength of battallion {$$$1,... | There are $$$n$$$ officers in the Army of Byteland. Each officer has some power associated with him. The power of the $$$i$$$-th officer is denoted by $$$p_{i}$$$. As the war is fast approaching, the General would like to know the strength of the army.The strength of an army is calculated in a strange way in Byteland. ... | In the first line output the initial strength of the army. In $$$i$$$-th of the next $$$q$$$ lines, output the strength of the army after $$$i$$$-th update. | The first line of the input contains a single integer $$$n$$$ ($$$1 \leq n \leq 3β
10^{5}$$$) Β β the number of officers in Byteland's Army. The second line contains $$$n$$$ integers $$$p_{1},p_{2},\ldots,p_{n}$$$ ($$$1 \leq p_{i} \leq 10^{9}$$$). The third line contains a single integer $$$q$$$ ($$$1 \leq q \leq 3β
10^{5... | standard output | standard input | PyPy 2 | Python | 2,800 | train_070.jsonl | 9c11f8f3a484509b7dfcd0b39691ed80 | 256 megabytes | ["2\n1 2\n2\n1 2\n2 1", "4\n1 2 3 4\n4\n1 5\n2 5\n3 5\n4 5"] | PASSED | import sys, os
range = xrange
input = raw_input
import __pypy__
mulmod = __pypy__.intop.int_mulmod
sub = __pypy__.intop.int_sub
mul = __pypy__.intop.int_mul
MOD = 10**9 + 7
MODINV = 1.0/MOD
def mulmod(a,b):
x = sub(mul(a,b), mul(MOD, int(a * MODINV * b)))
return x + MOD if (x < 0) else (x if x < MOD else x ... | 1583332500 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
1 second | ["1\n0\n2"] | 475a24d36eab99ae4f78815ccdc5da91 | NoteIn the first test case it's possible to make all ratings equal to $$$69$$$. First account's rating will increase by $$$1$$$, and second account's rating will decrease by $$$1$$$, so the sum of all changes will be equal to zero.In the second test case all accounts will be instantly infected, because all ratings (inc... | A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).Killjoy's account is already infected and has a rating equal to $$$x$$$. Its rating is constant. There are $$$n$$$ accounts except he... | For each test case output the minimal number of contests needed to infect all accounts. | The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$Β β the number of test cases. The next $$$2t$$$ lines contain the descriptions of all test cases. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$2 \le n \le 10^3$$$, $$$-4000 \le x \le 4000$$$)Β β the number of account... | standard output | standard input | PyPy 3 | Python | 1,500 | train_006.jsonl | d6ca80729f2e61fdd0b09578dac11561 | 256 megabytes | ["3\n2 69\n68 70\n6 4\n4 4 4 4 4 4\n9 38\n-21 83 50 -59 -77 15 -71 -78 20"] | PASSED | from collections import defaultdict
t = int(input())
for _ in range(t):
n,x = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
dic = defaultdict(lambda:0)
d = 0
c = 0
for i in range(n):
d+=(l[i]==x)
c+=l[i]-x
if d==n:
print(0)
elif c==0:
... | 1600526100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3", "6", "0"] | 9202022089083f17e7165c6c1e53f2e1 | NoteIn the first sample there are three suitable pairs: $$$(1; 9)$$$, $$$(3; 3)$$$ and $$$(9; 1)$$$.In the second sample case there are 6 suitable pairs: $$$(2; 220)$$$, $$$(4; 110)$$$, $$$(8; 55)$$$, $$$(10; 44)$$$, $$$(20; 22)$$$ and $$$(40; 11)$$$.Here the sample of cut for $$$(20; 22)$$$. The third sample has no s... | A rectangle with sides $$$A$$$ and $$$B$$$ is cut into rectangles with cuts parallel to its sides. For example, if $$$p$$$ horizontal and $$$q$$$ vertical cuts were made, $$$(p + 1) \cdot (q + 1)$$$ rectangles were left after the cutting. After the cutting, rectangles were of $$$n$$$ different types. Two rectangles are... | Output one integerΒ β the answer to the problem. | The first line consists of a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^{5}$$$)Β β amount of different types of rectangles left after cutting the initial rectangle. The next $$$n$$$ lines each consist of three integers $$$w_{i}, h_{i}, c_{i}$$$ $$$(1 \leq w_{i}, h_{i}, c_{i} \leq 10^{12})$$$Β β the lengths of th... | standard output | standard input | Python 2 | Python | 2,600 | train_040.jsonl | e75420a72c669da6c14313a2d7a89b7b | 256 megabytes | ["1\n1 1 9", "2\n2 3 20\n2 4 40", "2\n1 2 5\n2 3 5"] | PASSED | n = input()
w=[]
h=[]
c=[]
cntw={}
cnth={}
gcdC=0
cntC=0
def insert1(a,b,c):
if not a in b :
b[a]=c
else :
b[a]=b[a]+c
def gcd(a,b):
if a % b == 0 :
return b
else :
return gcd(b,a%b)
for i in range(0, n):
a,b,d = map(int, raw_input().split())
w.append(a)
h.append(b)
c.append(d)
insert1(a,cntw,d)
... | 1523973900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n2 1", "4\n1 2 2 1"] | 080287f34b0c1d52eb29eb81dada41dd | NoteIn the first test case Valera can put the first cube in the first heap, and second cube β in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is e... | Valera has 2Β·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from... | In the first line print a single number β the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2Β·n numbers bi (1ββ€βbiββ€β2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, ... | The first line contains integer n (1ββ€βnββ€β100). The second line contains 2Β·n space-separated integers ai (10ββ€βaiββ€β99), denoting the numbers on the cubes. | standard output | standard input | Python 3 | Python | 1,900 | train_009.jsonl | 9d17da0965a1769fbadef3c81ca29a6c | 256 megabytes | ["1\n10 99", "2\n13 24 13 45"] | PASSED | from math import*
from random import*
n = int(input()) * 2
A = list(map(int, input().split()))
amount = [0] * 101
B = []
for i in range(n):
if amount[A[i]] < 2:
amount[A[i]] += 1
B += [(A[i], i)]
B.sort()
x, y = [], []
for i in range(len(B)):
if(i % 2 == 0):
x.append(B[i][1])
else:... | 1381419000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["3\n1 2 4", "4\n1 2 4 6", "3\n1 3 5"] | 31b929252f7d63cb3654ed367224cc31 | null | Recently Irina arrived to one of the most famous cities of BerlandΒ β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.Initially Irina s... | Print the single integer k (2ββ€βkββ€βn)Β β the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line. Print k distinct integers in the second lineΒ β indices of showplaces that Irina will visit on her route, in the order of encou... | The first line of the input contains three integers n,βm and T (2ββ€βnββ€β5000,ββ1ββ€βmββ€β5000,ββ1ββ€βTββ€β109)Β β the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively. The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui,βvi,βti (1ββ€βui... | standard output | standard input | PyPy 3 | Python | 1,800 | train_039.jsonl | 8545bda8903e6a7207f8039f80ae388a | 256 megabytes | ["4 3 13\n1 2 5\n2 3 7\n2 4 8", "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1", "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2"] | PASSED | from sys import stdin, stdout
# LinkedList.py
class LLNode:
def __init__(self, value = None, nextNode = None):
self.value, self.nextNode = value, nextNode
class LinkedList:
def __init__(self, rootNode = None):
self.rootNode = rootNode
def FindBestPath(self, wayTime):
cNode = self.... | 1475244300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["abdc\na\nb\ndeforces\ncf\nxyzzw"] | adbaa266446e6d8d95a6cbc0b83cc7c7 | NoteThe first test case is explained in the statement.In the second test case, no operations can be performed on $$$s$$$.In the third test case, Initially, $$$s =$$$ "bbbbbbbbbb". After $$$1$$$ operation, $$$s =$$$ "b". In the fourth test case, Initially, $$$s =$$$ "codeforces". After $$$1$$$ operation, $$$s =$$$... | You are given a string $$$s$$$ consisting of lowercase letters of the English alphabet. You must perform the following algorithm on $$$s$$$: Let $$$x$$$ be the length of the longest prefix of $$$s$$$ which occurs somewhere else in $$$s$$$ as a contiguous substring (the other occurrence may also intersect the prefix). ... | For each test case, print a single line containing the string $$$s$$$ after executing the algorithm. It can be shown that such string is non-empty. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases. This is followed by $$$t$$$ lines, each containing a description of one test case. Each line contains a string $$$s$$$. The given strings consist only of lowercase letters of the English alphabet and have lengths betwe... | standard output | standard input | Python 3 | Python | 800 | train_102.jsonl | 9381cf628dd4afece180abe9c3117707 | 256 megabytes | ["6\nabcabdc\na\nbbbbbbbbbb\ncodeforces\ncffcfccffccfcffcfccfcffccffcfccf\nzyzyzwxxyyxxyyzzyzzxxwzxwywxwzxxyzzw"] | PASSED | t = int(input())
while (t > 0):
t -= 1
s1 = str(input())
s2 = ""
i = 0
mn = set()
while True:
if (s1[-i-1] not in mn):
s2 = s1[-i-1:]
mn.add(s1[-i-1])
i += 1
if i == len(s1):
break
print(s2) | 1647764100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["010\n011001010"] | fd3fad7de3068889e676e68551c00a0f | NoteIn the first test case, the bitstrings 00 and 01 are subsequences of the output string: 010 and 010. Note that 11 is not a subsequence of the output string, but this is not required.In the second test case all three input strings are subsequences of the output string: 011001010, 011001010 and 011001010. | A bitstring is a string that contains only the characters 0 and 1.Koyomi Kanou is working hard towards her dream of becoming a writer. To practice, she decided to participate in the Binary Novel Writing Contest. The writing prompt for the contest consists of three bitstrings of length $$$2n$$$. A valid novel for the co... | For each test case, print a single line containing a bitstring of length at most $$$3n$$$ that has at least two of the given bitstrings as subsequences. It can be proven that under the constraints of the problem, such a bitstring always exists. If there are multiple possible answers, you may output any of them. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). Each of the following three lines contains a bitstring of length $$$2n$$$. It is guaranteed that these three strings are pair... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_087.jsonl | f7d0d8172376c8ddf483da75a11248a7 | 256 megabytes | ["2\n1\n00\n11\n01\n3\n011001\n111010\n010001"] | PASSED | import sys
input = lambda : sys.stdin.readline().rstrip()
write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO)
LI = lambda : list(map(int, input().split()))
# sys.setrecur... | 1618583700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["RBRBR\n-1\nBBRRRRBB\nBR"] | 2e01de6090e862f7f18a47dcbcb3be53 | NoteThe first test case is considered in the statement.In the second test case, there are no even digits, so it is impossible to form a number from its digits that is divisible by $$$2$$$.In the third test case, each coloring containing at least one red and one black digit is possible, so you can color $$$4$$$ digits i... | It is given a non-negative integer $$$x$$$, the decimal representation of which contains $$$n$$$ digits. You need to color each its digit in red or black, so that the number formed by the red digits is divisible by $$$A$$$, and the number formed by the black digits is divisible by $$$B$$$.At least one digit must be col... | For each test case, output in a separate line: -1 if the desired coloring does not exist; a string $$$s$$$ of $$$n$$$ characters, each of them is a letter 'R' or 'B'. If the $$$i$$$-th digit of the number $$$x$$$ is colored in red, then the $$$i$$$-th character of the string $$$s$$$ must be the letter 'R', otherwise... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10$$$) β the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of two lines. The first line contains three integers $$$n$$$, $$$A$$$, $$$B$$$ ($$$2 \le n \le 40$$$, $$$1 \le A, B \le 40$$$). The second line contains a non-negative i... | standard output | standard input | PyPy 3-64 | Python | 2,100 | train_093.jsonl | 46ccfba2ed8cab9322fc62e5be626f3a | 256 megabytes | ["4\n5 3 13\n02165\n4 2 1\n1357\n8 1 1\n12345678\n2 7 9\n90"] | PASSED | import sys
import io, os
input = sys.stdin.readline
from collections import defaultdict
def main():
t = int(input())
for _ in range(t):
n, a, b = map(int, input().split())
s = list(str(input().rstrip()))
s = [int(c) for c in s]
dp = [-1]*(a*b*(n+1)*(n+1))
... | 1634135700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["4\n5 3", "0", "0"] | 2510469c09d7d145078e65de81640ddc | NoteIn the first test, one of the transforms might be as follows: $$$39 \to 56 \to 57 \to 62 \to 63$$$. Or more precisely: Pick $$$n = 5$$$. $$$x$$$ is transformed into $$$39 \oplus 31$$$, or $$$56$$$. Increase $$$x$$$ by $$$1$$$, changing its value to $$$57$$$. Pick $$$n = 3$$$. $$$x$$$ is transformed into $$$57 \op... | Cat Furrier Transform is a popular algorithm among cat programmers to create longcats. As one of the greatest cat programmers ever exist, Neko wants to utilize this algorithm to create the perfect longcat.Assume that we have a cat with a number $$$x$$$. A perfect longcat is a cat with a number equal $$$2^m - 1$$$ for s... | The first line should contain a single integer $$$t$$$ ($$$0 \le t \le 40$$$)Β β the number of operations to apply. Then for each odd-numbered operation print the corresponding number $$$n_i$$$ in it. That is, print $$$\lceil \frac{t}{2} \rceil$$$ integers $$$n_i$$$ ($$$0 \le n_i \le 30$$$), denoting the replacement $$$... | The only line contains a single integer $$$x$$$ ($$$1 \le x \le 10^6$$$). | standard output | standard input | Python 3 | Python | 1,300 | train_003.jsonl | db1e026064c77fad1e42b3310fb6c56f | 256 megabytes | ["39", "1", "7"] | PASSED |
from math import log2,log,ceil
def A(x):
# x==2**m => log2(x)==m*log2(2) => log2(x)==m
n=ceil(log2(x))
n=int(n)
kk=2**n-1
return x^kk,n
def B(x):
return x+1
def check(num):
num+=1
mm=log(num)/log(2)
q=int(mm)
if mm-q==0:
return True
return False
t=0
f=True
ans=[]
... | 1556116500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["Bob\nBob\nAlice\nAlice\nAlice\nAlice\nBob\nBob"] | 9b9b85f84636ebd0f7af8b410d9820f7 | NoteIn the notes, the cell numbers increase from left to right.In the first testcase for Alice, she has two choices: paint the first and the second cells, or paint the second and the third cells. No matter what choice Alice makes, there will be exactly one blue cell after Alice's move. Bob just needs to paint the blue ... | Alice and Bob are playing a game. There are $$$n$$$ cells in a row. Initially each cell is either red or blue. Alice goes first.On each turn, Alice chooses two neighbouring cells which contain at least one red cell, and paints that two cells white. Then, Bob chooses two neighbouring cells which contain at least one blu... | For each test case, output the name of the winner on a separate line. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) β the number of test cases. Description of test cases follows. For each test case, the first line contains an integer $$$n$$$ ($$$2 \leq n \leq 5 \cdot 10^5$$$) β the number of cells. The second line contains a string $$$s$$$ of length $$$n$$$ ... | standard output | standard input | PyPy 3-64 | Python | 2,600 | train_089.jsonl | 09499dc06366b260eab635056821d431 | 256 megabytes | ["8\n\n3\n\nBRB\n\n5\n\nRRBBB\n\n6\n\nRBRBRB\n\n8\n\nBBRRBRRB\n\n6\n\nBRRBRB\n\n12\n\nRBRBRBRBRRBB\n\n12\n\nRBRBRBRBBBRR\n\n4\n\nRBBR"] | PASSED | nimv = [1] * 500
def mex(x):
x.sort()
c=0
for i in x:
if i == c:
c += 1
return c
cnts = [4,4,4,24,4,4,4,14]
nimv[:3]= [0,1,1]
cp = 0
ci = 4
for i in range(3,500):
nimv[i]=mex([nimv[i-2]] + [nimv[i-j-3] ^ nimv[j] for j in range(i-2)])
q = nimv[-34*3:]
for i in range... | 1659276300 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2.5 seconds | ["0.680000000000000"] | 9b05933b72dc24d743cb59978f35c8f3 | null | The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each b... | Output a real numberΒ β the probability that Jedi Ivan will stay alive after the Tournament. Absolute or relative error of the answer must not exceed 10β-β6. | The first line contains a single integer n (1ββ€βnββ€β18)Β β the number of participants of the Sith Tournament. Each of the next n lines contains n real numbers, which form a matrix pij (0ββ€βpijββ€β1). Each its element pij is the probability that the i-th participant defeats the j-th in a duel. The elements on the main dia... | standard output | standard input | Python 2 | Python | 2,200 | train_008.jsonl | 21239c08c39f13a58961faf8ad7cba0e | 256 megabytes | ["3\n0.0 0.5 0.8\n0.5 0.0 0.4\n0.2 0.6 0.0"] | PASSED | import math
import sys
n=int(raw_input())
A=[]
#print "hi"
#sys.stdout.flush()
for j in range(n):
A+=[[float(x) for x in raw_input().split()]]
#print "hi"
while(True):
#print n
#print A
if n==1:
print "1.0"
break
if n==2:
print A[0][1]
break
M=0
j0=1
for j... | 1465834200 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
2 seconds | ["6", "8", "4"] | 3f3a013cedaaf8cbee0a74a4ed50f09d | NoteIn the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes): $$$(2, 3)$$$; $$$(5, 6)$$$; $$$(1, 4)$$$. So the answer is $$$6$$$.In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding bo... | International Women's Day is coming soon! Polycarp is preparing for the holiday.There are $$$n$$$ candy boxes in the shop for sale. The $$$i$$$-th box contains $$$d_i$$$ candies.Polycarp wants to prepare the maximum number of gifts for $$$k$$$ girls. Each gift will consist of exactly two boxes. The girls should be able... | Print one integer β the maximum number of the boxes Polycarp can give as gifts. | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le k \le 100$$$) β the number the boxes and the number the girls. The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^9$$$), where $$$d_i$$$ is the number of candies ... | standard output | standard input | Python 3 | Python | 1,200 | train_015.jsonl | a2d7d0d5cfbbaef286670a8539128300 | 256 megabytes | ["7 2\n1 2 2 3 2 4 10", "8 2\n1 2 2 3 2 4 6 10", "7 3\n1 2 2 3 2 4 5"] | PASSED | n, k = map(int, input().split(' '))
gifts = sorted(list(map(lambda cnd: int(cnd) % k, input().split())))
equal_classes = [0] * (k)
etalon = gifts[0]
for g in gifts:
if g == etalon:
equal_classes[g] += 1
else:
etalon = g
equal_classes[g] += 1
ans = equal_classes[0] - equal_classes[0] % 2
... | 1551971100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["2", "1"] | 1b2a2c8afcaf16b4055002a9511c6f23 | NoteIn the first example Pavel can change the permutation to 4,β3,β1,β2.In the second example Pavel can change any element of b to 1. | Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the reversed direction.Pavel has a plan: a permutation p and a sequence b1,βb2,β..... | Print single integerΒ β the minimum total number of elements in the given permutation p and the given sequence b he needs to change so that every skewer will visit each of 2n placements. | The first line contain the integer n (1ββ€βnββ€β2Β·105)Β β the number of skewers. The second line contains a sequence of integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β the permutation, according to which Pavel wants to move the skewers. The third line contains a sequence b1,βb2,β...,βbn consisting of zeros and ones, according to ... | standard output | standard input | Python 3 | Python | 1,700 | train_039.jsonl | 935797494e157cb3f664fb8fe267a91b | 256 megabytes | ["4\n4 3 2 1\n0 1 1 1", "3\n2 3 1\n0 0 0"] | PASSED | import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())
p = list(map(int, input().split()))
b = list(map(int, input().split()))
used = [False] * n
comp = 0
for i in range(n):
if not used[i]:
u = i
while True:
used[u] = True
v = p[u] - 1
if not used[v]:
... | 1485108900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["Yes", "Yes", "No", "No", "No"] | c5ec8b18c39720098f6ac2dbc0ddd4f4 | NoteIn the first example $$$3! + 2! + 2! + 2! + 3! + 3! = 6 + 2 + 2 + 2 + 6 + 6 = 24$$$. Number $$$24$$$ is divisible by $$$4! = 24$$$.In the second example $$$3! + 2! + 2! + 2! + 2! + 2! + 1! + 1! = 18$$$, is divisible by $$$3! = 6$$$.In the third example $$$7! + 7! + 7! + 7! + 7! + 7! + 7! = 7 \cdot 7!$$$. It is easy... | You are given an integer $$$x$$$ and an array of integers $$$a_1, a_2, \ldots, a_n$$$. You have to determine if the number $$$a_1! + a_2! + \ldots + a_n!$$$ is divisible by $$$x!$$$.Here $$$k!$$$ is a factorial of $$$k$$$Β β the product of all positive integers less than or equal to $$$k$$$. For example, $$$3! = 1 \cdot... | In the only line print "Yes" (without quotes) if $$$a_1! + a_2! + \ldots + a_n!$$$ is divisible by $$$x!$$$, and "No" (without quotes) otherwise. | The first line contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 500\,000$$$, $$$1 \le x \le 500\,000$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le x$$$)Β β elements of given array. | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_100.jsonl | c3236abe16ad94ae830b7995b9ce46f9 | 256 megabytes | ["6 4\n3 2 2 2 3 3", "8 3\n3 2 2 2 2 2 1 1", "7 8\n7 7 7 7 7 7 7", "10 5\n4 3 2 1 4 3 2 4 3 4", "2 500000\n499999 499999"] | PASSED | n,val=map(int,input().split())
if val==1:
print('Yes')
else:
numeri=list(map(int,input().split()))
m=min(numeri)
occorrenze=[0]*(val-m+1)
for i in numeri:
occorrenze[i-m]=occorrenze[i-m]+1
for j in range(len(occorrenze)-1):
if occorrenze[j]%(j+m+1)!=0:
... | 1666511400 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["5", "4"] | a39b2ed9165d4aa3dc8dd60bf0ad47f3 | NoteOn the first example, Kuro can choose these pairs: $$$(1, 2)$$$: his route would be $$$1 \rightarrow 2$$$, $$$(2, 3)$$$: his route would be $$$2 \rightarrow 3$$$, $$$(3, 2)$$$: his route would be $$$3 \rightarrow 2$$$, $$$(2, 1)$$$: his route would be $$$2 \rightarrow 1$$$, $$$(3, 1)$$$: his route would be $$... | Kuro is living in a country called Uberland, consisting of $$$n$$$ towns, numbered from $$$1$$$ to $$$n$$$, and $$$n - 1$$$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $$$a$$$ and $$$b$$$. Kuro loves walking and he is planning to take a walk... | A single integer resembles the number of pair of towns $$$(u, v)$$$ that Kuro can use as his walking route. | The first line contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 3 \cdot 10^5$$$, $$$1 \leq x, y \leq n$$$, $$$x \ne y$$$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively. $$$n - 1$$$ lines follow, each line contains two integers $$$a$$$ and $$$b$$$ ($... | standard output | standard input | Python 3 | Python | 1,600 | train_030.jsonl | d95a7a522835b5439ceb5f508b43471e | 256 megabytes | ["3 1 3\n1 2\n2 3", "3 1 3\n1 2\n1 3"] | PASSED | from collections import defaultdict
n,x,y = list(map(int,input().split()))
graph = defaultdict(list)
vis = [False for i in range(n+1)]
mat = [False for i in range(n+1)]
subtree = [0 for i in range(n+1)]
for i in range(n-1):
u,v = list(map(int,input().split()))
graph[u].append(v)
graph[v].append(u)
q = []
cur = 0
f... | 1526308500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["dbcadabcdbcadabc", "aaaaa"] | 87f64b4d5baca4b80162ae6075110b00 | NoteIn the first test, it is optimal to make one duplication: "dbcadabc" $$$\to$$$ "dbcadabcdbcadabc".In the second test it is optimal to delete the last $$$3$$$ characters, then duplicate the string $$$3$$$ times, then delete the last $$$3$$$ characters to make the string have length $$$k$$$."abcd" $$$\to$$$ "abc" $$$... | This is the easy version of the problem. The only difference is the constraints on $$$n$$$ and $$$k$$$. You can make hacks only if all versions of the problem are solved.You have a string $$$s$$$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $$$s:=s+s$$... | Print the lexicographically smallest string of length $$$k$$$ that can be obtained by doing the operations on string $$$s$$$. | The first line contains two integers $$$n$$$, $$$k$$$ ($$$1 \leq n, k \leq 5000$$$) β the length of the original string $$$s$$$ and the length of the desired string. The second line contains the string $$$s$$$, consisting of $$$n$$$ lowercase English letters. | standard output | standard input | Python 3 | Python | 1,600 | train_084.jsonl | c6a3c2f86764a668eff2348ce7c8057f | 256 megabytes | ["8 16\ndbcadabc", "4 5\nabcd"] | PASSED | import sys
data1 = sys.stdin.read()
import copy
import math
data = data1.split("\n")
f1 = data[0].split(' ')
n = int(f1[0])
k = f1[1]
string1 = list(data[1])
string1.append(" ")
final = list()
def check():
for t in range(0, n - 1):
if t == n-1:
return t
if ord(string1[t]) ... | 1624026900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["FHTAGN!", "NO"] | 4ecbfc792da55f458342c6eff2d5da5a | NoteLet us denote as a simple cycle a set of v vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., vβ-β1 and v, v and 1.A tree is a connected undirected graph consisting of n vertices and nβ-β1 edges (nβ>β0).A rooted tree is a tree where one vertex is select... | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super w... | Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is. | The first line contains two integers β the number of vertices n and the number of edges m of the graph (1ββ€βnββ€β100, 0ββ€βmββ€β). Each of the following m lines contains a pair of integers x and y, that show that an edge exists between vertices x and y (1ββ€βx,βyββ€βn,βxββ βy). For each pair of vertices there will be at most... | standard output | standard input | Python 3 | Python | 1,500 | train_034.jsonl | 77edf9b292ae441dd31c3b8416860ee6 | 256 megabytes | ["6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4", "6 5\n5 6\n4 6\n3 1\n5 1\n1 2"] | PASSED | def findSet(u):
if parent[u] != u:
parent[u] = findSet(parent[u])
return parent[u]
def unionSet(u, v):
up = findSet(u)
vp = findSet(v)
if up == vp:
return
if ranks[up] > ranks[vp]:
parent[vp] = up
elif ranks[up] < ranks[vp]:
parent[up] = vp
else:
... | 1312714800 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1 1 2 2 3 4 5 6", "0 1 0 1 1 1 1 2 2 2"] | c5f137635a6c0d1c96b83de049e7414a | NoteLet's look at the first example:Ways to reach the point $$$1$$$: $$$[0, 1]$$$;Ways to reach the point $$$2$$$: $$$[0, 2]$$$;Ways to reach the point $$$3$$$: $$$[0, 1, 3]$$$, $$$[0, 3]$$$;Ways to reach the point $$$4$$$: $$$[0, 2, 4]$$$, $$$[0, 4]$$$;Ways to reach the point $$$5$$$: $$$[0, 1, 5]$$$, $$$[0, 3, 5]$$$,... | There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move). The length of the first move you make should be divisible by $$$k$$$, the le... | Print $$$n$$$ integersΒ β the number of ways to reach the point $$$x$$$, starting from $$$0$$$, for every $$$x \in [1, n]$$$, taken modulo $$$998244353$$$. | The first (and only) line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). | standard output | standard input | PyPy 3-64 | Python | 2,000 | train_109.jsonl | 913885b607a5d73af864fc85a2f9c44d | 256 megabytes | ["8 1", "10 2"] | PASSED | n,k=map(int,input().split());M=998244353
f,z=[1]+[0]*n,[0]*(n+1);l=0
while l<=n-k:
s=[0]*k
for i in range(l,n+1):
j=i%k
s[j],f[i],z[i]=(s[j]+f[i])%M,s[j],(z[i]+s[j])%M
l+=k;k+=1
print(*z[1:]) | 1659623700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\nNO\nNO"] | 6cebf9af5cfbb949f22e8b336bf07044 | NoteThe given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not. | Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't. | The first line contains a single positive integer, n (1ββ€βnββ€β105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1ββ€βxiββ€β1012). Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d spec... | standard output | standard input | Python 3 | Python | 1,300 | train_001.jsonl | d21fe65e3b4a0c1ee1af187a728f3356 | 256 megabytes | ["3\n4 5 6"] | PASSED | from math import sqrt
n = int(input())
s = [int(i) for i in input().split()]
d = [1]*1000002
e = set()
for i in range(2,1000002):
if d[i]:
e.add(i**2)
for j in range(i**2,1000002,i):
d[j]=0
for i in range(n):
if s[i] in e:
print("YES")
else:
print("NO") | 1349105400 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["2\n6\n-1\n7"] | 3b158306d335459ff55dcf29e46010e8 | NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no ... | There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between ... | Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is ... | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) β the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) β the number of products and the value $$$k$$$. The second line ... | standard output | standard input | Python 3 | Python | 900 | train_024.jsonl | c32efb5eb4a151a95f71c1bc05a5dd6f | 256 megabytes | ["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"] | PASSED | z=input
from math import *
for _ in range(int(z())):
n,k=map(int,z().split())
l=sorted(list((map(int,z().split()))))
c,m,n=0,max(l),len(l)
if k>=2 or n>=0:
if l[-1]-l[0]>k*2:print(-1)
else:print(l[0]+k)
continue
for i in range(m+k,0,-1):
d=0
for j in l:
... | 1561559700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3"] | 0c5ae761b046c021a25b706644f0d3cd | null | A sequence a0,βa1,β...,βatβ-β1 is called increasing if aiβ-β1β<βai for each i:β0β<βiβ<βt.You are given a sequence b0,βb1,β...,βbnβ-β1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence in... | Output the minimal number of moves needed to make the sequence increasing. | The first line of the input contains two integer numbers n and d (2ββ€βnββ€β2000,β1ββ€βdββ€β106). The second line contains space separated sequence b0,βb1,β...,βbnβ-β1 (1ββ€βbiββ€β106). | standard output | standard input | Python 3 | Python | 900 | train_009.jsonl | f415bd9e646f999f2c360181ccbacf56 | 64 megabytes | ["4 2\n1 3 3 2"] | PASSED | I=lambda:map(int,input().split())
n,d=I()
a=*I(),
x=a[0]
r=0
for y in a[1:]:
z=0--(x+1-y)//d
if z>=0:
r+=z
y+=z*d
x=y
print(r) | 1272294000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["23", "12"] | ebb9e236b6370a9cba9ffcd77fe4c97e | NoteIn the first sample, it is optimal to draw edges between the points (1,2), (1,4), (3,4). These have costs 4, 14, 5, respectively. | Roy and Biv have a set of n points on the infinite number line.Each point has one of 3 colors: red, green, or blue.Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it conne... | Print a single integer, the minimum cost way to solve the problem. | The first line will contain an integer n (1ββ€βnββ€β300β000), the number of points. The next n lines will contain two tokens pi and ci (pi is an integer, 1ββ€βpiββ€β109, ci is a uppercase English letter 'R', 'G' or 'B'), denoting the position of the i-th point and the color of the i-th point. 'R' means red, 'G' denotes gre... | standard output | standard input | Python 3 | Python | 2,400 | train_074.jsonl | d81597db55642034bb306c93a41befcf | 256 megabytes | ["4\n1 G\n5 R\n10 B\n15 G", "4\n1 G\n2 R\n3 B\n10 G"] | PASSED | #! /usr/bin/env python3
#------------------------------------------------
# Author: krishna
# Created: Fri Dec 29 23:04:38 IST 2017
# File Name: f.py
# USAGE:
# f.py
# Description:
#
#------------------------------------------------
import sys
n = int(sys.stdin.readline().rstrip())
locations = {
'R' ... | 1514562000 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["4\n4\n1\n1"] | f7f1d57921fe7b7a697967dcfc8f0169 | NoteIn the first test battle points for each ant are vβ=β[4,β0,β2,β0,β2], so ant number 1 is freed. Mole eats the ants 2, 3, 4, 5.In the second test case battle points are vβ=β[0,β2,β0,β2], so no ant is freed and all of them are eaten by Mole.In the third test case battle points are vβ=β[2,β0,β2], so ants number 3 and ... | Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1ββ€βiββ€βn) has a strength si.In order to make his dinner more interesting, Mole organizes a version of Β«Hunger GamesΒ» for the ants. He chooses two numbers l and r (1ββ€βlββ€βrββ€βn) and each pair of ants with indices between... | Print to the standard output t lines. The i-th line contains number of ants that Mole eats from the segment [li,βri]. | The first line contains one integer n (1ββ€βnββ€β105), the size of the ant colony. The second line contains n integers s1,βs2,β...,βsn (1ββ€βsiββ€β109), the strengths of the ants. The third line contains one integer t (1ββ€βtββ€β105), the number of test cases. Each of the next t lines contains two integers li and ri (1ββ€β... | standard output | standard input | PyPy 2 | Python | 2,100 | train_062.jsonl | da2a4a4e23a6d99ca26015529c1e202b | 256 megabytes | ["5\n1 3 2 4 2\n4\n1 5\n2 5\n3 5\n4 5"] | PASSED | import sys
range = xrange
# n log n time and memory precalc,
# then answers queries in O(1) time
class Queries:
def __init__(self, A, f = lambda a,b: a + b, max_d = float('inf')):
self.f = f
self.lists = [A]
n = len(A)
for d in range(1, min(n.bit_length(), max_d + 1)):
t... | 1412609400 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["-2 -4 3\n1 1 1 1 1\n-2 -4 7 -6 4\n-9 -7 -4 2 1 -3 -9 -4 -5\n4 -1 -9 -4 -8 -9 -5 -1 9"] | d07ae42b7902ba3a49cf4463248710ea | NoteIn the first test case, the difference $$$(-4) - (-2) = -2$$$ is non-positive, while the difference $$$3 - (-4) = 7$$$ is non-negative.In the second test case, we don't have to flip any signs. All $$$4$$$ differences are equal to $$$0$$$, which is both non-positive and non-negative.In the third test case, $$$7 - (-... | You are given $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$n$$$ is odd. You are allowed to flip the sign of some (possibly all or none) of them. You wish to perform these flips in such a way that the following conditions hold: At least $$$\frac{n - 1}{2}$$$ of the adjacent differences $$$a_{i + 1} - a_i$$$ fo... | For each test case, print $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$, corresponding to the integers after flipping signs. $$$b_i$$$ has to be equal to either $$$a_i$$$ or $$$-a_i$$$, and of the adjacent differences $$$b_{i + 1} - b_i$$$ for $$$i = 1, \dots, n - 1$$$, at least $$$\frac{n - 1}{2}$$$ should be non-negati... | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 500$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3 \le n \le 99$$$, $$$n$$$ is odd) Β β the number of integers given to you... | standard output | standard input | Python 3 | Python | 1,100 | train_000.jsonl | a9cea3a4e9db46d684a3672e30e919a9 | 256 megabytes | ["5\n3\n-2 4 3\n5\n1 1 1 1 1\n5\n-2 4 7 -6 4\n9\n9 7 -4 -2 1 -3 9 -4 -5\n9\n-4 1 9 4 8 9 5 1 -9"] | PASSED | for _ in range(int(input())):
t=int(input())
l=[int(x) for x in input().split()]
for i in range(t):
if i%2==0 and l[i]<0:
... | 1593873900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.