prob_desc_time_limit stringclasses 21
values | prob_desc_sample_outputs stringlengths 5 329 | src_uid stringlengths 32 32 | prob_desc_notes stringlengths 31 2.84k ⌀ | prob_desc_description stringlengths 121 3.8k | prob_desc_output_spec stringlengths 17 1.16k ⌀ | prob_desc_input_spec stringlengths 38 2.42k ⌀ | prob_desc_output_to stringclasses 3
values | prob_desc_input_from stringclasses 3
values | lang stringclasses 5
values | lang_cluster stringclasses 1
value | difficulty int64 -1 3.5k ⌀ | file_name stringclasses 111
values | code_uid stringlengths 32 32 | prob_desc_memory_limit stringclasses 11
values | prob_desc_sample_inputs stringlengths 5 802 | exec_outcome stringclasses 1
value | source_code stringlengths 29 58.4k | prob_desc_created_at stringlengths 10 10 | tags listlengths 1 5 | hidden_unit_tests stringclasses 1
value | labels listlengths 8 8 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2 seconds | ["Yes\n2 2 2 \n1 1 1 1", "Yes\n3 1 3 \n2 2 2", "No"] | 016bf7989ba58fdc3894a4cf3e0ac302 | NoteIn the first sample, all dishes of the first day are better than dishes of the second day. So, the highest score will be $$$2$$$, for all dishes of the first day.In the third sample, the table is contradictory — there is no possible evaluation of the dishes that satisfies it. | Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the d... | The first line of output should contain "Yes", if it's possible to do a correct evaluation for all the dishes, or "No" otherwise. If case an answer exist, on the second line print $$$n$$$ integers — evaluations of dishes from the first set, and on the third line print $$$m$$$ integers — evaluations of dishes from the s... | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 1000$$$) — the number of dishes in both days. Each of the next $$$n$$$ lines contains a string of $$$m$$$ symbols. The $$$j$$$-th symbol on $$$i$$$-th line is $$$a_{ij}$$$. All strings consist only of "<", ">" and "=". | standard output | standard input | Python 3 | Python | 2,000 | train_029.jsonl | 1105e4e520630e0c038466958c22f635 | 256 megabytes | ["3 4\n>>>>\n>>>>\n>>>>", "3 3\n>>>\n<<<\n>>>", "3 2\n==\n=<\n=="] | PASSED | n, m = map(int, input().split())
dishes = [0 for _ in range(n + m)]
father = [-1 for _ in range(n + m)]
e_out = dict()
v_in = [0 for _ in range(n + m)]
def get_father(n):
if father[n] == -1:
return n
else:
father[n] = get_father(father[n])
return father[n]
compare_matrix = []
for i... | 1550917200 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["YES\nNO\nYES\nYES\nNO\nYES\nYES\nYES"] | c3df88e22a17492d4eb0f3239a27d404 | NoteIn the first test case of the example, the following sequence of moves can be performed: choose $$$i=3$$$, element $$$a_3=5$$$ is blue, so we decrease it, we get $$$a=[1,2,4,2]$$$; choose $$$i=2$$$, element $$$a_2=2$$$ is red, so we increase it, we get $$$a=[1,3,4,2]$$$; choose $$$i=3$$$, element $$$a_3=4$$$ is ... | You are given an array of integers $$$a$$$ of length $$$n$$$. The elements of the array can be either different or the same. Each element of the array is colored either blue or red. There are no unpainted elements in the array. One of the two operations described below can be applied to an array in a single step: eith... | Print $$$t$$$ lines, each of which contains the answer to the corresponding test case of the input. Print YES as an answer if the corresponding array can be transformed into a permutation, and NO otherwise. You can print the answer in any case (for example, the strings yEs, yes, Yes, and YES will be recognized as a pos... | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of input data sets in the test. The description of each set of input data consists of three lines. The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of the original array $$$a$$$. The second line ... | standard output | standard input | PyPy 3-64 | Python | 1,300 | train_108.jsonl | 146f825f0fdf5c72770365ff8caeea1c | 256 megabytes | ["8\n4\n1 2 5 2\nBRBR\n2\n1 1\nBB\n5\n3 1 4 2 5\nRBRRB\n5\n3 1 3 1 3\nRBRRB\n5\n5 1 5 1 5\nRBRRB\n4\n2 2 2 2\nBRBR\n2\n1 -2\nBR\n4\n-2 -1 4 0\nRRRR"] | PASSED | t = int(input())
for _ in range(t):
n = int(input())
A = list(map(int, input().split()))
B = []
R = []
S = input()
for a, s in zip(A, S):
if s == "B":
B.append(a)
else:
R.append(a)
B.sort()
R.sort()
flag = True
for i in range(len(B)):
if B[i] < i+1:
fla... | 1635863700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["6", "15", "7"] | 2090c7382ef9bc8dfd9ca1fc1743d3a7 | NoteIn the second sample the only optimal answer is to use two circles: a circle with $$$5$$$ chairs accomodating guests $$$1$$$ and $$$2$$$, and another one with $$$10$$$ chairs accomodationg guests $$$3$$$ and $$$4$$$.In the third sample, you have only one circle with one person. The guest should have at least five f... | You invited $$$n$$$ guests to dinner! You plan to arrange one or more circles of chairs. Each chair is going to be either occupied by one guest, or be empty. You can make any number of circles. Your guests happen to be a little bit shy, so the $$$i$$$-th guest wants to have a least $$$l_i$$$ free chairs to the left of ... | Output a single integer — the smallest number of chairs you have to use. | First line contains one integer $$$n$$$ — number of guests, ($$$1 \leqslant n \leqslant 10^5$$$). Next $$$n$$$ lines contain $$$n$$$ pairs of space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$0 \leqslant l_i, r_i \leqslant 10^9$$$). | standard output | standard input | Python 3 | Python | 1,900 | train_017.jsonl | b0fedd4835cfb0069279a40c181793ec | 512 megabytes | ["3\n1 1\n1 1\n1 1", "4\n1 2\n2 1\n3 5\n5 3", "1\n5 6"] | PASSED | n = int(input())
l = []
r = []
for i in range(n):
numbers_in_line = [int(num) for num in input().split()]
l_new, r_new = numbers_in_line
l.append(l_new)
r.append(r_new)
l.sort()
r.sort()
maxes = [max(lv, rv) for lv, rv in zip(l, r)]
print(n + sum(maxes))
| 1538636700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["6\n2\n15\n30"] | 5a544816938d05da4f85fe7589d3289a | NoteConsider the example: boundaries for first query are $$$(0 + 1) \bmod 3 + 1 = 2$$$ and $$$(0 + 3) \bmod 3 + 1 = 1$$$. LCM for segment $$$[1, 2]$$$ is equal to $$$6$$$; boundaries for second query are $$$(6 + 3) \bmod 3 + 1 = 1$$$ and $$$(6 + 3) \bmod 3 + 1 = 1$$$. LCM for segment $$$[1, 1]$$$ is equal to $$$2$$$;... | Yura owns a quite ordinary and boring array $$$a$$$ of length $$$n$$$. You think there is nothing more boring than that, but Vladik doesn't agree!In order to make Yura's array even more boring, Vladik makes $$$q$$$ boring queries. Each query consists of two integers $$$x$$$ and $$$y$$$. Before answering a query, the bo... | Print $$$q$$$ integers — the answers for the queries. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$) — the elements of the array. The third line contains a single integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of queries. The ... | standard output | standard input | PyPy 2 | Python | 2,700 | train_033.jsonl | 2c9b01f4d0b76f096e10b0fcc22b1f6b | 512 megabytes | ["3\n2 3 5\n4\n1 3\n3 3\n2 3\n2 3"] | PASSED | import sys
range = xrange
input = raw_input
# MOD
MOD = 10**9 + 7
def fast_modder(MOD):
""" Returns function modmul(a,b) that quickly calculates a * b % MOD, assuming 0 <= a,b < MOD """
import sys, platform
impl = platform.python_implementation()
maxs = sys.maxsize
if 'PyPy' in impl and MOD <= max... | 1601827500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["D\nLR\nLRULR\nDDDDDD"] | b894e16e8c00f8d97fde4a104466b3ef | NoteIn the first test case, Alice shows Bob the top row, the whole grid may look like: In the second test case, Alice shows Bob the bottom row, the whole grid may look like: In the third test case, Alice shows Bob the bottom row, the whole grid may look like: In the fourth test case, Alice shows Bob the top row, ... | Alice has a grid with $$$2$$$ rows and $$$n$$$ columns. She fully covers the grid using $$$n$$$ dominoes of size $$$1 \times 2$$$ — Alice may place them vertically or horizontally, and each cell should be covered by exactly one domino.Now, she decided to show one row of the grid to Bob. Help Bob and figure out what the... | For each test case, output one string — the other row of the grid, using the same format as the input string. If there are multiple answers, print any. | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 5000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the width of the grid. The second line of each ... | standard output | standard input | Python 3 | Python | 800 | train_089.jsonl | ead399f8737f3a5e4c18bb937feaf30f | 256 megabytes | ["4\n1\nU\n2\nLR\n5\nLRDLR\n6\nUUUUUU"] | PASSED |
n1 = int(input())
for a in range(n1):
n2 = int(input())
string1 = input().upper().strip()
str = ""
for i in string1:
if i == "U":
str += "D"
elif i == "D":
str += "U"
else:
str += i
print(str) | 1630852500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["25", "2", "Impossible"] | 14b65af01caf1f3971a2f671589b86a8 | null | Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for the contestants and wrote on each of them a unique id (integer fro... | If it is possible for Chloe and Vladik to choose prizes without fighting, print single integer — the maximum possible sum of pleasantness they can get together. Otherwise print Impossible. | The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of gifts. The next line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the pleasantness of the gifts. The next (n - 1) lines contain two numbers each. The i-th of these lines contains integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the de... | standard output | standard input | Python 2 | Python | 1,800 | train_014.jsonl | 18e5cdd84f36fc2a2ccf6d53818ed86e | 256 megabytes | ["8\n0 5 -1 4 3 2 6 5\n1 2\n2 4\n2 5\n1 3\n3 6\n6 7\n6 8", "4\n1 -5 1 1\n1 2\n1 4\n2 3", "1\n-1"] | PASSED | from collections import defaultdict
#import sys
#sys.setrecursionlimit(3*10**5)
n = int(raw_input())
A = [0]+map(int, raw_input().split())
AdjOf = [ [] for x in xrange(n+5)]
for i in xrange(n-1):
u,v = map(int, raw_input().split())
AdjOf[u].append(v)
AdjOf[v].append(u)
ChildrenOf = [ [] for x in xran... | 1481726100 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["2", "3", "5"] | 60776cefd6c1a2f3c16b3378ebc31a9a | NoteIn the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6. In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on... | Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. | The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of flats in the house. The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i. | standard output | standard input | Python 3 | Python | 1,500 | train_001.jsonl | 7dfb199bc37b4d5b53b4e6ca9a2f664f | 256 megabytes | ["3\nAaA", "7\nbcAAcbc", "6\naaBCCe"] | PASSED | n = int(input())
s = input()
D = dict()
A = set()
for i in range(n):
if s[i] not in A:
A.add(s[i])
l = 100001
for i in A:
D[i] = 0
g = 0
c = '0'
for i in range(n):
D[s[i]] += 1
q = 0
if c == '0':
for k in A:
if D[k] == 0:
break
else:
q ... | 1469205300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["2\n0\n0\n1\n2\n1\n1\n0"] | a4b8e1ffe14c91381ae69e3b23ee4937 | Note The tree before the task pow 1. The tree after the task pow 1. | Danil decided to earn some money, so he had found a part-time job. The interview have went well, so now he is a light switcher.Danil works in a rooted tree (undirected connected acyclic graph) with n vertices, vertex 1 is the root of the tree. There is a room in each vertex, light can be switched on or off in each room... | For each task get v print the number of rooms in the subtree of v, in which the light is turned on. | The first line contains a single integer n (1 ≤ n ≤ 200 000) — the number of vertices in the tree. The second line contains n - 1 space-separated integers p2, p3, ..., pn (1 ≤ pi < i), where pi is the ancestor of vertex i. The third line contains n space-separated integers t1, t2, ..., tn (0 ≤ ti ≤ 1), where ti is 1... | standard output | standard input | PyPy 2 | Python | 2,000 | train_013.jsonl | 72fda9afd2e47f8a6323e698b2beb69d | 256 megabytes | ["4\n1 1 1\n1 0 0 1\n9\nget 1\nget 2\nget 3\nget 4\npow 1\nget 1\nget 2\nget 3\nget 4"] | PASSED | from sys import stdin, stdout
from itertools import repeat
def main():
n = int(stdin.readline())
p = map(int, stdin.readline().split(), repeat(10, n - 1))
ch = [[] for _ in xrange(n)]
for i, x in enumerate(p, 1):
ch[x-1].append(i)
st = []
pu = st.append
po = st.pop
col = [None] *... | 1508773500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
3 seconds | ["0 1 1", "0 1 4 6", "0 1", "0 1 2 2 3"] | 261b22421590cf6bb1d602e1dc7e0243 | NoteIn the first sample, it takes no time to get to city 1; to get to city 2 it is possible to use a flight between 1 and 2, which will take 1 unit of time; to city 3 you can get via a road from city 1, which will take 1 unit of time. In the second sample, it also takes no time to get to city 1. To get to city 2 Stanle... | Stanley lives in a country that consists of $$$n$$$ cities (he lives in city $$$1$$$). There are bidirectional roads between some of the cities, and you know how long it takes to ride through each of them. Additionally, there is a flight between each pair of cities, the flight between cities $$$u$$$ and $$$v$$$ takes $... | Print $$$n$$$ integers, $$$i$$$-th of which is equal to the minimum time of traveling to city $$$i$$$. | In the first line of input there are three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$2 \leq n \leq 10^{5}$$$, $$$1 \leq m \leq 10^{5}$$$, $$$1 \leq k \leq 20$$$) — the number of cities, the number of roads, and the maximal number of flights Stanley can take. The following $$$m$$$ lines describe the roads. Each contain... | standard output | standard input | PyPy 3-64 | Python | 2,400 | train_082.jsonl | 1c473ae3f909b3bb1daa8513937b896f | 256 megabytes | ["3 1 2\n1 3 1", "4 3 1\n1 2 3\n2 4 5\n3 4 7", "2 1 1\n2 1 893746473", "5 5 2\n2 1 33\n1 5 93\n5 3 48\n2 3 21\n4 2 1"] | PASSED | from sys import stdin
input=lambda :stdin.readline()[:-1]
n,m,k=map(int,input().split())
edge=[[] for i in range(n)]
for _ in range(m):
a,b,c=map(int,input().split())
a,b=a-1,b-1
edge[a].append((b,c))
edge[b].append((a,c))
from heapq import heappop,heappush
mask=(1<<17)-1
def dijkstra():
hq=... | 1661006100 | [
"geometry",
"graphs"
] | [
0,
1,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1\n1.1\n1.2\n1.3\n1\n1.1\n1.1.1\n1.1.2\n1.2\n1.2.1\n2\n2.1\n2.2"] | c1bf6c8a9a20f377cf2a5dbea2267c88 | NoteIn the second example test case one example of a fitting list is:11.1 1.1.11.1.21.21.2.122.12.2This list can be produced by using the sequence of operations shown below: Original list with a single item $$$1$$$. Insert item $$$2$$$ by using the insertion operation of the second type after item $$$1$$$. Insert ... | William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | For each test case output $$$n$$$ lines which represent a valid nested list, which could become the data provided to you by William. 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$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^3$$$), which is the number of lines in the list. Each of the next $$$n$$$ ... | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_082.jsonl | 37fe5b8f35db843504398fccc877948f | 256 megabytes | ["2\n4\n1\n1\n2\n3\n9\n1\n1\n1\n2\n2\n1\n2\n1\n2"] | PASSED | for h in range(int(input())):
n=int(input())
s=[]
for i in range(n):
j = int(input())
if j==1:
s.append(j)
else:
while j-s[-1]!=1:
s.pop()
s[-1]=j
print('.'.join(map(str, s))) | 1622385300 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["3 2 2 0 0 0 0 \n0 3 0 2 0 0 \n1 \n0 0 1 1 1 \n1 0 4 0 0 0 \n2 2 2 2 0 0 0 0"] | c63640fd70e0268f03cb4eec18540f3a | NoteIn the first test case, one of the possible ways to form a tower of color $$$1$$$ and size $$$3$$$ is: place block $$$1$$$ at position $$$(0, 0)$$$; place block $$$2$$$ to the right of block $$$1$$$, at position $$$(1, 0)$$$; place block $$$3$$$ above block $$$2$$$, at position $$$(1, 1)$$$; place block $$$4$$... | You have a sequence of $$$n$$$ colored blocks. The color of the $$$i$$$-th block is $$$c_i$$$, an integer between $$$1$$$ and $$$n$$$.You will place the blocks down in sequence on an infinite coordinate grid in the following way. Initially, you place block $$$1$$$ at $$$(0, 0)$$$. For $$$2 \le i \le n$$$, if the $$$... | For each test case, output $$$n$$$ integers. The $$$r$$$-th of them should be the maximum size of an tower of color $$$r$$$ you can form by following the given rules. If you cannot form any tower of color $$$r$$$, the $$$r$$$-th integer should be $$$0$$$. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$c_1, c_2, \ldots, c_n$$$ ($$$1 \le c_i \le n$$$). It is guara... | standard output | standard input | Python 3 | Python | 1,100 | train_093.jsonl | 2484f6d989a143c0b9d42c956809e3d8 | 256 megabytes | ["6\n\n7\n\n1 2 3 1 2 3 1\n\n6\n\n4 2 2 2 4 4\n\n1\n\n1\n\n5\n\n5 4 5 3 5\n\n6\n\n3 3 3 1 3 3\n\n8\n\n1 2 3 4 4 3 2 1"] | PASSED |
def solveonecolor(array):
m = len(array)
if m==0:
return 0
elif m==1:
return 1
else:
maxi = 1
for i in range(m-1):
if (array[i+1]-array[i])%2==1:
maxi+=1
return maxi
def solve(n, array):
allans = []
subarrays... | 1658154900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["2", "2"] | 9a64ee19cf2d20978870c03311bf6cbf | NoteGraph from first sample:Graph from second sample: | You are given a set of size $$$m$$$ with integer elements between $$$0$$$ and $$$2^{n}-1$$$ inclusive. Let's build an undirected graph on these integers in the following way: connect two integers $$$x$$$ and $$$y$$$ with an edge if and only if $$$x \& y = 0$$$. Here $$$\&$$$ is the bitwise AND operation. Count ... | Print the number of connected components. | In the first line of input there are two integers $$$n$$$ and $$$m$$$ ($$$0 \le n \le 22$$$, $$$1 \le m \le 2^{n}$$$). In the second line there are $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$0 \le a_{i} < 2^{n}$$$) — the elements of the set. All $$$a_{i}$$$ are distinct. | standard output | standard input | PyPy 2 | Python | 2,500 | train_033.jsonl | 08e46f6cf2e865e6bb4993acb797fb70 | 256 megabytes | ["2 3\n1 2 3", "5 5\n5 19 10 20 12"] | PASSED | def main():
inp = readnumbers()
ii = 0
n = inp[ii]
ii += 1
m = inp[ii]
ii += 1
pow2 = 2**n
index = [-1]*pow2
#coupl = [[] for _ in range(pow2 + m)]
for _ in range(m):
u = inp[ii]
ii += 1
index[pow2 - 1 - u] = pow2 + _
# coupl[pow2 - 1 - u].ap... | 1527608100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1 0 1\n3 2 1\n12 7 1\n42 27 1\n341102826 248150916 1"] | 63fc2fb08d248f8ccdb3f5364c96dac1 | NoteIn the first test case, Alex wins if he receives the card $$$2$$$ (he plays it, and Boris cannot respond). If Alex receives the card $$$1$$$, the game ends in a draw.In the second test case: Alex wins if he receives the cards $$$[3, 4]$$$, $$$[2, 4]$$$ or $$$[1, 4]$$$; Boris wins if Alex receives the cards $$$[1... | Consider a game with $$$n$$$ cards ($$$n$$$ is even). Each card has a number written on it, between $$$1$$$ and $$$n$$$. All numbers on the cards are different. We say that a card with number $$$x$$$ is stronger than a card with number $$$y$$$ if $$$x > y$$$.Two players, Alex and Boris, play this game. In the beginn... | For each test case, print three integers: the number of ways to distribute the cards so that Alex wins; the number of ways to distribute the cards so that Boris wins; the number of ways to distribute the cards so that the game ends in a draw. Since the answers can be large, print them modulo $$$998244353$$$. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 30$$$) — the number of test cases. Then, $$$t$$$ lines follow. The $$$i$$$-th line contains one even integer $$$n$$$ ($$$2 \le n \le 60$$$). | standard output | standard input | PyPy 3-64 | Python | 1,500 | train_109.jsonl | 680b048f60b68c37836f2a9dabb3f14d | 512 megabytes | ["5\n\n2\n\n4\n\n6\n\n8\n\n60"] | PASSED | # Libraries
import sys
from math import *
from queue import PriorityQueue
# Definitions
mod = 998244353
e = pow(10,-6)
input = sys.stdin.readline
pq = PriorityQueue()
# sys.setrecursionlimit(10**6)
#Input forms
def imap():
return map(int,input().split())
def ilist():
return list(map(int,... | 1664462100 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["1\n000\n1010\n00"] | b37bbf1fe9ac5144cfa230633ccbdd79 | NoteThe explanation of the sample case (equal characters in equal positions are bold):The first test case: $$$\mathbf{1}$$$ is similar to $$$s[1..1] = \mathbf{1}$$$. The second test case: $$$\mathbf{000}$$$ is similar to $$$s[1..3] = \mathbf{000}$$$; $$$\mathbf{000}$$$ is similar to $$$s[2..4] = \mathbf{000}$$$; ... | A binary string is a string where each character is either 0 or 1. Two binary strings $$$a$$$ and $$$b$$$ of equal length are similar, if they have the same character in some position (there exists an integer $$$i$$$ such that $$$a_i = b_i$$$). For example: 10010 and 01111 are similar (they have the same character in ... | For each test case, print the corresponding binary string $$$w$$$ of length $$$n$$$. If there are multiple such strings — print any of them. It can be shown that at least one string $$$w$$$ meeting the constraints always exists. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$). The second line of each test case contains the binary string $$$s$$$ of length $$$2n - 1$$$. Each character $$$s_i$$$ is either... | standard output | standard input | Python 3 | Python | 800 | train_024.jsonl | 24dc8ec1f269c95ad32d47fb3b2eca1b | 256 megabytes | ["4\n1\n1\n3\n00000\n4\n1110000\n2\n101"] | PASSED | t = int(input())
for _ in range(t):
n, s = int(input()), input()
print(*[s[i] for i in range(0,len(s),2)], sep='')
| 1598366100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1", "2", "6720"] | 14da0cdf2939c796704ec548f49efb87 | null | There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is alrea... | In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7). | The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 ≤ n ≤ 1000, 1 ≤ m ≤ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initia... | standard output | standard input | Python 3 | Python | 1,900 | train_063.jsonl | 30ae3de8b79560873a74800fab9e2496 | 256 megabytes | ["3 1\n1", "4 2\n1 4", "11 2\n4 8"] | PASSED | import math
def solve( n, list1):
list1.sort()
inf = int(1e9 + 7)
t1 = [list1[0] - 1, n - list1[-1]]
t2 = []
for i in range(1, len(list1)):
t2.append((list1[i] - list1[i - 1] - 1))
num1 = 1
for i in range(n - len(list1)):
num1 = num1 * (i + 1)
num1 = num1 % inf
... | 1365348600 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["2\n-1\n10\n-1\n1"] | 9afcf090806cc9c3b87120b1b61f8f17 | NoteThe first case is explained in the description.In the second case, each rabbit will be at position $$$3$$$ and $$$7$$$ respectively at the $$$1$$$-st second. But in the $$$2$$$-nd second they will be at $$$6$$$ and $$$4$$$ respectively, and we can see that they will never be at the same position since the distance ... | Being tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller than the other.He noticed that the two rabbits were hopping towards each other. The positions of the two rabbits ca... | For each test case, print the single integer: number of seconds the two rabbits will take to be at the same position. If the two rabbits will never be at the same position simultaneously, print $$$-1$$$. | Each test contains one or more test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Each test case contains exactly one line. The line consists of four integers $$$x$$$, $$$y$$$, $$$a$$$, $$$b$$$ ($$$0 \le x \lt y \le 10^9$$$, $$$1 \le a,b \le 10^9$$$) — the current position of... | standard output | standard input | Python 3 | Python | 800 | train_000.jsonl | 964ed75e9176ed9bbcd4caa596b89c05 | 256 megabytes | ["5\n0 10 2 3\n0 10 3 3\n900000000 1000000000 1 9999999\n1 2 1 1\n1 3 1 1"] | PASSED |
arr =[]
test_cases =int(input(''))
for x in range(test_cases):
a=[]
a = list(map(int,input().split()))
arr.append(a)
for t in range(test_cases):
x=arr[t][0]
y=arr[t][1]
a=arr[t][2]
b=arr[t][3]
if abs(y-x)%(a+b)==0:
if abs(y-x)%(a+b)==0:
print (int((y-x)/(a+b)))
... | 1581771900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0\n\n2\n4 4\n3\n2 6 2"] | cced3c3d3f1a63e81e36c94fc2ce9379 | NoteIn the first test case of the example, the sum of all numbers is $$$12$$$, and their $$$\oplus$$$ is $$$6$$$, so the condition is already satisfied.In the second test case of the example, after adding $$$4, 4$$$, the array becomes $$$[8, 4, 4]$$$. The sum of numbers in it is $$$16$$$, $$$\oplus$$$ of numbers in it ... | Let's call an array $$$a_1, a_2, \dots, a_m$$$ of nonnegative integer numbers good if $$$a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.For example, array $$$[1, 2, 3, 6]$$$ is good, as $$$1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus ... | For each test case, output two lines. In the first line, output a single integer $$$s$$$ ($$$0\le s\le 3$$$) — the number of elements you want to append. In the second line, output $$$s$$$ integers $$$b_1, \dots, b_s$$$ ($$$0\le b_i \le 10^{18}$$$) — the elements you want to append to the array. If there are different ... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10\,000$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ $$$(1\le n \le 10^5)$$$ — the size of the array. The second line of each test case c... | standard output | standard input | Python 3 | Python | 1,400 | train_002.jsonl | c313a8d7bd8e233bce222ed35bba9043 | 256 megabytes | ["3\n4\n1 2 3 6\n1\n8\n2\n1 1"] | PASSED | for i in range(int(input())):
x=int(input())
m=list(map(int,input().split()))
s=0
ss=0
for j in range(x):
s=s^m[j]
ss+=m[j]
if s==0:
print("1")
print(ss)
else:
print("2")
print(str(s)+" "+str(ss+s))
| 1577628300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2", "3"] | eea7860e6bbbe5f399b9123ebd663e3e | Notegcd (greatest common divisor) of positive integers set {a1, a2, ..., an} is the maximum positive integer that divides all the integers {a1, a2, ..., an}.In the first sample, we can take Pokemons with strengths {2, 4} since gcd(2, 4) = 2.In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there ... | Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.But Zulu warns him that a group of k > 1 Pokemon with strengths {s1, s2,... | Print single integer — the maximum number of Pokemons Bash can take. | The input consists of two lines. The first line contains an integer n (1 ≤ n ≤ 105), the number of Pokemon in the lab. The next line contains n space separated integers, where the i-th of them denotes si (1 ≤ si ≤ 105), the strength of the i-th Pokemon. | standard output | standard input | Python 3 | Python | 1,400 | train_012.jsonl | 5ff303b7b41d94173510a011c561a205 | 512 megabytes | ["3\n2 3 4", "5\n2 3 4 6 7"] | PASSED | from collections import defaultdict
from math import sqrt
def solve():
n = int(input())
numbers = list(map(int, input().split(" ")))
if n == 1:
print(1)
return
amount = {}
for number in numbers:
if number not in amount:
amount[number] = 1
else:
... | 1484235300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["2"] | 0ef324e3e314ea17c01aafb822e90c63 | null | You are given a sequence a consisting of n integers. Find the maximum possible value of (integer remainder of ai divided by aj), where 1 ≤ i, j ≤ n and ai ≥ aj. | Print the answer to the problem. | The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·105). The second line contains n space-separated integers ai (1 ≤ ai ≤ 106). | standard output | standard input | Python 3 | Python | 2,100 | train_000.jsonl | d4176629e96d618983cf756526b2f1d1 | 256 megabytes | ["3\n3 4 5"] | PASSED | input()
s = sorted(set(map(int, input().split())))
c = m = 0
d = []
for b in s:
d += [c] * (b - c)
c = b
for b in s[-1::-1]:
if b < m + 2: break
m = max(m, c % b, *(a % b for a in d[2 * b - 1::b]))
print(m) | 1415205000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES", "NO", "NO"] | 42b6ada19f6f6276bb2f99049e2b9b76 | NoteSample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there. | Consider a table G of size n × m such that G(i, j) = GCD(i, j) for all 1 ≤ i ≤ n, 1 ≤ j ≤ m. GCD(a, b) is the greatest common divisor of numbers a and b.You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, sta... | Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO". | The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1012; 1 ≤ k ≤ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 ≤ ai ≤ 1012). | standard output | standard input | Python 3 | Python | 2,900 | train_052.jsonl | 10b3f5031d3f7f4234c491d9f507103d | 256 megabytes | ["100 100 5\n5 2 1 2 1", "100 8 5\n5 2 1 2 1", "100 100 7\n1 2 3 4 5 6 7"] | PASSED | '''
Created on Aug 28, 2016
@author: Md. Rezwanul Haque
'''
def gcd(a,b):
if b == 0:
return a
return gcd(b, a%b)
def extend_euclid(a,b):
if b == 0:
return 1,0
else:
y,x = extend_euclid(b, a%b)
y = y - (a//b)*x
return x,y
n,m,k = map(int,input().split())
a = ... | 1376668800 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["4\n3\n1\n28\n510049495001"] | eb3d8259ca598c3c455ddfdbe433cb78 | NoteIn the first test case, Alice can set $$$1,2,3$$$ or $$$4$$$ days as the number of days in a week.There are $$$6$$$ possible paintings shown in the picture, but there are only $$$4$$$ different shapes. So, the answer is $$$4$$$. Notice that the last example in the picture is an invalid painting because all cells ar... | A competitive eater, Alice is scheduling some practices for an eating contest on a magical calendar. The calendar is unusual because a week contains not necessarily $$$7$$$ days!In detail, she can choose any integer $$$k$$$ which satisfies $$$1 \leq k \leq r$$$, and set $$$k$$$ days as the number of days in a week.Alic... | For each test case, print a single integer — the answer to the problem. Please note, that the answer for some test cases won't fit into $$$32$$$-bit integer type, so you should use at least $$$64$$$-bit integer type in your programming language. | The 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 two integers $$$n$$$, $$$r$$$ ($$$1 \le n \le 10^9, 1 \le r \le 10^9$$$). | standard output | standard input | PyPy 3 | Python | 1,200 | train_000.jsonl | 854e94faac0d6749d0d2f0928eeac83e | 256 megabytes | ["5\n3 4\n3 2\n3 1\n13 7\n1010000 9999999"] | PASSED | from sys import stdin
input=stdin.readline
for _ in range(int(input())):
n,m=map(int,input().split())
if n<=m:
print((n*(n-1))//2+1)
else:
print((m*(m+1))//2) | 1593610500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["12.000000\n11.000000\n10.000000\n9.000000\n8.000000", "-1"] | 65fea461d3caa5a932d1e2c13e99a59e | null | A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.Polycarpus has already began the proce... | Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a soluti... | The first line contains a pair of integers n, b (2 ≤ n ≤ 100, 1 ≤ b ≤ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the current volume of drink in the i-th mug. | standard output | standard input | Python 3 | Python | 1,100 | train_029.jsonl | 5d018348eca4cf8eb9a3129ef2388b1c | 256 megabytes | ["5 50\n1 2 3 4 5", "2 2\n1 100"] | PASSED | x=[int(i) for i in input().split()]
n=x[0]
y=[int(i) for i in input().split()]
if x[1]<max(y)*n-sum(y):
print(-1)
raise SystemExit
for i in range(n):
s=x[1]/n-y[i]++sum(y)/n
print('%.6f'% s)
| 1333897500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["4", "6"] | 0cb9a20ca0a056b86885c5bcd031c13f | NoteIn the first example the tree looks like this: The red vertex is Alice's starting position, the blue one is Bob's. Bob will make the game run the longest by standing at the vertex 3 during all the game. So here are the moves:B: stay at vertex 3A: go to vertex 2B: stay at vertex 3A: go to vertex 3In the second exam... | Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of n vertices. Vertex 1 is the root of the tree.Alice starts at vertex 1 and Bob starts at vertex x (x ≠ 1). The moves are made in turns, Bob goes first. ... | Print the total number of moves Alice and Bob will make. | The first line contains two integer numbers n and x (2 ≤ n ≤ 2·105, 2 ≤ x ≤ n). Each of the next n - 1 lines contains two integer numbers a and b (1 ≤ a, b ≤ n) — edges of the tree. It is guaranteed that the edges form a valid tree. | standard output | standard input | Python 3 | Python | 1,700 | train_032.jsonl | 0c77d424bd54fe58ef5e016a538a5d48 | 256 megabytes | ["4 3\n1 2\n2 3\n2 4", "5 2\n1 2\n2 3\n3 4\n2 5"] | PASSED | from collections import deque
from sys import stdin
#Algoritmo BFS
def BFS(s):
if s==0:
distance=distance_Alice
else:
distance=distance_Bob
distance[s]=0
q=deque()
q.append(s)
while len(q)>0:
v=q.popleft()
for u in adjacents_list[v]:
if distance[u] =... | 1496675100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["2\n4"] | 24f4bd10ae714f957920afd47ac0c558 | NoteIn first case, for $$$m=2$$$, polynomials that satisfy the constraint are $$$x$$$ and $$$2$$$.In second case, for $$$m=4$$$, polynomials that satisfy the constraint are $$$x^2$$$, $$$x + 2$$$, $$$2x$$$ and $$$4$$$. | The Bubble Cup hypothesis stood unsolved for $$$130$$$ years. Who ever proves the hypothesis will be regarded as one of the greatest mathematicians of our time! A famous mathematician Jerry Mao managed to reduce the hypothesis to this problem:Given a number $$$m$$$, how many polynomials $$$P$$$ with coefficients in set... | For each test case $$$i$$$, print the answer on separate lines: number of polynomials $$$P$$$ as described in statement such that $$$P(2)=m_i$$$, modulo $$$10^9 + 7$$$. | The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 5\cdot 10^5)$$$ - number of test cases. On next line there are $$$t$$$ numbers, $$$m_i$$$ $$$(1 \leq m_i \leq 10^{18})$$$ - meaning that in case $$$i$$$ you should solve for number $$$m_i$$$. | standard output | standard input | Python 3 | Python | 2,400 | train_079.jsonl | 446fffa36187d1bef88d0cc5f4867624 | 256 megabytes | ["2\n2 4"] | PASSED | t = int(input())
a = list(map(int, input().split()))
out = []
for n in a:
ans = (n//2 + 2)
ans = ans*ans
ans //= 4
out.append(ans%1000000007)
print(' '.join(str(x) for x in out)) | 1601903100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["7\n4\n76"] | 64a375c7c49591c676dbdb039c93d218 | NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$. | Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &... | For each test case, output $$$f(n)$$$. | The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively. | standard output | standard input | Python 2 | Python | 900 | train_004.jsonl | 4215d67ceb22d705844ff2e13e69e8b7 | 256 megabytes | ["3\n3 4 2\n4 5 0\n325 265 1231232"] | PASSED | t=int(input())
for i in xrange(t):
a,b,n=map(int,raw_input().split())
dp=[a,b,a^b]
if n%3==0:
print dp[0]
elif n%3==1:
print dp[1]
elif n%3==2:
print dp[2] | 1566743700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1", "2"] | c01da186ee69936eb274dce6e1222e43 | NoteNote that numbers which you remove don't impact the procedure of telling whether the resulting sequence is good.It is possible that for some numbers $$$b_i$$$ and $$$b_j$$$, you will try to add the edge between them twice. Nevertheless, you will add this edge only once. | For a given sequence of distinct non-negative integers $$$(b_1, b_2, \dots, b_k)$$$ we determine if it is good in the following way: Consider a graph on $$$k$$$ nodes, with numbers from $$$b_1$$$ to $$$b_k$$$ written on them. For every $$$i$$$ from $$$1$$$ to $$$k$$$: find such $$$j$$$ ($$$1 \le j \le k$$$, $$$j\neq i... | You should output exactly one integer — the minimum possible number of elements to remove in order to make the remaining sequence good. | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 200,000$$$) — length of the sequence. The second line contains $$$n$$$ distinct non-negative integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the elements of the sequence. | standard output | standard input | Python 3 | Python | 2,100 | train_012.jsonl | 653fe61bde06bed578df895538ea6ef7 | 256 megabytes | ["5\n0 1 5 2 6", "7\n6 9 8 7 3 5 2"] | PASSED | n = int(input())
l = list(map(int,input().split()))
def fun(a):
if len(a) <= 3:
return len(a)
maxE = max(a)
if maxE == 0:
return len(a)
msb = 1
while 2 * msb <= maxE:
msb *= 2
l1 = []
l2 = []
for x in a:
if x >= msb:... | 1605450900 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["NO\nNO\nNO\nNO\nYES\nYES", "NO\nYES\nYES"] | 7f934f96cbe3990945e5ebcf5c208043 | NoteIn test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES". | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower). | First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list. Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100. | standard output | standard input | Python 3 | Python | 800 | train_008.jsonl | d10d8b9602b66c9a79532a16e4875ae7 | 256 megabytes | ["6\ntom\nlucius\nginny\nharry\nginny\nharry", "3\na\na\na"] | PASSED | numer = int(input())
newWords = list()
for i in range(numer):
inn = input()
if not inn in newWords:
newWords.append(inn)
print("NO")
else:
print("YES")
| 1506263700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["3", "3", "1", "2"] | 0c4dad4f65ad986d87c968520111e995 | null | Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions.Polycarpus believes that if h... | Print the minimum number of arithmetic progressions that you need to write one after another to get sequence a. The positions marked as -1 in a can be represented by any positive integers. | The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of elements in the sequence. The second line contains integer values a1, a2, ..., an separated by a space (1 ≤ ai ≤ 109 or ai = - 1). | standard output | standard input | Python 3 | Python | 2,400 | train_029.jsonl | c7fbc88ae02cfb6a7420bc1200d2707d | 256 megabytes | ["9\n8 6 4 2 1 4 7 10 2", "9\n-1 6 -1 2 -1 4 7 -1 2", "5\n-1 -1 -1 -1 -1", "7\n-1 -1 4 5 1 2 3"] | PASSED | n = int(input())
a = list(map(int, input().split()))
i = 0
ans = 0
while i < n:
ans += 1
i1 = i
while i1 < n and a[i1] == -1:
i1 += 1
if i1 == n:
break
i2 = i1 + 1
while i2 < n and a[i2] == -1:
i2 += 1
if i2 == n:
break
dist = i2 - i1
step = (a[i2] - a... | 1397376000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["YES\nYES\nNO\n1\n2\n2\n2", "YES\nYES\nYES\nYES\nNO\nYES\n3\n3\n1\n1\n2"] | c4f97a986dccc433835addca8efec972 | null | Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discovers a new relation between two words.He know that if two words have a ... | First, print m lines, one per each relation. If some relation is wrong (makes two words opposite and have the same meaning at the same time) you should print "NO" (without quotes) and ignore it, otherwise print "YES" (without quotes). After that print q lines, one per each question. If the two words have the same meani... | The first line of input contains three integers n, m and q (2 ≤ n ≤ 105, 1 ≤ m, q ≤ 105) where n is the number of words in the dictionary, m is the number of relations Mahmoud figured out and q is the number of questions Mahmoud asked after telling all relations. The second line contains n distinct words a1, a2, ..., a... | standard output | standard input | PyPy 2 | Python | 2,000 | train_007.jsonl | 0e2c6f8b50f65df269ef9882a1c3f3c7 | 256 megabytes | ["3 3 4\nhate love like\n1 love like\n2 love hate\n1 hate like\nlove like\nlove hate\nlike hate\nhate like", "8 6 5\nhi welcome hello ihateyou goaway dog cat rat\n1 hi welcome\n1 ihateyou goaway\n2 hello ihateyou\n2 hi goaway\n2 hi hello\n1 hi hello\ndog cat\ndog hi\nhi hello\nihateyou goaway\nwelcome ihateyou"] | PASSED | n, m, q = [int(x) for x in raw_input().split()]
a = raw_input().split()
c = {x: ([x], []) for x in a}
for _ in range(m):
t, x, y = raw_input().split()
sign = 1 if t == '2' else 0
if c[x][0] is c[y][1-sign]:
print "NO"
continue
print "YES"
if c[x][0] is c[y][sign]:
conti... | 1486487100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["2\n6\n0\n4"] | 58ee86d4913787582ccdb54073656dc0 | NoteIn the first test case, we can choose the $$$k=2$$$ characters $$$\texttt{"_ol"}$$$ and rearrange them as $$$\texttt{"_lo"}$$$ (so the resulting string is $$$\texttt{"llo"}$$$). It is not possible to sort the string choosing strictly less than $$$2$$$ characters.In the second test case, one possible way to sort $$$... | A string $$$s$$$ of length $$$n$$$, consisting of lowercase letters of the English alphabet, is given.You must choose some number $$$k$$$ between $$$0$$$ and $$$n$$$. Then, you select $$$k$$$ characters of $$$s$$$ and permute them however you want. In this process, the positions of the other $$$n-k$$$ characters remain... | For each test case, output the minimum $$$k$$$ that allows you to obtain a string sorted alphabetically, through the operation described above. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 40$$$) — the length of the string. The second line of each test case contains the string $$$s$$$. It is guar... | standard output | standard input | Python 3 | Python | 800 | train_098.jsonl | 26d5ca23c959da3d29b42d75ace12192 | 256 megabytes | ["4\n3\nlol\n10\ncodeforces\n5\naaaaa\n4\ndcba"] | PASSED | for i in range(int(input())):
n=int(input())
s=[i for i in input()]
t=sorted(s)
print(sum([int(s[i]!=t[i]) for i in range(n)]))
| 1627223700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["brother 30 60\nfather 80 60\nfriend 20 60\ngrandpa 120 120\nme 50 40\nuncle 100 20", "dummy 0 0\npack 10 10\nx 40 10\ny 10 10"] | 258f54f32c6df5390edd804294aad235 | NoteIn the first sample the widgets are arranged as follows: | Vasya writes his own library for building graphical user interface. Vasya called his creation VTK (VasyaToolKit). One of the interesting aspects of this library is that widgets are packed in each other. A widget is some element of graphical interface. Each widget has width and height, and occupies some rectangle on the... | For each widget print on a single line its name, width and height, separated by spaces. The lines must be ordered lexicographically by a widget's name. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout stream (also you may use %I64d specificator) | The first line contains an integer n — the number of instructions (1 ≤ n ≤ 100). Next n lines contain instructions in the language VasyaScript — one instruction per line. There is a list of possible instructions below. "Widget [name]([x],[y])" — create a new widget [name] of the type Widget possessing the width of [x... | standard output | standard input | Python 2 | Python | 2,300 | train_028.jsonl | 79ee7c1dbfa4ef3522c6c6602d985350 | 256 megabytes | ["12\nWidget me(50,40)\nVBox grandpa\nHBox father\ngrandpa.pack(father)\nfather.pack(me)\ngrandpa.set_border(10)\ngrandpa.set_spacing(20)\nWidget brother(30,60)\nfather.pack(brother)\nWidget friend(20,60)\nWidget uncle(100,20)\ngrandpa.pack(uncle)", "15\nWidget pack(10,10)\nHBox dummy\nHBox x\nVBox y\ny.pack(dummy)\ny.... | PASSED | import re
class Widget(object):
def __init__(self, type, w = 0, h = 0):
self.type = type
if type == 'Widget':
self.w = w
self.h = h
def calc_wh(self):
if not hasattr(self, 'w'):
if self.children:
self.w = self.border * 2
... | 1308236400 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["1\n0"] | 4b33db3950303b8993812cb265fa9819 | NoteIn the first test case, after removing $$$3$$$, the sequence becomes $$$[2,4,6,8]$$$. The pairs of consecutive elements are $$$\{[2, 4], [4, 6], [6, 8]\}$$$. Each consecutive pair has an even sum now. Hence, we only need to remove $$$1$$$ element to satisfy the condition asked.In the second test case, each consecut... | Given a sequence $$$a_1, a_2, \ldots, a_n$$$, find the minimum number of elements to remove from the sequence such that after the removal, the sum of every $$$2$$$ consecutive elements is even. | For each test case, print a single integer — the minimum number of elements to remove from the sequence such that the sum of every $$$2$$$ consecutive elements is even. | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 10^5$$$). The second line of each test case contains $$$n... | standard output | standard input | PyPy 3-64 | Python | 800 | train_089.jsonl | d4e7042f26b8b6e13853aba2649cacfa | 256 megabytes | ["2\n\n5\n\n2 4 3 6 8\n\n6\n\n3 5 9 7 1 3"] | PASSED | def ss(n, arr):
countOdd = 0
for i in range(n):
if (arr[i] % 2):
countOdd += 1
return min(countOdd, n - countOdd)
t = int(input())
while t:
ans = 0
n = int(input())
nums = list(map(int, input().split()))
print(ss(n, nums))
t -= 1
| 1654007700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nNO\nYES\nYES\nYES"] | a8201326dda46542b23dc4e528d413eb | NoteIn the first test case, you can first cut the $$$2 \times 2$$$ sheet into two $$$2 \times 1$$$ sheets, and then cut each of them into two more sheets. As a result, we get four sheets $$$1 \times 1$$$. We can choose any three of them and send them to our friends.In the second test case, a $$$3 \times 3$$$ sheet cann... | For the New Year, Polycarp decided to send postcards to all his $$$n$$$ friends. He wants to make postcards with his own hands. For this purpose, he has a sheet of paper of size $$$w \times h$$$, which can be cut into pieces.Polycarp can cut any sheet of paper $$$w \times h$$$ that he has in only two cases: If $$$w$$... | For each test case, output on a separate line: "YES", if it is possible to cut a sheet of size $$$w \times h$$$ into at least $$$n$$$ pieces; "NO" otherwise. You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive). | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing three integers $$$w$$$, $$$h$$$, $$$n$$$ ($$$1 \le w, h \le 10^4, 1 \le n \le 10^9$$$) — the width and height of the sheet Polycarp has and the ... | standard output | standard input | PyPy 3-64 | Python | 800 | train_089.jsonl | b1a430a24b32d6cfd018378f76cc8ecf | 256 megabytes | ["5\n2 2 3\n3 3 2\n5 10 2\n11 13 1\n1 4 4"] | PASSED | for i in range(int(input())):
l=list(map(int,input().split()))
if (l[2]<=1):
print("YES")
else:
ans=1
while l[1] % 2 == 0:
ans *= 2
l[1] /= 2
while l[0]%2==0:
ans*=2
l[0]/=2
... | 1609770900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1\n1\n3\n-1\n0"] | c15bce9c4b9eddf5c8c3421b768da98c | NoteIn the third sample test case the array will change as follows: At the beginning $$$a = [1, 1, 0, 1, 0]$$$, and $$$a^{\rightarrow 2} = [1, 0, 1, 1, 0]$$$. Their element-by-element "AND" is equal to $$$$$$[1 \,\&\, 1, 1 \,\&\, 0, 0 \,\&\, 1, 1 \,\&\, 1, 0 \,\&\, 0] = [1, 0, 0, 1, 0]$$$$$$ Now ... | You are given an array $$$a[0 \ldots n - 1] = [a_0, a_1, \ldots, a_{n - 1}]$$$ of zeroes and ones only. Note that in this problem, unlike the others, the array indexes are numbered from zero, not from one.In one step, the array $$$a$$$ is replaced by another array of length $$$n$$$ according to the following rules: F... | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to a test case should be a single integer — the number of steps after which the array will contain only zeros for the first time. If there are still elements equal to $$$1$$$ in the array after the end of the process, print ... | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of each test case description contains two integers: $$$n$$$ ($$$1 \le n \le 10^6$$$) — array size and $$$d$$$ ($$$1 \le d \le n$$$) — cyclic ... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_095.jsonl | cf9555ce57f7b6092eb06b56dd84a4dc | 256 megabytes | ["5\n2 1\n0 1\n3 2\n0 1 0\n5 2\n1 1 0 1 0\n4 2\n0 1 0 1\n1 1\n0"] | PASSED | for _ in range(int(input())):
n,d=map(int,input().split())
a = list(map(int, input().split()))
used = [False]*n
fail = False
res = 0
for i in range(n):
if used[i]:
continue
cur = i
pr = last = it = ans = 0
used[cur] = True
... | 1632839700 | [
"number theory",
"math",
"graphs"
] | [
0,
0,
1,
1,
1,
0,
0,
0
] | |
1 second | ["0\n4\n3"] | 354e27c81d3d57a64062b5daa05705ad | NoteIn the first test case, the original array is $$$[3, 2, 1, 0]$$$. In the second test case, the original array is $$$[0, 3, 2, 1]$$$.In the third test case, the original array is $$$[2, 1, 0]$$$. | This is the easy version of the problem. The difference in the constraints between both versions is colored below in red. You can make hacks only if all versions of the problem are solved.Marin and Gojou are playing hide-and-seek with an array.Gojou initially performs the following steps: First, Gojou chooses $$$2$$$... | For each test case print an integer $$$x$$$. If there are multiple answers, print any. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. In the first line of each test case contains two integers $$$l$$$ and $$$r$$$ ($$$ \color{red}{\boldsymbol{0} \boldsymbol{=} \boldsymbol{l}} \le r < 2^{17}$$$). The second line contains $$$r - l + 1$$$ integers of... | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_095.jsonl | d65168aa672f153cb07188b1f957ffd3 | 256 megabytes | ["3\n\n0 3\n\n3 2 1 0\n\n0 3\n\n4 7 6 5\n\n0 2\n\n1 2 3"] | PASSED | import sys
input=sys.stdin.readline
for iii in range(int(input())):
n,m=map(int,input().split())
q=list(map(int,input().split()))
q1=[0 for i in range(18)]
for i in q:
x=bin(i)
x=x[2:]
x=x[::-1]
for j in range(len(x)):
... | 1648391700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["5", "4"] | ad5ec7026cbefedca288df14c2bc58e5 | NoteIn the first example the balls can be divided into sets like that: one set with 4 balls of the first color, two sets with 3 and 4 balls, respectively, of the second color, and two sets with 4 balls of the third color. | There are n boxes with colored balls on the table. Colors are numbered from 1 to n. i-th box contains ai balls, all of which have color i. You have to write a program that will divide all balls into sets such that: each ball belongs to exactly one of the sets, there are no empty sets, there is no set containing two ... | Print one integer number — the minimum possible number of sets. | The first line contains one integer number n (1 ≤ n ≤ 500). The second line contains n integer numbers a1, a2, ... , an (1 ≤ ai ≤ 109). | standard output | standard input | Python 3 | Python | 2,500 | train_050.jsonl | 32dcdc039a97045a0616090e02ebd59d | 256 megabytes | ["3\n4 7 8", "2\n2 7"] | PASSED | # Returns the number of coins that is necessary for paying the amount
# with the two types of coins that have value of coin and coin + 1
def pay(coin, amount):
if amount // coin < amount % coin:
return -1;
if amount < coin * (coin + 1):
return amount // coin
return (amount - 1) // (coin + 1)... | 1490625300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["3\n4\n2\n3"] | 1ca582e932ac93ae2e1555deb16e3c3c | NoteThe split in the first test case is explained in the statement, it can be shown that it is optimal.In the second test case, it is possible to split into segments only by leaving a single segment. Then the thickness of this split is equal to the length of the entire sequence, that is, $$$4$$$.In the third test case,... | You are given a sequence $$$a=[a_1,a_2,\dots,a_n]$$$ consisting of $$$n$$$ positive integers.Let's call a group of consecutive elements a segment. Each segment is characterized by two indices: the index of its left end and the index of its right end. Denote by $$$a[l,r]$$$ a segment of the sequence $$$a$$$ with the lef... | For each test case, output one integer — the minimum possible thickness of a split of the sequence $$$a$$$ into segments. Note that there always exist a split, you can always consider whole sequence as one segment. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Each test case is described by two lines. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2000$$$) — the length of the sequence $$$a$$$. The second line of each test case contains exac... | standard output | standard input | PyPy 3-64 | Python | 1,100 | train_084.jsonl | 29fb3401fd7df0891a6f6d7ddb693a60 | 256 megabytes | ["4\n\n6\n\n55 45 30 30 40 100\n\n4\n\n10 23 7 13\n\n5\n\n10 55 35 30 65\n\n6\n\n4 1 1 1 1 4"] | PASSED | import sys
input = sys.stdin.readline
tests = int(input())
for _ in range(tests):
n = int(input())
arr = list(map(int, input().split()))
minsum, totsum = max(arr) - 1, sum(arr)
possible = []
while True:
brr = []
for elem in arr:
brr.append(elem)
k = ... | 1665498900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3\n2 3 3\n2 1 1", "9\n3 5 5\n4 3 3\n4 1 1\n4 2 2"] | ac25d2519df81490ea0e7997ab73aa24 | null | You are given an unweighted tree with n vertices. Then n - 1 following operations are applied to the tree. A single operation consists of the following steps: choose two leaves; add the length of the simple path between them to the answer; remove one of the chosen leaves from the tree. Initial answer (before applyi... | In the first line print one integer number — maximal possible answer. In the next n - 1 lines print the operations in order of their applying in format ai, bi, ci, where ai, bi — pair of the leaves that are chosen in the current operation (1 ≤ ai, bi ≤ n), ci (1 ≤ ci ≤ n, ci = ai or ci = bi) — choosen leaf that is rem... | The first line contains one integer number n (2 ≤ n ≤ 2·105) — the number of vertices in the tree. Next n - 1 lines describe the edges of the tree in form ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi). It is guaranteed that given graph is a tree. | standard output | standard input | Python 3 | Python | 2,400 | train_037.jsonl | a2c7d7b8774ebbf44de1664a325df7a1 | 256 megabytes | ["3\n1 2\n1 3", "5\n1 2\n1 3\n2 4\n2 5"] | PASSED | import sys
def main():
n = int(input())
edges = list(map(int, sys.stdin.read().split()))
tree_edges = dict()
for i in range(n):
tree_edges[i + 1] = set()
for i in range(0, len(edges) - 1, 2):
tree_edges[edges[i]].add(edges[i + 1])
tree_edges[edges[i + 1]].add(edges[i])
... | 1514469900 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["Yes\nNo\nNo\nYes\nNo\nYes"] | 0f960d19e576b7421a7c7a7166a884ea | NoteIn the first test case, let's consider the order $$$\{1, 2, 2\}$$$ of types of guests. Then: The first guest eats a chocolate cookie. After that, there are $$$2$$$ vanilla cookies and $$$1$$$ chocolate cookie. The second guest eats a chocolate cookie. After that, there are $$$2$$$ vanilla cookies and $$$0$$$ choc... | Anna is a girl so brave that she is loved by everyone in the city and citizens love her cookies. She is planning to hold a party with cookies. Now she has $$$a$$$ vanilla cookies and $$$b$$$ chocolate cookies for the party.She invited $$$n$$$ guests of the first type and $$$m$$$ guests of the second type to the party. ... | For each test case, print the answer in one line. If there exists at least one valid order, print "Yes". Otherwise, print "No". You can print each letter in any case (upper or lower). | 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 four integers $$$a$$$, $$$b$$$, $$$n$$$, $$$m$$$ ($$$0 \le a,b,n,m \le 10^{18... | standard output | standard input | PyPy 2 | Python | 1,300 | train_000.jsonl | e48daaec34f873ef69951a7092df49f5 | 256 megabytes | ["6\n2 2 1 2\n0 100 0 1\n12 13 25 1\n27 83 14 25\n0 0 1 0\n1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000"] | PASSED |
FAST_IO = 1
if FAST_IO:
import io, sys, atexit
rr = iter(sys.stdin.read().splitlines()).next
sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr()... | 1593610500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["Infinity", "-Infinity", "0/1", "1/2", "-9/5"] | 37cf6edce77238db53d9658bc92b2cab | NoteLet's consider all samples: You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function | You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit . | If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the... | The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separat... | standard output | standard input | Python 2 | Python | 1,400 | train_000.jsonl | 5e64b90cf2ad19927903fb5804805ac2 | 256 megabytes | ["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2"] | PASSED | n, m = map(int, raw_input().split())
P = map(int, raw_input().split())
Q = map(int, raw_input().split())
if n > m:
if P[0] > 0 and Q[0] > 0 or P[0] < 0 and Q[0] < 0:
print "Infinity"
else:
print "-Infinity"
elif n < m:
print "0/1"
else:
a, b = abs(P[0]), abs(Q[0])
for i in xrange(100... | 1339506000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n0\n0"] | 0ba97bcfb5f539c848f2cd097b34ff33 | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the characte... | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) – the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) – the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string ... | standard output | standard input | Python 3 | Python | 1,200 | train_003.jsonl | 1aeb8a70844e40040a2694416b79a313 | 256 megabytes | ["3\n2\n<>\n3\n><<\n1\n>"] | PASSED | for _ in range(int(input())):
n = int(input())
s = input().strip()
ans = 0
i = 0
while(i < n and s[i] == "<"):
ans += 1
i += 1
ans1 = 0
i = n - 1
while(i > -1 and s[i] == ">"):
ans1 += 1
i -= 1
print(min(ans, ans1))
| 1553267100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2.5 seconds | ["8", "4"] | 1fe6daf718b88cabb2e956e81add3719 | NoteIn the first sample there are 8 ways to split the sequence: "123434" = "123434" (maybe the given sequence is just one big number) "123434" = "1" + "23434" "123434" = "12" + "3434" "123434" = "123" + "434" "123434" = "1" + "23" + "434" "123434" = "1" + "2" + "3434" "123434" = "1" + "2" + "3" + "434" "123434"... | Limak is a little polar bear. In the snow he found a scroll with the ancient prophecy. Limak doesn't know any ancient languages and thus is unable to understand the prophecy. But he knows digits!One fragment of the prophecy is a sequence of n digits. The first digit isn't zero. Limak thinks that it's a list of some spe... | Print the number of ways to correctly split the given sequence modulo 109 + 7. | The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of digits. The second line contains a string of digits and has length equal to n. It's guaranteed that the first digit is not '0'. | standard output | standard input | PyPy 2 | Python | 2,000 | train_008.jsonl | de7dd131809a05b77a30ecd4e217a269 | 512 megabytes | ["6\n123434", "8\n20152016"] | PASSED | modulo = 10**9 + 7
def get_order(inp):
n = len(inp)
gt = [[-1] * i for i in range(n)]
for j in range(i)[::-1]:
if inp[n-1] > inp[j]:
gt[n-1][j] = 0
for i in range(n-1)[::-1]:
for j in range(i)[::-1]:
if inp[i] > inp[j]:
gt[i][j] = 0
el... | 1451487900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["5 2 3 1 5"] | 26aef004295df530352485ce53b47364 | NoteDescription of the sample: the deck is $$$[2, 1, 1, 4, \underline{3}, 3, 1]$$$ and the first card with color $$$t_1 = 3$$$ has position $$$5$$$; the deck is $$$[3, \underline{2}, 1, 1, 4, 3, 1]$$$ and the first card with color $$$t_2 = 2$$$ has position $$$2$$$; the deck is $$$[2, 3, \underline{1}, 1, 4, 3, 1]$... | You have a card deck of $$$n$$$ cards, numbered from top to bottom, i. e. the top card has index $$$1$$$ and bottom card — index $$$n$$$. Each card has its color: the $$$i$$$-th card has color $$$a_i$$$.You should process $$$q$$$ queries. The $$$j$$$-th query is described by integer $$$t_j$$$. For each query you should... | Print $$$q$$$ integers — the answers for each query. | The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 3 \cdot 10^5$$$; $$$1 \le q \le 3 \cdot 10^5$$$) — the number of cards in the deck and the number of queries. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 50$$$) — the colors of cards. The third line conta... | standard output | standard input | PyPy 3-64 | Python | 1,100 | train_089.jsonl | 6188494415985410424cd111460b2e7c | 256 megabytes | ["7 5\n2 1 1 4 3 3 1\n3 2 1 1 4"] | PASSED | import sys
n,q=map(int,sys.stdin.readline().split())
a=[int(i) for i in sys.stdin.readline().split()]
t=[int(i) for i in sys.stdin.readline().split()]
# print(a.index(t[0]))
for i in range(0,len(t)):
x=a.index(t[i])
print(x+1,end=" ")
a[:x+1]=[a[x]]+a[:x]
# print(a) | 1618238100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["4", "100"] | 6cc6db6f426bb1bce59f23bfcb762b08 | NoteThe first example is explained in the legend. | Recall that string $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly zero or all) characters. For example, for the string $$$a$$$="wowwo", the following strings are subsequences: "wowwo", "wowo", "oo", "wow", "", and others, but the following are not s... | Output a single integer, the wow factor of $$$s$$$. | The input contains a single non-empty string $$$s$$$, consisting only of characters "v" and "o". The length of $$$s$$$ is at most $$$10^6$$$. | standard output | standard input | Python 3 | Python | 1,300 | train_041.jsonl | bda2d24f8bcc551d5e24e57f1f043e93 | 256 megabytes | ["vvvovvv", "vvovooovovvovoovoovvvvovovvvov"] | PASSED | s = input()
ws = []
i = 0
while i < len(s):
cnt = 0
while i < len(s) and s[i] == 'v' :
cnt += 1
i += 1
if cnt != 0:
ws += ['w'] * (cnt - 1)
if i >= len(s):
break
ws.append('o')
i += 1
W = 0
WO = 0
WOW = 0
for c in ws:
if c == 'w':
W += 1
WOW +=... | 1563636900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
4 seconds | ["2.666666666666667"] | 7bdb68ab0752f8df94b4d5c7df759dfb | null | The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually cal... | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answ... | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($... | standard output | standard input | PyPy 3 | Python | 1,300 | train_002.jsonl | 617fb7a9a0116c3e42c32128ac05d3e6 | 256 megabytes | ["4 3\n3 4 1 2"] | PASSED | n,k = map(int,input().split())
l = list(map(int,input().split()))
i = 0
m = -10000
while i < len(l):
j = i
x = 1
som = 0
while j < len(l):
if x < k:
som += l[j]
x = x + 1
j = j + 1
continue
else:
som += l[j]
av = so... | 1530628500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["Anton", "Danik", "Friendship"] | 0de32a7ccb08538a8d88239245cef50b | NoteIn the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | Anton likes to play chess, and so does his friend Danik.Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.Now Anton wonders, who won more games, he or Danik? Help him determine this. | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes). | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of games played. The second line contains a string s, consisting of n uppercase English letters 'A' and 'D' — the outcome of each of the games. The i-th character of the string is equal to 'A' if the Anton won the i-th game and 'D' i... | standard output | standard input | Python 3 | Python | 800 | train_004.jsonl | e8159bffaa83d3c7a083730a2b620162 | 256 megabytes | ["6\nADAAAA", "7\nDDDAADA", "6\nDADADA"] | PASSED | n = int(input())
s = input()
p = 0
q = 0
for x in s:
if x=='A':
p+=1
else:
q+=1
if p>q:
print("Anton")
elif q>p:
print("Danik")
else:
print("Friendship") | 1479227700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["YES\nNO\nNO\nYES"] | 67856314f24ed718eb9b0d9fc9ab1abe | NoteConsider the example test from the statement.In order to obtain "ba" from "ababa", you may press Backspace instead of typing the first and the fourth characters.There's no way to obtain "bb" while typing "ababa".There's no way to obtain "aaaa" while typing "aaa".In order to obtain "ababa" while typing "aababa", you... | You are given two strings $$$s$$$ and $$$t$$$, both consisting of lowercase English letters. You are going to type the string $$$s$$$ character by character, from the first character to the last one.When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It del... | For each test case, print "YES" if you can obtain the string $$$t$$$ by typing the string $$$s$$$ and replacing some characters with presses of "Backspace" button, or "NO" if you cannot. You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized ... | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of test cases. The first line of each test case contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$). Each character of $$$s$$$ is a lowercase English letter. The second line of each test case contains the string $$$t$$$ ($$$1 \le ... | standard output | standard input | PyPy 3-64 | Python | 1,500 | train_105.jsonl | c9283d50f2f81b1034949fd581dff554 | 256 megabytes | ["4\nababa\nba\nababa\nbb\naaa\naaaa\naababa\nababa"] | PASSED | #!/usr/bin/env python3
def solve(s, t):
#print('---------')
#print(s)
#print(t)
if 0:
if t == s:
return 'YES'
if len(t) >= len(s):
return 'NO'
if t in s:
return 'YES'
#s = f' {s} '
#t = f' {t} '
max_tri... | 1626964500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["1\n4\n1\n3"] | dc1a20d875572a3f45a9844030b0fcf4 | NoteIn the first and third test cases, you can pick any vertex.In the second test case, one of the maximum cliques is $$$\{2, 3, 4, 5\}$$$.In the fourth test case, one of the maximum cliques is $$$\{3, 4, 6\}$$$. | Soroush and Keshi each have a labeled and rooted tree on $$$n$$$ vertices. Both of their trees are rooted from vertex $$$1$$$.Soroush and Keshi used to be at war. After endless decades of fighting, they finally became allies to prepare a Codeforces round. To celebrate this fortunate event, they decided to make a memori... | For each test case print a single integer — the size of the maximum clique in the memorial graph. | The first line contains an integer $$$t$$$ $$$(1\le t\le 3 \cdot 10^5)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ $$$(2\le n\le 3 \cdot 10^5)$$$. The second line of each test case contains $$$n-1$$$ integers $$$a_2, \ldots, a_n$... | standard output | standard input | PyPy 2 | Python | 2,300 | train_085.jsonl | 52dfb9e6684e60f172c36358acbd4dcc | 256 megabytes | ["4\n4\n1 2 3\n1 2 3\n5\n1 2 3 4\n1 1 1 1\n6\n1 1 1 1 2\n1 2 1 2 2\n7\n1 1 3 4 4 5\n1 2 1 4 2 5"] | PASSED | import sys
import os
from io import BytesIO
from operator import getitem
if sys.version_info[0] < 3:
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
f = sys.stdin
if os.environ.get('USER') == "loic":
f = open("data.in")
line = lambda: f.readline().strip('\r\n').split()
def write(w):
... | 1621866900 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["2\n1 1\n2 -1", "2\n1 1\n1 1", "-1"] | ec2f247cc30144e61e76805786475622 | NoteIn the first example, we can make a +1 operation on the two first digits, transforming number $$$\textbf{22}3$$$ into $$$\textbf{33}3$$$, and then make a -1 operation on the last two digits, transforming $$$3\textbf{33}$$$ into $$$3\textbf{22}$$$.It's also possible to do these operations in reverse order, which mak... | One player came to a casino and found a slot machine where everything depends only on how he plays. The rules follow.A positive integer $$$a$$$ is initially on the screen. The player can put a coin into the machine and then add $$$1$$$ to or subtract $$$1$$$ from any two adjacent digits. All digits must remain from $$$... | If it is impossible to win the jackpot, print a single integer $$$-1$$$. Otherwise, the first line must contain the minimal possible number $$$c$$$ of coins the player has to spend. $$$\min(c, 10^5)$$$ lines should follow, $$$i$$$-th of them containing two integers $$$d_i$$$ and $$$s_i$$$ ($$$1\le d_i\le n - 1$$$, $$$s... | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) standing for the length of numbers $$$a$$$ and $$$b$$$. The next two lines contain numbers $$$a$$$ and $$$b$$$, each one on a separate line ($$$10^{n-1} \le a, b < 10^n$$$). | standard output | standard input | Python 3 | Python | 2,700 | train_037.jsonl | 3682dc884087d0475b348a1c434078ca | 256 megabytes | ["3\n223\n322", "2\n20\n42", "2\n35\n44"] | PASSED | def main():
n = int(input())
a = list(map(int, (x for x in input())))
b = list(map(int, (x for x in input())))
x = [0] * (n - 1)
x[0] = b[0] - a[0]
for i in range(1, n - 1):
x[i] = b[i] - a[i] - x[i - 1]
if a[n - 1] + x[n - 2] != b[n - 1]:
print(-1)
return
cnt = s... | 1551627300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3\n0\n3"] | d5627b9fe5f6c5a7247e1f9d9e9b0c6a | NoteConsider the first test case.Initially $$$a = [1, 1, 1, 2, 2, 3]$$$.In the first operation, Eshag can choose the subsequence containing $$$a_1$$$, $$$a_5$$$ and $$$a_6$$$, their average is equal to $$$\frac{a_1 + a_5 + a_6}{3} = \frac{6}{3} = 2$$$. So $$$a_6$$$ will be deleted.After this $$$a = [1, 1, 1, 2, 2]$$$.I... | Eshag has an array $$$a$$$ consisting of $$$n$$$ integers.Eshag can perform the following operation any number of times: choose some subsequence of $$$a$$$ and delete every element from it which is strictly larger than $$$AVG$$$, where $$$AVG$$$ is the average of the numbers in the chosen subsequence.For example, if $$... | For each test case print a single integer — the maximum number of elements Eshag can delete from the array $$$a$$$. | The first line contains an integer $$$t$$$ $$$(1\le t\le 100)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ $$$(1\le n\le 100)$$$ — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1... | standard output | standard input | Python 3 | Python | 800 | train_085.jsonl | 1424e58ee903da5d88219bef5284bf05 | 256 megabytes | ["3\n6\n1 1 1 2 2 3\n6\n9 9 9 9 9 9\n6\n6 4 1 1 4 1"] | PASSED | for i in range(int(input())):
a, b = int(input()), [int(x) for x in input().split()]
print(a - b.count(min(b)))
| 1621866900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2 2\n1 4\n2 1\n0 1\n1 1\n0 1\n8 1\n3 6"] | 904af5d6a9d84b7b7b7ff8d63e6f0254 | NoteThe first test case is explained in the statement.In the second case, it is enough to cut any of the four occurrences.In the third case, string $$$s$$$ is the concatenation of two strings $$$t =$$$ "xyz", so there is a unique optimal sequence of $$$2$$$ moves.In the fourth and sixth cases, the string $$$s$$$ initia... | You are given two non-empty strings $$$s$$$ and $$$t$$$, consisting of Latin letters.In one move, you can choose an occurrence of the string $$$t$$$ in the string $$$s$$$ and replace it with dots.Your task is to remove all occurrences of the string $$$t$$$ in the string $$$s$$$ in the minimum number of moves, and also ... | For each test case print two integers — the minimum number of moves and the number of different optimal sequences, modulo $$$10^9 + 7$$$. | The first line of the input contains a single integer $$$q$$$ ($$$1 \le q \le 50$$$) — the number of test cases. The descriptions of the sets follow. The first line of each set contains a non-empty string $$$s$$$ ($$$1 \le |s| \le 500$$$) consisting of lowercase Latin letters. The second line of each set contains a non... | standard output | standard input | Python 3 | Python | 2,100 | train_110.jsonl | 765919fc9120fae0599ea4a5e2b713c2 | 256 megabytes | ["8\n\nabababacababa\n\naba\n\nddddddd\n\ndddd\n\nxyzxyz\n\nxyz\n\nabc\n\nabcd\n\nabacaba\n\nabaca\n\nabc\n\ndef\n\naaaaaaaa\n\na\n\naaaaaaaa\n\naa"] | PASSED | from typing import List, Dict, Set, Sequence, Tuple, Deque, AnyStr, Optional
# from sortedcontainers import SortedDict, SortedSet, SortedList
from collections import deque, Counter, OrderedDict
import bisect
case_num = int(input())
for case_index in range(case_num):
s = input()
t = input()
t_index... | 1662993300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["25", "849"] | 79ee1ff924432a184d8659db5f960304 | NoteThe tree in the second example is given below: We have $$$21$$$ subsets of size $$$2$$$ in the given tree. Hence, $$$$$$S \in \left\{\{1, 2\}, \{1, 3\}, \{1, 4\}, \{1, 5\}, \{1, 6\}, \{1, 7\}, \{2, 3\}, \{2, 4\}, \{2, 5\}, \{2, 6\}, \{2, 7\}, \{3, 4\}, \{3, 5\}, \{3, 6\}, \{3, 7\}, \{4, 5\}, \{4, 6\}, \{4, 7\}, \{... | You are given a tree $$$G$$$ with $$$n$$$ vertices and an integer $$$k$$$. The vertices of the tree are numbered from $$$1$$$ to $$$n$$$.For a vertex $$$r$$$ and a subset $$$S$$$ of vertices of $$$G$$$, such that $$$|S| = k$$$, we define $$$f(r, S)$$$ as the size of the smallest rooted subtree containing all vertices i... | Print the answer modulo $$$10^9 + 7$$$. | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$3 \le n \le 2 \cdot 10^5$$$, $$$1 \le k \le n$$$). Each of the following $$$n - 1$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le n$$$), denoting an edge between vertex $$$x$$$ and $$$y$$$. It is guaranteed that the given edges form a tr... | standard output | standard input | Python 3 | Python | 2,500 | train_089.jsonl | 548ab908d319fee1b75d8be50ac97f0d | 512 megabytes | ["3 2\n1 2\n1 3", "7 2\n1 2\n2 3\n2 4\n1 5\n4 6\n4 7"] | PASSED | import sys
sys.setrecursionlimit(300000)
import faulthandler
faulthandler.enable()
n, k = map(int, input().split())
MOD = 10**9 + 7
fact = [1 for i in range(n+1)]
for i in range(2, n+1):
fact[i] = i*fact[i-1] % MOD
inv_fact = [1 for i in range(n+1)]
inv_fact[-1] = pow(fact[-1], MOD-2, MOD)
for i in ... | 1654007700 | [
"math",
"trees"
] | [
0,
0,
0,
1,
0,
0,
0,
1
] | |
2 seconds | ["tolik", "bolik"] | 55099493c66b003d4261310bf2cc8f93 | null | There are n stone quarries in Petrograd.Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last for the i-th quarry) has xi + mi - 1 stones in it.Two oligarchs play ... | Output «tolik» if the oligarch who takes a stone first wins, and «bolik» otherwise. | The first line of the input contains one integer number n (1 ≤ n ≤ 105) — the amount of quarries. Then there follow n lines, each of them contains two space-separated integers xi and mi (1 ≤ xi, mi ≤ 1016) — the amount of stones in the first dumper of the i-th quarry and the number of dumpers at the i-th quarry. | standard output | standard input | Python 3 | Python | 2,000 | train_030.jsonl | 1275c417648c12931133a58c02fe061f | 64 megabytes | ["2\n2 1\n3 2", "4\n1 1\n1 1\n1 1\n1 1"] | PASSED | def f(x):
if x%4==0:
return x
elif x%4==1:
return 1
elif x%4==2:
return x+1
return 0
n = int(input())
res = 0
for i in range(n):
x,m = input().split()
x,m = int(x),int(m)
res ^= f(x-1)^f(x+m-1)
if res == 0:
print("bolik")
else:
print("tolik") | 1275145200 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
4 seconds | ["1 0 1 2 -1 -1 \n1 \n-1 -1 -1 \n1 0 0 0 0 \n1 1 2 1"] | 055346dd6d2e0cff043b52a395e31fdf | null | You are given a directed graph $$$G$$$ which can contain loops (edges from a vertex to itself). Multi-edges are absent in $$$G$$$ which means that for all ordered pairs $$$(u, v)$$$ exists at most one edge from $$$u$$$ to $$$v$$$. Vertices are numbered from $$$1$$$ to $$$n$$$.A path from $$$u$$$ to $$$v$$$ is a sequenc... | Output $$$t$$$ lines. The $$$i$$$-th line should contain an answer for the $$$i$$$-th test case: a sequence of $$$n$$$ integers from $$$-1$$$ to $$$2$$$. | The first contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Before each test case, there is an empty line. The first line of the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 4 \cdot 10^5, 0 \le m \le 4 \cdot 10^5$$$) — nu... | standard output | standard input | PyPy 3-64 | Python | 2,100 | train_103.jsonl | f6678b90251659960cf811b8f860934c | 512 megabytes | ["5\n\n6 7\n1 4\n1 3\n3 4\n4 5\n2 1\n5 5\n5 6\n\n1 0\n\n3 3\n1 2\n2 3\n3 1\n\n5 0\n\n4 4\n1 2\n2 3\n1 4\n4 3"] | PASSED | from collections import Counter, deque
# from itertools import combinations
import bisect
import heapq
from locale import currency
import math
from re import S
import sys
from types import GeneratorType
# sys.stdin = open('grey.in', 'r')
# sys.setrecursionlimit(1 * 10**9)
def bootstrap(f, stack=[])... | 1625927700 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6"] | ddbac4053bd07eada84bc44275367ae2 | null | Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: the graph contains exactly 2n + p edges; the graph doesn't contain self-loops and multiple edges; for any integer k (1 ≤ k ≤ n), any subgraph consisting of k vertices contains at most 2k + p edges. A subgraph of a graph... | For each of the t tests print 2n + p lines containing the description of the edges of a p-interesting graph: the i-th line must contain two space-separated integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi) — two vertices, connected by an edge in the resulting graph. Consider the graph vertices numbered with integers from 1 to ... | The first line contains a single integer t (1 ≤ t ≤ 5) — the number of tests in the input. Next t lines each contains two space-separated integers: n, p (5 ≤ n ≤ 24; p ≥ 0; ) — the number of vertices in the graph and the interest value for the appropriate test. It is guaranteed that the required graph exists. | standard output | standard input | PyPy 3 | Python | 1,500 | train_001.jsonl | ffa59de54a103421c0547de702ffc6af | 256 megabytes | ["1\n6 0"] | PASSED | #b=b[2:].zfill(32)
#for deque append(),pop(),appendleft(),popleft(),count()
import math,sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili=lambda:list(map(int,sys.stdin.readlines()))
li = lambda:list(map(int,input().split()))
I=lambda:int(input())
S=lambda:... | 1394983800 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["2\n4 5", "1\n4"] | 54c23dda2aa1d58ecf22c03015dca55c | null | Vasily the bear has got a sequence of positive integers a1, a2, ..., an. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum. The beauty of the written out numbers b1, b2, ..., bk is such maximum non-negative integer v, that number b1 and b2 ... | In the first line print a single integer k (k > 0), showing how many numbers to write out. In the second line print k integers b1, b2, ..., bk — the numbers to write out. You are allowed to print numbers b1, b2, ..., bk in any order, but all of them must be distinct. If there are multiple ways to write out the numbe... | The first line contains integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 109). | standard output | standard input | PyPy 3 | Python | 1,800 | train_053.jsonl | d0422d128e1e7f92f9e4acfeb03c63fa | 256 megabytes | ["5\n1 2 3 4 5", "3\n1 2 4"] | PASSED | import functools
n = int(input())
nums = list(map(int, input().split()))
bits = ["{0:b}".format(num) for num in nums]
def possible(v):
possible_vals = [
nums[x]
for x in range(n)
if len(bits[x]) > v and bits[x][len(bits[x])-v-1] == '1'
]
if len(possible_vals) == 0:
return ... | 1376062200 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
2 seconds | ["Bob\nAlice\nAlice\nBob"] | 255ee92f5b860eacd9d6321195072734 | NoteIn the first test case, the game ends immediately because Alice cannot make a move.In the second test case, Alice can subtract $$$2$$$ making $$$n = 2$$$, then Bob cannot make a move so Alice wins.In the third test case, Alice can subtract $$$3$$$ so that $$$n = 9$$$. Bob's only move is to subtract $$$3$$$ and make... | Alice and Bob are playing a game. They start with a positive integer $$$n$$$ and take alternating turns doing operations on it. Each turn a player can subtract from $$$n$$$ one of its divisors that isn't $$$1$$$ or $$$n$$$. The player who cannot make a move on his/her turn loses. Alice always moves first.Note that they... | For each test case output "Alice" if Alice will win the game or "Bob" if Bob will win, if both players play optimally. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$) — the initial number. | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_084.jsonl | bef7825be0f6c28f21cd1fceaf41bb98 | 256 megabytes | ["4\n1\n4\n12\n69"] | PASSED | import sys
input = sys.stdin.readline
inf = float('inf')
def getInt():
return int(input())
def getStr():
return input().strip()
def getList(split=True):
s = getStr()
if split:
s = s.split()
return map(int, s)
t = getInt()
# t = 1
M = 10 ** 9 + 7
A = {2**i for i in range(1, 32, 2)}... | 1624026900 | [
"number theory",
"math",
"games"
] | [
1,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["2", "3"] | 4866b4b48be5833b1f5a7206a241f83d | null | Your friend is developing a computer game. He has already decided how the game world should look like — it should consist of $$$n$$$ locations connected by $$$m$$$ two-way passages. The passages are designed in such a way that it should be possible to get from any location to any other location.Of course, some passages... | Print one integer — the maximum number of bosses your friend can place, considering all possible choices for $$$s$$$ and $$$t$$$. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 3 \cdot 10^5$$$, $$$n - 1 \le m \le 3 \cdot 10^5$$$) — the number of locations and passages, respectively. Then $$$m$$$ lines follow, each containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le n$$$, $$$x \ne y$$$) describing the endpoints... | standard output | standard input | Python 2 | Python | 2,100 | train_033.jsonl | 7b43d912307529fc1e36082abe5efadc | 256 megabytes | ["5 5\n1 2\n2 3\n3 1\n4 1\n5 2", "4 3\n1 2\n4 3\n3 2"] | PASSED | from sys import stdin
from itertools import repeat
def main():
n, m = map(int, stdin.readline().split())
dat = map(int, stdin.read().split(), repeat(10, 2 * m))
xt = [None] * (2 * m)
la = [None] * (n + 1)
j = 0
for i in xrange(m):
x, y = dat[j], dat[j+1]
xt[j] = la[y]
la[... | 1530110100 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["BAAA\nABAA\nBBBA\nBBBB", "BABBB\nBBBBB\nAABBB\nAAABA\nAAAAB"] | d9c77057a596c946592e73e1561aad8f | NoteHere's the graph in the first sample test case: Here's the graph in the second sample test case: | As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) with n vertices and m edges. There's a character written on each edge, a lower... | Print n lines, a string of length n in each one. The j-th character in i-th line should be 'A' if Max will win the game in case her marble is initially at vertex i and Lucas's marble is initially at vertex j, and 'B' otherwise. | The first line of input contains two integers n and m (2 ≤ n ≤ 100, ). The next m lines contain the edges. Each line contains two integers v, u and a lowercase English letter c, meaning there's an edge from v to u written c on it (1 ≤ v, u ≤ n, v ≠ u). There's at most one edge between any pair of vertices. It is guaran... | standard output | standard input | Python 3 | Python | 1,700 | train_023.jsonl | 0b7ebb12df20cd2f59114d1439827346 | 256 megabytes | ["4 4\n1 2 b\n1 3 a\n2 4 c\n3 4 b", "5 8\n5 3 h\n1 2 c\n3 1 c\n3 2 r\n5 1 r\n4 3 z\n5 4 r\n5 2 h"] | PASSED | # int(input())
# [int(i) for i in input().split()]
import sys
sys.setrecursionlimit(20000)
def go(v,w,last):
if game[v][w][last] >= 0: return(game[v][w][last])
flag = 0
move = 0
for p in edges_out[v]:
if p[1] >= last:
move = 1
if not go(w,p[0],p[1]):
... | 1517236500 | [
"games",
"graphs"
] | [
1,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["0\n1\n-1\n6\n10\n17"] | 6f0d3a7971ffc2571838ecd8bf14238d | NoteTest case $$$1$$$: $$$n=1$$$, $$$m=1$$$, and initially you are standing in $$$(1, 1)$$$ so $$$0$$$ move is required to reach $$$(n, m) = (1, 1)$$$.Test case $$$2$$$: you should go down to reach $$$(2, 1)$$$.Test case $$$3$$$: it is impossible to reach $$$(1, 3)$$$ without moving right two consecutive times, or with... | You are given a grid with $$$n$$$ rows and $$$m$$$ columns. Rows and columns are numbered from $$$1$$$ to $$$n$$$, and from $$$1$$$ to $$$m$$$. The intersection of the $$$a$$$-th row and $$$b$$$-th column is denoted by $$$(a, b)$$$. Initially, you are standing in the top left corner $$$(1, 1)$$$. Your goal is to reach ... | For each test case, print a single integer: $$$-1$$$ if it is impossible to reach $$$(n, m)$$$ under the given conditions, otherwise the minimum number of moves. | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of the test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^9$$$) — the size of the grid. | standard output | standard input | Python 3 | Python | 800 | train_084.jsonl | 96a0dcca545ceb8d9ee70d5712325dc3 | 256 megabytes | ["6\n\n1 1\n\n2 1\n\n1 3\n\n4 2\n\n4 6\n\n10 5"] | PASSED | test = int(input())
steps = 0
ans = []
for tests in range(test):
n, m = map(int, input().split())
if (n== 1 and m > 2) or (m == 1 and n > 2):
steps = -1
ans.append(steps)
if n == m == 1:
steps = 0
ans.append(steps)
if (m>=n) and n!=1:
if (m+n)%2 == 0:
... | 1650378900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["6", "8"] | 4695aa2b3590a0734ef2c6c580e471a9 | NoteConsider the first example.One option for Thanos is to burn the whole base $$$1-4$$$ with power $$$2 \cdot 2 \cdot 4 = 16$$$.Otherwise he can divide the base into two parts $$$1-2$$$ and $$$3-4$$$.For base $$$1-2$$$, he can either burn it with power $$$2 \cdot 1 \cdot 2 = 4$$$ or divide it into $$$2$$$ parts $$$1-1... | Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $$$2$$$. Thanos wants to destroy... | Output one integer — the minimum power needed to destroy the avengers base. | The first line contains four integers $$$n$$$, $$$k$$$, $$$A$$$ and $$$B$$$ ($$$1 \leq n \leq 30$$$, $$$1 \leq k \leq 10^5$$$, $$$1 \leq A,B \leq 10^4$$$), where $$$2^n$$$ is the length of the base, $$$k$$$ is the number of avengers and $$$A$$$ and $$$B$$$ are the constants explained in the question. The second line co... | standard output | standard input | PyPy 3 | Python | 1,700 | train_000.jsonl | e7c3fd91e0f1a37d1a760cf4f3954780 | 256 megabytes | ["2 2 1 2\n1 3", "3 2 1 2\n1 7"] | PASSED | def inint():
return int(input())
def mp():
return map(int,input().split())
from bisect import bisect,bisect_left
def sol(i,j):
works=bisect(a,j)-bisect_left(a,i)
if works==0:return A
if i==j:return B*works
m=(i+j)>>1
return min(B*(j-i+1)*works,sol(i,m)+sol(m+1,j))
n,k,A,B=mp()
... | 1549208100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1"] | f83c91c9e9252aba4736aa0bea82493b | null | n people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2, 3, ..., n - 1 friends among those who stayed by the moment of their leaving, did the same.What is the maximum amount of peop... | For each test output in a separate line one number — the maximum amount of people that could stay in the end. | The first input line contains one number t — amount of tests (1 ≤ t ≤ 105). Each of the following t lines contains one integer number n (1 ≤ n ≤ 105). | standard output | standard input | Python 3 | Python | 1,600 | train_024.jsonl | 6fb67219662a242a155a5ae94aab3b3d | 256 megabytes | ["1\n3"] | PASSED | n = input()
for i in range(0,int (n)):
x = input()
if int(x)-2 == -1:
print(0)
else:
print(int(x)-2) | 1278687600 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
1 second | ["3", "10"] | 54e2b6bea0dc6ee68366405945af50c6 | NoteIn the second example the head moves in the following way: 1->2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units 2->3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units 3->4 means movement from the sector 2 to the sector 4, i.e. it takes 2 time units... | HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read som... | Print the only integer — the number of time units needed to read the file. | The first line contains a positive integer n (1 ≤ n ≤ 2·105) — the number of fragments. The second line contains n different integers fi (1 ≤ fi ≤ n) — the number of the fragment written in the i-th sector. | standard output | standard input | Python 3 | Python | 1,200 | train_013.jsonl | c69e87f38fd7386bca19f794d75c5aa7 | 256 megabytes | ["3\n3 1 2", "5\n1 3 5 4 2"] | PASSED | from bisect import bisect
from itertools import permutations,combinations
n=int(input())
a=list(map(int,input().split()))
cnt=1
b = []
for x in a:
b.append([x,cnt])
cnt+=1
b.sort()
res = 0
for i in range(1,n):
res+=abs(b[i][1]-b[i-1][1])
print(res) | 1451055600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["16.000000"] | bb3fc45f903588baf131016bea175a9f | NoteIn the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16. | Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one... | Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9. | The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide. | standard output | standard input | Python 3 | Python | 2,100 | train_048.jsonl | b9da6adb7ff5f00a9127e39974a16d61 | 256 megabytes | ["5\n0 0\n0 4\n4 0\n4 4\n2 3"] | PASSED | # calculate convex of polygon v.
# v is list of complexes stand for points.
def convex(v, eps=1e-8):
# fetch the seed point
v.sort(key=lambda x:(x.real,x.imag))
v = v[0:1] + sorted(v[1:], key=lambda x:(x-v[0]).imag/abs(x-v[0]))
n = 1
for i in range(2, len(v)):
while n > 1 and ((v[n]-v[n-1]... | 1377876600 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
1 second | ["YES\n1 2 3 4 5\nYES\n1145 1926 1440 1220 1230 1350 1001 1000 1233\nNO\nYES\n1000000000"] | d2cc6efe7173a64482659ba59efeec16 | NoteIn the first test case, $$$\gcd(1,a_1),\gcd(2,a_2),\ldots,\gcd(5,a_5)$$$ are equal to $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, respectively. | You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$. | For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any. | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed... | standard output | standard input | PyPy 3 | Python | 1,100 | train_108.jsonl | 41f371e60d17f7738724802f7a0f13af | 256 megabytes | ["4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000"] | PASSED | for _ in range(int(input())):
n,l,r=[int(num) for num in input().split(" ",2)]
truth=True
for i in range(1,n+1):
if i*(1+(l-1)//i)>r:
print("No")
truth=False
break
if truth:
print("Yes")
a=[i*(1+(l-1)//i) for i in range(1,n+1)]
... | 1657982100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["0 2 12 22", "0 3 5"] | 857d84cfbf8c9ce5c95d36b4d2854a88 | null | You have an array $$$a$$$ consisting of $$$n$$$ distinct positive integers, numbered from $$$1$$$ to $$$n$$$. Define $$$p_k$$$ as $$$$$$p_k = \sum_{1 \le i, j \le k} a_i \bmod a_j,$$$$$$ where $$$x \bmod y$$$ denotes the remainder when $$$x$$$ is divided by $$$y$$$. You have to find and print $$$p_1, p_2, \ldots, p_n$$... | Print $$$n$$$ integers $$$p_1, p_2, \ldots, p_n$$$. | The first line contains $$$n$$$ — the length of the array ($$$2 \le n \le 2 \cdot 10^5$$$). The second line contains $$$n$$$ space-separated distinct integers $$$a_1, \ldots, a_n$$$ ($$$1 \le a_i \le 3 \cdot 10^5$$$, $$$a_i \neq a_j$$$ if $$$i \neq j$$$). | standard output | standard input | PyPy 3-64 | Python | 2,300 | train_105.jsonl | 510e4dee977c24b486afaabdc140aec0 | 256 megabytes | ["4\n6 2 7 3", "3\n3 2 1"] | PASSED | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def fenwick_tree(n):
tree = [0] * (n + 1)
return tree
def get_sum(i):
s = 0
while i > 0:
s += tree[i]
i -= i & -i
return s
def add(i, x):
while i < len(tree):
tree[i] += x
... | 1626964500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["5 2", "15 1", "18 6"] | 926c01419301caff034988aff98edc9d | NoteIn the first test, for $$$k = 2$$$, there exists only two valid partitions: $$$\{[1, 1], [2, 3]\}$$$ and $$$\{[1, 2], [3, 3]\}$$$. For each partition, the partition value is equal to $$$2 + 3 = 5$$$. So, the maximum possible value is $$$5$$$ and the number of partitions is $$$2$$$.In the third test, for $$$k = 3$$$... | You are given a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$ and an integer $$$k$$$, such that $$$1 \leq k \leq n$$$. A permutation means that every number from $$$1$$$ to $$$n$$$ is contained in $$$p$$$ exactly once.Let's consider all partitions of this permutation into $$$k$$$ disjoint ... | Print two integers — the maximum possible partition value over all partitions of the permutation into $$$k$$$ disjoint segments and the number of such partitions for which the partition value is equal to the maximum possible value, modulo $$$998\,244\,353$$$. Please note that you should only find the second value modul... | The first line contains two integers, $$$n$$$ and $$$k$$$ ($$$1 \leq k \leq n \leq 200\,000$$$) — the size of the given permutation and the number of segments in a partition. The second line contains $$$n$$$ different integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \leq p_i \leq n$$$) — the given permutation. | standard output | standard input | Python 3 | Python | 1,300 | train_008.jsonl | 7ff3d6d65fac4c998cfc52939c007b38 | 256 megabytes | ["3 2\n2 1 3", "5 5\n2 1 5 3 4", "7 3\n2 7 3 1 5 4 6"] | PASSED | [n, k]=list(map(int, input().split()))
arr=list(map(int, input().split()))
par_val=(k*(2*n-k+1))//2
prev, ways = 0, 1
while(arr[prev]<n-k+1):
prev+=1
start=prev+1
for idx in range(start, n):
if(arr[idx]>n-k):
ways*=(idx-prev)
prev=idx
print(par_val, ways%998244353) | 1584628500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["4\n3\n16"] | 1f7fa6c56cb7be9404aa2ebaba89a44c | NoteConsider the first test case of the example. The initial state of the trees is $$$[1, 2, 4]$$$. During the first day, let's water the first tree, so the sequence of heights becomes $$$[2, 2, 4]$$$; during the second day, let's water the second tree, so the sequence of heights becomes $$$[2, 4, 4]$$$; let's skip ... | There are $$$n$$$ trees in a park, numbered from $$$1$$$ to $$$n$$$. The initial height of the $$$i$$$-th tree is $$$h_i$$$.You want to water these trees, so they all grow to the same height.The watering process goes as follows. You start watering trees at day $$$1$$$. During the $$$j$$$-th day you can: Choose a tree... | For each test case, print one integer — the minimum number of days required to water the trees, so they grow to the same height. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of trees. The second line of the test case contains $$$n$$$ integers $$$h_1, h_2, \ldots, h_n$$... | standard output | standard input | Python 3 | Python | 1,700 | train_092.jsonl | 026173628ee9e396dea69cf2d4020dad | 256 megabytes | ["3\n3\n1 2 4\n5\n4 4 3 5 5\n7\n2 5 4 8 3 7 4"] | PASSED | import sys
from os import path
def solve(word):
# handel string input from codeforces
hieghts=word.split(" ")
trees = [int(i) for i in hieghts]
Max = max(trees)
Sum = 0
c1 = 0
#count number of even and odd days needed for all trees
for i in trees:
dist = Max - i
if(dist%2 == 1):
... | 1649514900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["? baa\n? aba\n? aab\n! xyz"] | e9079292d6bb328d8fe355101028cc6a | NoteIn the sample, the testcase described in the statement is used. The participant asks the first query with string baa, which is transformed to aab. The second query contains string aba, which is transformed to baa. The third query contains string aab, which is transformed to aba. The participant can deduce that the ... | This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You m... | To give the answer, your program should print one line $$$!$$$ $$$s$$$ with a line break in the end. After that, it should flush the output and terminate gracefully. | Initially the testing system sends one string $$$t$$$, consisting of lowercase Latin letters ($$$1 \le |t| = n \le 10^4$$$). | standard output | standard input | Python 3 | Python | 2,200 | train_038.jsonl | 7917fd1c04b7b478590335b4e4eefa96 | 256 megabytes | ["yzx\naab\nbaa\naba"] | PASSED | t = [tmp for tmp in input().strip()]
n = len(t)
az = 'abcdefghijklmnopqrstuvwxyz'
s1 = [tmp for tmp in az] * (n // 26 + 1)
s1 = s1[:n]
s2 = []
for ch in az:
s2 += [ch] * 26
s2 *= (n // 26 + 1)
s2 = s2[:n]
s3 = []
for ch in az:
s3 += [ch] * 676
s3 *= (n // 676 + 1)
s3 = s3[:n]
print("? ", *s1, sep='', flush... | 1550504400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | 753113fa5130a67423f2e205c97f8017 | null | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict o... | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | The first line contains an integer n, which is the number of people in the crew (1 ≤ n ≤ 100). Then follow n lines. The i-th of those lines contains two words — the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the lin... | standard output | standard input | Python 3 | Python | 900 | train_006.jsonl | 61868140103ea29a33149967d74b93f5 | 256 megabytes | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | PASSED | d = {
'rat':[],
'child':[],
'man':[],
'captain':[]
}
i = int(input())
while i:
s = input()
data = s.split()
if data[1] == 'child' or data[1] == 'woman':
d['child'].append(data[0])
else:
d[data[1]].append(data[0])
i = i -1
for p in d['rat']:
print(p)
for p in d['c... | 1298908800 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["2\n1\nMORTAL\n4"] | da18ca9f125d1524e7c0a2637b1fa3df | NoteIn the first test case, it can be done in two usages, as follows:Usage 1: Usage 2: In the second test case, it can be done with just one usage of the power. In the third test case, it is impossible to convert everyone to Beingawesomeism, so the answer is "MORTAL". | You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a $$$r \times c$$$ grid. Each cell on the grid represents a country. Each country has a dominant religion. There are only two religions in your world. One of the religions is called Be... | For each test case, output a single line containing the minimum number of usages of your power needed to convert everyone to Beingawesomeism, or the string "MORTAL" (without quotes) if it is impossible to do so. | The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 2\cdot 10^4$$$) denoting the number of test cases. The first line of each test case contains two space-separated integers $$$r$$$ and $$$c$$$ denoting the dimensions of the grid ($$$1 \le r, c \le 60$$$). The next $$$r$$$ lines each contains $$$c... | standard output | standard input | PyPy 2 | Python | 1,800 | train_003.jsonl | 083ed4da4425c06ce06878a75a6d9692 | 256 megabytes | ["4\n7 8\nAAPAAAAA\nPPPPAAAA\nPPPPAAAA\nAPAAPPPP\nAPAPPAPP\nAAAAPPAP\nAAAAPPAA\n6 5\nAAAAA\nAAAAA\nAAPAA\nAAPAP\nAAAPP\nAAAPP\n4 4\nPPPP\nPPPP\nPPPP\nPPPP\n3 4\nPPPP\nPAAP\nPPPP"] | PASSED | mod=10**9+7
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#import threading
#threading.stack_size(2**27)
#import sys
#sys.setrecursionlimit(10**6)
#fact=[1]
#for i in range(1,1000001):
# fact.append((fact[-1]*i)%mod)
#ifact=[0]*1000001
#ifact[1000000]=pow(fact[100... | 1576386300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3", "4", "25"] | 6fbcc92541705a63666701238778a04a | NoteIn first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25. | While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai ≤ aj and there are exactly ... | Print one integer — the answer to the problem. | The first line contains 3 integers n, x, k (1 ≤ n ≤ 105, 1 ≤ x ≤ 109, 0 ≤ k ≤ 109), where n is the size of the array a and x and k are numbers from the statement. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a. | standard output | standard input | Python 3 | Python | 1,700 | train_035.jsonl | 4fa449ec15c9300a4be42f932d13b2d0 | 256 megabytes | ["4 2 1\n1 3 5 7", "4 2 0\n5 3 1 7", "5 3 1\n3 3 3 3 3"] | PASSED | import math
import bisect
n, x, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
ans = 0
for num in a:
l = math.ceil(num/x)*x + (k-1)*x
r = l + x - 1
l = num if l < num else l
# print(l, r, bisect.bisect_left(a, l), bisect.bisect_right(a, r), bisect.bisect_right(a, r) - bisec... | 1511712300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["110", "010"] | 4aaeff1b38d501daf9a877667e075d49 | NoteIn the first example the segment from the $$$1$$$-st to the $$$5$$$-th positions is $$$1, 2, 3, 1, 2$$$. There is a subsequence $$$1, 3, 2$$$ that is a cyclic shift of the permutation. The subsegment from the $$$2$$$-nd to the $$$6$$$-th positions also contains a subsequence $$$2, 1, 3$$$ that is equal to the permu... | Recently Lynyrd and Skynyrd went to a shop where Lynyrd bought a permutation $$$p$$$ of length $$$n$$$, and Skynyrd bought an array $$$a$$$ of length $$$m$$$, consisting of integers from $$$1$$$ to $$$n$$$. Lynyrd and Skynyrd became bored, so they asked you $$$q$$$ queries, each of which has the following form: "does t... | Print a single string of length $$$q$$$, consisting of $$$0$$$ and $$$1$$$, the digit on the $$$i$$$-th positions should be $$$1$$$, if the subsegment of array $$$a$$$ from the $$$l_i$$$-th to the $$$r_i$$$-th positions, inclusive, contains a subsequence that is a cyclic shift of $$$p$$$, and $$$0$$$ otherwise. | The first line contains three integers $$$n$$$, $$$m$$$, $$$q$$$ ($$$1 \le n, m, q \le 2 \cdot 10^5$$$) — the length of the permutation $$$p$$$, the length of the array $$$a$$$ and the number of queries. The next line contains $$$n$$$ integers from $$$1$$$ to $$$n$$$, where the $$$i$$$-th of them is the $$$i$$$-th elem... | standard output | standard input | PyPy 3 | Python | 2,000 | train_002.jsonl | 21b7c60e1c22ab828099133b35ea728c | 256 megabytes | ["3 6 3\n2 1 3\n1 2 3 1 2 3\n1 5\n2 6\n3 5", "2 4 3\n2 1\n1 1 2 2\n1 2\n2 3\n3 4"] | PASSED | import sys
class segmentTree:
def __init__(self, n):
self.n = n
self.seg = [self.n + 1] * (self.n << 1)
def update(self, p, value):
p += self.n
self.seg[p] = value
while p > 1:
p >>= 1
self.seg[p] = min(self.seg[p * 2], self.seg[p * 2 + 1])
def query(self, l, r):
res = self.n
l += self... | 1553965800 | [
"math",
"trees"
] | [
0,
0,
0,
1,
0,
0,
0,
1
] | |
3 seconds | ["16\n0 1\n0 1\n0 -1\n0 -1", "312\n0 6\n5 -3\n-5 -3"] | 345f923c42c5b5f3975a6f8c61e6030f | null | Roland loves growing flowers. He has recently grown a beautiful rose at point (0, 0) of the Cartesian coordinate system. The rose is so beautiful that Roland is afraid that the evil forces can try and steal it. To protect the rose, Roland wants to build n watch towers. Let's assume that a tower is a point on the plane ... | In the first line print an integer — the maximum possible sum of squared distances. In the i-th of the following n lines print two integers, xi, yi — the coordinates of the i-th tower. Each tower must be inside or on the border of the circle with radius r. Note that there may be several towers located at the same point... | The first line contains two integers, n and r (2 ≤ n ≤ 8; 1 ≤ r ≤ 30). | standard output | standard input | Python 2 | Python | 2,700 | train_067.jsonl | 61e915a86cbef749b6d46b9401b85c28 | 256 megabytes | ["4 1", "3 6"] | PASSED | """
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++... | 1408548600 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["Alice\nDraw"] | 6cffd0fa1146b250a2608d53f3f738fa | NoteOne of the possible games Alice and Bob can play in the first testcase: Alice picks the first letter in $$$s$$$: $$$s=$$$"orces", $$$a=$$$"f", $$$b=$$$""; Bob picks the last letter in $$$s$$$: $$$s=$$$"orce", $$$a=$$$"f", $$$b=$$$"s"; Alice picks the last letter in $$$s$$$: $$$s=$$$"orc", $$$a=$$$"ef", $$$b=$$$... | Alice and Bob are playing a game. Initially, they are given a non-empty string $$$s$$$, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty.Alice starts, then they alternate moves. In one move, a player takes either the first or the last l... | For each testcase, print the result of the game if both players play optimally. If Alice wins, print "Alice". If Bob wins, print "Bob". If it's a draw, print "Draw". | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. Each testcase consists of a single line — a non-empty string $$$s$$$, consisting of lowercase Latin letters. The length of the string $$$s$$$ is even. The total length of the strings over all testcases doesn't exceed $$... | standard output | standard input | Python 3 | Python | 1,800 | train_098.jsonl | 6e37abf2becbf1e73f8cb2094859efc9 | 512 megabytes | ["2\n\nforces\n\nabba"] | PASSED | from functools import lru_cache
t = int(input())
for _ in range(t):
s = input()
l = len(s)
dp = [[True for i in range(l + 1)] for j in range(l + 1)]
for k in range(2, l + 1, 2):
for i in range(l + 1 - k):
j = i + k
dp[i][j] = (s[i] == s[j - 1] and dp[i + 1][j - 1... | 1662647700 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
1 second | ["-1\n57\n239\n6789"] | 43996d7e052aa628a46d03086f9c5436 | NoteIn the first test case, there are no possible solutions for $$$s$$$ consisting of one digit, because any such solution is divisible by itself.For the second test case, the possible solutions are: $$$23$$$, $$$27$$$, $$$29$$$, $$$34$$$, $$$37$$$, $$$38$$$, $$$43$$$, $$$46$$$, $$$47$$$, $$$49$$$, $$$53$$$, $$$54$$$, ... | You are given a integer $$$n$$$ ($$$n > 0$$$). Find any integer $$$s$$$ which satisfies these conditions, or report that there are no such numbers:In the decimal representation of $$$s$$$: $$$s > 0$$$, $$$s$$$ consists of $$$n$$$ digits, no digit in $$$s$$$ equals $$$0$$$, $$$s$$$ is not divisible by any of ... | For each test case, print an integer $$$s$$$ which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for $$$s$$$, print any solution. | The input consists of multiple test cases. The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 400$$$), the number of test cases. The next $$$t$$$ lines each describe a test case. Each test case contains one positive integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$). It is guaranteed that the sum o... | standard output | standard input | PyPy 3 | Python | 1,000 | train_028.jsonl | b94cdc8499c8864743e9d23a8468a2ab | 256 megabytes | ["4\n1\n2\n3\n4"] | PASSED | # def check(n):
# strng = str(n)
# if not("0" in strng or "1" in strng):
# if n%2 != 0 and n%3 != 0 and n%5 !=0 and n%7 != 0 :
# return True
# return False
def solve(n):
if n<2:
return -1
first = "3"*(n-1)+"7"
if int(first)%7 != 0:
return first
else :
... | 1584628500 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["2 2", "3 3 3"] | bb38c3a6a0e8b0458a4f5fd27dd3f5d8 | NoteIn the first example, the distance between vertex $$$1$$$ and $$$2$$$ equals to $$$2$$$ because one can walk through the edge of weight $$$2$$$ connecting them. So the distance to the farthest node for both $$$1$$$ and $$$2$$$ equals to $$$2$$$.In the second example, one can find that distance between $$$1$$$ and $... | Chouti was tired of the tedious homework, so he opened up an old programming problem he created years ago.You are given a connected undirected graph with $$$n$$$ vertices and $$$m$$$ weighted edges. There are $$$k$$$ special vertices: $$$x_1, x_2, \ldots, x_k$$$.Let's define the cost of the path as the maximum weight o... | The first and only line should contain $$$k$$$ integers. The $$$i$$$-th integer is the distance between $$$x_i$$$ and the farthest special vertex from it. | The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \leq k \leq n \leq 10^5$$$, $$$n-1 \leq m \leq 10^5$$$) — the number of vertices, the number of edges and the number of special vertices. The second line contains $$$k$$$ distinct integers $$$x_1, x_2, \ldots, x_k$$$ ($$$1 \leq x_i \leq n$$$). Ea... | standard output | standard input | Python 3 | Python | 1,800 | train_013.jsonl | c99af22108def166e8e22ba096d22b4c | 256 megabytes | ["2 3 2\n2 1\n1 2 3\n1 2 2\n2 2 1", "4 5 3\n1 2 3\n1 2 5\n4 2 1\n2 3 2\n1 4 4\n1 3 3"] | PASSED | n, m, k = map(int, input().split())
a = list(map(int, input().split()))
g = []
f = list(range(n+1))
s = [0] * (n+1)
def search(n):
while f[n] != n:
f[n] = f[f[n]]
n = f[n]
return n
def can_merge(u, v):
u = search(u)
v = search(v)
f[u] = v
if u == v:
return False
r =... | 1544970900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["5"] | a8c5b1377035f0a772510b5b80588d47 | NoteIn the sample case, the suitable pairs are: $$$a_1 \cdot a_4 = 8 = 2^3$$$; $$$a_1 \cdot a_6 = 1 = 1^3$$$; $$$a_2 \cdot a_3 = 27 = 3^3$$$; $$$a_3 \cdot a_5 = 216 = 6^3$$$; $$$a_4 \cdot a_6 = 8 = 2^3$$$. | You are given $$$n$$$ positive integers $$$a_1, \ldots, a_n$$$, and an integer $$$k \geq 2$$$. Count the number of pairs $$$i, j$$$ such that $$$1 \leq i < j \leq n$$$, and there exists an integer $$$x$$$ such that $$$a_i \cdot a_j = x^k$$$. | Print a single integer — the number of suitable pairs. | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq n \leq 10^5$$$, $$$2 \leq k \leq 100$$$). The second line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^5$$$). | standard output | standard input | Python 2 | Python | 1,800 | train_018.jsonl | 0c450c4102572848fa34d6f5274ed09d | 512 megabytes | ["6 3\n1 3 9 8 24 1"] | PASSED | from sys import stdin
from itertools import repeat
from collections import defaultdict
def main():
n, k = map(int, stdin.readline().split())
a = map(int, stdin.readline().split(), repeat(10, n))
b = range(100010)
c = [0] * 100010
z = int(pow(100010, 1. / k)) + 1
p = [1] * 100010
for i in xra... | 1572087900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["9\n4\n7\n44\n99"] | 8588dd273c9651f8d51cd3a2b7bd81bd | NoteIn the first test case, when Alice evaluates any of the sums $$$1 + 9$$$, $$$2 + 8$$$, $$$3 + 7$$$, $$$4 + 6$$$, $$$5 + 5$$$, $$$6 + 4$$$, $$$7 + 3$$$, $$$8 + 2$$$, or $$$9 + 1$$$, she will get a result of $$$100$$$. The picture below shows how Alice evaluates $$$6 + 4$$$: | Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully — instead of carrying to the next column, she carries to the column two columns to the left.For example, the regular way to evaluate the sum $$$2039 + 2976$$$ would be as shown: However, Alice evaluates it as shown: In part... | For each test case, output one integer — the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $$$n$$$. | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The description of the test cases follows. The only line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 10^9$$$) — the number Alice shows Bob. | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_089.jsonl | 1ab61c205e8d9fb69064db9ae1f858f9 | 256 megabytes | ["5\n100\n12\n8\n2021\n10000"] | PASSED | def solve(n):
s = str(n)
a = int(s[0:len(s):2])
b = int(s[1:len(s):2]) if len(s) > 1 else 0
return (a + 1) * (b + 1) - 2
t = int(input())
for _ in range(t):
n = int(input())
print(solve(n))
| 1630852500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["4\n2 3\n2 4\n6 6\n5 2\n4\n2 2\n2 3\n3 3\n3 2\n3\n2 5\n4 5\n4 2"] | 2ba73e9b1359a17d10cf2f06a30c871d | NoteIt is guaranteed that the solution always exists and is unique. It is guaranteed that in the correct solution the coordinates of the polygon vertices are between 2 and N - 2. A vertex (x1, y1) is lexicographically smaller than vertex (x2, y2) if x1 < x2 or . | Now that Heidi has made sure her Zombie Contamination level checker works, it's time to strike! This time, the zombie lair is a strictly convex polygon on the lattice. Each vertex of the polygon occupies a point on the lattice. For each cell of the lattice, Heidi knows the level of Zombie Contamination – the number of ... | For each test case, give the following output: The first line of the output should contain one integer V, the number of vertices of the polygon that is the secret lair. The next V lines each should contain two integers, denoting the vertices of the polygon in the clockwise order, starting from the lexicographically sma... | The input contains multiple test cases. The first line of each test case contains one integer N, the size of the lattice grid (5 ≤ N ≤ 500). The next N lines each contain N characters, describing the level of Zombie Contamination of each cell in the lattice. Every character of every line is a digit between 0 and 4. Ce... | standard output | standard input | Python 3 | Python | 2,600 | train_054.jsonl | 1702f9ee543c773b723e54c7e7505b29 | 256 megabytes | ["8\n00000000\n00000110\n00012210\n01234200\n02444200\n01223200\n00001100\n00000000\n5\n00000\n01210\n02420\n01210\n00000\n7\n0000000\n0122100\n0134200\n0013200\n0002200\n0001100\n0000000\n0"] | PASSED | import math
def lexComp(a, b):
if a[0] != b[0]:
return -1 if a[0] < b[0] else 1
if a[1] != b[1]:
return -1 if a[1] < b[1] else 1
return 0
def turn(a, b, c):
return (b[0] - a[0]) * (c[1] - b[1]) - (b[1] - a[1]) * (c[0] - b[0])
def dist2(a, b):
return (a[0] - b[0]) ** 2 + (a[1] ... | 1468137600 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["32\n5\n25\n14\n4", "6\n3\n98\n13\n22\n15\n3"] | af002b3aef8e7c698eb6f154a4b0bae0 | NoteThe first example is explained in the legend. | Vus the Cossack has a field with dimensions $$$n \times m$$$, which consists of "0" and "1". He is building an infinite field from this field. He is doing this in this way: He takes the current field and finds a new inverted field. In other words, the new field will contain "1" only there, where "0" was in the current ... | For each query, print the answer. | The first line contains three integers $$$n$$$, $$$m$$$, $$$q$$$ ($$$1 \leq n, m \leq 1\,000$$$, $$$1 \leq q \leq 10^5$$$) — the dimensions of the initial matrix and the number of queries. Each of the next $$$n$$$ lines contains $$$m$$$ characters $$$c_{ij}$$$ ($$$0 \leq c_{ij} \leq 1$$$) — the characters in the matrix... | standard output | standard input | PyPy 3 | Python | 2,500 | train_076.jsonl | 073eaab86ac4edce005bf25ac6dc9c38 | 256 megabytes | ["2 2 5\n10\n11\n1 1 8 8\n2 4 5 6\n1 2 7 8\n3 3 6 8\n5 6 7 8", "2 3 7\n100\n101\n4 12 5 17\n5 4 9 4\n1 4 13 18\n12 1 14 9\n3 10 7 18\n3 15 12 17\n8 6 8 12"] | PASSED | from sys import stdin,stdout
n,m,q = map(int, stdin.readline().split())
mat = [[0]*m for i in range(n)]
for i in range(n):
row = stdin.readline().strip()
for j,c in enumerate(row):
mat[i][j] = 1 if c == '1' else -1
#print(mat)
def get(a,b):
if a < 0 or b < 0:
return 0
x = a^b
ans... | 1561710000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3 1", "11 2 0 0"] | 607dd33e61f57caced7b61ca8001e871 | NoteConsider a string t = t1t2... t|t|, where ti denotes the i-th character of the string, and |t| denotes the length of the string.Then t[i... j] (1 ≤ i ≤ j ≤ |t|) represents the string titi + 1... tj (substring of t from position i to position j inclusive). | You are given three strings (s1, s2, s3). For each integer l (1 ≤ l ≤ min(|s1|, |s2|, |s3|) you need to find how many triples (i1, i2, i3) exist such that three strings sk[ik... ik + l - 1] (k = 1, 2, 3) are pairwise equal. Print all found numbers modulo 1000000007 (109 + 7).See notes if you are not sure about some of ... | You need to output min(|s1|, |s2|, |s3|) numbers separated by spaces — answers for the problem modulo 1000000007 (109 + 7). | First three lines contain three non-empty input strings. The sum of lengths of all strings is no more than 3·105. All strings consist only of lowercase English letters. | standard output | standard input | PyPy 2 | Python | 2,400 | train_055.jsonl | 13680e9d743be50cd1953498f8dc91c4 | 256 megabytes | ["abc\nbc\ncbc", "abacaba\nabac\nabcd"] | PASSED |
MOD = 1000000007
oo = int(2e9)
class Node:
def __init__(self, p, l = oo):
self.spos = p
self.slink = 0
self.length = l
self.next_node = [0 for _ in range(28)]
#Ukkonen
class SuffixTree:
def __init__(self, s):
self.nodes = [Node(0)]
self.s = []
self.po... | 1406480400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1\n-1\n3\n3"] | 41d791867f27a57b50eebaad29754520 | NoteIn the first regiment we can move once the second or the third mole.We can't make the second regiment compact.In the third regiment, from the last 3 moles we can move once one and twice another one.In the fourth regiment, we can move twice the first mole and once the third mole. | Captain Marmot wants to prepare a huge and important battle against his enemy, Captain Snake. For this battle he has n regiments, each consisting of 4 moles.Initially, each mole i (1 ≤ i ≤ 4n) is placed at some position (xi, yi) in the Cartesian plane. Captain Marmot wants to move some moles to make the regiments compa... | Print n lines to the standard output. If the regiment i can be made compact, the i-th line should contain one integer, the minimal number of required moves. Otherwise, on the i-th line print "-1" (without quotes). | The first line contains one integer n (1 ≤ n ≤ 100), the number of regiments. The next 4n lines contain 4 integers xi, yi, ai, bi ( - 104 ≤ xi, yi, ai, bi ≤ 104). | standard output | standard input | Python 2 | Python | 2,000 | train_010.jsonl | 86c67b2f8b0861d5a51142640f45a880 | 256 megabytes | ["4\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-2 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n-1 1 0 0\n2 2 0 1\n-1 0 0 -2\n3 0 0 -2\n-1 1 -2 0"] | PASSED | n = int(raw_input().strip())
ans = [4*4] * n
for i in range(4*n):
if i%4 == 0: coords = [[] for _ in range(4)]
x,y,a,b = map(int, raw_input().strip().split())
coords[i%4] += [complex(x,y)]
for _ in range(3):
x, y = a - (y - b), b + (x - a)
coords[i%4] += [complex(x,y)]
if i%4 == 3:... | 1412609400 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["2", "-1", "6", "7237"] | 42d0350a0a18760ce6d0d7a4d65135ec | NoteIn first sample test, buying one card is not enough: for example, if you buy a card with length 100, you can't jump to any cell whose index is not a multiple of 100. The best way is to buy first and second card, that will make you be able to jump to any cell.In the second sample test, even if you buy all cards, you... | Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0.There are also n cards, each card has 2 attributes: length li and cost ci. If she pays ci dollars then she can apply i-th card. After apply... | If it is impossible to buy some cards and become able to jump to any cell, output -1. Otherwise output the minimal cost of buying such set of cards. | The first line contains an integer n (1 ≤ n ≤ 300), number of cards. The second line contains n numbers li (1 ≤ li ≤ 109), the jump lengths of cards. The third line contains n numbers ci (1 ≤ ci ≤ 105), the costs of cards. | standard output | standard input | Python 2 | Python | 1,900 | train_042.jsonl | bcc042319447dc20ed76302950868889 | 256 megabytes | ["3\n100 99 9900\n1 1 1", "5\n10 20 30 40 50\n1 1 1 1 1", "7\n15015 10010 6006 4290 2730 2310 1\n1 1 1 1 1 1 10", "8\n4264 4921 6321 6984 2316 8432 6120 1026\n4264 4921 6321 6984 2316 8432 6120 1026"] | PASSED | #!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys
import math
import random
import operator
from fractions import Fraction, gcd
from decimal import Decimal, getcontext
from itertools import product, permutations, combinations
getcontext().prec = 100
def gcd(a, b):
while b:
a, b = b, a % b
return ... | 1422894600 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 секунда | ["1", "6"] | fa897b774525f038dc2d1b65c4ceda28 | ПримечаниеВ первом примере всего один вариант для выбора состава, который удовлетворяет описанным условиям, поэтому ответ 1.Во втором примере подходят следующие игровые сочетания (в порядке вратарь-защитник-защитник-нападающий-нападающий-нападающий): 16 20 12 13 21 11 16 20 12 13 11 10 16 20 19 13 21 11 16 20 19 13... | Завтра у хоккейной команды, которой руководит Евгений, важный матч. Евгению нужно выбрать шесть игроков, которые выйдут на лед в стартовом составе: один вратарь, два защитника и три нападающих.Так как это стартовый состав, Евгения больше волнует, насколько красива будет команда на льду, чем способности игроков. А именн... | Выведите одно целое число — количество возможных стартовых составов. | Первая строка содержит три целых числа g, d и f (1 ≤ g ≤ 1 000, 1 ≤ d ≤ 1 000, 1 ≤ f ≤ 1 000) — число вратарей, защитников и нападающих в команде Евгения. Вторая строка содержит g целых чисел, каждое в пределах от 1 до 100 000 — номера вратарей. Третья строка содержит d целых чисел, каждое в пределах от 1 до 100 000 —... | стандартный вывод | стандартный ввод | Python 3 | Python | 1,700 | train_062.jsonl | 2dbc5c24d5a709ce39e645505f0c4d83 | 256 мегабайт | ["1 2 3\n15\n10 19\n20 11 13", "2 3 4\n16 40\n20 12 19\n13 21 11 10"] | PASSED | import sys
import math
import random
import time
def func_cnk(keepers, defenders, attackers, flag):
if flag == 'kpr':
kpr = 1
defs = math.factorial(defenders) // math.factorial(2) // math.factorial(defenders - 2)
atts = math.factorial(attackers) // math.factorial(3) // math.factorial(attack... | 1520004900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nNO"] | 4f3bec9c36d0ac2fdb8041469133458c | NoteConsider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from... | A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the le... | For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise. | The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed t... | standard output | standard input | Python 2 | Python | 1,500 | train_024.jsonl | c43c5f8c4ba474f44e404563f71364e4 | 256 megabytes | ["2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#"] | PASSED | import sys
def check(coor1, coor2):
dx = coor1[0] - coor2[0]
dy = coor1[1] - coor2[1]
if dx % 2 != 0 or dy % 2 != 0 :
return False
if ((dx/2)-(dy/2) )% 2==0 and dx/2%2 == 0:
return True
return False
def solve(data):
horse = []
for y in xrange(8):
for x in x... | 1384443000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2", "Impossible", "3"] | 12b64f77fc9dd44a7e0287ff0a716a6a | NoteLet's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?". | Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split!Fangy did not like it... | On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. | The first line contains an integer n, which is the size of one message (2 ≤ n ≤ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. | standard output | standard input | Python 2 | Python | 1,600 | train_035.jsonl | 475cd15ab57f6076fd4f6e6aa22ca057 | 256 megabytes | ["25\nHello. I am a little walrus.", "2\nHow are you?", "19\nHello! Do you like fish? Why?"] | PASSED | n = int(raw_input())
a = map(len, (" " + raw_input()).replace('?', '.').replace('!', '.')[:-1].split('.'))
res = 0
t = -1
for i in a:
if i > n:
print "Impossible"
exit()
if t + i + 1 <= n:
t += i + 1
else:
res += 1
t = i
if t != 0:
res += 1
print res | 1301155200 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["3", "4"] | 98348af1203460b3f69239d3e8f635b9 | NoteIn the first sample, if we rearrange elements of the sequence as - 1, 2, 1, the whole sequence ai would be Fibonacci-ish.In the second sample, the optimal way to rearrange elements is , , , , 28. | Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if the sequence consists of at least two elements f0 and f1 are arbitrary fn + 2 = fn + 1 + fn for all n ≥ 0. You are given some sequence of integers a1, a2, ..., an. Your task is rearrange elements... | Print the length of the longest possible Fibonacci-ish prefix of the given sequence after rearrangement. | The first line of the input contains a single integer n (2 ≤ n ≤ 1000) — the length of the sequence ai. The second line contains n integers a1, a2, ..., an (|ai| ≤ 109). | standard output | standard input | Python 3 | Python | 2,000 | train_003.jsonl | 11bb6e8a96c3a8748f736fe3943ef0a8 | 512 megabytes | ["3\n1 2 -1", "5\n28 35 7 14 21"] | PASSED | #!/usr/bin/env python3
n = int(input())
a = [int(x) for x in input().split()]
sorted_a = sorted(a)
dict_a = {}
for x in a:
if not x in dict_a:
dict_a[x] = 1
else:
dict_a[x] += 1
sorted_uniq_a = sorted(dict_a.keys())
max_fib_prefix = [a[0], a[1]]
for i in range(0, len(sorted_uniq_a)):
for... | 1456506900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2", "2"] | 875e7048b7a254992b9f62b9365fcf9b | NoteLet us remind you that a tree is a connected graph on n vertices and n - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if i... | Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the verti... | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most m consecutive vertices with cats. | The first line contains two integers, n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ n) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains n integers a1, a2, ..., an, where each ai either equals to 0 (then vertex i has no cat), or equals to 1... | standard output | standard input | PyPy 3 | Python | 1,500 | train_000.jsonl | 1f978826abaf13952a87551a910eda11 | 256 megabytes | ["4 1\n1 1 0 0\n1 2\n1 3\n1 4", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"] | PASSED | import sys
import time
def input(): return sys.stdin.readline().strip()
def iinput(): return int(input())
def rinput(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1e9)+7
n, m = rinput()
a = get_list()
g = [[] f... | 1442939400 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["1 2 3", "6 1 3 4 2 5"] | 13d7f6127a7fe945e19d461b584c6228 | NoteThis is the picture with the polygonal line from the $$$1$$$ test: As we see, this polygonal line is non-self-intersecting and winding, because the turn in point $$$2$$$ is left.This is the picture with the polygonal line from the $$$2$$$ test: | Vasya has $$$n$$$ different points $$$A_1, A_2, \ldots A_n$$$ on the plane. No three of them lie on the same line He wants to place them in some order $$$A_{p_1}, A_{p_2}, \ldots, A_{p_n}$$$, where $$$p_1, p_2, \ldots, p_n$$$ — some permutation of integers from $$$1$$$ to $$$n$$$.After doing so, he will draw oriented p... | If the satisfying permutation doesn't exists, print $$$-1$$$. In the other case, print $$$n$$$ numbers $$$p_1, p_2, \ldots, p_n$$$ — the permutation which was found ($$$1 \leq p_i \leq n$$$ and all $$$p_1, p_2, \ldots, p_n$$$ are different). If there exists more than one solution, you can find any. | The first line contains one integer $$$n$$$ — the number of points ($$$3 \leq n \leq 2000$$$). Next $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$, divided by space — coordinates of the point $$$A_i$$$ on the plane ($$$-10^9 \leq x_i, y_i \leq 10^9$$$). The last line contains a string $$$s$$$ consisting of... | standard output | standard input | PyPy 2 | Python | 2,600 | train_079.jsonl | 5d228bc096bb83158df9825d92839c0f | 256 megabytes | ["3\n1 1\n3 1\n1 3\nL", "6\n1 0\n0 1\n0 2\n-1 0\n-1 -1\n2 1\nRLLR"] | PASSED | n = int(raw_input())
pts = [map(int, raw_input().split()) for __ in xrange(n)]
s = raw_input().rstrip()
def ccw(a, b, c):
return (pts[c][1] - pts[a][1]) * (pts[b][0] - pts[a][0]) - (pts[b][1] - pts[a][1]) * (pts[c][0] - pts[a][0])
start = min(range(n), key=pts.__getitem__)
unused = set(range(n))
unused.remove(start)... | 1557671700 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["16", "1", "2", "2", "1"] | 6156ef296f6d512887d10a0624ad4a7b | null | You are given a rooted tree of $$$2^n - 1$$$ vertices. Every vertex of this tree has either $$$0$$$ children, or $$$2$$$ children. All leaves of this tree have the same distance from the root, and for every non-leaf vertex, one of its children is the left one, and the other child is the right one. Formally, you are giv... | Print one integer — the number of different strings that can be obtained as the preorder string of the given tree, if you can apply any number of operations described in the statement. Since it can be very large, print it modulo $$$998244353$$$. | The first line contains one integer $$$n$$$ ($$$2 \le n \le 18$$$). The second line contains a sequence of $$$2^n-1$$$ characters $$$s_1, s_2, \dots, s_{2^n-1}$$$. Each character is either A or B. The characters are not separated by spaces or anything else. | standard output | standard input | PyPy 3-64 | Python | 2,100 | train_087.jsonl | 68547facb61a95a56f008088a07eb26c | 512 megabytes | ["4\nBAAAAAAAABBABAB", "2\nBAA", "2\nABA", "2\nAAB", "2\nAAA"] | PASSED | from collections import deque
import sys
from sys import stdin, stdout
import math
import random
sys.setrecursionlimit(10**5)
answer_li = []
INF = float("inf")
mod = 998244353
read = stdin.readline
def ir(): return int(read())
def mir(): return map(int, read().strip().split())
def lmir(): return lis... | 1650638100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["YES\n001\n001\n110", "NO"] | 8adebeaed713b7e90c68553127d17b19 | null | Given three numbers $$$n, a, b$$$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $$$a$$$, and the number of components in its complement is $$$b$$$. The matrix must be symmetric, and all digits on the main diagonal must be zeroes.In an undirected graph ... | If there is no graph that satisfies these constraints on a single line, print "NO" (without quotes). Otherwise, on the first line, print "YES"(without quotes). In each of the next $$$n$$$ lines, output $$$n$$$ digits such that $$$j$$$-th digit of $$$i$$$-th line must be $$$1$$$ if and only if there is an edge between v... | In a single line, three numbers are given $$$n, a, b \,(1 \le n \le 1000, 1 \le a, b \le n)$$$: is the number of vertexes of the graph, the required number of connectivity components in it, and the required amount of the connectivity component in it's complement. | standard output | standard input | Python 3 | Python | 1,700 | train_029.jsonl | a55ece13fa24b0b2162e5bcbaa81ab1d | 256 megabytes | ["3 1 2", "3 3 3"] | PASSED |
from collections import defaultdict
n,a,b = map(int,input().split())
hash = defaultdict(list)
# debug
# def dfs(n):
#
#
# bool[n] = True
# for i in hash[n]:
# if bool[i] == False:
# dfs(i)
if a == 1 and b == 1:
if n == 2 or n == 3:
print('NO')
exit()
if a == 1 o... | 1528625100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["YES\nYES\nNO\nNO\nYES\nNO"] | a6c6b2a66ba51249fdc5d4188ca09e3b | NoteIn the first test case, the permutation $$$[1]$$$ satisfies the array $$$c$$$.In the second test case, the permutation $$$[2,1]$$$ satisfies the array $$$c$$$.In the fifth test case, the permutation $$$[5, 1, 2, 4, 6, 3]$$$ satisfies the array $$$c$$$. Let's see why this is true. The zeroth cyclic shift of $$$p$$$... | Shinju loves permutations very much! Today, she has borrowed a permutation $$$p$$$ from Juju to play with.The $$$i$$$-th cyclic shift of a permutation $$$p$$$ is a transformation on the permutation such that $$$p = [p_1, p_2, \ldots, p_n] $$$ will now become $$$ p = [p_{n-i+1}, \ldots, p_n, p_1,p_2, \ldots, p_{n-i}]$$$... | For each test case, print "YES" if there is a permutation $$$p$$$ exists that satisfies the array $$$c$$$, and "NO" otherwise. 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 input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 5 \cdot 10^3$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$c_1,c_2,\ldots,... | standard output | standard input | Python 3 | Python | 1,700 | train_095.jsonl | eff6df552aeb789ea076eecdb4f05fe8 | 256 megabytes | ["6\n\n1\n\n1\n\n2\n\n1 2\n\n2\n\n2 2\n\n6\n\n1 2 4 6 3 5\n\n6\n\n2 3 1 2 3 4\n\n3\n\n3 2 1"] | PASSED | a,b,c=input,int,range
for _ in c(b(a())):n=b(a());m=list(map(b,a().split()));print("YNEOS"[m.count(1)!= 1 or m[0]>m[-1]+1 or any(m[i+1]-m[i]>1 for i in range(n-1))::2]) | 1648391700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\nYES\nNO\nYES\nNO"] | 48151011c3d380ab303ae38d0804176a | NoteThe first test case is explained in the statement.In the second test case both $$$s_1$$$ and $$$s_2$$$ are empty and $$$p'=$$$ "threetwoone" is $$$p$$$ shuffled.In the third test case the hash could not be obtained from the password.In the fourth test case $$$s_1=$$$ "n", $$$s_2$$$ is empty and $$$p'=$$$ "one" is $... | Polycarp has built his own web service. Being a modern web service it includes login feature. And that always implies password security problems.Polycarp decided to store the hash of the password, generated by the following algorithm: take the password $$$p$$$, consisting of lowercase Latin letters, and shuffle the le... | For each test case print the answer to it — "YES" if the given hash $$$h$$$ could be obtained from the given password $$$p$$$ or "NO" otherwise. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains a non-empty string $$$p$$$, consisting of lowercase Latin letters. The length of $$$p$$$ does not exceed $$$100$$$. The second line of each test case contains a non-empty string $$$h... | standard output | standard input | PyPy 2 | Python | 1,000 | train_009.jsonl | c6f603b595ff5f95fc7f9f71cf147aaf | 256 megabytes | ["5\nabacaba\nzyxaabcaabkjh\nonetwothree\nthreetwoone\none\nzzonneyy\none\nnone\ntwenty\nten"] | PASSED | t = input()
for _ in xrange(t):
p = raw_input()
h = raw_input()
n = len(p)
m = len(h)
ans = False
low = 0
p = ''.join(sorted(p))
while low+n<=m:
temp = h[low:low+n]
temp = ''.join(sorted(temp))
if p == temp:
ans = True
break
low +=... | 1576766100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["4\n3", "8\n9\n7\n6\n9"] | 740d2aba32f69b8cfe8f7cb624621a63 | NoteIn the first example:In the first query there are $$$4$$$ arrays that are $$$5$$$-similar to $$$[2,4]$$$: $$$[1,4],[3,4],[2,3],[2,5]$$$.In the second query there are $$$3$$$ arrays that are $$$5$$$-similar to $$$[4,5]$$$: $$$[1,5],[2,5],[3,5]$$$. | Given a positive integer $$$k$$$, two arrays are called $$$k$$$-similar if: they are strictly increasing; they have the same length; all their elements are positive integers between $$$1$$$ and $$$k$$$ (inclusive); they differ in exactly one position. You are given an integer $$$k$$$, a strictly increasing array $$... | Print $$$q$$$ lines. The $$$i$$$-th of them should contain the answer to the $$$i$$$-th query. | The first line contains three integers $$$n$$$, $$$q$$$ and $$$k$$$ ($$$1\leq n, q \leq 10^5$$$, $$$n\leq k \leq 10^9$$$) — the length of array $$$a$$$, the number of queries and number $$$k$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots,a_n$$$ ($$$1 \leq a_i \leq k$$$). This array is strictly increa... | standard output | standard input | PyPy 3-64 | Python | 1,200 | train_092.jsonl | 4f7ad7291bece73019a6d44146bd4ca4 | 256 megabytes | ["4 2 5\n1 2 4 5\n2 3\n3 4", "6 5 10\n2 4 6 7 8 9\n1 4\n1 2\n3 5\n1 6\n5 5"] | PASSED | import sys
import math
def prime_generator(nr_elemente_prime):
#print("pornire")
vector_prime=[-1]*nr_elemente_prime
vector_rasp=[0]*nr_elemente_prime
vector_prime[1]=1
vector_rasp[1]=1
#primes sieve
contor=2
for i in range(2,nr_elemente_prime):
if vector_prime[i]==-1:
vector_pr... | 1613141400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1\n2\n9\n10\n26"] | ea011f93837fdf985f7eaa7a43e22cc8 | NoteExplanations for the two first test cases of the example: if $$$n = 4$$$, then for every integer $$$x$$$ such that $$$1 \le x \le n$$$, $$$\dfrac{x}{f(f(x))} = 1$$$; if $$$n = 37$$$, then for some integers $$$x$$$ such that $$$1 \le x \le n$$$, $$$\dfrac{x}{f(f(x))} = 1$$$ (for example, if $$$x = 23$$$, $$$f(f(x)... | Let's define a function $$$f(x)$$$ ($$$x$$$ is a positive integer) as follows: write all digits of the decimal representation of $$$x$$$ backwards, then get rid of the leading zeroes. For example, $$$f(321) = 123$$$, $$$f(120) = 21$$$, $$$f(1000000) = 1$$$, $$$f(111) = 111$$$.Let's define another function $$$g(x) = \df... | For each test case, print one integer — the number of different values of the function $$$g(x)$$$, if $$$x$$$ can be any integer from $$$[1, n]$$$. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Each test case consists of one line containing one integer $$$n$$$ ($$$1 \le n < 10^{100}$$$). This integer is given without leading zeroes. | standard output | standard input | Python 3 | Python | null | train_020.jsonl | b1705e42199181a59f2604e7ee326801 | 256 megabytes | ["5\n4\n37\n998244353\n1000000007\n12345678901337426966631415"] | PASSED | from sys import stdin, stdout
readline, writeline = stdin.readline, stdout.write
def iint():
return int(readline().strip())
for _ in range(iint()):
n = readline().strip()
writeline("{}\n".format(len(n)))
| 1606746900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
6.5 seconds | ["0\n0\n1\n2\n5\n1\n5"] | a4f03259518029b38d71ed4c41209677 | null | A triple of points $$$i$$$, $$$j$$$ and $$$k$$$ on a coordinate line is called beautiful if $$$i < j < k$$$ and $$$k - i \le d$$$.You are given a set of points on a coordinate line, initially empty. You have to process queries of three types: add a point; remove a point; calculate the number of beautiful tripl... | For each query, print one integer — the number of beautiful triples after processing the respective query. | The first line contains two integers $$$q$$$ and $$$d$$$ ($$$1 \le q, d \le 2 \cdot 10^5$$$) — the number of queries and the parameter for defining if a triple is beautiful, respectively. The second line contains $$$q$$$ integers $$$a_1, a_2, \dots, a_q$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$) denoting the queries. The in... | standard output | standard input | PyPy 3-64 | Python | 2,500 | train_098.jsonl | 4cee4a89a61a89075d2bcf77539ddcc8 | 512 megabytes | ["7 5\n8 5 3 2 1 5 6"] | PASSED |
###############################
class lazy_segtree():
def update(self,k):self.d[k]=self.op(self.d[2*k],self.d[2*k+1])
def all_apply(self,k,f):
self.d[k]=self.mapping(f,self.d[k])
if (k<self.size):self.lz[k]=self.composition(f,self.lz[k])
def push(self,k):
self.all_apply(2*k,self... | 1657290900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["-100 1\n1 1 1 -1"] | d5e09a8fb7eeeba9a41daa2b565866ba | NoteFor the first door Naruto can use energies $$$[-100, 1]$$$. The required equality does indeed hold: $$$1 \cdot (-100) + 100 \cdot 1 = 0$$$.For the second door Naruto can use, for example, energies $$$[1, 1, 1, -1]$$$. The required equality also holds: $$$1 \cdot 1 + 2 \cdot 1 + 3 \cdot 1 + 6 \cdot (-1) = 0$$$. | Naruto has sneaked into the Orochimaru's lair and is now looking for Sasuke. There are $$$T$$$ rooms there. Every room has a door into it, each door can be described by the number $$$n$$$ of seals on it and their integer energies $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$. All energies $$$a_i$$$ are nonzero and do not exceed... | For each door print a space separated sequence of nonzero integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$|b_{i}| \leq 100$$$, $$$b_{i} \neq 0$$$) denoting the seals that can open the door. If there are multiple valid answers, print any. It can be proven that at least one answer always exists. | The first line contains the only integer $$$T$$$ ($$$1 \leq T \leq 1000$$$) standing for the number of rooms in the Orochimaru's lair. The other lines contain descriptions of the doors. Each description starts with the line containing the only even integer $$$n$$$ ($$$2 \leq n \leq 100$$$) denoting the number of seals.... | standard output | standard input | PyPy 3 | Python | 800 | train_007.jsonl | bc963f8d964bd813df4b93b899aabd32 | 256 megabytes | ["2\n2\n1 100\n4\n1 2 3 6"] | PASSED | import os
import heapq
import sys,threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
def power(x, p,m):
res = 1
while p:
if p ... | 1603623900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["aa.b\nc.hg", "a!aa", "aa|a"] | 0f04f757dc734208d803ee0f6be5d1f0 | null | BerOilGasDiamondBank has branches in n cities, at that n is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: the calendar should consist of exactly n / 2 lines of strictly equal length, each of which contains exactly two names and exactly one sep... | Print n / 2 lines of similar length which are the required calendar. Every line should contain exactly two words and exactly one separator between them. If there are several solutions, print the lexicographically minimal one. The lexicographical comparison of lines is realized by the "<" operator in the modern progr... | The first line contains an integer n (1 ≤ n ≤ 104, n is even) which is the number of branches. Then follow n lines which are the names of the cities. All the names consist of lowercase Latin letters; their lengths are no less than 1 and no more than 10 symbols. The next line contains a single symbol d (d has an ASCII-c... | standard output | standard input | Python 3 | Python | 2,000 | train_011.jsonl | 6cb1e2e7ed501c72f2001529ed268681 | 256 megabytes | ["4\nb\naa\nhg\nc\n.", "2\naa\na\n!", "2\naa\na\n|"] | PASSED | n = int(input())
a = []
for i in range(10):
a.append([])
res = 0
for i in range(n):
s = input()
a[len(s)-1].append(s)
res += len(s)
res //= (n // 2)
c = input()
b = []
for i in range(10):
a[i].sort()
b.append(0)
for i in range(n // 2):
cur = 'zzzzzzzzzzzzz'
s = ''
for j in range(10):... | 1296489600 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
5 seconds | ["2\n1110\n1011", "1\n101001", "2\n111100\n110110"] | a8cc83b982c1d017b68a61adcb38d1a7 | null | There are $$$n$$$ cities in Berland. Some pairs of cities are connected by roads. All roads are bidirectional. Each road connects two different cities. There is at most one road between a pair of cities. The cities are numbered from $$$1$$$ to $$$n$$$.It is known that, from the capital (the city with the number $$$1$$$... | Print $$$t$$$ ($$$1 \le t \le k$$$) — the number of ways to choose a set of roads for repair. Recall that you need to find $$$k$$$ different options; if there are fewer than $$$k$$$ of them, then you need to find all possible different valid options. In the following $$$t$$$ lines, print the options, one per line. Prin... | The first line of the input contains integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \le n \le 2\cdot10^5, n-1 \le m \le 2\cdot10^5, 1 \le k \le 2\cdot10^5$$$), where $$$n$$$ is the number of cities in the country, $$$m$$$ is the number of roads and $$$k$$$ is the number of options to choose a set of roads for repair. It i... | standard output | standard input | Python 3 | Python | 2,100 | train_040.jsonl | f918aa05780ba54adf1cd0f00e401c08 | 256 megabytes | ["4 4 3\n1 2\n2 3\n1 4\n4 3", "4 6 3\n1 2\n2 3\n1 4\n4 3\n2 4\n1 3", "5 6 2\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5"] | PASSED | from math import inf
nmk = list(map(int, input().split(' ')))
n = nmk[0]
m = nmk[1]
k = nmk[2]
a = []
for i in range(m):
a.append(list(map(int, input().split(' '))))
smej = [[] for j in range(n)]
nums = {}
t = 0
for i in a:
nums.update({(i[0], i[1]):t})
t += 1
smej[i[0]-1].append(i[1]-1)
smej[i[1]-1].append(i... | 1531150500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.