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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 second | ["Yes\n1 1", "No", "Yes\n1 2 3 1 5"] | 9abcb5481648a6485a818946f8f94d1d | NoteBelow one can find one of the possible solutions for the first sample case. The sum of subtree sizes equals $$$3 + 1 + 1 = 5$$$, and the branching coefficient equals $$$2$$$. Below one can find one of the possible solutions for the third sample case. The sum of subtree sizes equals $$$6 + 3 + 2 + 1 + 2 + 1 = 15$$$... | Misha walked through the snowy forest and he was so fascinated by the trees to decide to draw his own tree!Misha would like to construct a rooted tree with $$$n$$$ vertices, indexed from 1 to $$$n$$$, where the root has index 1. Every other vertex has a parent $$$p_i$$$, and $$$i$$$ is called a child of vertex $$$p_i$$... | If the required tree does not exist, output «No». Otherwise output «Yes» on the first line, and in the next one output integers $$$p_2$$$, $$$p_3$$$, ..., $$$p_n$$$, where $$$p_i$$$ denotes the parent of vertex $$$i$$$. | The only input line contains two integers $$$n$$$ and $$$s$$$ — the number of vertices in the tree and the desired sum of the subtree sizes ($$$2 \le n \le 10^5$$$; $$$1 \le s \le 10^{10}$$$). | standard output | standard input | Python 3 | Python | 2,400 | train_054.jsonl | f635dcc097455b2ce5d5d22d62b32b3e | 256 megabytes | ["3 5", "4 42", "6 15"] | PASSED | import math
def f(n,k):
if k==1:
return (n*(n+1))//2
a=math.floor(math.log(n,k))
b=sum(k**i for i in range(a+1))
c=sum((i+1)*k**i for i in range(a+1))
if n<b:
return c-(b-n)*(a+1)
else:
return c+(n-b)*(a+2)
n,s=map(int,input().split())
if s==(n*(n+1))//2:
print("Yes")... | 1546706100 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
3 seconds | ["6", "2"] | 6da720d47a627df3afb876253b1cbe58 | null | "Eat a beaver, save a tree!" — That will be the motto of ecologists' urgent meeting in Beaverley Hills.And the whole point is that the population of beavers on the Earth has reached incredible sizes! Each day their number increases in several times and they don't even realize how much their unhealthy obsession with tre... | Print the maximum number of beavers munched by the "Beavermuncher-0xFF". Please, do not use %lld specificator to write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d). | The first line contains integer n — the number of vertices in the tree (1 ≤ n ≤ 105). The second line contains n integers ki (1 ≤ ki ≤ 105) — amounts of beavers on corresponding vertices. Following n - 1 lines describe the tree. Each line contains two integers separated by space. These integers represent two vertices c... | standard output | standard input | Python 2 | Python | 2,100 | train_066.jsonl | a7266edb99e50f2ef6a576ff13b8c7a5 | 256 megabytes | ["5\n1 3 1 3 2\n2 5\n3 4\n4 5\n1 5\n4", "3\n2 1 1\n3 2\n1 2\n3"] | PASSED | n = input()+1
k = [0]+map(int,raw_input().split())
d = [[] for _ in xrange(n)]
for _ in xrange(n-2):
a,b = [int(x) for x in raw_input().split()]
d[a].append(b)
d[b].append(a)
s = input()
q = [0]
d[0] = [s]
v = [True]+[False]*n
for x in q:
for u in d[x]:
if not v[u]:
v[u]=True
... | 1303226100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["26\n24\n134"] | 7100fa11adfa0c1f5d33f9e3a1c3f352 | NoteIn the first test case, a way of getting the minimum possible perimeter is to arrange the slices of cheese as follows.We can calculate that the perimeter of the constructed shape is $$$2+5+1+1+1+1+3+1+5+1+2+3=26$$$. It can be shown that we cannot get a smaller perimeter.Consider the following invalid arrangement.Ev... | Pak Chanek has $$$n$$$ two-dimensional slices of cheese. The $$$i$$$-th slice of cheese can be represented as a rectangle of dimensions $$$a_i \times b_i$$$. We want to arrange them on the two-dimensional plane such that: Each edge of each cheese is parallel to either the x-axis or the y-axis. The bottom edge of each... | For each test case, output a line containing an integer representing the minimum possible perimeter of the constructed shape. | Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 2 \cdot 10^4$$$) — the number of test cases. The following lines contain the description of each test case. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the number of... | standard output | standard input | Python 3 | Python | 800 | train_096.jsonl | eb88a3bab2f463ab873d441b1ba730fa | 256 megabytes | ["3\n\n4\n\n4 1\n\n4 5\n\n1 1\n\n2 3\n\n3\n\n2 4\n\n2 6\n\n2 3\n\n1\n\n2 65"] | PASSED | t = int(input())
while t > 0:
t-=1
n = int(input()) # number of slices
x = n
slicesH = []
slicesW = []
totala = 0
totalb = 0
currw = 0
currh = 0
existingh = []
slicesH2 = []
slicesW2 = []
existingh2 = []
while x>0:
x-=1
a,b =... | 1667034600 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["167", "582491518"] | f4a9abc1cdfcdc2c96982477f17a197b | NoteDescription of the first example: $$$f(1, 1) = 5 \cdot 1 = 5$$$; $$$f(1, 2) = 2 \cdot 1 + 5 \cdot 2 = 12$$$; $$$f(1, 3) = 2 \cdot 1 + 4 \cdot 2 + 5 \cdot 3 = 25$$$; $$$f(1, 4) = 2 \cdot 1 + 4 \cdot 2 + 5 \cdot 3 + 7 \cdot 4 = 53$$$; $$$f(2, 2) = 2 \cdot 1 = 2$$$; $$$f(2, 3) = 2 \cdot 1 + 4 \cdot 2 = 10$$$; ... | You are given an array $$$a_1, a_2, \dots, a_n$$$. All $$$a_i$$$ are pairwise distinct.Let's define function $$$f(l, r)$$$ as follows: let's define array $$$b_1, b_2, \dots, b_{r - l + 1}$$$, where $$$b_i = a_{l - 1 + i}$$$; sort array $$$b$$$ in increasing order; result of the function $$$f(l, r)$$$ is $$$\sum\lim... | Print one integer — the total sum of $$$f$$$ for all subsegments of $$$a$$$ modulo $$$10^9+7$$$ | The first line contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$) — array $$$a$$$. | standard output | standard input | PyPy 3 | Python | 2,300 | train_032.jsonl | e41eb7e15c0c70495a44339e6c917ed3 | 256 megabytes | ["4\n5 2 4 7", "3\n123456789 214365879 987654321"] | PASSED | import sys
MOD = (int)(1e9+7)
def add(a, b):
a += b
if a >= MOD: a -= MOD
return a
def mul(a, b):
return (a * b) % MOD
class fenwickTree:
def __init__(self, max_val):
self.max_val = max_val + 5
self.tree = [0] * self.max_val
def update(self, idx, value):
idx += 1
while idx < self.max_val:
self.t... | 1557930900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1 1 1", "77 77 79"] | 91d5147fb602298e08cbdd9f86d833f8 | null | Little C loves number «3» very much. He loves all things about it.Now he has a positive integer $$$n$$$. He wants to split $$$n$$$ into $$$3$$$ positive integers $$$a,b,c$$$, such that $$$a+b+c=n$$$ and none of the $$$3$$$ integers is a multiple of $$$3$$$. Help him to find a solution. | Print $$$3$$$ positive integers $$$a,b,c$$$ in a single line, such that $$$a+b+c=n$$$ and none of them is a multiple of $$$3$$$. It can be proved that there is at least one solution. If there are multiple solutions, print any of them. | A single line containing one integer $$$n$$$ ($$$3 \leq n \leq 10^9$$$) — the integer Little C has. | standard output | standard input | PyPy 3 | Python | 800 | train_006.jsonl | 49c570e87d093a34dd80dc8f29de7209 | 256 megabytes | ["3", "233"] | PASSED |
n = int(input())
if n % 2 != 0:
n = n - 1
a = n // 2
b = n - a
while a % 3 == 0 or b % 3 == 0:
a = a + 1
b = b - 1
print(1 , a , b)
else:
n = n - 2
a = n // 2
b = n - a
while a % 3 == 0 or b % 3 == 0:
a = a + 1
b = b - 1
print(2 , a , b)
| 1537540500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2.5 seconds | ["2 1 0 1\n1 2 1 0\n0 1 2 1\n1 0 1 2", "1 0 0 0 0 0 0 0\n0 2 0 0 0 0 2 0\n0 0 1 0 1 1 0 0\n0 0 0 2 0 0 0 2\n0 0 1 0 1 1 0 0\n0 0 1 0 1 1 0 0\n0 2 0 0 0 0 2 0\n0 0 0 2 0 0 0 2"] | 23467790e295f49feaaf1fc64beafa86 | NoteThe following picture describes the first example.The tree with red edges is a BFS tree rooted at both $$$1$$$ and $$$2$$$.Similarly, the BFS tree for other adjacent pairs of vertices can be generated in this way. | We define a spanning tree of a graph to be a BFS tree rooted at vertex $$$s$$$ if and only if for every node $$$t$$$ the shortest distance between $$$s$$$ and $$$t$$$ in the graph is equal to the shortest distance between $$$s$$$ and $$$t$$$ in the spanning tree. Given a graph, we define $$$f(x,y)$$$ to be the number o... | Print $$$n$$$ lines, each consisting of $$$n$$$ integers. The integer printed in the row $$$i$$$ and the column $$$j$$$ should be $$$f(i,j) \bmod 998\,244\,353$$$. | The first line contains two integers $$$n$$$, $$$m$$$ ($$$1 \le n \le 400$$$, $$$0 \le m \le 600$$$) — the number of vertices and the number of edges in the graph. The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$a_i$$$, $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n$$$, $$$a_i < b_i$$$), representing an edge... | standard output | standard input | PyPy 3 | Python | 2,600 | train_085.jsonl | 89a5265b7f65c09bcc7a586db0959607 | 512 megabytes | ["4 4\n1 2\n2 3\n3 4\n1 4", "8 9\n1 2\n1 3\n1 4\n2 7\n3 5\n3 6\n4 8\n2 3\n3 4"] | PASSED | #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
def main():
n,m = map(int,input().split())
MOD = 998244353
adjList = []
dist = []
ans = []
for _ in range(n):
adjList.append([])
for _ in range(m):
a,b = map(int,input().split())
... | 1615377900 | [
"math",
"trees",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
1
] | |
2 seconds | ["none\nany\nat least one\nat least one\nany", "any\nany\nnone", "at least one\nat least one\nat least one"] | be83ef61283f104dcb00612ae11f2e93 | NoteIn the second sample the MST is unique for the given graph: it contains two first edges.In the third sample any two edges form the MST for the given graph. That means that each edge is included at least in one MST. | You are given a connected weighted undirected graph without any loops and multiple edges. Let us remind you that a graph's spanning tree is defined as an acyclic connected subgraph of the given graph that includes all of the graph's vertexes. The weight of a tree is defined as the sum of weights of the edges that the g... | Print m lines — the answers for all edges. If the i-th edge is included in any MST, print "any"; if the i-th edge is included at least in one MST, print "at least one"; if the i-th edge isn't included in any MST, print "none". Print the answers for the edges in the order in which the edges are specified in the input. | The first line contains two integers n and m (2 ≤ n ≤ 105, ) — the number of the graph's vertexes and edges, correspondingly. Then follow m lines, each of them contains three integers — the description of the graph's edges as "ai bi wi" (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106, ai ≠ bi), where ai and bi are the numbers of vertexe... | standard output | standard input | Python 3 | Python | 2,300 | train_073.jsonl | 0ba0bade310d53c2e2bcf3caf30ccaee | 256 megabytes | ["4 5\n1 2 101\n1 3 100\n2 3 2\n2 4 2\n3 4 1", "3 3\n1 2 1\n2 3 1\n1 3 2", "3 3\n1 2 1\n2 3 1\n1 3 1"] | PASSED | import sys, threading
from heapq import heappop, heappush
#from mygraph import MyGraph
from collections import defaultdict
n_nodes, n_edges = map(int, input().split())
edges = list()
results = defaultdict(lambda: 'any')
highest = defaultdict(lambda: -1)
to_check = defaultdict(list)
graph = defaultdict(list)
class U... | 1331046000 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["1\n3", "2\n3 4", "0"] | f046fc902b22fdbc3b1ec9cb4f411179 | NoteIn the first test, $$$p=2$$$. If $$$x \le 2$$$, there are no valid permutations for Yuzu. So $$$f(x)=0$$$ for all $$$x \le 2$$$. The number $$$0$$$ is divisible by $$$2$$$, so all integers $$$x \leq 2$$$ are not good. If $$$x = 3$$$, $$$\{1,2,3\}$$$ is the only valid permutation for Yuzu. So $$$f(3)=1$$$, so the ... | This is the easy version of the problem. The difference between versions is the constraints on $$$n$$$ and $$$a_i$$$. You can make hacks only if all versions of the problem are solved.First, Aoi came up with the following idea for the competitive programming problem:Yuzu is a girl who collecting candies. Originally, sh... | In the first line, print the number of good integers $$$x$$$. In the second line, output all good integers $$$x$$$ in the ascending order. It is guaranteed that the number of good integers $$$x$$$ does not exceed $$$10^5$$$. | The first line contains two integers $$$n$$$, $$$p$$$ $$$(2 \le p \le n \le 2000)$$$. It is guaranteed, that the number $$$p$$$ is prime (it has exactly two divisors $$$1$$$ and $$$p$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 2000)$$$. | standard output | standard input | PyPy 3 | Python | 1,900 | train_001.jsonl | d5c42d3f633256749816436a710ad52a | 256 megabytes | ["3 2\n3 4 5", "4 3\n2 3 5 6", "4 3\n9 1 1 1"] | PASSED | def func(length, prime):
nums = sorted(map(int, input().split()))
mini = max(nums[0], nums[-1]-length+1)
xs = list(range(mini, min(mini+length, nums[-1]+1)))
L = len(xs) # candidates, 0~L-length
idxs = [0] * length
for i in range(L-1, -1, -1):
if xs[i] == nums[-1]:
idxs[-1... | 1593610500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["3\n4", "20", "-1"] | 7589b30ec643278d8a83d74d43d9aebe | null | Daniel is organizing a football tournament. He has come up with the following tournament format: In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages are... | Print all possible numbers of invited teams in ascending order, one per line. If exactly n games cannot be played, output one number: -1. | The first line contains a single integer n (1 ≤ n ≤ 1018), the number of games that should be played. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | standard input | Python 3 | Python | 1,800 | train_009.jsonl | 7462c70ad5102f5ef7cf9ccf5e2ab786 | 256 megabytes | ["3", "25", "2"] | PASSED | def cc(res):
l = 1
r = res
while l<=r:
mid = l+r >>1
if mid*mid==res:
return mid
elif mid*mid>res:
r = mid-1
else:
l = mid+1
return -1
def solve(a,b,c):
if b*b-4*a*c<0:
return -1
r = cc(b*b-4*a*c)
if r*r!=b*b-... | 1373734800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["0.0000000\n0\n2.0000\n0.00\n1"] | 9f019c3898f27d687c5b3498586644e8 | NoteIn the picture, the downtowns of the first three test cases are illustrated. Triangles are enumerated according to the indices of test cases they belong to. In the first two test cases, all points on the borders of the downtowns are safe, thus the answers are $$$0$$$.In the following picture unsafe points for the ... | Sam lives in Awesomeburg, its downtown has a triangular shape. Also, the following is true about the triangle: its vertices have integer coordinates, the coordinates of vertices are non-negative, and its vertices are not on a single line. He calls a point on the downtown's border (that is the border of the triangle)... | For each test case print a single number — the answer to the problem. Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{-9}$$$. Formally let your answer be $$$a$$$, jury answer be $$$b$$$. Your answer will be considered correct if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-... | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Description of the test cases follows. Each test case contains three lines, each of them contains two integers $$$x_i$$$, $$$y_i$$$ ($$$0 \le x_i, y_i \le 10^9$$$) — coordinates ... | standard output | standard input | Python 3 | Python | 800 | train_092.jsonl | 37265648ec77aa531ad8d59a5c98a7fc | 256 megabytes | ["5\n8 10\n10 4\n6 2\n4 6\n0 1\n4 2\n14 1\n11 2\n13 2\n0 0\n4 0\n2 4\n0 1\n1 1\n0 0"] | PASSED | n=int(input(""))
k=0
ne=[]
for i in range(n):
d=0
a=input("")
b=input("")
c=input("")
a=a.split()
b=b.split()
c=c.split()
l=[a,b,c]
if int(a[1])==int(b[1]) and int(c[1])<int(a[1]):
d=d+int(a[0])-int(b[0])
if int(b[1])==int(c[1]) and int(a[1])<int(c[1... | 1645611000 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
1 second | ["4", "16", "0", "18716"] | 47a8fd4c1f4e7b1d4fd15fbaf5f6fda8 | null | Imagine that your city is an infinite 2D plane with Cartesian coordinate system. The only crime-affected road of your city is the x-axis. Currently, there are n criminals along the road. No police station has been built on this road yet, so the mayor wants to build one.As you are going to be in charge of this new polic... | Print a single integer, that means the minimum possible distance you need to cover to catch all the criminals. | The first line of the input will have two integers n (1 ≤ n ≤ 106) and m (1 ≤ m ≤ 106) separated by spaces. The next line will contain n integers separated by spaces. The ith integer is the position of the ith criminal on the x-axis. Absolute value of positions will not exceed 109. If a criminal has position x, he/she ... | standard output | standard input | Python 2 | Python | 2,000 | train_059.jsonl | 465864721312b41ec9b5ec83aeb0c216 | 256 megabytes | ["3 6\n1 2 3", "5 5\n-7 -6 -3 -1 1", "1 369\n0", "11 2\n-375 -108 1336 1453 1598 1892 2804 3732 4291 4588 4822"] | PASSED | n, m = map(int,raw_input().split())
C = map(int,raw_input().split())
res,l = 0, 0
while l < n:
res = res + C[n - 1] - C[l]
l,n = l + m, n - m
print res*2
| 1399044600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3\n1\n0\n595458194\n200000000"] | 116dd636a4f2547aef01a68f98c46ca2 | NoteIn the first test case, the possible arrays $$$b$$$ are: $$$[4,2,1]$$$; $$$[4,2,3]$$$; $$$[4,2,5]$$$. In the second test case, the only array satisfying the demands is $$$[1,1]$$$.In the third test case, it can be proven no such array exists. | You are given two integers $$$n$$$ and $$$m$$$ and an array $$$a$$$ of $$$n$$$ integers. For each $$$1 \le i \le n$$$ it holds that $$$1 \le a_i \le m$$$.Your task is to count the number of different arrays $$$b$$$ of length $$$n$$$ such that: $$$1 \le b_i \le m$$$ for each $$$1 \le i \le n$$$, and $$$\gcd(b_1,b_2,b... | For each test case, print a single integer — the number of different arrays satisfying the conditions above. Since this number can be large, print it modulo $$$998\,244\,353$$$. | Each test consist of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le m \le 10^9$$$) — the ... | standard output | standard input | PyPy 3-64 | Python | 1,800 | train_101.jsonl | 12adcb65337194fec096bfd9137e45bd | 256 megabytes | ["5\n\n3 5\n\n4 2 1\n\n2 1\n\n1 1\n\n5 50\n\n2 3 5 2 3\n\n4 1000000000\n\n60 30 1 1\n\n2 1000000000\n\n1000000000 2"] | PASSED | #from pyrival import *
import math
import sys
import heapq
input = lambda: sys.stdin.readline().rstrip("\r\n")
mod = 998244353
# Count the number of numbers
# up to m which are divisible
# by given prime numbers
def count(a, n, m):
#print(a)
#print(n, m)
total = 0
# Run from i = 000..0 to i = 111..1... | 1667745300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["Yes\n4\n4 3\n4 2\n1 3\n1 2", "Yes\n6\n6 5\n6 4\n6 3\n5 4\n5 3\n2 1", "No"] | f1c1d50865d46624294b5a31d8834097 | null | There are n players sitting at a round table. All of them have s cards of n colors in total. Besides, initially the first person had cards of only the first color, the second one had cards of only the second color and so on. They can swap the cards by the following rules: as the players swap, a player can give a card... | On the first line print "No" if such sequence of swaps is impossible. Otherwise, print "Yes". If the answer is positive, next print number k — the number of the swaps. Then on k lines describe the swaps by pairs of indices of the swapping players. Print the swaps and the numbers of the swaps in any order. | The first line contains integers n (1 ≤ n ≤ 200000) and s (1 ≤ s ≤ 200000). The second line contains n numbers, the i-th number stands for how many cards the i-th player has by the moment the game starts. It is possible that a player has no cards initially. | standard output | standard input | Python 2 | Python | 2,200 | train_037.jsonl | 8c83488018611ed3649fcb9d1aeb1d9a | 256 megabytes | ["4 8\n2 2 2 2", "6 12\n1 1 2 2 3 3", "5 5\n0 0 0 0 5"] | PASSED | from heapq import *
n, s = map(int, raw_input().split())
a = map(int, raw_input().split())
q = [(-x, i) for (i, x) in enumerate(a) if x > 0]
heapify(q)
res = []
while q:
(x, i) = heappop(q)
if -x > len(q):
print 'No'
break
for (y, j) in [heappop(q) for _ in xrange(-x)]:
res.append((i... | 1322838000 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["YES\nNO\nYES"] | 0a720a0b06314fde783866b47f35af81 | NoteIn the first test case of the example two operations can be used to make both $$$a$$$ and $$$b$$$ equal to zero: choose $$$x = 4$$$ and set $$$a := a - x$$$, $$$b := b - 2x$$$. Then $$$a = 6 - 4 = 2$$$, $$$b = 9 - 8 = 1$$$; choose $$$x = 1$$$ and set $$$a := a - 2x$$$, $$$b := b - x$$$. Then $$$a = 2 - 2 = 0$$$, ... | You are given two integers $$$a$$$ and $$$b$$$. You may perform any number of operations on them (possibly zero).During each operation you should choose any positive integer $$$x$$$ and set $$$a := a - x$$$, $$$b := b - 2x$$$ or $$$a := a - 2x$$$, $$$b := b - x$$$. Note that you may choose different values of $$$x$$$ i... | For each test case print the answer to it — YES if it is possible to make $$$a$$$ and $$$b$$$ equal to $$$0$$$ simultaneously, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then the test cases follow, each test case is represented by one line containing two integers $$$a$$$ and $$$b$$$ for this test case ($$$0 \le a, b \le 10^9$$$). | standard output | standard input | PyPy 3 | Python | 1,300 | train_002.jsonl | 28de3f0c5c80437e99979cb0e751672d | 256 megabytes | ["3\n6 9\n1 1\n1 2"] | PASSED | t = int(input())
while t:
t -= 1
a, b = tuple(map(int, input().split()))
if (a > b):
a, b = b, a
if ((2 * a - b) % 3 == 0 and b <= 2 * a):
print("Yes")
else:
print("No")
| 1574862600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["7\n1\n1\n2\n1\n3\n3\n3"] | 7c0ffbba9e61a25e51c91b1f89c35532 | null | You are given a matrix $$$a$$$, consisting of $$$3$$$ rows and $$$n$$$ columns. Each cell of the matrix is either free or taken.A free cell $$$y$$$ is reachable from a free cell $$$x$$$ if at least one of these conditions hold: $$$x$$$ and $$$y$$$ share a side; there exists a free cell $$$z$$$ such that $$$z$$$ is r... | Print $$$q$$$ integers — the $$$j$$$-th value should be equal to the number of the connected components of the matrix, consisting of columns from $$$l_j$$$ to $$$r_j$$$ of the matrix $$$a$$$, inclusive. | The first line contains an integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the number of columns of matrix $$$a$$$. The $$$i$$$-th of the next three lines contains a description of the $$$i$$$-th row of the matrix $$$a$$$ — a string, consisting of $$$n$$$ characters. Each character is either $$$1$$$ (denoting a free... | standard output | standard input | PyPy 3-64 | Python | 2,500 | train_092.jsonl | c2ec762d45fcc57722b5c5f06d808acc | 256 megabytes | ["12\n100101011101\n110110010110\n010001011101\n8\n1 12\n1 1\n1 2\n9 9\n8 11\n9 12\n11 12\n4 6"] | PASSED | import sys
def Column2Num( m, idx ):
return int(m[0][idx] != 0) | (int(m[1][idx]) << 1) | (int(m[2][idx]) << 2)
def QColumn( m, bits, idx ):
if bits[idx] == 5:
if m[0][idx] == m[2][idx]:
return True
return False
def GetIntegratedCount( m ):
ret, curr = [ 0 ], set()
... | 1649514900 | [
"math",
"trees"
] | [
0,
0,
0,
1,
0,
0,
0,
1
] | |
2 seconds | ["5\n4\n2\n0"] | 21f7c9e71ce1532514a6eaf0ff1c92da | NoteThe towers in the example are: before the queries: $$$[[5, 1], [2], [7, 4, 3], [6]]$$$; after the first query: $$$[[2], [7, 5, 4, 3, 1], [6]]$$$; after the second query: $$$[[7, 5, 4, 3, 2, 1], [6]]$$$; after the third query, there is only one tower: $$$[7, 6, 5, 4, 3, 2, 1]$$$. | You have a set of $$$n$$$ discs, the $$$i$$$-th disc has radius $$$i$$$. Initially, these discs are split among $$$m$$$ towers: each tower contains at least one disc, and the discs in each tower are sorted in descending order of their radii from bottom to top.You would like to assemble one tower containing all of those... | Print $$$m$$$ integers. The $$$k$$$-th integer ($$$0$$$-indexed) should be equal to the difficulty of the set of towers after the first $$$k$$$ queries are performed. | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le m \le n \le 2 \cdot 10^5$$$) — the number of discs and the number of towers, respectively. The second line contains $$$n$$$ integers $$$t_1$$$, $$$t_2$$$, ..., $$$t_n$$$ ($$$1 \le t_i \le m$$$), where $$$t_i$$$ is the index of the tower dis... | standard output | standard input | Python 3 | Python | 2,300 | train_050.jsonl | a7ff58d757af1055594167694f353909 | 512 megabytes | ["7 4\n1 2 3 3 1 4 3\n3 1\n2 3\n2 4"] | PASSED | def get_ints():
return map(int, input().split())
def main():
_, m = get_ints()
s = [set() for _ in range(m)]
prev, score = -1, -1
for index, dest in enumerate(get_ints()):
s[dest - 1].add(index)
if prev != dest:
score += 1
prev = dest
ans = [score]
for... | 1594565100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["abc", "abdc"] | e758ae072b8aed53038e4593a720276d | null | Petya recieved a gift of a string s with length up to 105 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: Extract the first character of s and append t with this character. Extract the last character of t and append u with this characte... | Print resulting string u. | First line contains non-empty string s (1 ≤ |s| ≤ 105), consisting of lowercase English letters. | standard output | standard input | Python 3 | Python | 1,700 | train_015.jsonl | 8bde194f031c0f296fa6a89cf3f64bbf | 256 megabytes | ["cab", "acdb"] | PASSED | #! /bin/python
s = input()
resultBase = ""
resultRest = ""
best = len(s) - 1
mini = [0] * len(s)
for i in range(len(s) - 1, -1, -1):
mini[i] = best
if s[best] >= s[i]:
best = i
for i in range(len(s)):
resultRest += s[i]
while len(resultRest) > 0 and resultRest[-1] <= s[mini[i]]:
resul... | 1492266900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["4", "2", "0", "3", "1"] | 87d3c1d8d3d1f34664ff32081222117d | NoteIn the first example the question marks can be replaced in the following way: "aaaababbbb". $$$f_1 = 4$$$, $$$f_2 = 4$$$, thus the answer is $$$4$$$. Replacing it like this is also possible: "aaaabbbbbb". That way $$$f_1 = 4$$$, $$$f_2 = 6$$$, however, the minimum of them is still $$$4$$$.In the second example one ... | You are given a string $$$s$$$ of length $$$n$$$. Each character is either one of the first $$$k$$$ lowercase Latin letters or a question mark.You are asked to replace every question mark with one of the first $$$k$$$ lowercase Latin letters in such a way that the following value is maximized.Let $$$f_i$$$ be the maxim... | Print a single integer — the maximum value of the string after every question mark is replaced with one of the first $$$k$$$ lowercase Latin letters. | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le k \le 17$$$) — the length of the string and the number of first Latin letters used. The second line contains a string $$$s$$$, consisting of $$$n$$$ characters. Each character is either one of the first $$$k$$$ lowercase ... | standard output | standard input | PyPy 3 | Python | 2,500 | train_094.jsonl | 969d66385f4f66d2d8faf899a2e66eb0 | 256 megabytes | ["10 2\na??ab????b", "9 4\n?????????", "2 3\n??", "15 3\n??b?babbc??b?aa", "4 4\ncabd"] | PASSED | import io,os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import deque
n, k = map(int,input().split())
s = input()
def judge(needed):
inf = 2147483647
minstate = [inf]*(1<<k)
minstate[0] = 0
effect = [[inf]*(n+1) for j in range(k)]
for j i... | 1626273300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["T\nHL"] | 5bfce6c17af24959b4af3c9408536d05 | NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has bee... | For each game, print on a single line the name of the winner, "T" or "HL" (without quotes) | The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integer... | standard output | standard input | PyPy 3 | Python | 1,800 | train_002.jsonl | 8defb17bc2d2c6dc10de686b573670ee | 256 megabytes | ["2\n1\n2\n2\n1 1"] | PASSED | for t in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
l.sort()
s=sum(l)
if l[-1]>s-l[-1]:
print("T")
elif s%2==0:
print("HL")
else:
print("T") | 1598798100 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
1 second | ["10\n15\n1999999999\n113\n1000000001\n1"] | 7d6f76e24fe9a352beea820ab56f03b6 | null | You are given two positive integers $$$n$$$ and $$$k$$$. Print the $$$k$$$-th positive integer that is not divisible by $$$n$$$.For example, if $$$n=3$$$, and $$$k=7$$$, then all numbers that are not divisible by $$$3$$$ are: $$$1, 2, 4, 5, 7, 8, 10, 11, 13 \dots$$$. The $$$7$$$-th number among them is $$$10$$$. | For each test case print the $$$k$$$-th positive integer that is not divisible by $$$n$$$. | The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Next, $$$t$$$ test cases are given, one per line. Each test case is two positive integers $$$n$$$ ($$$2 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$). | standard output | standard input | Python 3 | Python | 1,200 | train_000.jsonl | 83641157346168524dfcefc5d55e6430 | 256 megabytes | ["6\n3 7\n4 12\n2 1000000000\n7 97\n1000000000 1000000000\n2 1"] | PASSED | import math
t=int(input())
for _ in range(0,t):
n,k=map(int,input().split(" "))
need=math.floor((k-1)//(n-1))
print(k+need) | 1589034900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["4\n-1\n5"] | 474f29da694929a64eaed6eb8e4349c3 | NoteIn the first test case the optimal sequence is: $$$4 \rightarrow 2 \rightarrow 1 \rightarrow 3 \rightarrow 5$$$.In the second test case it is possible to get to pages $$$1$$$ and $$$5$$$.In the third test case the optimal sequence is: $$$4 \rightarrow 7 \rightarrow 10 \rightarrow 13 \rightarrow 16 \rightarrow 19$$$... | Vasya is reading a e-book. The file of the book consists of $$$n$$$ pages, numbered from $$$1$$$ to $$$n$$$. The screen is currently displaying the contents of page $$$x$$$, and Vasya wants to read the page $$$y$$$. There are two buttons on the book which allow Vasya to scroll $$$d$$$ pages forwards or backwards (but h... | Print one line for each test. If Vasya can move from page $$$x$$$ to page $$$y$$$, print the minimum number of times he needs to press a button to do it. Otherwise print $$$-1$$$. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of testcases. Each testcase is denoted by a line containing four integers $$$n$$$, $$$x$$$, $$$y$$$, $$$d$$$ ($$$1\le n, d \le 10^9$$$, $$$1 \le x, y \le n$$$) — the number of pages, the starting page, the desired page, and the number of ... | standard output | standard input | Python 2 | Python | 1,200 | train_002.jsonl | 7309be6e7e7fdb09adedff421628d79d | 256 megabytes | ["3\n10 4 5 2\n5 1 3 4\n20 4 19 3"] | PASSED | import math
a = input()
for _ in xrange(0, a):
bookSize, startPage, endPage, jumpsAllowed = map(int, raw_input().split())
jumps = abs(((endPage - startPage) / float(jumpsAllowed)))
if jumps.is_integer():
print int(jumps)
continue
jumpsLeft = abs(math.ceil(((startPage - 1) / float(ju... | 1543415700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["1", "12", "0"] | 1c2a2ad98e7162e89d36940b2848b921 | null | There are n points marked on the plane. The points are situated in such a way that they form a regular polygon (marked points are its vertices, and they are numbered in counter-clockwise order). You can draw n - 1 segments, each connecting any two marked points, in such a way that all points have to be connected with e... | Print the number of ways to connect points modulo 109 + 7. | The first line contains one number n (3 ≤ n ≤ 500) — the number of marked points. Then n lines follow, each containing n elements. ai, j (j-th element of line i) is equal to 1 iff you can connect points i and j directly (otherwise ai, j = 0). It is guaranteed that for any pair of points ai, j = aj, i, and for any point... | standard output | standard input | PyPy 2 | Python | 2,500 | train_017.jsonl | 60ad08b3377da64e3da0c570835fbe26 | 256 megabytes | ["3\n0 0 1\n0 0 1\n1 1 0", "4\n0 1 1 1\n1 0 1 1\n1 1 0 1\n1 1 1 0", "3\n0 0 0\n0 0 1\n0 1 0"] | PASSED | import sys
range = xrange
input = raw_input
MOD = 10**9 + 7
INVMOD = 1.0/MOD
import __pypy__
mulmod = __pypy__.intop.int_mulmod
sub = __pypy__.intop.int_sub
mul = __pypy__.intop.int_mul
def mo(a,b):
return sub(mul(a,b), mul(MOD, int(INVMOD * a * b)))
n = int(input())
A = []
for _ in range(n):
A.append([int(... | 1510239900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["3 3 5 5", "1000000000 1000000000 1000000000 1000000000 1000000000"] | 41645bbe84910de81ac4ed2a56a046d3 | NoteFor the first example, When k = 0, one possible optimal game is as follows: Oleg eats the carrot with juiciness 1. Igor eats the carrot with juiciness 5. Oleg eats the carrot with juiciness 2. The remaining carrot has juiciness 3.When k = 1, one possible optimal play is as follows: Oleg eats the carrot with juicine... | Oleg the bank client and Igor the analyst are arguing again. This time, they want to pick a gift as a present for their friend, ZS the coder. After a long thought, they decided that their friend loves to eat carrots the most and thus they want to pick the best carrot as their present.There are n carrots arranged in a l... | Output n space-separated integers x0, x1, ..., xn - 1. Here, xi denotes the juiciness of the carrot the friends will present to ZS if k = i. | The first line of input contains a single integer n (1 ≤ n ≤ 3·105) — the total number of carrots. The next line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109). Here ai denotes the juiciness of the i-th carrot from the left of the line. | standard output | standard input | PyPy 3 | Python | 2,800 | train_029.jsonl | 6be7cc557c658d4c3f2837d49f561f47 | 256 megabytes | ["4\n1 2 3 5", "5\n1000000000 1000000000 1000000000 1000000000 1"] | PASSED | def evens(A):
n = len(A)
l = n//2-1; r = n//2
if len(A)%2 == 1: l+= 1
ans = [max(A[l], A[r])]
while r < n-1:
l-= 1; r+= 1
ans.append(max(ans[-1], A[l], A[r]))
return ans
def interleave(A, B):
q = []
for i in range(len(B)): q+= [A[i], B[i]]
if len(A) != len(B): q.appe... | 1494668100 | [
"math",
"games"
] | [
1,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES", "NO"] | 21c0e12347d8be7dd19cb9f43a31be85 | NoteIn the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".In the second sample the first string can be splitted into strings "aa" and "bb", that are equiv... | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases: They are equal. If we split string a into two halves of the same size a1 and a2, and string b into two halves of the same size b1 and b2, then one... | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200 000 and consists of lowercase English letters. The strings have the same length. | standard output | standard input | Python 3 | Python | 1,700 | train_010.jsonl | eb0b65066323e88c4f008711ac4c69d7 | 256 megabytes | ["aaba\nabaa", "aabb\nabab"] | PASSED | def checaEquavalencia(a, b, tam):
if a == b:
#print('YES')
return True
elif len(a) % 2 == 1:
return False
elif len(b) % 2 == 1:
return False
elif tam > 1:
tam = tam // 2
a1 = a[ : tam]
a2 = a[tam : ]
b1 = b[ : tam]
b2 = b[tam : ]
#caso1 = checaEquavalencia(a1, b1, tam) ... | 1437573600 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["poisson\nuniform"] | e1dad71bee6d60b4d6dc33ea8cf09ba1 | NoteThe full example input is visually represented below, along with the probability distribution function it was drawn from (the y-axis is labeled by its values multiplied by 250). | Heidi is a statistician to the core, and she likes to study the evolution of marmot populations in each of V (1 ≤ V ≤ 100) villages! So it comes that every spring, when Heidi sees the first snowdrops sprout in the meadows around her barn, she impatiently dons her snowshoes and sets out to the Alps, to welcome her frien... | Output one line per village, in the same order as provided in the input. The village's line shall state poisson if the village's distribution is of the Poisson type, and uniform if the answer came from a uniform distribution. | The first line of input will contain the number of villages V (1 ≤ V ≤ 100). The following V lines each describe one village. The description of each village consists of 250 space-separated integers k, drawn from one of the above distributions. | standard output | standard input | Python 3 | Python | 2,100 | train_045.jsonl | 2eeedebdca4c38ae7b7ceff577c02f97 | 256 megabytes | ["2\n92 100 99 109 93 105 103 106 101 99 ... (input is truncated)\n28 180 147 53 84 80 180 85 8 16 ... (input is truncated)"] | PASSED | v = int(input())
eps = 3
def ans(a):
a.sort()
if len(a) % 2 == 0:
med = a[len(a)//2]
else:
med = (a[len(a)//2] + a[len(a)//2 - 1]) // 2
l = med - med // 2
r = med + med // 2
c1 = c2 = 0
for i in a:
if i >= l and i <= r:
c1 += 1
else:
... | 1495958700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3.729935587093555327", "11.547005383792516398"] | b44c6836ee3d597a78d4b6b16ef1d4b3 | null | A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road.We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point... | Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if... | The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively. The second line contains two integers and t (0 < v, t ≤ 1000), which are denoting the maximum s... | standard output | standard input | Python 2 | Python | 2,100 | train_006.jsonl | 8427e856a1960db1ba05e67361e0751f | 256 megabytes | ["0 0 5 5\n3 2\n-1 -1\n-1 0", "0 0 0 1000\n100 1000\n-50 0\n50 0"] | PASSED | x,y,xx,yy=map(float,raw_input().split())
v,t=map(float,raw_input().split())
vx,vy=map(float,raw_input().split())
ux,uy=map(float,raw_input().split())
X=x+vx*t
Y=y+vy*t
ans=0
if (X-xx)*(X-xx)+(Y-yy)*(Y-yy)>v*t*v*t:
ans=t
x=X
y=Y
else:
t=0
ux=vx
uy=vy
l=0.0
r=float(pow(10,20))
while r-l>pow(0.1,7)... | 1445763600 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["25\n1438\n1101\n686531475"] | 592e219abe72054c3de1b6823a1d049d | NoteLet's illustrate what happens with the first test case. Initially, we have $$$s = $$$ 231. Initially, $$$\ell = 0$$$ and $$$c = \varepsilon$$$ (the empty string). The following things happen if we follow the procedure above: Step 1, Move once: we get $$$\ell = 1$$$. Step 2, Cut once: we get $$$s = $$$ 2 and $$$c ... | We start with a string $$$s$$$ consisting only of the digits $$$1$$$, $$$2$$$, or $$$3$$$. The length of $$$s$$$ is denoted by $$$|s|$$$. For each $$$i$$$ from $$$1$$$ to $$$|s|$$$, the $$$i$$$-th character of $$$s$$$ is denoted by $$$s_i$$$. There is one cursor. The cursor's location $$$\ell$$$ is denoted by an intege... | For each test case, output a single line containing a single integer denoting the answer for that test case modulo $$$10^9 + 7$$$. | The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) denoting the number of test cases. The next lines contain descriptions of the test cases. The first line of each test case contains a single integer $$$x$$$ ($$$1 \le x \le 10^6$$$). The second line of each test case consists of the init... | standard output | standard input | PyPy 3 | Python | 1,700 | train_005.jsonl | 6c363be6160858827861bfddf5206e10 | 256 megabytes | ["4\n5\n231\n7\n2323\n6\n333\n24\n133321333"] | PASSED | for _ in range(int(input())):
x = int(input())
sen = list(map(int, input()))
l = 1
len_sen = len(sen)
while(l <= x):
itr = sen[l-1]
len_sen = (l + (len_sen - l) * sen[l-1])%(1000000007)
idx = len(sen)
for _ in range(itr-1):
if len(sen) < x:
sen += sen[l:idx]
else:
break
l+=1
print(len_s... | 1576386300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["0", "4", "5"] | cd921b5fc4140f1cd19e73c42b3bc2fe | NoteIn the first test case string a is the same as string b and equals 100 letters a. As both strings are equal, the Hamming distance between them is zero.In the second test case strings a and b differ in their 3-rd, 5-th, 6-th and 7-th characters. Thus, the Hamming distance equals 4.In the third test case string a is ... | Xenia is an amateur programmer. Today on the IT lesson she learned about the Hamming distance.The Hamming distance between two strings s = s1s2... sn and t = t1t2... tn of equal length n is value . Record [si ≠ ti] is the Iverson notation and represents the following: if si ≠ ti, it is one, otherwise — zero.Now Xenia w... | Print a single integer — the required Hamming distance. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | The first line contains two integers n and m (1 ≤ n, m ≤ 1012). The second line contains a non-empty string x. The third line contains a non-empty string y. Both strings consist of at most 106 lowercase English letters. It is guaranteed that strings a and b that you obtain from the input have the same length. | standard output | standard input | Python 2 | Python | 1,900 | train_013.jsonl | e8072e571611b1d5a86bb6c7f6b8fdce | 256 megabytes | ["100 10\na\naaaaaaaaaa", "1 1\nabacaba\nabzczzz", "2 3\nrzr\naz"] | PASSED | def gcd(a, b):
c = a % b
return gcd(b, c) if c else b
h = {j: i for i, j in enumerate('abcdefghijklmnopqrstuvwxyz')}
n, m = map(int, raw_input().split())
x, y = raw_input(), raw_input()
a, b = len(x), len(y)
s, c = 0, gcd(a, b)
u, v = range(0, a, c), range(0, b, c)
if a == c:
if b == c:
for i in ran... | 1381838400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1\n0 1\n0\n1", "2\n-1 0 1\n1\n0 1"] | c2362d3254aefe30da99c4aeb4e1a894 | NoteIn the second example you can print polynomials x2 - 1 and x. The sequence of transitions is(x2 - 1, x) → (x, - 1) → ( - 1, 0).There are two steps in it. | Suppose you have two polynomials and . Then polynomial can be uniquely represented in the following way:This can be done using long division. Here, denotes the degree of polynomial P(x). is called the remainder of division of polynomial by polynomial , it is also denoted as . Since there is a way to divide polynom... | Print two polynomials in the following format. In the first line print a single integer m (0 ≤ m ≤ n) — the degree of the polynomial. In the second line print m + 1 integers between - 1 and 1 — the coefficients of the polynomial, from constant to leading. The degree of the first polynomial should be greater than the... | You are given a single integer n (1 ≤ n ≤ 150) — the number of steps of the algorithm you need to reach. | standard output | standard input | Python 3 | Python | 2,200 | train_057.jsonl | e09a3026235d45b3ddf68edc82d0b6cb | 256 megabytes | ["1", "2"] | PASSED | n = int(input())
def print_poly(a):
print(len(a) - 1)
print(' '.join(map(str, a)))
def shift_add(a, mul, b):
c = [0] * (len(a) + 1)
for i in range(len(a)): c[i + 1] = a[i] * mul
for i in range(len(b)): c[i] += b[i]
return c
a = [0, 1]
b = [1]
for i in range(n - 1):
c = shift_add(a, 1, b)... | 1513697700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["4 6 5\n2 2 3"] | 39d8677b310bee8747c5112af95f0e33 | NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$... | Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n ... | For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are... | The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such t... | standard output | standard input | Python 3 | Python | 1,500 | train_001.jsonl | 851a794c71a9a03c398e6560fb6c1aab | 512 megabytes | ["2\n4 6 13\n2 3 1"] | PASSED | # -*- coding: utf-8 -*-
"""
Created on Tue Jul 21 01:33:02 2020
@author: Manan Tyagi
"""
import math
t=int(input())
p=0
a=0
while t:
t-=1
l,r,m=map(int,input().split())
mxd=r-l
if m<l:
pr=m-l
c=r
b=c+pr
a=l
elif m==l:
a=l
b=l
c=l
... | 1595149200 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["4", "2"] | 5be268e0607f2d654d7f5ae4f11e2f08 | NoteThe following is the structure of the cards in the first example.Pak Chanek can choose the permutation $$$a = [1, 5, 4, 3, 2, 6]$$$.Let $$$w_i$$$ be the number written on card $$$i$$$. Initially, $$$w_i = a_i$$$. Pak Chanek can do the following operations in order: Select card $$$5$$$. Append $$$w_5 = 2$$$ to the ... | Pak Chanek has $$$n$$$ blank heart-shaped cards. Card $$$1$$$ is attached directly to the wall while each of the other cards is hanging onto exactly one other card by a piece of string. Specifically, card $$$i$$$ ($$$i > 1$$$) is hanging onto card $$$p_i$$$ ($$$p_i < i$$$).In the very beginning, Pak Chanek must w... | Print a single integer — the maximum length of the longest non-decreasing subsequence of $$$s$$$ at the end if Pak Chanek does all the steps optimally. | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of heart-shaped cards. The second line contains $$$n - 1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i < i$$$) describing which card that each card hangs onto. | standard output | standard input | Python 3 | Python | 1,800 | train_096.jsonl | 91168a86225097c6f1b2250ba9478ff5 | 256 megabytes | ["6\n1 2 1 4 2", "2\n1"] | PASSED | import sys, threading
from collections import defaultdict
def main():
def dfs(node):
d = 1
childs_sum = 0
for adj in tree[node]:
child_depth,childs_val = dfs(adj)
d = max(d, 1 + child_depth)
childs_sum += childs_val
return (d,ma... | 1667034600 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["0\n1\n2\n3"] | 8c4a0a01c37fa1b7c507043ee6d93544 | NoteIn the first sample, the array $$$a$$$ is already good.In the second sample, it's enough to delete $$$1$$$, obtaining array $$$[4, 4, 5, 6]$$$, which is good. | Let's call an array of $$$k$$$ integers $$$c_1, c_2, \ldots, c_k$$$ terrible, if the following condition holds:Let $$$AVG$$$ be the $$$\frac{c_1 + c_2 + \ldots + c_k}{k}$$$(the average of all the elements of the array, it doesn't have to be integer). Then the number of elements of the array which are bigger than $$$AVG... | For each testcase, print the minimum number of elements that you have to delete from it to obtain a good array. | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the size of $$$a$$$. The second line of each testcase contains $$$n$$$ integers $$$... | standard output | standard input | PyPy 3-64 | Python | 2,300 | train_084.jsonl | 1685b7530b86ed69b16a9bee6b9baf83 | 256 megabytes | ["4\n3\n1 2 3\n5\n1 4 4 5 6\n6\n7 8 197860736 212611869 360417095 837913434\n8\n6 10 56026534 405137099 550504063 784959015 802926648 967281024"] | PASSED | import sys
input = sys.stdin.buffer.readline
def finder(A, x, l, r):
if A[r] < x:
return r+1
if A[l] >= x:
return l
s = l
e = r
#A[s] < x <= A[e]
while s+1 < e:
m = (s+e)//2
if A[m] < x:
s, e = m, e
else:
s, e = s... | 1637678100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\nNO\nNO\nYES\nYES\nNO"] | 6d5aefc5a08194e35826764d60c8db3c | NoteIn the first test case, an awesome subsequence of $$$s$$$ is $$$[ab, cc, ba]$$$ | Mihai plans to watch a movie. He only likes palindromic movies, so he wants to skip some (possibly zero) scenes to make the remaining parts of the movie palindromic.You are given a list $$$s$$$ of $$$n$$$ non-empty strings of length at most $$$3$$$, representing the scenes of Mihai's movie.A subsequence of $$$s$$$ is c... | For each test case, print "YES" if there is an awesome subsequence of $$$s$$$, or "NO" otherwise (case insensitive). | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of scenes in the movie. Then follows $$$n$$$ lines, the $$$i$$... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_093.jsonl | 025f21716a3c704f5d6b0869b0a6f57c | 512 megabytes | ["6\n\n5\n\nzx\n\nab\n\ncc\n\nzx\n\nba\n\n2\n\nab\n\nbad\n\n4\n\nco\n\ndef\n\norc\n\nes\n\n3\n\na\n\nb\n\nc\n\n3\n\nab\n\ncd\n\ncba\n\n2\n\nab\n\nab"] | PASSED | import re
for _ in range(int(input())):
n = int(input())
arr = []
for i in range(n):
arr.append(input())
tst = [[arr[0], set(), set(), set()]]
if arr[0] == arr[0][::-1]:
print("YES")
continue
flag = False
for i in range(1, n):
tst.append([arr[i], t... | 1642862100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["2\n3\n1\n3\n0\n0\n2\n1\n3\n4\n9\n2"] | 728e0e5e5d8350a2b79e6a4b5bef407b | NoteThe answer for the first test case was considered above.The answer for the second test case was considered above.In the third test case, it's enough to add to the right the digit $$$4$$$ — the number $$$6$$$ will turn into $$$64$$$.In the fourth test case, let's add to the right the digit $$$8$$$ and then erase $$$... | You are given an integer $$$n$$$. In $$$1$$$ move, you can do one of the following actions: erase any digit of the number (it's acceptable that the number before the operation has exactly one digit and after the operation, it is "empty"); add one digit to the right. The actions may be performed in any order any numbe... | For each test case, output in a separate line one integer $$$m$$$ — the minimum number of moves to transform the number into any power of $$$2$$$. | 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 consists of one line containing one integer $$$n$$$ ($$$1 \le n \le 10^9$$$). | standard output | standard input | PyPy 3-64 | Python | 1,300 | train_103.jsonl | d895ba5787b15bdccc74fbbb6874a733 | 256 megabytes | ["12\n1052\n8888\n6\n75\n128\n1\n301\n12048\n1504\n6656\n1000000000\n687194767"] | PASSED | from heapq import heapify, heappush, heappop
from collections import Counter, defaultdict, deque
from queue import PriorityQueue
from itertools import combinations, product, permutations
from bisect import bisect_left, bisect_right
from functools import lru_cache
from sys import stdin, stdout # for input /output
import... | 1629297300 | [
"math",
"strings"
] | [
0,
0,
0,
1,
0,
0,
1,
0
] | |
1 second | ["2", "0", "Impossible"] | 4147fef7a151c52e92c010915b12c06b | null | You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.The following defin... | If it's impossible to get RBS from s print Impossible. Otherwise print the least number of replaces needed to get RBS from s. | The only line contains a non empty string s, consisting of only opening and closing brackets of four kinds. The length of s does not exceed 106. | standard output | standard input | Python 3 | Python | 1,400 | train_015.jsonl | f2bee33273d4cf388ebf1960543f6567 | 256 megabytes | ["[<}){}", "{()}[]", "]]"] | PASSED | k, s = 0, []
for q in input():
i = '[{<(]}>)'.find(q)
if i > 3:
if not s:
s = 1
break
if s.pop() != i - 4: k += 1
else: s += [i]
print('Impossible' if s else k)
# Made By Mostafa_Khaled | 1451055600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1 1 0 -1 \n1 1 2 2 1 0 2 6 \n3 0 1 4 3 \n1 0 -1 -1 -1 -1 -1 -1 \n2 1 0 2 -1 -1"] | 18d19440e6df7316af0682ce99911738 | NoteIn the first set of example inputs, $$$n=3$$$: to get $$$\mathrm{MEX}=0$$$, it is enough to perform one increment: $$$a_1$$$++; to get $$$\mathrm{MEX}=1$$$, it is enough to perform one increment: $$$a_2$$$++; $$$\mathrm{MEX}=2$$$ for a given array, so there is no need to perform increments; it is impossible to ... | Dmitry has an array of $$$n$$$ non-negative integers $$$a_1, a_2, \dots, a_n$$$.In one operation, Dmitry can choose any index $$$j$$$ ($$$1 \le j \le n$$$) and increase the value of the element $$$a_j$$$ by $$$1$$$. He can choose the same index $$$j$$$ multiple times.For each $$$i$$$ from $$$0$$$ to $$$n$$$, determine ... | For each test case, output $$$n + 1$$$ integer — $$$i$$$-th number is equal to the minimum number of operations for which you can make the array $$$\mathrm{MEX}$$$ equal to $$$i$$$ ($$$0 \le i \le n$$$), or -1 if this cannot be done. | The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of the description of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the array $$... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_093.jsonl | 4f81f4db3e705bbbe22ad9af00a44a3a | 256 megabytes | ["5\n3\n0 1 3\n7\n0 1 2 3 4 3 2\n4\n3 0 0 0\n7\n4 6 2 3 5 0 5\n5\n4 0 1 0 4"] | PASSED | INF = float('inf')
def solve():
n = int(input())
mmin = n + 1
a = []
cnt = [0] * (n + 1)
for i in input().split():
i = int(i)
mmin = min(mmin, i)
a.append(i)
cnt[i] += 1
a.sort()
if mmin > 0:
print(0, end = ' ')
i = 1
whi... | 1640010900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["aaa\n\naaab\n\nabba\n\nbba\n\nabaaa\n\naabba"] | d341e5848836563953b3ec204cd59acc | null | This is an interactive problem.After completing the last level of the enchanted temple, you received a powerful artifact of the 255th level. Do not rush to celebrate, because this artifact has a powerful rune that can be destroyed with a single spell $$$s$$$, which you are going to find. We define the spell as some non... | null | null | standard output | standard input | Python 3 | Python | 2,300 | train_018.jsonl | 0e06aa3a94bb6c99f3aebb47cbede5c0 | 256 megabytes | ["2\n\n2\n\n1\n\n2\n\n3\n\n0"] | PASSED | from sys import stdout
def f(x):
if x == 0:
exit(0)
stdout.flush()
print('a')
x1 = int(input())
f(x1)
if x1 == 300:
print('b' * 300)
exit(0)
lenz = x1 + 1
print('a' * lenz)
x = int(input())
f(x)
ca = lenz - x
patt = ''
c1 = 1
c2 = ca
if ca == 0:
print('b' * (lenz - 1))
x = int(input(... | 1577198100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["7\n2000000000\n0"] | c8da5d7debf5d7a6fc04bb3a68cda2f0 | NoteIn the first test case, we can achieve total intersection $$$5$$$, for example, using next strategy: make $$$[al_1, ar_1]$$$ from $$$[1, 2]$$$ to $$$[1, 4]$$$ in $$$2$$$ steps; make $$$[al_2, ar_2]$$$ from $$$[1, 2]$$$ to $$$[1, 3]$$$ in $$$1$$$ step; make $$$[bl_1, br_1]$$$ from $$$[3, 4]$$$ to $$$[1, 4]$$$ in... | You are given two lists of segments $$$[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$$$ and $$$[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$$$.Initially, all segments $$$[al_i, ar_i]$$$ are equal to $$$[l_1, r_1]$$$ and all segments $$$[bl_i, br_i]$$$ are equal to $$$[l_2, r_2]$$$.In one step, you can choose one s... | Print $$$t$$$ integers — one per test case. For each test case, print the minimum number of step you need to make $$$I$$$ greater or equal to $$$k$$$. | The first line contains the single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le k \le 10^9$$$) — the length of lists and the minimum required total intersection. The second line o... | standard output | standard input | PyPy 3 | Python | 2,100 | train_029.jsonl | 8a691ca2ec3cfb2dbef97c283dec64ac | 256 megabytes | ["3\n3 5\n1 2\n3 4\n2 1000000000\n1 1\n999999999 999999999\n10 3\n5 10\n7 8"] | PASSED | for _ in range(int(input())):
n,k=map(int,input().split())
l1,r1=map(int,input().split())
l2,r2=map(int,input().split())
over=min(r1,r2)-max(l1,l2)
moves=0
#Case1: Already overlapped
if (l1,r1)==(l2,r2):
if (r1-l1)*n>=k:
print(0)
else:
k-=(r1-l1)*n
... | 1596033300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["2\n3 2", "-1", "0"] | a0bceeb856fd95ece1990a0f98658d1a | null | Joseph really likes the culture of Japan. Last year he learned Japanese traditional clothes and visual arts and now he is trying to find out the secret of the Japanese game called Nonogram.In the one-dimensional version of the game, there is a row of $$$n$$$ empty cells, some of which are to be filled with a pen. There... | If there is no profile with the mask $$$m$$$, output the number $$$-1$$$. Otherwise, on the first line, output an integer $$$k$$$ — the number of integers in the profile $$$p'$$$. On the second line, output $$$k$$$ integers of the profile $$$p'$$$. | The only line contains a string $$$m$$$ — the mask of the source profile $$$p$$$. The length of $$$m$$$ is $$$n$$$ ($$$1 \le n \le 100\,000$$$). The string $$$m$$$ consists of symbols # and _ — denoting filled and empty cells respectively. | standard output | standard input | PyPy 3 | Python | 2,700 | train_099.jsonl | 39bca825532bbcec505c933ae44d5f62 | 512 megabytes | ["__#_____", "_#", "___"] | PASSED | import copy
from collections import defaultdict as dd
from collections import deque
import math
import sys
import os
# sys.setrecursionlimit(10**5) # This uses something like 128 MB RAM. I guess only play with this if I expect recursion depth problems.
#region set up dbg commands
# set up debug stuff.
# remember .b... | 1617523500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1 2", "0 1", "3 1"] | d3bdb328e4d37de374cb3201c2a86eee | NoteThe simple cycle is a cycle that doesn't contain any vertex twice. | After Vitaly was expelled from the university, he became interested in the graph theory.Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once.Vitaly was wondering how to solve the following problem. You are given an undirected graph consisting of n vertices and m edges, not necess... | Print in the first line of the output two space-separated integers t and w — the minimum number of edges that should be added to the graph to form a simple cycle of an odd length consisting of more than one vertex where each vertex occurs at most once, and the number of ways to do this. | The first line of the input contains two integers n and m ( — the number of vertices in the graph and the number of edges in the graph. Next m lines contain the descriptions of the edges of the graph, one edge per line. Each edge is given by a pair of integers ai, bi (1 ≤ ai, bi ≤ n) — the vertices that are connected b... | standard output | standard input | Python 3 | Python | 2,000 | train_022.jsonl | 7d1726ad951b396535227c8f1de213b7 | 256 megabytes | ["4 4\n1 2\n1 3\n4 2\n4 3", "3 3\n1 2\n2 3\n3 1", "3 0"] | PASSED | n, m = [int(x) for x in input().split()]
E = {i:[] for i in range(n)}
for i in range(m):
u, v = [int(x)-1 for x in input().split()]
E[v].append(u)
E[u].append(v)
def dfs():
visited = [False for i in range(n)]
colour = [0 for i in range(n)]
ans = 0
for v in range(n):
if visited[v]: c... | 1435676400 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
2 seconds | ["1 1", "1 1", "1 1", "3 4"] | 6b049bd466b050f2dd0a305a381bc0bf | NoteThe picture below shows the rectangles in the first and second samples. The possible answers are highlighted. The picture below shows the rectangles in the third and fourth samples. | You are given $$$n$$$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $$$(n-1)$$$ of the given $$$n$$$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.Find any point with integer coordina... | Print two integers $$$x$$$ and $$$y$$$ — the coordinates of any point that belongs to at least $$$(n-1)$$$ given rectangles. | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 132\,674$$$) — the number of given rectangles. Each the next $$$n$$$ lines contains four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$ and $$$y_2$$$ ($$$-10^9 \le x_1 < x_2 \le 10^9$$$, $$$-10^9 \le y_1 < y_2 \le 10^9$$$) — the coordinates of the bottom ... | standard output | standard input | PyPy 2 | Python | 1,600 | train_008.jsonl | bf69563439d55a97172689024f59060f | 256 megabytes | ["3\n0 0 1 1\n1 1 2 2\n3 0 4 1", "3\n0 0 1 1\n0 1 1 2\n1 0 2 1", "4\n0 0 5 5\n0 0 4 4\n1 1 4 4\n1 1 4 4", "5\n0 0 10 8\n1 2 6 7\n2 3 5 6\n3 4 4 5\n8 1 9 2"] | PASSED | from sys import stdin
def max_arr(a):
tem = [(-float('inf'), -float('inf'), float('inf'), float('inf'))]
for i in range(len(a) - 1, -1, -1):
tem.append(
(max(tem[-1][0], a[i][0]), max(tem[-1][1], a[i][1]), min(tem[-1][2], a[i][2]), min(tem[-1][3], a[i][3])))
return tem[::-1]
valid = ... | 1535387700 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
0.5 second | ["33 109"] | 9c9235394dceba81c8af6be02aa54fcc | null | Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions ... | The only output line should contain two integer non-negative numbers X and Y. Print the only number -1 if there is no answer. | The first line contains integer number A and the second line contains integer number B (0 ≤ A, B ≤ 264 - 1). | standard output | standard input | PyPy 3 | Python | 1,700 | train_002.jsonl | d1a84608421f164b8f3cc10e5767ff36 | 256 megabytes | ["142\n76"] | PASSED | a = int(input())
b = int(input())
k = a - b
if k % 2:
print(-1)
exit(0)
k >>= 1
if k < 0:
print(-1)
exit(0)
print(k, a - k) | 1302609600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["#b\n#big\n#big", "#book\n#co\n#cold", "#\n#\n#art\n#at", "#apple\n#apple\n#fruit"] | 27baf9b1241c0f8e3a2037b18f39fe34 | NoteWord a1, a2, ..., am of length m is lexicographically not greater than word b1, b2, ..., bk of length k, if one of two conditions hold: at first position i, such that ai ≠ bi, the character ai goes earlier in the alphabet than character bi, i.e. a has smaller character than b in the first position where they diff... | Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashta... | Print the resulting hashtags in any of the optimal solutions. | The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of hashtags being edited now. Each of the next n lines contains exactly one hashtag of positive length. It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exce... | standard output | standard input | Python 3 | Python | 1,800 | train_023.jsonl | f1d9236bcb4d08dedd2a6468e7411e2e | 256 megabytes | ["3\n#book\n#bigtown\n#big", "3\n#book\n#cool\n#cold", "4\n#car\n#cart\n#art\n#at", "3\n#apple\n#apple\n#fruit"] | PASSED | def cut_to_lexicographic(word_bigger, word_smaller):
if len(word_bigger) > len(word_smaller):
return word_bigger[:len(word_smaller)]
for l in range(len(word_bigger)):
if word_bigger[l] != word_smaller[l]:
return word_smaller[:l]
return word_bigger
n = int(input())
array = [str(... | 1487930700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["YES", "NO", "NO"] | 600b322b10cbde66ad8ffba5dc7d84e6 | NoteThe graph corresponding to the first example:The graph corresponding to the second example:The graph corresponding to the third example: | As the name of the task implies, you are asked to do some work with segments and trees.Recall that a tree is a connected undirected graph such that there is exactly one simple path between every pair of its vertices.You are given $$$n$$$ segments $$$[l_1, r_1], [l_2, r_2], \dots, [l_n, r_n]$$$, $$$l_i < r_i$$$ for e... | Print "YES" if the resulting graph is a tree and "NO" otherwise. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the number of segments. The $$$i$$$-th of the next $$$n$$$ lines contain the description of the $$$i$$$-th segment — two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i < r_i \le 2n$$$). It is guaranteed that all segments borders are ... | standard output | standard input | PyPy 2 | Python | 2,100 | train_053.jsonl | e7c658c57be950068a07962ba23666b5 | 256 megabytes | ["6\n9 12\n2 11\n1 3\n6 10\n5 7\n4 8", "5\n1 3\n2 4\n5 9\n6 8\n7 10", "5\n5 8\n3 6\n2 9\n7 10\n1 4"] | PASSED | import sys
range = xrange
input = raw_input
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
n = inp[ii]; ii += 1
A = [0]*(2 * n)
L = []
R = []
for i in range(n):
l = inp[ii] - 1; ii += 1
r = inp[ii] - 1; ii += 1
L.append(l)
R.append(r)
A[l] = i
A[r] = ~i
class segtree:
def _... | 1576766100 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["3 1 2 1\n6 5 2 5 3 1 2\n0\n9 4 1 2 10 4 1 2 1 5\n1 1"] | 10c9b2d70030f7ed680297455d1f1bb0 | NoteIn the first test case, we have $$$01\to 11\to 00\to 10$$$.In the second test case, we have $$$01011\to 00101\to 11101\to 01000\to 10100\to 00100\to 11100$$$.In the third test case, the strings are already the same. Another solution is to flip the prefix of length $$$2$$$, which will leave $$$a$$$ unchanged. | This is the easy version of the problem. The difference between the versions is the constraint on $$$n$$$ and the required number of operations. You can make hacks only if all versions of the problem are solved.There are two binary strings $$$a$$$ and $$$b$$$ of length $$$n$$$ (a binary string is a string consisting of... | For each test case, output an integer $$$k$$$ ($$$0\le k\le 3n$$$), followed by $$$k$$$ integers $$$p_1,\ldots,p_k$$$ ($$$1\le p_i\le n$$$). Here $$$k$$$ is the number of operations you use and $$$p_i$$$ is the length of the prefix you flip in the $$$i$$$-th operation. | The first line contains a single integer $$$t$$$ ($$$1\le t\le 1000$$$) — the number of test cases. Next $$$3t$$$ lines contain descriptions of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 1000$$$) — the length of the binary strings. The next two lines contain two binar... | standard output | standard input | Python 3 | Python | 1,300 | train_002.jsonl | d4d3962c1c7559e61bf49f8d1b5ac2ba | 256 megabytes | ["5\n2\n01\n10\n5\n01011\n11100\n2\n01\n01\n10\n0110011011\n1000110100\n1\n0\n1"] | PASSED | for _ in range(int(input())):
n=int(input())
s=input()
s1=input()
s=list(str(x) for x in s)
s1=list(str(x) for x in s1)
c=[]
for i in range(n-1,-1,-1):
if s[len(s)-1]==s1[i]:
s=s[:len(s)-1]
##print(s,i)
continue
if int(s1[i])+int(s[0])==1:
... | 1595342100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["2", "5", "20"] | b4341e1b0ec0b7341fdbe6edfe81a0d4 | NoteIn the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{1... | Petya loves computer games. Finally a game that he's been waiting for so long came out!The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is c... | The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units. | The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-t... | standard output | standard input | Python 2 | Python | 1,400 | train_004.jsonl | 5bed3c1be610b42b888bf959b632ff60 | 256 megabytes | ["2 4\n7 9", "3 8\n17 15 19", "2 2\n99 100"] | PASSED | n,k=map(int,raw_input().split())
t=map(int,raw_input().split())
li=[]
for i in t:
li+=[[10-i%10,i]]
li.sort()
for i in xrange(n):
if(k>=li[i][0]):
if(li[i][0]!=10):
k-=li[i][0]
li[i][1]+=li[i][0]
else:
break
for i in xrange(n):
while(k>9 and li[i][1]<100):
... | 1443430800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["18\n10\n0"] | 4bcaa910cce687f0881a36231aa1a2c8 | NoteAn optimal solution for the first test case is shown in the following figure: The beauty is $$$\left|4-3 \right|+\left|3-5 \right|+\left|2-4 \right|+\left|5-2 \right|+\left|1-6 \right|+\left|6-1 \right|=18$$$.An optimal solution for the second test case is shown in the following figure: The beauty is $$$\left|2-2... | Tokitsukaze has two colorful tapes. There are $$$n$$$ distinct colors, numbered $$$1$$$ through $$$n$$$, and each color appears exactly once on each of the two tapes. Denote the color of the $$$i$$$-th position of the first tape as $$$ca_i$$$, and the color of the $$$i$$$-th position of the second tape as $$$cb_i$$$.No... | For each test case, print a single integer — the highest possible beauty. | The first contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$1\leq n \leq 10^5$$$) — the number of colors. The second line contains $$$n$$$ integers $$$ca_1, ca_2, \ldots, ca_n$$$ ($$$1 \leq ca_i \leq... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_097.jsonl | 7cadc2c941678666d49d6b1410a69dee | 256 megabytes | ["3\n\n6\n\n1 5 4 3 2 6\n\n5 3 1 4 6 2\n\n6\n\n3 5 4 6 2 1\n\n3 6 4 5 2 1\n\n1\n\n1\n\n1"] | PASSED |
def compute(cycleSize, n):
curr = n-1
res = 0
# print("n", n)
for i in range(cycleSize-1):
# print("add", curr)
res += curr
curr -= 1
# print("add", n-cycleSize//2)
if cycleSize % 2 == 0:
res += n - cycleSize//2
else:
res += cycleSize//2
... | 1652020500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["4", "1", "0"] | ea6f55b3775076fcba6554b743b1a8ae | NoteIn the first sample there are four different valid pairs: p = "(", q = "))" p = "()", q = ")" p = "", q = "())" p = "", q = ")()" In the second sample the only way to obtain a desired string is choose empty p and q.In the third sample there is no way to get a valid sequence of brackets. | As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings!The sequence of round brackets is called valid if and only if: the t... | Print the number of pairs of string p and q such that p + s + q is a valid sequence of round brackets modulo 109 + 7. | First line contains n and m (1 ≤ m ≤ n ≤ 100 000, n - m ≤ 2000) — the desired length of the string and the length of the string bought by Gabi, respectively. The second line contains string s of length m consisting of characters '(' and ')' only. | standard output | standard input | PyPy 3 | Python | 2,000 | train_036.jsonl | 166da3d46ab92364324e17d8f14f3c43 | 256 megabytes | ["4 1\n(", "4 4\n(())", "4 3\n((("] | PASSED | n, m = map(int, input().split())
s = input()
mod = 10 ** 9 + 7
c, b, ans, d, k = 0, 0, 0, [[1]], n - m
for i in s:
c += (i == '(') * 2 - 1
b = min(c, b)
for i in range(n - m):
nd = d[-1][1:] + [0] * 2
for j in range(1, i + 2):
nd[j] = (nd[j] + d[-1][j - 1]) % mod
d.append(nd)
for i in range(... | 1455986100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["99\n55\n11115", "385\n360\n792\n8360"] | b3108315889607dabcd3112bcfe3fb54 | null | Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to n.Let us remind you the definition of the greatest common divisor: GCD(a1, ..., ak) = d, where d represents such a maximal positive number that each ai (1 ≤ i ≤ k) is eve... | If there is no answer, print "-1" without quotes. Otherwise print a set of n distinct positive numbers a1, a2, ..., an. Each line must contain one number. Each number must consist of not more than 100 digits, and must not contain any leading zeros. If there are several solutions to that problem, print any of them. Do n... | The first line contains an integer n (2 ≤ n ≤ 50). | standard output | standard input | PyPy 3 | Python | 1,700 | train_000.jsonl | 7a21e907e5a05a060d05c5e7a9a905a4 | 256 megabytes | ["3", "4"] | PASSED |
def isprime(a):
if(a==1 or a==0 or a==2 ):
return 0
x=2
while x*x<=a:
if a%x==0:
return 0
x+=1
return 1
primes=[]
m=1
cnt=0
for x in range(1,300):
if(isprime(x)):
primes.append(x)
n=int(input())
if(n==2):
print(-1)
else :
for i in range(0,n-1):
... | 1299513600 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["1\n2\n9\n1174\n1000000000000"] | e519e4495c9acef4c4a614aef73cb322 | null | Polycarp found a rectangular table consisting of $$$n$$$ rows and $$$m$$$ columns. He noticed that each cell of the table has its number, obtained by the following algorithm "by columns": cells are numbered starting from one; cells are numbered from left to right by columns, and inside each column from top to bottom... | For each test case, output the cell number in the numbering "by rows". | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. Each test case consists of a single line containing three integers $$$n$$$, $$$m$$$, $$$x$$$ ($$$1 \le n, m \le 10^6$$$, $$$1 \le x \le n \cdot m$$$), where $$$n$$$ and $$$m$$$ are the number of rows and columns i... | standard output | standard input | PyPy 3-64 | Python | 800 | train_101.jsonl | 5cb8253afe5729035dae4acb79573787 | 256 megabytes | ["5\n1 1 1\n2 2 3\n3 5 11\n100 100 7312\n1000000 1000000 1000000000000"] | PASSED | for t in range(int(input())):
n,m,k=map(int, input().split())
a=0
if int(k/n)==k/n:
a = int(k/n)
else:
a = int(k/n)+1
k-=(int(k/n)*n)
if k==0:
k=n-1
else:
k-=1
a+=(m*k)
print(a) | 1616682900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0\n8\n218"] | 94ec011dc830661c226bd860b9d70de5 | NoteIn the first test case, we can, for example, swap $$$a_3$$$ with $$$b_3$$$ and $$$a_4$$$ with $$$b_4$$$. We'll get arrays $$$a = [3, 3, 3, 3]$$$ and $$$b = [10, 10, 10, 10]$$$ with sum $$$3 \cdot |3 - 3| + 3 \cdot |10 - 10| = 0$$$.In the second test case, arrays already have minimum sum (described above) equal to $... | You are given two arrays of length $$$n$$$: $$$a_1, a_2, \dots, a_n$$$ and $$$b_1, b_2, \dots, b_n$$$.You can perform the following operation any number of times: Choose integer index $$$i$$$ ($$$1 \le i \le n$$$); Swap $$$a_i$$$ and $$$b_i$$$. What is the minimum possible sum $$$|a_1 - a_2| + |a_2 - a_3| + \dots + ... | For each test case, print one integer — the minimum possible sum $$$\sum\limits_{i=1}^{n-1}{\left(|a_i - a_{i+1}| + |b_i - b_{i+1}|\right)}$$$. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 4000$$$) — the number of test cases. Then, $$$t$$$ test cases follow. The first line of each test case contains the single integer $$$n$$$ ($$$2 \le n \le 25$$$) — the length of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$... | standard output | standard input | Python 3 | Python | 800 | train_092.jsonl | 7516327b54b7793b095f76c3dbc30edc | 256 megabytes | ["3\n\n4\n\n3 3 10 10\n\n10 10 3 3\n\n5\n\n1 2 3 4 5\n\n6 7 8 9 10\n\n6\n\n72 101 108 108 111 44\n\n10 87 111 114 108 100"] | PASSED | for j in range(0,int(input())):
n=int(input())
sum=0
l1=[int(x) for x in input().split()]
l2=[int(x) for x in input().split()]
for i in range(1,n):
if(abs(l1[i]-l1[i-1])+abs(l2[i]-l2[i-1])>abs(l1[i-1]-l2[i])+abs(l2[i-1]-l1[i])):
l1[i],l2[i]=l2[i],l1[i]
sum+=(abs(l... | 1649514900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1", "0", "2", "8"] | 45c1dd4eeba668a454dabf0993cdecac | NoteIn the first test case, the only way to fill in the $$$\texttt{?}$$$s is to fill it in as such: 010111010 This can be accomplished by doing a single operation by choosing $$$(i,j)=(2,2)$$$.In the second test case, it can be shown that there is no sequence of operations that can produce that grid. | There is a grid with $$$r$$$ rows and $$$c$$$ columns, where the square on the $$$i$$$-th row and $$$j$$$-th column has an integer $$$a_{i, j}$$$ written on it. Initially, all elements are set to $$$0$$$. We are allowed to do the following operation: Choose indices $$$1 \le i \le r$$$ and $$$1 \le j \le c$$$, then rep... | Print a single integer representing the number of ways to fill up grid $$$b$$$ modulo $$$998244353$$$. | The first line contains two integers $$$r$$$ and $$$c$$$ ($$$1 \le r, c \le 2000$$$) — the number of rows and columns of the grid respectively. The $$$i$$$-th of the next $$$r$$$ lines contain $$$c$$$ characters $$$b_{i, 1}, b_{i, 2}, \ldots, b_{i, c}$$$ ($$$b_{i, j} \in \{0, 1, ?\}$$$). | standard output | standard input | PyPy 3 | Python | 3,200 | train_108.jsonl | 5178c98fbee2bf661f6321b6f8e00552 | 256 megabytes | ["3 3\n?10\n1??\n010", "2 3\n000\n001", "1 1\n?", "6 9\n1101011?0\n001101?00\n101000110\n001011010\n0101?01??\n00?1000?0"] | PASSED | # import io,os
# read = io.BytesIO(os.read(0, os.fstat(0).st_size))
# I = lambda: [*map(int, read.readline().split())]
import sys
I=lambda:[*map(int,sys.stdin.readline().split())]
M = 998244353
r, c = I()
rows = []
for i in range(r):
rows.append([*input()])
if r % 2 == 0 and c % 2 == 0:
blanks = 0
fo... | 1650722700 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
2 seconds | ["10 10 10\n10 10 10\n10 10 10", "4 4\n10 6", "-1 -1\n-1 -1"] | 7b13ee633c81abdcf912542ba1779a45 | NoteIn the first example, the answer is always $$$10$$$ no matter how you walk.In the second example, $$$answer_{21} = 10$$$, the path is $$$(2,1) \to (1,1) \to (1,2) \to (2,2) \to (2,1)$$$, the boredness is $$$4 + 1 + 2 + 3 = 10$$$. | You are wandering in the explorer space of the 2050 Conference.The explorer space can be viewed as an undirected weighted grid graph with size $$$n\times m$$$. The set of vertices is $$$\{(i, j)|1\le i\le n, 1\le j\le m\}$$$. Two vertices $$$(i_1,j_1)$$$ and $$$(i_2, j_2)$$$ are connected by an edge if and only if $$$|... | Output $$$n$$$ lines with $$$m$$$ numbers each. The $$$j$$$-th number in the $$$i$$$-th line, $$$answer_{ij}$$$, should be the minimum possible boredness if you walk from $$$(i, j)$$$ and go back to it after exactly $$$k$$$ steps. If you cannot go back to vertex $$$(i, j)$$$ after exactly $$$k$$$ steps, $$$answer_{ij}$... | The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2\leq n, m\leq 500, 1\leq k\leq 20$$$). The $$$j$$$-th number ($$$1\le j \le m - 1$$$) in the $$$i$$$-th line of the following $$$n$$$ lines is the number of exibits on the edge between vertex $$$(i, j)$$$ and vertex $$$(i, j+1)$$$. The $$$j$$$-th... | standard output | standard input | PyPy 3-64 | Python | 1,800 | train_101.jsonl | 0403abc133f6b660468ad64c73d8b684 | 256 megabytes | ["3 3 10\n1 1\n1 1\n1 1\n1 1 1\n1 1 1", "2 2 4\n1\n3\n4 2", "2 2 3\n1\n2\n3 4"] | PASSED | def roll(i,j):
ways = []
if j:
ways.append( 2 * horizontal[i][j-1] + grid[i][j-1])
if m-1-j:
ways.append(2 * horizontal[i][j] + grid[i][j+1])
if i:
ways.append(2 * vertical[i-1][j] + grid[i-1][j])
if n-1-i:
ways.append(2 * vertical[i][j] + grid[i+1][j])
... | 1619188500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1", "0", "4", "1"] | 583168dfbaa91b79c623b44b7efee653 | NoteIn the third sample there are four appropriate different substrings. They are: ab, abab, ababab, abababab.In the fourth sample identificators intersect. | Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the sbegin and ending with the send (it is possible sbegin = send), the given string t has. Substrings... | Output the only number — the amount of different substrings of t that start with sbegin and end with send. | The input file consists of three lines. The first line contains string t. The second and the third lines contain the sbegin and send identificators, correspondingly. All three lines are non-empty strings consisting of lowercase Latin letters. The length of each string doesn't exceed 2000 characters. | standard output | standard input | Python 3 | Python | 2,000 | train_014.jsonl | 631060720a3500ab8de5900b33dcfdb0 | 256 megabytes | ["round\nro\nou", "codeforces\ncode\nforca", "abababab\na\nb", "aba\nab\nba"] | PASSED | from functools import cmp_to_key
def calc_lcp(s, sa):
rank = [0 for _ in range(len(s))]
for i in range(len(s)):
rank[sa[i]] = i
lcp = [0 for _ in range(len(s) - 1)]
h = 0
for i in range(len(s)):
if rank[i] < len(s) - 1:
while max(i, sa[rank[i] + 1]) + h < len... | 1315494000 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["1", "2", "0"] | 3583a9762191ee8f8c3c2a287cb1ec1d | NoteIn the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronoun... | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did. The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types: Valentin pronounced some word and didn't get an electric shock. This action is d... | standard output | standard input | Python 3 | Python | 1,600 | train_003.jsonl | 96b99887cdaf368867b4fdf5ee5731e1 | 256 megabytes | ["5\n! abc\n. ad\n. b\n! cd\n? c", "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e", "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h"] | PASSED | '''input
5
! abc
. ad
. b
! cd
? c
'''
t = [0] * 26
e = 0
n = int(input())
if n == 1:
print(0)
quit()
for i in range(n-1):
x, y = input().split()
if x == '!':
if 1 in t:
c = [ord(p) - 97 for p in set(y)]
for x in range(26):
if not(t[x] == 1 and x in c):
t[x] = -1
else:
for l in set(y):
if ... | 1514037900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["13\n9\n3"] | 113a43af2f1c5303f83eb842ef532040 | NoteIn the first testcase, it's enough to consider the following modified paths: RD $$$\rightarrow$$$ RRD $$$\rightarrow$$$ RRRD $$$\rightarrow$$$ RRRDD $$$\rightarrow$$$ RRRDDD — this path visits cells $$$(1, 1)$$$, $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(1, 4)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$ and $$$(4, 4)$$$; RD $$$\righta... | Consider a grid of size $$$n \times n$$$. The rows are numbered top to bottom from $$$1$$$ to $$$n$$$, the columns are numbered left to right from $$$1$$$ to $$$n$$$.The robot is positioned in a cell $$$(1, 1)$$$. It can perform two types of moves: D — move one cell down; R — move one cell right. The robot is not all... | For each testcase, print a single integer — the number of cells such that there exists at least one sequence of modifications that the robot visits this cell on the modified path and doesn't move outside the grid. | 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 the single integer $$$n$$$ ($$$2 \le n \le 10^8$$$) — the number of rows and columns in the grid. The second line of each testcase contains a non-empty string $$$s$$$, consisting... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_108.jsonl | 93b24e422cf9bba138e4ee5d5b6a6be5 | 256 megabytes | ["3\n\n4\n\nRD\n\n5\n\nDRDRDRDR\n\n3\n\nD"] | PASSED | import sys
from array import array
import re
input = lambda: sys.stdin.buffer.readline().decode().strip()
inp = lambda dtype: [dtype(x) for x in input().split()]
inp_2d = lambda dtype, n: [dtype(input()) for _ in range(n)]
inp_2ds = lambda dtype, n: [inp(dtype) for _ in range(n)]
ceil1 = lambda a, b: (a + b - ... | 1645540500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["5", "2", "0", "-1"] | a3a7515219ebb0154218ee3520e20d75 | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what i... | Print the minimal number of moves Mike needs in order to make all the strings equal or print - 1 if there is no solution. | The first line contains integer n (1 ≤ n ≤ 50) — the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | standard output | standard input | Python 3 | Python | 1,300 | train_008.jsonl | a92c478d9a6acd1d61dff61f27b4d575 | 256 megabytes | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | PASSED | def rotate(s):
n = len(s)
return s[1:] + s[0]
n = int(input())
a = [input() for _ in range(n)]
s = a[0]
n = len(s)
min_cost = float('inf')
for _ in range(n):
s = rotate(s)
cost = 0
for i in a:
found = False
for _ in range(n):
if i == s:
found = True
... | 1492785300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["4", "2", "4"] | fc057414df9fd8b61e01cda8bc5cdcaf | NoteIn the first and second examples initial positions of black tokens are shown with black points, possible positions of the white token (such that the black player wins) are shown with white points.The first example: The second example: In the third example the white tokens should be located in the inner square 2 × 2... | Consider the following game for two players. There is one white token and some number of black tokens. Each token is placed on a plane in a point with integer coordinates x and y.The players take turn making moves, white starts. On each turn, a player moves all tokens of their color by 1 to up, down, left or right. Bla... | Print the number of points where the white token can be located initially, such that if both players play optimally, the black player wins. | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of black points. The (i + 1)-th line contains two integers xi, yi ( - 105 ≤ xi, yi, ≤ 105) — the coordinates of the point where the i-th black token is initially located. It is guaranteed that initial positions of black tokens are distinct. | standard output | standard input | Python 2 | Python | 2,500 | train_007.jsonl | f924891c3197a9a876a50a9ab2e2080b | 256 megabytes | ["4\n-2 -1\n0 1\n0 -3\n2 -1", "4\n-2 0\n-1 1\n0 -2\n1 -1", "16\n2 1\n1 2\n-1 1\n0 1\n0 0\n1 1\n2 -1\n2 0\n1 0\n-1 -1\n1 -1\n2 2\n0 -1\n-1 0\n0 2\n-1 2"] | PASSED | from sys import stdin
from itertools import repeat
def solve(a):
inf = 1001001001
C = 400010
lmn = [inf] * 400010
lmx = [-inf] * 400010
for x, y in a:
x = (x - 1) / 2 + 100005
if lmn[x] > y:
lmn[x] = y
if lmx[x] < y:
lmx[x] = y
rmn = lmn[:]
rmx... | 1520177700 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
1 second | ["8\n-1\n-1\n-1\n4\n1\n-1"] | 07597a8d08b59d4f8f82369bb5d74a49 | NoteIn the first test case, there's a desired circle of $$$8$$$ people. The person with the number $$$6$$$ will look at the person with the number $$$2$$$ and the person with the number $$$8$$$ will look at the person with the number $$$4$$$.In the second test case, there's no circle meeting the conditions. If the pers... | Some number of people (this number is even) have stood in a circle. The people stand in the circle evenly. They are numbered clockwise starting from a person with the number $$$1$$$. Each person is looking through the circle's center at the opposite person. A sample of a circle of $$$6$$$ persons. The orange arrows ... | For each test case output in a separate line a single integer $$$d$$$ — the number of the person being looked at by the person with the number $$$c$$$ in a circle such that the person with the number $$$a$$$ is looking at the person with the number $$$b$$$. If there are multiple solutions, print any of them. Output $$$... | 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 consists of one line containing three distinct integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \le a,b,c \le 10^8$$$). | standard output | standard input | Python 3 | Python | 800 | train_103.jsonl | 994ed22a5a5cbb17090838f6abe68981 | 256 megabytes | ["7\n6 2 4\n2 3 1\n2 4 10\n5 3 4\n1 3 2\n2 5 4\n4 3 2"] | PASSED | t=int(input())
qwe=[]
for i in range(t):
qwe.append(list(map(int,input().split())))
for j in range(t):
a = qwe[j][0]
b = qwe[j][1]
c = qwe[j][2]
if a > b:
a, b = b, a
h = b - a
f = 2 * h
if (f < b) or (c > f):
d = -1
else:
if (c + h) >... | 1629297300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n0\n1\n3"] | 7a724f327c6202735661be25ef9328d2 | NoteIn the first test case of the example, it is sufficient to move the first bracket to the end of the string.In the third test case of the example, it is sufficient to move the last bracket to the beginning of the string.In the fourth test case of the example, we can choose last three openning brackets, move them to ... | You are given a bracket sequence $$$s$$$ of length $$$n$$$, where $$$n$$$ is even (divisible by two). The string $$$s$$$ consists of $$$\frac{n}{2}$$$ opening brackets '(' and $$$\frac{n}{2}$$$ closing brackets ')'.In one move, you can choose exactly one bracket and move it to the beginning of the string or to the end ... | For each test case, print the answer — the minimum number of moves required to obtain regular bracket sequence from $$$s$$$. It can be proved that the answer always exists under the given constraints. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$2 \le n \le 50$$$) — the length of $$$s$$$. It is guaranteed that $$$n$$$ is even. The second line of the test ca... | standard output | standard input | Python 3 | Python | 1,000 | train_032.jsonl | 105ca32a1572ebe881f0dfe548135f10 | 256 megabytes | ["4\n2\n)(\n4\n()()\n8\n())()()(\n10\n)))((((())"] | PASSED |
t=int(input())
for i in range(t):
n=int(input())
s=input()
while '()' in s:
s=s.replace('()','')
m=s.count(')')
print(m) | 1593354900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["YES\nYES\nNO"] | 9b9b01e5d2329291eee80356525eaf04 | NoteIn the first query, you can perform two operations $$$s_1 = s_2$$$ (after it $$$s$$$ turns into "aabb") and $$$t_4 = t_3$$$ (after it $$$t$$$ turns into "aabb"). In the second query, the strings are equal initially, so the answer is "YES".In the third query, you can not make strings $$$s$$$ and $$$t$$$ equal. There... | You are given two strings of equal length $$$s$$$ and $$$t$$$ consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.During each operation you choose two adjacent characters in any string and assign the value of the first character to the value of the second or vi... | For each query, print "YES" if it is possible to make $$$s$$$ equal to $$$t$$$, and "NO" otherwise. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes", and "YES" will all be recognized as positive answer). | The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is represented by two consecutive lines. The first line of each query contains the string $$$s$$$ ($$$1 \le |s| \le 100$$$) consisting of lowercase Latin letters. The second line of each query contains the string $$$... | standard output | standard input | Python 3 | Python | 1,000 | train_000.jsonl | aa279198e77a2eb7deb7c6e43928baf1 | 256 megabytes | ["3\nxabb\naabx\ntechnocup\ntechnocup\na\nz"] | PASSED | n=int(input())
for i in range (n):
a,b=(input()),(input())
for i in b:
if i in a:
k="YES"
break
else:
k="NO"
print(k) | 1570374300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["YES", "YES", "NO"] | 447ebe088a0a60a7a44a3fc76056bc65 | NoteIn the first sample .In the second sample .In the third sample . | A continued fraction of height n is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height n. Check if they are equal. | Print "YES" if these fractions are equal and "NO" otherwise. | The first line contains two space-separated integers p, q (1 ≤ q ≤ p ≤ 1018) — the numerator and the denominator of the first fraction. The second line contains integer n (1 ≤ n ≤ 90) — the height of the second fraction. The third line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1018) — the continued ... | standard output | standard input | Python 3 | Python | 1,700 | train_022.jsonl | 5fad1e9b0b4077ba279ffa32b3481b45 | 256 megabytes | ["9 4\n2\n2 4", "9 4\n3\n2 3 1", "9 4\n3\n1 2 4"] | PASSED | p,q = input().split()
p = int(p)
q = int(q)
n = int(input())
A = input().split()
a = 1
b = int(A[n-1])
i = n-2
while( i >= 0 ):
aux = b
b = a + b*int(A[i])
a = aux
i = i-1
print ("YES" if p*a == q*b else "NO" ) | 1368968400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3", "3"] | c3c3ac7a8c9d2ce142e223309ab005e6 | NoteIn the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3).In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the ... | A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missile... | Print the single number — the number of Super Duper Secret Missile Silos that are located in Berland. | The first line contains three integers n, m and s (2 ≤ n ≤ 105, , 1 ≤ s ≤ n) — the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s. Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≤ ... | standard output | standard input | Python 2 | Python | 1,900 | train_034.jsonl | 7d05cf904c01f04ba9a69d2aa39513e1 | 256 megabytes | ["4 6 1\n1 2 1\n1 3 3\n2 3 1\n2 4 1\n3 4 1\n1 4 2\n2", "5 6 3\n3 1 1\n3 2 1\n3 4 1\n3 5 1\n1 2 6\n4 5 8\n4"] | PASSED | from heapq import *
n,m,s=map(int,raw_input().split())
g=[[] for _ in range(n+1)]
for _ in range(m):
u,v,w=map(int,raw_input().split())
g[u].append((v,w))
g[v].append((u,w))
l=input()
d=[10**10]*(n+1)
d[s]=0
q=[(0,s)]
while q:
t,u=heappop(q)
if t==d[u]:
for v,w in g[u]:
if d[v]>t+w:
d[v]=t+... | 1326899100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["3", "0", "inf"] | 749c290c48272a53e2e79730dab0538e | NoteIn the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.... | Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi =... | Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. | The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers... | standard output | standard input | Python 2 | Python | 1,700 | train_008.jsonl | ad6b114a251dfc728156c85cc083b945 | 256 megabytes | ["3 2 30 4\n6 14 25 48", "123 1 2143435 4\n123 11 -5453 141245", "123 1 2143435 4\n54343 -13 6 124"] | PASSED | b1, q, l, m = [int(x) for x in raw_input().split()]
lst = [int(x) for x in raw_input().split()]
st = set(lst)
cur = b1
ans = 0
ok = False
if abs(b1) > l:
print 0
exit()
for _ in xrange(64):
if cur not in st:
ans += 1
cur *= q
if abs(cur) > l:
ok = True
break
if not ok and q == 0:
if 0 in st:
print an... | 1490803500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1.50000000000000000000", "2.00000000000000000000"] | 85b78251160db9d7ca1786e90e5d6f21 | NoteIn the first sample, there are two cases. One is directly remove the root and another is remove the root after one step. Thus the expected steps are: 1 × (1 / 2) + 2 × (1 / 2) = 1.5In the second sample, things get more complex. There are two cases that reduce to the first sample, and one case cleaned at once. Thus ... | Momiji has got a rooted tree, consisting of n nodes. The tree nodes are numbered by integers from 1 to n. The root has number 1. Momiji decided to play a game on this tree.The game consists of several steps. On each step, Momiji chooses one of the remaining tree nodes (let's denote it by v) and removes all the subtree ... | Print a single real number — the expectation of the number of steps in the described game. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. | The first line contains integer n (1 ≤ n ≤ 105) — the number of nodes in the tree. The next n - 1 lines contain the tree edges. The i-th line contains integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi) — the numbers of the nodes that are connected by the i-th edge. It is guaranteed that the given graph is a tree. | standard output | standard input | Python 2 | Python | 2,200 | train_011.jsonl | af0b4b86f374570c2fc40e816116dee7 | 256 megabytes | ["2\n1 2", "3\n1 2\n1 3"] | PASSED | n = input()
edge = [[] for _ in range(n)]
for i in range(n - 1):
a, b = map(int, raw_input().split())
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
d = [0] * n
d[0] = 1
p = [0]
for u in p:
for v in edge[u]:
if not d[v]:
d[v] = d[u] + 1
p.append(v)
print sum((1. / x ... | 1362929400 | [
"probabilities",
"math",
"trees"
] | [
0,
0,
0,
1,
0,
1,
0,
1
] | |
2 seconds | ["0\n0\n3\n3", "0\n0\n0\n3\n3\n4\n4\n5", "0\n0\n0\n0\n3\n4\n4"] | d795e0f49617b1aa281c72f24a632f67 | NoteIn the first example, $$$1,2,3$$$ can go on day $$$3$$$ and $$$4$$$. In the second example, $$$2,4,5$$$ can go on day $$$4$$$ and $$$5$$$. $$$1,2,4,5$$$ can go on day $$$6$$$ and $$$7$$$. $$$1,2,3,4,5$$$ can go on day $$$8$$$. In the third example, $$$1,2,5$$$ can go on day $$$5$$$. $$$1,2,3,5$$$ can go on... | There are $$$n$$$ persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends.We want to plan a trip for every evening of $$$m$$$ days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should ho... | Print exactly $$$m$$$ lines, where the $$$i$$$-th of them ($$$1\leq i\leq m$$$) contains the maximum number of people that can go on the trip on the evening of the day $$$i$$$. | The first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$2 \leq n \leq 2 \cdot 10^5, 1 \leq m \leq 2 \cdot 10^5$$$, $$$1 \le k < n$$$) — the number of people, the number of days and the number of friends each person on the trip should have in the group. The $$$i$$$-th ($$$1 \leq i \leq m$$$) of the n... | standard output | standard input | Python 3 | Python | 2,200 | train_073.jsonl | 10accb27649ab606e19aeacbd53bbb52 | 256 megabytes | ["4 4 2\n2 3\n1 2\n1 3\n1 4", "5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2", "5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3"] | PASSED | from collections import deque
def solve(adj, m, k, uv):
n = len(adj)
nn = [len(a) for a in adj]
q = deque()
for i in range(n):
if nn[i] < k:
q.append(i)
while q:
v = q.popleft()
for u in adj[v]:
nn[u] -= 1
if nn[u] == k-1:
... | 1535898900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1\n2\n5\n2\n0", "8\n2\n9\n8"] | 7e03c9e316f36c1d9487286237e24c6f | NoteAnswers on queries from the first example are described in the problem statement. | The only difference between the easy and the hard versions is the maximum value of $$$k$$$.You are given an infinite sequence of form "112123123412345$$$\dots$$$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $$$1$$$ to $$$1$$$, the ... | Print $$$q$$$ lines. In the $$$i$$$-th line print one digit $$$x_i$$$ $$$(0 \le x_i \le 9)$$$ — the answer to the query $$$i$$$, i.e. $$$x_i$$$ should be equal to the element at the position $$$k_i$$$ of the sequence. | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. The $$$i$$$-th of the following $$$q$$$ lines contains one integer $$$k_i$$$ $$$(1 \le k_i \le 10^9)$$$ — the description of the corresponding query. | standard output | standard input | PyPy 3 | Python | 1,900 | train_032.jsonl | e1aefc351f762be9d78167f3fac6bb43 | 256 megabytes | ["5\n1\n3\n20\n38\n56", "4\n2132\n506\n999999999\n1000000000"] | PASSED | word = ''
arr = [0]
for i in range(1,22000):
word = word + str(i)
arr.append(arr[-1] + len(word))
def sol(k):
d = 0
for i in range(1,22000):
if arr[i] > k:
d = i - 1
break
k = k - arr[d]
if k == 0:
return str(d)[-1]
else:
return word[... | 1569049500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["2 4 2 0"] | 8543bcd08ec0bbbf9a0a3682468287f4 | NoteThe minimal possible total cost is $$$566 \cdot 1+239 \cdot 1+30 \cdot 1+1 \cdot 2+1 \cdot 2=839$$$: | Julia's $$$n$$$ friends want to organize a startup in a new country they moved to. They assigned each other numbers from 1 to $$$n$$$ according to the jobs they have, from the most front-end tasks to the most back-end ones. They also estimated a matrix $$$c$$$, where $$$c_{ij} = c_{ji}$$$ is the average number of messa... | Output a description of a hierarchy tree that minimizes the total cost of communication. To do so, for each team member from 1 to $$$n$$$ output the number of the member in its parent node, or 0 for the leader. If there are many optimal trees, output a description of any one of them. | The first line contains an integer $$$n$$$ ($$$1 \le n \le 200$$$) – the number of team members organizing a startup. The next $$$n$$$ lines contain $$$n$$$ integers each, $$$j$$$-th number in $$$i$$$-th line is $$$c_{ij}$$$ — the estimated number of messages per month between team members $$$i$$$ and $$$j$$$ ($$$0 \le... | standard output | standard input | PyPy 3-64 | Python | 2,100 | train_091.jsonl | 649315f68598a26f2a9b26cc6dd8f7e1 | 512 megabytes | ["4\n0 566 1 0\n566 0 239 30\n1 239 0 1\n0 30 1 0"] | PASSED | n=int(input())
c=[]
for _ in range(n):
c.append(tuple(map(int,input().split())))
prefix_sum=[[0]*(n+1) for _ in range(n+1)]
for i in range(1,n+1):
temp=0
for j in range(1,n+1):
temp+=c[i-1][j-1]
prefix_sum[i][j]+=prefix_sum[i-1][j]+temp
def get_rectangel_sum(x1,y1,x2,y2):
retu... | 1649837100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["YES\naccx\naegx\nbega\nbdda\nYES\naha\naha\nYES\nzz\naa\nzz\nNO\nYES\naaza\nbbza\nNO\nYES\nbbaabbaabbaabbaay\nddccddccddccddccy\nNO"] | a15f7324d545c26725324928eaaa645c | null | The only difference between this problem and D1 is that you don't have to provide the way to construct the answer in D1, but you have to do it in this problem.There's a table of $$$n \times m$$$ cells ($$$n$$$ rows and $$$m$$$ columns). The value of $$$n \cdot m$$$ is even.A domino is a figure that consists of two cell... | For each test case: print "NO" if it's not possible to place the dominoes on the table in the described way; otherwise, print "YES" on a separate line, then print $$$n$$$ lines so that each of them contains $$$m$$$ lowercase letters of the Latin alphabet — the layout of the dominoes on the table. Each cell of the ta... | 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 a single line. The line contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$1 \le n,m \le 100$$$, $$$0 \le k \le \frac{nm}{2}$$$, $$$n \cdot m$$$ is even) — the cou... | standard output | standard input | PyPy 3-64 | Python | 2,100 | train_099.jsonl | 7dcef7b2db9c1183b624f0a31f094345 | 256 megabytes | ["8\n4 4 2\n2 3 0\n3 2 3\n1 2 0\n2 4 2\n5 2 2\n2 17 16\n2 1 1"] | PASSED | import sys
from math import ceil
input = sys.stdin.readline
inf = float('inf')
def getInt():
return int(input())
def getList():
return map(int, input().split())
def getStr():
return input().strip()
t = getInt()
# t = 1
def solve():
# what we are trying to accomplish here is to make the empty re... | 1627050900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["4", "1", "0"] | 6a3d6919435e5ba63bb95cd387a11b06 | NoteIn the first sample, the four ways are to: Make everyone love each other Make 1 and 2 love each other, and 3 hate 1 and 2 (symmetrically, we get 3 ways from this). In the second sample, the only possible solution is to make 1 and 3 love each other and 2 and 4 hate each other. | There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has n characters. The characters are labeled from 1 to n. Every pair of two characters can either mutually love each other or mutually hate each other (the... | Print a single integer equal to the number of ways to fill in the remaining pairs so that you are happy with every triangle modulo 1 000 000 007. | The first line of input will contain two integers n, m (3 ≤ n ≤ 100 000, 0 ≤ m ≤ 100 000). The next m lines will contain the description of the known relationships. The i-th line will contain three integers ai, bi, ci. If ci is 1, then ai and bi are in love, otherwise, they hate each other (1 ≤ ai, bi ≤ n, ai ≠ bi, ). ... | standard output | standard input | Python 3 | Python | 2,200 | train_010.jsonl | a2d4687aa2a2cf8406e82f48a03cccda | 256 megabytes | ["3 0", "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0", "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1"] | PASSED | class DSU(object):
def __init__(self, n):
self.father = list(range(n))
self.size = n
def union(self, x, s):
x = self.find(x)
s = self.find(s)
if x == s:
return
self.father[s] = x
self.size -= 1
def find(self, x):
xf = self.father[... | 1435163400 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["6"] | 414d1f0cef26fbbf4ede8eac32a1dd48 | null | You are playing another computer game, and now you have to slay $$$n$$$ monsters. These monsters are standing in a circle, numbered clockwise from $$$1$$$ to $$$n$$$. Initially, the $$$i$$$-th monster has $$$a_i$$$ health.You may shoot the monsters to kill them. Each shot requires exactly one bullet and decreases the h... | For each test case, print one integer — the minimum number of bullets you have to fire to kill all of the monsters. | The first line contains one integer $$$T$$$ ($$$1 \le T \le 150000$$$) — the number of test cases. Then the test cases follow, each test case begins with a line containing one integer $$$n$$$ ($$$2 \le n \le 300000$$$) — the number of monsters. Then $$$n$$$ lines follow, each containing two integers $$$a_i$$$ and $$$b_... | standard output | standard input | PyPy 3 | Python | 1,600 | train_001.jsonl | 72cd6ae417f3e5a3c274175c5e1ad52e | 256 megabytes | ["1\n3\n7 15\n2 14\n5 3"] | PASSED | import sys
input = sys.stdin.buffer.readline
T = int(input())
for _ in range(T):
n = int(input())
a,b = [],[]
for i in range(n):
x,y = map(int,input().split())
a.append(x)
b.append(y)
for i in range(n):
b[i] = min(a[(i+1)%n],b[i])
b[-1] = min(a[0],b[-1])
print(sum... | 1586529300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n3\n2"] | 68b7567880b9980d793dae2bce690356 | NoteIn the first test case, $$$a$$$ = $$$[6, 6, 6]$$$ and $$$a'$$$ = $$$[6, 6, 6]$$$. $$$\text{LIS}(a) = \text{LIS}(a')$$$ = $$$1$$$. Hence the beauty is $$$min(1, 1) = 1$$$.In the second test case, $$$a$$$ can be rearranged to $$$[2, 5, 4, 5, 4, 2]$$$. Then $$$a'$$$ = $$$[2, 4, 5, 4, 5, 2]$$$. $$$\text{LIS}(a) = \text... | You are given an array $$$a$$$ of $$$n$$$ positive integers. Let $$$\text{LIS}(a)$$$ denote the length of longest strictly increasing subsequence of $$$a$$$. For example, $$$\text{LIS}([2, \underline{1}, 1, \underline{3}])$$$ = $$$2$$$. $$$\text{LIS}([\underline{3}, \underline{5}, \underline{10}, \underline{20}])$$$ ... | For each test case, output a single integer — the maximum possible beauty of $$$a$$$ after rearranging its elements arbitrarily. | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 2\cdot 10^5)$$$ — the length of array $$$a$$$. ... | standard output | standard input | Python 3 | Python | 1,400 | train_101.jsonl | e28b9b4974cd149635d4eee98cee90e8 | 256 megabytes | ["3\n\n3\n\n6 6 6\n\n6\n\n2 5 4 5 2 4\n\n4\n\n1 3 2 2"] | PASSED | import sys
from collections import Counter
from math import ceil
sys.setrecursionlimit(10**5)
def pro(arr):
n=len(arr)
dic = {}
for i in range(n):
dic[arr[i]]=dic.get(arr[i],0) + 1
a,b=0,0
for i,j in dic.items():
if(j>=2):
b+=1
else:
... | 1653230100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1", "2 1 4\n3 5 7\n6 9 8"] | a7da19d857ca09f052718cb69f2cea57 | null | Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. | Print n lines with n integers. All the integers should be different and from 1 to n2. The sum in each row, column and both main diagonals should be odd. | The only line contains odd integer n (1 ≤ n ≤ 49). | standard output | standard input | Python 2 | Python | 1,500 | train_018.jsonl | cc3f25da0df27998828208b556c23193 | 256 megabytes | ["1", "3"] | PASSED | #n = input()
n = input()
odds = [i for i in range(1,n*n+1) if i % 2 == 1]
evens = [i for i in range(1,n*n+1) if i % 2 == 0]
#print(odds)
#print(evens)
magic = []
for i in range(int(n/2)):
magic.append(2*i+1)
magic2 = magic[::-1]
magic = magic + [n] + magic2
#print(magic)
result = []
for i in range(n):
... | 1471875000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2\n5\n1"] | 1a6881aeb197b8ed429f46850eb27b9c | NoteIn the first test case, $$$121$$$ can be represented as $$$121 = 110 + 11$$$ or $$$121 = 111 + 10$$$.In the second test case, $$$5$$$ can be represented as $$$5 = 1 + 1 + 1 + 1 + 1$$$.In the third test case, $$$1\,000\,000\,000$$$ is a binary decimal itself, thus the answer is $$$1$$$. | Let's call a number a binary decimal if it's a positive integer and all digits in its decimal notation are either $$$0$$$ or $$$1$$$. For example, $$$1\,010\,111$$$ is a binary decimal, while $$$10\,201$$$ and $$$787\,788$$$ are not.Given a number $$$n$$$, you are asked to represent $$$n$$$ as a sum of some (not necess... | For each test case, output the smallest number of binary decimals required to represent $$$n$$$ as a sum. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^9$$$), denoting the number to be represented. | standard output | standard input | Python 3 | Python | 800 | train_102.jsonl | cc7ad02d3c50f0a742261a162b06840f | 512 megabytes | ["3\n121\n5\n1000000000"] | PASSED | nt = int(input())
for tt in range(nt):
s = max(map(int, list(input())))
print(s) | 1626532500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["0.000000", "13.000000"] | c4609bd2b4652cb5c2482b16909ec64a | NoteIn the first test the sequence is already sorted, so the answer is 0. | Jeff has become friends with Furik. Now these two are going to play one quite amusing game.At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p1, p2, ..., pn. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two adjacent... | In a single line print a single real value — the answer to the problem. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. | The first line contains integer n (1 ≤ n ≤ 3000). The next line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation p. The numbers are separated by spaces. | standard output | standard input | Python 3 | Python | 1,900 | train_004.jsonl | 261e1491695a20540a455845278ef8dc | 256 megabytes | ["2\n1 2", "5\n3 5 2 4 1"] | PASSED | #!/usr/bin/python3
import sys
class CumTree:
def __init__(self, a, b):
self.a = a
self.b = b
self.count = 0
if a == b:
return
mid = (a + b) // 2
self.levo = CumTree(a, mid)
self.desno = CumTree(mid+1, b)
def manjsi(self, t):
... | 1380900600 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
1 second | ["6\ntabbat", "6\noxxxxo", "0", "20\nababwxyzijjizyxwbaba"] | 554115bec46bb436a0a1ddf8c05a2d08 | NoteIn the first example, "battab" is also a valid answer.In the second example, there can be 4 different valid answers including the sample output. We are not going to provide any hints for what the others are.In the third example, the empty string is the only valid palindrome string. | Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "kkkkkk" are palindromes, while strings "moon", "tv", and "abab" are not. An empty string is also a palindrome.Gildong love... | In the first line, print the length of the longest palindrome string you made. In the second line, print that palindrome. If there are multiple answers, print any one of them. If the palindrome is empty, print an empty line or don't print this line at all. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100$$$, $$$1 \le m \le 50$$$) — the number of strings and the length of each string. Next $$$n$$$ lines contain a string of length $$$m$$$ each, consisting of lowercase Latin letters only. All strings are distinct. | standard output | standard input | Python 3 | Python | 1,100 | train_007.jsonl | f8d9d5e737d926b02d3d943ba12a857c | 256 megabytes | ["3 3\ntab\none\nbat", "4 2\noo\nox\nxo\nxx", "3 5\nhello\ncodef\norces", "9 4\nabab\nbaba\nabcd\nbcde\ncdef\ndefg\nwxyz\nzyxw\nijji"] | PASSED | x,y=map(int,input().split())
a=set()
l=[]
for i in range(x):
l.append(input())
a.add(l[-1])
s=set()
m=''
for i in a:
r=i[::-1]
if i!=r and r in a and r not in s:
s.add(i)
elif r==i and len(i)>len(m):
m=i
s=''.join(list(s))
o=s+m+s[::-1]
print(len(o))
print(o) | 1581771900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["1\n1 1 3\n102\n114 228 456\n4\n4 8 16\n6\n18 18 18\n1\n100 100 100\n7\n1 22 22\n2\n1 19 38\n8\n6 24 48"] | 140737ecea3ff1c71cdd5e51e6abf297 | null | You are given three integers $$$a \le b \le c$$$.In one move, you can add $$$+1$$$ or $$$-1$$$ to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you can... | For each test case, print the answer. In the first line print $$$res$$$ — the minimum number of operations you have to perform to obtain three integers $$$A \le B \le C$$$ such that $$$B$$$ is divisible by $$$A$$$ and $$$C$$$ is divisible by $$$B$$$. On the second line print any suitable triple $$$A, B$$$ and $$$C$$$. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. Each test case is given on a separate line as three space-separated integers $$$a, b$$$ and $$$c$$$ ($$$1 \le a \le b \le c \le 10^4$$$). | standard output | standard input | PyPy 2 | Python | 2,000 | train_001.jsonl | 0d1806a7713772b6b558ba99f1f732bc | 256 megabytes | ["8\n1 2 3\n123 321 456\n5 10 15\n15 18 21\n100 100 101\n1 22 29\n3 19 38\n6 30 46"] | PASSED | for _ in xrange(input()):
a, b, c = map(int, raw_input().strip().split())
ans = float('inf')
A, B, C = 0, 0, 0
for x in xrange(1, 2 * a + 1):
for y in xrange(x, 2 * b + 1, x):
z1 = (c / y) * y
z2 = z1 + y
z = [z1, z2]
cur = [abs(a - x)... | 1582554900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["baba\naaaaaa\n-1"] | 710c7211d23cf8c01fae0b476a889276 | NoteIn the first test case, "baba" = "baba" $$$\cdot~1~=$$$ "ba" $$$\cdot~2$$$.In the second test case, "aaaaaa" = "aa" $$$\cdot~3~=$$$ "aaa" $$$\cdot~2$$$. | Let's define a multiplication operation between a string $$$a$$$ and a positive integer $$$x$$$: $$$a \cdot x$$$ is the string that is a result of writing $$$x$$$ copies of $$$a$$$ one after another. For example, "abc" $$$\cdot~2~=$$$ "abcabc", "a" $$$\cdot~5~=$$$ "aaaaa".A string $$$a$$$ is divisible by another string... | For each test case, print $$$LCM(s, t)$$$ if it exists; otherwise, print -1. It can be shown that if $$$LCM(s, t)$$$ exists, it is unique. | The first line contains one integer $$$q$$$ ($$$1 \le q \le 2000$$$) — the number of test cases. Each test case consists of two lines, containing strings $$$s$$$ and $$$t$$$ ($$$1 \le |s|, |t| \le 20$$$). Each character in each of these strings is either 'a' or 'b'. | standard output | standard input | Python 3 | Python | 1,000 | train_106.jsonl | 0a429e6459b1b35894a02ad19c0e97b5 | 256 megabytes | ["3\nbaba\nba\naa\naaa\naba\nab"] | PASSED | def lcm(a,b):
if a<b:
sm=a
else:
sm=b
for i in range(1,sm+1):
if a%i==0 and b%i==0:
hcf=i
return int(a*b/hcf)
T=int(input())
for i in range(T):
t=str(input())
s=str(input())
p=s
q=t
l1=int(lcm(int(len(s)),int(len(t)))/int(len(s)))
... | 1610634900 | [
"number theory",
"math",
"strings"
] | [
0,
0,
0,
1,
1,
0,
1,
0
] | |
2 seconds | ["9", "8"] | f010eebcf35357f8c791a1c6101189ba | NoteIn the first sample, roads of the spanning tree have cost 2, while other roads have cost 3. One example of an optimal path is .In the second sample, we have the same spanning tree, but roads in the spanning tree cost 3, while other roads cost 2. One example of an optimal path is . | A group of n cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are roads in total. It takes exactly y seconds to traverse any single road.A spanning tree is a set of roads containing exactly n - 1 roads such that it's possible to travel between any two cities... | Print a single integer — the minimum number of seconds one needs to spend in order to visit all the cities exactly once. | The first line of the input contains three integers n, x and y (2 ≤ n ≤ 200 000, 1 ≤ x, y ≤ 109). Each of the next n - 1 lines contains a description of a road in the spanning tree. The i-th of these lines contains two integers ui and vi (1 ≤ ui, vi ≤ n) — indices of the cities connected by the i-th road. It is guarant... | standard output | standard input | Python 3 | Python | 2,200 | train_074.jsonl | b3b362d8ee8d5790f5f91b32ef29d636 | 256 megabytes | ["5 2 3\n1 2\n1 3\n3 4\n5 3", "5 3 2\n1 2\n1 3\n3 4\n5 3"] | PASSED | from collections import defaultdict
from collections import deque
from functools import reduce
n, x, y = [int(x) for x in input().split()]
E = defaultdict(set)
for i in range(n-1):
u, v = [int(x) for x in input().split()]
E[u].add(v)
E[v].add(u)
if x > y:
for v in E:
if len(E[v]) == n-1:
... | 1454087400 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["YES\nNO\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nNO"] | 7975af65a23bad6a0997921c7e31d3ca | NoteIn the first test case, $$$24 = 17 + 7$$$, $$$27$$$ itself is a lucky number, $$$25$$$ cannot be equal to a sum of lucky numbers. | Nezzar's favorite digit among $$$1,\ldots,9$$$ is $$$d$$$. He calls a positive integer lucky if $$$d$$$ occurs at least once in its decimal representation. Given $$$q$$$ integers $$$a_1,a_2,\ldots,a_q$$$, for each $$$1 \le i \le q$$$ Nezzar would like to know if $$$a_i$$$ can be equal to a sum of several (one or more) ... | For each integer in each test case, print "YES" in a single line if $$$a_i$$$ can be equal to a sum of lucky numbers. Otherwise, print "NO". You can print letters in any case (upper or lower). | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 9$$$) — the number of test cases. The first line of each test case contains two integers $$$q$$$ and $$$d$$$ ($$$1 \le q \le 10^4$$$, $$$1 \le d \le 9$$$). The second line of each test case contains $$$q$$$ integers $$$a_1,a_2,\ldots,a_q$$$ ($$$1 \le a_i ... | standard output | standard input | PyPy 3-64 | Python | 1,100 | train_087.jsonl | ada615f7bea1f69afd5027fd58bf1110 | 512 megabytes | ["2\n3 7\n24 25 27\n10 7\n51 52 53 54 55 56 57 58 59 60"] | PASSED | def islucky(num,k):
f=False
while num>0:
r=num%10
if r==k:
f=True
break
num=num//10
return f
t=int(input())
for _ in range(t):
n,k=map(int,input().split())
ar=list(map(int,input().split()))
for x in range(n):
num=ar[x]
if num>=10... | 1611844500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["6 14 1 25", "12 10 12"] | f41be1fcb6164181c49b37ed9313696e | null | Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well.There are n cities in Berland. People can travel between cities using two-directional train routes; there are exactly m routes, i-th route can be used to go from cit... | Print n integers. i-th of them must be equal to the minimum number of coins a person from city i has to spend to travel to some city j (or possibly stay in city i), attend a concert there, and return to city i (if j ≠ i). | The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 2·105). Then m lines follow, i-th contains three integers vi, ui and wi (1 ≤ vi, ui ≤ n, vi ≠ ui, 1 ≤ wi ≤ 1012) denoting i-th train route. There are no multiple train routes connecting the same pair of cities, that is, for each (v, u) neither extra (... | standard output | standard input | PyPy 3 | Python | 2,000 | train_004.jsonl | 6b530b28de0ae51d3e22876fe461e697 | 256 megabytes | ["4 2\n1 2 4\n2 3 7\n6 20 1 25", "3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20"] | PASSED | from __future__ import division, print_function
py2 = round(0.5)
if py2:
from future_builtins import ascii, filter, hex, map, oct, zip
range = xrange
import os, sys
from io import BytesIO, IOBase
# FastIO for PyPy2 and PyPy3 by Pajenegod,
class FastI(object):
def __init__(self, fd=0, buffersize=2**14):
... | 1518793500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["..X", ".X.X.X", "...XX"] | 94f52d78b1347fd04c9d39e8789a73ec | NoteThe lexicographical comparison of is performed by the < operator in modern programming languages. The a string is lexicographically less that the b string, if there exists such i (1 ≤ i ≤ n), that ai < bi, and for any j (1 ≤ j < i) aj = bj. | After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys have a chance to resolve the problem once and for all. Sasha sele... | For each query print "." if the slot should be empty and "X" if the slot should be charged. | The first line contains three integers n, k and p (1 ≤ n ≤ 1018, 0 ≤ k ≤ n, 1 ≤ p ≤ 1000) — the number of slots in the cylinder, the number of bullets and the number of queries. Then follow p lines; they are the queries. Each line contains one integer xi (1 ≤ xi ≤ n) the number of slot to describe. Please do not use th... | standard output | standard input | Python 2 | Python | 1,900 | train_036.jsonl | fe8711e230a503d5c9532532f5e4cc45 | 256 megabytes | ["3 1 3\n1\n2\n3", "6 3 6\n1\n2\n3\n4\n5\n6", "5 2 5\n1\n2\n3\n4\n5"] | PASSED | #!/usr/bin/python
def query(n, k, x):
if k == 0: return 0
if k == n: return 1
if n % 2 == 0:
evens = max(2, n - 2*k + 2)
odds = n + 1
k -= n/2
if k > 0:
odds = n - 1 - 2*k + 2
if x % 2 == 0:
return int(x >= evens)
else:
return int(x >= odds)
else:
if x == n: return 1
k -= 1
evens = max(2... | 1312714800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\n7\n0\n1"] | 2f12b2bb23497119bb70ca0839991d68 | null | You are given an array $$$a$$$ of $$$n$$$ integers. Find the number of pairs $$$(i, j)$$$ ($$$1 \le i < j \le n$$$) where the sum of $$$a_i + a_j$$$ is greater than or equal to $$$l$$$ and less than or equal to $$$r$$$ (that is, $$$l \le a_i + a_j \le r$$$).For example, if $$$n = 3$$$, $$$a = [5, 1, 2]$$$, $$$l = 4$... | For each test case, output a single integer — the number of index pairs $$$(i, j)$$$ ($$$i < j$$$), such that $$$l \le a_i + a_j \le r$$$. | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains three integers $$$n, l, r$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le l \le r \le 10^9$$$) — the length of the array and the limits on the sum in the pair. The second line cont... | standard output | standard input | Python 3 | Python | 1,300 | train_097.jsonl | ad8c38b2611f4b80a5ad0735bdebfc1a | 256 megabytes | ["4\n3 4 7\n5 1 2\n5 5 8\n5 1 2 4 3\n4 100 1000\n1 1 1 1\n5 9 13\n2 5 5 1 1"] | PASSED | # _
#####################################################################################################################
def nPairs(lengthOfArray, l, r, array):
iFinal = lengthOfArray - 1
array.sort()
total = 0
for i in range(iFinal):
curr_l, curr_r = l - array[i], r - array[i]
... | 1623335700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["11122", "21122", "111111", "2212222"] | 43336ae43d65a11c80337d0b6ea6b934 | NoteBelow you can see the tree in the first sample : If $$$k = 1$$$ then the first player can cut the edge $$$(1, 2)$$$.If $$$k = 2$$$ or $$$k = 3$$$, the first player can cut the edge $$$(2, 4)$$$, after that only the edges $$$(1, 2)$$$ and $$$(2, 3)$$$ remain. After the second players move, there will be a single ed... | After many unsuccessful tries, Mashtali decided to copy modify an AtCoder problem. So here is his copied new problem:There is a tree with $$$n$$$ vertices and some non-empty set of the vertices are pinned to the ground.Two players play a game against each other on the tree. They alternately perform the following action... | Print a string of length $$$n$$$. The $$$i$$$-th character should be '1' if the first player wins the $$$i$$$-th scenario, and '2' otherwise. | The first line of input contains an integer $$$n$$$ — the number of vertices ($$$1 \le n \le 3 \cdot 10^5$$$). The $$$i$$$-th of the following $$$n-1$$$ lines contains two integers $$$u_i, v_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \ne v_i$$$) — the endpoints of the $$$i$$$-th edge. It's guaranteed that these edges for... | standard output | standard input | PyPy 3-64 | Python | 3,100 | train_085.jsonl | 0a0e63651df7f1ebcba6908ebee9c109 | 256 megabytes | ["5\n1 2\n2 3\n2 4\n4 5", "5\n1 2\n2 3\n1 4\n4 5", "6\n1 2\n2 4\n5 1\n6 3\n3 2", "7\n1 2\n3 7\n4 6\n2 3\n2 4\n1 5"] | PASSED | import sys
input = sys.stdin.buffer.readline
N = int(input())
T = [[] for i in range(N)]
for i in range(1, N):
u, v = map(int, input().split())
u -= 1
v -= 1
T[u].append(v)
T[v].append(u)
stk = [(1, 0)]
par = [-1] * N
dp = [0] * N
while stk:
t, u = stk.pop()
if t == 1:
stk.append((2, u))
... | 1637678100 | [
"games",
"trees"
] | [
1,
0,
0,
0,
0,
0,
0,
1
] | |
3 seconds | ["YES\nYES\nNO\nNO", "NO\nNO\nYES\nNO\nNO"] | 6709c8078cd29e69cf1be285071b2527 | null | Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).For example, as a result of typing the word "hello", the followi... | Output $$$n$$$ lines. In the $$$i$$$-th line for the $$$i$$$-th pair of words $$$s$$$ and $$$t$$$ print YES if the word $$$t$$$ could be printed by typing the word $$$s$$$. Otherwise, print NO. | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of pairs to check. Further input contains $$$n$$$ descriptions of pairs. The first line of each description contains a single non-empty word $$$s$$$ consisting of lowercase Latin letters. The second line of the description co... | standard output | standard input | Python 3 | Python | 1,200 | train_013.jsonl | 3423f3eafa77e4ca2d087dbeafbf72b5 | 256 megabytes | ["4\nhello\nhello\nhello\nhelloo\nhello\nhlllloo\nhello\nhelo", "5\naa\nbb\ncodeforces\ncodeforce\npolycarp\npoolycarpp\naaaa\naaaab\nabcdefghijklmnopqrstuvwxyz\nzabcdefghijklmnopqrstuvwxyz"] | PASSED | for _ in range(int(input())):
a = input()
b = input()
l1,l2 = len(a),len(b)
f = 1
i,j = 0,0
while i < l1:
last = a[i]
c = 0
while i < l1 and a[i] == last:
c += 1
i += 1
p = 0
while j < l2 and b[j] == last:
p += 1
... | 1560955500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["YES\nNO"] | 941adee47c2a28588ebe7dfe16e0c91a | NoteIn the first test case one of the reorders could be $$$[1, 2, 5]$$$. The sum is equal to $$$(\frac{1}{1} + \frac{2}{2} + \frac{5}{3}) + (\frac{2}{2} + \frac{5}{3}) + (\frac{5}{3}) = 8$$$. The brackets denote the inner sum $$$\sum_{j=i}^{n}{\frac{a_j}{j}}$$$, while the summation of brackets corresponds to the sum ov... | For a given array $$$a$$$ consisting of $$$n$$$ integers and a given integer $$$m$$$ find if it is possible to reorder elements of the array $$$a$$$ in such a way that $$$\sum_{i=1}^{n}{\sum_{j=i}^{n}{\frac{a_j}{j}}}$$$ equals $$$m$$$? It is forbidden to delete elements as well as insert new elements. Please note that ... | For each test case print "YES", if it is possible to reorder the elements of the array in such a way that the given formula gives the given value, and "NO" otherwise. | The first line contains a single integer $$$t$$$ — the number of test cases ($$$1 \le t \le 100$$$). The test cases follow, each in two lines. The first line of a test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100$$$, $$$0 \le m \le 10^6$$$). The second line contains integers $$$a_1, a_2, \ldots, a... | standard output | standard input | Python 3 | Python | 800 | train_000.jsonl | c6369d45756b7a324a1962585eb1df08 | 256 megabytes | ["2\n3 8\n2 5 1\n4 4\n0 1 2 3"] | PASSED | t = int(input())
while t>0:
t = t-1
n,m = map(int,input().split())
arr = list(map(int,input().split()))
if (sum(arr) == m):
print("Yes")
else:
print("No")
| 1603548300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n2\n21\n121\n212"] | 1a5f266b49aadbeef59e19bcf5524a57 | NoteThe only numbers with the sum of digits equal to $$$2$$$ without zeros are $$$2$$$ and $$$11$$$. But the last one has two ones in a row, so it's not valid. That's why the answer is $$$2$$$.The only numbers with the sum of digits equal to $$$3$$$ without zeros are $$$111$$$, $$$12$$$, $$$21$$$, and $$$3$$$. The firs... | Madoka finally found the administrator password for her computer. Her father is a well-known popularizer of mathematics, so the password is the answer to the following problem.Find the maximum decimal number without zeroes and with no equal digits in a row, such that the sum of its digits is $$$n$$$.Madoka is too tired... | For each test case print the maximum number you can obtain. | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Description of the test cases follows. The only line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the required sum of the digits. | standard output | standard input | PyPy 3 | Python | 800 | train_096.jsonl | bceffa82c363e842171628c41d2a1582 | 256 megabytes | ["5\n1\n2\n3\n4\n5"] | PASSED | from math import inf
from collections import *
import math, os, sys, heapq, bisect, random
from functools import lru_cache
from itertools import *
def inp(): return sys.stdin.readline().rstrip("\r\n")
def out(var): sys.stdout.write(str(var)) # for fast output, always take string
def inpu(): return int(inp())
d... | 1647009300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["4", "7", "12"] | a569cd5f8bf8aaf011858f839e91848a | NoteIn the first test case it's optimal to install two towers with efficiencies $$$2$$$ at vertices $$$1$$$ and $$$3$$$.In the second test case it's optimal to install a tower with efficiency $$$1$$$ at vertex $$$1$$$ and two towers with efficiencies $$$3$$$ at vertices $$$2$$$ and $$$5$$$.In the third test case it's o... | You are given a tree with $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$. The height of the $$$i$$$-th vertex is $$$h_i$$$. You can place any number of towers into vertices, for each tower you can choose which vertex to put it in, as well as choose its efficiency. Setting up a tower with efficiency $$$e$$$ costs $$$... | Print one integer — the minimum required number of coins. | The first line contains an integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of vertices in the tree. The second line contains $$$n$$$ integers $$$h_i$$$ ($$$1 \le h_i \le 10^9$$$) — the heights of the vertices. Each of the next $$$n - 1$$$ lines contain a pair of numbers $$$v_i, u_i$$$ ($$$1 \le v_i, u_i \le n... | standard output | standard input | PyPy 3-64 | Python | 2,500 | train_090.jsonl | 786ea06f699169284910a078e5e27b97 | 256 megabytes | ["3\n1 2 1\n1 2\n2 3", "5\n1 3 3 1 3\n1 3\n5 4\n4 3\n2 3", "2\n6 1\n1 2"] | PASSED | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write... | 1644676500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["3"] | de87bb6ffd3c703d8845d4dd301bdbf5 | NoteThe answer for the first test sample is subsequence [1, 2, 3]. | Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should find the length of the longest common subsequence of these permutations. Can... | Print the length of the longest common subsequence. | The first line contains two integers n and k (1 ≤ n ≤ 1000; 2 ≤ k ≤ 5). Each of the next k lines contains integers 1, 2, ..., n in some order — description of the current permutation. | standard output | standard input | Python 3 | Python | 1,900 | train_008.jsonl | 8713fe1256830155b10308bdc1b64283 | 256 megabytes | ["4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3"] | PASSED | # ========== //\\ //|| ||====//||
# || // \\ || || // ||
# || //====\\ || || // ||
# || // \\ || || // ||
# ========== // \\ ======== ||//====||
# code
def solve():
n, k = map(int, input().split())
c = [ ... | 1409383800 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["0 \n1 -1 1"] | a89c585ebd9608141399c813385c04c6 | NoteIn the first test case of the example, both teams get $$$1$$$ point since the game between them is a tie.In the second test case of the example, team $$$1$$$ defeats team $$$2$$$ (team $$$1$$$ gets $$$3$$$ points), team $$$1$$$ loses to team $$$3$$$ (team $$$3$$$ gets $$$3$$$ points), and team $$$2$$$ wins against ... | A big football championship will occur soon! $$$n$$$ teams will compete in it, and each pair of teams will play exactly one game against each other.There are two possible outcomes of a game: the game may result in a tie, then both teams get $$$1$$$ point; one team might win in a game, then the winning team gets $$$3$... | For each test case, print $$$\frac{n(n - 1)}{2}$$$ integers describing the results of the games in the following order: the first integer should correspond to the match between team $$$1$$$ and team $$$2$$$, the second — between team $$$1$$$ and team $$$3$$$, then $$$1$$$ and $$$4$$$, ..., $$$1$$$ and $$$n$$$, $$$2$$$ ... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of teams. | standard output | standard input | PyPy 3-64 | Python | 1,500 | train_082.jsonl | 2e26d2be2d21d8ed4210d12a08904773 | 256 megabytes | ["2\n2\n3"] | PASSED | for _ in range(int(input())):
n = int(input())
if n % 2 == 1:
cnt = 1
for i in range(n * (n - 1) // 2):
print(cnt, end=" ")
if cnt == 1:
cnt = -1
else:
cnt = 1
print()
else:
for i in range(n):
... | 1613399700 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
2 seconds | ["NO\nNO\nYES\nNO\nYES\nYES\nNO\nYES"] | ee27020ca43546993b82357527585831 | NoteIn the first example, $$$6$$$ can be represented as $$$6$$$, $$$1 \cdot 6$$$, $$$2 \cdot 3$$$. But $$$3$$$ and $$$1$$$ are not a good numbers because they are not divisible by $$$2$$$, so there is only one way.In the second example, $$$12$$$ can be represented as $$$6 \cdot 2$$$, $$$12$$$, $$$3 \cdot 4$$$, or $$$3 ... | Madoka is going to enroll in "TSUNS PTU". But she stumbled upon a difficult task during the entrance computer science exam: A number is called good if it is a multiple of $$$d$$$. A number is called beatiful if it is good and it cannot be represented as a product of two good numbers. Notice that a beautiful number mu... | For each set of input data, output "NO" if the number cannot be represented in at least two ways. Otherwise, output "YES". You can output each letter in any case (for example, "YES", "Yes", "yes", "yEs", "yEs" will be recognized as a positive answer). | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — number of test cases. Below comes their description. Each test case consists of two integers $$$x$$$ and $$$d$$$, separated by a space ($$$2 \leq x, d \leq 10^9$$$). It is guaranteed that $$$x$$$ is a multiple of $$$d$$$. | standard output | standard input | Python 3 | Python | 1,900 | train_096.jsonl | c4c7b447b1bf2ea91ece296c562df2e5 | 256 megabytes | ["8\n\n6 2\n\n12 2\n\n36 2\n\n8 2\n\n1000 10\n\n2376 6\n\n128 4\n\n16384 4"] | PASSED | t = int(input())
def isPrime(x):
i = 2
while (i*i <= x):
if (x % i == 0):
return False
i += 1
return True
def solve(x, d):
cnt = 0
# print(x,d)
while (x % d == 0):
cnt += 1
x //= d
if (cnt <= 1):
print("NO")
return
d_is_prime = isPrime(d)
# pri... | 1647009300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["7", "2"] | b3d093272fcb289108fe45be8c72f38e | NoteIn the first example the shark travels inside a location on days $$$1$$$ and $$$2$$$ (first location), then on $$$4$$$-th and $$$5$$$-th days (second location), then on $$$7$$$-th and $$$8$$$-th days (third location). There are three locations in total.In the second example the shark only moves inside a location on... | For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations.Max is a young biologist. For $$$n$$$ days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the... | Print a single integer $$$k$$$, such that the shark was in each location the same number of days, the number of locations is maximum possible satisfying the first condition, $$$k$$$ is smallest possible satisfying the first and second conditions. | The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of days. The second line contains $$$n$$$ distinct positive integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the distance traveled in each of the day. | standard output | standard input | Python 3 | Python | 1,900 | train_001.jsonl | 9c3b3af8a5de182cb68e237b62d1e00e | 256 megabytes | ["8\n1 2 7 3 4 8 5 6", "6\n25 1 2 3 14 36"] | PASSED | import bisect;
def getIntList():
return list(map(int, input().split()));
def getTransIntList(n):
first=getIntList();
m=len(first);
result=[[0]*n for _ in range(m)];
for i in range(m):
result[i][0]=first[i];
for j in range(1, n):
curr=getIntList();
for i in range(m):
... | 1526574900 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
5 seconds | ["124780545", "798595483"] | b4f8a6f5b1d1fa641514e10d18c316f7 | null | Santa Claus has received letters from $$$n$$$ different kids throughout this year. Of course, each kid wants to get some presents from Santa: in particular, the $$$i$$$-th kid asked Santa to give them one of $$$k_i$$$ different items as a present. Some items could have been asked by multiple kids.Santa is really busy, ... | Print the probatility that the Bot produces a valid decision as follows: Let this probability be represented as an irreducible fraction $$$\frac{x}{y}$$$. You have to print $$$x \cdot y^{-1} \mod 998244353$$$, where $$$y^{-1}$$$ is the inverse element of $$$y$$$ modulo $$$998244353$$$ (such integer that $$$y \cdot y^{-... | The first line contains one integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the number of kids who wrote their letters to Santa. Then $$$n$$$ lines follow, the $$$i$$$-th of them contains a list of items wanted by the $$$i$$$-th kid in the following format: $$$k_i$$$ $$$a_{i, 1}$$$ $$$a_{i, 2}$$$ ... $$$a_{i, k_i}$$$ ($$$1 ... | standard output | standard input | PyPy 2 | Python | 1,700 | train_001.jsonl | d8d1d4b8782cbc4c1ac1a99b704407ae | 256 megabytes | ["2\n2 2 1\n1 1", "5\n2 1 2\n2 3 1\n3 2 4 3\n2 1 4\n3 4 3 2"] | PASSED | # template begins
#####################################
# import libraries for input/ output handling
# on generic level
import atexit, io, sys
# A stream implementation using an in-memory bytes
# buffer. It inherits BufferedIOBase.
buffer = io.BytesIO()
sys.stdout = buffer
# print via her... | 1577457600 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
3 seconds | ["2 3 5 7 11", "10 3 7"] | bf8bbbb225813cdf42e7a2e454f0b787 | NoteNote that in the second sample, the array is already pairwise coprime so we printed it. | Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same length such that: b is lexicographically greater than or equal to a. bi ≥ 2. b is pairwise coprime: for every 1 ≤ i < j ≤ n, bi and bj are coprime, i. e. GCD(bi, bj) = 1, where GCD(w, z) is the greatest common divis... | Output n space-separated integers, the i-th of them representing bi. | The first line contains an integer n (1 ≤ n ≤ 105), the number of elements in a and b. The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 105), the elements of a. | standard output | standard input | Python 3 | Python | 1,900 | train_035.jsonl | d5c08d93def8fe7aba2270e294e86e97 | 256 megabytes | ["5\n2 3 5 4 13", "3\n10 3 7"] | PASSED | import atexit
import io
import sys
# Buffering IO
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
ppp = ('2 3 5 7 1... | 1522771500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
4 seconds | ["1", "642377629"] | 8508d39c069936fb402e4f4433180465 | NoteTo better understand in which situation several winners are possible let's examine the second test:One possible result of the tournament is as follows ($$$a \rightarrow b$$$ means that $$$a$$$ defeated $$$b$$$): $$$1 \rightarrow 2$$$ $$$2 \rightarrow 3$$$ $$$3 \rightarrow 1$$$ $$$1 \rightarrow 4$$$ $$$1 \right... | William is not only interested in trading but also in betting on sports matches. $$$n$$$ teams participate in each match. Each team is characterized by strength $$$a_i$$$. Each two teams $$$i < j$$$ play with each other exactly once. Team $$$i$$$ wins with probability $$$\frac{a_i}{a_i + a_j}$$$ and team $$$j$$$ w... | Output a single integer — the expected value of the number of winners of the tournament modulo $$$10^9 + 7$$$. Formally, let $$$M = 10^9+7$$$. It can be demonstrated that the answer can be presented as a irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. ... | The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 14$$$), which is the total number of teams participating in a match. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^6$$$) — the strengths of teams participating in a match. | standard output | standard input | PyPy 3-64 | Python | 2,500 | train_107.jsonl | 8b2d744a149d3800c66a18d088e48849 | 256 megabytes | ["2\n1 2", "5\n1 5 2 11 14"] | PASSED | import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import cycle, permutations
from math import log,gcd
input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())
mod = 10**9 + 7
N = 2*... | 1630247700 | [
"probabilities",
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
1,
0,
0
] | |
1 second | ["0", "2"] | 10efa17a66af684dbc13c456ddef1b1b | null | You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pairs of integers (i1, j1), (i2, j2), ..., (im, jm). Each good pair (ik, jk) meets the following conditions: ik + jk is an odd number and 1 ≤ ik < jk ≤ n.In one operation you can perform a sequence of actions: tak... | Output the answer for the problem. | The first line contains two space-separated integers n, m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100). The second line contains n space-separated integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109) — the description of the array. The following m lines contain the description of good pairs. The k-th line contains two space-separated integer... | standard output | standard input | PyPy 3 | Python | 2,100 | train_003.jsonl | caa0ae34e1ca58574edf92dcd1bacb61 | 256 megabytes | ["3 2\n8 3 8\n1 2\n2 3", "3 2\n8 12 8\n1 2\n2 3"] | PASSED | def g(i):
u[i] = 0
for j in p[i]:
if v[j] < 0 or u[v[j]] and g(v[j]):
v[j] = i
return 1
return 0
f = lambda: map(int, input().split())
n, m = f()
s = k = 0
d = [[]]
for i in f():
j = 2
t = []
while j * j <= i:
while i % j == 0:
t.append((j, k)... | 1419438600 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["1\n-1\n1\n5"] | 8d9fc054fb1541b70991661592ae70b1 | NoteExplanation of the first test case: There is only one athlete, therefore he is superior to everyone else (since there is no one else), and thus he is likely to get the gold medal.Explanation of the second test case: There are $$$n=3$$$ athletes. Athlete $$$1$$$ is superior to athlete $$$2$$$. Indeed athlete $$$1$... | The Olympic Games have just started and Federico is eager to watch the marathon race.There will be $$$n$$$ athletes, numbered from $$$1$$$ to $$$n$$$, competing in the marathon, and all of them have taken part in $$$5$$$ important marathons, numbered from $$$1$$$ to $$$5$$$, in the past. For each $$$1\le i\le n$$$ and ... | For each test case, print a single integer — the number of an athlete who is likely to get the gold medal (that is, an athlete who is superior to all other athletes). If there are no such athletes, print $$$-1$$$. If there is more than such one athlete, print any of them. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 50\,000$$$) — the number of athletes. Then $$$n$$$ lines follow, each describing the ranking positions of... | standard output | standard input | PyPy 3-64 | Python | 1,500 | train_098.jsonl | addf45c7cc607dec8191bc4280e147fc | 256 megabytes | ["4\n1\n50000 1 50000 50000 50000\n3\n10 10 20 30 30\n20 20 30 10 10\n30 30 10 20 20\n3\n1 1 1 1 1\n2 2 2 2 2\n3 3 3 3 3\n6\n9 5 3 7 1\n7 4 1 6 8\n5 6 7 3 2\n6 7 8 8 6\n4 2 2 4 5\n8 3 6 9 4"] | PASSED |
def win(a, b):
cnt = 0
for i in range(5):
if a[i] < b[i]:
cnt += 1
if cnt >= 3:
return a
return b
for _ in range(int(input())):
n = int(input())
l = []
for i in range(n):
l.append(list(map(int, input().split())))
ini = l[0]
idx ... | 1627223700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
0.5 seconds | ["YES\n2 2 1 1", "YES\n2 1 2 1 1", "NO"] | 973ef4e00b0489261fce852af11aa569 | null | You are given an array of $$$n$$$ integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.The GCD of a group of integers is the largest non-negative integer that divides all the integers i... | In the first line print "YES" (without quotes), if it is possible to split the integers into two groups as required, and "NO" (without quotes) otherwise. If it is possible to split the integers, in the second line print $$$n$$$ integers, where the $$$i$$$-th integer is equal to $$$1$$$ if the integer $$$a_i$$$ should b... | The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$). The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array. | standard output | standard input | PyPy 3 | Python | 2,900 | train_069.jsonl | d0fb462219c501f38659407c24be1fd3 | 256 megabytes | ["4\n2 3 6 7", "5\n6 15 35 77 22", "5\n6 10 15 1000 75"] | PASSED | import sys
def gcd(l):
if len(l)==0:
return 0
if len(l)==1:
return l[0]
if len(l)==2:
if l[1]==0:
return l[0]
return gcd([l[1],l[0]%l[1]])
return gcd([gcd(l[:-1]),l[-1]])
def brute_force(l1,l2,l,sol):
if len(l)==0:
g1=gcd(l1)
g2=gcd(l2)
r... | 1564497300 | [
"number theory",
"probabilities"
] | [
0,
0,
0,
0,
1,
1,
0,
0
] | |
2 seconds | ["90.0000000000", "135.0000000000", "270.0000000000", "36.8698976458"] | a67cdb7501e99766b20a2e905468c29c | NoteSolution for the first sample test is shown below: Solution for the second sample test is shown below: Solution for the third sample test is shown below: Solution for the fourth sample test is shown below: | Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this a... | Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10 - 6. | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of mannequins. Next n lines contain two space-separated integers each: xi, yi (|xi|, |yi| ≤ 1000) — the coordinates of the i-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that no two mannequins a... | standard output | standard input | Python 2 | Python | 1,800 | train_005.jsonl | b6599d88f0d03dd7ce38328fb2b09053 | 256 megabytes | ["2\n2 0\n0 2", "3\n2 0\n0 2\n-2 2", "4\n2 0\n0 2\n-2 0\n0 -2", "2\n2 1\n1 2"] | PASSED | def subtract(a1, a2):
if a1 > a2 + 0.0000001:
return a1-a2
elif abs(a1-a2) <= 0.0000001:
return 0
return 360+a1-a2
def angle(a1, a2):
import math
return math.atan2(a2,a1)*180/math.pi
def start():
n = input()
degreesPositive = []
for _ in xrange(n):
a1, a2 = map(... | 1357659000 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1 2 3 4 5 \n-1\n1 3 2 \n1 2 \n-1"] | 88c8376ad65c5c932c15dc09d6c4d75f | null | A permutation is a sequence of $$$n$$$ integers from $$$1$$$ to $$$n$$$, in which all the numbers occur exactly once. For example, $$$[1]$$$, $$$[3, 5, 2, 1, 4]$$$, $$$[1, 3, 2]$$$ are permutations, and $$$[2, 3, 2]$$$, $$$[4, 3, 1]$$$, $$$[0]$$$ are not.Polycarp was given four integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 ... | For each test case, output on a separate line: $$$n$$$ integers — a permutation of length $$$n$$$ that fits the condition above if such a permutation exists; -1, otherwise. If there are several suitable permutations, print any of them. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$). Then $$$t$$$ test cases follow. Each test case consist of one line with four integers $$$n$$$ ($$$1 \le n \le 500$$$), $$$l$$$ ($$$1 \le l \le n$$$), $$$r$$$ ($$$l \le r \le n$$$), $$$s$$$ ($$$1 \le s \le \frac{n (n+1)}{2}$$$). It is guaranteed t... | standard output | standard input | PyPy 3 | Python | 1,600 | train_107.jsonl | 2f5f644247eb261b1be9ac81041e2884 | 256 megabytes | ["5\n5 2 3 5\n5 3 4 1\n3 1 2 4\n2 2 2 2\n2 1 1 3"] | PASSED | for _ in range(int(input())):
n,l,r,s = map(int,input().split())
x = r-l +1
t = []
p = 1
b = True
while x>1:
t.append(p)
s -= p
if s<=0:
b = False
break
p += 1
x -= 1
t.append(s)
# print(t)
if s<p:
b = False
# print(t)
if t[-1]>n:
if len(t)>1:
k = t[-1]-n
t[-1... | 1618065300 | [
"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.