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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3 seconds | ["5", "6", "17"] | 7fe380a1848eae621c734cc9a3e463e0 | NoteFor the first example, the picture below shows one of the possible solutions (wires that can be removed are marked in red): The second and the third examples can be seen below: | An electrical grid in Berland palaces consists of 2 grids: main and reserve. Wires in palaces are made of expensive material, so selling some of them would be a good idea!Each grid (main and reserve) has a head node (its number is $$$1$$$). Every other node gets electricity from the head node. Each node can be reached ... | Print a single integer — the maximal amount of wires that can be cut so that each device is powered. | The first line contains an integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of devices in the palace. The next line contains an integer $$$a$$$ ($$$1 + n \le a \le 1000 + n$$$) — the amount of nodes in the main grid. Next line contains $$$a - 1$$$ integers $$$p_i$$$ ($$$1 \le p_i \le a$$$). Each integer $$$p_i$$$ ... | standard output | standard input | PyPy 2 | Python | 2,400 | train_044.jsonl | b5e68b9714fb97a7e4327dcd0705e70c | 256 megabytes | ["3\n6\n4 1 1 4 2\n6 5 3\n4\n1 1 1\n3 4 2", "4\n6\n4 4 1 1 1\n3 2 6 5\n6\n6 6 1 1 1\n5 4 3 2", "5\n14\n1 1 11 2 14 14 13 7 12 2 5 6 1\n9 8 3 10 4\n16\n1 1 9 9 2 5 10 1 14 3 7 11 6 12 2\n8 16 13 4 15"] | PASSED | from __future__ import print_function,division
import sys#log min est tolérable
n=int(input())
def f():
global n
co=[[0]*n for k in range(n)]
a=int(input())
p=[0]+list(map(int,raw_input().split()))
d=[0]*a
s=[1]*a
s[0]=0
mi=[n]*a#plus peit
ma=[-1]*a#le plus tard
for k in p[1:]:
... | 1575038100 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
4 seconds | ["0 98 49 25 114", "0 -1 9"] | abee4d188bb59d82fcf4579c7416a343 | NoteThe graph in the first example looks like this.In the second example the path from $$$1$$$ to $$$3$$$ goes through $$$2$$$, so the resulting payment is $$$(1 + 2)^2 = 9$$$. | There are $$$n$$$ cities and $$$m$$$ bidirectional roads in the country. The roads in the country form an undirected weighted graph. The graph is not guaranteed to be connected. Each road has it's own parameter $$$w$$$. You can travel through the roads, but the government made a new law: you can only go through two roa... | For every city $$$t$$$ print one integer. If there is no correct path between $$$1$$$ and $$$t$$$ output $$$-1$$$. Otherwise print out the minimum amount of money needed to travel from $$$1$$$ to $$$t$$$. | First line contains two integers $$$n$$$, $$$m$$$ ($$$2 \leq n \leq 10^5$$$, $$$1 \leq m \leq min(\frac{n \cdot (n - 1)}{2}, 2 \cdot 10^5)$$$). Next $$$m$$$ lines each contain three integers $$$v_i$$$, $$$u_i$$$, $$$w_i$$$ ($$$1 \leq v_i, u_i \leq n$$$, $$$1 \leq w_i \leq 50$$$, $$$u_i \neq v_i$$$). It's guaranteed tha... | standard output | standard input | PyPy 3 | Python | 2,200 | train_110.jsonl | d80aa438141545f138a8bcab4be1f6c2 | 512 megabytes | ["5 6\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n1 5 1\n2 4 2", "3 2\n1 2 1\n2 3 2"] | PASSED | from heapq import heappush, heappop
n, m = map(int, input().split())
adj = [[] for i in range(n + 1)]
md = 10**9; dist = [md] * (51 * (n+1)); dist[51] = 0
for i in range(m): u, v, w = map(int, input().split()); adj[u].append((v, w)); adj[v].append((u, w))
gr = [(0, 51 * 1)]
while gr:
ol_d, c = heappop(gr)
... | 1613658900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["YES\nYES\nNO\nNO\nYES"] | b132bf94af4352c4a690316eb610ebe1 | NoteIn the first test case, you can stop the algorithm before the $$$0$$$-th step, or don't choose any position several times and stop the algorithm.In the second test case, you can add $$$k^0$$$ to $$$v_1$$$ and stop the algorithm.In the third test case, you can't make two $$$1$$$ in the array $$$v$$$.In the fifth tes... | Suppose you are performing the following algorithm. There is an array $$$v_1, v_2, \dots, v_n$$$ filled with zeroes at start. The following operation is applied to the array several times — at $$$i$$$-th step ($$$0$$$-indexed) you can: either choose position $$$pos$$$ ($$$1 \le pos \le n$$$) and increase $$$v_{pos}$$... | For each test case print YES (case insensitive) if you can achieve the array $$$a$$$ after some step or NO (case insensitive) otherwise. | The first line contains one integer $$$T$$$ ($$$1 \le T \le 1000$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 30$$$, $$$2 \le k \le 100$$$) — the size of arrays $$$v$$$ and $$$... | standard output | standard input | Python 3 | Python | 1,400 | train_000.jsonl | 29be1ad0f126e5a3e6d36c2f864393f5 | 256 megabytes | ["5\n4 100\n0 0 0 0\n1 2\n1\n3 4\n1 4 1\n3 2\n0 1 3\n3 9\n0 59049 810"] | PASSED | def giveb(num, k):
l = []
while num > 0:
if num%k not in [0,1]:
return 'notvalid'
else:
l.append(str(num%k))
num = num//k
return ''.join(l[::-1])
for _ in range(int(input())):
n, k = map(int, input().split())
l = list(map(int, input().split()))
... | 1583764500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["0 12 3 3", "0 1 1 254 254"] | deed251d324f7bbe53eefa94f92c3bbc | NoteOne possible way to group colors and assign keys for the first sample:Color $$$2$$$ belongs to the group $$$[0,2]$$$, with group key $$$0$$$.Color $$$14$$$ belongs to the group $$$[12,14]$$$, with group key $$$12$$$.Colors $$$3$$$ and $$$4$$$ belong to group $$$[3, 5]$$$, with group key $$$3$$$.Other groups won't a... | Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.Their algorithm will be tested on an array of integers, where the $$$i$$$-th integer represents the color of the $$$i$$$-th pixel in the image. The image is in black and white, ... | Print $$$n$$$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter. | The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq k \leq 256$$$), the number of pixels in the image, and the maximum size of a group, respectively. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$0 \leq p_i \leq 255$$$), where $$$p_i$$$ is th... | standard output | standard input | Python 3 | Python | 1,700 | train_042.jsonl | 8fc1de325280aed985db6b16cde07317 | 256 megabytes | ["4 3\n2 14 3 4", "5 2\n0 2 1 255 254"] | PASSED | n, k = map(int, input().split())
P = map(int, input().split())
parent = list(range(256))
sz = [1] * 256
def rt(x):
if x != parent[x]:
parent[x] = rt(parent[x])
return parent[x]
def u(rx, ry):
parent[ry] = rx
sz[rx] += sz[ry]
ans = [0] * n
for i, p in enumerate(P):
rx = rt(p)
while rx ... | 1525791900 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["YES 2\n2\n1 2\n2 3", "YES 2\n4\n1 2\n3 2\n4 2\n5 2", "NO"] | 69ee6170d9f1480647d1a3fed4d1f77b | NoteHere are the graphs for the first two example cases. Both have diameter of $$$2$$$. $$$d_1 = 1 \le a_1 = 2$$$$$$d_2 = 2 \le a_2 = 2$$$$$$d_3 = 1 \le a_3 = 2$$$ $$$d_1 = 1 \le a_1 = 1$$$$$$d_2 = 4 \le a_2 = 4$$$$$$d_3 = 1 \le a_3 = 1$$$$$$d_4 = 1 \le a_4 = 1$$$ | Graph constructive problems are back! This time the graph you are asked to build should match the following properties.The graph is connected if and only if there exists a path between every pair of vertices.The diameter (aka "longest shortest path") of a connected undirected graph is the maximum number of edges in the... | Print "NO" if no graph can be constructed under the given conditions. Otherwise print "YES" and the diameter of the resulting graph in the first line. The second line should contain a single integer $$$m$$$ — the number of edges in the resulting graph. The $$$i$$$-th of the next $$$m$$$ lines should contain two integer... | The first line contains a single integer $$$n$$$ ($$$3 \le n \le 500$$$) — the number of vertices in the graph. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n - 1$$$) — the upper limits to vertex degrees. | standard output | standard input | Python 3 | Python | 1,800 | train_009.jsonl | b5bc1656bdb063e417cabb09569185cc | 256 megabytes | ["3\n2 2 2", "5\n1 4 1 1 1", "3\n1 1 1"] | PASSED | a = []
n = 0
Ones = []
def solution ():
s = 0
for item in a :
s = s + item
if s < 2*(n-1) :
print("NO")
return
for i in range(n):
if a[i] == 1 :
a[i] = 0
Ones.append(i)
t = len(Ones)
d = (n-t) - 1 + min(2,t)
print("... | 1543415700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["4\n4\n2\n3\n4"] | 3ca37d1209b487a383b56ba4b7c1e872 | NoteThe image depicts the tree from the first test case during each second.A vertex is black if it is not infected. A vertex is blue if it is infected by injection during the previous second. A vertex is green if it is infected by spreading during the previous second. A vertex is red if it is infected earlier than the ... | A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Children of the vertex $$$v$$$ are all vertices for which $$$v$$$ is the parent... | For each test case you should output a single integer — the minimal number of seconds needed to infect the whole tree. | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 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$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of the vertices in the ... | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_096.jsonl | 3daf6d2ec16b1db183b9346ba63f6de0 | 256 megabytes | ["5\n7\n1 1 1 2 2 4\n5\n5 5 1 4\n2\n1\n3\n3 1\n6\n1 1 1 1 1"] | PASSED | import sys
input=sys.stdin.readline
def get_rid_of_zeros():
while len(number_of_children) and number_of_children[-1]<=0:
number_of_children.pop()
for _ in range(int(input())):
n=int(input())
x=list(map(int,input().split()))
number_of_children=[0]*n
for i in x:
number_of_chi... | 1649428500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1.5 seconds | ["2\n-1\n1\n2\n5"] | af40a0de6d3c0ff7bcd2c1b077b05d6e | NoteIn the first example, we will understand chapters $$$\{2, 4\}$$$ in the first reading and chapters $$$\{1, 3\}$$$ in the second reading of the book.In the second example, every chapter requires the understanding of some other chapter, so it is impossible to understand the book.In the third example, every chapter re... | You are given a book with $$$n$$$ chapters.Each chapter has a specified list of other chapters that need to be understood in order to understand this chapter. To understand a chapter, you must read it after you understand every chapter on its required list.Currently you don't understand any of the chapters. You are goi... | For each test case, if the entire book can be understood, print how many times you will read it, otherwise print $$$-1$$$. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2\cdot10^4$$$). The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of chapters. Then $$$n$$$ lines follow. The $$$i$$$-th line begins with an integer $... | standard output | standard input | PyPy 3-64 | Python | 1,800 | train_094.jsonl | bd9707c575d230e94cb38c7b9453c41b | 256 megabytes | ["5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 2\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 5\n0"] | PASSED | for _ in range(int(input())):
n = int(input())
adj = [[] for i in range(n)]
in_degree= [[] for i in range(n)]
for i in range(n):
l = list(map(int,input().split()))
for j in range(1,len(l)):
adj[l[j]-1].append(i)
in_degree[i] = l[0]
count= 0
from collections im... | 1631975700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["5 3", "1 7", "2999999987 2", "12 13"] | ca7de8440f5bbbe75e8b93654ce75cd3 | NoteIn the first example the minimum value of $$$y$$$ equals to $$$5$$$, i.e. the minimum number of people who could have broken into the basement, is $$$5$$$. Each of them has taken $$$3$$$ swords: three of them have taken $$$3$$$ swords of the first type, and two others have taken $$$3$$$ swords of the third type.In ... | There were $$$n$$$ types of swords in the theater basement which had been used during the plays. Moreover there were exactly $$$x$$$ swords of each type. $$$y$$$ people have broken into the theater basement and each of them has taken exactly $$$z$$$ swords of some single type. Note that different people might have take... | Print two integers $$$y$$$ and $$$z$$$ — the minimum number of people which could have broken into the basement and the number of swords each of them has taken. | The first line of the input contains one integer $$$n$$$ $$$(2 \le n \le 2 \cdot 10^{5})$$$ — the number of types of swords. The second line of the input contains the sequence $$$a_1, a_2, \dots, a_n$$$ $$$(0 \le a_i \le 10^{9})$$$, where $$$a_i$$$ equals to the number of swords of the $$$i$$$-th type, which have remai... | standard output | standard input | Python 3 | Python | 1,300 | train_022.jsonl | 2a8d299d7cd11a758738717f92c2786d | 256 megabytes | ["3\n3 12 6", "2\n2 9", "7\n2 1000000000 4 6 8 4 2", "6\n13 52 0 13 26 52"] | PASSED | from math import gcd
n = int(input())
d1 = [int(i) for i in input().split()]
mn = min(d1)
mx = max(d1)
d2 = [mx - i for i in d1]
g = d2[0]
for i in range(1, n):
g = gcd(g, d2[i])
sm = sum(d2)
am = sm // g
print(am, g)
| 1569049500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1 1 2", "1 1 1 2 3"] | 291bfc61026dddf6c53f4cd9a8aa2baa | NoteIn the first example for $$$k = 1$$$ and $$$k = 2$$$ we can use only one color: the junctions $$$2$$$ and $$$3$$$ will be happy. For $$$k = 3$$$ you have to put the bulbs of different colors to make all the junctions happy.In the second example for $$$k = 4$$$ you can, for example, put the bulbs of color $$$1$$$ in... | There is one apple tree in Arkady's garden. It can be represented as a set of junctions connected with branches so that there is only one way to reach any junctions from any other one using branches. The junctions are enumerated from $$$1$$$ to $$$n$$$, the junction $$$1$$$ is called the root.A subtree of a junction $$... | Output $$$n$$$ integers. The $$$i$$$-th of them should be the minimum number of colors needed to make the number of happy junctions be at least $$$i$$$. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of junctions in the tree. The second line contains $$$n - 1$$$ integers $$$p_2$$$, $$$p_3$$$, ..., $$$p_n$$$ ($$$1 \le p_i < i$$$), where $$$p_i$$$ means there is a branch between junctions $$$i$$$ and $$$p_i$$$. It is guaranteed ... | standard output | standard input | Python 3 | Python | 1,600 | train_025.jsonl | a887646245738abe27e94f7cf11b39fd | 256 megabytes | ["3\n1 1", "5\n1 1 3 3"] | PASSED | n = int(input())
p = [0,0] + [int(w) for w in input().split()]
d = [0] * (n+1)
for i in range(n, 1, -1):
if d[i] == 0:
d[i] = 1
d[p[i]] += d[i]
if n == 1:
d[1] = 1
d = d[1:]
d.sort()
print(*d) | 1543163700 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["2\n1 2\n2 3", "3\n1 2\n2 3\n3 4\n3 5"] | ad49b1b537ca539ea0898ee31a0aecf8 | NoteIn the first example the only network is shown on the left picture.In the second example one of optimal networks is shown on the right picture.Exit-nodes are highlighted. | Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly k of the nodes should be exit-nodes, that means that each of them should be ... | In the first line print the minimum possible distance between the two most distant exit-nodes. In each of the next n - 1 lines print two integers: the ids of the nodes connected by a wire. The description of each wire should be printed exactly once. You can print wires and wires' ends in arbitrary order. The nodes shou... | The first line contains two integers n and k (3 ≤ n ≤ 2·105, 2 ≤ k ≤ n - 1) — the total number of nodes and the number of exit-nodes. Note that it is always possible to build at least one network with n nodes and k exit-nodes within the given constraints. | standard output | standard input | Python 2 | Python | 1,800 | train_005.jsonl | aff35ff907371f0ded1169be148b0b3f | 512 megabytes | ["3 2", "5 3"] | PASSED | n,k=map(int,raw_input().split())
print (n-1)/k*2+min((n-1)%k,2)
for i in range(n-1):
print max(1,i+2-k),i+2 | 1499791500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["2\n4\n5\n999999999\n5"] | 681ee82880ddd0de907aac2ccad8fc04 | NoteIn the first sample: $$$f_3(1) = \left\lfloor\frac{1}{3}\right\rfloor + 1 \bmod 3 = 0 + 1 = 1$$$, $$$f_3(2) = \left\lfloor\frac{2}{3}\right\rfloor + 2 \bmod 3 = 0 + 2 = 2$$$, $$$f_3(3) = \left\lfloor\frac{3}{3}\right\rfloor + 3 \bmod 3 = 1 + 0 = 1$$$, $$$f_3(4) = \left\lfloor\frac{4}{3}\right\rfloor + 4 \bmod 3... | Not so long ago, Vlad came up with an interesting function: $$$f_a(x)=\left\lfloor\frac{x}{a}\right\rfloor + x \bmod a$$$, where $$$\left\lfloor\frac{x}{a}\right\rfloor$$$ is $$$\frac{x}{a}$$$, rounded down, $$$x \bmod a$$$ — the remainder of the integer division of $$$x$$$ by $$$a$$$.For example, with $$$a=3$$$ and $$... | For each test case, output one number on a separate line — the maximum value of the function on a given segment for a given $$$a$$$. | The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of input test cases. This is followed by $$$t$$$ lines, each of which contains three integers $$$l_i$$$, $$$r_i$$$ and $$$a_i$$$ ($$$1 \le l_i \le r_i \le 10^9, 1 \le a_i \le 10^9$$$) — the left and right boundaries of the se... | standard output | standard input | Python 3 | Python | 900 | train_104.jsonl | ab2b4efc6652567f2ee7130d242e6188 | 256 megabytes | ["5\n\n1 4 3\n\n5 8 4\n\n6 10 6\n\n1 1000000000 1000000000\n\n10 12 8"] | PASSED | t = int(input())
if t>0:
for i in range(t):
l,r,a = map(int, input().split())
if a>r:
print(r//a + r%a)
else:
if r//a == l//a:
print(r//a + r%a)
elif r//a - l//a == 1:
r1 = r//a + r%a
l1 = l//a + (... | 1646750100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["54", "1000000000000000000"] | 96dee17800e147350bd37e60f66f49dd | NoteIn the first example you may use emotes in the following sequence: $$$4, 4, 5, 4, 4, 5, 4, 4, 5$$$. | There are $$$n$$$ emotes in very popular digital collectible card game (the game is pretty famous so we won't say its name). The $$$i$$$-th emote increases the opponent's happiness by $$$a_i$$$ units (we all know that emotes in this game are used to make opponents happy).You have time to use some emotes only $$$m$$$ ti... | Print one integer — the maximum opponent's happiness if you use emotes in a way satisfying the problem statement. | The first line of the input contains three integers $$$n, m$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le k \le m \le 2 \cdot 10^9$$$) — the number of emotes, the number of times you can use emotes and the maximum number of times you may use the same emote in a row. The second line of the input contains $$$n... | standard output | standard input | Python 3 | Python | 1,000 | train_003.jsonl | b47668a9dbe68acfd1ab79305816edcd | 256 megabytes | ["6 9 2\n1 3 3 7 4 2", "3 1000000000 1\n1000000000 987654321 1000000000"] | PASSED | n,m,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
a = max(arr)
if arr.count(a) > 1:
b = a
else:
arr = sorted(arr)
b = arr[n - 2]
u = 0
l = m // (k + 1)
u += l * (k * a + b)
w = m % (k + 1)
u += w * a
print(u)
| 1550504400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["-1", "0", "1\n1", "1\n2"] | c046e64e008e997620efc21aec199bdb | NoteIn the first sample we have single vertex without edges. It's degree is 0 and we can not get 1. | Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or - 1. To pass the level, he needs to find a «good» subset of edges of the graph or say... | Print - 1 in a single line, if solution doesn't exist. Otherwise in the first line k — number of edges in a subset. In the next k lines indexes of edges. Edges are numerated in order as they are given in the input, starting from 1. | The first line contains two integers n, m (1 ≤ n ≤ 3·105, n - 1 ≤ m ≤ 3·105) — number of vertices and edges. The second line contains n integers d1, d2, ..., dn ( - 1 ≤ di ≤ 1) — numbers on the vertices. Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n) — edges. It's guaranteed, that graph in the in... | standard output | standard input | Python 2 | Python | 2,100 | train_031.jsonl | ab3d69f6d5910e91765b7b127a4ae42c | 256 megabytes | ["1 0\n1", "4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4", "2 1\n1 1\n1 2", "3 3\n0 -1 1\n1 2\n2 3\n1 3"] | PASSED | from collections import deque
def subtree_specs(graph, d, node, visited, edges_dict, res_edges):
num_ones = 0
for nb in graph[node]:
if not visited[nb]:
visited[nb] = True
res = subtree_specs(graph, d, nb, visited, edges_dict, res_edges)
if res % 2 == 1:
... | 1503068700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["YES", "YES", "NO"] | 64b597a47106d0f08fcfad155e0495c3 | NoteIn the first example, all stations are opened, so Bob can simply travel to the station with number $$$3$$$.In the second example, Bob should travel to the station $$$5$$$ first, switch to the second track and travel to the station $$$4$$$ then.In the third example, Bob simply can't enter the train going in the dire... | Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home.In the city in which Alice and Bob live, the first metro line is being built. This metro line contains $$$n$$$ stations numbered from $$$1$$$ to $$$n$$$. Bob lives near the station with number... | Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower). | The first line contains two integers $$$n$$$ and $$$s$$$ ($$$2 \le s \le n \le 1000$$$) — the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station $$$1$$$. Next lines describe information about closed and open stations. The second line contains $$$n$$$ intege... | standard output | standard input | PyPy 3 | Python | 900 | train_011.jsonl | f6b8724cd7715792859c5f3fbff36a20 | 256 megabytes | ["5 3\n1 1 1 1 1\n1 1 1 1 1", "5 4\n1 0 0 0 1\n0 1 1 1 1", "5 2\n0 1 1 1 1\n1 1 1 1 1"] | PASSED | n,s = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s-=1
if a[0]==0:
print('NO')
elif a[s]==1:
print('YES')
elif any([(a[i] and b[i]) for i in range(s+1,n)]) and b[s]==1:
print('YES')
else:
print('NO') | 1541860500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["2", "2"] | 944ab87c148df0fc59ec0263d6fd8b9f | NoteIn the first sample string t has a form 'a'. The only optimal option is to replace all characters '?' by 'a'.In the second sample using two replacements we can make string equal to "aba?aba??". It is impossible to get more than two occurrences. | Vasya wrote down two strings s of length n and t of length m consisting of small English letters 'a' and 'b'. What is more, he knows that string t has a form "abab...", namely there are letters 'a' on odd positions and letters 'b' on even positions.Suddenly in the morning, Vasya found that somebody spoiled his string. ... | Print the only integer — the minimum number of replacements Vasya has to perform to make the beauty of string s the maximum possible. | The first line contains a single integer n (1 ≤ n ≤ 105) — the length of s. The second line contains the string s of length n. It contains small English letters 'a', 'b' and characters '?' only. The third line contains a single integer m (1 ≤ m ≤ 105) — the length of t. The string t contains letters 'a' on odd position... | standard output | standard input | Python 3 | Python | 2,100 | train_053.jsonl | 496f25e71bb9f302589dfad055890d09 | 256 megabytes | ["5\nbb?a?\n1", "9\nab??ab???\n3"] | PASSED | match = 0; nonmatch = 0; count = 0
def calc_match(s, t, p):
global match
global nonmatch
global count
if p == len(s)-len(t):
return
if p+len(t) < len(s):
if s[p+len(t)] == '?':
count -= 1
elif s[p+len(t)] == t[-1]:
match -= 1
else:
nonmatch -= 1
match, nonmatch = nonmatch, ... | 1513008300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["72900", "317451037"] | 6fcd8713af5a108d590bc99da314cded | NoteIn the first example, $$$f_{4} = 90$$$, $$$f_{5} = 72900$$$.In the second example, $$$f_{17} \approx 2.28 \times 10^{29587}$$$. | Let $$$f_{x} = c^{2x-6} \cdot f_{x-1} \cdot f_{x-2} \cdot f_{x-3}$$$ for $$$x \ge 4$$$.You have given integers $$$n$$$, $$$f_{1}$$$, $$$f_{2}$$$, $$$f_{3}$$$, and $$$c$$$. Find $$$f_{n} \bmod (10^{9}+7)$$$. | Print $$$f_{n} \bmod (10^{9} + 7)$$$. | The only line contains five integers $$$n$$$, $$$f_{1}$$$, $$$f_{2}$$$, $$$f_{3}$$$, and $$$c$$$ ($$$4 \le n \le 10^{18}$$$, $$$1 \le f_{1}$$$, $$$f_{2}$$$, $$$f_{3}$$$, $$$c \le 10^{9}$$$). | standard output | standard input | Python 3 | Python | 2,300 | train_000.jsonl | 3bf934bfa45c8ccf487e4f51f1003160 | 256 megabytes | ["5 1 2 5 3", "17 97 41 37 11"] | PASSED | def mat_mul(a, b):
n, m, p = len(a), len(b), len(b[0])
res = [[0]*p for _ in range(n)]
for i in range(n):
for j in range(p):
for k in range(m):
res[i][j] += a[i][k]*b[k][j]
res[i][j] %= 1000000006
return res
def mat_pow(a, n):
if n == 1: return a
... | 1560258300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["1", "-1", "2 4 1 3", "2 5 3 1 4"] | dfca19b36c1d682ee83224a317e495e9 | null | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.You have integer n. Find some lucky permutation p of size n. | Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) after a space — the required permutation. If there are multiple answers, you can print any of them. | The first line contains integer n (1 ≤ n ≤ 105) — the required permutation size. | standard output | standard input | Python 3 | Python | 1,400 | train_062.jsonl | b7f82d0e86758b4eada6e788a850e0e2 | 256 megabytes | ["1", "2", "4", "5"] | PASSED | n = int(input())
p = [0] * n
if n == 1:
print(1)
exit()
for sh in range(n // 4):
p[n - sh * 2 - 2] = n - sh * 2
p[sh * 2] = n - 1 - sh * 2
p[n - sh * 2 - 1] = 2 + sh * 2
p[sh * 2 + 1] = 1 + sh * 2
if n % 4 == 1:
p[n // 2] = n // 2 + 1
if n % 4 == 2:
print(-1)
exit()
if n % 4 == ... | 1364025600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["70 27 \n17 \n3 4 100 4\n10 90\n1 1 2 1 1 1 1 1 1 \n999900 90 9"] | 2afb210831529a99f8f04f13e5438d55 | NoteIn the first test case, $$$70_{10} + 27_{10} = 97_{10}$$$, and Alice's sum is $$$$$$70_{11} + 27_{11} = 97_{11} = 9 \cdot 11 + 7 = 106_{10}.$$$$$$ (Here $$$x_b$$$ represents the number $$$x$$$ in base $$$b$$$.) It can be shown that it is impossible for Alice to get a larger sum than $$$106_{10}$$$.In the second tes... | On the board, Bob wrote $$$n$$$ positive integers in base $$$10$$$ with sum $$$s$$$ (i. e. in decimal numeral system). Alice sees the board, but accidentally interprets the numbers on the board as base-$$$11$$$ integers and adds them up (in base $$$11$$$).What numbers should Bob write on the board, so Alice's sum is as... | For each test case, output $$$n$$$ positive integers — the numbers Bob should write on the board, so Alice's sum is as large as possible. If there are multiple answers, print any of them. | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The only line of each test case contains two integers $$$s$$$ and $$$n$$$ ($$$1 \leq s \leq 10^9$$$; $$$1 \leq n \leq \min(100, s)$$$) — ... | standard output | standard input | PyPy 3 | Python | 2,000 | train_089.jsonl | a93f197c100725a3cfdee58adc6ca091 | 256 megabytes | ["6\n97 2\n17 1\n111 4\n100 2\n10 9\n999999 3"] | PASSED |
def solver(s, n):
num = 10 ** (len(str(s))-1)
for i in range(n-1):
while s - num < n - (i + 1):
num //= 10
print(num, end=' ')
s -= num
print(s)
T = int(input())
for t in range(T):
S, N = map(int, input().split())
solver(S, N)
'''
6
97 2
17 1
... | 1630852500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["NO\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES"] | 9363df0735005832573ef4d17b6a8302 | NoteFor the first test case, $$$a = [1]$$$, so the answer is "NO", since the only element in the array is $$$1$$$.For the second test case the array is $$$a = [3, 4, 5]$$$ and we have $$$1$$$ operation. After the first operation the array can change to: $$$[3, 20]$$$, $$$[4, 15]$$$ or $$$[5, 12]$$$ all of which having ... | Consider the array $$$a$$$ composed of all the integers in the range $$$[l, r]$$$. For example, if $$$l = 3$$$ and $$$r = 7$$$, then $$$a = [3, 4, 5, 6, 7]$$$.Given $$$l$$$, $$$r$$$, and $$$k$$$, is it possible for $$$\gcd(a)$$$ to be greater than $$$1$$$ after doing the following operation at most $$$k$$$ times? Cho... | For each test case, print "YES" if it is possible to have the GCD of the corresponding array greater than $$$1$$$ by performing at most $$$k$$$ operations, and "NO" otherwise (case insensitive). | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The description of test cases follows. The input for each test case consists of a single line containing $$$3$$$ non-negative integers $$$l$$$, $$$r$$$, and $$$k$$$ ($$$1 \leq l \leq r \leq 10^9, \enspace ... | standard output | standard input | Python 3 | Python | 800 | train_093.jsonl | b55bd725eed01cfdac7878fa1f797954 | 256 megabytes | ["9\n1 1 0\n3 5 1\n13 13 0\n4 4 0\n3 7 4\n4 10 3\n2 4 0\n1 7 3\n1 5 3"] | PASSED | for i in range(int(input())):
a=list(map(int,input().split(' ')))
if a[0]==a[1]:
if a[0]!=1:
print('YES')
else:
print('NO')
else:
k=a[2]
if a[0]%2!=0:
d=1+(a[1]-a[0])//2
else:
d=(a[1]-a[0]+1)//2
if k... | 1642862100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["7", "6"] | 55512092f84fdf712b212ed389ae6bc8 | NoteThere are $$$7$$$ subpermutations in the first test case. Their segments of indices are $$$[1, 4]$$$, $$$[3, 3]$$$, $$$[3, 6]$$$, $$$[4, 7]$$$, $$$[6, 7]$$$, $$$[7, 7]$$$ and $$$[7, 8]$$$.In the second test case $$$6$$$ subpermutations exist: $$$[1, 1]$$$, $$$[2, 2]$$$, $$$[2, 3]$$$, $$$[3, 4]$$$, $$$[4, 4]$$$ and ... | You have an array $$$a_1, a_2, \dots, a_n$$$. Let's call some subarray $$$a_l, a_{l + 1}, \dots , a_r$$$ of this array a subpermutation if it contains all integers from $$$1$$$ to $$$r-l+1$$$ exactly once. For example, array $$$a = [2, 2, 1, 3, 2, 3, 1]$$$ contains $$$6$$$ subarrays which are subpermutations: $$$[a_2 \... | Print the number of subpermutations of the array $$$a$$$. | The first line contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le n$$$). This array can contain the same integers. | standard output | standard input | PyPy 3 | Python | 2,500 | train_033.jsonl | 4ff0b87eabe82c7e06ea8d4c654cc33c | 256 megabytes | ["8\n2 4 1 3 4 2 1 2", "5\n1 1 2 1 2"] | PASSED | import sys
import math
input=sys.stdin.readline
#sys.setrecursionlimit(1000000)
mod=int(1000000007)
i=lambda :map(int,input().split())
n=int(input())
a=[int(x) for x in input().split()]
t=[[0]*21 for i in range(300005)]
for i in range(n):
t[i][0]=a[i]
def build(n):
for j in range(1,20):
for i in rang... | 1559745300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
5 seconds | ["A\nD 3\n2\nB\n2"] | 299c209b070e510e7ed3b525f51fec8a | NoteThe first example has two test cases. In the first test case, the graph looks like the following. In the sample output, the player decides to play as Alice and chooses "decreasing" and starting at node $$$3$$$. The judge responds by moving to node $$$6$$$. After, the player moves to node $$$2$$$. At this point, th... | You are given a complete bipartite graph with $$$2n$$$ nodes, with $$$n$$$ nodes on each side of the bipartition. Nodes $$$1$$$ through $$$n$$$ are on one side of the bipartition, and nodes $$$n+1$$$ to $$$2n$$$ are on the other side. You are also given an $$$n \times n$$$ matrix $$$a$$$ describing the edge weights. $$... | null | null | standard output | standard input | PyPy 2 | Python | 3,500 | train_080.jsonl | 4899e07de654ffb241a773dd528ec9f0 | 256 megabytes | ["2\n3\n3 1 9\n2 5 7\n6 4 8\n6\n-1\n1\n1\nI 1\n-1"] | PASSED | import sys
def stable_marriage(p1, p2):
n = len(p1)
ret = [-1 for __ in xrange(2*n)]
free = [True for __ in xrange(n)]
nfree = n
def engage(m,w):
ret[w+n] = m
ret[m] = w+n
free[m] = False
while nfree > 0:
m = next(i for i in xrange(n) if free[i])
idx = ... | 1556989500 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["1 2 4\n1 2\n1\n1\n1 2 3 4 5"] | 81f4bc9ac72ed39da8614131954d0d99 | NoteIn the first test case: If $$$k = 1$$$, we can make four elimination operations with sets of indices $$$\{1\}$$$, $$$\{2\}$$$, $$$\{3\}$$$, $$$\{4\}$$$. Since $$$\&$$$ of one element is equal to the element itself, then for each operation $$$x = a_i$$$, so $$$a_i - x = a_i - a_i = 0$$$. If $$$k = 2$$$, we can... | You are given array $$$a_1, a_2, \ldots, a_n$$$, consisting of non-negative integers.Let's define operation of "elimination" with integer parameter $$$k$$$ ($$$1 \leq k \leq n$$$) as follows: Choose $$$k$$$ distinct array indices $$$1 \leq i_1 < i_2 < \ldots < i_k \le n$$$. Calculate $$$x = a_{i_1} ~ \& ... | For each test case, print all values $$$k$$$, such that it's possible to make all elements of $$$a$$$ equal to $$$0$$$ in a finite number of elimination operations with the given parameter $$$k$$$. Print them in increasing order. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 10^4$$$). Description of the test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$1 \leq n \leq 200\,000$$$) — the length of array $$$a$$$. The second line of each test cas... | standard output | standard input | PyPy 3-64 | Python | 1,300 | train_092.jsonl | 7e7a62fc9de0b210b642622ef7f91298 | 512 megabytes | ["5\n4\n4 4 4 4\n4\n13 7 25 19\n6\n3 5 3 1 7 1\n1\n1\n5\n0 0 0 0 0"] | PASSED | def getint():
return [int(i) for i in input().split()]
def get():
return int(input())
def getstr():
return [i for i in input().split()]
def S():
for test in range(int(input())):
solve()
import math
import itertools as it
import bisect
import time
import collections as ct
def solv... | 1635143700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | [">\n=\n<\n=\n<"] | a4eeaf7252b9115b67b9eca5f2bf621d | NoteThe comparisons in the example are: $$$20 > 19$$$, $$$1000 = 1000$$$, $$$1999 < 2000$$$, $$$1 = 1$$$, $$$99 < 100$$$. | Monocarp wrote down two numbers on a whiteboard. Both numbers follow a specific format: a positive integer $$$x$$$ with $$$p$$$ zeros appended to its end.Now Monocarp asks you to compare these two numbers. Can you help him? | For each testcase print the result of the comparison of the given two numbers. If the first number is smaller than the second one, print '<'. If the first number is greater than the second one, print '>'. If they are equal, print '='. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains two integers $$$x_1$$$ and $$$p_1$$$ ($$$1 \le x_1 \le 10^6; 0 \le p_1 \le 10^6$$$) — the description of the first number. The second line of each testcase contains two integers ... | standard output | standard input | PyPy 3-64 | Python | 900 | train_090.jsonl | 3068e6f323024f5174400f4f5839664a | 256 megabytes | ["5\n2 1\n19 0\n10 2\n100 1\n1999 0\n2 3\n1 0\n1 0\n99 0\n1 2"] | PASSED | import math
for _ in range(int(input())):
x1, p1 = map(int, input().split())
x2, p2 = map(int, input().split())
a=math.log(x1/x2, 10)
if a>(p2-p1):
print(">")
elif a<(p2-p1):
print("<")
else:
print("=")
| 1638369300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["5 6 3", "5 12 23 34 36 27 18 11 6 1"] | 126eaff19fe69989cd5b588503a0fed8 | null | The academic year has just begun, but lessons and olympiads have already occupied all the free time. It is not a surprise that today Olga fell asleep on the Literature. She had a dream in which she was on a stairs. The stairs consists of n steps. The steps are numbered from bottom to top, it means that the lowest step ... | Print n numbers, the i-th of which is equal either to the duration of Olga's dream or to - 1 if Olga never goes beyond the stairs, if in the beginning of sleep she was on the i-th step. | The first line contains single integer n (1 ≤ n ≤ 106) — the number of steps on the stairs. The second line contains a string s with the length n — it denotes the initial direction of pointers on the stairs. The i-th character of string s denotes the direction of the pointer above i-th step, and is either 'U' (it means... | standard output | standard input | Python 3 | Python | 2,400 | train_059.jsonl | 2fdee68b4cc319ff695a85c873ee20d9 | 256 megabytes | ["3\nUUD", "10\nUUDUDUUDDU"] | PASSED | n=int(input())
string = input()
q1,q2,B,C=[],[],[],[]
A=0
for i in range(n):
if string[i] == "D":
q1.append(i)
else:
q2.append(n-1-i)
for i in range(len(q1)):
A+=(q1[i]-i)*2+1
B.append(A)
A=0
temp = []
for i in range(len(q2)):
A+=(q2[len(q2)-1-i]-i)*2+1
C.append(A)
C.reverse()
... | 1477922700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2", "4", "6"] | 2ff789ae0095bb7ff0e747b0d4df59bc | NoteFor first example, the lamps' states are shown in the picture above. The largest number of simultaneously on lamps is $$$2$$$ (e.g. at the moment $$$2$$$).In the second example, all lights are initially on. So the answer is $$$4$$$. | It is a holiday season, and Koala is decorating his house with cool lights! He owns $$$n$$$ lights, all of which flash periodically.After taking a quick glance at them, Koala realizes that each of his lights can be described with two parameters $$$a_i$$$ and $$$b_i$$$. Light with parameters $$$a_i$$$ and $$$b_i$$$ will... | Print a single integer — the maximum number of lights that will ever be on at the same time. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of lights. The next line contains a string $$$s$$$ of $$$n$$$ characters. The $$$i$$$-th character is "1", if the $$$i$$$-th lamp is initially on. Otherwise, $$$i$$$-th character is "0". The $$$i$$$-th of the following $$$n$$$ lines co... | standard output | standard input | Python 3 | Python | 1,300 | train_012.jsonl | 935fc042813d682016d9659abed59f30 | 256 megabytes | ["3\n101\n3 3\n3 2\n3 1", "4\n1111\n3 4\n5 2\n3 1\n3 2", "6\n011100\n5 3\n5 5\n2 4\n3 5\n4 2\n1 5"] | PASSED | import math
n = int(input())
ini = str(input())
ab = []
maxon = 0
for i in range(n):
abi = list(map(int, input().split()))
ab.append(abi)
for t in range(1, 241):
res = []
i = 0
for abi in ab:
if t-abi[1] <= 0:
res.append(int(ini[i])==0)
else:
res.append(math.... | 1568466300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["4\n2\n0"] | e1de1e92fac8a6db3222c0d3c26843d8 | NoteIn the first sample, one of the optimal solutions is:$$$a = \{2, 0, 1, 1, 0, 2, 1\}$$$$$$b = \{1, 0, 1, 0, 2, 1, 0\}$$$$$$c = \{2, 0, 0, 0, 0, 2, 0\}$$$In the second sample, one of the optimal solutions is:$$$a = \{0, 2, 0, 0, 0\}$$$$$$b = \{1, 1, 0, 1, 0\}$$$$$$c = \{0, 2, 0, 0, 0\}$$$In the third sample, the only... | You are given two sequences $$$a_1, a_2, \dots, a_n$$$ and $$$b_1, b_2, \dots, b_n$$$. Each element of both sequences is either $$$0$$$, $$$1$$$ or $$$2$$$. The number of elements $$$0$$$, $$$1$$$, $$$2$$$ in the sequence $$$a$$$ is $$$x_1$$$, $$$y_1$$$, $$$z_1$$$ respectively, and the number of elements $$$0$$$, $$$1$... | For each test case, print the maximum possible sum of the sequence $$$c$$$. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains three integers $$$x_1$$$, $$$y_1$$$, $$$z_1$$$ ($$$0 \le x_1, y_1, z_1 \le 10^8$$$) — the number of $$$0$$$-s, $$$1$$$-s and $$$2$$$-s in the s... | standard output | standard input | PyPy 2 | Python | 1,100 | train_003.jsonl | cad704dd4ed3566b651c43dbef08f063 | 256 megabytes | ["3\n2 3 2\n3 3 1\n4 0 1\n2 3 0\n0 0 1\n0 0 1"] | PASSED | t = int(raw_input())
for _ in range(t):
x1, y1, z1 = map(int, raw_input().strip().split(" "))
x2, y2, z2 = map(int, raw_input().strip().split(" "))
answer = 0
num_twos = min(z1, y2)
answer += 2*num_twos
z1 -= num_twos
y2 -= num_twos
a = min(x1, z2)
x1 -= a
z2 -= a
b = min(x2... | 1598020500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES", "NO"] | 159f163dd6da4668f01a66ddf746eb93 | null | Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment.Fortunately, chemical laws allow material transformations (yes, chemistry in ... | Print YES if it is possible to conduct an experiment. Otherwise print NO. | The first line contains one integer number n (1 ≤ n ≤ 105) — the number of materials discovered by Berland chemists. The second line contains n integer numbers b1, b2... bn (1 ≤ bi ≤ 1012) — supplies of BerSU laboratory. The third line contains n integer numbers a1, a2... an (1 ≤ ai ≤ 1012) — the amounts required for t... | standard output | standard input | Python 3 | Python | 2,300 | train_020.jsonl | 810501201fd3d73fd805eeb1d2947516 | 256 megabytes | ["3\n1 2 3\n3 2 1\n1 1\n1 1", "3\n3 2 1\n1 2 3\n1 1\n1 2"] | PASSED | import sys
# @profile
def main():
f = sys.stdin
# f = open('input.txt', 'r')
# fo = open('log.txt', 'w')
n = int(f.readline())
# b = []
# for i in range(n):
# b.append()
b = list(map(int, f.readline().strip().split(' ')))
a = list(map(int, f.readline().strip().split(' ')))
# ... | 1504623900 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["2\n1\n3\n2", "1\n1\n1"] | 907893a0a78a7444d26bdd793d9c7499 | null | After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has n balls and m baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to m, correspondingly. The ... | Print n numbers, one per line. The i-th line must contain the number of the basket for the i-th ball. | The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — the number of balls and baskets, correspondingly. | standard output | standard input | Python 3 | Python | 1,300 | train_013.jsonl | bad5c6e4ada7d55066d0b84ff5b06e1e | 256 megabytes | ["4 3", "3 1"] | PASSED | n, m = map(int, input().split())
a = []
t = 1 if m % 2 else -1
for i in range(m):
a.append(int(m/2)+int(m%2)+t*int((i+1)/2))
t *= -1
for i in range(n):
print(a[int(i%m)])
| 1339342200 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
5 seconds | ["3 1 0\n2 0"] | f07a78f9317b2d897aca2d9ca62837f0 | NoteIn the first test case, If we delete the nodes in order $$$1 \rightarrow 2 \rightarrow 3$$$ or $$$1 \rightarrow 3 \rightarrow 2$$$, then the obtained sequence will be $$$a = [2, 0, 0]$$$ which has $$$\operatorname{gcd}$$$ equals to $$$2$$$. If we delete the nodes in order $$$2 \rightarrow 1 \rightarrow 3$$$, t... | You are given a tree with $$$n$$$ nodes. As a reminder, a tree is a connected undirected graph without cycles.Let $$$a_1, a_2, \ldots, a_n$$$ be a sequence of integers. Perform the following operation exactly $$$n$$$ times: Select an unerased node $$$u$$$. Assign $$$a_u :=$$$ number of unerased nodes adjacent to $$$u... | For each test case, print $$$n$$$ integers in a single line, where for each $$$k$$$ from $$$1$$$ to $$$n$$$, the $$$k$$$-th integer denotes the answer when $$$\operatorname{gcd}$$$ equals to $$$k$$$. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$). Each of the next $$$n - 1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$) indicating there is... | standard output | standard input | PyPy 3 | Python | 2,600 | train_087.jsonl | 9a6a374d9337b890aac0a54f793cc58f | 256 megabytes | ["2\n3\n2 1\n1 3\n2\n1 2"] | PASSED | import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
MOD = 998244353
t = int(input())
while t > 0:
t -= 1
n = int(input())
g = [[] for i in range(n)]
for i in range(n - 1):
x, y = map(int, input().split())
g[x - 1] += [y - 1]
g[y - 1] += [x - 1]
f = [0] * n
pa... | 1627569300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["3 2 1", "-1", "3 2 1"] | 46e7cd6723553d2c6d6c6d0999a5b5fc | null | A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive.Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same... | If the required division into teams doesn't exist, print number -1. Otherwise, print lines. In each line print three integers xi, yi, zi (1 ≤ xi, yi, zi ≤ n) — the i-th team. If there are multiple answers, you are allowed to print any of them. | The first line of the input contains integers n and m (3 ≤ n ≤ 48, . Then follow m lines, each contains a pair of integers ai, bi (1 ≤ ai < bi ≤ n) — the pair ai, bi means that students with numbers ai and bi want to be on the same team. It is guaranteed that n is divisible by 3. It is guaranteed that each pair ai, ... | standard output | standard input | Python 3 | Python | 1,500 | train_021.jsonl | a224c103dbbde749d324089fc8ebeb64 | 256 megabytes | ["3 0", "6 4\n1 2\n2 3\n3 4\n5 6", "3 3\n1 2\n2 3\n1 3"] | PASSED | from collections import defaultdict
n,m = list(map(int,input().split()))
if m==0:
for i in range(1,n+1,3):
print(i,i+1,i+2)
else:
graph = defaultdict(list)
for i in range(m):
u,v = list(map(int,input().split()))
graph[u].append(v)
graph[v].append(u)
visited = [False for i... | 1366903800 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["1\n4\n4\n4\n3\n1"] | e0a1dc397838852957d0e15ec98d5efe | NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$. | You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with ... | For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house. | First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed t... | standard output | standard input | Python 3 | Python | 1,500 | train_110.jsonl | f10555b5b32416d10d803cdd54f66b8a | 256 megabytes | ["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"] | PASSED | import os
DEBUG = 'DEBUG' in os.environ
def debug(*args):
if DEBUG:
print(">", *args)
def solution(houses):
if len(houses) == 1:
return 1
housesX = []
housesY = []
for house in houses:
housesX.append(house[0])
housesY.append(house[1])
housesX.sort()
housesY.sort()
... | 1613658900 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
1 second | ["0.9230769231\n0.6666666667"] | c8a42b3dfa8c9ee031ab4efd4c90bd58 | NoteDish from the first sample looks like this:Dish from the second sample looks like this: | Have you ever tasted Martian food? Well, you should.Their signature dish is served on a completely black plate with the radius of R, flat as a pancake.First, they put a perfectly circular portion of the Golden Honduras on the plate. It has the radius of r and is located as close to the edge of the plate as possible sta... | Print t lines — the radius of the k-th portion of the Green Bull Terrier for each test. The absolute or relative error of the answer should not exceed 10 - 6. | The first line contains integer t (1 ≤ t ≤ 104) — amount of testcases. Each of the following t lines contain three positive integers: the radii of the plate and a portion of the Golden Honduras R and r (1 ≤ r < R ≤ 104) and the number k (1 ≤ k ≤ 104). In the pretests 1 ≤ k ≤ 2. | standard output | standard input | Python 3 | Python | 2,800 | train_007.jsonl | 4fea16271eab35b5a5bea72728e35584 | 256 megabytes | ["2\n4 3 1\n4 2 2"] | PASSED | #!/usr/bin/env python3
def solve(R,r,k):
# Thanks to Numberphile's "Epic circles" video
# Use the formula for radii of circles in Pappus chain
r = r / R
n = k
answer = ((1-r)*r)/(2*((n**2)*((1-r)**2)+r))
# Note that in a Pappus chain the diameter of the circle is 1, so we need to scale up:
answer = 2*R *... | 1303226100 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
4 seconds | ["6"] | fe29785b8286b6d74318c0eaa6ae2bb5 | null | You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x, y) as the difference between maximum and minimum value of ai on a simple path connecting vertices x and y.Your task is to calculate . | Print one number equal to . | The first line contains one integer number n (1 ≤ n ≤ 106) — the number of vertices in the tree. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the numbers written on the vertices. Then n - 1 lines follow. Each line contains two integers x and y denoting an edge connecting vertex x and vert... | standard output | standard input | PyPy 2 | Python | 2,400 | train_077.jsonl | fb8172d92186c320ce8a43053757fb03 | 256 megabytes | ["4\n2 2 3 1\n1 2\n1 3\n1 4"] | PASSED | import sys
range = xrange
input = raw_input
# returns order such that A[order[i]] <= A[order[i + 1]]
def sqrtsorted(A, maxval = 10**6):
asqrt = int((maxval)**0.5 + 2)
blocks1 = [[] for _ in range(asqrt)]
blocks2 = [[] for _ in range(asqrt)]
for i in range(len(A)):
blocks1[A[i] % asqrt].append(i... | 1515848700 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["4", "15"] | f6cd855ceda6029fc7d14daf2c9bb7dc | NoteIn the first sample the sequence is being modified as follows: . It has 4 inversions formed by index pairs (1, 4), (2, 3), (2, 4) and (3, 4). | There is an infinite sequence consisting of all positive integers in the increasing order: p = {1, 2, 3, ...}. We performed n swap operations with this sequence. A swap(a, b) is an operation of swapping the elements of the sequence on positions a and b. Your task is to find the number of inversions in the resulting seq... | Print a single integer — the number of inversions in the resulting sequence. | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of swap operations applied to the sequence. Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 109, ai ≠ bi) — the arguments of the swap operation. | standard output | standard input | Python 2 | Python | 2,100 | train_018.jsonl | da026a653cedbfd25e981e854ae2253b | 256 megabytes | ["2\n4 2\n1 4", "3\n1 6\n3 4\n2 5"] | PASSED | from sys import stdin
from itertools import repeat
def main():
n = int(stdin.readline())
data = map(int, stdin.read().split(), repeat(10, 2 * n))
d = {}
for i in xrange(n):
a, b = data[i*2], data[i*2+1]
d[a], d[b] = d.get(b, b), d.get(a, a)
s = d.keys()
s.sort()
idx = {}
... | 1430411400 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
6 seconds | ["3\n4\n2\n4\n1"] | e93981ba508fec99c8ae3e8aa480dd52 | NoteConsider the example test case.The answer to the first query is $$$3$$$, as there are three suitable substrings: $$$s[3\dots6]$$$, $$$s[3\dots4]$$$ and $$$s[5\dots6]$$$.The answer to the second query is $$$4$$$. The substrings are $$$s[3\dots6]$$$, $$$s[3\dots4]$$$, $$$s[5\dots6]$$$ and $$$s[2\dots7]$$$.After the t... | This is the hard version of the problem. The only difference between the easy and the hard versions are removal queries, they are present only in the hard version."Interplanetary Software, Inc." together with "Robots of Cydonia, Ltd." has developed and released robot cats. These electronic pets can meow, catch mice and... | For each query, print a single integer in a separate line, the number of substrings that are simple RBS. The answers must be printed in the same order as the queries are specified in the input. | The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 3\cdot10^5$$$, $$$1 \le q \le 3\cdot10^5$$$), the length of the string, and the number of queries. The second line contains the string $$$s$$$, consisting of $$$n$$$ characters "(" and ")". Each of the following $$$q$$$ lines contains three intege... | standard output | standard input | PyPy 3 | Python | 2,800 | train_085.jsonl | a9b2b77cf19d54b922a79a6b22d43040 | 256 megabytes | ["9 8\n)(()())()\n2 3 6\n2 2 7\n1 3 4\n2 2 7\n2 2 9\n1 5 6\n1 2 7\n2 8 9"] | PASSED | ''' E2. Cats on the Upgrade (hard version)
https://codeforces.com/contest/1625/problem/E2
'''
import io, os, sys
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # decode().strip() if str
output = sys.stdout.write
DEBUG = os.environ.get('debug') not in [None, '0']
if DEBUG:
from inspect import curre... | 1641989100 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["0", "5554443330", "-1"] | b263917e47e1c84340bcb1c77999fd7e | NoteIn the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number. | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?You are given a set of digits, your task is to find the maximum integer that you can make ... | On a single line print the answer to the problem. If such number does not exist, then you should print -1. | A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space. | standard output | standard input | Python 3 | Python | 1,600 | train_013.jsonl | bcef56c06439c10a9f397b5b0d7dd437 | 256 megabytes | ["1\n0", "11\n3 4 5 4 5 3 5 3 4 4 0", "8\n3 2 5 1 5 2 2 3"] | PASSED | def ans():
global answered
global final
if(answered):
return
sum = 0
for i in final:
sum+=i
if(sum==0):
print(0)
answered = True
return
for i in final:
print(i,end="")
print()
answered = True
answered = False
N = int(input())
A = list(int(i) for i in input().split())
A.sort()
A.reverse()
f... | 1343662200 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["11\n0\n13\n60\n58"] | 9fcc55a137b5ff021fdc8e1e867ce856 | NoteIn the first test case, one possible strategy is as follows: Buy a good key for $$$5$$$ coins, and open chest $$$1$$$, receiving $$$10$$$ coins. Your current balance is $$$0 + 10 - 5 = 5$$$ coins. Buy a good key for $$$5$$$ coins, and open chest $$$2$$$, receiving $$$10$$$ coins. Your current balance is $$$5 + 1... | There are $$$n$$$ chests. The $$$i$$$-th chest contains $$$a_i$$$ coins. You need to open all $$$n$$$ chests in order from chest $$$1$$$ to chest $$$n$$$.There are two types of keys you can use to open a chest: a good key, which costs $$$k$$$ coins to use; a bad key, which does not cost any coins, but will halve all... | For each test case output a single integer — the maximum number of coins you can obtain after opening the chests in order from chest $$$1$$$ to chest $$$n$$$. Please note, that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language... | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$; $$$0 \leq k \leq 10^9$$$) — the number of chests and the cost of a good key respectively. The second line of each ... | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_086.jsonl | 7a3f8606cd2126032a9416cac5e3ef54 | 256 megabytes | ["5\n\n4 5\n\n10 10 3 1\n\n1 2\n\n1\n\n3 12\n\n10 10 29\n\n12 51\n\n5 74 89 45 18 69 67 67 11 96 23 59\n\n2 57\n\n85 60"] | PASSED | import sys
from array import array
input = lambda: sys.stdin.buffer.readline().decode().strip()
inp = lambda dtype: [dtype(x) for x in input().split()]
for _ in range(int(input())):
n, k = inp(int)
a = array('i', inp(int))
dp = [array('q', [-10 ** 18] * 30) for _ in range(2)]
dp[1][0] = 0
... | 1657636500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["? 1 3 2\n\n? 1 2 3\n\n! 2"] | e66101a49797b1e244dd9709dc21e657 | NoteThe tree in the example is as follows:The input and output for example illustrate possible interaction on that test (empty lines are inserted only for clarity).The hack corresponding to the example would look like:3 22 3 1 | The graph is called tree if it is connected and has no cycles. Suppose the tree is rooted at some vertex. Then tree is called to be perfect $$$k$$$-ary tree if each vertex is either a leaf (has no children) or has exactly $$$k$$$ children. Also, in perfect $$$k$$$-ary tree all leafs must have same depth.For example, th... | null | null | standard output | standard input | Python 3 | Python | 2,400 | train_023.jsonl | 8c0e7d24018a1ac63e2aa2cc3feaad96 | 256 megabytes | ["3 2\n\nNo\n\nYes"] | PASSED | from math import log
from random import randint
import sys
n, k = map(int, input().split())
lg = int(log(n, k)) * 2 + 1
have = set()
def find_diam():
a = randint(1, n)
b = randint(a, n)
#print('New')
if (a == b) or (a, b) in have:
return []
have.add((a, b))
cnt = 2
was = [a, b]
for i in range(1, n + 1):
if... | 1542901500 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
2 seconds | ["3\n2\n1\n1\n1\n5\n1\n1\n3\n3"] | ca817fe0a97e2d8a6bcfcb00103b6b6d | Note In the first test case, $$$s$$$="bxyaxzay", $$$k=2$$$. We use indices in the string from $$$1$$$ to $$$8$$$. The following coloring will work: $$$\mathtt{\mathbf{\color{red}{b}\color{blue}{xy}\color{red}{a}\color{blue}{x}z\color{red}{a}\color{blue}{y}}}$$$ (the letter z remained uncolored). After painting: swap t... | You have a string $$$s$$$ consisting of lowercase Latin alphabet letters. You can color some letters in colors from $$$1$$$ to $$$k$$$. It is not necessary to paint all the letters. But for each color, there must be a letter painted in that color.Then you can swap any two symbols painted in the same color as many times... | For each set of input data, output a single integer — the maximum length of the shortest palindrome string that can be obtained. | The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of input data sets in the test. The descriptions of the input data sets follow. The first line of the description of each input data set contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) ... | standard output | standard input | Python 3 | Python | 1,400 | train_102.jsonl | ad6619e0a1d9b2b8e2ba1cdd91cb4561 | 256 megabytes | ["10\n\n8 2\n\nbxyaxzay\n\n6 3\n\naaaaaa\n\n6 1\n\nabcdef\n\n6 6\n\nabcdef\n\n3 2\n\ndxd\n\n11 2\n\nabcabcabcac\n\n6 6\n\nsipkic\n\n7 2\n\neatoohd\n\n3 1\n\nllw\n\n6 2\n\nbfvfbv"] | PASSED | for t in range(int(input())):
n, k = map(int, input().split())
s = input()
d = dict()
for i in s:
if i in d:
d[i] += 1
else:
d[i] = 1
counter_2 = 0
for i in d:
counter_2 += d[i]//2
ans = (counter_2//k)*2 ... | 1641825300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["2 1\n4 3\n2 2"] | 601853dd471f5dc7f72fa42bfcf0c858 | null | There is a rectangular grid of size $$$n \times m$$$. Each cell of the grid is colored black ('0') or white ('1'). The color of the cell $$$(i, j)$$$ is $$$c_{i, j}$$$. You are also given a map of directions: for each cell, there is a direction $$$s_{i, j}$$$ which is one of the four characters 'U', 'R', 'D' and 'L'. ... | For each test case, print two integers — the maximum number of robots you can place to satisfy all the conditions described in the problem statement and the maximum number of black cells occupied by robots before all movements if the number of robots placed is maximized. Note that you can place robots only before all m... | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 < nm \le 10^6$$$) — the number of rows and the number of columns correspondingly. The n... | standard output | standard input | PyPy 3 | Python | 2,200 | train_006.jsonl | 5433dcd5ae14bf9cf19f831ff5d477dd | 256 megabytes | ["3\n1 2\n01\nRL\n3 3\n001\n101\n110\nRLL\nDLD\nULL\n3 3\n000\n000\n000\nRRD\nRLD\nULL"] | PASSED | from sys import stdin, gettrace
if not gettrace():
def input():
return next(stdin)[:-1]
# def input():
# return stdin.buffer.readline()
def main():
def solve():
n,m = map(int, input().split())
colour = []
for _ in range(n):
colour.append(input())
dir = ... | 1586788500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["1 2 3\n2 1\n2 1 3\n-1\n1\n3 2 1 4"] | 667c5af27db369257039d0832258600d | NoteIn the first test case for permutation $$$p = [1, 2, 3]$$$ Vasya should write $$$next = [2, 3, 4]$$$, because each number in permutation is less than next. It's easy to see, that it is the only satisfying permutation.In the third test case, any permutation can be the answer because all numbers $$$next_i$$$ are lost... | Vasya has written some permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, so for all $$$1 \leq i \leq n$$$ it is true that $$$1 \leq p_i \leq n$$$ and all $$$p_1, p_2, \ldots, p_n$$$ are different. After that he wrote $$$n$$$ numbers $$$next_1, next_2, \ldots, next_n$$$. The number $$$next_i$$... | Print $$$T$$$ lines, in $$$i$$$-th of them answer to the $$$i$$$-th test case. If there is no such permutations $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, that Vasya could write, print the only number $$$-1$$$. In the other case print $$$n$$$ different integers $$$p_1, p_2, \ldots, p_n$$$, separat... | The first line contains one integer $$$t$$$ — the number of test cases ($$$1 \leq t \leq 100\,000$$$). Next $$$2 \cdot t$$$ lines contains the description of test cases,two lines for each. The first line contains one integer $$$n$$$ — the length of the permutation, written by Vasya ($$$1 \leq n \leq 500\,000$$$). The s... | standard output | standard input | PyPy 2 | Python | 2,100 | train_019.jsonl | c613dad11d5b1e8baf36061434b5232b | 256 megabytes | ["6\n3\n2 3 4\n2\n3 3\n3\n-1 -1 -1\n3\n3 4 -1\n1\n2\n4\n4 -1 4 5"] | PASSED | import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
t=int(input())
for u in xrange(t):
n=int(input())
a=list... | 1557671700 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
2 seconds | ["3\n1 5 4", "-1"] | 9f13d3d0266b46e4201ea6a2378d1b71 | NoteConsider the examples above.In the first example, the group of spiders is illustrated on the picture below: We choose the two-legged, the ten-legged and the $$$16$$$-legged spiders. It's not hard to see that each pair may weave a web with enough durability, as $$$2 \oplus 10 = 8 \ge 8$$$, $$$2 \oplus 16 = 18 \ge 8... | Binary Spiders are species of spiders that live on Mars. These spiders weave their webs to defend themselves from enemies.To weave a web, spiders join in pairs. If the first spider in pair has $$$x$$$ legs, and the second spider has $$$y$$$ legs, then they weave a web with durability $$$x \oplus y$$$. Here, $$$\oplus$$... | In the first line, print a single integer $$$\ell$$$ ($$$2 \le \ell \le n$$$), the maximum possible amount of defenders. In the second line, print $$$\ell$$$ integers $$$b_i$$$, separated by a single space ($$$1 \le b_i \le n$$$) — indices of spiders that will become defenders. If there exists more than one way to choo... | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 3\cdot10^5$$$, $$$0 \le k \le 2^{30} - 1$$$), the amount of spiders in the group and the minimal allowed durability of a web. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$0 \le a_i \le 2^{30}-1$$$) — the number of legs the $$$i$$$-th sp... | standard output | standard input | PyPy 3-64 | Python | 2,300 | train_085.jsonl | a81fe9e0c138b0bd7a50f1db754766ac | 256 megabytes | ["6 8\n2 8 4 16 10 14", "6 1024\n1 2 3 1 4 0"] | PASSED | import sys
import os
from io import BytesIO, IOBase
from _collections import defaultdict
from random import randrange
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writ... | 1641989100 | [
"math",
"trees"
] | [
0,
0,
0,
1,
0,
0,
0,
1
] | |
6 seconds | ["4"] | 507e3e805e91a91e5130f53588e62dab | NoteAfter the trap is set, the new energy requirement for the first Corridor may be either smaller, larger, or equal to the old energy requiremenet.In the example, if the energy of the first Corridor is set to $$$4$$$ or less, then the Daleks may use the set of Corridors $$$\{ \{ 1,2 \}, \{ 2,3 \} \}$$$ (in particular,... | Heidi found out that the Daleks have created a network of bidirectional Time Corridors connecting different destinations (at different times!). She suspects that they are planning another invasion on the entire Space and Time. In order to counter the invasion, she plans to deploy a trap in the Time Vortex, along a care... | Output a single integer: $$$E_{max}(c_1)$$$ for the first Corridor $$$c_1$$$ from the input. | The first line contains integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 10^5$$$, $$$n - 1 \leq m \leq 10^6$$$), number of destinations to be invaded and the number of Time Corridors. Each of the next $$$m$$$ lines describes a Corridor: destinations $$$a$$$, $$$b$$$ and energy $$$e$$$ ($$$1 \leq a, b \leq n$$$, $$$a \neq... | standard output | standard input | Python 2 | Python | 1,900 | train_026.jsonl | 3dcbeb2f45226a36dd152e22fb99488c | 128 megabytes | ["3 3\n1 2 8\n2 3 3\n3 1 4"] | PASSED | from __future__ import division, print_function
def main():
class DSU:
def __init__ (self,n):
self.parent=list(range(n))
self.size=[1]*n
self.count_sets=n
def find(self,u):
to_update=[]
while u!=self.parent[u]:
to_update.app... | 1562483100 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["4", "2"] | 2ed58a84bd705e416cd25f139f904d68 | NoteIn the first sample, you can obtain a nested sequence of $$$4$$$ rubber bands($$$1$$$, $$$2$$$, $$$5$$$, and $$$6$$$) by the conversion shown below. Of course, there are other conversions exist to make a nested sequence of $$$4$$$ rubber bands. However, you cannot make sequence of $$$5$$$ or more nested rubber band... | You have a tree of $$$n$$$ vertices. You are going to convert this tree into $$$n$$$ rubber bands on infinitely large plane. Conversion rule follows: For every pair of vertices $$$a$$$ and $$$b$$$, rubber bands $$$a$$$ and $$$b$$$ should intersect if and only if there is an edge exists between $$$a$$$ and $$$b$$$ in t... | Print the answer. | The first line contains integer $$$n$$$ ($$$3 \le n \le 10^{5}$$$) — the number of vertices in tree. The $$$i$$$-th of the next $$$n-1$$$ lines contains two integers $$$a_{i}$$$ and $$$b_{i}$$$ ($$$1 \le a_{i} \lt b_{i} \le n$$$) — it means there is an edge between $$$a_{i}$$$ and $$$b_{i}$$$. It is guaranteed that giv... | standard output | standard input | PyPy 2 | Python | 2,700 | train_019.jsonl | bc4e721e99e76e8d11f3c5c29816f7ae | 256 megabytes | ["6\n1 3\n2 3\n3 4\n4 5\n4 6", "4\n1 2\n2 3\n3 4"] | PASSED | FAST_IO = 1
if FAST_IO:
import io, sys, atexit
rr = iter(sys.stdin.read().splitlines()).next
sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().s... | 1586700300 | [
"math",
"trees"
] | [
0,
0,
0,
1,
0,
0,
0,
1
] | |
1 second | ["YES\n11640\n1024", "YES\n2842545891539\n28171911281811000", "NO"] | 695418026140545863313f5f3cc1bf00 | null | Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long intege... | In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines — the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part mu... | The first line of the input contains the public key of the messenger — an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 ≤ a, b ≤ 108). | standard output | standard input | Python 2 | Python | 1,700 | train_002.jsonl | e7307ec36730a59a230d6c52b843010c | 256 megabytes | ["116401024\n97 1024", "284254589153928171911281811000\n1009 1000", "120\n12 1"] | PASSED | from sys import stdin, stdout
def main_mine():
key = stdin.readline().strip()
a, b = map(int, stdin.readline().split())
l = len(key)
n = map(int, key)
div_b = []
div = 0
mod10 = 1
for d in reversed(n):
div = (div + d * mod10) % b
mod10 = 10 * mod10 % b
div_... | 1416733800 | [
"number theory",
"math",
"strings"
] | [
0,
0,
0,
1,
1,
0,
1,
0
] | |
1 second | ["6", "2", "120"] | dbc9b7ff6f495fe72a747d79006488c3 | NoteIn the first example, $$$[1, 2, 3]$$$ is a valid permutation as we can consider the index with value $$$3$$$ as the source and index with value $$$1$$$ as the sink. Thus, after conversion we get a beautiful array $$$[2, 2, 2]$$$, and the total cost would be $$$2$$$. We can show that this is the only transformation ... | An array is called beautiful if all the elements in the array are equal.You can transform an array using the following steps any number of times: Choose two indices $$$i$$$ and $$$j$$$ ($$$1 \leq i,j \leq n$$$), and an integer $$$x$$$ ($$$1 \leq x \leq a_i$$$). Let $$$i$$$ be the source index and $$$j$$$ be the sink ... | Output a single integer — the number of balanced permutations modulo $$$10^9+7$$$. | The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the size of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). | standard output | standard input | PyPy 3-64 | Python | 2,300 | train_088.jsonl | af5d509b026485193816964ca9791ba9 | 256 megabytes | ["3\n1 2 3", "4\n0 4 0 4", "5\n0 11 12 13 14"] | PASSED | from operator import mod
import os,sys
from random import randint, shuffle
from io import BytesIO, IOBase
from collections import defaultdict,deque,Counter
from bisect import bisect_left,bisect_right
from heapq import heappush,heappop
from functools import lru_cache
from itertools import accumulate, permutati... | 1618151700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2\n2 3", "1\n1"] | 5ec62d1ab7bd3b14ec3f1508ca327134 | NoteIn the first test case there is no guest who is friend of all other guests, so at least two steps are required to perform the task. After second guest pairwise introduces all his friends, only pairs of guests (4, 1) and (4, 2) are not friends. Guest 3 or 5 can introduce them.In the second test case guest number 1 i... | Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure.At each step he selects o... | In the first line print the minimum number of steps required to make all pairs of guests friends. In the second line print the ids of guests, who are selected at each step. If there are multiple solutions, you can output any of them. | The first line contains two integers n and m (1 ≤ n ≤ 22; ) — the number of guests at the party (including Arseny) and the number of pairs of people which are friends. Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n; u ≠ v), which means that people with numbers u and v are friends initially. It's g... | standard output | standard input | PyPy 3 | Python | 2,400 | train_027.jsonl | c0f811ea6bb1db4648e6cf9d8c2d24d6 | 256 megabytes | ["5 6\n1 2\n1 3\n2 3\n2 5\n3 4\n4 5", "4 4\n1 2\n1 3\n1 4\n3 4"] | PASSED | from collections import defaultdict
def count(x):
c=0
while x > 0:
c+=1
x &= (x-1)
return c
n,m=map(int,input().split())
g=defaultdict(list)
for _ in range(m):
u, v = map(int,input().split())
u-=1;v-=1
g[u].append(v)
g[v].append(u)
mask1=0;mask2=0;MAX=(1<<n)-1
a=[0]*(1 << n... | 1514037900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["4\n3\n0\n8"] | 2b611e202c931d50d8a260b2b45d4cd7 | NoteIn the first example, the correct pairs are: ($$$1, 4$$$), ($$$4,1$$$), ($$$3, 6$$$), ($$$6, 3$$$).In the second example, the correct pairs are: ($$$1, 2$$$), ($$$2, 1$$$), ($$$3, 3$$$). | You are given three positive (greater than zero) integers $$$c$$$, $$$d$$$ and $$$x$$$. You have to find the number of pairs of positive integers $$$(a, b)$$$ such that equality $$$c \cdot lcm(a, b) - d \cdot gcd(a, b) = x$$$ holds. Where $$$lcm(a, b)$$$ is the least common multiple of $$$a$$$ and $$$b$$$ and $$$gcd(a,... | For each test case, print one integer — the number of pairs ($$$a, b$$$) such that the above equality holds. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing three integer $$$c$$$, $$$d$$$ and $$$x$$$ ($$$1 \le c, d, x \le 10^7$$$). | standard output | standard input | PyPy 3-64 | Python | 2,100 | train_104.jsonl | a8f61ce25f495e816fe420d0ffc5ee21 | 512 megabytes | ["4\n1 1 3\n4 2 6\n3 3 7\n2 7 25"] | PASSED | import sys
input = lambda: sys.stdin.readline().rstrip()
MAX = 2*(10**7) + 1
memo = {}
def get_divisors(x: int) -> list:
if x in memo:
return memo[x]
factori = []
while x > 1:
factori.append(min_fact[x])
x //= min_fact[x]
now = [1]
factori.sort()
for p in factori:
... | 1616079000 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
3 seconds | ["2\n0\n1", "0\n0\n2\n0\n0\n2\n1\n0\n1\n1"] | a3e89153f98c139d7e84f2307b128b24 | NoteThe following is an explanation of the first example. The graph in the first example. Here is one possible walk for the first query:$$$$$$1 \overset{5}{\rightarrow} 3 \overset{3}{\rightarrow} 2 \overset{1}{\rightarrow} 1 \overset{5}{\rightarrow} 3 \overset{1}{\rightarrow} 4 \overset{2}{\rightarrow} 5.$$$$$$The a... | There is an undirected, connected graph with $$$n$$$ vertices and $$$m$$$ weighted edges. A walk from vertex $$$u$$$ to vertex $$$v$$$ is defined as a sequence of vertices $$$p_1,p_2,\ldots,p_k$$$ (which are not necessarily distinct) starting with $$$u$$$ and ending with $$$v$$$, such that $$$p_i$$$ and $$$p_{i+1}$$$ a... | For each query, print one line containing a single integer — the answer to the query. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 10^5$$$; $$$n-1 \leq m \leq \min{\left(\frac{n(n-1)}{2},10^5\right)}$$$). Each of the next $$$m$$$ lines contains three integers $$$a$$$, $$$b$$$, and $$$w$$$ ($$$1 \leq a, b \leq n$$$, $$$a \neq b$$$; $$$0 \leq w < 2^{30}$$$) indicating an u... | standard output | standard input | PyPy 3-64 | Python | 2,200 | train_110.jsonl | 2dc6d518f26630ddb8c7a847b998cd3c | 256 megabytes | ["6 7\n1 2 1\n2 3 3\n3 1 5\n4 5 2\n5 6 4\n6 4 6\n3 4 1\n3\n1 5\n1 2\n5 3", "9 8\n1 2 5\n2 3 11\n3 4 10\n3 5 10\n5 6 2\n5 7 1\n7 8 5\n7 9 5\n10\n5 7\n2 5\n7 1\n6 4\n5 2\n7 6\n4 1\n6 2\n4 7\n2 8"] | PASSED | import sys
import os
from io import BytesIO, IOBase
# region fastio
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 ... | 1650206100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["Matching\n2\nIndSet\n1\nIndSet\n2 4\nMatching\n1 15"] | 0cca30daffe672caa6a6fdbb6a935f43 | NoteThe first two graphs are same, and there are both a matching of size 1 and an independent set of size 1. Any of these matchings and independent sets is a correct answer.The third graph does not have a matching of size 2, however, there is an independent set of size 2. Moreover, there is an independent set of size 5... | You are given a graph with $$$3 \cdot n$$$ vertices and $$$m$$$ edges. You are to find a matching of $$$n$$$ edges, or an independent set of $$$n$$$ vertices.A set of edges is called a matching if no two edges share an endpoint.A set of vertices is called an independent set if no two vertices are connected with an edge... | Print your answer for each of the $$$T$$$ graphs. Output your answer for a single graph in the following format. If you found a matching of size $$$n$$$, on the first line print "Matching" (without quotes), and on the second line print $$$n$$$ integers — the indices of the edges in the matching. The edges are numbered ... | The first line contains a single integer $$$T \ge 1$$$ — the number of graphs you need to process. The description of $$$T$$$ graphs follows. The first line of description of a single graph contains two integers $$$n$$$ and $$$m$$$, where $$$3 \cdot n$$$ is the number of vertices, and $$$m$$$ is the number of edges in ... | standard output | standard input | PyPy 3 | Python | 2,000 | train_006.jsonl | 8980f99302324d7e031f5fd5b9e94516 | 256 megabytes | ["4\n1 2\n1 3\n1 2\n1 2\n1 3\n1 2\n2 5\n1 2\n3 1\n1 4\n5 1\n1 6\n2 15\n1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6\n5 6"] | PASSED | import sys
input = sys.stdin.readline
def main():
tes = int(input())
for testcase in [0]*tes:
n,m = map(int,input().split())
new = [True]*(3*n)
res = []
for i in range(1,m+1):
u,v = map(int,input().split())
if new[u-1] and new[v-1]:
if le... | 1564497300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
3 seconds | ["36\n6"] | 6b7a083225f0dd895cc48ca68af695f4 | NoteIn the second testcase of the example there are six y-factorizations: { - 4, - 1}; { - 2, - 2}; { - 1, - 4}; {1, 4}; {2, 2}; {4, 1}. | You are given two positive integer numbers x and y. An array F is called an y-factorization of x iff the following conditions are met: There are y elements in F, and all of them are integer numbers; . You have to count the number of pairwise distinct arrays that are y-factorizations of x. Two arrays A and B are consi... | Print q integers. i-th integer has to be equal to the number of yi-factorizations of xi modulo 109 + 7. | The first line contains one integer q (1 ≤ q ≤ 105) — the number of testcases to solve. Then q lines follow, each containing two integers xi and yi (1 ≤ xi, yi ≤ 106). Each of these lines represents a testcase. | standard output | standard input | Python 3 | Python | 2,000 | train_075.jsonl | fc4e4b92a16a26e9eca55156a8ec3150 | 256 megabytes | ["2\n6 3\n4 2"] | PASSED | from array import array
md = 10 ** 9 + 7
def fact_all(N):
lp = array('Q', [2]*(N+1))
pr = array('Q', [2])
pra = pr.append
for i in range(3, N+1, 2):
if lp[i] == 2:
lp[i] = i
pra(i)
for p in pr:
ip = i * p
if p > lp[i] or ip > N:
... | 1511449500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["0.0000000000", "0.0740740741"] | 9d55b98c75e703a554051d3088a68e59 | NoteIn the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total.In the second case, each game could've had three outcomes — 10 - 2, 1... | Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to t... | Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. ... | The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar. The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number. | standard output | standard input | PyPy 2 | Python | 1,800 | train_044.jsonl | eb36cec500c3d2faf9c1abf8877b4b2b | 256 megabytes | ["2\n1 2", "3\n1 2 10"] | PASSED | n , m = input() , map(int,raw_input().split())
a = {}
for i in xrange(n-1):
for j in xrange(i+1,n):
x = abs(m[i]-m[j])
if x in a:
a[x]+=1
else:
a[x]=1
d = [i for i in a]
b = [0]*10005
for i in xrange(len(d)):
for j in xrange(i,len(d)):
if d[i]==d[j]:
b[d[i]+d[j]] += a[d[i]]*a[d[j]]
else:
b[d[i... | 1455384900 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
1 second | ["Yes", "No", "Yes"] | cf7bf89a6038586b69d3b8021cee0b27 | NoteIn the first example the second point can be removed.In the second example there is no suitable for the condition point.In the third example any point can be removed. | You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis. | Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower). | The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide. | standard output | standard input | PyPy 3 | Python | 800 | train_001.jsonl | 61fc6ea722848cad301ddb85324a964c | 256 megabytes | ["3\n1 1\n-1 -1\n2 -1", "4\n1 1\n2 2\n-1 1\n-2 2", "3\n1 2\n2 1\n4 60"] | PASSED | n=int(input())
countl=0
countr=0
for _ in range(n):
a,b=map(int,input().split())
if a<0:
countl+=1
else:
countr+=1
if min(countl,countr)<=1:
print("Yes")
else:
print("No") | 1513008300 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
3 seconds | ["1\n3 \n-1\n0\n\n2\n1 2"] | 128fb67bf707590cb1b60bceeb7ce598 | null | Polycarp has $$$n$$$ different binary words. A word called binary if it contains only characters '0' and '1'. For example, these words are binary: "0001", "11", "0" and "0011100".Polycarp wants to offer his set of $$$n$$$ binary words to play a game "words". In this game, players name words and each next word (starting... | Print answer for all of $$$t$$$ test cases in the order they appear. If there is no answer for the test case, print -1. Otherwise, the first line of the output should contain $$$k$$$ ($$$0 \le k \le n$$$) — the minimal number of words in the set which should be reversed. The second line of the output should contain $$$... | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. The first line of a test case contains one integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — the number of words in the Polycarp's set. Next $$$n$$$ lines contain the... | standard output | standard input | PyPy 3 | Python | 1,900 | train_012.jsonl | 2154823c2da2f45b62b1e588ff11f789 | 256 megabytes | ["4\n4\n0001\n1000\n0011\n0111\n3\n010\n101\n0\n2\n00000\n00001\n4\n01\n001\n0001\n00001"] | PASSED | k = int(input())
for i in range(k):
is_t = set()
a = dict()
a['00'] = []
a['11'] = []
a['01'] = []
a['10'] = []
n = int(input())
s = []
for i in range(n):
b = input()
a[b[0] + b[-1]].append(i)
s.append(b)
is_t.add(b)
c = len(a['10'])
d = le... | 1576321500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["NO\nYES\nYES\nNO\nYES\nYES"] | 73a077e8e715c72e37cf10fca281d3e2 | NoteThe state of conveyor with $$$t = 0$$$. Red arrow represents the direction of each belt, and blue figure represents slime.The state of conveyor with $$$t = 1$$$.The state of conveyor with $$$t = 2$$$. | There is a conveyor with $$$120$$$ rows and $$$120$$$ columns. Each row and column is numbered from $$$0$$$ to $$$119$$$, and the cell in $$$i$$$-th row and $$$j$$$-th column is denoted as $$$(i, j)$$$. The top leftmost cell is $$$(0, 0)$$$. Each cell has a belt, and all belts are initially facing to the right.Initiall... | Print the answer for each test case, one per line. If there is a slime ball in the cell $$$(x, y)$$$ after $$$t$$$ seconds from the initial state, print "YES". Otherwise, print "NO". | The first line contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. The only line of each query contains three integers $$$t$$$, $$$x$$$, and $$$y$$$ ($$$0 \le t \le 10^{18}$$$, $$$0 \le x, y < 120$$$). | standard output | standard input | PyPy 3-64 | Python | 2,700 | train_104.jsonl | 495a0ecff1011b3894b7934093b1e3ea | 256 megabytes | ["6\n\n1 1 0\n\n5 1 3\n\n0 0 0\n\n2 4 5\n\n2 0 2\n\n1547748756 100 111"] | PASSED | #from math import ceil, floor #, gcd, log, factorial, comb, perm,
#log10, log2, log, sin, asin, tan, atan, radians
#from heapq import heappop,heappush,heapify #heappop(hq), heapify(list)
#from collections import defaultdict as dd
#mydd=dd(list) for .append
#from collections import deque as dq #deque e.g. myqueue=... | 1663598100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["YES\nYES\nYES\nYES\nYES\nYES\nNO\nYES", "YES\nYES\nYES\nYES\nYES\nNO\nYES\nNO"] | 0cc9671ff72e44bd5921cc0e46ada36c | NoteIn the first example, after the 6th evolution the religion descriptions are: ad, bc, and ab. The following figure shows how these descriptions form three disjoint subsequences of the Word of Universe: | During the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution of each of these beliefs, and you now wonder if the followers of each religion could coexist in peace.The Word of Unive... | Write $$$q$$$ lines. The $$$i$$$-th of them should be YES if the religions could coexist in peace after the $$$i$$$-th evolution, or NO otherwise. You can print each character in any case (either upper or lower). | The first line of the input contains two integers $$$n, q$$$ ($$$1 \leq n \leq 100\,000$$$, $$$1 \leq q \leq 1000$$$) — the length of the Word of Universe and the number of religion evolutions, respectively. The following line contains the Word of Universe — a string of length $$$n$$$ consisting of lowercase English ch... | standard output | standard input | PyPy 3 | Python | 2,200 | train_026.jsonl | 342c6c4cfe6f53639c9998131d3aaa6a | 256 megabytes | ["6 8\nabdabc\n+ 1 a\n+ 1 d\n+ 2 b\n+ 2 c\n+ 3 a\n+ 3 b\n+ 1 c\n- 2", "6 8\nabbaab\n+ 1 a\n+ 2 a\n+ 3 a\n+ 1 b\n+ 2 b\n+ 3 b\n- 1\n+ 2 z"] | PASSED | import sys
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
n, q = map(int, input().split())
s = '!' + input()
nxt = [[n + 1] * (n + 2) for _ in range(26)]
for i in range(n - 1, -1, -1):
c = ord(s[i + 1]) - 97
for j in range(26):
nxt[j][i] = nxt[j][i + 1]
nxt[c][i] = i + 1
w... | 1556548500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["2\n6"] | 787a45f427c2db98b2ddb78925e0e0f1 | NoteIn the first test case, Phoenix has two coins with weights $$$2$$$ and $$$4$$$. No matter how he divides the coins, the difference will be $$$4-2=2$$$.In the second test case, Phoenix has four coins of weight $$$2$$$, $$$4$$$, $$$8$$$, and $$$16$$$. It is optimal for Phoenix to place coins with weights $$$2$$$ and ... | Phoenix has $$$n$$$ coins with weights $$$2^1, 2^2, \dots, 2^n$$$. He knows that $$$n$$$ is even.He wants to split the coins into two piles such that each pile has exactly $$$\frac{n}{2}$$$ coins and the difference of weights between the two piles is minimized. Formally, let $$$a$$$ denote the sum of weights in the fir... | For each test case, output one integer — the minimum possible difference of weights between the two piles. | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 30$$$; $$$n$$$ is even) — the number of coins that Phoenix has. | standard output | standard input | Python 3 | Python | 800 | train_002.jsonl | 7d3dee2a0554a46c4963daeaf61c361e | 256 megabytes | ["2\n2\n4"] | PASSED | no=int(input())
j=[]
for r in range(no):
weights=[]
n=int(input())
for each in range(1,n+ 1):
weights.append(pow(2,each))
ans=sum(weights[:n//2])
j.append(ans)
for r in j:
print(r)
| 1588343700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["26730", "1115598", "11", "265359409"] | 6e093dbcbcaa7c87c9b62546745984db | null | This problem differs from the next one only in the presence of the constraint on the equal length of all numbers $$$a_1, a_2, \dots, a_n$$$. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too.A team of SIS students is going to make a trip on a subm... | Print the answer modulo $$$998\,244\,353$$$. | The first line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 100\,000$$$) — the number of elements in the array. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. All numbers $$$a_1, a_2, \dots, a_n$$$ are of equal ... | standard output | standard input | Python 3 | Python | 1,500 | train_005.jsonl | 720d3b34a94690518bc5def3f7d1925f | 256 megabytes | ["3\n12 33 45", "2\n123 456", "1\n1", "5\n1000000000 1000000000 1000000000 1000000000 1000000000"] | PASSED | def main():
n = int(input())
a = [int(i) for i in input().split()]
size = len(str(a[0]))
ans = 0; MOD = 998244353
ten = [1]
for i in range(1, 21): ten.append(ten[-1] * 10)
for i in range(n):
for j in range(size):
ans += int(str(a[i])[j]) * ten[2 * size - 2 * j - 1] * n
ans += int(str(a[i])[j]) * ten[2 * ... | 1563374100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
4 seconds | ["32"] | 08b8dbb6e167db69dc965e8ad4835808 | NoteIn the sample testcase, one optimum solution is to prepare the first problem on day 1 and print it on day 1, prepare the second problem on day 2 and print it on day 4, prepare the third problem on day 3 and print it on day 5, and prepare the fourth problem on day 6 and print it on day 8. | The marmots need to prepare k problems for HC2 over n days. Each problem, once prepared, also has to be printed.The preparation of a problem on day i (at most one per day) costs ai CHF, and the printing of a problem on day i (also at most one per day) costs bi CHF. Of course, a problem cannot be printed before it has b... | Output the minimum cost of preparation and printing k problems — that is, the minimum possible sum ai1 + ai2 + ... + aik + bj1 + bj2 + ... + bjk, where 1 ≤ i1 < i2 < ... < ik ≤ n, 1 ≤ j1 < j2 < ... < jk ≤ n and i1 ≤ j1, i2 ≤ j2, ..., ik ≤ jk. | The first line of input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an () — the preparation costs. The third line contains n space-separated integers b1, ..., bn () — the printing costs. | standard output | standard input | PyPy 3 | Python | 2,400 | train_001.jsonl | 310dc096081dd15a9e2b17c39a3d1557 | 256 megabytes | ["8 4\n3 8 7 9 9 4 6 8\n2 5 9 4 3 8 9 1"] | PASSED | from collections import deque
from heapq import heappop, heappush
class Edge(object):
__slots__ = ('x', 'y', 'cap', 'cost', 'inv')
def __repr__(self):
return '{e.x}-->{e.y} ({e.cap} , {e.cost})'.format(e=self)
class MCFP(list):
def add(G, x, y, cap, cost):
n = max(x, y) + 1
while ... | 1495958700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["YES\nNO\nNO\nNO\nYES", "NO\nNO\nYES"] | ac8519dfce1b3b1fafc02820563a2dbd | NoteExplanation of the test from the condition: Initially $$$A=[2,2,1]$$$, $$$B=[0,0,0]$$$. After operation "A 1 3": $$$A=[0,0,0]$$$, $$$B=[0,0,0]$$$ (addition is modulo 3). After operation "A 1 3": $$$A=[1,1,2]$$$, $$$B=[0,0,0]$$$. After operation "B 1 1": $$$A=[1,1,2]$$$, $$$B=[1,0,0]$$$. After operation "B 2 2": $$$... | One of my most productive days was throwing away 1,000 lines of code.— Ken ThompsonFibonacci addition is an operation on an array $$$X$$$ of integers, parametrized by indices $$$l$$$ and $$$r$$$. Fibonacci addition increases $$$X_l$$$ by $$$F_1$$$, increases $$$X_{l + 1}$$$ by $$$F_2$$$, and so on up to $$$X_r$$$ which... | After each operation, print "YES" (without quotes) if the arrays are equal and "NO" otherwise. Letter case does not matter. | The first line contains 3 numbers $$$n$$$, $$$q$$$ and $$$MOD$$$ ($$$1 \le n, q \le 3\cdot 10^5, 1 \le MOD \le 10^9+7$$$) — the length of the arrays, the number of operations, and the number modulo which all operations are performed. The second line contains $$$n$$$ numbers — array $$$A$$$ ($$$0 \le A_i < MOD$$$). T... | standard output | standard input | PyPy 3-64 | Python | 2,700 | train_107.jsonl | 0dc4ee3a39acbca3dbdcc3bf2b7fbd08 | 256 megabytes | ["3 5 3\n2 2 1\n0 0 0\nA 1 3\nA 1 3\nB 1 1\nB 2 2\nA 3 3", "5 3 10\n2 5 0 3 5\n3 5 8 2 5\nB 2 3\nB 3 4\nA 1 2"] | PASSED | # import sys
# I = lambda: [*map(int, sys.stdin.readline().split())]
import io,os
read = io.BytesIO(os.read(0, os.fstat(0).st_size))
I = lambda: read.readline().split()
n, q, M = map(int, I())
F = [1, 1]
period = None
for i in range(n - 1):
F.append((F[-1] + F[-2]) % M)
A = [*map(int, I())]
B = [*map(... | 1644158100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["138.23007676", "289.02652413"] | 56a13208f0a9b2fad23756f39acd64af | NoteThe first sample corresponds to the illustrations in the legend. | The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it?The discotheque can be seen as an infinite xy-plane, in which there are a total of n dancers. Once someone starts moving around, they will move only inside their own movement range, which is ... | Output one decimal number — the largest achievable sum of spaciousness over two halves of the night. The output is considered correct if it has a relative or absolute error of at most 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if . | The first line of input contains a positive integer n (1 ≤ n ≤ 1 000) — the number of dancers. The following n lines each describes a dancer: the i-th line among them contains three space-separated integers xi, yi and ri ( - 106 ≤ xi, yi ≤ 106, 1 ≤ ri ≤ 106), describing a circular movement range centered at (xi, yi) wi... | standard output | standard input | Python 3 | Python | 2,000 | train_045.jsonl | 7d44e8f59c58fe1cfbef6f9ddda3c967 | 256 megabytes | ["5\n2 1 6\n0 4 1\n2 -1 3\n1 -2 1\n4 -1 1", "8\n0 0 1\n0 0 2\n0 0 3\n0 0 4\n0 0 5\n0 0 6\n0 0 7\n0 0 8"] | PASSED |
import math
class circ:
def __init__(self, x, y, r):
self.x = x*1.0
self.y = y*1.0
self.r = r*1.0
n = 0
n = int(input())
vec = []
for i in range(n):
st = input().split(' ')
a = int(st[0])
b = int(st[1])
c = int(st[2])
vec.append(circ(a,b,c))
gr = [[] for i in range(n)]
pad = [-1 for i in range(n)]
vis =... | 1496837700 | [
"geometry",
"trees"
] | [
0,
1,
0,
0,
0,
0,
0,
1
] | |
0.5 seconds | ["6", "10"] | 43a65d1cfe59931991b6aefae1ecd10e | NoteIn the first example, the $$$[l, r]$$$ pairs corresponding to even substrings are: $$$s[1 \dots 2]$$$ $$$s[2 \dots 2]$$$ $$$s[1 \dots 4]$$$ $$$s[2 \dots 4]$$$ $$$s[3 \dots 4]$$$ $$$s[4 \dots 4]$$$ In the second example, all $$$10$$$ substrings of $$$s$$$ are even substrings. Note, that while substrings $$$s[1 \do... | You are given a string $$$s=s_1s_2\dots s_n$$$ of length $$$n$$$, which only contains digits $$$1$$$, $$$2$$$, ..., $$$9$$$.A substring $$$s[l \dots r]$$$ of $$$s$$$ is a string $$$s_l s_{l + 1} s_{l + 2} \ldots s_r$$$. A substring $$$s[l \dots r]$$$ of $$$s$$$ is called even if the number represented by it is even. Fi... | Print the number of even substrings of $$$s$$$. | The first line contains an integer $$$n$$$ ($$$1 \le n \le 65000$$$) — the length of the string $$$s$$$. The second line contains a string $$$s$$$ of length $$$n$$$. The string $$$s$$$ consists only of digits $$$1$$$, $$$2$$$, ..., $$$9$$$. | standard output | standard input | Python 3 | Python | 800 | train_021.jsonl | 7f7652ce48cf7994a80ee217c39c238f | 256 megabytes | ["4\n1234", "4\n2244"] | PASSED | def f():
a=input()
b=str(input())
n=0
for i in range(len(b)):
if int(b[i])%2==0:
n+=i+1
print(n)
return n
f() | 1553182500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["2 9 15", "11 14 20 27 31"] | c047040426e736e9085395ed9666135f | null | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. ... | Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | The input contains a single integer: n (1 ≤ n ≤ 105). | standard output | standard input | PyPy 2 | Python | 1,200 | train_002.jsonl | ee9812557f344ad714c7db3a612d66f2 | 256 megabytes | ["3", "5"] | PASSED | def sos(n):
lst=[]
prime = [True for i in range(n+1)]
p=2
while(p * p <= n):
if (prime[p] == True):
for i in range(p * 2, n+1, p):
prime[i] = False
p+=1
lis =[]
for p in range(2, n):
if prime[p]:
lst.append(str(p))
return lst
... | 1372941000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["3", "13"] | 587ac3b470aaacaa024a0c6dde134b7c | NoteIn the first example, all three non-empty possible subsequences are good: $$$\{1\}$$$, $$$\{1, 2\}$$$, $$$\{2\}$$$In the second example, the possible good subsequences are: $$$\{2\}$$$, $$$\{2, 2\}$$$, $$$\{2, 22\}$$$, $$$\{2, 14\}$$$, $$$\{2\}$$$, $$$\{2, 22\}$$$, $$$\{2, 14\}$$$, $$$\{1\}$$$, $$$\{1, 22\}$$$, $$$... | You are given an integer array $$$a_1, a_2, \ldots, a_n$$$.The array $$$b$$$ is called to be a subsequence of $$$a$$$ if it is possible to remove some elements from $$$a$$$ to get $$$b$$$.Array $$$b_1, b_2, \ldots, b_k$$$ is called to be good if it is not empty and for every $$$i$$$ ($$$1 \le i \le k$$$) $$$b_i$$$ is d... | Print exactly one integer — the number of good subsequences taken modulo $$$10^9 + 7$$$. | The first line contains an integer $$$n$$$ ($$$1 \le n \le 100\,000$$$) — the length of the array $$$a$$$. The next line contains integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$). | standard output | standard input | PyPy 2 | Python | 1,700 | train_000.jsonl | 3e451b277d6d35becc4a2827d1ca5177 | 256 megabytes | ["2\n1 2", "5\n2 2 1 22 14"] | PASSED | #!/usr/bin/env python
"""
This file is part of https://github.com/Cheran-Senthil/PyRival.
Copyright 2018 Cheran Senthilkumar all rights reserved,
Cheran Senthilkumar <hello@cheran.io>
Permission to use, modify, and distribute this software is given under the
terms of the MIT License.
"""
from sys import stdin
def m... | 1542901500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["1\n3\n7", "1\n4\n10\n22\n43", "1\n3\n10\n24\n51\n109\n213\n421\n833"] | 6744d8bcba9ef2853788ca7168b76373 | NoteLet us consider the first sample after all characters have been appended to $$$S$$$, so S is "111".As you can see, "1", "11", and "111" all correspond to some distinct English letter. In fact, they are translated into a 'T', an 'M', and an 'O', respectively. All non-empty sequences of English letters that are repre... | In Morse code, an letter of English alphabet is represented as a string of some length from $$$1$$$ to $$$4$$$. Moreover, each Morse code representation of an English letter contains only dots and dashes. In this task, we will represent a dot with a "0" and a dash with a "1".Because there are $$$2^1+2^2+2^3+2^4 = 30$$$... | Print $$$m$$$ lines, the $$$i$$$-th of which being the answer after the $$$i$$$-th modification to $$$S$$$. | The first line contains an integer $$$m$$$ ($$$1 \leq m \leq 3\,000$$$) — the number of modifications to $$$S$$$. Each of the next $$$m$$$ lines contains either a "0" (representing a dot) or a "1" (representing a dash), specifying which character should be appended to $$$S$$$. | standard output | standard input | PyPy 3 | Python | 2,400 | train_063.jsonl | ca5fc176f61d2aad3762d6937170b0a2 | 256 megabytes | ["3\n1\n1\n1", "5\n1\n0\n1\n0\n1", "9\n1\n1\n0\n0\n0\n1\n1\n0\n1"] | PASSED | import os, sys
nums = list(map(int, os.read(0, os.fstat(0).st_size).split()))
MOD = 10 ** 9 + 7
BAD = ([0, 0, 1, 1], [0, 1, 0, 1], [1, 1, 1, 0], [1, 1, 1, 1])
def zfunc(s):
z = [0] * len(s)
l = r = 0
for i in range(1, len(s)):
if i <= r:
z[i] = min(r - i + 1, z[i - l])
while i ... | 1551022500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1111111", "1101"] | 1925187d2c4b9caa1e74c29d9f33f3a6 | NoteIn sample test case $$$l=19$$$, $$$r=122$$$. $$$f(x,y)$$$ is maximal and is equal to $$$127$$$, with $$$x=27$$$, $$$y=100$$$, for example. | You are given two integers $$$l$$$ and $$$r$$$ in binary representation. Let $$$g(x, y)$$$ be equal to the bitwise XOR of all integers from $$$x$$$ to $$$y$$$ inclusive (that is $$$x \oplus (x+1) \oplus \dots \oplus (y-1) \oplus y$$$). Let's define $$$f(l, r)$$$ as the maximum of all values of $$$g(x, y)$$$ satisfying ... | In a single line output the value of $$$f(l, r)$$$ for the given pair of $$$l$$$ and $$$r$$$ in binary representation without extra leading zeros. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the length of the binary representation of $$$r$$$. The second line contains the binary representation of $$$l$$$ — a string of length $$$n$$$ consisting of digits $$$0$$$ and $$$1$$$ ($$$0 \le l < 2^n$$$). The third line contains the binary... | standard output | standard input | PyPy 3-64 | Python | 2,600 | train_105.jsonl | c4196ff2a3bc8c4b0f74f61159997f98 | 256 megabytes | ["7\n0010011\n1111010", "4\n1010\n1101"] | PASSED | n = int(input())
le = int(input(), 2)
rg = int(input(), 2)
ans = rg
if (2 ** (n - 1)) & le:
if rg % 2 == 0 and le <= rg - 2:
ans += 1
else:
ans = 2 ** n - 1 if rg else 0
print('{0:b}'.format(ans)) | 1615039500 | [
"math",
"strings"
] | [
0,
0,
0,
1,
0,
0,
1,
0
] | |
2 seconds | ["7\n11\n8"] | 3d898a45ab89b93e006270a77db49017 | NoteIn the first test case, the longest simple cycle is shown below: We can't increase it with the first chain, since in such case it won't be simple — the vertex $$$2$$$ on the second chain will break simplicity. | You have $$$n$$$ chains, the $$$i$$$-th chain consists of $$$c_i$$$ vertices. Vertices in each chain are numbered independently from $$$1$$$ to $$$c_i$$$ along the chain. In other words, the $$$i$$$-th chain is the undirected graph with $$$c_i$$$ vertices and $$$(c_i - 1)$$$ edges connecting the $$$j$$$-th and the $$$(... | For each test case, print the length of the longest simple cycle. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of chains you have. The second line of each test case contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$... | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_102.jsonl | cd48fa58a957ba80c73f9ebf030ca4c8 | 256 megabytes | ["3\n4\n3 4 3 3\n-1 1 2 2\n-1 2 2 3\n2\n5 6\n-1 5\n-1 1\n3\n3 5 2\n-1 1 1\n-1 3 5"] | PASSED | import sys, threading
import math
from os import path
from collections import defaultdict, Counter, deque
from bisect import *
from string import ascii_lowercase
from functools import cmp_to_key
import heapq
def readInts():
x = list(map(int, (sys.stdin.readline().rstrip().split())))
return x[0] ... | 1611930900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["0", "5", "3"] | bd49960701cc29bcef693808db82366f | null | Little town Nsk consists of n junctions connected by m bidirectional roads. Each road connects two distinct junctions and no two roads connect the same pair of junctions. It is possible to get from any junction to any other junction by these roads. The distance between two junctions is equal to the minimum possible num... | Print one integer — the number of pairs of junctions not connected by a direct road, such that building a road between these two junctions won't decrease the distance between junctions s and t. | The firt line of the input contains integers n, m, s and t (2 ≤ n ≤ 1000, 1 ≤ m ≤ 1000, 1 ≤ s, t ≤ n, s ≠ t) — the number of junctions and the number of roads in Nsk, as well as the indices of junctions where mayors home and work are located respectively. The i-th of the following m lines contains two integers ui and v... | standard output | standard input | PyPy 2 | Python | 1,600 | train_012.jsonl | cc47626a2dbcef38b989c206cc5af5bf | 256 megabytes | ["5 4 1 5\n1 2\n2 3\n3 4\n4 5", "5 4 3 5\n1 2\n2 3\n3 4\n4 5", "5 6 1 5\n1 2\n1 3\n1 4\n4 5\n3 5\n2 5"] | PASSED | n,m,s,t = map(int, raw_input().split())
a=[0]*(n+1)
b=list(a)
g= [[] for i in range(n+1)]
for i in range(m):
u,v = map(int, raw_input().split())
g[u]+=[v]
g[v]+=[u]
def bfs(x, a):
q=[x]
while q:
c=q.pop()
for y in g[c]:
if not a[y]:
a[y] = a[c]+1
... | 1521698700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["NO\nYES\n1 4\nNO"] | fa16d33fb9447eea06fcded0026c6e31 | NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$. | For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 < 4$$$ while ar... | For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$. Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can... | The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ... | standard output | standard input | Python 3 | Python | 1,200 | train_016.jsonl | db9381f90684c020fab1bf6b2405d7aa | 256 megabytes | ["3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020"] | PASSED | t=int(input())
for o in range(t):
n=int(input())
l=list(map(int,input().split()))
flag=0
for i in range(n-1):
if abs(l[i]-l[i+1])>=2:
print("YES")
print(str(i+1)+" "+str(i+2))
flag=1
break
if(... | 1577628300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2\n1 2 1 3", "1\n1 2"] | e7517e32caa1b044ebf1d39276560b47 | NoteSequence x1, x2, ..., xs is lexicographically smaller than sequence y1, y2, ..., ys, if there is such integer r (1 ≤ r ≤ s), that x1 = y1, x2 = y2, ..., xr - 1 = yr - 1 and xr < yr. | A permutation p of length n is a sequence of distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n). A permutation is an identity permutation, if for any i the following equation holds pi = i. A swap (i, j) is the operation that swaps elements pi and pj in the permutation. Let's assume that f(p) is the minimum number of swaps ... | In the first line, print integer k — the minimum number of swaps. In the second line, print 2k integers x1, x2, ..., x2k — the description of the swap sequence. The printed numbers show that you need to consecutively make swaps (x1, x2), (x3, x4), ..., (x2k - 1, x2k). If there are multiple sequence swaps of the minimu... | The first line contains integer n (1 ≤ n ≤ 3000) — the length of permutation p. The second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — Valera's initial permutation. The last line contains integer m (0 ≤ m < n). | standard output | standard input | Python 2 | Python | 2,100 | train_052.jsonl | da4e9223c725963ecfcd1581dfb40a64 | 256 megabytes | ["5\n1 2 3 4 5\n2", "5\n2 1 4 5 3\n2"] | PASSED | n = int(raw_input())
a = [0] + map(int, raw_input().split())
g = [0] * (n+1)
l = []
st = [0] * (n+1)
nd = [0] * (n+1)
k = 0
for x in xrange(1, n+1):
if g[x]:
continue
y = a[x]
st[x] = len(l)
while not g[y]:
g[y] = x
l.append(y)
y = a[y]
nd[x] = len(l)
k += nd[x] -... | 1402241400 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
3 seconds | ["0\n2\n2\n10"] | 11452ff3750578d8b2ac5b76ba2749fd | NoteIn the first test case, the only possible action is to delete vertex $$$2$$$, after which we save $$$0$$$ vertices in total.In the second test case, if we delete vertex $$$2$$$, we can save vertices $$$3$$$ and $$$4$$$. | Byteland is a beautiful land known because of its beautiful trees.Misha has found a binary tree with $$$n$$$ vertices, numbered from $$$1$$$ to $$$n$$$. A binary tree is an acyclic connected bidirectional graph containing $$$n$$$ vertices and $$$n - 1$$$ edges. Each vertex has a degree at most $$$3$$$, whereas the root... | For each test case, output the maximum number of vertices Misha can save. | There are several test cases in the input data. The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 5000$$$) — the number of test cases. This is followed by the test cases description. The first line of each test case contains one integer $$$n$$$ ($$$2\leq n\leq 3\cdot 10^5$$$) — the number of vertices of ... | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_095.jsonl | 25e87820dd31860090cc15f04339fe73 | 256 megabytes | ["4\n\n2\n\n1 2\n\n4\n\n1 2\n\n2 3\n\n2 4\n\n7\n\n1 2\n\n1 5\n\n2 3\n\n2 4\n\n5 6\n\n5 7\n\n15\n\n1 2\n\n2 3\n\n3 4\n\n4 5\n\n4 6\n\n3 7\n\n2 8\n\n1 9\n\n9 10\n\n9 11\n\n10 12\n\n10 13\n\n11 14\n\n11 15"] | PASSED | import sys
input = lambda: sys.stdin.readline().rstrip()
out = sys.stdout.writelines
class RootedTree:
def __init__(self, G: list, root: int):
self._n = len(G)
self._G = G
self._root = root
self._height = -1
self._toposo = []
self._dist = []
self._descendant_num = []
se... | 1654878900 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["10\n12\n12"] | 9fd9bc0a037b2948d60ac2bd5d57740f | NoteIn the first query, $$$n=5$$$ and $$$k=1$$$. The divisors of $$$5$$$ are $$$1$$$ and $$$5$$$, the smallest one except $$$1$$$ is $$$5$$$. Therefore, the only operation adds $$$f(5)=5$$$ to $$$5$$$, and the result is $$$10$$$.In the second query, $$$n=8$$$ and $$$k=2$$$. The divisors of $$$8$$$ are $$$1,2,4,8$$$, wh... | Orac is studying number theory, and he is interested in the properties of divisors.For two positive integers $$$a$$$ and $$$b$$$, $$$a$$$ is a divisor of $$$b$$$ if and only if there exists an integer $$$c$$$, such that $$$a\cdot c=b$$$.For $$$n \ge 2$$$, we will denote as $$$f(n)$$$ the smallest positive divisor of $$... | Print $$$t$$$ lines, the $$$i$$$-th of them should contain the final value of $$$n$$$ in the $$$i$$$-th query by Orac. | The first line of the input is a single integer $$$t\ (1\le t\le 100)$$$: the number of times that Orac will ask you. Each of the next $$$t$$$ lines contains two positive integers $$$n,k\ (2\le n\le 10^6, 1\le k\le 10^9)$$$, corresponding to a query by Orac. It is guaranteed that the total sum of $$$n$$$ is at most $$$... | standard output | standard input | PyPy 3 | Python | 900 | train_001.jsonl | 213273f4f75bc1e760fee2653b2167cb | 256 megabytes | ["3\n5 1\n8 2\n3 4"] | PASSED | def f(n):
for i in range(3,n+1,2):
if n%i == 0:
return i
return n
for t in range(int(input())):
n, k = map(int, input().split())
if n%2 == 0:
n += 2*k
else:
n += f(n)
n += 2*(k-1)
print(n)
| 1589286900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1", "0", "4"] | b07668a66a5e50659233ba055a893bd4 | null | As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city to another moving along the roads.The «Two Paths» company, where Bob's brother works, has won a tender to repair two paths in Flatland. A path is... | Output the maximum possible profit. | The first line contains an integer n (2 ≤ n ≤ 200), where n is the amount of cities in the country. The following n - 1 lines contain the information about the roads. Each line contains a pair of numbers of the cities, connected by the road ai, bi (1 ≤ ai, bi ≤ n). | standard output | standard input | Python 3 | Python | 1,900 | train_078.jsonl | d9daa3748f1dd8de5947b98d7a6c6086 | 64 megabytes | ["4\n1 2\n2 3\n3 4", "7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7", "6\n1 2\n2 3\n2 4\n5 4\n6 4"] | PASSED | __author__ = 'Darren'
def solve():
def get_diameter(u):
depth, v = dfs(u, set())
return dfs(v, set())[0]
def dfs(u, visited):
visited.add(u)
max_depth, deepest_node = -1, u
for v in adj_list[u]:
if v not in visited:
depth, w = dfs(v, visite... | 1274283000 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["YES\nNO"] | 33a31edb75c9b0cf3a49ba97ad677632 | NoteIn the first example, the product of the whole array ($$$20$$$) isn't a perfect square.In the second example, all subsequences have a perfect square product. | Given an array $$$a$$$ of length $$$n$$$, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square.A sequence $$$b$$$ is a subsequence of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deleting some (possibly zero) elements. | If there's a subsequence of $$$a$$$ whose product isn't a perfect square, print "YES". Otherwise, print "NO". | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 100$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$... | standard output | standard input | PyPy 3-64 | Python | 800 | train_110.jsonl | bb160c235436fb56c1869ab9dee74987 | 256 megabytes | ["2\n3\n1 5 4\n2\n100 10000"] | PASSED | import math
for _t in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in l:
if(int(math.sqrt(i))**2!=math.sqrt(i)**2):
ans=1
if(ans==1):
print("YES")
else:
print("NO") | 1618839300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1.5 seconds | ["NO\nYES\nNO\nYES\nNO\nYES"] | c47d999006d4738868f58168c7e2df2b | NoteTest case $$$1$$$: $$$n>m$$$, so they can not sit down.Test case $$$2$$$: the first person can sit $$$2$$$-nd and the second person can sit in the $$$0$$$-th chair. Both of them want at least $$$1$$$ empty chair on both sides, chairs $$$1$$$ and $$$3$$$ are free, so this is a good solution.Test case $$$3$$$: if ... | $$$m$$$ chairs are arranged in a circle sequentially. The chairs are numbered from $$$0$$$ to $$$m-1$$$. $$$n$$$ people want to sit in these chairs. The $$$i$$$-th of them wants at least $$$a[i]$$$ empty chairs both on his right and left side. More formally, if the $$$i$$$-th person sits in the $$$j$$$-th chair, then n... | For each test case print "YES" (without quotes) if it is possible for everyone to sit down and fulfil the restrictions, and "NO" (without quotes) 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 answers). | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 5 \cdot 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 10^5$$$, $$$1 \leq m \leq 10^... | standard output | standard input | PyPy 3-64 | Python | 900 | train_084.jsonl | 1c0536f7f35ee72300c107d00744a7b7 | 256 megabytes | ["6\n3 2\n1 1 1\n2 4\n1 1\n2 5\n2 1\n3 8\n1 2 1\n4 12\n1 2 1 3\n4 19\n1 2 1 3"] | PASSED | from sys import stdin
from math import gcd
from collections import deque, defaultdict
from heapq import heappush, heappop
t = int(stdin.readline())
for _ in range(t):
n, m = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
s = 0
min_val = 10e9
max_val = 0
... | 1650378900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3", "2", "3"] | 960e4c234666d2444b80d5966f1d285d | NoteIn the first sample the string "heavymetalisheavymetal" contains powerful substring "heavymetal" twice, also the whole string "heavymetalisheavymetal" is certainly powerful.In the second sample the string "heavymetalismetal" contains two powerful substrings: "heavymetal" and "heavymetalismetal". | Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style.Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of consec... | Print exactly one number — the number of powerful substrings of the given string. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Input contains a single non-empty string consisting of the lowercase Latin alphabet letters. Length of this string will not be greater than 106 characters. | standard output | standard input | PyPy 3 | Python | 1,300 | train_002.jsonl | 81fa2c8632e013eca4a457fff4397b9f | 256 megabytes | ["heavymetalisheavymetal", "heavymetalismetal", "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou"] | PASSED | #_________________ Mukul Mohan Varshney _______________#
#Template
import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt,floor,factorial,gcd,log,ceil
from collections import deque,Counter,defaultdict
from itertools import permut... | 1371223800 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["3"] | 35d68cc84b4c0025f03f857779f540d7 | null | People in the Tomskaya region like magic formulas very much. You can see some of them below.Imagine you are given a sequence of positive integer numbers p1, p2, ..., pn. Lets write down some magic formulas:Here, "mod" means the operation of taking the residue after dividing.The expression means applying the bitwise xo... | The only line of output should contain a single integer — the value of Q. | The first line of the input contains the only integer n (1 ≤ n ≤ 106). The next line contains n integers: p1, p2, ..., pn (0 ≤ pi ≤ 2·109). | standard output | standard input | Python 3 | Python | 1,600 | train_016.jsonl | 770748ad86c824958dcc54a2ad59e0b3 | 256 megabytes | ["3\n1 2 3"] | PASSED | n,a=int(input()),list(map(int,input().split()))
x,s=[0]*(n+1),0
for i in range(1,n+1):
x[i]=i^x[i-1]
if (n//i)%2:s^=x[i-1]
s^=x[n%i]
s^=a[i-1]
print(s)
| 1398409200 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1", "0\n2"] | 89bf97a548fe12921102e77dda63283a | Notein the first sample there is only one room at the same distance from rooms number 2 and 3 — room number 1. | A and B are preparing themselves for programming contests.The University where A and B study is a set of rooms connected by corridors. Overall, the University has n rooms connected by n - 1 corridors so that you can get from any room to any other one by moving along the corridors. The rooms are numbered from 1 to n.Eve... | In the i-th (1 ≤ i ≤ m) line print the number of rooms that are equidistant from the rooms where A and B write contest on the i-th day. | The first line contains integer n (1 ≤ n ≤ 105) — the number of rooms in the University. The next n - 1 lines describe the corridors. The i-th of these lines (1 ≤ i ≤ n - 1) contains two integers ai and bi (1 ≤ ai, bi ≤ n), showing that the i-th corridor connects rooms ai and bi. The next line contains integer m (1 ≤ m... | standard output | standard input | Python 2 | Python | 2,100 | train_072.jsonl | dbad5a17a56b08efebd1a31c3a3a1e78 | 256 megabytes | ["4\n1 2\n1 3\n2 4\n1\n2 3", "4\n1 2\n2 3\n2 4\n2\n1 2\n1 3"] | PASSED | from sys import stdin, stdout
def main():
n = int(stdin.readline())
to = [0]
xt = [0]
last = [0] * (n + 1)
toa = to.append
xta = xt.append
c = 1
for _ in xrange(n - 1):
a, b = map(int, stdin.readline().split())
xta(last[a])
last[a] = c
toa(b)
c += ... | 1425128400 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["balance", "left", "right", "balance"] | 19f2c21b18e84f50e251b1dfd557d32f | NoteAs you solve the problem, you may find the following link useful to better understand how a lever functions: http://en.wikipedia.org/wiki/Lever.The pictures to the examples: | You have a description of a lever as string s. We'll represent the string length as record |s|, then the lever looks as a horizontal bar with weights of length |s| - 1 with exactly one pivot. We will assume that the bar is a segment on the Ox axis between points 0 and |s| - 1.The decoding of the lever description is gi... | Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance. | The first line contains the lever description as a non-empty string s (3 ≤ |s| ≤ 106), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar. To solve the problem yo... | standard output | standard input | Python 3 | Python | 900 | train_000.jsonl | d36fa9385ce03251c358eb8d5febc507 | 256 megabytes | ["=^==", "9===^==1", "2==^7==", "41^52=="] | PASSED | lever = input().split("^")
leftWeight = 0
for d in range(len(lever[0])):
if lever[0][d] != "=":
leftWeight += int(lever[0][d])*(len(lever[0])-d)
rightWeight = 0
for d in range(len(lever[1])):
if lever[1][d] != "=":
rightWeight += int(lever[1][d])*(d+1)
if leftWeight > rightWeight:
print("left")
if right... | 1387893600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["ORZ", "0"] | 391c2abbe862139733fcb997ba1629b8 | null | In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substri... | Output the longest common subsequence of s1 and s2 without virus as a substring. If there are multiple answers, any of them will be accepted. If there is no valid common subsequence, output 0. | The input contains three strings in three separate lines: s1, s2 and virus (1 ≤ |s1|, |s2|, |virus| ≤ 100). Each string consists only of uppercase English letters. | standard output | standard input | Python 3 | Python | 2,000 | train_065.jsonl | 400644b8550135348931110e71de3267 | 512 megabytes | ["AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ", "AA\nA\nA"] | PASSED | a, b, v = input(), input(), input()
t = [[-1] * len(b) for x in range(len(a))]
def g(i, j):
if i < 0 or j < 0: return ''
if t[i][j] == -1:
s = g(i - 1, j - 1)
if a[i] == b[j]: s += a[i]
t[i][j] = max(s, g(i - 1, j), g(i, j - 1), key=lambda q: len(q) - q.count(v))
return t[i][j]
s =... | 1379691000 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["4\n-1\n8\n-1", "1\n2"] | 89c97b6c302bbb51e9d5328c680a7ea7 | null | Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs. Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + ... | For each query, print its answer in a single line. | The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105). Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query. | standard output | standard input | Python 3 | Python | 1,900 | train_004.jsonl | 99a55935d070f23c133bc07879301231 | 256 megabytes | ["2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8", "1 5 2\n1 5 10\n2 7 4"] | PASSED | import math
A, B, n = map(int, input().split())
ans = []
for _ in range(n):
l, t, m = map(int, input().split())
if A + B * (l - 1) > t:
ans.append(-1)
continue
r1 = (t - A) / B + 1
D = (B-2*A)*(B-2*A)-4*B*(-2*l*A+2*A-B*(l-2)*(l-1)-2*m*t)
r2 = int(((B-2*A) + math.sqrt(D)) / 2 / B)
if r1 > r2:
r1 = r2
a... | 1429029300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["5 3 -1", "14 4 14 4 7 7", "12 5"] | 476c05915a1536cd989c4681c61c9deb | NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t... | Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T... | Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$. | The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ... | standard output | standard input | PyPy 3-64 | Python | 2,000 | train_110.jsonl | 9e47cf1d6760e3ecabd46f304caf31aa | 256 megabytes | ["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"] | PASSED | import sys
import os
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
input = lambda: sys.stdin.readline().rstrip()
N,C = map(int, input().split())
A = [0]*(C+1)
for _ in range(N):
c,d,h = map(int, input().split())
A[c] = max(A[c], h*d)
# 与上面的循环分开,避免有多个c==1的情况
for c in range(... | 1647960300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\n4\n2", "NO", "YES\n2 1 5\n4"] | 4a644d97824d29c42dbb48d79b9958fe | null | Petya and Vasya are competing with each other in a new interesting game as they always do.At the beginning of the game Petya has to come up with an array of $$$N$$$ positive integers. Sum of all elements in his array should be equal to $$$S$$$. Then Petya has to select an integer $$$K$$$ such that $$$0 \leq K \leq S$$$... | If Petya can win, print "YES" (without quotes) in the first line. Then print Petya's array in the second line. The array should contain $$$N$$$ positive integers with sum equal to $$$S$$$. In the third line print $$$K$$$. If there are many correct answers, you can print any of them. If Petya can't win, print "NO" (with... | The first line contains two integers $$$N$$$ and $$$S$$$ ($$$1 \leq N \leq S \leq 10^{6}$$$) — the required length of the array and the required sum of its elements. | standard output | standard input | PyPy 3 | Python | 1,400 | train_004.jsonl | 9810cf7107e6a1b3e59cb739e6642855 | 256 megabytes | ["1 4", "3 4", "3 8"] | PASSED | n,s = list(map(int,input().split()))
val = s//n
rem = s%n
v1 = val
v2 = val+rem
if v1>1:
print('YES')
for i in range(0,n-1):
print(v1,end=" ")
print(v2)
print(1)
else:
print('NO') | 1589628900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["netman: Hello, Vladik!\nVladik: Hi", "Impossible", "Impossible\nnetman: tigerrrrr, banany2001, klinchuh, my favourite team ever, are you ready?\nklinchuh: yes, coach!\ntigerrrrr: yes, netman\nbanany2001: yes of course."] | 3ac91d8fc508ee7d1afcf22ea4b930e4 | null | Recently Vladik discovered a new entertainment — coding bots for social networks. He would like to use machine learning in his bots so now he want to prepare some learning data for them.At first, he need to download t chats. Vladik coded a script which should have downloaded the chats, however, something went wrong. In... | Print the information about the t chats in the following format: If it is not possible to recover senders, print single line "Impossible" for this chat. Otherwise print m messages in the following format: <username>:<text> If there are multiple answers, print any of them. | The first line contains single integer t (1 ≤ t ≤ 10) — the number of chats. The t chats follow. Each chat is given in the following format. The first line of each chat description contains single integer n (1 ≤ n ≤ 100) — the number of users in the chat. The next line contains n space-separated distinct usernames. Eac... | standard output | standard input | Python 2 | Python | 2,200 | train_031.jsonl | b2b217c1460f8ccec742cb00cf3122d3 | 256 megabytes | ["1\n2\nVladik netman\n2\n?: Hello, Vladik!\n?: Hi", "1\n2\nnetman vladik\n3\nnetman:how are you?\n?:wrong message\nvladik:im fine", "2\n3\nnetman vladik Fedosik\n2\n?: users are netman, vladik, Fedosik\nvladik: something wrong with this chat\n4\nnetman tigerrrrr banany2001 klinchuh\n4\n?: tigerrrrr, banany2001, klinch... | PASSED | import sys
t =sys.stdin.readline()
t = int(t)
for tttt in range(t) :
org=[]
dic={}
n =sys.stdin.readline()
n = int(n)
users=sys.stdin.readline().split()
users=['?']+users
for k in range(n+1):
dic[users[k]]=k
m = sys.stdin.readline()
m=int(m)
messusers=[]
messages=[]
for mmmm in range(m):... | 1483713300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["1 2\n2 3", "16 32 48\n32 48 64", "327 583\n408 664"] | 5f0b8e6175113142be15ac960e4e9c4c | NoteIn the first example, the matrix $$$a$$$ can be used as the matrix $$$b$$$, because the absolute value of the difference between numbers in any adjacent pair of cells is $$$1 = 1^4$$$.In the third example: $$$327$$$ is a multiple of $$$3$$$, $$$583$$$ is a multiple of $$$11$$$, $$$408$$$ is a multiple of $$$12$$$... | You are given a matrix $$$a$$$ consisting of positive integers. It has $$$n$$$ rows and $$$m$$$ columns.Construct a matrix $$$b$$$ consisting of positive integers. It should have the same size as $$$a$$$, and the following conditions should be met: $$$1 \le b_{i,j} \le 10^6$$$; $$$b_{i,j}$$$ is a multiple of $$$a_{i... | The output should contain $$$n$$$ lines each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line should be $$$b_{i,j}$$$. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n,m \le 500$$$). Each of the following $$$n$$$ lines contains $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$a_{i,j}$$$ ($$$1 \le a_{i,j} \le 16$$$). | standard output | standard input | PyPy 3-64 | Python | 2,200 | train_092.jsonl | 1e3d9f925d7235ff95b86a9b7f6e0e14 | 256 megabytes | ["2 2\n1 2\n2 3", "2 3\n16 16 16\n16 16 16", "2 2\n3 11\n12 8"] | PASSED | a = []
n, m = map(int, input().split())
t = 720720
for _ in range(n):
a.append([])
for j in map(int, input().split()):
a[-1].append(j)
for i in range(n):
for j in range(m):
if ((i + 1) + (j + 1)) % 2 == 1:
a[i][j] = t
else:
a[i][j] **= 4
... | 1613141400 | [
"number theory",
"math",
"graphs"
] | [
0,
0,
1,
1,
1,
0,
0,
0
] | |
1 second | ["YES", "nO", "YES"] | 424f37abd0e19208e6b0cb8b670e7187 | NoteThe following image shows the first sample: both $$$P$$$ and $$$T$$$ are squares. The second sample was shown in the statements. | Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon $$$P$$$ which is defined by coordinates of its vertices. Define $$$P(x,y)$$$ as a polygon obtained by translating $$$P$$$ by vector $$$\overrightarrow {(x,y)}$$$. The picture below ... | Output "YES" in a separate line, if $$$P$$$ and $$$T$$$ are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower). | The first line of input will contain a single integer $$$n$$$ ($$$3 \le n \le 10^5$$$) — the number of points. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$x_i, y_i$$$ ($$$|x_i|, |y_i| \le 10^9$$$), denoting the coordinates of the $$$i$$$-th vertex. It is guaranteed that these points are listed in ... | standard output | standard input | Python 3 | Python | 1,800 | train_010.jsonl | 2f41e6e84e49f712fe66b29f73de52fb | 256 megabytes | ["4\n1 0\n4 1\n3 4\n0 3", "3\n100 86\n50 0\n150 0", "8\n0 0\n1 0\n2 1\n3 3\n4 6\n3 6\n2 5\n1 3"] | PASSED | n = int(input())
polygon = [None] * n
for i in range(n):
polygon[i] = tuple(map(int, input().split()))
if n % 2:
print("NO")
else:
def same(id1, id2):
ax = polygon[id1 + 1][0] - polygon[id1][0]
ay = polygon[id1 + 1][1] - polygon[id1][1]
bx = polygon[id2 + 1][0] - polygon[id2][0]
... | 1581257100 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["3", "3223", "3133"] | 0aa46c224476bfba2b1e1227b58e1630 | NoteIn the second sample, sequence a consists of 4 elements: {a1, a2, a3, a4} = {1, 3, 2, 5}. Sequence a has exactly 2 longest increasing subsequences of length 3, they are {a1, a2, a4} = {1, 3, 5} and {a1, a3, a4} = {1, 2, 5}.In the third sample, sequence a consists of 4 elements: {a1, a2, a3, a4} = {1, 5, 2, 3}. Sequ... | The next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence. For better understanding, Nam decided to learn it a few days before the lesson.Nam created a sequence a consisting of n (1 ≤ n ≤ 105) elements a1, a2, ..., an (1 ≤ ai ≤ 105). A subsequence ai1, a... | Print a string consisting of n characters. i-th character should be '1', '2' or '3' depending on which group among listed above index i belongs to. | The first line contains the single integer n (1 ≤ n ≤ 105) denoting the number of elements of sequence a. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 105). | standard output | standard input | Python 3 | Python | 2,200 | train_046.jsonl | 6da85e1824eddba6e014ce3f1c036a01 | 256 megabytes | ["1\n4", "4\n1 3 2 5", "4\n1 5 2 3"] | PASSED | # a simple parser for python. use get_number() and get_word() to read
def main():
def parser():
while 1:
data = list(input().split(' '))
for number in data:
if len(number) > 0:
yield(number)
input_parser = parser()
gets = lambda: next(inpu... | 1415718000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3\n2\n0"] | ee295fd90ee9283709447481f172c73c | NoteFor the first test case, you can't make any moves, so the answer is $$$3$$$.For the second test case, one optimal sequence of moves is BABA $$$\to$$$ BA. So, the answer is $$$2$$$.For the third test case, one optimal sequence of moves is AABBBABBBB $$$\to$$$ AABBBABB $$$\to$$$ AABBBB $$$\to$$$ ABBB $$$\to$$$ AB $$$... | Zookeeper is playing a game. In this game, Zookeeper must use bombs to bomb a string that consists of letters 'A' and 'B'. He can use bombs to bomb a substring which is either "AB" or "BB". When he bombs such a substring, the substring gets deleted from the string and the remaining parts of the string get concatenated.... | For each test case, print a single integer: the length of the shortest string that Zookeeper can make. | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 20000)$$$ — the number of test cases. The description of the test cases follows. Each of the next $$$t$$$ lines contains a single test case each, consisting of a non-empty string $$$s$$$: the string that Zookeepe... | standard output | standard input | PyPy 3 | Python | 1,100 | train_010.jsonl | 2b7de7879c2dcc346bc389a268301dfe | 256 megabytes | ["3\nAAA\nBABA\nAABBBABBBB"] | PASSED | from collections import Counter
import math
import sys
from bisect import bisect,bisect_left,bisect_right
from itertools import permutations
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else ... | 1602939900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["2\n999993 1000000", "1\n1000000"] | 4143caa25fcc2f4d400d169f9697be01 | null | Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris.There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chris's teacher picks a subset of blocks X and keeps it to himself. He will give them back ... | In the first line of output print a single integer m (1 ≤ m ≤ 106 - n), the number of blocks in the set Y. In the next line output m distinct space-separated integers y1, y2, ..., ym (1 ≤ yi ≤ 106), such that the required equality holds. The sets X and Y should not intersect, i.e. xi ≠ yj for all i, j (1 ≤ i ≤ n; 1 ≤ j... | The first line of input contains a single integer n (1 ≤ n ≤ 5·105), the number of blocks in the set X. The next line contains n distinct space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 106), the numbers of the blocks in X. Note: since the size of the input and output could be very large, don't use slow output techn... | standard output | standard input | Python 2 | Python | 1,700 | train_028.jsonl | 365fd80633977137b93b4607bd6daf99 | 256 megabytes | ["3\n1 4 5", "1\n1"] | PASSED | s = 10 ** 6
cnt = int(raw_input())
data = set(map(int, raw_input().split()))
ans = []
p = 0
for i in data:
now = s + 1 - i
if now in data:
p += 1
else:
ans.append(now)
p /= 2
if p > 0:
for i in xrange(1, s / 2 + 1):
now = s + 1 - i
if (now not in data) and (i not in dat... | 1395502200 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n6\n-1"] | 5eac47595f0212b2b652518f0fefd238 | NoteOne of the possible answers to the first test case: $$$(0, 0) \to (1, 0) \to (1, 1) \to (2, 2)$$$.One of the possible answers to the second test case: $$$(0, 0) \to (0, 1) \to (1, 2) \to (0, 3) \to (1, 4) \to (2, 3) \to (3, 2) \to (4, 3)$$$.In the third test case Mikhail cannot reach the point $$$(10, 1)$$$ in 9 mo... | Mikhail walks on a Cartesian plane. He starts at the point $$$(0, 0)$$$, and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point $$$(0, 0)$$$, he can go to any of the following points in one move: $$$(1, 0)$$$; $$$(1, 1)$$$; $$$(0, 1)$$$; $$$(-1, 1)$$$; $$$(-1,... | Print $$$q$$$ integers. The $$$i$$$-th integer should be equal to -1 if Mikhail cannot go from the point $$$(0, 0)$$$ to the point $$$(n_i, m_i)$$$ in exactly $$$k_i$$$ moves described above. Otherwise the $$$i$$$-th integer should be equal to the the maximum number of diagonal moves among all possible movements. | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Then $$$q$$$ lines follow. The $$$i$$$-th of these $$$q$$$ lines contains three integers $$$n_i$$$, $$$m_i$$$ and $$$k_i$$$ ($$$1 \le n_i, m_i, k_i \le 10^{18}$$$) — $$$x$$$-coordinate of the destination point of ... | standard output | standard input | PyPy 3 | Python | 1,600 | train_030.jsonl | 842d73b7e765029e0bd8a6926e88a7c9 | 256 megabytes | ["3\n2 2 3\n4 3 7\n10 1 9"] | PASSED | for _ in range(int(input())):
n,m,k = map(int,input().split())
if max(n,m)>k:
print(-1)
else:
if (n+m)%2==0:
if (n+k)%2==0:
print(k)
else:
print(k-2)
else:
print(k-1) | 1536330900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["and 2 5\n\nor 5 6\n\nfinish 5"] | 7fb8b73fa2948b360644d40b7035ce4a | NoteIn the example, the hidden sequence is $$$[1, 6, 4, 2, 3, 5, 4]$$$.Below is the interaction in the example.Query (contestant's program)Response (interactor)Notesand 2 52$$$a_2=6$$$, $$$a_5=3$$$. Interactor returns bitwise AND of the given numbers.or 5 67$$$a_5=3$$$, $$$a_6=5$$$. Interactor returns bitwise OR of the... | This is an interactive taskWilliam has a certain sequence of integers $$$a_1, a_2, \dots, a_n$$$ in his mind, but due to security concerns, he does not want to reveal it to you completely. William is ready to respond to no more than $$$2 \cdot n$$$ of the following questions: What is the result of a bitwise AND of t... | null | It is guaranteed that for each element in a sequence the condition $$$0 \le a_i \le 10^9$$$ is satisfied. | standard output | standard input | PyPy 3-64 | Python | 1,800 | train_107.jsonl | 75e5d3dda0079d906b06255f041ce7de | 256 megabytes | ["7 6\n\n2\n\n7"] | PASSED | import os
import sys
from io import BytesIO, IOBase
# region fastio
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 ... | 1630247700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1 \n1 2 3 \n1 2 4 3 \n1 2 3 4 5"] | a57823a7ca0f67a07f94175ab59d33de | NoteIn the first test case, the permutation has length $$$1$$$, so the only possible segment is $$$[1,1]$$$. The resulting permutation is $$$[1]$$$.In the second test case, we can obtain the identity permutation by reversing the segment $$$[1,2]$$$. The resulting permutation is $$$[1,2,3]$$$.In the third test case, the... | You are given a permutation $$$p_1, p_2, \ldots, p_n$$$ of length $$$n$$$. You have to choose two integers $$$l,r$$$ ($$$1 \le l \le r \le n$$$) and reverse the subsegment $$$[l,r]$$$ of the permutation. The permutation will become $$$p_1,p_2, \dots, p_{l-1},p_r,p_{r-1}, \dots, p_l,p_{r+1},p_{r+2}, \dots ,p_n$$$.Find t... | For each test case print the lexicographically smallest permutation you can obtain. | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 500$$$) — the length of the permutation. The second line ... | standard output | standard input | PyPy 3-64 | Python | 800 | train_106.jsonl | f9e5b7fd2e9dfc5b2ea3a05870dc5985 | 256 megabytes | ["4\n\n1\n\n1\n\n3\n\n2 1 3\n\n4\n\n1 4 2 3\n\n5\n\n1 2 3 4 5"] | PASSED | #lista=list(map(int,input().split()))
#x=lista[0]
#n=lista[0]
import math
#import sys
#from collections import deque
#from sys import stdin, stdout
from decimal import *
#lista=list(map(int,input().split()))
#x=lista[0]
#n=lista[0]
rasp_final=""
#my_set=set()
#for x in range(1, 100000):
#my_set.add... | 1644849300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n2\n1 3", "0", "1\n4\n1 2 5 6"] | f78d04f699fc94103e5b08023949854d | NoteIn the first sample, the string is '(()(('. The operation described corresponds to deleting the bolded subsequence. The resulting string is '(((', and no more operations can be performed on it. Another valid answer is choosing indices $$$2$$$ and $$$3$$$, which results in the same final string.In the second sample,... | Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how hard he tries, he will not be able to remove a simple subsequence!W... | In the first line, print an integer $$$k$$$ — the minimum number of operations you have to apply. Then, print $$$2k$$$ lines describing the operations in the following format: For each operation, print a line containing an integer $$$m$$$ — the number of characters in the subsequence you will remove. Then, print a li... | The only line of input contains a string $$$s$$$ ($$$1 \le |s| \le 1000$$$) formed by characters '(' and ')', where $$$|s|$$$ is the length of $$$s$$$. | standard output | standard input | Python 3 | Python | 1,200 | train_005.jsonl | a1c2ac3f5608d4165a7ebd50c2047367 | 256 megabytes | ["(()((", ")(", "(()())"] | PASSED | s = input()
a = []
i = 0
j = len(s) - 1
while i < j:
while i < j and s[i] != '(':
i += 1
while i < j and s[j] != ')':
j -= 1
if i < j and s[i] == '(' and s[j] == ')':
a.append(i + 1)
a.append(j + 1)
i += 1
j -= 1
if a:
print(1)
print(len(a))
p... | 1583246100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["18\n1000000000000000000"] | 7e6bc93543ad7bf80a019559b7bf99e0 | NoteThe picture below shows the solution for the first sample. The cost $$$18$$$ is reached by taking $$$c_3$$$ 3 times and $$$c_2$$$ once, amounting to $$$5+5+5+3=18$$$. | Lindsey Buckingham told Stevie Nicks "Go your own way". Nicks is now sad and wants to go away as quickly as possible, but she lives in a 2D hexagonal world.Consider a hexagonal tiling of the plane as on the picture below. Nicks wishes to go from the cell marked $$$(0, 0)$$$ to a certain cell given by the coordinates. ... | For each testcase output the smallest cost of a path from the origin to the given cell. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^{4}$$$). Description of the test cases follows. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$-10^{9} \le x, y \le 10^{9}$$$) representing the coordinates of the target he... | standard output | standard input | PyPy 3 | Python | 1,900 | train_057.jsonl | c568755c85884c2ed08ab579f968dc55 | 256 megabytes | ["2\n-3 1\n1 3 5 7 9 11\n1000000000 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000"] | PASSED | import sys
input = sys.stdin.readline
def main():
x, y = map(int, input().split())
clst = list(map(int, input().split()))
clst[0] = min(clst[0], clst[5] + clst[1])
clst[1] = min(clst[1], clst[0] + clst[2])
clst[2] = min(clst[2], clst[1] + clst[3])
clst[3] = min(clst[3], clst[2] + clst[4])
c... | 1603011900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["Yes\nYes\nNo"] | a375dd323b7adbfa9f1cad9aa48f7247 | null | Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rec... | Print $$$t$$$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower). | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is given in two lines. The first line contains two integers $$$a_1$$$ and $$$b_1$$$ ($$$1 \le a_1, b_1 \le 100$$$) — the dimensions of the first one obtained after ... | standard output | standard input | PyPy 2 | Python | 900 | train_003.jsonl | 4dddf9c7fa10167424d2b2e288128e76 | 256 megabytes | ["3\n2 3\n3 1\n3 2\n1 3\n3 3\n1 3"] | PASSED | for _ in range(input()):
a1,b1=map(int,raw_input().split())
a2,b2=map(int,raw_input().split())
if a1==a2 and b1+b2==a1:
print "YES"
elif a1==b2 and a2+b1==a1:
print "YES"
elif a2==b1 and a1+b2==a2:
print "YES"
elif b1==b2 and a1+a2==b1:
print "YES"
else:
... | 1590154500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1 1 1 1\n1 4 3 2 1\n1 3 3\n1"] | 188c9dbb3e1851b7b762ed6b4b23d1bd | NoteIn the first test case one of the optimal solutions is to increase the whole array on each operation (that is, choose the suffix starting at index $$$1$$$). The final array $$$[11, 12, 13, 14]$$$ contains $$$0$$$ inversions.In the second test case, $$$a$$$ will be equal to $$$[2, 4, 3, 5, 6]$$$, $$$[2, 4, 3, 7, 8]$... | You are given a permutation $$$a$$$ of size $$$n$$$ and you should perform $$$n$$$ operations on it. In the $$$i$$$-th operation, you can choose a non-empty suffix of $$$a$$$ and increase all of its elements by $$$i$$$. How can we perform the operations to minimize the number of inversions in the final array?Note that ... | For each test case, print $$$n$$$ integers $$$x_{1}, x_{2}, \ldots, x_{n}$$$ ($$$1 \le x_{i} \le n$$$ for each $$$1 \le i \le n$$$) indicating that the $$$i$$$-th operation must be applied to the suffix starting at index $$$x_{i}$$$. If there are multiple answers, print any of them. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of the array. The second line contains $$$n$$$ dist... | standard output | standard input | PyPy 3-64 | Python | 1,300 | train_103.jsonl | dd8c1cc7844f7e1b3b876232b0071137 | 256 megabytes | ["4\n\n4\n\n1 2 3 4\n\n5\n\n1 3 2 4 5\n\n3\n\n2 3 1\n\n1\n\n1"] | PASSED | import collections
import heapq
import sys
import math
import itertools
import bisect
from io import BytesIO, IOBase
import os
######################################################################################
#--------------------------------------funs here-------------------------------------#
#########... | 1665844500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES", "YES", "NO", "NO"] | d629d09782a7af0acc359173ac4b4f0a | NoteIn the first example a wildcard character '*' can be replaced with a string "force". So the string $$$s$$$ after this replacement is "codeforces" and the answer is "YES".In the second example a wildcard character '*' can be replaced with an empty string. So the string $$$s$$$ after this replacement is "vkcup" and t... | You are given two strings $$$s$$$ and $$$t$$$. The string $$$s$$$ consists of lowercase Latin letters and at most one wildcard character '*', the string $$$t$$$ consists only of lowercase Latin letters. The length of the string $$$s$$$ equals $$$n$$$, the length of the string $$$t$$$ equals $$$m$$$.The wildcard charact... | Print "YES" (without quotes), if you can obtain the string $$$t$$$ from the string $$$s$$$. Otherwise print "NO" (without quotes). | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the length of the string $$$s$$$ and the length of the string $$$t$$$, respectively. The second line contains string $$$s$$$ of length $$$n$$$, which consists of lowercase Latin letters and at most one wildcard character '*'.... | standard output | standard input | PyPy 3 | Python | 1,200 | train_018.jsonl | e9f7a76fa6922a64caabc97b99848854 | 256 megabytes | ["6 10\ncode*s\ncodeforces", "6 5\nvk*cup\nvkcup", "1 1\nv\nk", "9 6\ngfgf*gfgf\ngfgfgf"] | PASSED | n,m=map(int,input().split())
s=input()
t=input()
if(m<n-1):
print('NO')
else:
if('*' in s):
i=0
f=1
while(i<n and s[i]!='*'):
if(s[i]!=t[i]):
f=0
break
else:
i=i+1
if(f==1):
i=n-1
j=m-... | 1534516500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["abcd", "codeforces"] | 9c90974a0bb860a5e180760042fd5045 | null | An African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter ... | Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter. | The first line contains two integers n and m (1 ≤ n, m ≤ 100). Next n lines contain m lowercase Latin letters each. That is the crossword grid. | standard output | standard input | Python 3 | Python | 1,100 | train_008.jsonl | a2e817889f8204c5dc430678c3715f49 | 256 megabytes | ["3 3\ncba\nbcd\ncbc", "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf"] | PASSED | n, m = list(map(int, input().strip().split()))
A = [[0] * m] * n
for r in range(n):
A[r] = list(input().strip())
def in_row(A, r, c):
x = A[r][c]
left, right = A[r][:c], A[r][c + 1:]
if (x in left) or (x in right):
return True
def in_col(A, r, c):
x = A[r][c]
for row in range(n):
... | 1308236400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["2\n2 5 6 7\n3 6 4 5\n0"] | cbd550be6982ef259de500194c33eff2 | NoteNote the graph can be unconnected after a certain operation.Consider the first test case of the example: The red edges are removed, and the green ones are added. | Nastia has an unweighted tree with $$$n$$$ vertices and wants to play with it!The girl will perform the following operation with her tree, as long as she needs: Remove any existing edge. Add an edge between any pair of vertices. What is the minimum number of operations Nastia needs to get a bamboo from a tree? A bamb... | For each test case in the first line print a single integer $$$k$$$ — the minimum number of operations required to obtain a bamboo from the initial tree. In the next $$$k$$$ lines print $$$4$$$ integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ ($$$1 \le x_1, y_1, x_2, y_{2} \le n$$$, $$$x_1 \neq y_1$$$, $$$x_2 \neq y... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of vertices in the tree. Next $$$n - 1$$$ lines of each test cases describe the edges of the tree in form $$$a... | standard output | standard input | PyPy 3 | Python | 2,500 | train_099.jsonl | 200a857939310d5a9e10ea9da1ec289a | 256 megabytes | ["2\n7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n4\n1 2\n1 3\n3 4"] | PASSED | from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
... | 1620398100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["Vanya\nVova\nVanya\nBoth", "Both\nBoth"] | f98ea97377a06963d1e6c1c215ca3a4a | NoteIn the first sample Vanya makes the first hit at time 1 / 3, Vova makes the second hit at time 1 / 2, Vanya makes the third hit at time 2 / 3, and both boys make the fourth and fifth hit simultaneously at the time 1.In the second sample Vanya and Vova make the first and second hit simultaneously at time 1. | Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to... | Print n lines. In the i-th line print word "Vanya", if the last hit on the i-th monster was performed by Vanya, "Vova", if Vova performed the last hit, or "Both", if both boys performed it at the same time. | The first line contains three integers n,x,y (1 ≤ n ≤ 105, 1 ≤ x, y ≤ 106) — the number of monsters, the frequency of Vanya's and Vova's attack, correspondingly. Next n lines contain integers ai (1 ≤ ai ≤ 109) — the number of hits needed do destroy the i-th monster. | standard output | standard input | Python 3 | Python | 1,800 | train_010.jsonl | f728236602f12a1581c0b821bbf5d3af | 256 megabytes | ["4 3 2\n1\n2\n3\n4", "2 1 1\n1\n2"] | PASSED | n, x, y = map(int, input().split())
for _ in range(n):
a = int(input())
c1, c2 = ((a + 1) * x // (x + y)) / x, ((a + 1) * y // (x + y)) / y
if c1 == c2:
print('Both')
elif c1 > c2:
print('Vanya')
else:
print('Vova')
| 1417451400 | [
"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.