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 | ["14", "6", "0"] | d7d8d91be04f5d9065a0c22e66d11de3 | NoteIn the first example: In the second example: Note that the three poles $$$(0, 0)$$$, $$$(0, 2)$$$ and $$$(0, 4)$$$ are connected by a single wire.In the third example: | This problem is same as the previous one, but has larger constraints.It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system con... | Print a single integer — the number of pairs of wires that are intersecting. | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — the number of electric poles. Each of the following $$$n$$$ lines contains two integers $$$x_i$$$, $$$y_i$$$ ($$$-10^4 \le x_i, y_i \le 10^4$$$) — the coordinates of the poles. It is guaranteed that all of these $$$n$$$ points are distinct. | standard output | standard input | PyPy 3 | Python | 1,900 | train_027.jsonl | 19a44d49b3a269a465e6e55b1d0434a4 | 256 megabytes | ["4\n0 0\n1 1\n0 3\n1 2", "4\n0 0\n0 2\n0 4\n2 0", "3\n-1 -1\n1 0\n3 1"] | PASSED | from math import *
class slopeC:
def __init__(self):
self.chil = set()
n = int(input())
slopes = {}
L = []
for i in range(n):
x, y = map(int, input().split())
for l in L:
if x != l[0]:
slope = (y - l[1]) / (x - l[0])
else:
slope = inf
... | 1557414300 | [
"math",
"geometry"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
1 second | ["5"] | 0c4bc51e5be9cc642f62d2b3df2bddc4 | NoteThe following image represents possible process of removing leaves from the tree: | Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.The girl noticed that some of the tree's vertices are sad, so she decided to play with them. Let's call verte... | Print the only integer — the minimum number of leaves Alyona needs to remove such that there will be no any sad vertex left in the tree. | In the first line of the input integer n (1 ≤ n ≤ 105) is given — the number of vertices in the tree. In the second line the sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 109) is given, where ai is the number written on vertex i. The next n - 1 lines describe tree edges: ith of them consists of two integers pi and c... | standard output | standard input | Python 3 | Python | 1,600 | train_036.jsonl | b2a00fa84d1f4b276c67ca14b2ce5639 | 256 megabytes | ["9\n88 22 83 14 95 91 98 53 11\n3 24\n7 -8\n1 67\n1 64\n9 65\n5 12\n6 -80\n3 8"] | PASSED | n=int(input())
a=[0]+list(map(int,input().split()))
E=[[] for _ in range(n+1)]
for i in range(n-1):
p,c=map(int,input().split())
E[i+2]+=[(p,c)]
E[p]+=[(i+2,c)]
ans=0
ch=[(1,0,0)]
while ch:
nom,pre,l=ch.pop()
if l>a[nom]: continue
ans+=1
for x,c in E[nom]:
if x!=pre: ch+=[(x,nom,max... | 1466181300 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["-1 1\n-4 9\n-18 50\n-4 9"] | 4dfa99acbe06b314f0f0b934237c66f3 | NoteIn the first test case: $$$\frac{-1}{1} + \frac{1}{1} = 0 = \frac{-1 + 1}{1 + 1}$$$.In the second test case: $$$\frac{-4}{2} + \frac{9}{3} = 1 = \frac{-4 + 9}{2 + 3}$$$.In the third test case: $$$\frac{-18}{3} + \frac{50}{5} = 4 = \frac{-18 + 50}{3 + 5}$$$.In the fourth test case: $$$\frac{-4}{6} + \frac{9}{9} = \f... | Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u +... | For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation. | standard output | standard input | PyPy 3-64 | Python | 800 | train_091.jsonl | 8a37a0977957e1619d4bab49069662d6 | 256 megabytes | ["4\n1 1\n2 3\n3 5\n6 9"] | PASSED | import math
def lcm(a, b):
return (a * b) // math.gcd(a, b)
t = int(input())
for _ in range(t):
u, v = map(int, input().split(' '))
u *= u
v *= v
k = lcm(u, v)
print(k // v, -(k // u)) | 1636869900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\nNO\nYES"] | f690e6008010dfce1238cc2f0379e52c | NoteFor the first test case, we can travel from node $$$1$$$ to node $$$3$$$, $$$x$$$ changing from $$$0$$$ to $$$1$$$, then we travel from node $$$3$$$ to node $$$2$$$, $$$x$$$ becoming equal to $$$3$$$. Now, we can teleport to node $$$3$$$ and travel from node $$$3$$$ to node $$$4$$$, reaching node $$$b$$$, since $$$... | You are given a weighted tree with $$$n$$$ vertices. Recall that a tree is a connected graph without any cycles. A weighted tree is a tree in which each edge has a certain weight. The tree is undirected, it doesn't have a root.Since trees bore you, you decided to challenge yourself and play a game on the given tree.In ... | For each test case output "YES" if you can reach vertex $$$b$$$, and "NO" otherwise. | The 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 three integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$2 \leq n \leq 10^5$$$), ($$$1 \leq a, b \leq n; a \ne b$$$) — the number of vertices, and the starting and desired ending nod... | standard output | standard input | PyPy 3 | Python | 1,700 | train_101.jsonl | e8a960ceb05ec5e06169e3d76df70dfa | 256 megabytes | ["3\n\n5 1 4\n\n1 3 1\n\n2 3 2\n\n4 3 3\n\n3 5 1\n\n2 1 2\n\n1 2 2\n\n6 2 3\n\n1 2 1\n\n2 3 1\n\n3 4 1\n\n4 5 3\n\n5 6 5"] | PASSED | t = int(input())
for _ in range(t):
n, st, fi = map(int, input().split())
st -= 1
fi -= 1
g = [[] for i in range(n)]
for i in range(n - 1):
a, b, w = map(int, input().split())
a -= 1
b -= 1
g[a].append((b, w))
g[b].append((a, w))
hashesSt = []
hashesFi = []
used = [False] * n
used[fi... | 1669041300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["YES\nNO\nYES\nNO\nNO"] | 2e8f7f611ba8d417fb7d12fda22c908b | null | You are given an array $$$a$$$ consisting of $$$n$$$ integers.In one move, you can choose two indices $$$1 \le i, j \le n$$$ such that $$$i \ne j$$$ and set $$$a_i := a_j$$$. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is th... | For each test case, print the answer on it — "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases. The next $$$2t$$$ lines describe test cases. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2000$$$) — the number of elements in $$$a$$$. The second line of the test case contains ... | standard output | standard input | Python 3 | Python | 800 | train_003.jsonl | 09c9da5d0f2b22710d91c767271ea934 | 256 megabytes | ["5\n2\n2 3\n4\n2 2 8 8\n3\n3 3 3\n4\n5 5 5 5\n4\n1 1 1 1"] | PASSED | t=int(input())
for k in range(t):
n=int(input())
a=list(map(int,input().split()))
even,odd=0,0
for key in a:
if key%2:
odd+=1
else:
even+=1
if sum(a)%2 or (even and odd):
print('YES')
else:
print('NO')
| 1580826900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["Yes", "Yes", "No"] | 068e6bbfe590f4485528e85fa991ff24 | NoteThe examples are explained below. Example 1. Example 2. Example 3. | Ramesses came to university to algorithms practice, and his professor, who is a fairly known programmer, gave him the following task.You are given two matrices $$$A$$$ and $$$B$$$ of size $$$n \times m$$$, each of which consists of $$$0$$$ and $$$1$$$ only. You can apply the following operation to the matrix $$$A$$$ ar... | Print "Yes" (without quotes) if it is possible to transform the matrix $$$A$$$ to the matrix $$$B$$$ using the operations described above, and "No" (without quotes), if it is not possible. You can print each letter in any case (upper or lower). | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 500$$$) — the number of rows and the number of columns in matrices $$$A$$$ and $$$B$$$. Each of the next $$$n$$$ lines contain $$$m$$$ integers: the $$$j$$$-th integer in the $$$i$$$-th line is the $$$j$$$-th element of the $$$i$$$-th row of ... | standard output | standard input | Python 3 | Python | 1,500 | train_036.jsonl | 02adc0fd24fa584bbf9f3fe5066b4f65 | 256 megabytes | ["3 3\n0 1 0\n0 1 0\n1 0 0\n1 0 0\n1 0 0\n1 0 0", "6 7\n0 0 1 1 0 0 1\n0 1 0 0 1 0 1\n0 0 0 1 0 0 1\n1 0 1 0 1 0 0\n0 1 0 0 1 0 1\n0 1 0 1 0 0 1\n1 1 0 1 0 1 1\n0 1 1 0 1 0 0\n1 1 0 1 0 0 1\n1 0 1 0 0 1 0\n0 1 1 0 1 0 0\n0 1 1 1 1 0 1", "3 4\n0 1 0 1\n1 0 1 0\n0 1 0 1\n1 1 1 1\n1 1 1 1\n1 1 1 1"] | PASSED | n, m = map(int, input().split())
A = []
B = []
for _ in range(n):
row = list(map(int, input().split()))
A.append(row)
for _ in range(n):
row = list(map(int, input().split()))
B.append(row)
flag = 0
for i in range(n):
re = 0
for j in range(m):
if A[i][j]!=B[i][j]:
re += 1
... | 1554550500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\nAG\nAM", "8\nAT\nCH\nCY\nDG\nDO\nER\nIN\nOW", "4\nAD\nAE\nBB\nCC"] | 739f51381ed125770e61194b9bc8adb0 | NoteIn the first sample, the solution uses two sheets: the first sheet has A on one side and G on the other side; the second sheet has A on one side and M on the other side.The name AA can be spelled using the A side of both sheets. The name GA can be spelled using the G side of the first sheet and the A side of the se... | Vittorio has three favorite toys: a teddy bear, an owl, and a raccoon. Each of them has a name. Vittorio takes several sheets of paper and writes a letter on each side of every sheet so that it is possible to spell any of the three names by arranging some of the sheets in a row (sheets can be reordered and flipped as n... | The first line of the output contains a single integer $$$m$$$ — the minimum number of sheets required. Then $$$m$$$ lines follow: the $$$j$$$-th of these lines contains a string of two uppercase letters of the English alphabet — the letters appearing on the two sides of the $$$j$$$-th sheet. Note that you can print th... | The first line contains a string $$$t$$$ consisting of uppercase letters of the English alphabet ($$$1\le |t| \le 1000$$$) — the name of the teddy bear. The second line contains a string $$$o$$$ consisting of uppercase letters of the English alphabet ($$$1\le |o| \le 1000$$$) — the name of the owl. The third line conta... | standard output | standard input | PyPy 3-64 | Python | -1 | train_085.jsonl | 3cf7a776238434cd1ea41d3cfc1ad9f6 | 256 megabytes | ["AA\nGA\nMA", "TEDDY\nHEDWIG\nRACCOON", "BDC\nCAA\nCE"] | PASSED | class SegmentTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.tree = [ide_ele] * 2 * self.num
self.size = n
for i in range(n):
s... | 1650798300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["First\n2", "Second"] | f5d9490dc6e689944649820df5f23657 | NoteIn the first sample the first player has multiple winning moves. But the minimum one is to cut the character in position 2. In the second sample the first player has no available moves. | Two people play the following string game. Initially the players have got some string s. The players move in turns, the player who cannot make a move loses. Before the game began, the string is written on a piece of paper, one letter per cell. An example of the initial situation at s = "abacaba" A player's move is the... | If the second player wins, print in the single line "Second" (without the quotes). Otherwise, print in the first line "First" (without the quotes), and in the second line print the minimal possible winning move — integer i (1 ≤ i ≤ |s|). | The first line contains string s (1 ≤ |s| ≤ 5000). It is guaranteed that string s only contains lowercase English letters. | standard output | standard input | Python 2 | Python | 2,300 | train_017.jsonl | 06c42845e9bcb693cb58d286fb6ef6ce | 256 megabytes | ["abacaba", "abcde"] | PASSED | from sys import stdin
def task():
value = stdin.readline()
games = []
counter = 0
for i in xrange(1, len(value)-1):
if value[i - 1] == value[i + 1]:
counter += 1
else:
if counter > 0:
games.append(counter)
counter = 0
if counter >... | 1368968400 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
6 seconds | ["98\n128\n219\n229", "3639\n5122\n5162\n5617\n7663\n7806\n7960"] | 470ada4754e9601bc7a1548456dab8d7 | null | William has two arrays of numbers $$$a_1, a_2, \dots, a_n$$$ and $$$b_1, b_2, \dots, b_m$$$. The arrays satisfy the conditions of being convex. Formally an array $$$c$$$ of length $$$k$$$ is considered convex if $$$c_i - c_{i - 1} < c_{i + 1} - c_i$$$ for all $$$i$$$ from $$$2$$$ to $$$k - 1$$$ and $$$c_1 < c_2... | After each change, output one integer, the minimum length of the path in the constructed matrix. | The first line contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$2 \le n \le 100, 2 \le m \le 10^5$$$, $$$1 \le q \le 10^5$$$), the sizes of the arrays and the number of changes. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{12}$$$), the contents of array $$$a$$$. The... | standard output | standard input | PyPy 3-64 | Python | 3,000 | train_110.jsonl | b5a01e1e18bd101b7d29c77fd61bdac2 | 256 megabytes | ["5 3 4\n1 2 4 7 11\n5 7 10\n1 3 2\n2 2 5\n1 5 4\n2 1 7", "5 6 7\n4 9 22 118 226\n7 94 238 395 565 738\n2 1 95\n1 4 54\n1 2 5\n1 2 87\n2 6 62\n2 1 143\n1 1 77"] | PASSED | class BIT(object):
def __init__(self, n):
self.__bit = [0]*(n+1)
def add(self, i, val):
while i < len(self.__bit):
self.__bit[i] += val
i += (i & -i)
def query(self, i):
ret = 0
while i > 0:
ret += self.__bit[i]
i... | 1638110100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["0 1 0", "-1", "0 1 3 2 0", "0 1 2 4 9 3 6 13 10 5 11 7 15 14 12 8 0"] | 1563061fe7b515531238be320739564a | null | Piegirl found the red button. You have one last chance to change the inevitable end.The circuit under the button consists of n nodes, numbered from 0 to n - 1. In order to deactivate the button, the n nodes must be disarmed in a particular order. Node 0 must be disarmed first. After disarming node i, the next node to b... | Print an order in which you can to disarm all nodes. If it is impossible, print -1 instead. If there are multiple orders, print any one of them. | Input consists of a single integer n (2 ≤ n ≤ 105). | standard output | standard input | Python 3 | Python | 2,800 | train_076.jsonl | 1cff4012135320ddba5538a3c9e3ea1f | 256 megabytes | ["2", "3", "4", "16"] | PASSED | n=int(input())
if n&1:
print(-1)
else:
D,R=[False]*(10**6),[0]*(10**6)
i,j=0,0
while True:
D[j]=True
R[i]=j
i+=1
if not D[(j+n)>>1]:
j=(j+n)>>1
elif not D[j>>1]:
j=j>>1
else:
break
print(" ".join(str(R[i]) for i in range(n,-1,-1)))
| 1373734800 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["2", "545732279"] | 91749edcc396819d4172d06e2744b20b | null | Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only some of them are black. Currently Gerald is finishing a game of gia... | Print a single line — the remainder of the number of ways to move Gerald's pawn from the upper left to the lower right corner modulo 109 + 7. | The first line of the input contains three integers: h, w, n — the sides of the board and the number of black cells (1 ≤ h, w ≤ 105, 1 ≤ n ≤ 2000). Next n lines contain the description of black cells. The i-th of these lines contains numbers ri, ci (1 ≤ ri ≤ h, 1 ≤ ci ≤ w) — the number of the row and column of the i-t... | standard output | standard input | PyPy 2 | Python | 2,200 | train_019.jsonl | ee1195ece0e2f2e10a38e0517a12a6af | 256 megabytes | ["3 4 2\n2 2\n2 3", "100 100 3\n15 16\n16 15\n99 88"] | PASSED | #from sys import setrecursionlimit as srl
import sys
if sys.subversion[0] == "PyPy":
import io, atexit
sys.stdout = io.BytesIO()
atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
sys.stdin = io.BytesIO(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip()
RS = raw... | 1437573600 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["9\n17\n12\n29\n14\n3\n9"] | 4f6a929b40d24c3b64f7ab462a8f39bb | NoteIn first test case the "expansion" of the string is: 'a', 'ac', 'acb', 'acba', 'acbac', 'c', 'cb', 'cba', 'cbac', 'b', 'ba', 'bac', 'a', 'ac', 'c'. The answer can be, for example, 'a', 'ac', 'acb', 'acba', 'acbac', 'b', 'ba', 'bac', 'c'. | Morning desert sun horizonRise above the sands of time...Fates Warning, "Exodus"After crossing the Windswept Wastes, Ori has finally reached the Windtorn Ruins to find the Heart of the Forest! However, the ancient repository containing this priceless Willow light did not want to open!Ori was taken aback, but the Voice... | For every test case print one non-negative integer — the answer to the problem. | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10^3$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$1 \le n \le 5000$$$) — length of the string. The sec... | standard output | standard input | PyPy 3 | Python | 2,500 | train_086.jsonl | 970b3818ebde76ea2cc49d9e3d2ebefd | 512 megabytes | ["7\n5\nacbac\n8\nacabacba\n12\naaaaaaaaaaaa\n10\nabacabadac\n8\ndcbaabcd\n3\ncba\n6\nsparky"] | PASSED | import collections
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
s = input()
maxList = [n - index for index in range(n)]
longestCommonPrefix = [0] * (n + 1)
for index in range(n - 1, -1, -1):
for j in range(index + 1, n):
... | 1629988500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["1", "0", "13"] | a5d56056fd66713128616bc7c2de8b22 | null | Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces a... | Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. | The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile. | standard output | standard input | PyPy 2 | Python | 1,200 | train_046.jsonl | 8e19832cb294f891a89fbd7149b649c8 | 256 megabytes | ["1\n1", "1\n2", "3\n5 6 7"] | PASSED | # ///==========Libraries, Constants and Functions=============///
#mkraghav
import sys
inf = float("inf")
mod = 1000000007
def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())
def input(): return sys.stdin.readline()
def int1():return... | 1297440000 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
2 seconds | ["2\n1 2\n2 2", "-1", "5\n3 1\n1 2\n2 2\n2 3\n3 1", "-1"] | dcb55324681dd1916449570d6bc64e47 | NoteAssignment a ^= b denotes assignment a = a ^ b, where operation "^" is bitwise XOR of two integers. | There are some tasks which have the following structure: you are given a model, and you can do some operations, you should use these operations to achive the goal. One way to create a new task is to use the same model and same operations, but change the goal.Let's have a try. I have created the following task for Topco... | If there is no solution, output -1. If there is a solution, then in the first line output an integer m (0 ≤ m ≤ 1000000) – the number of assignments you need to perform. Then print m lines, each line should contain two integers i and j (1 ≤ i, j ≤ n), which denote assignment xi ^= xj. If there are multiple solutions yo... | The first line contains an integer n (1 ≤ n ≤ 10000). The second line contains n integers: x1 to xn (0 ≤ xi ≤ 109). The third line contains n integers: y1 to yn (0 ≤ yi ≤ 109). | standard output | standard input | Python 2 | Python | 2,700 | train_081.jsonl | d37018c83acc201461b7228adcd7ddec | 256 megabytes | ["2\n3 5\n6 0", "5\n0 0 0 0 0\n1 2 3 4 5", "3\n4 5 6\n1 2 3", "3\n1 2 3\n4 5 6"] | PASSED | n=int(raw_input())
x=map(int,raw_input().split())
y=map(int,raw_input().split())
cnt=0
ans1=[]
ans2=[]
bit=dict()
for i in range(30,-1,-1):
for j in range(0,n):
if x[j]&1<<i > 0 and x[j] < 1<<i+1:
if i not in bit:
bit[i] = j
else:
x[j] ^= x[bit[i]]
... | 1411918500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["9", "2", "0", "-1"] | 90f08c2c8f7575330639fdd158bc8e6b | NoteIn the first example, Charlie can move all chocolate pieces to the second box. Each box will be divisible by $$$17$$$.In the second example, Charlie can move a piece from box $$$2$$$ to box $$$3$$$ and a piece from box $$$4$$$ to box $$$5$$$. Each box will be divisible by $$$3$$$.In the third example, each box is a... | This is the harder version of the problem. In this version, $$$1 \le n \le 10^6$$$ and $$$0 \leq a_i \leq 10^6$$$. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problemsChristmas is coming, and our protagonist, Bob, is preparing a spectacular present for his l... | If there is no way for Charlie to make Alice happy, print $$$-1$$$. Otherwise, print a single integer $$$x$$$ — the minimum number of seconds for Charlie to help Bob make Alice happy. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the number of chocolate boxes. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^6$$$) — the number of chocolate pieces in the $$$i$$$-th box. It is guaranteed that at least one of $$$a_1, a_2, \ldots, a... | standard output | standard input | PyPy 3 | Python | 2,100 | train_011.jsonl | 523503f81df7e827fe66eb9c0c8c3908 | 256 megabytes | ["3\n4 8 5", "5\n3 10 2 1 5", "4\n0 5 15 10", "1\n1"] | PASSED | # 素因数分解
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n //= i
table.append(i)
i += 1
if n > 1:
table.append(n)
return table
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
# ... | 1574174100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["2\n1 2 1 1 2", "1\n1 1 1", "3\n1 1 2 3 2 3 1 3 1"] | 0cc73612bcfcd3be142064e2da9e92e3 | null | Treeland consists of $$$n$$$ cities and $$$n-1$$$ roads. Each road is bidirectional and connects two distinct cities. From any city you can get to any other city by roads. Yes, you are right — the country's topology is an undirected tree.There are some private road companies in Treeland. The government decided to sell ... | In the first line print the required $$$r$$$ ($$$1 \le r \le n - 1$$$). In the second line print $$$n-1$$$ numbers $$$c_1, c_2, \dots, c_{n-1}$$$ ($$$1 \le c_i \le r$$$), where $$$c_i$$$ is the company to own the $$$i$$$-th road. If there are multiple answers, print any of them. | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 200000, 0 \le k \le n - 1$$$) — the number of cities and the maximal number of cities which can have two or more roads belonging to one company. The following $$$n-1$$$ lines contain roads, one road per line. Each line contains a pair of integers ... | standard output | standard input | PyPy 2 | Python | 1,900 | train_005.jsonl | a80874b08b34b1330f099ec32856748b | 256 megabytes | ["6 2\n1 4\n4 3\n3 5\n3 6\n5 2", "4 2\n3 1\n1 4\n1 2", "10 2\n10 3\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n3 8\n3 9"] | PASSED | # will you survive without fast IO?
# will not stripping save you some time?
from collections import deque
n, k = map(int, raw_input().split())
g = [[] for i in xrange(n + 1)]
par = [0] * (n + 1)
deg = [0] * (n + 1)
edges = []
idx = 0
for i in xrange(n - 1):
u, v = map(int, raw_input().split())
g[u].append(v)... | 1553006100 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["1 1 1\n66 0 61\n5 5 0\n0 1001 1001\n1000000001 0 1000000001"] | f80dea1e07dba355bfbefa4ff65ff45a | null | The elections in which three candidates participated have recently ended. The first candidate received $$$a$$$ votes, the second one received $$$b$$$ votes, the third one received $$$c$$$ votes. For each candidate, solve the following problem: how many votes should be added to this candidate so that he wins the electio... | For each test case, output in a separate line three integers $$$A$$$, $$$B$$$, and $$$C$$$ ($$$A, B, C \ge 0$$$) separated by spaces — the answers to the problem for the first, second, and third candidate, respectively. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing three integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$0 \le a,b,c \le 10^9$$$). | standard output | standard input | PyPy 3-64 | Python | 800 | train_093.jsonl | a320cb4bd70d5f2c0faae617e986eae6 | 256 megabytes | ["5\n0 0 0\n10 75 15\n13 13 17\n1000 0 0\n0 1000000000 0"] | PASSED | t = int(input())
for i in range(t):
a,b,c = map(int,input().split())
if (a==b==c) == 1:
print(1,1,1)
elif a>b and a>c:
print(0,a-b+1,a-c+1)
elif b>c and b>a:
print(b-a+1,0,b-c+1)
elif c>a and c>b:
print(c-a+1,c-b+1,0)
elif a==b:
if c>a:
... | 1634135700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1", "6"] | 0090979443c294ef6aed7cd09201c9ef | null | String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (k - 1)-palindromes. By definition, any string (even empty) is 0-palindrome.Let's call the palindrome degree of string s such a maximum number k, for which s is k-palindrome. For example, "abaaba" has deg... | Output the only number — the sum of the polindrome degrees of all the string's prefixes. | The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5·106. The string is case-sensitive. | standard output | standard input | PyPy 2 | Python | 2,200 | train_081.jsonl | d1977b8ab54a2757bb115dd1bf250974 | 256 megabytes | ["a2A", "abacaba"] | PASSED | T = raw_input()
P = T + '#' + T[::-1]
def compute_prefix_func(P):
m = len(P)
pi = [0] * m
for q in range(1, m):
k = pi[q-1]
while k > 0 and P[k] != P[q]:
k = pi[k-1]
if P[k] == P[q]:
k += 1
pi[q] = k
return pi
pi = compute_prefix_func(P)
pos = ... | 1270136700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["8\n7\n5"] | df2fa3d9e5fdf23656c12416451fcdb9 | NoteIn the first test case, one of the optimal solutions is shown below: Each point was moved two times, so the answer $$$2 + 2 + 2 + 2 = 8$$$.In the second test case, one of the optimal solutions is shown below: The answer is $$$3 + 1 + 0 + 3 = 7$$$.In the third test case, one of the optimal solutions is shown b... | You are given four different integer points $$$p_1$$$, $$$p_2$$$, $$$p_3$$$ and $$$p_4$$$ on $$$\mathit{XY}$$$ grid.In one step you can choose one of the points $$$p_i$$$ and move it in one of four directions by one. In other words, if you have chosen point $$$p_i = (x, y)$$$ you can move it to $$$(x, y + 1)$$$, $$$(x,... | For each test case, print the single integer — the minimum number of steps to make a square. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of four lines. Each line contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 10^9$$$) — coordinates of one of the points $$$p_i = (x, y)$$$. All points are different in one test case. | standard output | standard input | Python 3 | Python | null | train_021.jsonl | 14dd7aa5015394112e0776c0afefcf6b | 256 megabytes | ["3\n0 2\n4 2\n2 0\n2 4\n1 0\n2 0\n4 0\n6 0\n1 6\n2 2\n2 5\n4 1"] | PASSED | T = int(input());ans = [0]*T
for t in range(T):
X,Y = [0]*4,[0]*4;A = [0]*4
for i in range(4):X[i],Y[i] = map(int, input().split());A[i] = [X[i], Y[i]]
X.sort(); Y.sort(); A.sort();cnt = 0
for i in range(2):
rank = 1
for j in range(4):
if A[i][1] < A[j][1]:rank += 1
i... | 1606746900 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
6 seconds | ["5", "25", "793019428", "94810539"] | 77443424be253352aaf2b6c89bdd4671 | NoteIn the first test, there are three ways to move the token from cell $$$3$$$ to cell $$$1$$$ in one shift: using subtraction of $$$y = 2$$$, or using division by $$$z = 2$$$ or $$$z = 3$$$.There are also two ways to move the token from cell $$$3$$$ to cell $$$1$$$ via cell $$$2$$$: first subtract $$$y = 1$$$, and th... | Note that the memory limit in this problem is lower than in others.You have a vertical strip with $$$n$$$ cells, numbered consecutively from $$$1$$$ to $$$n$$$ from top to bottom.You also have a token that is initially placed in cell $$$n$$$. You will move the token up until it arrives at cell $$$1$$$.Let the token be ... | Print the number of ways to move the token from cell $$$n$$$ to cell $$$1$$$, modulo $$$m$$$. | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 4 \cdot 10^6$$$; $$$10^8 < m < 10^9$$$; $$$m$$$ is a prime number) — the length of the strip and the modulo. | standard output | standard input | PyPy 3 | Python | 1,900 | train_100.jsonl | bbab8ef7c5efe2eb878aa74f4a613178 | 128 megabytes | ["3 998244353", "5 998244353", "42 998244353", "787788 100000007"] | PASSED | import sys
from array import array
input = sys.stdin.readline
def ri(): return [int(i) for i in input().split()]
def rs(): return input().split()[0]
def main():
t = 1
for _ in range(t):
n, m = ri()
sum = [0] * (n + 2) # ans[x] + ... + ans[n]
sum[n] = 1
sum[n + 1] = 0
... | 1629815700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["? C\n\n? CH\n\n? CCHO\n\n! CCHH", "? O\n\n? HHH\n\n! CHHHH\n\n\n? COO\n\n? COOH\n\n? HCCOO\n\n? HH\n\n! HHHCCOOH"] | ecd8c5d7f869cabe35cc9bbdbfb8e00c | NoteNote that the example interaction contains extra empty lines so that it's easier to read. The real interaction doesn't contain any empty lines and you shouldn't print any extra empty lines as well. | MisoilePunch♪ - 彩This is an interactive problem!On a normal day at the hidden office in A.R.C. Markland-N, Rin received an artifact, given to her by the exploration captain Sagar.After much analysis, she now realizes that this artifact contains data about a strange flower, which has existed way before the New Age. Howe... | null | null | standard output | standard input | Python 3 | Python | 3,500 | train_014.jsonl | 1b991933f1d5f39e3f8b8604bdebd60e | 256 megabytes | ["1\n4\n\n2 1 2\n\n1 2\n\n0\n\n1", "2\n5\n\n0\n\n2 2 3\n\n1\n8\n\n1 5\n\n1 5\n\n1 3\n\n2 1 2\n\n1"] | PASSED |
import sys
n, L, minID = None, None, None
s = []
def fill(id, c):
global n, L, s, minID
L -= (s[id] == 'L')
s = s[0:id] + c + s[ id +1:]
minID = min(minID, id)
def query(cmd, str):
global n, L, s, minID
print(cmd, ''.join(str))
print(cmd, ''.join(str), file=sys.stderr)
sys.stdout.flus... | 1579440900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n1\n2\n2"] | ec89860dacb5a11b3a2273d2341b07a1 | NoteIn the third case, he can connect two sticks with lengths $$$1$$$ and $$$2$$$ and he will get one stick with length $$$3$$$. So, he will have two sticks with lengths $$$3$$$.In the fourth case, he can connect two sticks with lengths $$$1$$$ and $$$3$$$ and he will get one stick with length $$$4$$$. After that, he w... | A penguin Rocher has $$$n$$$ sticks. He has exactly one stick with length $$$i$$$ for all $$$1 \le i \le n$$$.He can connect some sticks. If he connects two sticks that have lengths $$$a$$$ and $$$b$$$, he gets one stick with length $$$a + b$$$. Two sticks, that were used in the operation disappear from his set and the... | For each test case, print a single integer — the answer to the problem. | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case, the only line contains a single integer $$$n$$$ ($$$1 \le n \le 10^{9}$$$). | standard output | standard input | PyPy 3 | Python | 800 | train_001.jsonl | f4fa89559ce4954c97800c40b63d31d1 | 256 megabytes | ["4\n1\n2\n3\n4"] | PASSED | n=input("")
cases=[]
for _ in range(int(n)):
t=input("")
cases.append(int(t))
answers=[]
def f(n):
if n%2==0:
return n//2
else:
return (n//2) +1
for case in cases:
answers.append(f(case))
for a in answers:
print(a)
| 1593610500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nYES"] | d40f0f3b577a1a5cfad2a657d6a1b90a | NoteIn the first test case, the strings are initially $$$s = $$$ "a" and $$$t = $$$ "a". After the first operation the string $$$t$$$ becomes "aaa". Since "a" is already lexicographically smaller than "aaa", the answer for this operation should be "YES".After the second operation string $$$s$$$ becomes "aaa", and since... | Alperen has two strings, $$$s$$$ and $$$t$$$ which are both initially equal to "a". He will perform $$$q$$$ operations of two types on the given strings: $$$1 \;\; k \;\; x$$$ — Append the string $$$x$$$ exactly $$$k$$$ times at the end of string $$$s$$$. In other words, $$$s := s + \underbrace{x + \dots + x}_{k \text... | For each operation, output "YES", if it is possible to arrange the elements in both strings in such a way that $$$s$$$ is lexicographically smaller than $$$t$$$ and "NO" otherwise. | The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The first line of each test case contains an integer $$$q$$$ $$$(1 \leq q \leq 10^5)$$$ — the number of operations Alperen will perform. Then $$$q$$$ lines follow, each containing two positive integers $$$d$$$... | standard output | standard input | PyPy 3 | Python | 1,500 | train_099.jsonl | 35f86d32c4db95018faf9b9924f0fb96 | 256 megabytes | ["3\n\n5\n\n2 1 aa\n\n1 2 a\n\n2 3 a\n\n1 2 b\n\n2 3 abca\n\n2\n\n1 5 mihai\n\n2 2 buiucani\n\n3\n\n1 5 b\n\n2 3 a\n\n2 4 paiu"] | PASSED | t = int(input())
for _ in range(t):
q = int(input())
s_a_count = 1
t_a_count = 1
other_than_a_t = False
other_than_a_s = False
for _ in range(q):
line = list(map(str, input().rstrip().split()))
if line[0] == '2':
for char in line[2]:
... | 1665671700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["11\n20\n3"] | ee32db8e7cdd9561d9215651ff8a262e | NoteIn the first test case: you should take $$$3$$$ swords and $$$3$$$ war axes: $$$3 \cdot 5 + 3 \cdot 6 = 33 \le 33$$$ and your follower — $$$3$$$ swords and $$$2$$$ war axes: $$$3 \cdot 5 + 2 \cdot 6 = 27 \le 27$$$. $$$3 + 3 + 3 + 2 = 11$$$ weapons in total.In the second test case, you can take all available wea... | You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course.You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $$$p$$$ units and your follower — at most $$$f$... | For each test case, print the maximum number of weapons (both swords and war axes) you and your follower can carry. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains two integers $$$p$$$ and $$$f$$$ ($$$1 \le p, f \le 10^9$$$) — yours and your follower's capacities. The second line of each test case contains two integers $$$cnt_s$$$ and $$$... | standard output | standard input | Python 3 | Python | 1,700 | train_011.jsonl | cf15903dc834983b43574a24cc3a3abf | 256 megabytes | ["3\n33 27\n6 10\n5 6\n100 200\n10 10\n5 5\n1 19\n1 3\n19 5"] | PASSED | def controller(p, f, cnt_s, cnt_w, s, w):
def proc(cap_p, cap_f, cnt, weight):
sp, sf = cap_p//weight, cap_f//weight
if cnt >= sp + sf:
return (0, sp, sf) # if total == 0, then total == sp + sf
sp, sf = min(cnt,sp), min(cnt,sf)
return (cnt, sp, sf)
if s > w:
... | 1598366100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n0\n1\n0\n2\n1 1\n4\n1 1 0 0"] | eca92beb189c4788e8c4744af1428bc7 | NoteIn the first and second cases, alternating sum of the array, obviously, equals $$$0$$$.In the third case, alternating sum of the array equals $$$1 - 1 = 0$$$.In the fourth case, alternating sum already equals $$$1 - 1 + 0 - 0 = 0$$$, so we don't have to remove anything. | Alexandra has an even-length array $$$a$$$, consisting of $$$0$$$s and $$$1$$$s. The elements of the array are enumerated from $$$1$$$ to $$$n$$$. She wants to remove at most $$$\frac{n}{2}$$$ elements (where $$$n$$$ — length of array) in the way that alternating sum of the array will be equal $$$0$$$ (i.e. $$$a_1 - a_... | For each test case, firstly, print $$$k$$$ ($$$\frac{n}{2} \leq k \leq n$$$) — number of elements that will remain after removing in the order they appear in $$$a$$$. Then, print this $$$k$$$ numbers. Note that you should print the numbers themselves, not their indices. We can show that an answer always exists. If ther... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^3$$$, $$$n$$$ is even) — length of the array. The second line contains ... | standard output | standard input | Python 2 | Python | 1,100 | train_008.jsonl | 36e966f0809dc2974f0ff34a42979980 | 256 megabytes | ["4\n2\n1 0\n2\n0 0\n4\n0 1 1 1\n4\n1 1 0 0"] | PASSED | def solve():
n = int(raw_input())
a = map(int, raw_input().split())
c = sum(a)
m = n / 2
if n - c >= m:
b = [0] * m
else:
b = [1] * ((m + 1) / 2) * 2
print len(b)
for x in b:
print x,
print
T = int(raw_input())
for t in xrange(T):
solve()
| 1599575700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"] | a017393743ae70a4d8a9d9dc40410653 | null | Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck! | Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and brin... | The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000. | standard output | standard input | PyPy 3 | Python | 1,200 | train_005.jsonl | 7790035c00258e3549f7ea34503da575 | 64 megabytes | ["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"] | PASSED | from sys import stdin
lines = list(map(lambda _: _.strip(), stdin.readlines()))
max_len = max(list(map(len, lines)))
print((max_len + 2) * '*')
left = 0
for line in lines:
pad = max_len - len(line)
if pad % 2 != 0:
left_pad = pad // 2 + left
left = 1 - left
else:
left_pad = pad // 2
right_pad = pad - l... | 1269100800 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["3", "2", "-1"] | 07600ef3a0e1d216699648b2d17189e8 | NoteIn the first sample the tree is split into $$$\{1\},\ \{2\},\ \{3\}$$$.In the second sample the tree is split into $$$\{1,\ 2\},\ \{3\}$$$ or $$$\{1,\ 3\},\ \{2\}$$$.In the third sample it is impossible to split the tree. | You are given a rooted tree on $$$n$$$ vertices, its root is the vertex number $$$1$$$. The $$$i$$$-th vertex contains a number $$$w_i$$$. Split it into the minimum possible number of vertical paths in such a way that each path contains no more than $$$L$$$ vertices and the sum of integers $$$w_i$$$ on each path does n... | Output one number — the minimum number of vertical paths. If it is impossible to split the tree, output $$$-1$$$. | The first line contains three integers $$$n$$$, $$$L$$$, $$$S$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le L \le 10^5$$$, $$$1 \le S \le 10^{18}$$$) — the number of vertices, the maximum number of vertices in one path and the maximum sum in one path. The second line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$1 \... | standard output | standard input | Python 3 | Python | 2,400 | train_059.jsonl | 5112c44c5a4f5f64d2f1154cebd5954f | 256 megabytes | ["3 1 3\n1 2 3\n1 1", "3 3 6\n1 2 3\n1 1", "1 1 10000\n10001"] | PASSED | def solve(n, l, s, www, children):
ans = 0
dp = [{} for _ in range(n)]
for v in range(n - 1, -1, -1):
cv = children[v]
if not cv:
dp[v][1] = www[v]
continue
ans += len(cv) - 1
wv = www[v]
if wv > s:
return -1
dv = dp[v]
... | 1538750100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
4.5 seconds | ["2 4\n4 10\n1 3"] | 55c692d380a4d1c0478ceb7cffde342f | NoteExplanation of the sample:At the first query, the tree consist of root, so we purchase $$$2$$$ tons of gold and pay $$$2 \cdot 2 = 4$$$. $$$3$$$ tons remain in the root.At the second query, we add vertex $$$2$$$ as a son of vertex $$$0$$$. Vertex $$$2$$$ now has $$$3$$$ tons of gold with price $$$4$$$ per one ton.A... | You are given a rooted tree. Each vertex contains $$$a_i$$$ tons of gold, which costs $$$c_i$$$ per one ton. Initially, the tree consists only a root numbered $$$0$$$ with $$$a_0$$$ tons of gold and price $$$c_0$$$ per ton.There are $$$q$$$ queries. Each query has one of two types: Add vertex $$$i$$$ (where $$$i$$$ i... | For each query of the second type, print the resulting amount of gold we bought and the minimum amount of money we should spend. | The first line contains three integers $$$q$$$, $$$a_0$$$ and $$$c_0$$$ ($$$1 \le q \le 3 \cdot 10^5$$$; $$$1 \le a_0, c_0 < 10^6$$$) — the number of queries, the amount of gold in the root and its price. Next $$$q$$$ lines contain descriptions of queries; The $$$i$$$-th query has one of two types: "$$$1$$$ $$$p_... | standard output | standard input | PyPy 3 | Python | 2,200 | train_085.jsonl | 41909de309b27273ee1583a0da8c5cc0 | 256 megabytes | ["5 5 2\n2 0 2\n1 0 3 4\n2 2 4\n1 0 1 3\n2 4 2"] | PASSED | from array import array
import math
import os
import sys
input = sys.stdin.buffer.readline
q, a0, c0 = map(int, input().split())
mod = pow(10, 9) + 7
n = q + 5
pow2 = [1]
for _ in range(20):
pow2.append(2 * pow2[-1])
cnt = [0] * n
cost = [0] * n
cnt[0], cost[0] = a0, c0
dp = array("l", [-1] * (20 * ... | 1622817300 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["1 6\n2 6\n3 5\n3 6\n4 5", "1 6\n1 7\n2 6\n3 5\n3 6\n4 5\n7 8", "1 3\n2 3\n3 5\n4 5\n5 7\n6 7\n7 12\n8 12\n9 11\n9 12\n10 11", "1 2\n1 4\n3 4"] | 61bb5f2b315eddf2e658e3f54d8f43b8 | Note Answer for the first sample test. Answer for the second sample test. | It's Petya's birthday party and his friends have presented him a brand new "Electrician-$$$n$$$" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him.Construction set "Electrician-$$$n$$$" consists of $$$2n - 1$$$ wires and $$$2n$$$ light bulbs. Each bulb has its own un... | Print $$$2n - 1$$$ lines. The $$$i$$$-th of them should contain two distinct integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq 2n$$$, $$$a_i \ne b_i$$$) — indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. | The first line of the input contains a single integer $$$n$$$ ($$$1 \leq n \leq 100\,000$$$) — the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$ ($$$1 \leq d_i \leq n$$$), where $$$d_i$$$ stands for the number of... | standard output | standard input | Python 3 | Python | 2,000 | train_022.jsonl | 2e635e3e95195018a786084468e20aa5 | 512 megabytes | ["3\n2 2 2", "4\n2 2 2 1", "6\n2 2 2 2 2 2", "2\n1 1"] | PASSED | # https://codeforces.com/contest/1214/problem/E
n = int(input())
d = map(int, input().split())
d = [[2*i+1, di] for i, di in enumerate(d)]
d = sorted(d, key=lambda x:x[1], reverse = True)
edge = []
arr = [x[0] for x in d]
for i, [x, d_] in enumerate(d):
if i + d_ - 1 == len(arr) - 1:
arr.append(x+1)
... | 1567587900 | [
"math",
"trees",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
1
] | |
2 seconds | ["750000007", "125000003"] | a44cba5685500b16e24b8fba30451bc5 | NoteThe answer for the first sample is equal to $$$\frac{14}{8}$$$.The answer for the second sample is equal to $$$\frac{17}{8}$$$. | Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only $$$T$$$ seconds after coming. Fortunately, Adilbek can spend time w... | Print one integer — the expected value of the number of crosswords Adilbek solves in $$$T$$$ seconds, expressed in the form of $$$P \cdot Q^{-1} \bmod (10^9 + 7)$$$. | The first line contains two integers $$$n$$$ and $$$T$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le T \le 2 \cdot 10^{14}$$$) — the number of crosswords and the time Adilbek has to spend, respectively. The second line contains $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$1 \le t_i \le 10^9$$$), where $$$t_i$$$ is the... | standard output | standard input | PyPy 2 | Python | 2,400 | train_001.jsonl | 81bda70b1f577dfe53f0cb3c1bd9d668 | 256 megabytes | ["3 5\n2 2 2", "3 5\n2 1 2"] | PASSED | MOD = 10 ** 9 + 7
MAX = 5 * 10 ** 5
fac, ifac, ipow2 = [1] * MAX, [1] * MAX, [1] * MAX
for i in range(1, MAX):
fac[i] = fac[i - 1] * i % MOD
ifac[i] = pow(fac[i], MOD - 2, MOD)
ipow2[i] = ipow2[i - 1] * (MOD + 1) // 2 % MOD
choose = lambda n, k: fac[n] * ifac[k] % MOD * ifac[n - k] % MOD
n, t = map(int, raw... | 1563115500 | [
"probabilities",
"number theory"
] | [
0,
0,
0,
0,
1,
1,
0,
0
] | |
2 seconds | ["4\n0\n6\n3\n6"] | ebf0bf949a29eeaba3bcc35091487199 | NoteQuestions about the optimal strategy will be ignored. | Alice and Bob play a game. They have a binary string $$$s$$$ (a string such that each character in it is either $$$0$$$ or $$$1$$$). Alice moves first, then Bob, then Alice again, and so on.During their move, the player can choose any number (not less than one) of consecutive equal characters in $$$s$$$ and delete them... | For each test case, print one integer — the resulting score of Alice (the number of $$$1$$$-characters deleted by her). | The first line contains one integer $$$T$$$ ($$$1 \le T \le 500$$$) — the number of test cases. Each test case contains exactly one line containing a binary string $$$s$$$ ($$$1 \le |s| \le 100$$$). | standard output | standard input | Python 3 | Python | 800 | train_002.jsonl | e9974cd0511c658c8bd6ff0266080b81 | 256 megabytes | ["5\n01111001\n0000\n111111\n101010101\n011011110111"] | PASSED | t = int(input())
for _ in range(t):
s = sorted(input().split('0'), reverse=True)[::2]
res = sum(list(map(len, s)))
print(res)
| 1597415700 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["2 1 3", "-1", "2 5 1 3 4"] | f9c6ef39752d1da779e07c27dff918a9 | NoteIn the first example, Johnny starts with writing blog number $$$2$$$, there are no already written neighbors yet, so it receives the first topic. Later he writes blog number $$$1$$$, it has reference to the already written second blog, so it receives the second topic. In the end, he writes blog number $$$3$$$, it h... | Today Johnny wants to increase his contribution. His plan assumes writing $$$n$$$ blogs. One blog covers one topic, but one topic can be covered by many blogs. Moreover, some blogs have references to each other. Each pair of blogs that are connected by a reference has to cover different topics because otherwise, the re... | If the solution does not exist, then write $$$-1$$$. Otherwise, output $$$n$$$ distinct integers $$$p_1, p_2, \ldots, p_n$$$ $$$(1 \leq p_i \leq n)$$$, which describe the numbers of blogs in order which Johnny should write them. If there are multiple answers, print any. | The first line contains two integers $$$n$$$ $$$(1 \leq n \leq 5 \cdot 10^5)$$$ and $$$m$$$ $$$(0 \leq m \leq 5 \cdot 10^5)$$$ — the number of blogs and references, respectively. Each of the following $$$m$$$ lines contains two integers $$$a$$$ and $$$b$$$ ($$$a \neq b$$$; $$$1 \leq a, b \leq n$$$), which mean that the... | standard output | standard input | PyPy 3 | Python | 1,700 | train_009.jsonl | 290a82cd8acafaf3e81dab446a4fb100 | 256 megabytes | ["3 3\n1 2\n2 3\n3 1\n2 1 3", "3 3\n1 2\n2 3\n3 1\n1 1 1", "5 3\n1 2\n2 3\n4 5\n2 1 2 2 1"] | PASSED | '''import os,io
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
I= lambda: list(map(int,input().split()))'''
import os,io
from sys import stdout
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
I=lambda:list(map(int,input().split()))
n,edge=I()
go=[[] for _ in range(n+1)]
for _ in range(edge): ... | 1591281300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["13 2", "-1", "3 4"] | 8e8437c62ea72f01f7e921e99dca931f | null | Little Timofey likes integers a lot. Unfortunately, he is very young and can't work with very big integers, so he does all the operations modulo his favorite prime m. Also, Timofey likes to look for arithmetical progressions everywhere.One of his birthday presents was a sequence of distinct integers a1, a2, ..., an. Ti... | Print -1 if it is not possible to rearrange the elements of the sequence so that is will be an arithmetical progression modulo m. Otherwise, print two integers — the first element of the obtained progression x (0 ≤ x < m) and its difference d (0 ≤ d < m). If there are multiple answers, print any of them. | The first line contains two integers m and n (2 ≤ m ≤ 109 + 7, 1 ≤ n ≤ 105, m is prime) — Timofey's favorite prime module and the length of the sequence. The second line contains n distinct integers a1, a2, ..., an (0 ≤ ai < m) — the elements of the sequence. | standard output | standard input | Python 3 | Python | 2,600 | train_058.jsonl | 7bab6dfbf20b5857223dbbe23ec88431 | 256 megabytes | ["17 5\n0 2 4 13 15", "17 5\n0 2 4 13 14", "5 3\n1 2 3"] | PASSED | def solve(n, m, a):
if n == 0:
return 0, 1
if n == 1:
return a[0], 1
d = (a[1]-a[0]) % m
if d < 0: d += m
st = set(a)
cnt = 0
for v in a:
cnt += ((v + d) % m) in st
cnt = n-cnt
d = (d * pow(cnt, m-2, m)) % m
now = a[0]
while (now + m - d) % m in st:
... | 1486042500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["YES\n10 50 60\nYES\n169 39 208\nYES\n28 154 182"] | f10aa45956e930df3df0e23f2592c8f1 | NoteIn the first test case: $$$60$$$ — good number; $$$10$$$ and $$$50$$$ — nearly good numbers.In the second test case: $$$208$$$ — good number; $$$169$$$ and $$$39$$$ — nearly good numbers.In the third test case: $$$154$$$ — good number; $$$28$$$ and $$$182$$$ — nearly good numbers. | Nastia has $$$2$$$ positive integers $$$A$$$ and $$$B$$$. She defines that: The integer is good if it is divisible by $$$A \cdot B$$$; Otherwise, the integer is nearly good, if it is divisible by $$$A$$$. For example, if $$$A = 6$$$ and $$$B = 4$$$, the integers $$$24$$$ and $$$72$$$ are good, the integers $$$6$$$, $... | For each test case print: "YES" and $$$3$$$ different positive integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^{18}$$$) such that exactly one of them is good and the other $$$2$$$ are nearly good, and $$$x + y = z$$$. "NO" if no answer exists. YES NO If there are multiple answers, print any. | 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 two integers $$$A$$$ and $$$B$$$ ($$$1 \le A \le 10^6$$$, $$$1 \le B \le 10^6$$$) — numbers that Nastia has. | standard output | standard input | Python 3 | Python | 1,000 | train_099.jsonl | f0205bc518a93d63a5cbb478101adf5d | 256 megabytes | ["3\n5 3\n13 2\n7 11"] | PASSED | for _ in range(int(input())):
a,b=map(int,input().split())
x=a*b*2
y=x-a
z=a
if y+z==x and y!=z:
print('YES')
print(y,z,x)
else:
print('NO')
| 1620398100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["Mike\nAnn\nAnn\nMike", "Mike\nMike\nMike"] | 1e107d9fb8bead4ad942b857685304c4 | null | Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and... | Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally | The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters. | null | null | Python 3 | Python | 1,300 | train_004.jsonl | 4cb1087356c162969187cfe58df931d9 | 256 mebibytes | ["abba", "cba"] | PASSED | str = input()
min = str[0]
print('Mike')
for i in range(1, len(str)):
if str[i] > min:
print('Ann')
else:
min = str[i]
print('Mike')
| 1568822700 | [
"games",
"strings"
] | [
1,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["4\n9\n2\n12\n3\n1"] | 2b757fa66ce89046fe18cdfdeafa6660 | NoteIn the first test case, one of the optimal solutions is: Divide $$$a$$$ by $$$b$$$. After this operation $$$a = 4$$$ and $$$b = 2$$$. Divide $$$a$$$ by $$$b$$$. After this operation $$$a = 2$$$ and $$$b = 2$$$. Increase $$$b$$$. After this operation $$$a = 2$$$ and $$$b = 3$$$. Divide $$$a$$$ by $$$b$$$. After ... | You have two positive integers $$$a$$$ and $$$b$$$.You can perform two kinds of operations: $$$a = \lfloor \frac{a}{b} \rfloor$$$ (replace $$$a$$$ with the integer part of the division between $$$a$$$ and $$$b$$$) $$$b=b+1$$$ (increase $$$b$$$ by $$$1$$$) Find the minimum number of operations required to make $$$a=0$... | For each test case, print a single integer: the minimum number of operations required to make $$$a=0$$$. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The only line of the description of each test case contains two integers $$$a$$$, $$$b$$$ ($$$1 \le a,b \le 10^9$$$). | standard output | standard input | Python 3 | Python | 1,000 | train_092.jsonl | 78a09ee5fffd23419b136d1677624f6c | 256 megabytes | ["6\n9 2\n1337 1\n1 1\n50000000 4\n991026972 997\n1234 5678"] | PASSED | def count_divs(a, b):
count = 0
while a > 0:
a = a // b
count += 1
return count
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
b_additions = 0
if b == 1:
b = 2
b_additions += 1
prev_res = count_divs(a, b) + b_additions
... | 1613141400 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["Yes\n4 5 16 11 64 44", "Yes\n100 9900", "No"] | d07730b7bbbfa5339ea24162df7a5cab | NoteIn the first example $$$x_1=4$$$ $$$x_1+x_2=9$$$ $$$x_1+x_2+x_3=25$$$ $$$x_1+x_2+x_3+x_4=36$$$ $$$x_1+x_2+x_3+x_4+x_5=100$$$ $$$x_1+x_2+x_3+x_4+x_5+x_6=144$$$ All these numbers are perfect squares.In the second example, $$$x_1=100$$$, $$$x_1+x_2=10000$$$. They are all perfect squares. There're other answers... | Chouti is working on a strange math problem.There was a sequence of $$$n$$$ positive integers $$$x_1, x_2, \ldots, x_n$$$, where $$$n$$$ is even. The sequence was very special, namely for every integer $$$t$$$ from $$$1$$$ to $$$n$$$, $$$x_1+x_2+...+x_t$$$ is a square of some integer number (that is, a perfect square).... | If there are no possible sequence, print "No". Otherwise, print "Yes" and then $$$n$$$ positive integers $$$x_1, x_2, \ldots, x_n$$$ ($$$1 \le x_i \le 10^{13}$$$), where $$$x_2, x_4, \ldots, x_n$$$ should be same as in input data. If there are multiple answers, print any. Note, that the limit for $$$x_i$$$ is larger th... | The first line contains an even number $$$n$$$ ($$$2 \le n \le 10^5$$$). The second line contains $$$\frac{n}{2}$$$ positive integers $$$x_2, x_4, \ldots, x_n$$$ ($$$1 \le x_i \le 2 \cdot 10^5$$$). | standard output | standard input | Python 3 | Python | 1,900 | train_010.jsonl | 295cae8f4b7e32124a2ccab0c71df4fc | 256 megabytes | ["6\n5 11 44", "2\n9900", "6\n314 1592 6535"] | 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 __future__ import divisi... | 1544970900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
4 seconds | ["5\n9\n0\n117"] | f760f108c66f695e1e51dc6470d29ce7 | NoteLet $$$f(l, r)$$$ denote the extreme value of $$$[a_l, a_{l+1}, \ldots, a_r]$$$.In the first test case, $$$f(1, 3) = 3$$$, because YouKn0wWho can perform the following operations on the subarray $$$[5, 4, 3]$$$ (the newly inserted elements are underlined):$$$[5, 4, 3] \rightarrow [\underline{3}, \underline{2}, 4,... | For an array $$$b$$$ of $$$n$$$ integers, the extreme value of this array is the minimum number of times (possibly, zero) the following operation has to be performed to make $$$b$$$ non-decreasing: Select an index $$$i$$$ such that $$$1 \le i \le |b|$$$, where $$$|b|$$$ is the current length of $$$b$$$. Replace $$$b... | For each test case, print a single integer — the sum of extreme values of all subarrays of $$$a$$$ modulo $$$998\,244\,353$$$. | 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$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^5$$$). It is ... | standard output | standard input | PyPy 3-64 | Python | 2,300 | train_083.jsonl | cd8b9a9239ea0a48ac46b570813b99fb | 256 megabytes | ["4\n3\n5 4 3\n4\n3 2 1 4\n1\n69\n8\n7264 40515 28226 92776 35285 21709 75124 48163"] | PASSED | import sys
input = sys.stdin.readline
MOD = 998244353
t=int(input())
for _ in range(t):
n = int(input())
A = list(map(int, input().split()))
cnt = {}
ans = 0
for l in range(n - 1, -1, -1):
cnt2 = {}
a = A[l]
for k, v in cnt.items():
tmp = ... | 1635604500 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
2 seconds | ["YES\n8 10 8", "NO"] | 15aa3adb14c17023f71eec11e1c32efe | null | Xenia has a set of weights and pan scales. Each weight has an integer weight from 1 to 10 kilos. Xenia is going to play with scales and weights a little. For this, she puts weights on the scalepans, one by one. The first weight goes on the left scalepan, the second weight goes on the right scalepan, the third one goes ... | In the first line print "YES", if there is a way to put m weights on the scales by all rules. Otherwise, print in the first line "NO". If you can put m weights on the scales, then print in the next line m integers — the weights' weights in the order you put them on the scales. If there are multiple solutions, you can p... | The first line contains a string consisting of exactly ten zeroes and ones: the i-th (i ≥ 1) character in the line equals "1" if Xenia has i kilo weights, otherwise the character equals "0". The second line contains integer m (1 ≤ m ≤ 1000). | standard output | standard input | Python 3 | Python | 1,700 | train_001.jsonl | a7578778b2b485fe53759e7fdf156656 | 256 megabytes | ["0000000101\n3", "1000000000\n2"] | PASSED | def solve(a, b, m, M, weights, last, solution):
# print(a,b,m,M,weights, solution)
if (a-b > 10):
return False
if m == M:
print("YES")
print(*solution)
return True
for w in weights:
if w != last and b+w > a:
solution[m] = w
if (solve(b+w, a, m+1, M, weights, w, solution)):
... | 1377531000 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["WIN", "WIN", "LOSE"] | d66c7774acb7e4b1f5da105dfa5c1d36 | NoteIn the first example, there are 3 possible cells for the first city to reclaim: (2, 1), (3, 1), or (3, 2). The first two possibilities both lose, as they leave exactly one cell for the other city. However, reclaiming the cell at (3, 2) leaves no more cells that can be reclaimed, and therefore the first city wins. ... | In a far away land, there are two cities near a river. One day, the cities decide that they have too little space and would like to reclaim some of the river area into land.The river area can be represented by a grid with r rows and exactly two columns — each cell represents a rectangular area. The rows are numbered 1 ... | Output "WIN" if the city whose turn it is to choose a cell can guarantee that they will be the last to choose a cell. Otherwise print "LOSE". | The first line consists of two integers r and n (1 ≤ r ≤ 100, 0 ≤ n ≤ r). Then n lines follow, describing the cells that were already reclaimed. Each line consists of two integers: ri and ci (1 ≤ ri ≤ r, 1 ≤ ci ≤ 2), which represent the cell located at row ri and column ci. All of the lines describing the cells will be... | standard output | standard input | Python 3 | Python | 2,100 | train_002.jsonl | 9fd1ed24d0de81efd4964e6f88630e77 | 256 megabytes | ["3 1\n1 1", "12 2\n4 1\n8 1", "1 1\n1 2"] | PASSED | r,n = [int(x) for x in input().split()]
cells = [[int(x) for x in input().split()] for i in range(n)]
cells.sort()
#print(cells)
out = False
res = {True:"WIN",False:"LOSE"}
if len(cells) == 0: print(res[r%2 == 1])
else:
out = False
#print(cells[0][0] > 1)
#print(cells[-1][0] < r)
for i in range(1,n):
... | 1375549200 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
3 seconds | ["0 2\n2 4\n4 6", "0 2\n2 10"] | 3088bbe6ff34570ff798d6e3735deda3 | NoteIn the first example, it is possible to make all segments equal. Viva la revolucion! In the second example, citizens live close to the capital, so the length of the shortest segment is 2 and the length of the longest segment is 8. | A revolution has recently happened in Segmentland. The new government is committed to equality, and they hired you to help with land redistribution in the country.Segmentland is a segment of length $$$l$$$ kilometers, with the capital in one of its ends. There are $$$n$$$ citizens in Segmentland, the home of $$$i$$$-th... | Output $$$n$$$ pairs of numbers $$$s_i, f_i$$$ ($$$0 \leq s_i < f_i \leq l$$$), one pair per line. The pair on $$$i$$$-th line denotes the ends of the $$$[s_i, f_i]$$$ segment that $$$i$$$-th citizen receives. If there are many possible arrangements with the same difference between the lengths of the longest and the... | The first line of the input contains two integers $$$l$$$ and $$$n$$$ ($$$2 \leq l \leq 10^9; 1 \leq n \leq 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 < a_1 < a_2 < \dots < a_n < l$$$). | standard output | standard input | PyPy 3-64 | Python | 2,500 | train_091.jsonl | f663c16730040e6b6c3e71fab5722df6 | 512 megabytes | ["6 3\n1 3 5", "10 2\n1 2"] | PASSED | import io
import os
import heapq
from collections import deque, Counter
FILE_INPUT_MODE = 0 # 0 for BytesIO, 1 for input.txt, -1 for stdin, input()
if FILE_INPUT_MODE >= 0:
if FILE_INPUT_MODE == 1:
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
FD = os.open(f"{CURRENT_DIR... | 1649837100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["0 0 1 2 0 1 \n0 0 \n0 0 2 1 1 0"] | 94f1b5a8dfd54bcc1a4150414a48c6dd | null | There are $$$n$$$ cities in Berland. The city numbered $$$1$$$ is the capital. Some pairs of cities are connected by a one-way road of length 1.Before the trip, Polycarp for each city found out the value of $$$d_i$$$ — the shortest distance from the capital (the $$$1$$$-st city) to the $$$i$$$-th city.Polycarp begins h... | For each test case, on a separate line output $$$n$$$ numbers, the $$$i$$$-th of which is equal to the minimum possible distance from the capital to the city where Polycarp ended his journey. | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case is preceded by an empty line. The first line of each test case contains two integers $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) and $$$m$$$ ($$$1 \leq m \leq 2 \cdot 10^5$$$)... | standard output | standard input | PyPy 3-64 | Python | 2,100 | train_090.jsonl | ec81a48098744f3939ece12727ce81d5 | 256 megabytes | ["3\n\n6 7\n1 2\n1 3\n2 5\n2 4\n5 1\n3 6\n6 2\n\n2 2\n1 2\n2 1\n\n6 8\n1 2\n1 5\n2 6\n6 1\n2 3\n3 4\n4 2\n5 4"] | PASSED | import sys, math
#sys.setrecursionlimit(10**6)
INF = float('inf')
mod = 10**9 + 7
#mod = 998244353
input = lambda: sys.stdin.readline().rstrip()
li = lambda: list(map(int, input().split()))
from collections import deque
def bfs(start):
queue = deque([start])
seen = [INF] * N
seen[start] = 0
while queue... | 1609770900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["2\n1 3 2 4\n3\n1 2 3 4 5 6\n3\n6 5 4 3 2 1"] | 152aba87aaf14d1841f6622dc66051af | NoteFor the first test case, permutation $$$a = [1,3,2,4]$$$ and threshold $$$k = 2$$$ will produce sequence $$$b$$$ as follows. When $$$i = 1$$$, $$$x = a_i = 1 \leq k$$$, there is no $$$a_j$$$ ($$$1 \leq j < i$$$) that $$$a_j > k$$$. Therefore, $$$b_1 = n + 1 = 5$$$. When $$$i = 2$$$, $$$x = a_i = 3 > k$$... | Given a permutation $$$a_1, a_2, \dots, a_n$$$ of integers from $$$1$$$ to $$$n$$$, and a threshold $$$k$$$ with $$$0 \leq k \leq n$$$, you compute a sequence $$$b_1, b_2, \dots, b_n$$$ as follows. For every $$$1 \leq i \leq n$$$ in increasing order, let $$$x = a_i$$$. If $$$x \leq k$$$, set $$$b_{x}$$$ to the last e... | For each test case, output the threshold $$$k$$$ ($$$0 \leq k \leq n$$$) in the first line, and then output the permutation $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq n$$$) in the second line such that the permutation $$$a_1, a_2, \dots, a_n$$$ and threshold $$$k$$$ produce the sequence $$$b_1, b_2, \dots, b_n$$$. ... | Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. The following lines contain the description of each test case. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$), indicating the length of the p... | standard output | standard input | PyPy 3 | Python | 1,900 | train_103.jsonl | 3a5d1f990fe376dad986c5bd1509379b | 512 megabytes | ["3\n\n4\n\n5 3 1 2\n\n6\n\n7 7 7 3 3 3\n\n6\n\n4 4 4 0 0 0"] | PASSED |
# def dfs(node, stack, next, visited):
# if node == -1 or node in visited:
# return
# visited.add(node)
# # print(node, next)
# dfs(next[node], stack, next, visited)
# stack.append(node)
import sys
from collections import defaultdict
# sys.setrecursionlimit(200000)
def dfs(no... | 1664548500 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["12.566370614359172464", "21.991148575128551812"] | 1d547a38250c7780ddcf10674417d5ff | NoteIn the first sample snow will be removed from that area: | Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it... | Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if . | The first line of the input contains three integers — the number of vertices of the polygon n (), and coordinates of point P. Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on... | standard output | standard input | Python 3 | Python | 1,900 | train_020.jsonl | 8091f88eb26abb4602aae9807a65d173 | 256 megabytes | ["3 0 0\n0 1\n-1 2\n1 2", "4 1 -1\n0 0\n1 2\n2 0\n1 1"] | PASSED | def dot_product(v1, v2):
return v1.x * v2.x + v1.y * v2.y
class vector:
def __init__(self, x, y):
self.x = x
self.y = y
def length(self):
return (self.x ** 2 + self.y ** 2) ** 0.5
def cross_product(self, v):
return self.x * v.y - self.y * v.x
class line:
def __in... | 1452789300 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
5 seconds | ["10110"] | 3c058688183e5cd7dd91ae592ccd8048 | NoteThe original scheme from the example (before the input is changed):Green indicates bits '1', yellow indicates bits '0'.If Natasha changes the input bit $$$2$$$ to $$$0$$$, then the output will be $$$1$$$.If Natasha changes the input bit $$$3$$$ to $$$0$$$, then the output will be $$$0$$$.If Natasha changes the inpu... | Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex $$$1$$$, in which every leaf (excluding root) is an input, and all other vertices are logical elements, including the roo... | Print a string of characters '0' and '1' (without quotes) — answers to the problem for each input in the ascending order of their vertex indices. | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^6$$$) — the number of vertices in the graph (both inputs and elements). The $$$i$$$-th of the next $$$n$$$ lines contains a description of $$$i$$$-th vertex: the first word "AND", "OR", "XOR", "NOT" or "IN" (means the input of the scheme) is the vertex... | standard output | standard input | PyPy 3 | Python | 2,000 | train_017.jsonl | fe5fe577e4accb9887353a67d3e7d5ef | 256 megabytes | ["10\nAND 9 4\nIN 1\nIN 1\nXOR 6 5\nAND 3 7\nIN 0\nNOT 10\nIN 1\nIN 1\nAND 2 8"] | PASSED | # https://codeforces.com/problemset/problem/1010/D
# TLE
import sys
input=sys.stdin.readline
def handle(type_, val_, u, g, S):
if type_ == 'NOT':
S.append(g[u][0])
else:
v1, v2 = g[u]
val1, val2 = Val[v1], Val[v2]
if oper[type_](1-val1, val2) != val_:
... | 1532617500 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["3 4 6 5 7", "-1", "3 4 5 2 1 4 3 2"] | c207550a5a74098c1d50407d12a2baec | NoteThe first example is explained is the problem statement.In the third example, for $$$a = [3, 4, 5, 2, 1, 4, 3, 2]$$$, a possible permutation $$$p$$$ is $$$[7, 1, 5, 4, 3, 2, 6]$$$. In that case, Neko would have constructed the following arrays: $$$b = [3, 4, 2, 1, 1, 3, 2]$$$ $$$c = [4, 5, 5, 2, 4, 4, 3]$$$ $$$b... | A permutation of length $$$k$$$ is a sequence of $$$k$$$ integers from $$$1$$$ to $$$k$$$ containing each integer exactly once. For example, the sequence $$$[3, 1, 2]$$$ is a permutation of length $$$3$$$.When Neko was five, he thought of an array $$$a$$$ of $$$n$$$ positive integers and a permutation $$$p$$$ of length... | If Neko made a mistake and there is no array $$$a$$$ and a permutation $$$p$$$ leading to the $$$b'$$$ and $$$c'$$$, print -1. Otherwise, print $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$), denoting the elements of the array $$$a$$$. If there are multiple possible solutions, print any of them. | The first line contains an integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the number of elements in array $$$a$$$. The second line contains $$$n-1$$$ integers $$$b'_1, b'_2, \ldots, b'_{n-1}$$$ ($$$1 \leq b'_i \leq 10^9$$$). The third line contains $$$n-1$$$ integers $$$c'_1, c'_2, \ldots, c'_{n-1}$$$ ($$$1 \leq c'_i \le... | standard output | standard input | Python 3 | Python | 2,400 | train_032.jsonl | add9735b040cd0cbdb11429468c7c618 | 256 megabytes | ["5\n4 5 3 5\n6 7 4 6", "3\n2 4\n3 2", "8\n2 3 1 1 2 4 3\n3 4 4 2 5 5 4"] | PASSED | class multiset:
def __init__(self):
self.contenido = dict()
self.len = 0
def add(self, x):
self.contenido[x] = self.contenido.get(x, 0)+1
self.len += 1
def remove(self, x):
valor = self.contenido.get(x, 1)-1
if valor == 0:
del self.contenido[x]
else:
self.contenido[x] = valor
self.len -= 1
... | 1556116500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["9\n8\n11\n8\n8\n8\n9"] | bab40fe0052e2322116c084008c43366 | null | Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains n vertices and m edges.For each edge (u, v) find the minimal possible weight of the spanning tree that contains the edge (u, v).The weight of the spanning tree is the sum of weights of all edges included in spanning tree. | Print m lines. i-th line should contain the minimal possible weight of the spanning tree that contains i-th edge. The edges are numbered from 1 to m in order of their appearing in input. | First line contains two integers n and m (1 ≤ n ≤ 2·105, n - 1 ≤ m ≤ 2·105) — the number of vertices and edges in graph. Each of the next m lines contains three integers ui, vi, wi (1 ≤ ui, vi ≤ n, ui ≠ vi, 1 ≤ wi ≤ 109) — the endpoints of the i-th edge and its weight. | standard output | standard input | Python 3 | Python | 2,100 | train_019.jsonl | 549fb73b0a26d7b8bd5feed1366e110c | 256 megabytes | ["5 7\n1 2 3\n1 3 1\n1 4 5\n2 3 2\n2 5 3\n3 4 2\n4 5 4"] | PASSED | def find(u):
if u == par[u] :
return u
par[u] = find(par[u])
return par[u]
def union(u,v):
if len(ev[u]) < len(ev[v]):
u, v = v, u
par[v] = u
for j in ev[v] & ev[u]:
ans[j] -= w
ev[u] ^= ev[v]
n, m = map(int, input().split())
ev = [set() for _ in range(n + 1)]
ans,d... | 1450537200 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["1907", "Impossible", "Infinity", "1897"] | 2a4c24341231cabad6021697f15d953a | NoteIn the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating ... | Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating ch... | If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers ci and di ( - 100 ≤ ci ≤ 100, 1 ≤ di ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. | standard output | standard input | Python 3 | Python | 1,600 | train_007.jsonl | 9a738dc403b7b18c118fab0db75e8231 | 256 megabytes | ["3\n-7 1\n5 2\n8 2", "2\n57 1\n22 2", "1\n-5 1", "4\n27 2\n13 1\n-50 1\n8 2"] | PASSED | s, t = -10 ** 8, 10 ** 8
for i in range(int(input())):
c, d = map(int, input().split())
if d == 1:
s = max(s, 1900)
else:
t = min(t, 1899)
# print(s,t)
if s > t:
print('Impossible')
exit()
s, t = s + c, t + c
print('Infinity' if t > 5 * 10 ** 7 else t) | 1483107300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["<", ">", "=", ">", ">"] | fd63aeefba89bef7d16212a0d9e756cd | null | You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.As input/output can reach huge siz... | Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=". | The first line contains a non-negative integer a. The second line contains a non-negative integer b. The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits. | standard output | standard input | Python 3 | Python | 900 | train_001.jsonl | ce0dcff71efaed247f00b7c787a821e2 | 256 megabytes | ["9\n10", "11\n10", "00012345\n12345", "0123\n9", "0123\n111"] | PASSED | def main():
a = input()
b = input()
boolean = False
index_to_start_a = 0
index_to_start_b = 0
while index_to_start_a < len(a) and a[index_to_start_a] == "0":
index_to_start_a += 1
while index_to_start_b < len(b) and b[index_to_start_b] == "0":
index_to_start_b += 1
a ... | 1452524400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["0 1 2", "-10 -9 -8 -7 -6", "Incorrect sequence"] | d42e599073345659188ffea3b2cdd4c7 | null | After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length n (a1, a2, ..., an), consisting of integers and integer k, not exceeding n.This sequence had the following property: if you write out the sums of all its segments consisting of k consecutive elements (a1 + a2 ... + ak... | If Arthur is wrong at some point and there is no sequence that could fit the given information, print a single string "Incorrect sequence" (without the quotes). Otherwise, print n integers — Arthur's favorite sequence. If there are multiple such sequences, print the sequence with the minimum sum |ai|, where |ai| is the... | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105), showing how many numbers are in Arthur's sequence and the lengths of segments respectively. The next line contains n space-separated elements ai (1 ≤ i ≤ n). If ai = ?, then the i-th element of Arthur's sequence was replaced by a question mark. Otherwis... | standard output | standard input | Python 3 | Python | 2,200 | train_051.jsonl | 17fb8fd4f95f32c53197a814d30f60bf | 256 megabytes | ["3 2\n? 1 2", "5 1\n-10 -9 ? -7 -6", "5 3\n4 6 7 2 9"] | PASSED | INF = 1 << 60
Q = 1 << 58
def solve():
ans = [0] * n
for i in range(k):
b = [-INF]
b.extend(a[i:n:k])
m = len(b)
b.append(INF)
lb = -INF
p, q = 1, 0
while p < m:
while b[p] == Q:
p += 1
l = p - q - 1
lb ... | 1424795400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["Lose Win Win Loop\nLoop Win Win Win", "Win Win Win Win Win Win Win\nLose Win Lose Lose Win Lose Lose"] | 7c6b04687b4e608be1fd7d04abb015ee | null | Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer.In this game there are n objects numbered from 1 to n arranged in a circle (in clockwise order). Object number 1 is a black hole and the other... | In the first line print n - 1 words separated by spaces where i-th word is "Win" (without quotations) if in the scenario that Rick plays first and monster is initially in object number i + 1 he wins, "Lose" if he loses and "Loop" if the game will never end. Similarly, in the second line print n - 1 words separated by s... | The first line of input contains a single integer n (2 ≤ n ≤ 7000) — number of objects in game. The second line contains integer k1 followed by k1 distinct integers s1, 1, s1, 2, ..., s1, k1 — Rick's set. The third line contains integer k2 followed by k2 distinct integers s2, 1, s2, 2, ..., s2, k2 — Morty's set 1 ≤ ki ... | standard output | standard input | PyPy 2 | Python | 2,000 | train_010.jsonl | 9ba2f72823c716184674b48e2f5e3236 | 256 megabytes | ["5\n2 3 2\n3 1 2 3", "8\n4 6 2 3 4\n2 3 6"] | PASSED | #!/usr/bin/env python3
from __future__ import absolute_import
from sys import stdin,stdout
from itertools import imap
def ri():
return imap(int, raw_input().split())
n = int(raw_input())
a = list(ri())
b = list(ri())
a = a[1:]
b = b[1:]
T = [[-1 for i in xrange(2)] for j in xrange(n)]
T[0][0] = 1
T[0][1] = 0
f... | 1490281500 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
1 second | ["2", "1", "6"] | 393ed779ea3ca8fdb63e8de1293eecd3 | NoteIn the first sample the superior subarrays are (0, 1) and (3, 2).Subarray (0, 1) is superior, as a0 ≥ a0, a0 ≥ a1, a0 ≥ a2, a0 ≥ a3, a0 ≥ a0, ...Subarray (3, 2) is superior a3 ≥ a3, a0 ≥ a0, a3 ≥ a1, a0 ≥ a2, a3 ≥ a3, ...In the third sample any pair of (l, s) corresponds to a superior subarray as all the elements o... | You are given an infinite periodic array a0, a1, ..., an - 1, ... with the period of length n. Formally, . A periodic subarray (l, s) (0 ≤ l < n, 1 ≤ s < n) of array a is an infinite periodic array with a period of length s that is a subsegment of array a, starting with position l.A periodic subarray (l, s) is su... | Print a single integer — the sought number of pairs. | The first line contains number n (1 ≤ n ≤ 2·105). The second line contains n numbers a0, a1, ..., an - 1 (1 ≤ ai ≤ 106), separated by a space. | standard output | standard input | PyPy 2 | Python | 2,400 | train_054.jsonl | b4ed419ee263930a37c82b6eba4a43dc | 256 megabytes | ["4\n7 1 2 3", "2\n2 1", "3\n1 1 1"] | PASSED | # -*- coding: utf-8 -*-
import fractions
from collections import defaultdict
if __name__ == '__main__':
n = int(raw_input())
a = map(int, raw_input().split())
a *= 2
inf = min(a) - 1
a[-1] = inf
result = 0
numbers_by_gcd = defaultdict(list)
for i in xrange(1, n):
numbers_by_gc... | 1443890700 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
2 seconds | ["12\n37\n1000000\n5000349985"] | e092d58ac58e1e41d17be946128234e5 | NoteTest case 1:Marisa can start at $$$x=2$$$. In the first minute, she moves to $$$x=1$$$ and collect $$$5$$$ mushrooms. The number of mushrooms will be $$$[1,7,2,3,4]$$$. In the second minute, she moves to $$$x=2$$$ and collects $$$7$$$ mushrooms. The numbers of mushrooms will be $$$[2,1,3,4,5]$$$. After $$$2$$$ minu... | The enchanted forest got its name from the magical mushrooms growing here. They may cause illusions and generally should not be approached.—Perfect Memento in Strict SenseMarisa comes to pick mushrooms in the Enchanted Forest. The Enchanted forest can be represented by $$$n$$$ points on the $$$X$$$-axis numbered $$$1$$... | For each test case, print the maximum number of mushrooms Marisa can pick after $$$k$$$ minutes. | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 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$$$, $$$k$$$ ($$$1 \le n \le 2 \cdot 10 ^ 5$$$, $$$1\le k \le 10^9$$$) — t... | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_090.jsonl | 6208916751285f37a1001de34997ea92 | 256 megabytes | ["4\n\n5 2\n\n5 6 1 2 3\n\n5 7\n\n5 6 1 2 3\n\n1 2\n\n999999\n\n5 70000\n\n1000000000 1000000000 1000000000 1000000000 1000000000"] | PASSED | import sys,math
input=sys.stdin.readline
for _ in range(int(input())):
#n=int(input())
n,k=map(int,input().split())
l=list(map(int,input().split()))
if n==1:
print(l[0]+(k-1))
elif k>=n:
ans=sum(l)+((n*(n-1))//2)+n*(k-n)
print(ans)
else:
s=... | 1654266900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["acac\nabc\n-1\nabaabaaab"] | 6c51676bc12bce8ba6e36b64357ef9f0 | NoteIn the first test case "acac" is greater than or equal to $$$s$$$, and each letter appears $$$2$$$ or $$$0$$$ times in it, so it is beautiful.In the second test case each letter appears $$$0$$$ or $$$1$$$ times in $$$s$$$, so $$$s$$$ itself is the answer.We can show that there is no suitable string in the third tes... | You are given a string $$$s$$$ consisting of lowercase English letters and a number $$$k$$$. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by $$$k$$$. You are asked to find the lexicographically smallest beautiful string of ... | For each test case output in a separate line lexicographically smallest beautiful string of length $$$n$$$, which is greater or equal to string $$$s$$$, or $$$-1$$$ if such a string does not exist. | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10\,000$$$) — the number of test cases. The next $$$2 \cdot T$$$ lines contain the description of test cases. The description of each test case consists of two lines. The first line of the description contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k ... | standard output | standard input | Python 3 | Python | 2,000 | train_105.jsonl | 8ba251a60d9717dec38f8ef15195c242 | 256 megabytes | ["4\n4 2\nabcd\n3 1\nabc\n4 3\naaaa\n9 3\nabaabaaaa"] | PASSED | import threading
import sys
threading.stack_size(16*2048*2048)
sys.setrecursionlimit(100010)
def getnext(index,fre,k,s,flag):
if sum(fre)>len(s)-index:
return "ERROR"
# print(index,fre,pre,flag)
if index==len(s): return ""
cur = ord(s[index])-97
if not flag:
nexts = ""
s... | 1615039500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["2\n4"] | a0e738765161bbbfe8e7c5abaa066b0d | NoteFor the first case, the game is as follows: Mr. Chanek takes one coin. The opponent takes two coins. Mr. Chanek takes one coin. The opponent takes one coin. For the second case, the game is as follows: Mr. Chanek takes three coins. The opponent takes one coin. Mr. Chanek takes one coin. The opponent takes... | Lately, Mr. Chanek frequently plays the game Arena of Greed. As the name implies, the game's goal is to find the greediest of them all, who will then be crowned king of Compfestnesia.The game is played by two people taking turns, where Mr. Chanek takes the first turn. Initially, there is a treasure chest containing $$$... | $$$T$$$ lines, each line is the answer requested by Mr. Chanek. | The first line contains a single integer $$$T$$$ $$$(1 \le T \le 10^5)$$$ denotes the number of test cases. The next $$$T$$$ lines each contain a single integer $$$N$$$ $$$(1 \le N \le 10^{18})$$$. | standard output | standard input | PyPy 3 | Python | 1,400 | train_043.jsonl | ddb979e14439371630e5f5c4f12b64f2 | 256 megabytes | ["2\n5\n6"] | PASSED | import os,io
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def fnxn(n):
n1 = n
ans = 0
while n:
if n in dp:
ans += dp[n]
n = 0
elif n%4 == 0:
ans += 1
n -= 2
elif n%2 == 0:
n//=2
ans += n
... | 1601182800 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["36", "1728"] | 9a5bd9f937da55c3d26d5ecde6e50280 | NoteIn the first sample n = 2·3 = 6. The divisors of 6 are 1, 2, 3 and 6, their product is equal to 1·2·3·6 = 36.In the second sample 2·3·2 = 12. The divisors of 12 are 1, 2, 3, 4, 6 and 12. 1·2·3·4·6·12 = 1728. | Ayrat has number n, represented as it's prime factorization pi of size m, i.e. n = p1·p2·...·pm. Ayrat got secret information that that the product of all divisors of n taken modulo 109 + 7 is the password to the secret data base. Now he wants to calculate this value. | Print one integer — the product of all divisors of n modulo 109 + 7. | The first line of the input contains a single integer m (1 ≤ m ≤ 200 000) — the number of primes in factorization of n. The second line contains m primes numbers pi (2 ≤ pi ≤ 200 000). | standard output | standard input | Python 2 | Python | 2,000 | train_020.jsonl | ad569439ed16862257ace1348c875c40 | 256 megabytes | ["2\n2 3", "3\n2 3 2"] | PASSED | from collections import Counter
from operator import __mul__
mod = 10 ** 9 + 7
n = input()
p = map(int, raw_input().split())
p = Counter(p)
prod = 1
exp = 1
perfsq=1
fl=0
for x,a in p.items():
if(a%2==1):
fl=1
if(fl):
for x,a in p.items():
exp*=(a+1)
prod *= pow(x,(a),mod)
... | 1452261900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["0\n11\n4\n4\n17\n60"] | 28277036765f76f20c327ab2fda6c43b | NoteIn the first test case, we shall not perform any operations as $$$S$$$ is already equal to $$$T$$$, which is the set $$$\{1, 2, 3, 4, 5, 6\}$$$.In the second test case, initially, $$$S = \{1, 2, 3, 4, 5, 6, 7\}$$$, and $$$T = \{1, 2, 4, 7\}$$$. We shall perform the following operations: Choose $$$k=3$$$, then del... | You are given a set $$$S$$$, which contains the first $$$n$$$ positive integers: $$$1, 2, \ldots, n$$$.You can perform the following operation on $$$S$$$ any number of times (possibly zero): Choose a positive integer $$$k$$$ where $$$1 \le k \le n$$$, such that there exists a multiple of $$$k$$$ in $$$S$$$. Then, del... | For each test case, output one non-negative integer — the minimum possible total cost of operations such that $$$S$$$ would be transformed into $$$T$$$. | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) — the number of test cases. The description of the test cases follows. The first line contains a single positive integer $$$n$$$ ($$$1 \le n \le 10^6$$$). The second line of each test case contains a binary string of length $$$n$$... | standard output | standard input | PyPy 3-64 | Python | 1,200 | train_097.jsonl | ab73b67c320fde1ef1bd893b033ad756 | 256 megabytes | ["6\n\n6\n\n111111\n\n7\n\n1101001\n\n4\n\n0000\n\n4\n\n0010\n\n8\n\n10010101\n\n15\n\n110011100101100"] | PASSED | # func.cache_clear() func.cache_info() no imports
# from fractions import Fraction
import time
# list.sort(key = lambda x: (-x[0], -x[1]))
# words.sort(key = lambda x: len(x)) sorts based on length or words.sort(key=len)
# d.get(key, num) if key in d then it gives the val for that key else gives the number you hav... | 1663934700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2.500000000000", "8.965874696353"] | de8c909d6ca4f3b2f885fc60be246458 | null | Everybody knows that the capital of Berland is connected to Bercouver (the Olympic capital) by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. Traffic signs in Berland are a bit peculiar, because they limit the speed only at that point on the ro... | Print the answer with at least five digits after the decimal point. | The first line of the input file contains two integer numbers a and v (1 ≤ a, v ≤ 10000). The second line contains three integer numbers l, d and w (2 ≤ l ≤ 10000; 1 ≤ d < l; 1 ≤ w ≤ 10000). | standard output | standard input | Python 2 | Python | 2,100 | train_037.jsonl | a29722ae1c580779256ef761736a41cb | 64 megabytes | ["1 1\n2 1 3", "5 70\n200 170 40"] | PASSED | import math
def getfloats(): return map(float, raw_input().split())
def calc(v0, v, a, x):
t = (v - v0) / a
x0 = v0 * t + 0.5 * a * t * t
if x0 > x: return (x, (math.sqrt(v0 * v0 + 2 * a * x) - v0) / a)
return (x0, t)
def go(v0, v, a, x):
x0, t = calc(v0, v, a, x)
return t + (x - x0) / v
a, v = getfloats()
l, ... | 1269100800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["9\n4\n6"] | d458a65b351b2ba7f9891178ef1b64a1 | NoteInitially, the permutation has the form $$$[1, 2, 3, 4]$$$. Queries processing is as follows: $$$2 + 3 + 4 = 9$$$; $$$[1, 2, 3, 4] \rightarrow [1, 2, 4, 3] \rightarrow [1, 3, 2, 4] \rightarrow [1, 3, 4, 2]$$$; $$$1 + 3 = 4$$$; $$$4 + 2 = 6$$$ | A permutation is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ — are permutations, and $$$[1, 1]$$$, $$$[4, 3, 1]$$$, $$$[2, 3, 4]$$$ — no.Permutation $$$a$$$ is lexicographically smaller than permutat... | For each query of the $$$1$$$-st type, output on a separate line one integer — the required sum. | The first line contains two integers $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) and $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$), where $$$n$$$ — the length of the initial permutation, and $$$q$$$ — the number of queries. The next $$$q$$$ lines contain a single query of the $$$1$$$-st or $$$2$$$-nd type. The $$$1$$$-st type ... | standard output | standard input | Python 3 | Python | 2,400 | train_060.jsonl | 6478e5dee9b10bb9397ba3050edade76 | 256 megabytes | ["4 4\n1 2 4\n2 3\n1 1 2\n1 3 4"] | PASSED | import io,os;from math import *;input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
manual = 20;n,Q = map(int,input().split());after = min(manual, n);before = n -after;ind = 0
def unrankperm(i):
unused = [i+1 for i in range(after)];r = []
for j in range(after)[::-1]:use = i // factorial(j);r.append(unused[use... | 1604327700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["54\n56"] | 9089fb2547751ca140a65f03fe78c916 | NoteIn the first test case, one of optimal solutions is four paths $$$1 \to 2 \to 3 \to 5$$$, $$$1 \to 2 \to 3 \to 5$$$, $$$1 \to 4$$$, $$$1 \to 4$$$, here $$$c=[4,2,2,2,2]$$$. The value equals to $$$4\cdot 6+ 2\cdot 2+2\cdot 1+2\cdot 5+2\cdot 7=54$$$.In the second test case, one of optimal solution is three paths $$$1... | You are given a rooted tree consisting of $$$n$$$ vertices. The vertices are numbered from $$$1$$$ to $$$n$$$, and the root is the vertex $$$1$$$. You are also given a score array $$$s_1, s_2, \ldots, s_n$$$.A multiset of $$$k$$$ simple paths is called valid if the following two conditions are both true. Each path st... | For each test case, print a single integer — the maximum value of a path multiset. | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two space-separated integers $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) and $$$k$$$ ($$$1 \le... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_103.jsonl | 0aa4f7c04879e29daa20b32f27724b29 | 256 megabytes | ["2\n\n5 4\n\n1 2 1 3\n\n6 2 1 5 7\n\n5 3\n\n1 2 1 3\n\n6 6 1 4 10"] | PASSED | from sys import stdin, stdout
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(... | 1665844500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["27", "18"] | de5a9d39dcd9ad7c53ae0fa2d441d3f0 | NoteIn the first sample, it would be optimal to buy video cards with powers 3, 15 and 9. The video card with power 3 should be chosen as the leading one and all other video cards will be compatible with it. Thus, the total power would be 3 + 15 + 9 = 27. If he buys all the video cards and pick the one with the power 2 ... | Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated.There are n video cards in the shop, the power of the i-th video card is equal to inte... | The only line of the output should contain one integer value — the maximum possible total power of video cards working together. | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of video cards in the shop. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 200 000) — powers of video cards. | standard output | standard input | Python 3 | Python | 1,900 | train_073.jsonl | 5daf5dcd6ad1a9d9a9fad2f1a3a09612 | 256 megabytes | ["4\n3 2 15 9", "4\n8 2 2 7"] | PASSED | def main():
n = int(input())
aa = list(map(int, input().split()))
aa.sort()
lim = aa[-1] + 1
cnt, a = [0] * lim, aa[0] - 1
for i, b in zip(range(n, -1, -1), aa):
if a != b:
cnt[a + 1:b + 1] = [i] * (b - a)
a = b
avail, res = [True] * lim, []
for i, a in en... | 1476611100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["YES\n0\n10\n110", "NO"] | 1670a3d7dba83e29e98f0ac6fe4acb18 | null | Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, but at the same time they could always understand each other perfect... | If there’s no such set of words, in the single line output NO. Otherwise, in the first line output YES, and in the next N lines output the words themselves in the order their lengths were given in the input file. If the answer is not unique, output any. | The first line contains one integer N (1 ≤ N ≤ 1000) — the number of words in Old Berland language. The second line contains N space-separated integers — the lengths of these words. All the lengths are natural numbers not exceeding 1000. | standard output | standard input | Python 3 | Python | 1,900 | train_029.jsonl | b49df763e44559e6bbc8ca97eb2d7bbc | 256 megabytes | ["3\n1 2 3", "3\n1 1 1"] | PASSED | import sys
sys.setrecursionlimit(1050)
class Node:
def __init__(self, depth, parent):
self.depth = depth
self.parent = parent
self.left = None
self.right = None
self.leaf = False
def __str__(self):
return 'depth = %d, left? %s, right? %s' % (self.depth,
self.left != None, self.right... | 1288018800 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
3 seconds | ["2", "3", "0", "0"] | b4332870aac6159d5aaa4ff21f8e9f7f | NoteThe acquaintances graph for the first example is shown in the picture below (next to each student there is their group number written).In that test we can select the following groups: Select the first and the second groups. For instance, one team can be formed from students $$$1$$$ and $$$4$$$, while other team ca... | The new academic year has started, and Berland's university has $$$n$$$ first-year students. They are divided into $$$k$$$ academic groups, however, some of the groups might be empty. Among the students, there are $$$m$$$ pairs of acquaintances, and each acquaintance pair might be both in a common group or be in two di... | Print a single integer — the number of ways to choose two different groups such that it's possible to select two teams to play the game. | The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 500\,000$$$; $$$0 \le m \le 500\,000$$$; $$$2 \le k \le 500\,000$$$) — the number of students, the number of pairs of acquaintances and the number of groups respectively. The second line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n... | standard output | standard input | PyPy 2 | Python | 2,500 | train_013.jsonl | 99c4d33d7a26bfdd881cc121de5f36f7 | 512 megabytes | ["6 8 3\n1 1 2 2 3 3\n1 3\n1 5\n1 6\n2 5\n2 6\n3 4\n3 5\n5 6", "4 3 3\n1 1 2 2\n1 2\n2 3\n3 4", "4 4 2\n1 1 1 2\n1 2\n2 3\n3 1\n1 4", "5 5 2\n1 2 1 2 1\n1 2\n2 3\n3 4\n4 5\n5 1"] | PASSED | import os
import sys
from atexit import register
from io import BytesIO
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
def main():
class UnionFind():
def __init__(self, n):
self.n = n
self.root =... | 1604228700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
3 seconds | ["2", "4", "0"] | 44d3494f40176d56c8fe57908ff09db5 | NoteIn the first test case possible arrays are $$$[1, 2, 1]$$$ and $$$[2, 1, 2]$$$.In the second test case possible arrays are $$$[1, 2]$$$, $$$[1, 3]$$$, $$$[2, 1]$$$ and $$$[2, 3]$$$. | You are given an array of $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$. Your task is to calculate the number of arrays of $$$n$$$ positive integers $$$b_1, b_2, \ldots, b_n$$$ such that: $$$1 \le b_i \le a_i$$$ for every $$$i$$$ ($$$1 \le i \le n$$$), and $$$b_i \neq b_{i+1}$$$ for every $$$i$$$ ($$$1 \le i... | Print the answer modulo $$$998\,244\,353$$$ in a single line. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). | standard output | standard input | PyPy 3 | Python | 2,400 | train_088.jsonl | 870ea5ed861d57ff48c9bd55ba572e9a | 512 megabytes | ["3\n2 2 2", "2\n2 3", "3\n1 1 1"] | PASSED | import sys
input = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, data, default=0, func=max):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_... | 1639322100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
0.5 seconds | ["572", "3574", "-1"] | bc375e27bd52f413216aaecc674366f8 | null | Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of c... | If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from t... | The first line contains an odd positive integer n — the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes. | standard output | standard input | Python 2 | Python | 1,300 | train_001.jsonl | fdfba12830bb7bd699582d5175d1fe3c | 256 megabytes | ["527", "4573", "1357997531"] | PASSED | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
# pylint: disable=C0111
def main():
n = list(raw_input().strip())
maxswap = (0, -1)
for x in xrange(len(n) - 2, -1, -1):
if int(n[x]) % 2 == 0:
if maxswap[0] == 0 or (int(n[-1]) - int(n[x]) > 0):
maxswap = (int(n[-1]) - int... | 1422376200 | [
"math",
"strings"
] | [
0,
0,
0,
1,
0,
0,
1,
0
] | |
2 seconds | ["9\n12\n3595374"] | 2cc35227174e6a4d48e0839cba211724 | NoteFor $$$n = 3$$$ the sequence is $$$[1,3,4,9...]$$$ | Theofanis really likes sequences of positive integers, thus his teacher (Yeltsa Kcir) gave him a problem about a sequence that consists of only special numbers.Let's call a positive number special if it can be written as a sum of different non-negative powers of $$$n$$$. For example, for $$$n = 4$$$ number $$$17$$$ is ... | For each test case, print one integer — the $$$k$$$-th special number in increasing order modulo $$$10^9+7$$$. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first and only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 10^9$$$; $$$1 \le k \le 10^9$$$). | standard output | standard input | Python 3 | Python | 1,100 | train_097.jsonl | 1a3f3791cc31c216f3c7afb8215f6371 | 256 megabytes | ["3\n3 4\n2 12\n105 564"] | PASSED | import math
t = int(input())
def calcul(n, k):
s = 0
while k>0:
x = math.log2(k)
p = int(x)
c = pow(2, p)
i = int(c*(x-p))
#update
s += pow(n, p)
k -= c
p = i
return s%(1000000007)
for i in range(t):
n, k = ... | 1633705500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nYES\nNO\nYES\nYES\nNO\nNO"] | 7ac27da2546a50d453f7bb6cacef1068 | null | In the pet store on sale there are: $$$a$$$ packs of dog food; $$$b$$$ packs of cat food; $$$c$$$ packs of universal food (such food is suitable for both dogs and cats). Polycarp has $$$x$$$ dogs and $$$y$$$ cats. Is it possible that he will be able to buy food for all his animals in the store? Each of his dogs and ... | For each test case in a separate line, output: YES, if suitable food can be bought for each of $$$x$$$ dogs and for each of $$$y$$$ cats; NO else. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response). | The first line of input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ lines are given, each containing a description of one test case. Each description consists of five integers $$$a, b, c, x$$$ and $$$y$$$ ($$$0 \le a,b,c,x,y \le 10^8$$$). | standard output | standard input | PyPy 3-64 | Python | 800 | train_092.jsonl | f98f3016f39da1ab0ed61bf80c55fa56 | 256 megabytes | ["7\n\n1 1 4 2 3\n\n0 0 0 0 0\n\n5 5 0 4 6\n\n1 1 1 1 1\n\n50000000 50000000 100000000 100000000 100000000\n\n0 0 0 100000000 100000000\n\n1 3 2 2 5"] | PASSED | for _ in range(int(input())):
a,b,c,x,y=map(int,input().split())
if a>=x and b>=y:
print('YES')
elif a>=x and b<y:
if b+c<y:
print('NO')
else:
print('YES')
elif a<x and b>=y:
if a+c<x:
print('NO')
else:
... | 1651761300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2 1 1 \n9 0 \n0 4 9 6 9"] | fd47f1eb701077abc5ec67163ad4fcc5 | NoteIn the first test case, we can prove that initial sequence was $$$[2,1,1]$$$. In that case, the following moves were performed: On the first wheel: $$$2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{D}]{} 9$$$. On the second wheel: $$$1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\... | Luca has a cypher made up of a sequence of $$$n$$$ wheels, each with a digit $$$a_i$$$ written on it. On the $$$i$$$-th wheel, he made $$$b_i$$$ moves. Each move is one of two types: up move (denoted by $$$\texttt{U}$$$): it increases the $$$i$$$-th digit by $$$1$$$. After applying the up move on $$$9$$$, it becomes ... | For each test case, output $$$n$$$ space-separated digits — the initial sequence of the cypher. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of wheels. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$0 \leq a_i \leq 9$$$) — the digit shown on t... | standard output | standard input | PyPy 3-64 | Python | 800 | train_086.jsonl | 57311e8ef789ed2bee89cb84f7f07670 | 256 megabytes | ["3\n\n3\n\n9 3 1\n\n3 DDD\n\n4 UDUU\n\n2 DU\n\n2\n\n0 9\n\n9 DDDDDDDDD\n\n9 UUUUUUUUU\n\n5\n\n0 5 9 8 3\n\n10 UUUUUUUUUU\n\n3 UUD\n\n8 UUDUUDDD\n\n10 UUDUUDUDDU\n\n4 UUUU"] | PASSED | t = int(input())
while t:
n = int(input())
s1 = list(input().split(" "))
swaps = []
while n:
sw = input()
total_swap = 0
for i in sw:
if i == "U":
total_swap += 1
elif i == "D":
total_swap -= 1
swaps... | 1657636500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["18\n5\n5000000000"] | 882deb8385fb175b4547f43b1eb01fc6 | NoteIn the first test, you can apply the operation $$$x=1$$$, $$$l=3$$$, $$$r=3$$$, and the operation $$$x=1$$$, $$$l=5$$$, $$$r=5$$$, then the array becomes $$$[0, 6, 2, 1, 4, 5]$$$.In the second test, you can apply the operation $$$x=2$$$, $$$l=2$$$, $$$r=3$$$, and the array becomes $$$[1, 1, -1, -1, 1, -1, 1]$$$, th... | You are given an array $$$a$$$ of $$$n$$$ integers and a set $$$B$$$ of $$$m$$$ positive integers such that $$$1 \leq b_i \leq \lfloor \frac{n}{2} \rfloor$$$ for $$$1\le i\le m$$$, where $$$b_i$$$ is the $$$i$$$-th element of $$$B$$$. You can make the following operation on $$$a$$$: Select some $$$x$$$ such that $$$x$... | For each test case print a single integer — the maximum possible sum of all $$$a_i$$$ after applying such operation any number of times. | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2\leq n \leq 10^6$$$, $$$1 \leq m \leq \lfloor \frac{n}{2... | standard output | standard input | PyPy 2 | Python | 2,400 | train_088.jsonl | fc56835124bef36b019bb7ac0f94a91c | 256 megabytes | ["3\n6 2\n0 6 -2 1 -4 5\n1 2\n7 1\n1 -1 1 -1 1 -1 1\n2\n5 1\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1"] | PASSED | from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
from bisect import bisect_left as lower_bound, bisect_right as upper_bound
... | 1643294100 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["3", "0", "755808950"] | f88140475930b3d654ad80d620d48c1a | NoteIn the first sample, there are three active startups labeled $$$1$$$, $$$2$$$ and $$$3$$$, and zero acquired startups. Here's an example of how one scenario can happen Startup $$$1$$$ acquires startup $$$2$$$ (This state can be represented by the array $$$[-1, 1, -1]$$$) Startup $$$3$$$ acquires startup $$$1$$$ (... | There are $$$n$$$ startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.The following steps hap... | Print a single integer, the expected number of days needed for the process to end with exactly one active startup, modulo $$$10^9+7$$$. | The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 500$$$), the number of startups. The next line will contain $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$a_i = -1$$$ or $$$1 \leq a_i \leq n$$$). If $$$a_i = -1$$$, then that means startup $$$i$$$ is active. Otherwise, if $$$1 \leq a... | standard output | standard input | Python 3 | Python | 3,200 | train_035.jsonl | ab7092ad2b2a2b98a8315b00e888c591 | 256 megabytes | ["3\n-1 -1 -1", "2\n2 -1", "40\n3 3 -1 -1 4 4 -1 -1 -1 -1 -1 10 10 10 10 10 10 4 20 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 3 3 3 3 3 3 3"] | PASSED | n,a=int(input()),input().split()
print((pow(2,n-1)-1-sum(pow(2,a.count(x))-1for x in{*a}-{'-1'}))%(10**9+7)) | 1534685700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2 4 6 1 3", "1 -3 4 11 6"] | fa256021dc519f526ef3878cce32ff31 | NoteIn the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.In the second sample test, the sequence 1, - 3, 4... | There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performing the following procedure: The crow sets ai initially 0. The crow then adds bi to ai, subtracts bi + 1, adds the bi + 2 number, and so on until the n'th number. Thus, ai = bi - bi + 1 + bi + 2 - b... | Print n integers corresponding to the sequence b1, b2, ..., bn. It's guaranteed that the answer is unique and fits in 32-bit integer type. | The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of integers written in the row. The next line contains n, the i'th of which is ai ( - 109 ≤ ai ≤ 109) — the value of the i'th number. | standard output | standard input | Python 3 | Python | 800 | train_007.jsonl | e577e8b1dc6f986d3ca89b22e9a18e7c | 256 megabytes | ["5\n6 -4 8 -2 3", "5\n3 -2 -1 5 6"] | PASSED | a=int(input())
b=list(map(int,input().split()))
for x in range(a-1):
print(b[x]+b[x+1],end=' ')
print(b[-1],end='') | 1473525900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["B 4\n\nA 2\n\nA 8\n\nC 4"] | 513480a6c7a715e237c3a63805208039 | NoteNote that to make the sample more clear, we added extra empty lines. You shouldn't print any extra empty lines during the interaction process.In the first test $$$n=10$$$ and $$$x=4$$$.Initially the set is: $$$\{1,2,3,4,5,6,7,8,9,10\}$$$.In the first operation, you ask how many numbers are multiples of $$$4$$$ and ... | This is an interactive problem.There is an unknown integer $$$x$$$ ($$$1\le x\le n$$$). You want to find $$$x$$$.At first, you have a set of integers $$$\{1, 2, \ldots, n\}$$$. You can perform the following operations no more than $$$10000$$$ times: A $$$a$$$: find how many numbers are multiples of $$$a$$$ in the curr... | null | The first line contains one integer $$$n$$$ ($$$1\le n\le 10^5$$$). The remaining parts of the input will be given throughout the interaction process. | standard output | standard input | Python 3 | Python | 2,600 | train_002.jsonl | 7050d3c4034763a599f5c3db5bc453cd | 512 megabytes | ["10\n\n2\n\n4\n\n0"] | PASSED | n = int(input())
is_prime = [1] * (n + 1)
primes = [2]
i = 3
while i * i <= n:
if is_prime[i] == 1:
primes.append(i)
for j in range(i * i, n + 1, i * 2):
is_prime[j] = 0
i += 2
for j in range(i, n + 1, 2):
if is_prime[j]:
primes.append(j)
s = set(range(1, n + 1))
ans ... | 1599918300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["10 10 10 10 10 4 0 0 0 0", "13 13 13 13 0 0 0 0 0 0 0"] | 0ad96b6a8032d70df400bf2ad72174bf | null | A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the... | Print n numbers. The i-th of them should be equal to ai. | We are given 3 space-separated integers n, k, t (1 ≤ n, k ≤ 100, 0 ≤ t ≤ 100). | standard output | standard input | Python 2 | Python | 1,300 | train_003.jsonl | ec8ce31bbd816b4ae4e3786bde536b2a | 256 megabytes | ["10 10 54", "11 13 37"] | PASSED | arr = [int(x) for x in raw_input().split()]
n, k, t = arr
s = t * n * k / 100
for i in range(n):
w = min(s, k)
print(w)
s -= w
| 1301410800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["6\n15\n-2"] | 93fb13c40ab03700ef9a827796bd3d9d | NoteIn the first example, it is enough to delete the entire string, then we will get $$$2 \cdot 3 + 0 = 6$$$ points.In the second example, if we delete characters one by one, then for each deleted character we will get $$$(-2) \cdot 1 + 5 = 3$$$ points, i. e. $$$15$$$ points in total.In the third example, we can delete... | You are given a string $$$s$$$ of length $$$n$$$ consisting only of the characters 0 and 1.You perform the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from the string and glue the remaining two parts together (any of them can be empty) in the same ... | For each testcase, print a single integer — the maximum number of points that you can score. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of testcases. The first line of each testcase contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \le n \le 100; -100 \le a, b \le 100$$$) — the length of the string $$$s$$$ and the parameters $$$a$$$ and $$$b$$$. The second l... | standard output | standard input | PyPy 3-64 | Python | 1,000 | train_094.jsonl | 5500e25cef752be2d521ce1d7a287ea3 | 256 megabytes | ["3\n3 2 0\n000\n5 -2 5\n11001\n6 1 -4\n100111"] | PASSED | # ------------------- fast io --------------------
from itertools import count
import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
... | 1626273300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3", "10", "2"] | 4278fece7812148863688c67218aca7b | NoteIn the first example it is enough to set mouse trap in rooms $$$1$$$ and $$$4$$$. If mouse starts in room $$$1$$$ then it gets caught immideately. If mouse starts in any other room then it eventually comes to room $$$4$$$.In the second example it is enough to set mouse trap in room $$$2$$$. If mouse starts in room ... | Medicine faculty of Berland State University has just finished their admission campaign. As usual, about $$$80\%$$$ of applicants are girls and majority of them are going to live in the university dormitory for the next $$$4$$$ (hopefully) years.The dormitory consists of $$$n$$$ rooms and a single mouse! Girls decided ... | Print a single integer — the minimal total amount of burles girls can spend to set the traps in order to guarantee that the mouse will eventually be caught no matter the room it started from. | The first line contains as single integers $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of rooms in the dormitory. The second line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 10^4$$$) — $$$c_i$$$ is the cost of setting the trap in room number $$$i$$$. The third line contains $$$n$$$ ... | standard output | standard input | Python 3 | Python | 1,700 | train_016.jsonl | f35bf4ec04cdc62c5d494e3fc3d0902b | 256 megabytes | ["5\n1 2 3 2 10\n1 3 4 3 3", "4\n1 10 2 10\n2 4 2 2", "7\n1 1 1 1 1 1 1\n2 2 2 3 6 7 6"] | PASSED | n = int(input())
C = [int(s) for s in input().split(" ")]
A = [int(s)-1 for s in input().split(" ")]
al = [False for i in range(0, n)]
ans = 0
for v in range(0, n):
if al[v]:
continue
sequence = []
while not al[v]:
sequence.append(v)
al[v] = True
v = A[v]
if v in sequence... | 1534602900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1\n0"] | b12f2784bafb3db74598a22ac4603646 | NoteIn the example the army consists of two warriors with personalities 3 and 4 after first two events. Then Vova tries to hire a commander with personality 6 and leadership 3, and only one warrior respects him (, and 2 < 3, but , and 5 ≥ 3). Then warrior with personality 4 leaves, and when Vova tries to hire that c... | As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires.Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and he wants to choose the person who will be respected by warriors.Each w... | For each event of the third type print one integer — the number of warriors who respect the commander Vova tries to hire in the event. | The first line contains one integer q (1 ≤ q ≤ 100000) — the number of events. Then q lines follow. Each line describes the event: 1 pi (1 ≤ pi ≤ 108) — one warrior with personality pi joins Vova's army; 2 pi (1 ≤ pi ≤ 108) — one warrior with personality pi leaves Vova's army (it is guaranteed that there is at least... | standard output | standard input | Python 2 | Python | 2,000 | train_000.jsonl | 9dd47ff1a6c097b41b91861520e875fe | 256 megabytes | ["5\n1 3\n1 4\n3 6 3\n2 4\n3 6 3"] | PASSED | from sys import stdin, stdout
from itertools import izip
def main(it=int, bi=bin):
n = int(stdin.readline())
to = [None] * 5800000
s = [0] * 5800000
c = 1
ans = []
pu = ans.append
for line in stdin:
line = line.split()
if line[0] == '3':
p, l = bi(it(line[1]))[2:]... | 1497539100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["1", "0", "2"] | a1c3876d705ac8e8b81394ba2be12ed7 | NoteIn the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold).In the second sample test the two given words couldn't be obtained from the same word by removing one letter.In the third sample test the two given words could be obtained from either wo... | Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics.Polycarp needed to write a code that could, given two words, check whether the... | Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. | The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. | standard output | standard input | PyPy 3 | Python | 1,800 | train_060.jsonl | e887d6774737bf369455f3ccd2798865 | 256 megabytes | ["7\nreading\ntrading", "5\nsweet\nsheep", "3\ntoy\ntry"] | PASSED | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.wri... | 1429286400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["NO\nYES\nYES\nYES\nNO"] | 7d6d1c5af6e3faefe67f585a5130d6bd | NoteOne possible path for the fourth test case is given in the picture in the statement. | You are given a grid with $$$n$$$ rows and $$$m$$$ columns. We denote the square on the $$$i$$$-th ($$$1\le i\le n$$$) row and $$$j$$$-th ($$$1\le j\le m$$$) column by $$$(i, j)$$$ and the number there by $$$a_{ij}$$$. All numbers are equal to $$$1$$$ or to $$$-1$$$. You start from the square $$$(1, 1)$$$ and can move ... | For each test case, print "YES" if there exists a path from the top left to the bottom right that adds up to $$$0$$$, and "NO" otherwise. You can output each letter in any case. | 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 two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the size of the grid. Each of the following $$$n$$... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_089.jsonl | a65e4a4042961721c6407329f5477aa9 | 256 megabytes | ["5\n\n1 1\n\n1\n\n1 2\n\n1 -1\n\n1 4\n\n1 -1 1 -1\n\n3 4\n\n1 -1 -1 -1\n\n-1 1 1 -1\n\n1 1 1 -1\n\n3 4\n\n1 -1 1 1\n\n-1 1 -1 1\n\n1 -1 1 1"] | PASSED | from sys import stdin
input = stdin.readline
#// - remember to add .strip() when input is a string
t = int(input())
for _ in range(t):
n, m = map(int,input().split())
grid = []
for i in range(n):
row = list(map(int,input().split()))
grid.append(row)
new = []
for i in range(l... | 1655562900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["? 1 2\n\n? 3 4\n\n? 4 4\n\n! aabc"] | 438d18b7381671df3a68fb421b6c8169 | null | This problem is different with easy version only by constraints on total answers lengthIt is an interactive problemVenya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string $$$s$$$ of length $$$n$$$, consisting only of lowercase English letters. The player ca... | null | First line contains number $$$n$$$ ($$$1 \le n \le 100$$$) — the length of the picked string. | standard output | standard input | PyPy 3 | Python | 2,800 | train_041.jsonl | 96af280b0afb82f33da48fc634d9cc66 | 256 megabytes | ["4\n\na\naa\na\n\ncb\nb\nc\n\nc"] | PASSED | from sys import stdout
class String2:
def __init__(self, s, b=None):
if b is not None:
self.b = b
return
self.b = [0] * 26
for i in s:
self.b[ord(i) - ord('a')] += 1
def __add__(self, other):
b = self.b.copy()
for i in range(26):
... | 1578233100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["6 5 4 0 0 0", "1 2 0", "0 6 5 4 3 2 1"] | 97e68e5cf05c157b4f83eb07ff003790 | null | Nikita likes tasks on order statistics, for example, he can easily find the $$$k$$$-th number in increasing order on a segment of an array. But now Nikita wonders how many segments of an array there are such that a given number $$$x$$$ is the $$$k$$$-th number in increasing order on this segment. In other words, you sh... | Print $$$n+1$$$ integers, where the $$$i$$$-th number is the answer for Nikita's question for $$$k=i-1$$$. | The first line contains two integers $$$n$$$ and $$$x$$$ $$$(1 \le n \le 2 \cdot 10^5, -10^9 \le x \le 10^9)$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(-10^9 \le a_i \le 10^9)$$$ — the given array. | standard output | standard input | PyPy 3 | Python | 2,300 | train_040.jsonl | d59f52be8990f5ed8efbf2e0e7018c4a | 256 megabytes | ["5 3\n1 2 3 4 5", "2 6\n-5 9", "6 99\n-1 -1 -1 -1 -1 -1"] | PASSED | from math import pi
from cmath import exp
def fft(a, lgN, rot=1): # rot=-1 for ifft
N = 1<<lgN
assert len(a)==N
rev = [0]*N
for i in range(N):
rev[i] = (rev[i>>1]>>1)+(i&1)*(N>>1)
A = [a[rev[i]] for i in range(N)]
h = 1
while h<N:
w_m = exp((0+1j) * rot * (pi / h))
for k in range(0, N, h<<1):
... | 1529166900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["edb\nccbbba\nbbbbbaaaaaaa\nz\naaaaa"] | 9c86925036cd1f83273bc21e2ea3e5c8 | NoteIn the first test case, the books can be divided into $$$3$$$ compartments as below: the first compartment contains the books with indices $$$1, 2, 3, 7$$$: $$$multiset_1 = \{$$$'c', 'a', 'b', 'd'$$$\}$$$ $$$\rightarrow$$$ $$$MEX(multiset_1) =$$$ 'e' the second compartment contains the books with indices $$$4, 5,... | Ela loves reading a lot, just like her new co-workers in DTL! On her first day after becoming an engineer in DTL, she is challenged by a co-worker to sort a heap of books into different compartments on the shelf.$$$n$$$ books must be split into $$$k$$$ compartments on the bookshelf ($$$n$$$ is divisible by $$$k$$$). Ea... | For each test case, output a string of $$$k$$$ letters which is the most optimal string that Ela can find. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 200$$$; $$$1 \le k \le n$$$). It is guaranteed that $$$n$$$ is divis... | standard output | standard input | Python 3 | Python | 900 | train_094.jsonl | e69487aa7886ac8ea861fbf4d2ff0991 | 256 megabytes | ["5\n\n12 3\n\ncabccadabaac\n\n12 6\n\ncabccadabaac\n\n12 12\n\ncabccadabaac\n\n25 1\n\nabcdefghijklmnopqrstuvwxy\n\n10 5\n\nbcdxedbcfg"] | PASSED | import sys
input = sys.stdin.buffer.readline
def main():
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
burti = list(input())
#burti = burti[:-1]
print(get_mex(n, k, burti))
def get_mex(n, k, b):
burti = [0] * 30
for i in b:
... | 1665153300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["100\n22\n14\n42"] | acec4108e865c3f894de14248156abfd | NoteIn the first test case you can remove snow from the cells $$$(2, 1)$$$ and $$$(2, 2)$$$ for $$$100$$$ coins. Then you can give instructions All friends in the first collum should move to the previous cell. After this, your friend will be in the cell $$$(2, 1)$$$. All friends in the second row should move to the ... | Circular land is an $$$2n \times 2n$$$ grid. Rows of this grid are numbered by integers from $$$1$$$ to $$$2n$$$ from top to bottom and columns of this grid are numbered by integers from $$$1$$$ to $$$2n$$$ from left to right. The cell $$$(x, y)$$$ is the cell on the intersection of row $$$x$$$ and column $$$y$$$ for $... | For each test case output one integer — the minimal number of coins you should spend. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \leq n \leq 250$$$). Each of the next $$$2n$$$ lines contains $$$2n$$$ integers $$$c_{i, 1}, c_{i, 2}, \ldots, c_{i, 2n}$$$ ($$$0 \leq c_{i, j... | standard output | standard input | PyPy 3-64 | Python | 2,100 | train_092.jsonl | 8f324c47c20358fd3d96489d3977c613 | 256 megabytes | ["4\n\n1\n\n0 8\n\n1 99\n\n2\n\n0 0 0 0\n\n0 0 0 0\n\n9 9 2 2\n\n9 9 9 9\n\n2\n\n0 0 4 2\n\n0 0 2 4\n\n4 2 4 2\n\n2 4 2 4\n\n4\n\n0 0 0 0 0 0 0 2\n\n0 0 0 0 0 0 2 0\n\n0 0 0 0 0 2 0 0\n\n0 0 0 0 2 0 0 0\n\n0 0 0 2 2 0 2 2\n\n0 0 2 0 1 6 2 1\n\n0 2 0 0 2 4 7 4\n\n2 0 0 0 2 0 1 6"] | PASSED | from sys import stdin, gettrace
if gettrace():
def inputi():
return input()
else:
def input():
return next(stdin)[:-1]
def inputi():
return stdin.buffer.readline()
def solve():
n = int(input())
cc = [[int(c) for c in input().split()] for _ in range(2*n)]
res = sum(su... | 1641220500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["20", "114", "3"] | 0b4362204bb9f0e95eaf7e2949315c8f | NoteIn the first sample, the given tree has 6 vertices and it's displayed on the drawing below. Limak can jump to any vertex within distance at most 2. For example, from the vertex 5 he can jump to any of vertices: 1, 2 and 4 (well, he can also jump to the vertex 5 itself). There are pairs of vertices (s, t) such tha... | A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them.Limak is a little polar bear. He lives in a tree that consists of n vertices, numbered 1 through n.Limak recently learned how to jump. He can jump from a vertex to any vertex wi... | Print one integer, denoting the sum of f(s, t) over all pairs of vertices (s, t) such that s < t. | The first line of the input contains two integers n and k (2 ≤ n ≤ 200 000, 1 ≤ k ≤ 5) — the number of vertices in the tree and the maximum allowed jump distance respectively. The next n - 1 lines describe edges in the tree. The i-th of those lines contains two integers ai and bi (1 ≤ ai, bi ≤ n) — the indices on verti... | standard output | standard input | PyPy 2 | Python | 2,100 | train_064.jsonl | 57b3a9f455ce6f04fc39ab4ec77df006 | 256 megabytes | ["6 2\n1 2\n1 3\n2 4\n2 5\n4 6", "13 3\n1 2\n3 2\n4 2\n5 2\n3 6\n10 6\n6 7\n6 13\n5 8\n5 9\n9 11\n11 12", "3 5\n2 1\n3 1"] | PASSED | def main():
inp = readnumbers()
ii = 0
n = inp[ii]
ii += 1
k = inp[ii]
ii += 1
coupl = [[] for _ in range(n)]
for _ in range(n-1):
u = inp[ii]-1
ii += 1
v = inp[ii]-1
ii += 1
coupl[u].append(v)
coupl[v].append(u)
found = [False]*n
... | 1489851300 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1.5 seconds | ["17\n2 5 11\n-1"] | 0639fbeb3a5be67a4c0beeffe8f5d43b | NoteFor the first test case, there are only two paths having one edge each: $$$1 \to 2$$$ and $$$2 \to 1$$$, both having a weight of $$$17$$$, which is prime. The second test case is described in the statement.It can be proven that no such assignment exists for the third test case. | You are given a tree of $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$, with edges numbered from $$$1$$$ to $$$n-1$$$. A tree is a connected undirected graph without cycles. You have to assign integer weights to each edge of the tree, such that the resultant graph is a prime tree.A prime tree is a tree where the wei... | For each test case, if a valid assignment exists, then print a single line containing $$$n-1$$$ integers $$$a_1, a_2, \dots, a_{n-1}$$$ ($$$1 \leq a_i \le 10^5$$$), where $$$a_i$$$ denotes the weight assigned to the edge numbered $$$i$$$. Otherwise, print $$$-1$$$. If there are multiple solutions, you may print any. | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the number of vertices in the tree. Then, $$$... | standard output | standard input | PyPy 3-64 | Python | 1,400 | train_109.jsonl | 947c08be65b538faad5719f99f375b76 | 256 megabytes | ["3\n2\n1 2\n4\n1 3\n4 3\n2 1\n7\n1 2\n1 3\n3 4\n3 5\n6 2\n7 2"] | PASSED | from collections import defaultdict
class Graph:
def __init__(self):
self.graph = defaultdict(list)
def addEdge(self,u,v):
self.graph[u].append(v)
self.graph[v].append(u)
# 2.DFS from a vertex
def DFS(self,vertex):
path=[]
stack... | 1642257300 | [
"number theory",
"trees"
] | [
0,
0,
0,
0,
1,
0,
0,
1
] | |
3 seconds | ["39\n32\n0"] | 99e3ab8db0a27cdb6882486dcd46ef0b | Note In the first query, their movement from the $$$1$$$-st to the $$$2$$$-nd room is as follows. $$$1 \rightarrow 5$$$ — takes $$$\max(|10 + 4|, |10 - 4|) = 14$$$ energy. $$$5 \rightarrow 6$$$ — takes $$$\max(|4 + (-6)|, |4 - (-6)|) = 10$$$ energy. $$$6 \rightarrow 2$$$ — takes $$$\max(|-6 + (-9)|, |-6 - (-9)|) = ... | Chanek Jones is back, helping his long-lost relative Indiana Jones, to find a secret treasure in a maze buried below a desert full of illusions.The map of the labyrinth forms a tree with $$$n$$$ rooms numbered from $$$1$$$ to $$$n$$$ and $$$n - 1$$$ tunnels connecting them such that it is possible to travel between eac... | For each type $$$2$$$ query, output a line containing an integer — the minimum sum of energy needed for Chanek and Indiana to take the secret treasure. | The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \leq n \leq 10^5$$$, $$$1 \leq q \leq 10^5$$$) — the number of rooms in the maze and the number of queries. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq |a_i| \leq 10^9$$$) — inital illusion rate of each room. The $$$i$$$... | standard output | standard input | PyPy 3 | Python | 2,300 | train_102.jsonl | 84f05661557fd1a0cc492051130ef824 | 512 megabytes | ["6 4\n10 -9 2 -1 4 -6\n1 5\n5 4\n5 6\n6 2\n6 3\n2 1 2\n1 1 -3\n2 1 2\n2 3 3"] | PASSED | def naiveSolve():
return
def solve():
return
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
... | 1633181700 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["10.0000000000", "-1", "85.4800000000"] | d9bd63e03bf51ed87ba73cd15e8ce58d | NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Ma... | Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight... | If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be consider... | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$) — weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the numbe... | standard output | standard input | Python 3 | Python | 1,500 | train_000.jsonl | 81dc74b11eab12928dcc4fe4ab4fde0f | 256 megabytes | ["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3"] | PASSED | """for p in range(int(input())):
n,k=map(int,input().split(" "))
number=input().split(" ")
chances=[k for i in range(n)]
prev=-1
prev_updated=-1
last_used=False
toSub=0
start=0
prevSub=0
if(number[0]=='1'):
prev=0
prev_updated=0
start=1
for i in range(start,n):
if(number[i]=='1'):
# print("... | 1532617500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | ee9ba877dee1a2843e885a18823cbff0 | null | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of ... | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditi... | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | standard output | standard input | Python 2 | Python | 1,100 | train_005.jsonl | 6b79c0b265b02b0d8b1c3879c2880d13 | 256 megabytes | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | PASSED | I=lambda:map(int, raw_input().split())
n=input()
for _ in xrange(n):
s=raw_input()
if s.startswith('miao.') and s.endswith('lala.'): print 'OMG>.< I don\'t know!'
elif s.startswith('miao.'): print 'Rainbow\'s'
elif s.endswith('lala.'): print 'Freda\'s'
else: print 'OMG>.< I don\'t know!' | 1369582200 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["3", "10"] | 782b819eb0bfc86d6f96f15ac09d5085 | NoteThe first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one. | Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divide... | Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7). | The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | standard output | standard input | Python 3 | Python | 1,300 | train_023.jsonl | acd19a5f6a8b1c40c2c03f39b1e4fa52 | 256 megabytes | ["1", "2"] | PASSED | n = int(input())
mod = 10**9 +7
def power_2_k(k):
if k == 0:
return 1
if k % 2 == 0:
lower = power_2_k(k // 2)
return (lower * lower) % mod
else:
k -= 1
lower = power_2_k(k // 2)
return (((lower * lower) % mod) * 2) % mod
p = power_2_k(n)
print((p * (p + 1)... | 1336145400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0\nDDRR"] | 13c58291ab9cf7ad1b8c466c3e36aacf | null | There is a square matrix n × n, consisting of non-negative integer numbers. You should find such a way on it that starts in the upper left cell of the matrix; each following cell is to the right or down from the current cell; the way ends in the bottom right cell. Moreover, if we multiply together all the numbers a... | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | The first line contains an integer number n (2 ≤ n ≤ 1000), n is the size of the matrix. Then follow n lines containing the matrix elements (non-negative integer numbers not exceeding 109). | standard output | standard input | PyPy 3 | Python | 2,000 | train_004.jsonl | fce8911b7e6e06e7b36a7a2c9f5b4251 | 64 megabytes | ["3\n1 2 3\n4 5 6\n7 8 9"] | PASSED | n = int(input())
xr = range(n)
a5 = [list(map(int, input().split())) for _ in xr]
a2 = [[0 for _ in xr] for _ in xr]
y = 0
x0 = -1
for y in xr:
for x in xr:
i = a5[y][x]
m5 = 0
m2 = 0
if i == 0:
x0 = x
while i and i%2 == 0:
i/=2
... | 1267117200 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1\n****\n*..*\n****\n****\n..**", "1\n***\n***\n***"] | e514d949e7837c603a9ee032f83b90d2 | NoteIn the first example there are only two lakes — the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border wit... | The map of Berland is a rectangle of the size n × m, which consists of cells of size 1 × 1. Each cell is either land or water. The map is surrounded by the ocean. Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that i... | In the first line print the minimum number of cells which should be transformed from water to land. In the next n lines print m symbols — the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, pri... | The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 50, 0 ≤ k ≤ 50) — the sizes of the map and the number of lakes which should be left on the map. The next n lines contain m characters each — the description of the map. Each of the characters is either '.' (it means that the corresponding cell i... | standard output | standard input | Python 3 | Python | 1,600 | train_027.jsonl | 7ffd074e9d27acae64081da685cb6dac | 256 megabytes | ["5 4 1\n****\n*..*\n****\n**.*\n..**", "3 3 0\n***\n*.*\n***"] | PASSED | n,m,k = (int(x) for x in input().split())
Map = []
lakesizes = [0]
lakemembers = [0]
for i in range(n):
Map.append([x for x in input()])
stack = [(x,y,None) for x in range(1,m-1) for y in range(1,n-1)] + [(0,y,None) for y in range(n)] + [(m-1,y,None) for y in range(n)] + [(x,0,None) for x in range(1,m-1)] + [(x... | 1475494500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["4", "3"] | 09f5623c3717c9d360334500b198d8e0 | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number ... | In a single line print a single integer — the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | The first line contains integer n (3 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play. | standard output | standard input | PyPy 2 | Python | 1,600 | train_009.jsonl | 598070e42b55dd31be98dadc7a48faed | 256 megabytes | ["3\n3 2 2", "4\n2 2 2 2"] | PASSED | """
// Author : snape_here - Susanta Mukherjee
"""
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(... | 1380295800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1.5000000000", "10.2222222222"] | f404720fd6624174c33d93af6349e561 | NoteIn the first sample, Niwel has three bears. Two bears can choose the path , while one bear can choose the path . Even though the bear that goes on the path can carry one unit of weight, in the interest of fairness, he is restricted to carry 0.5 units of weight. Thus, the total weight is 1.5 units overall. Note tha... | Niwel is a little golden bear. As everyone knows, bears live in forests, but Niwel got tired of seeing all the trees so he decided to move to the city.In the city, Niwel took on a job managing bears to deliver goods. The city that he lives in can be represented as a directed graph with n nodes and m edges. Each edge ha... | Print one real value on a single line — the maximum amount of weight Niwel can deliver if he uses exactly x bears. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consid... | The first line contains three integers n, m and x (2 ≤ n ≤ 50, 1 ≤ m ≤ 500, 1 ≤ x ≤ 100 000) — the number of nodes, the number of directed edges and the number of bears, respectively. Each of the following m lines contains three integers ai, bi and ci (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ ci ≤ 1 000 000). This represents a dir... | standard output | standard input | Python 3 | Python | 2,200 | train_051.jsonl | 88233b56744fe41b4fe1fcc8149e2b33 | 256 megabytes | ["4 4 3\n1 2 2\n2 4 1\n1 3 1\n3 4 2", "5 11 23\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n1 3 4\n2 4 5\n3 5 6\n1 4 2\n2 5 3\n1 5 2\n3 2 30"] | PASSED | from queue import Queue
def addEdge(s, t, flow):
E[s].append((len(E[t]), t, flow))
E[t].append((len(E[s])-1, s, 0))
def mkLevel():
global src, des, E, lvl
for i in range(n):
lvl[i] = -1
lvl[src] = 0
q = Queue()
q.put(src)
while (not q.empty()):
cur = q.get()
... | 1458376500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["8\n0\n500\n2128012501878\n899999999999999999"] | 50738d19041f2e97e2e448eff3feed84 | null | You are given a positive integer $$$n$$$. In one move, you can increase $$$n$$$ by one (i.e. make $$$n := n + 1$$$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $$$n$$$ be less than or equal to $$$s$$$.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $$$n$$$ be less than or equal to $$$s$$$. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 10^{18}$$$; $$$1 \le s \le 162$$$). | standard output | standard input | Python 3 | Python | 1,500 | train_005.jsonl | db1243f680b2a769c0b2379280066c8f | 256 megabytes | ["5\n2 1\n1 1\n500 4\n217871987498122 10\n100000000000000001 1"] | PASSED | for _ in range(int(input())):
d,s=input().split()
n=[int(i) for i in d]
s=int(s)
if sum(n)<=s:
print(0)
else:
c=0
t=len(n)
for i in range(len(n)):
if c+n[i]<s:
c+=n[i]
else:
break
f=d[i:]
t=t-i
... | 1599230100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["5 2 \n8 2 1 3 \n9 3 8 \n100 50 25 75 64 \n42 \n128 96 80 88 52 7 \n17 2 4 8 16"] | bdd1974e46f99eff3d03ed4174158dd9 | NoteIn the first test case of the example, there are only two possible permutations $$$b$$$ — $$$[2, 5]$$$ and $$$[5, 2]$$$: for the first one $$$c=[2, 1]$$$, for the second one $$$c=[5, 1]$$$.In the third test case of the example, number $$$9$$$ should be the first in $$$b$$$, and $$$GCD(9, 3)=3$$$, $$$GCD(9, 8)=1$$$... | Alexander is a well-known programmer. Today he decided to finally go out and play football, but with the first hit he left a dent on the new Rolls-Royce of the wealthy businessman Big Vova. Vladimir has recently opened a store on the popular online marketplace "Zmey-Gorynych", and offers Alex a job: if he shows his pro... | For each test case output the answer in a single line — the desired sequence $$$b$$$. If there are multiple answers, print any. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^3$$$) — the length of the sequence $$$a$$$. The second line of each tes... | standard output | standard input | PyPy 3 | Python | 1,300 | train_015.jsonl | ec7dd9492b6309e80129e40cc2248f55 | 256 megabytes | ["7\n2\n2 5\n4\n1 8 2 3\n3\n3 8 9\n5\n64 25 75 100 50\n1\n42\n6\n96 128 88 80 52 7\n5\n2 4 8 16 17"] | PASSED | import math
def get_int():
return int(input())
def get_int_list():
return list(map(int, input().split()))
def get_char_list():
return list(input())
def gcd(x, y):
if x < y:
return gcd(y, x)
z = x % y
if z == 0:
return y
else:
return gcd(y, z)
cases = get_int()
... | 1599575700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
3 seconds | ["YES\nYES\nNO\nYES"] | a213bc75245657907c0ae28b067985f2 | NoteThe queries in the example are following: substrings "a" and "a" are isomorphic: f(a) = a; substrings "ab" and "ca" are isomorphic: f(a) = c, f(b) = a; substrings "bac" and "aba" are not isomorphic since f(b) and f(c) must be equal to a at same time; substrings "bac" and "cab" are isomorphic: f(b) = c, f(a) = ... | You are given a string s of length n consisting of lowercase English letters.For two given strings s and t, say S is the set of distinct characters of s and T is the set of distinct characters of t. The strings s and t are isomorphic if their lengths are equal and there is a one-to-one mapping (bijection) f between S a... | For each query in a separate line print "YES" if substrings s[xi... xi + leni - 1] and s[yi... yi + leni - 1] are isomorphic and "NO" otherwise. | The first line contains two space-separated integers n and m (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 2·105) — the length of the string s and the number of queries. The second line contains string s consisting of n lowercase English letters. The following m lines contain a single query on each line: xi, yi and leni (1 ≤ xi, yi ≤ n, 1 ≤... | standard output | standard input | Python 3 | Python | 2,300 | train_075.jsonl | 8505e2d022784e6519f8fd2c4442ad77 | 256 megabytes | ["7 4\nabacaba\n1 1 1\n1 4 2\n2 1 3\n2 4 3"] | PASSED | def getIntList():
return list(map(int, input().split()));
def getTransIntList(n):
first=getIntList();
m=len(first);
result=[[0]*n for _ in range(m)];
for i in range(m):
result[i][0]=first[i];
for j in range(1, n):
curr=getIntList();
for i in range(m):
result[i... | 1526913900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["10100\n011\n10100101"] | 9683d5960247359b6b9066e96897d6f9 | NoteIn the first test case, we have the following: $$$s_1 = s_2 + s_2$$$, since $$$\texttt{abab} = \texttt{ab} + \texttt{ab}$$$. Remember that $$$j$$$ can be equal to $$$k$$$. $$$s_2$$$ is not the concatenation of any two strings in the list. $$$s_3 = s_2 + s_5$$$, since $$$\texttt{abc} = \texttt{ab} + \texttt{c}$$... | You are given $$$n$$$ strings $$$s_1, s_2, \dots, s_n$$$ of length at most $$$\mathbf{8}$$$. For each string $$$s_i$$$, determine if there exist two strings $$$s_j$$$ and $$$s_k$$$ such that $$$s_i = s_j + s_k$$$. That is, $$$s_i$$$ is the concatenation of $$$s_j$$$ and $$$s_k$$$. Note that $$$j$$$ can be equal to $$$k... | For each test case, output a binary string of length $$$n$$$. The $$$i$$$-th bit should be $$$\texttt{1}$$$ if there exist two strings $$$s_j$$$ and $$$s_k$$$ where $$$s_i = s_j + s_k$$$, and $$$\texttt{0}$$$ otherwise. Note that $$$j$$$ can be equal to $$$k$$$. | 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 a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of strings. Then $$$n$$$ lines follow, the $$$i$$$-th of which contains non-empty string $$$s_i$$$ of length ... | standard output | standard input | PyPy 3-64 | Python | 1,100 | train_086.jsonl | 31e0c17a56cfd42027cfd11450e4b881 | 256 megabytes | ["3\n\n5\n\nabab\n\nab\n\nabc\n\nabacb\n\nc\n\n3\n\nx\n\nxx\n\nxxx\n\n8\n\ncodeforc\n\nes\n\ncodes\n\ncod\n\nforc\n\nforces\n\ne\n\ncode"] | PASSED | #import io, os
#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t=int(input())
for _ in range(t):
n=int(input())
words=[]
prefs={}
suffs={}
for i in range(n):
word=input()
words.append(word)
if not word in prefs:
prefs.update({word:1})
else:
prefs.updat... | 1657636500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["10", "180 10"] | 87c3a8a0d49288d0f6242fe2ac69a641 | null | You wrote down all integers from $$$0$$$ to $$$10^n - 1$$$, padding them with leading zeroes so their lengths are exactly $$$n$$$. For example, if $$$n = 3$$$ then you wrote out 000, 001, ..., 998, 999.A block in an integer $$$x$$$ is a consecutive segment of equal digits that cannot be extended to the left or to the r... | In the only line print $$$n$$$ integers. The $$$i$$$-th integer is equal to the number of blocks of length $$$i$$$. Since these integers may be too large, print them modulo $$$998244353$$$. | The only line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). | standard output | standard input | PyPy 3 | Python | 1,800 | train_007.jsonl | 62d191e3d38ce5676f43b46a4709c270 | 256 megabytes | ["1", "2"] | PASSED | # |
# _` | __ \ _` | __| _ \ __ \ _` | _` |
# ( | | | ( | ( ( | | | ( | ( |
# \__,_| _| _| \__,_| \___| \___/ _| _| \__,_| \__,_|
import sys
def read_line():
return sys.stdin.readline()[:-1]
def read_int():
return int(sys.s... | 1584974100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2\n5000 9\n1\n7 \n4\n800 70 6 9000 \n1\n10000 \n1\n10"] | cd2519f4a7888b2c292f05c64a9db13a | null | A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from $$$1$$$ to $$$9$$$ (inclusive) are round.For example, the following number... | Print $$$t$$$ answers to the test cases. Each answer must begin with an integer $$$k$$$ — the minimum number of summands. Next, $$$k$$$ terms must follow, each of which is a round number, and their sum is $$$n$$$. The terms can be printed in any order. If there are several answers, print any of them. | 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 a line containing an integer $$$n$$$ ($$$1 \le n \le 10^4$$$). | standard output | standard input | PyPy 3 | Python | 800 | train_000.jsonl | 52a2313fac7f87cb6696ab7b8e4dc447 | 256 megabytes | ["5\n5009\n7\n9876\n10000\n10"] | PASSED | t = int(input())
for i in range(t):
canPrintLength = True
summends = []
num = int(input())
if num in range(1,11):
print(1)
print(num)
else:
a = 10
g = str(num)
length = len(g)
while num!=0:
rem = num%a
if rem !=0:
... | 1590154500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["5\n1 2\n5 3\n4 5\n1 5\n1 3", "0"] | 3b885c926076382f778a27a3c1f49d91 | NoteThe following animation showcases the first sample test case. The black numbers represent the indices of the points, while the boxed orange numbers represent their labels. In the second test case, all labels are already in their correct positions, so no operations are necessary. | Based on a peculiar incident at basketball practice, Akari came up with the following competitive programming problem!You are given $$$n$$$ points on the plane, no three of which are collinear. The $$$i$$$-th point initially has a label $$$a_i$$$, in such a way that the labels $$$a_1, a_2, \dots, a_n$$$ form a permutat... | If it is impossible to perform a valid sequence of operations, print $$$-1$$$. Otherwise, print an integer $$$k$$$ ($$$0 \le k \le \frac{n(n - 1)}{2}$$$) — the number of operations to perform, followed by $$$k$$$ lines, each containing two integers $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$, $$$i\neq j$$$) — the ind... | The first line contains an integer $$$n$$$ ($$$3 \le n \le 2000$$$) — the number of points. The $$$i$$$-th of the following $$$n$$$ lines contains three integers $$$x_i$$$, $$$y_i$$$, $$$a_i$$$ ($$$-10^6 \le x_i, y_i \le 10^6$$$, $$$1 \le a_i \le n$$$), representing that the $$$i$$$-th point has coordinates $$$(x_i, y... | standard output | standard input | Python 3 | Python | 3,000 | train_087.jsonl | 769343769fd52101ba06f019dab19e35 | 256 megabytes | ["5\n-1 -2 2\n3 0 5\n1 3 4\n4 -3 3\n5 2 1", "3\n5 4 1\n0 0 2\n-3 -2 3"] | PASSED | import sys,io,os
try:Z=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
except:Z=lambda:sys.stdin.readline().encode()
from math import atan2;from collections import deque
def path(R):
H=deque();H.append(R)
while P[R]>=0:
R=P[R];H.append(R)
if len(H)>2:P[H.popleft()]=H[-1]
return ... | 1618583700 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["-1\n1 2", "1 2\n1 3\n2 4\n2 5\n3 6\n4 7\n4 8\n1 2\n1 3\n2 4\n2 5\n2 6\n3 7\n6 8"] | b1959af75dfdf8281e70ae66375caa14 | NoteIn the first sample, there is only 1 tree with 2 nodes (node 1 connected to node 2). The algorithm will produce a correct answer in it so we printed - 1 in the first section, but notice that we printed this tree in the second section.In the second sample:In the first tree, the algorithm will find an answer with 4 ... | Mahmoud was trying to solve the vertex cover problem on trees. The problem statement is:Given an undirected tree consisting of n nodes, find the minimum number of vertices that cover all the edges. Formally, we need to find a set of vertices such that for each edge (u, v) that belongs to the tree, either u is in the se... | The output should consist of 2 independent sections, each containing a tree. The algorithm should find an incorrect answer for the tree in the first section and a correct answer for the tree in the second. If a tree doesn't exist for some section, output "-1" (without quotes) for that section only. If the answer for a ... | The only line contains an integer n (2 ≤ n ≤ 105), the number of nodes in the desired trees. | standard output | standard input | Python 3 | Python | 1,500 | train_005.jsonl | 618613b04fb35fe6c9c94258bfc4974c | 256 megabytes | ["2", "8"] | PASSED | def wrong(x):
if n < 6:
print(-1)
else:
print("1 2")
print("2 3")
print("2 4")
print("4 5")
print("4 6")
for i in range(7, x + 1):
print("4", i)
def true(x):
for i in range(x-1):
print(i+1,i+2)
n = int(input())
wrong(n)
true(n) | 1522771500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.