prob_desc_time_limit
stringclasses
21 values
prob_desc_sample_outputs
stringlengths
5
329
src_uid
stringlengths
32
32
prob_desc_notes
stringlengths
31
2.84k
prob_desc_description
stringlengths
121
3.8k
prob_desc_output_spec
stringlengths
17
1.16k
prob_desc_input_spec
stringlengths
38
2.42k
prob_desc_output_to
stringclasses
3 values
prob_desc_input_from
stringclasses
3 values
lang
stringclasses
5 values
lang_cluster
stringclasses
1 value
difficulty
int64
-1
3.5k
file_name
stringclasses
111 values
code_uid
stringlengths
32
32
prob_desc_memory_limit
stringclasses
11 values
prob_desc_sample_inputs
stringlengths
5
802
exec_outcome
stringclasses
1 value
source_code
stringlengths
29
58.4k
prob_desc_created_at
stringlengths
10
10
tags
listlengths
1
5
hidden_unit_tests
stringclasses
1 value
labels
listlengths
8
8
1 second
["4\n2 1 1 1\n1 1 1 2\n1 2 2 2\n2 2 2 1", "4\n2 2 1 2\n1 2 2 2\n1 2 1 3\n1 3 1 2"]
3cc8a5fcd612e9328e5d2c8d824d792a
NoteConsider the first example. The current state of the table:00 1001 11The first operation. The cell $$$(2, 1)$$$ contains the string $$$01$$$. Applying the operation to cells $$$(2, 1)$$$ and $$$(1, 1)$$$, we move the $$$1$$$ from the end of the string $$$01$$$ to the beginning of the string $$$00$$$ and get the st...
Egor came up with a new chips puzzle and suggests you to play.The puzzle has the form of a table with $$$n$$$ rows and $$$m$$$ columns, each cell can contain several black or white chips placed in a row. Thus, the state of the cell can be described by a string consisting of characters '0' (a white chip) and '1' (a blac...
On the first line print $$$q$$$ — the number of operations used. You should find such a solution that $$$0 \leq q \leq 4 \cdot s$$$. In each the next $$$q$$$ lines print 4 integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$. On the $$$i$$$-th line you should print the description of the $$$i$$$-th operation. These int...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n, m \leq 300$$$) — the number of rows and columns of the table, respectively. The following $$$n$$$ lines describe the initial state of the table in the following format: each line contains $$$m$$$ non-empty strings consisting of zeros and ones. In th...
standard output
standard input
PyPy 3
Python
2,400
train_035.jsonl
349b29b035c022afb562388b821d7008
256 megabytes
["2 2\n00 10\n01 11\n10 01\n10 01", "2 3\n0 0 0\n011 1 0\n0 0 1\n011 0 0"]
PASSED
def fill(oper, curr, upper, second, n, m): for i in range(n): for j in range(m): for s in reversed(curr[i][j]): if s == '0': if i == 0: dest = (j + 1) % m oper.append((0, j, 0, dest)) uppe...
1539880500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2", "0", "797922655"]
907f7db88fb16178d6be57bea12f90a2
NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$.
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$...
Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$.
The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w...
standard output
standard input
Python 2
Python
1,400
train_002.jsonl
600fdd1ce561721193160d86be5d7f6d
256 megabytes
["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"]
PASSED
R = lambda: map(int, raw_input().split()) r, c = R() ret = [[-1] * c for i in range(r)] for i, x in zip(range(r), R()): for j in range(x): ret[i][j] = 1 if x != c: ret[i][x] = 0 flag = 1 for i, x in zip(range(c), R()): if flag: for j in range(x): if ret[j][i] == 0: ...
1569762300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["4\n7\n11", "5\n4\n1\n5", "82\n125\n9\n191\n62\n63\n97"]
461378e9179c9de454674ea9dc49c56c
NoteIn the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to $$$4$$$. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is $$$7$$$. In the third question Vasya con...
Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up $$$q$$$ questions about this song. Each question is about a subsegment of the song starting from the $$$l$$$-th letter to the $$$r$$$-th letter. Vasya considers a substring made up from c...
Print $$$q$$$ lines: for each question print the length of the string obtained by Vasya.
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1\leq n\leq 100\,000$$$, $$$1\leq q \leq 100\,000$$$) — the length of the song and the number of questions. The second line contains one string $$$s$$$ — the song, consisting of $$$n$$$ lowercase letters of English letters. Vasya's questions are contained in...
standard output
standard input
PyPy 3-64
Python
800
train_096.jsonl
1340e6b65325cc0ce1f2806a74ebaf39
256 megabytes
["7 3\nabacaba\n1 3\n2 5\n1 7", "7 4\nabbabaa\n1 3\n5 7\n6 6\n2 4", "13 7\nsonoshikumiwo\n1 5\n2 10\n7 7\n1 13\n4 8\n2 5\n3 9"]
PASSED
n, t = map(int, input().split()) ui = input() req = [0 for z in range(n + 1)] for i, res in enumerate(ui): req[i + 1] = req[i] + (ord(res) - 96) for q in range(t): l, r = map(int, input().split()) print(req[r] - req[l - 1])
1624183500
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["4\n0\n3"]
e58fcbf5c49dc5666b1c65a0d5c76b6e
NoteIn the first test case, the original array is $$$[7, 6, 5, 4]$$$. In the second test case, the original array is $$$[4, 7, 6, 5]$$$.In the third test case, the original array is $$$[3, 1, 2]$$$.
This is the hard version of the problem. The difference in the constraints between both versions are 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 perform 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{\le} \boldsymbol{l}} \le r < 2^{17}$$$). The second line contains $$$r - l + 1$$$ space-sepe...
standard output
standard input
PyPy 3-64
Python
2,300
train_095.jsonl
ac7d7fb931eab5a5eeeb50058d3a449b
256 megabytes
["3\n\n4 7\n\n3 2 1 0\n\n4 7\n\n4 7 6 5\n\n1 3\n\n0 2 1"]
PASSED
import sys input = sys.stdin.readline dd = [0] * (2 ** 17 + 1) for _ in range(int(input())): l, r = [int(xx) for xx in input().split()] a = [int(xx) for xx in input().split()] for i in range(r - l + 1): dd[a[i]] = 1 if l % 2 == 0 and r % 2 == 1: if r - l > 1000: g =...
1648391700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["3 3 4 4 4 4 4 4 5 5 5 5 \n1 1"]
dc1dc5e5dd17d19760c772739ce244a7
NoteOne possible sequence of choices for the first testcase where Tina has $$$k=3$$$ buckets of paints is as follows.Tina paints the seats at positions $$$(1, 2)$$$, $$$(2, 2)$$$, $$$(3, 2)$$$ with pink paint. Rahul chooses the seat at $$$(3, 1)$$$ after which Tina chooses to sit at $$$(1, 3)$$$. Therefore, the distanc...
Rahul and Tina are looking forward to starting their new year at college. As they enter their new classroom, they observe the seats of students are arranged in a $$$n \times m$$$ grid. The seat in row $$$r$$$ and column $$$c$$$ is denoted by $$$(r, c)$$$, and the distance between two seats $$$(a,b)$$$ and $$$(c,d)$$$ i...
For each test case, output $$$n \cdot m$$$ ordered integers — the distance between Rahul and Tina if both of them act optimally for every $$$k \in [0, n \cdot m - 1]$$$.
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 5 \cdot 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$2 \leq n \cdot m \leq 10^5$$$) — the number of rows ...
standard output
standard input
PyPy 3-64
Python
1,300
train_109.jsonl
36b53e049ccb682c7eebf86cd2d41b1c
256 megabytes
["2\n\n4 3\n\n1 2"]
PASSED
def main(): import sys readline=sys.stdin.readline for _ in range(int(readline())): n,m=map(int,readline().split()) ans=[] for a in range(n): for b in range(m): ans.append(max(a+b,a+m-b-1,n-a+m-b-2,n-a-1+b)) print(' '.join(map(str,sorted(ans)))) main()
1642257300
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
2 seconds
["1", "V", "IV", "1111001", "A"]
c619d699e3e5fb42aea839ef6080c86c
NoteYou can find more information about roman numerals here: http://en.wikipedia.org/wiki/Roman_numerals
It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.Recently the Romans declared war on Persia. They dreamed to occupy Armenia. In the recent war, the Romans were badly defeated. Now their senior army general, Philip is capture...
Write a single line that contains integer c in base b. You must omit leading zeros.
The first line contains two integers a and b (2 ≤ a, b ≤ 25). Only b may be replaced by an R which indicates Roman numbering system. The next line contains a single non-negative integer c in base a which may contain leading zeros but its length doesn't exceed 103. It is guaranteed that if we have Roman numerals includ...
standard output
standard input
Python 3
Python
2,000
train_049.jsonl
e595002367f398e053845df76c44662b
256 megabytes
["10 2\n1", "16 R\n5", "5 R\n4", "2 2\n1111001", "12 13\nA"]
PASSED
numbers = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'A':10,'B':11,'C':12,'D':13,'E':14,'F':15,'G':16,'H':17,'I':18,'J':19,'K':20,'L':21,'M':22,'N':23,'O':24,'P':25,'Q':26,'R':27,'S':28,'T':29,'U':30,'V':31,'W':32,'X':33,'Y':34,'Z':35} characters = {0:'0',1:'1',2:'2',3:'3',4:'4',5:'5',6:'6',7:'7',8:'8...
1298390400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES\nYES\nYES\nYES\nNO"]
2515630678babfa39f606d535948abf7
NoteIn the first test case, you can remove all stones without using a superability: $$$[1, 2, 1] \rightarrow [1, 1, 0] \rightarrow [0, 0, 0]$$$.In the second test case, you can apply superability to the second and the third piles and then act like in the first testcase.In the third test case, you can apply superability...
During cleaning the coast, Alice found $$$n$$$ piles of stones. The $$$i$$$-th pile has $$$a_i$$$ stones.Piles $$$i$$$ and $$$i + 1$$$ are neighbouring for all $$$1 \leq i \leq n - 1$$$. If pile $$$i$$$ becomes empty, piles $$$i - 1$$$ and $$$i + 1$$$ doesn't become neighbouring.Alice is too lazy to remove these stones...
For each test case, print YES or NO — is it possible to remove all stones using the superability not more than once or not.
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) — the number of piles. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($...
standard output
standard input
PyPy 3
Python
2,200
train_100.jsonl
51c1acc5694f3f39b47f04c3f0704ac3
256 megabytes
["5\n3\n1 2 1\n3\n1 1 2\n5\n2 2 2 1 3\n5\n2100 1900 1600 3000 1600\n2\n2443 2445"]
PASSED
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) L, R = [0] * (n + 1), [0] * (n + 1) for i in range(n): L[i + 1] = -1 if L[i] < 0 else A[i] - L[i] for i in range(n - 1, -1, -1): R[i] = -1 if R[i + 1] <...
1611066900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["d 2\ns 3\n! 5"]
5e34b8ed812d392799f45c3c3fa1c979
NoteIn the first example, the hidden node is node $$$5$$$. We first ask about the distance between node $$$x$$$ and node $$$2$$$. The answer is $$$3$$$, so node $$$x$$$ is either $$$4$$$ or $$$5$$$. We then ask about the second node in the path from node $$$3$$$ to node $$$x$$$. Note here that node $$$3$$$ is an ances...
This is an interactive problem.You're given a tree consisting of $$$n$$$ nodes, rooted at node $$$1$$$. A tree is a connected graph with no cycles.We chose a hidden node $$$x$$$. In order to find this node, you can ask queries of two types: d $$$u$$$ ($$$1 \le u \le n$$$). We will answer with the distance between nod...
To print the answer, print "! x" (without quotes).
The first line contains the integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of nodes in the tree. Each of the next $$$n-1$$$ lines contains two space-separated integers $$$u$$$ and $$$v$$$ ($$$1 \le u,v \le n$$$) that mean there's an edge between nodes $$$u$$$ and $$$v$$$. It's guaranteed that the given g...
standard output
standard input
Python 3
Python
2,400
train_025.jsonl
36e9cfe7b32f4fd7e3d06d16f15264f6
256 megabytes
["5\n1 2\n1 3\n3 4\n3 5\n3\n5"]
PASSED
def sec(tup): return -tup[1] def do(graph,top,level): if level==0: print("!",top) return None curr=top for i in range(level): curr=graph[curr] print("d",curr) dist=int(input()) if dist==0: print("!",curr) return None newt=top for i in range(lev...
1559570700
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1 second
["No", "Yes", "No"]
8fd51c391728b433cc94923820e908ff
NoteIn the first example the first player is unable to make a turn, so he loses.In the second example first player turns the string into "q", then second player is unable to move, so he loses.
Two people are playing a game with a string $$$s$$$, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A...
If the first player wins, print "Yes". If the second player wins, print "No".
The only line contains the string $$$s$$$, consisting of lowercase latin letters ($$$1 \leq |s| \leq 100\,000$$$), where $$$|s|$$$ means the length of a string $$$s$$$.
standard output
standard input
Python 3
Python
1,200
train_001.jsonl
0ac7e679160fa139a0478a0bbb566a16
256 megabytes
["abacaba", "iiq", "abba"]
PASSED
s = input() n = len(s) a = [] a.append(s[0]) ans = 0 for i in range(1, n): if a: cur = a.pop() if cur == s[i]: ans += 1 continue else: a.append(cur) a.append(s[i]) else: a.append(s[i]) if ans % 2: print('Yes') else: print...
1548167700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["No", "Yes\n4 12 7 31 7 61"]
4033eee4e822b9df57e30297e339c17d
NoteIn the first example no permutation is valid.In the second example the given answer lead to the sequence $$$a_1 = 4$$$, $$$a_2 = 8$$$, $$$a_3 = 15$$$, $$$a_4 = 16$$$, $$$a_5 = 23$$$, $$$a_6 = 42$$$.
Vitya has learned that the answer for The Ultimate Question of Life, the Universe, and Everything is not the integer 54 42, but an increasing integer sequence $$$a_1, \ldots, a_n$$$. In order to not reveal the secret earlier than needed, Vitya encrypted the answer and obtained the sequence $$$b_1, \ldots, b_n$$$ using ...
If there are no valid permutations, print a single line containing "No". Otherwise in the first line print the word "Yes", and in the second line print integers $$$b'_1, \ldots, b'_n$$$ — a valid permutation of integers $$$b_i$$$. The unordered multisets $$$\{b_1, \ldots, b_n\}$$$ and $$$\{b'_1, \ldots, b'_n\}$$$ shoul...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$). The second line contains $$$n$$$ integers $$$b_1, \ldots, b_n$$$ ($$$1 \leq b_i &lt; 2^{60}$$$).
standard output
standard input
PyPy 2
Python
2,200
train_060.jsonl
d3ccd7f0aa8552894cdc24383c30b5e6
256 megabytes
["3\n1 2 3", "6\n4 7 7 12 31 61"]
PASSED
import sys def interleave(c, b, mask): lb, ib, s = len(b), 0, False if ib<lb: yield b[ib] ib, s = 1, True for e in c: yield e s ^= (e&mask)>0 if not s and ib<lb: yield b[ib] ib, s = ib+1, True if ib<lb: yield -1 def calprefix(b): cur = 0 for e in b: cur ^= e yield cur n = int(raw_input()) ...
1525007700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1\n5\n4"]
b89e9598adae3da19903cdbfd225dd3c
NoteIn the first test case we get either $$$a = [1, 2]$$$ or $$$a = [2, 1]$$$ after casting the spell for the first time, and it is impossible to cast it again.
— Hey folks, how do you like this problem?— That'll do it. BThero is a powerful magician. He has got $$$n$$$ piles of candies, the $$$i$$$-th pile initially contains $$$a_i$$$ candies. BThero can cast a copy-paste spell as follows: He chooses two piles $$$(i, j)$$$ such that $$$1 \le i, j \le n$$$ and $$$i \ne j$$$....
For each test case, print one integer — the maximum number of times BThero can cast the spell without losing his magic power.
The first line contains one integer $$$T$$$ ($$$1 \le T \le 500$$$) — the number of test cases. Each test case consists of two lines: the first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 1000$$$, $$$2 \le k \le 10^4$$$); the second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n...
standard output
standard input
Python 3
Python
800
train_006.jsonl
d7aab99a4852170a83d0ff0e7a84e745
256 megabytes
["3\n2 2\n1 1\n3 5\n1 2 3\n3 7\n3 2 2"]
PASSED
x1 = int(input()) for i in range(x1): n,k = map(int,input().split()) l = list(map(int,input().split())) c=0 d=min(l) l.sort() for i in range(1,n): c+=(k-l[i])//d print(c)
1601219100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1\n5 6 7 9 4 2", "6\n7 2 4 6 8 1 3 5", "-1"]
86bf9688b92ced5238009eefd051387d
null
Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct. Nikolay has m cards, distinct numbers from 1 to m are written on...
If there is no answer, print -1. Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th numb...
The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even. The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.
standard output
standard input
Python 3
Python
1,900
train_020.jsonl
50894e6c8f81b1921873a203326db8c7
256 megabytes
["6 2\n5 6 7 9 4 5", "8 6\n7 7 7 7 8 8 8 8", "4 1\n4 2 1 10"]
PASSED
#!/usr/bin/env python3 class CantException(Exception): pass def odd_v(value): return 1 if value % 2 == 1 else -1 change_idx = 1 acceptable = {-1: set(), 1: set()} def change(card_values, oddv, m): global change_idx if acceptable[oddv]: res = acceptable[oddv].pop() card_values.a...
1482057300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES\nYES", "NO\nNO"]
0369c070f4ac9aba4887bae32ad8b85b
NoteLet's look at the first test case of the first sample: At first, all citizens are in the capital. Let's describe one of possible scenarios: a person from city $$$1$$$: he lives in the capital and is in good mood; a person from city $$$4$$$: he visited cities $$$1$$$ and $$$4$$$, his mood was ruined between cit...
Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index.There are $$$n$$$ cities and $$$n−1$$$ undirected roads connecting pairs of cities. Citizens of any city can reach any other city traveling by these roads...
For each test case, print YES, if the collected data is correct, or NO — otherwise. You can print characters in YES or NO in any case.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^5$$$; $$$0 \le m \le 10^9$$$) — the number of cities and citizens. The second line of each test case contains $$$n$$$ integ...
standard output
standard input
Python 3
Python
1,800
train_003.jsonl
4d469d39f9db33f22e52909f52b92a5a
256 megabytes
["2\n7 4\n1 0 1 1 0 1 0\n4 0 0 -1 0 -1 0\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n5 11\n1 2 5 2 1\n-11 -2 -6 -2 -1\n1 2\n1 3\n1 4\n3 5", "2\n4 4\n1 1 1 1\n4 1 -3 -1\n1 2\n1 3\n1 4\n3 13\n3 3 7\n13 1 4\n1 2\n1 3"]
PASSED
import os import sys from io import BytesIO, IOBase import math def dfsVisited (G, node, nodeInfo, V, P): V.add (node) ans = 0 for v in G[node]: if v not in V: ans += dfsVisited (G, v, nodeInfo, V, P) ans += P[node-1] nodeInfo[node-1][0] = ans return ans ...
1596119700
[ "math", "trees" ]
[ 0, 0, 0, 1, 0, 0, 0, 1 ]
2 seconds
["1 2\n3 3", "2 3\n4 6", "1 1\n2 2", "2 7\n8 13"]
23261cfebebe782715646c38992c48a6
NoteIn the first example $$$s[1;2] = 12$$$ and $$$s[3;3] = 5$$$, $$$12+5=17$$$.In the second example $$$s[2;3] = 54$$$ and $$$s[4;6] = 471$$$, $$$54+471=525$$$.In the third example $$$s[1;1] = 2$$$ and $$$s[2;2] = 3$$$, $$$2+3=5$$$.In the fourth example $$$s[2;7] = 218633$$$ and $$$s[8;13] = 757639$$$, $$$218633+757639...
Let's call a positive integer good if there is no digit 0 in its decimal representation.For an array of a good numbers $$$a$$$, one found out that the sum of some two neighboring elements is equal to $$$x$$$ (i.e. $$$x = a_i + a_{i + 1}$$$ for some $$$i$$$). $$$x$$$ had turned out to be a good number as well.Then the e...
In the first line, print two integers $$$l_1$$$, $$$r_1$$$, meaning that the first term of the sum ($$$a_i$$$) is in the string $$$s$$$ from position $$$l_1$$$ to position $$$r_1$$$. In the second line, print two integers $$$l_2$$$, $$$r_2$$$, meaning that the second term of the sum ($$$a_{i + 1}$$$) is in the string $...
The first line contains the string $$$s$$$ ($$$2 \le |s| \le 5 \cdot 10^5$$$). The second line contains an integer $$$x$$$ ($$$2 \le x &lt; 10^{200000}$$$). An additional constraint on the input: the answer always exists, i.e you can always select two adjacent substrings of the string $$$s$$$ so that if you convert the...
standard output
standard input
PyPy 3
Python
3,200
train_090.jsonl
2453a85f89f18fa1a6f787779ff48d24
256 megabytes
["1256133\n17", "9544715561\n525", "239923\n5", "1218633757639\n976272"]
PASSED
import sys s = sys.stdin.readline().strip() x = sys.stdin.readline().strip() ls, lx = len(s), len(x) MOD = 2**31-1 h = [0] * (ls+1) p = [1] * (ls+1) def gh(start, end): return (h[end+1] - h[start] * p[end-start+1]) % MOD def gen_z(s, zx = None, x=None): z = [0]*len(s) l, r, start = 0, -1, 0 ...
1633856700
[ "math", "strings" ]
[ 0, 0, 0, 1, 0, 0, 1, 0 ]
3 seconds
["7\n4\n1"]
6c1d534c1066997eb7e7963b4e783708
NoteIn the first test case, the array $$$a$$$ is not good, but if we take the subsequence $$$[a_1, a_2, a_3, a_4, a_5, a_6, a_8]$$$, then the square can be split as shown in the statement.In the second test case, we can take the subsequence consisting of the last four elements of $$$a$$$ and cut the square with a horiz...
There is a $$$k \times k$$$ grid, where $$$k$$$ is even. The square in row $$$r$$$ and column $$$c$$$ is denoted by $$$(r,c)$$$. Two squares $$$(r_1, c_1)$$$ and $$$(r_2, c_2)$$$ are considered adjacent if $$$\lvert r_1 - r_2 \rvert + \lvert c_1 - c_2 \rvert = 1$$$.An array of adjacent pairs of squares is called strong...
For each test case, output a single integer — the size of the largest strong subsequence of $$$a$$$.
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two space-separated integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$; $$$2 \leq k \leq 50...
standard output
standard input
PyPy 3-64
Python
2,700
train_109.jsonl
fbce098fcc71f106dfe8a865041df174
512 megabytes
["3\n\n8 4\n\n1 2 1 3\n\n2 2 2 3\n\n3 2 3 3\n\n4 2 4 3\n\n1 4 2 4\n\n2 1 3 1\n\n2 2 3 2\n\n4 1 4 2\n\n7 2\n\n1 1 1 2\n\n2 1 2 2\n\n1 1 1 2\n\n1 1 2 1\n\n1 2 2 2\n\n1 1 2 1\n\n1 2 2 2\n\n1 6\n\n3 3 3 4"]
PASSED
import io, os input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline from heapq import heappop, heappush for _ in range(int(input())): q, n = map(int, input().split()) graph = [[[] for j in range(n + 1)] for i in range(n + 1)] for x in range(n + 1): for y in range(n + 1): ...
1642257300
[ "geometry", "graphs" ]
[ 0, 1, 1, 0, 0, 0, 0, 0 ]
1 second
["1", "0"]
1b8596fcbaa42fa334b782b78ad1931b
NoteIn the first test case, Qingshan can only choose $$$x=3$$$ to win, so the answer is $$$1$$$.In the second test case, if Qingshan will choose $$$x=4$$$, Daniel can choose $$$y=1$$$. In the first turn (Qingshan's) Qingshan chooses $$$x'=3$$$ and changes $$$x$$$ to $$$3$$$. In the second turn (Daniel's) Daniel chooses...
On a weekend, Qingshan suggests that she and her friend Daniel go hiking. Unfortunately, they are busy high school students, so they can only go hiking on scratch paper.A permutation $$$p$$$ is written from left to right on the paper. First Qingshan chooses an integer index $$$x$$$ ($$$1\le x\le n$$$) and tells it to D...
Print the number of possible values of $$$x$$$ that Qingshan can choose to make her win.
The first line contains a single integer $$$n$$$ ($$$2\le n\le 10^5$$$) — the length of the permutation. The second line contains $$$n$$$ distinct integers $$$p_1,p_2,\dots,p_n$$$ ($$$1\le p_i\le n$$$) — the permutation.
standard output
standard input
PyPy 3-64
Python
1,900
train_085.jsonl
bcbe05872ccfdfee5211bb0a249738a3
256 megabytes
["5\n1 2 5 4 3", "7\n1 2 4 6 5 3 7"]
PASSED
n = int(input()) a = [int(i) for i in input().split()] r = [] cur = 0 i = 0 while n != i + 1: while n != i + 1 and a[i] < a[i + 1]: i += 1 cur += 1 r.append(cur + 1) cur = 1 while n != i + 1 and a[i] > a[i + 1]: i += 1 cur += 1 r.append(cur) cur = 0...
1615377900
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
2 seconds
["2", "2"]
9ed2a081b65df66629fcf0d4fc0bb02c
NoteConsider the first sample test. Here the string s has two good substrings: "b??" (after we replace the question marks we get "baa"), "???" (after we replace the question marks we get "baa").Let's consider the second sample test. Here the string s has two good substrings: "ab?" ("?" can be replaced by "c"), "b?c" ("...
A string t is called an anagram of the string s, if it is possible to rearrange letters in t so that it is identical to the string s. For example, the string "aab" is an anagram of the string "aba" and the string "aaa" is not.The string t is called a substring of the string s if it can be read starting from some positi...
Print the single number representing the number of good substrings of string s. Two substrings are considered different in their positions of occurrence are different. Thus, if some string occurs several times, then it should be counted the same number of times.
The first line is non-empty string s, consisting of no more than 105 lowercase Latin letters and characters "?". The second line is non-empty string p, consisting of no more than 105 lowercase Latin letters. Please note that the length of the string p can exceed the length of the string s.
standard output
standard input
PyPy 2
Python
1,500
train_015.jsonl
4554a2bd185ee93367daa91e09f62ebb
256 megabytes
["bb??x???\naab", "ab?c\nacb"]
PASSED
s = raw_input() p = raw_input() from collections import Counter dp = Counter(p) def eqp(d): need = 0 p = dp for key in p: if key not in d: need += p[key] continue if d[key] > p[key]: return False if d[key] < p[key]: need += p[ke...
1326899100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["1230", "2750685", "2189"]
c943742fb0720af18058ff0da8a33974
NoteFor the first example the answer is just the sum of numbers from $$$l$$$ to $$$r$$$ which equals to $$$\frac{50 \cdot 51}{2} - \frac{9 \cdot 10}{2} = 1230$$$. This example also explained in the problem statement but for $$$k = 1$$$.For the second example the answer is just the sum of numbers from $$$l$$$ to $$$r$$$...
You are given two integers $$$l$$$ and $$$r$$$ ($$$l \le r$$$). Your task is to calculate the sum of numbers from $$$l$$$ to $$$r$$$ (including $$$l$$$ and $$$r$$$) such that each number contains at most $$$k$$$ different digits, and print this sum modulo $$$998244353$$$.For example, if $$$k = 1$$$ then you have to cal...
Print one integer — the sum of numbers from $$$l$$$ to $$$r$$$ such that each number contains at most $$$k$$$ different digits, modulo $$$998244353$$$.
The only line of the input contains three integers $$$l$$$, $$$r$$$ and $$$k$$$ ($$$1 \le l \le r &lt; 10^{18}, 1 \le k \le 10$$$) — the borders of the segment and the maximum number of different digits.
standard output
standard input
Python 3
Python
2,300
train_033.jsonl
de930c6302e4fe4819684b472e8876c6
256 megabytes
["10 50 2", "1 2345 10", "101 154 2"]
PASSED
MOD = 998244353 def pop_count(x) : ans = 0 while (x > 0) : ans = ans + x % 2 x = x // 2 return ans def check(x, k) : mask = 0 nx = int(x) while (nx > 0) : mask = mask | (1 << (nx % 10)) nx = nx // 10 if (pop_count(mask) <= k) : return x return ...
1540478100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["YES\nNO\nYES\nNO\nYES"]
cbd91ac0fc9e4ca01996791e4c94bd6e
NoteIn the first test case, $$$s[2\ldots 4] = $$$ "010". In this case $$$s_1s_3s_5$$$ ("001000") and $$$s_2s_3s_6$$$ ("001000") are good suitable subsequences, while $$$s_2s_3s_4$$$ ("001000") is not good. $$$s[1\ldots 3] = $$$ "001". No suitable good subsequence exists. $$$s[3\ldots 5] = $$$ "100". Here $$$s_3s_5s...
Hr0d1y has $$$q$$$ queries on a binary string $$$s$$$ of length $$$n$$$. A binary string is a string containing only characters '0' and '1'.A query is described by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \leq l_i \lt r_i \leq n)$$$. For each query, he has to determine whether there exists a good subsequence in $$...
For each test case, output $$$q$$$ lines. The $$$i$$$-th line of the output of each test case should contain "YES" if there exists a good subsequence equal to the substring $$$s[l_i...r_i]$$$, and "NO" otherwise. You may print each letter in any case (upper or lower).
The first line of the input contains a single integer $$$t$$$ ($$$1\leq t \leq 100$$$) — the number of test cases. The description of each test case is as follows. The first line contains two integers $$$n$$$ ($$$2 \leq n \leq 100$$$) and $$$q$$$ ($$$1\leq q \leq 100$$$) — the length of the string and the number of que...
standard output
standard input
PyPy 3
Python
null
train_000.jsonl
7ba1d2c9acbb3e1bbad4c98bdcb8cc79
256 megabytes
["2\n6 3\n001000\n2 4\n1 3\n3 5\n4 2\n1111\n1 4\n2 3"]
PASSED
# Legends Always Come Up with Solution # Author: Manvir Singh import os from io import BytesIO, IOBase import sys from collections import Counter from math import sqrt, pi, ceil, log, inf, gcd, floor def main(): for _ in range(int(input())): n, q = map(int, input().split()) a = input().strip() ...
1605969300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["1\n4"]
6a333044e2ed8f9f4fa44bc16b994418
NoteIn the first test case, the starting and the ending points of the box are $$$(1,2)$$$ and $$$(2,2)$$$ respectively. This is the same as the picture in the statement. Wabbit needs only $$$1$$$ second to move as shown in the picture in the statement.In the second test case, Wabbit can start at the point $$$(2,1)$$$. ...
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point $$$(x_1,y_1)$$$ to the point $$$(x_2,y_2)$$$.He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly $$$1$$$ unit away from the box in the direction of one of two coordina...
For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from $$$(x_1,y_1)$$$ to $$$(x_2,y_2)$$$.
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$: the number of test cases. The description of the test cases follows. Each of the next $$$t$$$ lines contains four space-separated integers $$$x_1, y_1, x_2, y_2$$$ $$$(1 \leq x_1, y_1, x_2, y_2 \leq 10^9...
standard output
standard input
Python 3
Python
800
train_010.jsonl
4c96ca28274b9c6a937cefa475333b14
256 megabytes
["2\n1 2 2 2\n1 1 2 2"]
PASSED
import math o=int(input()) for i in range(o): s=input() l=s.split() f1=math.fabs(int(l[0])-int(l[2])) f2=math.fabs(int(l[1])-int(l[3])) if int(l[0])!=int(l[2]) and int(l[1])!=int(l[3]): print(int(2+f1+f2)) else: print(int(f1+f2))
1602939900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["GBGBG", "BBGBGBB", "NO"]
2a14f4a526ad2237b897102bfa298003
null
Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing t...
If it is impossible to drink n cups of tea, print "NO" (without quotes). Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black...
The first line contains four integers n, k, a and b (1 ≤ k ≤ n ≤ 105, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that a + b = n.
standard output
standard input
Python 3
Python
1,500
train_010.jsonl
c99b6d0f4746fae34551c1971ee7a02f
256 megabytes
["5 1 3 2", "7 2 2 5", "4 3 4 0"]
PASSED
n, k, a, b = [int(x) for x in input().split()] s = "NO" if (int(n / (k+1)) <= min(a, b)): s = "" actual = (a >= b) while(a != b): v = int(n / (k+1)) if (actual): m = max(min(k, a - v), 1) s += "G" * m a -= m else: m = max(min(k, b - v...
1482057300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES\nYES\nYES\nNO\nYES\nNO"]
65a64ea63153fec4d660bad1287169d3
NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, othe...
You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is loc...
For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower).
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $...
standard output
standard input
PyPy 3
Python
800
train_107.jsonl
54344f85c3e889c48a513d917305cd39
256 megabytes
["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"]
PASSED
t = int(input()) for i in range(1,t+1): x,y = input().split() x, y = int(x), int(y) s = input() d = "" if x > 0: d += x * "R" if x < 0: d += abs(x) * "L" if y > 0: d += y * "U" if y < 0: d += abs(y) * "D" for i in range(0,len(d)): ...
1612535700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
4.5 seconds
["1", "2", "0"]
ba82353e9bc1ee36ed068547d2f4043d
null
You are given a tree consisting of $$$n$$$ vertices. A number is written on each vertex; the number on vertex $$$i$$$ is equal to $$$a_i$$$.Let's denote the function $$$g(x, y)$$$ as the greatest common divisor of the numbers written on the vertices belonging to the simple path from vertex $$$x$$$ to vertex $$$y$$$ (in...
If there is no pair of vertices $$$x, y$$$ such that $$$g(x, y) &gt; 1$$$, print $$$0$$$. Otherwise print the maximum value of $$$dist(x, y)$$$ among such pairs.
The first line contains one integer $$$n$$$ — the number of vertices $$$(1 \le n \le 2 \cdot 10^5)$$$. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ $$$(1 \le a_i \le 2 \cdot 10^5)$$$ — the numbers written on vertices. Then $$$n - 1$$$ lines follow, each containing two integers $$$x$$$ ...
standard output
standard input
PyPy 3
Python
2,000
train_076.jsonl
725234a665a10e2222c41abd77423eb0
256 megabytes
["3\n2 3 4\n1 2\n2 3", "3\n2 3 4\n1 3\n2 3", "3\n1 1 1\n1 2\n2 3"]
PASSED
from sys import stdin, stdout from math import * from heapq import * from collections import * dv=list(range(200002)) for i in range(2,200002): if ((i*i)>=200002): break if (dv[i]==i): j=i while ((i*j)<200002): dv[i*j]=i j=j+1 def loPr(x): global dv if (...
1547217300
[ "number theory", "trees" ]
[ 0, 0, 0, 0, 1, 0, 0, 1 ]
1 second
["YES", "NO"]
aeda11f32911d256fb6263635b738e99
NoteThe first sample: Those near pairs of blue and orange points actually coincide. First, manipulate the first engine: use the second operation with $$$\theta = \pi$$$ (to rotate all power sources $$$180$$$ degrees).The power sources in the first engine become $$$(0, 0)$$$, $$$(0, -2)$$$, and $$$(-2, 0)$$$. Second...
After the war, the supersonic rocket became the most common public transportation.Each supersonic rocket consists of two "engines". Each engine is a set of "power sources". The first engine has $$$n$$$ power sources, and the second one has $$$m$$$ power sources. A power source can be described as a point $$$(x_i, y_i)$...
Print "YES" if the supersonic rocket is safe, otherwise "NO". You can print each letter in an arbitrary case (upper or lower).
The first line contains two integers $$$n$$$, $$$m$$$ ($$$3 \le n, m \le 10^5$$$) — the number of power sources in each engine. Each of the next $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$0\leq x_i, y_i\leq 10^8$$$) — the coordinates of the $$$i$$$-th power source in the first engine. Each of the n...
standard output
standard input
PyPy 3
Python
2,400
train_053.jsonl
41a57db03a5726e49a482d24032adbfa
256 megabytes
["3 4\n0 0\n0 2\n2 0\n0 2\n2 2\n2 0\n1 1", "3 4\n0 0\n0 2\n2 0\n0 2\n2 2\n2 0\n0 0"]
PASSED
import sys # > 0 anti-clock, < 0 clockwise, == 0 same line def orientation(p1, p2, p3): return (p2[0] - p1[0])*(p3[1] - p1[1]) - (p2[1] - p1[1])*(p3[0] - p1[0]) def dot(p1, p2, p3, p4): return (p2[0]-p1[0])*(p4[0]-p3[0]) + (p2[1]-p1[1])*(p4[1]-p3[1]) def theta(p1, p2): dx = p2[0] - p1[0] dy = p2[1...
1533737100
[ "geometry", "strings" ]
[ 0, 1, 0, 0, 0, 0, 1, 0 ]
2 seconds
["2", "-1"]
24a43df3e6d2af348692cdfbeb8a195c
NoteIn the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recog...
Do you know a story about the three musketeers? Anyway, you will learn about its origins now.Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.There are n warriors. Richelimakieu wants to choose three of t...
If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes).
The first line contains two space-separated integers, n and m (3 ≤ n ≤ 4000, 0 ≤ m ≤ 4000) — respectively number of warriors and number of pairs of warriors knowing each other. i-th of the following m lines contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi). Warriors ai and bi know each other. Ea...
standard output
standard input
PyPy 2
Python
1,500
train_012.jsonl
e13831f19029c448f77cda19924761d9
256 megabytes
["5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5", "7 4\n2 1\n3 6\n5 1\n1 7"]
PASSED
n,m=map(int,raw_input().split()) graph=[[False for i in xrange(n+1)]for j in xrange(n+1)] graph2=[[] for i in xrange(n+1)] for i in xrange(m): u,v=map(int,raw_input().split()) graph[u][v]=graph[v][u]=True graph2[u].append(v) graph2[v].append(u) ans=1e999 for u in xrange(1,n+1): for v in graph2[u]: ...
1440865800
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["AGACGTCT", "AGCT", "===", "==="]
d6423f380e6ba711d175d91e73f97b47
NoteIn the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.In the second example the genome is already decoded correctly and each nucleotide i...
The process of mammoth's genome decoding in Berland comes to its end!One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is a...
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
The first line contains the integer n (4 ≤ n ≤ 255) — the length of the genome. The second line contains the string s of length n — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
standard output
standard input
Python 3
Python
900
train_033.jsonl
29a584a597e5dad49537e256e6f4353d
256 megabytes
["8\nAG?C??CT", "4\nAGCT", "6\n????G?", "4\nAA??"]
PASSED
n=input("") Gene= list(input("")) l= len(Gene)/4 for i in range(len(Gene)): if Gene[i]=='?': if Gene.count("A")!=l: Gene[i]="A" elif Gene.count("C")!=l: Gene[i]="C" elif Gene.count("G")!=l: Gene[i]="G" elif Gene.count("T")!=l: Gene[i]="...
1482113100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["0.57142857142857139685", "-1"]
2df45858a638a90d30315844df6d1084
NoteHere is a picture of the first samplePoints A, B, C, D - start mice positions, segments are their paths.Then, at first time when all mice will be in rectangle it will be looks like this:Here is a picture of the second samplePoints A, D, B will never enter rectangle.
Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them.The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in ...
In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formally...
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≤ x1 ≤ x2 ≤ 100 000), (0 ≤ y1 ≤ y2 ≤ 100 000) — the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice....
standard output
standard input
Python 3
Python
2,300
train_020.jsonl
80f745db8f080782def902190e43c603
256 megabytes
["4\n7 7 9 8\n3 5 7 5\n7 5 2 4\n3 3 7 8\n6 6 3 2", "4\n7 7 9 8\n0 3 -5 4\n5 0 5 4\n9 9 -1 -6\n10 5 -7 -10"]
PASSED
rd = lambda: map(int, input().split()) n = int(input()) x1, y1, x2, y2 = rd() l = [] r = [] m = [] for i in range(n): t = [] rx, ry, vx, vy = rd() m.append([rx, ry, vx, vy]) if x1 <= rx <= x2 and y1 <= ry <= y2: t.append(0) if vx == 0 and vy == 0: t.append(0x3f3f3f3f3f3f3f3f)...
1492965900
[ "geometry", "math" ]
[ 0, 1, 0, 1, 0, 0, 0, 0 ]
2 seconds
["4 1 5\n1 2 2\n1000000000 1 1\n6 6 10"]
a07c199ca02f0abaab6c73efdb2a5b2d
NoteFor the first test case, the best choice is $$$a=4$$$, $$$l=1$$$, $$$r=5$$$, and the game would go as follows. Marian starts with one dollar. After the first round, he ends up with $$$2$$$ dollars because the numbers coincide with the chosen one. After the second round, he ends up with $$$4$$$ dollars because t...
Marian is at a casino. The game at the casino works like this.Before each round, the player selects a number between $$$1$$$ and $$$10^9$$$. After that, a dice with $$$10^9$$$ faces is rolled so that a random number between $$$1$$$ and $$$10^9$$$ appears. If the player guesses the number correctly their total money is ...
For each test case, output three integers $$$a$$$, $$$l$$$, and $$$r$$$ such that Marian makes the most amount of money gambling with his strategy. If there are multiple answers, you may output any of them.
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2\cdot 10^5$$$) — the number of rounds. The second line of each test case contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1...
standard output
standard input
PyPy 3-64
Python
1,700
train_096.jsonl
cefedd04c6e37082f0e70005a9833e24
256 megabytes
["4\n\n5\n\n4 4 3 4 4\n\n5\n\n11 1 11 1 11\n\n1\n\n1000000000\n\n10\n\n8 8 8 9 9 6 6 9 6 6"]
PASSED
#!/usr/bin/env python3 import sys import math, random import functools, itertools, collections, heapq, bisect from collections import Counter, defaultdict, deque input = sys.stdin.readline # to read input quickly # available on Google, AtCoder Python3, not available on Codeforces # import numpy as np # impor...
1655217300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2", "1"]
cf1eb164c4c970fd398ef9e98b4c07b1
NoteIn the first test, there are two objects mentioned. The roots that represent them are "a","ab".In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".
In Aramic language words can only represent objects.Words in Aramic have special properties: A word is a root if it does not contain the same letter more than once. A root and all its permutations represent the same object. The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in $$$y...
Output one integer — the number of different objects mentioned in the given ancient Aramic script.
The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^3$$$) — the number of words in the script. The second line contains $$$n$$$ words $$$s_1, s_2, \ldots, s_n$$$ — the script itself. The length of each string does not exceed $$$10^3$$$. It is guaranteed that all characters of the strings are small latin le...
standard output
standard input
Python 2
Python
900
train_003.jsonl
98236d01d326228228aca13f322600c9
256 megabytes
["5\na aa aaa ab abb", "3\namer arem mrea"]
PASSED
n = int(raw_input().strip()) x = raw_input().split(' ') res = len(set([''.join(sorted(set(i))) for i in x])) print res
1525183500
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["391 0\n0 6 1 3 5\n0"]
f18a5fa0b2e7e96cb5994b7b2dbe0189
NoteIn the first test case the array changes as follows:Initially, the array is $$$[-199, 192]$$$. $$$d = 192$$$.After the operation, the array becomes $$$[d-(-199), d-192] = [391, 0]$$$.
Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem:You are given an array $$$a$$$ of $$$n$$$ integers. You are also given an integer $$$k$$$. Lord Omkar wants...
For each case, print the final version of array $$$a$$$ after $$$k$$$ operations described above.
Each test contains multiple test cases. The first line contains the number of cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5, 1 \leq k \leq 10^{18}$$$) – the length of your array and ...
standard output
standard input
PyPy 3
Python
800
train_020.jsonl
218b099d0e20e60926872927b7b7159a
256 megabytes
["3\n2 1\n-199 192\n5 19\n5 -1 4 2 0\n1 2\n69"]
PASSED
t=int(input()) for i in range(0,t): n,k=map(int,input().split()) ls=list(map(int,input().rstrip().split())) if(k%2==1): maxx=ls[0] for l in range(0,n): if ls[l]>maxx: maxx=ls[l] for l in range(0,n): ls[l]=maxx-ls[l] else:...
1597588500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["19.0000000000", "-1"]
8eda3e355d2823b0c8f92e1628dc1b69
null
Vasya lagged behind at the University and got to the battlefield. Just joking! He's simply playing some computer game. The field is a flat platform with n trenches dug on it. The trenches are segments on a plane parallel to the coordinate axes. No two trenches intersect.There is a huge enemy laser far away from Vasya. ...
If Vasya can get from point A to point B, print the minimum time he will need for it. Otherwise, print number -1. The answer will be considered correct if the absolute or relative error does not exceed 10 - 4
The first line contains two space-separated integers: a and b (1 ≤ a, b ≤ 1000), — the duration of charging and the duration of shooting, in seconds. The second line contains four space-separated integers: Ax, Ay, Bx, By ( - 104 ≤ Ax, Ay, Bx, By ≤ 104) — the coordinates of points А and B. It is guaranteed that points A...
standard output
standard input
Python 2
Python
2,200
train_061.jsonl
3352b1902067fa6b8c0010b33c65bc73
256 megabytes
["2 4\n0 5 6 5\n3\n0 0 0 4\n1 1 4 1\n6 0 6 4", "5 10\n0 0 10 10\n1\n5 0 5 9"]
PASSED
import math R = lambda: map(int, raw_input().split()) a, b = R() Ax, Ay, Bx, By = R() n = R()[0] x1, y1, x2, y2 = [Ax],[Ay],[Ax],[Ay] for i in range(n): _t1, _t2, _t3, _t4 = R() if (_t1 > _t3): _t1, _t3 = _t3, _t1 if (_t2 > _t4):_t2, _t4 = _t4, _t2 x1.append(_t1) y1.append(_t2) x2.append(_t3) y2.append(_t4) ...
1335280200
[ "geometry", "graphs" ]
[ 0, 1, 1, 0, 0, 0, 0, 0 ]
2 seconds
["3\n6\n1"]
e5244179b8ef807b1c6abfe113bd4f3b
NoteThe first test case is considered in the statement.In the second test case, there are $$$6$$$ good subarrays: $$$a_{1 \dots 1}$$$, $$$a_{2 \dots 2}$$$, $$$a_{1 \dots 2}$$$, $$$a_{4 \dots 4}$$$, $$$a_{5 \dots 5}$$$ and $$$a_{4 \dots 5}$$$. In the third test case there is only one good subarray: $$$a_{2 \dots 6}$$$.
You are given an array $$$a_1, a_2, \dots , a_n$$$ consisting of integers from $$$0$$$ to $$$9$$$. A subarray $$$a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$$$ is good if the sum of elements of this subarray is equal to the length of this subarray ($$$\sum\limits_{i=l}^{r} a_i = r - l + 1$$$).For example, if $$$a = [1,...
For each test case print one integer — the number of good subarrays of the array $$$a$$$.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array $$$a$$$. The second line of each test case contains a string consisting of $$$n$$$ decimal digits, where the $...
standard output
standard input
Python 3
Python
1,600
train_025.jsonl
587654258f0454e11c17216cc06713cb
256 megabytes
["3\n3\n120\n5\n11011\n6\n600005"]
PASSED
from sys import stdin,stdout for _ in range(int(stdin.readline())): n=int(stdin.readline()) # a=list(map(int,stdin.readline().split())) a=[int(ch)-1 for ch in input()] s=ans=0;d={0:1} for v in a: s+=v ans+=d.get(s,0) d[s]=d.get(s,0)+1 print(ans)
1597415700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1\n23\n19\n6\n26"]
4841cbc3d3ef29929690b78e30fbf22e
NoteFor the first test case, Atilla needs to know only the character $$$\texttt{a}$$$, so the alphabet of size $$$1$$$ which only contains $$$\texttt{a}$$$ is enough.For the second test case, Atilla needs to know the characters $$$\texttt{d}$$$, $$$\texttt{o}$$$, $$$\texttt{w}$$$, $$$\texttt{n}$$$. The smallest alphabe...
In order to write a string, Atilla needs to first learn all letters that are contained in the string.Atilla needs to write a message which can be represented as a string $$$s$$$. He asks you what is the minimum alphabet size required so that one can write this message.The alphabet of size $$$x$$$ ($$$1 \leq x \leq 26$$...
For each test case, output a single integer — the minimum alphabet size required to so that Atilla can write his message $$$s$$$.
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the length of the string. The second line of each test case contains a string $$$s$$$ of length $$$n$$$, consisting of lo...
standard output
standard input
Python 2
Python
800
train_101.jsonl
3eb0e5971c25df234b921d942fc87dfa
256 megabytes
["5\n\n1\n\na\n\n4\n\ndown\n\n10\n\ncodeforces\n\n3\n\nbcf\n\n5\n\nzzzzz"]
PASSED
import sys raw_input = iter(sys.stdin.read().splitlines()).next def solution(): n = int(raw_input()) s = raw_input() return ord(max(s))-ord('a')+1 for case in xrange(int(raw_input())): print '%s' % solution()
1669041300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["3", "1", "1"]
1254d7ee968ed89a229e02ccefaf5994
NoteFor example $$$1$$$, by disturbing both blocks of sand on the first row from the top at the first and sixth columns from the left, and the block of sand on the second row from the top and the fourth column from the left, it is possible to have all the required amounts of sand fall in each column. It can be proved t...
This is the hard version of the problem. The difference between the versions is the constraints on $$$a_i$$$. You can make hacks only if all versions of the problem are solved.Little Dormi has recently received a puzzle from his friend and needs your help to solve it. The puzzle consists of an upright board with $$$n$$...
Print one non-negative integer, the minimum amount of operations needed to solve the puzzle.
The first line consists of two space-separated positive integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \cdot m \leq 400\,000$$$). Each of the next $$$n$$$ lines contains $$$m$$$ characters, describing each row of the board. If a character on a line is '.', the corresponding cell is empty. If it is '#', the cell contains a b...
standard output
standard input
Python 3
Python
3,000
train_091.jsonl
564b5149bfdefab0343980c38cb23bd6
512 megabytes
["5 7\n#....#.\n.#.#...\n#....#.\n#....##\n#.#....\n4 1 1 1 0 3 1", "3 3\n#.#\n#..\n##.\n3 1 1", "7 5\n.#..#\n#....\n..##.\n..##.\n..###\n..#..\n#.##.\n0 0 2 4 2"]
PASSED
import itertools import math from math import inf def readline(): return map(int, input().split()) def blocks(bits): start = None for (i, bit) in enumerate(itertools.chain(bits, [False])): if bit and start is None: start = i if not bit and start is not None: yield...
1623598500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["Yes\n1\n1 4", "No", "Yes\n4\n1 2\n1 3\n1 4\n1 5"]
0a476638c2122bfb236b53742cf8a89d
NoteThe tree from the first example is shown on the picture below: The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.The tree from the second example is shown on the picture below: We can show that there are no val...
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two paths ...
If there are no decompositions, print the only line containing "No". Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $$$m$$$. Each of the next $$$m$$$ lines should contain two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \neq v_i$$$)...
The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^{5}$$$) the number of nodes in the tree. Each of the next $$$n - 1$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n$$$, $$$a_i \neq b_i$$$) — the edges of the tree. It is guaranteed that the given edges form a tree.
standard output
standard input
Python 3
Python
1,400
train_031.jsonl
50c70d8441dd5ff28a892026a9aa91bb
256 megabytes
["4\n1 2\n2 3\n3 4", "6\n1 2\n2 3\n3 4\n2 5\n3 6", "5\n1 2\n1 3\n1 4\n1 5"]
PASSED
n = int(input()) deg = [0]*100005 leaves = [] for i in range(1,n): a,b = map(int, input().split()) deg[a]+=1 deg[b]+=1 cnt = 0 mxdeg = 0 root = 0 for j in range(1,n+1): if deg[j]>mxdeg: mxdeg = deg[j] root = j if deg[j] == 1: leaves.append(j) if deg[j] > 2: cnt+=1...
1527432600
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["1\nAE", "-1", "2\nAAE"]
94e58f3f7aa4d860b95d34c7c9f89058
NoteFor the first test, the statement $$$\forall x_1, \exists x_2, x_1&lt;x_2$$$ is true. Answers of "EA" and "AA" give false statements. The answer "EE" gives a true statement, but the number of universal quantifiers in this string is less than in our answer.For the second test, we can show that no assignment of quant...
Logical quantifiers are very useful tools for expressing claims about a set. For this problem, let's focus on the set of real numbers specifically. The set of real numbers includes zero and negatives. There are two kinds of quantifiers: universal ($$$\forall$$$) and existential ($$$\exists$$$). You can read more about ...
If there is no assignment of quantifiers for which the statement is true, output a single integer $$$-1$$$. Otherwise, on the first line output an integer, the maximum possible number of universal quantifiers. On the next line, output a string of length $$$n$$$, where the $$$i$$$-th character is "A" if $$$Q_i$$$ should...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2\le n\le 2\cdot 10^5$$$; $$$1\le m\le 2\cdot 10^5$$$) — the number of variables and the number of inequalities in the formula, respectively. The next $$$m$$$ lines describe the formula. The $$$i$$$-th of these lines contains two integers $$$j_i$$$,$$$k_i$$$ ...
standard output
standard input
PyPy 2
Python
2,600
train_004.jsonl
67c0321099415a106a7927e599fd0948
256 megabytes
["2 1\n1 2", "4 3\n1 2\n2 3\n3 1", "3 2\n1 3\n2 3"]
PASSED
import sys range = xrange input = raw_input def toposort(graph): res = []; found = [0] * len(graph) stack = list(range(len(graph))) while stack: node = stack.pop() if node < 0: res.append(~node) elif not found[node]: found[node] = 1 stack.appen...
1588775700
[ "math", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
2 seconds
["YES\n0 0\n1 0\n0 1\n2 0\n1 -1\n-1 1\n0 2", "NO", "YES\n3 3\n4 3\n5 3\n6 3"]
1ee7ec135d957db2fca0aa591fc44b16
NoteIn the first sample one of the possible positions of tree is:
Dasha decided to have a rest after solving the problem. She had been ready to start her favourite activity — origami, but remembered the puzzle that she could not solve. The tree is a non-oriented connected graph without cycles. In particular, there always are n - 1 edges in a tree with n vertices.The puzzle is to po...
If the puzzle doesn't have a solution then in the only line print "NO". Otherwise, the first line should contain "YES". The next n lines should contain the pair of integers xi, yi (|xi|, |yi| ≤ 1018) — the coordinates of the point which corresponds to the i-th vertex of the tree. If there are several solutions, print a...
The first line contains single integer n (1 ≤ n ≤ 30) — the number of vertices in the tree. Each of next n - 1 lines contains two integers ui, vi (1 ≤ ui, vi ≤ n) that mean that the i-th edge of the tree connects vertices ui and vi. It is guaranteed that the described graph is a tree.
standard output
standard input
Python 3
Python
2,000
train_069.jsonl
52d546f4ca5d5d47a31d2168aeb37c12
256 megabytes
["7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7", "6\n1 2\n2 3\n2 4\n2 5\n2 6", "4\n1 2\n2 3\n3 4"]
PASSED
#https://codeforces.com/problemset/problem/761/E def solve(): def push(u, v, g): if u not in g: g[u] = [] if v not in g: g[v] = [] g[u].append(v) g[v].append(u) n = int(input()) g = {} for _ in range(n-1): u, v = map(int, ...
1485873300
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1 second
["1 4 2 3 5 6 \n1 2 3 4 \n-1\n5 6 3 4 1 2 \n-1\n1 8 6 7 2 4 3 5"]
c2db558ecf921161ab4da003bd393ec7
NoteThe first test case is parsed in the problem statement.
A sequence of $$$n$$$ numbers is called permutation if it contains all numbers from $$$1$$$ to $$$n$$$ exactly once. For example, the sequences [$$$3, 1, 4, 2$$$], [$$$1$$$] and [$$$2,1$$$] are permutations, but [$$$1,2,1$$$], [$$$0,1$$$] and [$$$1,3,4$$$] — are not.For a permutation $$$p$$$ of even length $$$n$$$ you ...
For each test case, print on a separate line: lexicographically minimal permutation $$$p$$$ such that you can make an array $$$b$$$ from it; or a number -1 if the permutation you are looking for does not exist.
The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains one even integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$). The second line of each test case contains exactly $$$\frac{...
standard output
standard input
PyPy 3-64
Python
1,900
train_085.jsonl
d29358a55d6d4b859d3c787bbdcd35fd
256 megabytes
["6\n\n6\n\n4 3 6\n\n4\n\n2 4\n\n8\n\n8 7 2 3\n\n6\n\n6 4 2\n\n4\n\n4 4\n\n8\n\n8 7 4 5"]
PASSED
import collections import math import bisect import sys import heapq import itertools #import functools def solve(): n = int(input()) arr = [int(i) for i in sys.stdin.readline().split()] dic = {} for i, num in enumerate(arr): dic[num] = i if len(dic) != n // 2 or n not in dic:...
1668782100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["Utkarsh\nAshish\nUtkarsh\nUtkarsh\nAshish"]
d4d41e75c68ce5e94c92e1b9876891bf
NoteIn the first test case, one possible sequence of moves can be$$$(0, 0) \xrightarrow{\text{Ashish }} (0, 1) \xrightarrow{\text{Utkarsh }} (0, 2)$$$.Ashish has no moves left, so Utkarsh wins.
Utkarsh is forced to play yet another one of Ashish's games. The game progresses turn by turn and as usual, Ashish moves first.Consider the 2D plane. There is a token which is initially at $$$(0,0)$$$. In one move a player must increase either the $$$x$$$ coordinate or the $$$y$$$ coordinate of the token by exactly $$$...
For each test case, if Ashish wins the game, print "Ashish", otherwise print "Utkarsh" (without the quotes).
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The only line of each test case contains two space separated integers $$$d$$$ ($$$1 \leq d \leq 10^5$$$) and $$$k$$$ ($$$1 \leq k \leq d$$$).
standard output
standard input
Python 3
Python
null
train_021.jsonl
1c221cb4e56c5aaad964ef9a7a5cd759
256 megabytes
["5\n2 1\n5 2\n10 3\n25 4\n15441 33"]
PASSED
t = int(input()) for i in range(t): n,k=map(int,input().split()) x = int((n / k)/2**0.5) a = (x+1)**2 + (x)**2 b = (n/k)**2 if a >b: print('Utkarsh') else: print('Ashish')
1605969300
[ "geometry", "math", "games" ]
[ 1, 1, 0, 1, 0, 0, 0, 0 ]
3 seconds
["YES\n2\n1 4\n4\n5 3 2 1\n5\n4 1 2 3 5", "NO\n2"]
8c06963c45469f638a1c7c4769295be9
NoteHere is what the queries look like for the first test case (red corresponds to the 1st query, blue 2nd query, and green 3rd query): Notice that every edge in the graph is part of either $$$0$$$ or $$$2$$$ colored query edges.The graph in the second test case looks like this: There does not exist an assignment...
She does her utmost to flawlessly carry out a person's last rites and preserve the world's balance of yin and yang.Hu Tao, being the little prankster she is, has tried to scare you with this graph problem! You are given a connected undirected graph of $$$n$$$ nodes with $$$m$$$ edges. You also have $$$q$$$ queries. Eac...
If it is possible to force all edge weights to be even, print "YES" on the first line, followed by $$$2q$$$ lines indicating the choice of path for each query in the same order the queries are given. For each query, the first line should contain a single integer $$$x$$$: the number of nodes in the chosen path. The next...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 3 \cdot 10^5$$$, $$$n-1 \leq m \leq \min{\left(\frac{n(n-1)}{2}, 3 \cdot 10^5\right)}$$$). Each of the next $$$m$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x, y \leq n$$$, $$$x\neq y$$$) indicating an undirected edge between n...
standard output
standard input
PyPy 3
Python
2,200
train_087.jsonl
fb387101b53d97c89a12905bb41874ad
512 megabytes
["6 7\n2 1\n2 3\n3 5\n1 4\n6 1\n5 6\n4 5\n3\n1 4\n5 1\n4 5", "5 7\n4 3\n4 5\n2 1\n1 4\n1 3\n3 5\n3 2\n4\n4 2\n3 5\n5 1\n4 5"]
PASSED
import sys input=sys.stdin.readline def unionfind(u): v=u while u!=parent[u]: u=parent[u] while v!=u: w=parent[v] parent[v]=u v=parent[w] return u def path(u,v): s=[u] pre=[-1]*(n+1) pre[u]=u while s: x=s.pop() for y in g[x...
1634468700
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1 second
["aa", "abca"]
c01fc2cb6efc7eef290be12015f8d920
NoteIn the first example you can remove any character of $$$s$$$ to obtain the string "aa".In the second example "abca" &lt; "abcd" &lt; "abcda" &lt; "abda" &lt; "acda" &lt; "bcda".
You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.You have to remove at most one (i.e. zero or one) character of this string in such a way that the string you obtain will be lexicographically smallest among all strings that can be obtained using this operation.String $$$s = s_1 s_2 \dots s_n$...
Print one string — the smallest possible lexicographically string that can be obtained by removing at most one character from the string $$$s$$$.
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of $$$s$$$. The second line of the input contains exactly $$$n$$$ lowercase Latin letters — the string $$$s$$$.
standard output
standard input
Python 3
Python
1,200
train_020.jsonl
4d11c7f5103873c1181250dba643b83f
256 megabytes
["3\naaa", "5\nabcda"]
PASSED
n = int(input()) s = input() min = n - 1 for i in range(n - 1): if s[i] > s[i + 1]: min = i break print(s[:min] + s[min + 1:])
1542033300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["2 4 1 2 \n1 3"]
3342e71884677534b7a126f89d441585
NoteIn the first test case:The player begins at height $$$2$$$, next going up to height $$$4$$$ increasing the difficulty by $$$1$$$. After that he will go down to height $$$1$$$ and the difficulty doesn't change because he is going downhill. Finally the player will go up to height $$$2$$$ and the difficulty will incre...
You are a game designer and want to make an obstacle course. The player will walk from left to right. You have $$$n$$$ heights of mountains already selected and want to arrange them so that the absolute difference of the heights of the first and last mountains is as small as possible. In addition, you want to make the ...
For each test case, output $$$n$$$ integers — the given heights in an order that maximizes the difficulty score among all orders that minimize $$$|h_1-h_n|$$$. If there are multiple orders that satisfy these requirements, you may output any.
The first line will contain a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) — the number of mountains. The second line of each test case contains $$$n$$$ i...
standard output
standard input
PyPy 3-64
Python
1,200
train_084.jsonl
26fc8dcabda715685cbd10dd07636f9c
256 megabytes
["2\n4\n4 2 1 2\n2\n3 1"]
PASSED
for _ in range(int(input())): n = int(input()) res=[] a = list(map(int,input().split())) a.sort() last=0 first = 0 minn=1e9 first,last = 0,0 for i in range(1,n): if a[i]==a[i-1]: first,last = a[i],a[i] ind=i ind2=i-1 ...
1624026900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["0\n1\n3\n3"]
4f8eac547bbd469a69de2f4aae4a87f0
NoteIn the first test case, Mocha can choose the interval $$$[1,2]$$$, then the sequence becomes $$$[ 0, 0]$$$, where the first element is $$$1\,\&amp;\,2$$$, and the second element is $$$2\,\&amp;\,1$$$.In the second test case, Mocha can choose the interval $$$[1,3]$$$, then the sequence becomes $$$[ 1,1,1]$$$, where ...
Mocha is a young girl from high school. She has learned so much interesting knowledge from her teachers, especially her math teacher. Recently, Mocha is learning about binary system and very interested in bitwise operation.This day, Mocha got a sequence $$$a$$$ of length $$$n$$$. In each operation, she can select an ar...
For each test case, print one integer — the minimal value of the maximum value in the sequence.
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the length of the sequence. The second line of ...
standard output
standard input
PyPy 3-64
Python
900
train_095.jsonl
ccee34b56e6d91baebf9d6c0a2d73673
256 megabytes
["4\n2\n1 2\n3\n1 1 3\n4\n3 11 3 7\n5\n11 7 15 3 7"]
PASSED
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) x=a[0] for i in range(1,n): x=a[i]&x if x==0: break print(x)
1629038100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1\n3\n2\n3\n4"]
38afe98586a3b8d6061fe7e3e8fc4d02
NoteIn the first test case $$$x = 1$$$, so you need only one jump: the $$$1$$$-st jump from $$$0$$$ to $$$0 + 1 = 1$$$.In the second test case $$$x = 2$$$. You need at least three jumps: the $$$1$$$-st jump from $$$0$$$ to $$$0 + 1 = 1$$$; the $$$2$$$-nd jump from $$$1$$$ to $$$1 + 2 = 3$$$; the $$$3$$$-rd jump fro...
You are standing on the $$$\mathit{OX}$$$-axis at point $$$0$$$ and you want to move to an integer point $$$x &gt; 0$$$.You can make several jumps. Suppose you're currently at point $$$y$$$ ($$$y$$$ may be negative) and jump for the $$$k$$$-th time. You can: either jump to the point $$$y + k$$$ or jump to the point ...
For each test case, print the single integer — the minimum number of jumps to reach $$$x$$$. It can be proved that we can reach any integer point $$$x$$$.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first and only line of each test case contains the single integer $$$x$$$ ($$$1 \le x \le 10^6$$$) — the destination point.
standard output
standard input
PyPy 3
Python
null
train_017.jsonl
deed7bf9d36bb86d56a139a6f422d7f7
256 megabytes
["5\n1\n2\n3\n4\n5"]
PASSED
t=int(input()) for i in range(t): n=int(input()) u=1 while((u*(u+1)/2)<n): u += 1 a=u*(u+1)/2 c=a-n for j in range(1,u+1): if(c==j+1): c = c-j-1 print(int(u+c))
1606746900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
4 seconds
["3", "2", "1"]
10f2f1df27cf61f11afb074dab01ebec
NoteThere are three good substrings in the first sample test: «aab», «ab» and «b».In the second test only substrings «e» and «t» are good.
Smart Beaver recently got interested in a new word game. The point is as follows: count the number of distinct good substrings of some string s. To determine if a string is good or not the game uses rules. Overall there are n rules. Each rule is described by a group of three (p, l, r), where p is a string and l and r (...
Print a single integer — the number of good substrings of string s.
The first line contains string s. The second line contains integer n. Next n lines contain the rules, one per line. Each of these lines contains a string and two integers pi, li, ri, separated by single spaces (0 ≤ li ≤ ri ≤ |pi|). It is guaranteed that all the given strings are non-empty and only contain lowercase Eng...
standard output
standard input
Python 3
Python
1,700
train_050.jsonl
9e646f3585e336052db5afa339565ff5
256 megabytes
["aaab\n2\naa 0 0\naab 1 1", "ltntlnen\n3\nn 0 0\nttlneenl 1 4\nlelllt 1 1", "a\n0"]
PASSED
def count(p, s): start = 0 c = 0 while True: try: pos = s.index(p, start) c += 1 start = pos + 1 except ValueError: return c s = input() n = int(input()) pravs = [] for i in range(n): p, l, r = input().split() l = int(l); r = int(r) ...
1371042000
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["32\n8646\n604"]
d3c3bc95605010040e2018e465eb9fab
NoteIn the first test case $$$99 + 32 = 131$$$ is a palindrome. Note that another answer is $$$12$$$, because $$$99 + 12 = 111$$$ is also a palindrome.In the second test case $$$1023 + 8646 = 9669$$$.In the third test case $$$385 + 604 = 989$$$.
During a daily walk Alina noticed a long number written on the ground. Now Alina wants to find some positive number of same length without leading zeroes, such that the sum of these two numbers is a palindrome. Recall that a number is called a palindrome, if it reads the same right to left and left to right. For exampl...
For each of $$$t$$$ test cases print an answer — a positive $$$n$$$-digit integer without leading zeros, such that the sum of the input integer and this number is a palindrome. We can show that at least one number satisfying the constraints exists. If there are multiple solutions, you can output any of them.
The first line of input data contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. Next, descriptions of $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 100\,000$$$) — the length of the number that is written on the ground. The ...
standard output
standard input
PyPy 3-64
Python
1,100
train_094.jsonl
24297919af6e3029c3955b14692ec317
256 megabytes
["3\n2\n99\n4\n1023\n3\n385"]
PASSED
# Import helpful pages from multiprocessing.dummy import current_process import queue from sys import stdin, stdout from collections import defaultdict import copy import math import itertools import heapq import bisect from turtle import back # Helper methods for execution def get_int_dd(): def def_value(): re...
1655629500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["Iwantorderpizza", "sampleaseinout"]
586341bdd33b1dc3ab8e7f9865b5f6f6
null
Amugae has a sentence consisting of $$$n$$$ words. He want to compress this sentence into one word. Amugae doesn't like repetitions, so when he merges two words into one word, he removes the longest prefix of the second word that coincides with a suffix of the first word. For example, he merges "sample" and "please" in...
In the only line output the compressed word after the merging process ends as described in the problem.
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the number of the words in Amugae's sentence. The second line contains $$$n$$$ words separated by single space. Each words is non-empty and consists of uppercase and lowercase English letters and digits ('A', 'B', ..., 'Z', 'a', 'b', ..., 'z', '0', '1...
standard output
standard input
Python 2
Python
2,000
train_001.jsonl
b902082ef641b4164a498953a9a0d707
256 megabytes
["5\nI want to order pizza", "5\nsample please ease in out"]
PASSED
def kmp(s): i,j = -1,0 fail = [0]*len(s) while j < len(s): if i == -1 or s[j] == s[i]: fail[j] = i j += 1 i += 1 else: i = -1 if i == 0 else fail[i-1]+1 return fail[-1]+1 n = input() words = raw_input().split(" ") out =...
1565526900
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["62\n112\n107\n-1", "26\n-1\n36\n30\n-1\n26\n34\n26\n-1\n36"]
67dd049fafc464fed87fbd23f0ccc8ab
NoteConsider the first example.In the first shop, Monocarp can only buy $$$0$$$ red pepper packages and $$$1$$$ black pepper package. Black pepper added to all dishes will sum up to $$$10 + 50 + 2 = 62$$$.In the second shop, Monocarp can buy any number of red and black pepper packages: $$$0$$$ and $$$3$$$, $$$1$$$ and ...
Monocarp is going to host a party for his friends. He prepared $$$n$$$ dishes and is about to serve them. First, he has to add some powdered pepper to each of them — otherwise, the dishes will be pretty tasteless.The $$$i$$$-th dish has two values $$$a_i$$$ and $$$b_i$$$ — its tastiness with red pepper added or black p...
Print $$$m$$$ integers. For each shop, print the maximum total tastiness of the dishes after Monocarp buys pepper packages only in this shop and adds the pepper to the dishes. If it's impossible to purchase the packages so that each dish will get the pepper added once and no pepper is left, print -1.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of dishes. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i, b_i \le 10^9$$$) — the tastiness of the $$$i$$$-th dish with red pepper added or black pepper added, respectivel...
standard output
standard input
PyPy 3-64
Python
2,300
train_098.jsonl
f550dd6d6a089108f2b1ab9130f6de7f
256 megabytes
["3\n5 10\n100 50\n2 2\n4\n2 3\n1 1\n3 2\n2 2", "10\n3 1\n2 3\n1 1\n2 1\n6 3\n1 4\n4 3\n1 3\n5 3\n5 4\n10\n8 10\n9 3\n1 4\n2 5\n8 3\n3 5\n1 6\n7 2\n6 7\n3 1"]
PASSED
import sys input = sys.stdin.readline n=int(input()) ans=0 l=[] for _ in range(n): a,b=map(int,input().split()) ans+=a l.append(b-a) l.sort(reverse=True) idx=10**10 for i in range(n): if l[i]<0: idx=i break rui=[0] for i in range(n): rui.append(rui[-1]+l[i]) def extgcd(a, b): if...
1662647700
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["0\n0\n1"]
644ef17fe304b090e0cf33a84ddc546a
NoteIn the first test case, the ugliness is already $$$0$$$.In the second test case, you should do one operation, with $$$i = 1$$$ and $$$j = 3$$$. The new heights will now be $$$[2, 2, 2, 2]$$$, with an ugliness of $$$0$$$.In the third test case, you may do three operations: with $$$i = 3$$$ and $$$j = 1$$$. The new...
There are $$$n$$$ block towers in a row, where tower $$$i$$$ has a height of $$$a_i$$$. You're part of a building crew, and you want to make the buildings look as nice as possible. In a single day, you can perform the following operation: Choose two indices $$$i$$$ and $$$j$$$ ($$$1 \leq i, j \leq n$$$; $$$i \neq j$$$...
For each test case, output a single integer — the minimum possible ugliness of the buildings.
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the number of buildings. The second line of each test case contains $$$n$$$ space separated integers $$$...
standard output
standard input
Python 3
Python
800
train_100.jsonl
45465e3519b41f75e5aa47cc1abbd9e0
256 megabytes
["3\n3\n10 10 10\n4\n3 2 1 2\n5\n1 2 3 1 5"]
PASSED
t=int(input()) if t>=1 and t<=10000: for j in range(t): b= int(input()) a=input().split() sum=0 for i in range(len(a)): sum=sum +int(a[i]) if sum%b==0: print(0) else: print(1)
1640356500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["First", "First", "Draw", "First", "Second"]
6f52388b652a900e63ec39406225392c
null
Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first...
Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes.
The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word. It is guaranteed that both words consist of 2·n characters "0" and "1".
standard output
standard input
Python 3
Python
1,500
train_033.jsonl
0de64ede6037fed936e2d94b590a3df3
256 megabytes
["2\n0111\n0001", "3\n110110\n001001", "3\n111000\n000111", "4\n01010110\n00101101", "4\n01100000\n10010011"]
PASSED
from sys import stdin def readLine(): return stdin.readline(); def main(): while True: n = int(readLine()); a = readLine(); b = readLine(); both = 0; onlyA = 0; onlyB = 0; for i in range(2*n): if a[i] == '1' and b[i] == '1': both += 1; elif a[i] == '1': onlyA +=...
1366644900
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
2 seconds
["NO\nYES\nYES\nYES\nNO"]
3ec1b7027f487181dbdfb12f295f11ae
null
Polycarp remembered the $$$2020$$$-th year, and he is happy with the arrival of the new $$$2021$$$-th year. To remember such a wonderful moment, Polycarp wants to represent the number $$$n$$$ as the sum of a certain number of $$$2020$$$ and a certain number of $$$2021$$$.For example, if: $$$n=4041$$$, then the number...
For each test case, output on a separate line: "YES" if the number $$$n$$$ is representable as the sum of a certain number of $$$2020$$$ and a certain number of $$$2021$$$; "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 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case contains one integer $$$n$$$ ($$$1 \leq n \leq 10^6$$$) — the number that Polycarp wants to represent as the sum of the numbers $$$2020$$$ and $$$2021$$$.
standard output
standard input
PyPy 3-64
Python
900
train_086.jsonl
46b3d5d55dfd9c2705827cff9285abea
256 megabytes
["5\n1\n4041\n4042\n8081\n8079"]
PASSED
import math def get(): return list(map(int, input().split())) def intput(): return int(input()) def rec(w,memo): if(w in memo): return memo[w] if (w==0): return True if (w<0): return False memo[w]=rec(w - 2021, memo) | rec(w - 2020, memo) return memo[w] de...
1611586800
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["142857", "Impossible", "102564"]
86dc5cb9e667fc2ae4d988613feddcb6
NoteSample 1: 142857·5 = 714285.Sample 2: The number that consists of a single digit cannot stay what it is when multiplied by 2, thus, the answer to the test sample is "Impossible".
Teacher thinks that we make a lot of progress. Now we are even allowed to use decimal notation instead of counting sticks. After the test the teacher promised to show us a "very beautiful number". But the problem is, he's left his paper with the number in the teachers' office.The teacher remembers that the "very beauti...
If the teacher's made a mistake and such number doesn't exist, then print on a single line "Impossible" (without the quotes). Otherwise, print the "very beautiful number" without leading zeroes.
The single line contains integers p, x (1 ≤ p ≤ 106, 1 ≤ x ≤ 9).
standard output
standard input
Python 3
Python
null
train_070.jsonl
94f99c26af7d19738cc24a431e5c839a
256 megabytes
["6 5", "1 2", "6 4"]
PASSED
p, k = map(int, input().split()) u = 10 * k - 1 v = pow(10, p - 1, u) - k for y in range(k, 10): if (y * v) % u == 0: q = d = 9 * y while q % u: q = 10 * q + d q = str(q // u) print(q * (p // len(q))) break else: print('Impossible')
1392910200
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["7", "100"]
6bb2793e275426eb076972fab69d0eba
null
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1 ≤ i, j ≤ N2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.
Print a single number which represents the number of pairs i and j with the needed property. Pairs (x, y) and (y, x) should be considered different, i.e. the ordered pairs count.
The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105.
standard output
standard input
PyPy 3
Python
1,500
train_004.jsonl
fc92b516d112816ef177feeed05e3455
256 megabytes
["great10", "aaaaaaaaaa"]
PASSED
def f(x=input()): d = dict() for i in x: if i in d: d[i]+=1 else: d[i] = 1 return sum([j*j for _,j in d.items()]) print(f())
1292862000
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["4\n1\n2\n2\n1\n8\n1\n2\n2"]
15823d23340c845e0c257974390cb69f
NoteIn the first test case, there are $$$4$$$ distinct permutation that can be made using the process: $$$[2,3,1,4,5,6,7]$$$, $$$[2,3,1,7,6,5,4]$$$, $$$[2,3,1,4,6,5,7]$$$, $$$[2,3,1,7,5,6,4]$$$.In the second test case, there is only one distinct permutation that can be made using the process: $$$[1]$$$.In the third tes...
While searching for the pizza, baby Hosssam came across two permutations $$$a$$$ and $$$b$$$ of length $$$n$$$.Recall that a permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation...
For each test case, print the number of possible permutations $$$c$$$, modulo $$$10^9+7$$$.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 10^5$$$) — the length of the permutations. The next line contains $$$n$$$ distinct integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1\le a_i\le n$$$) — th...
standard output
standard input
PyPy 3-64
Python
1,400
train_100.jsonl
f0c033a7d2f640720635c40df4676d30
256 megabytes
["9\n7\n1 2 3 4 5 6 7\n2 3 1 7 6 5 4\n2 0 1 0 0 0 0\n1\n1\n1\n0\n6\n1 5 2 4 6 3\n6 5 3 1 4 2\n6 0 0 0 0 0\n8\n1 6 4 7 2 3 8 5\n3 2 8 1 4 5 6 7\n1 0 0 7 0 3 0 5\n10\n1 8 6 2 4 7 9 3 10 5\n1 9 2 3 4 10 8 6 7 5\n1 9 2 3 4 10 8 6 7 5\n7\n1 2 3 4 5 6 7\n2 3 1 7 6 5 4\n0 0 0 0 0 0 0\n5\n1 2 3 4 5\n1 2 3 4 5\n0 0 0 0 0\n5\n1 ...
PASSED
import sys input = sys.stdin.readline def pow(x, a, mod): if a == 0: return 1 if a == 1: return x % mod if a % 2: return (x * pow(x * x, a // 2, mod)) % mod else: return (pow(x * x, a // 2, mod)) % mod def sol(n, a, b, d): vis = [False] * n ai...
1651847700
[ "math", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
3 seconds
["9", "12"]
2596db1dfc124ea9e14c3f13c389c8d2
NoteThe picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3·3 = 9.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hed...
Print the maximum possible value of the hedgehog's beauty.
First line of the input contains two integers n and m(2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number segments on the picture respectively. Then follow m lines, each containing two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the numbers of points connected by corresponding segment. It's guar...
standard output
standard input
Python 3
Python
1,600
train_027.jsonl
ffe546a4b2f133c3b4a40d24d29ef7b2
256 megabytes
["8 6\n4 5\n3 5\n2 5\n1 2\n2 8\n6 7", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4"]
PASSED
R = lambda : map(int, input().split()) n,m=R() adj=[[] for _ in range(n)] from collections import defaultdict d=defaultdict(int) for i in range(m): u,v=R() if (u>v): u,v=v,u adj[u-1].append(v-1) d[u-1]+=1 d[v-1]+=1 h=defaultdict(int) for i in range(n): h[i]=max(h[i],1) for v in ad...
1452261900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
4 seconds
["1\n1", "3\n1 3 4", "4\n1 4 5 6", "7\n1 2 4 5 6 7 9"]
81f7807397635c9ce01f9100e68cb420
null
Let's call a set of positive integers $$$a_1, a_2, \dots, a_k$$$ quadratic if the product of the factorials of its elements is a square of an integer, i. e. $$$\prod\limits_{i=1}^{k} a_i! = m^2$$$, for some integer $$$m$$$.You are given a positive integer $$$n$$$.Your task is to find a quadratic subset of a set $$$1, 2...
In the first line, print a single integer — the size of the maximum subset. In the second line, print the subset itself in an arbitrary order.
A single line contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$).
standard output
standard input
PyPy 3-64
Python
2,900
train_085.jsonl
174b1d60eff3d63cd65d55d4091e1504
256 megabytes
["1", "4", "7", "9"]
PASSED
def is_square(n): return int(n ** 0.5) ** 2 == n def solve(n): if n <= 3: return range(2, n+1) k = n >> 1 if n % 4 == 0: return [k] if n % 4 == 1: return [k, n] if n % 4 == 2: if is_square(n + 2): return [k + 1] if is_square(2 ...
1640615700
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
3 seconds
["2\n1 3 4", "-1", "4\n1 3 2 3 4"]
c23efec5ead55d9adee703c3ff535b94
null
In Ancient Berland there were n cities and m two-way roads of equal length. The cities are numbered with integers from 1 to n inclusively. According to an ancient superstition, if a traveller visits three cities ai, bi, ci in row, without visiting other cities between them, a great disaster awaits him. Overall there ar...
If there are no path from 1 to n print -1. Otherwise on the first line print the number of roads d along the shortest path from the city 1 to the city n. On the second line print d + 1 numbers — any of the possible shortest paths for Vasya. The path should start in the city 1 and end in the city n.
The first line contains three integers n, m, k (2 ≤ n ≤ 3000, 1 ≤ m ≤ 20000, 0 ≤ k ≤ 105) which are the number of cities, the number of roads and the number of the forbidden triplets correspondingly. Then follow m lines each containing two integers xi, yi (1 ≤ xi, yi ≤ n) which are the road descriptions. The road is d...
standard output
standard input
Python 3
Python
2,000
train_039.jsonl
b497e10aee4e64e951c3c9b6d0571ea7
256 megabytes
["4 4 1\n1 2\n2 3\n3 4\n1 3\n1 4 3", "3 1 0\n1 2", "4 4 2\n1 2\n2 3\n3 4\n1 3\n1 2 3\n1 3 4"]
PASSED
if __name__ =='__main__': n, m, k = map(int, input().split()) graph = [[] for i in range(n + 2)] for i in range(m): u, v = map(int, input().split()) graph[u].append(v) graph[v].append(u) graph[n].append(n+1) processed =[[-1 for i in range(n+2)] for j in range(n+2)] forbid = set(a + (b+c*n)*n for (a,b,c) ...
1297440000
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["YES", "NO", "YES"]
c4b7265ff4332225c0d5617c3233a910
null
One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where ...
If the given state is reachable in the described game, output YES, otherwise NO.
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of cells in the array. The second line contains n distinct integers from 1 to n — permutation. The last line contains n integers from 1 to n — favourite numbers of the cells.
standard output
standard input
Python 3
Python
1,600
train_034.jsonl
cc056a88cd96d0b8039a6bc699aa93e6
256 megabytes
["5\n5 4 3 2 1\n1 1 1 1 1", "7\n4 3 5 1 2 7 6\n4 6 6 1 6 6 1", "7\n4 2 5 1 3 7 6\n4 6 6 1 6 6 1"]
PASSED
n = int(input()) data = list(map(int, input().split())) spans = list(map(int, input().split())) connect = [[False for c in range(n)] for r in range(n)] for p, span in enumerate(spans): for r in [p-span, p+span]: if r >= 0 and r < n: connect[p][r] = connect[r][p] = True def visit(data, connect, seen, group...
1284735600
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
4 seconds
["OR 1 2\n\nOR 2 3\n\nXOR 2 4\n\n! 0 0 2 3"]
0ce667283c449582aa79c64927a4b781
NoteThe array $$$a$$$ in the example is $$$[0, 0, 2, 3]$$$.
The only difference between the easy and hard versions is the constraints on the number of queries.This is an interactive problem.Ridbit has a hidden array $$$a$$$ of $$$n$$$ integers which he wants Ashish to guess. Note that $$$n$$$ is a power of two. Ashish is allowed to ask three different types of queries. They are...
null
The first line of input contains one integer $$$n$$$ $$$(4 \le n \le 2^{16})$$$ — the length of the array. It is guaranteed that $$$n$$$ is a power of two.
standard output
standard input
Python 3
Python
null
train_027.jsonl
5ce5536001501032bbd9e6c2a1e938eb
256 megabytes
["4\n\n0\n\n2\n\n3"]
PASSED
n = int(input()) a = [0] know = 0 pos = [0]*n pos[0] = 1 for i in range(2, n+1): print("XOR", 1, i) x = int(input()) a.append(x) if pos[x] > 0 and know == 0: know = 1 print("OR", pos[x], i) a[0] = int(input())^x pos[x] = i if know == 0: print("OR", 1, pos[1]) x = int(input()) # x = a[0] | (a[0] ^ 1) print...
1605969300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
4 seconds
["11111", "1111110", "0"]
7f855479e9df3405bb29f2a0cb1cb3b3
NoteIn the first example, you can choose the substrings 11010 and 101. $$$f(s_1) = 26$$$, $$$f(s_2) = 5$$$, their bitwise OR is $$$31$$$, and the binary representation of $$$31$$$ is 11111.In the second example, you can choose the substrings 1110010 and 11100.
You are given a string $$$s$$$ consisting of $$$n$$$ characters. Each character of $$$s$$$ is either 0 or 1.A substring of $$$s$$$ is a contiguous subsequence of its characters.You have to choose two substrings of $$$s$$$ (possibly intersecting, possibly the same, possibly non-intersecting — just any two substrings). A...
Print the maximum possible value you can get in binary representation without leading zeroes.
The first line contains one integer $$$n$$$ — the number of characters in $$$s$$$. The second line contains $$$s$$$ itself, consisting of exactly $$$n$$$ characters 0 and/or 1. All non-example tests in this problem are generated randomly: every character of $$$s$$$ is chosen independently of other characters; for each ...
standard output
standard input
Python 3
Python
1,700
train_088.jsonl
68c59b97cfa6f2b5b06a497f09bfadb1
512 megabytes
["5\n11010", "7\n1110010", "4\n0000"]
PASSED
n = int(input()) s = input() s = list(s) i = 0 while s[i] == '0': i += 1 if i == n: break if i == n: print(0) else: s = s[i:] n = len(s) ans = [i for i in s] i = 0 o = 0 while s[i] == '1': o += 1 i += 1 if o == 0: print('0') else: ones ...
1666017300
[ "probabilities" ]
[ 0, 0, 0, 0, 0, 1, 0, 0 ]
2 seconds
["3\n0\n1\n-1"]
389be6455476db86a8a5d9d5343ee35a
NoteIn the first test case, there are 3 good prefixes of $$$t$$$: with length $$$28$$$, $$$30$$$ and $$$32$$$.
You are given string $$$s$$$ of length $$$n$$$ consisting of 0-s and 1-s. You build an infinite string $$$t$$$ as a concatenation of an infinite number of strings $$$s$$$, or $$$t = ssss \dots$$$ For example, if $$$s =$$$ 10010, then $$$t =$$$ 100101001010010...Calculate the number of prefixes of $$$t$$$ with balance e...
Print $$$T$$$ integers — one per test case. For each test case print the number of prefixes or $$$-1$$$ if there is an infinite number of such prefixes.
The first line contains the single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of test cases. Next $$$2T$$$ lines contain descriptions of test cases — two lines per test case. The first line contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 10^5$$$, $$$-10^9 \le x \le 10^9$$$) — the length of string $$...
standard output
standard input
Python 3
Python
1,700
train_004.jsonl
8dca9099c4c5940f13721bd53c96f999
256 megabytes
["4\n6 10\n010010\n5 3\n10101\n1 0\n0\n2 0\n01"]
PASSED
for i in range(int(input())): n,x = map(int,input().split()) s=input() count0=0 l=[] for j in range(n): if s[j]=="0": count0+=1 l.append(count0) else: count0-=1 l.append(count0) a=s.count("0") b=len(s)-a k=a-b if a==b and x==0: print(-1) elif a==b and x in l: print(-1) elif a==b and x n...
1580308500
[ "math", "strings" ]
[ 0, 0, 0, 1, 0, 0, 1, 0 ]
2 seconds
["0\n1\n1\n2\n1\n-1"]
7ad14848b3b9f075477fbf0c5f648c77
NoteFor the $$$1$$$-st test case, since $$$s$$$ and $$$t$$$ are equal, you don't need to apply any operation.For the $$$2$$$-nd test case, you only need to apply one operation on the entire string ab to convert it to ba.For the $$$3$$$-rd test case, you only need to apply one operation on the entire string abc to conve...
You are given two strings $$$s$$$ and $$$t$$$, each of length $$$n$$$ and consisting of lowercase Latin alphabets. You want to make $$$s$$$ equal to $$$t$$$. You can perform the following operation on $$$s$$$ any number of times to achieve it — Choose any substring of $$$s$$$ and rotate it clockwise once, that is, if...
For each test case, output the minimum number of operations to convert $$$s$$$ to $$$t$$$. If it is not possible to convert $$$s$$$ to $$$t$$$, output $$$-1$$$ instead.
The first line of the input contains a single integer $$$t$$$ $$$(1\leq t \leq 2000)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ $$$(1\leq n \leq 2000)$$$ — the length of the strings. The second and the third lines contain...
standard output
standard input
PyPy 3
Python
2,600
train_050.jsonl
7eca10c9f82a669d27abaa16b70ddb7e
256 megabytes
["6\n1\na\na\n2\nab\nba\n3\nabc\ncab\n3\nabc\ncba\n4\nabab\nbaba\n4\nabcc\naabc"]
PASSED
def num(c): return ord(c) - 97 import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) s1 = input().strip() s2 = input().strip() char1 = [0] * 26 char2 = [0] * 26 for c in s1: char1[num(c)] += 1 for c in s2: char2[num(c)] += 1 if ...
1590935700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["3 5\n2 4"]
259e39c9e63e43678e596c0d8c66937c
NoteThe first query is $$$P=17$$$. $$$a=3$$$ and $$$b=5$$$ are valid bases in this case, because $$$17 \bmod 3 = 17 \bmod 5 = 2$$$. There are other pairs which work as well.In the second query, with $$$P=5$$$, the only solution is $$$a=2$$$ and $$$b=4$$$.
Gregor is learning about RSA cryptography, and although he doesn't understand how RSA works, he is now fascinated with prime numbers and factoring them.Gregor's favorite prime number is $$$P$$$. Gregor wants to find two bases of $$$P$$$. Formally, Gregor is looking for two integers $$$a$$$ and $$$b$$$ which satisfy bot...
Your output should consist of $$$t$$$ lines. Each line should consist of two integers $$$a$$$ and $$$b$$$ ($$$2 \le a &lt; b \le P$$$). If there are multiple possible solutions, print any.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Each subsequent line contains the integer $$$P$$$ ($$$5 \le P \le {10}^9$$$), with $$$P$$$ guaranteed to be prime.
standard output
standard input
Python 3
Python
800
train_086.jsonl
1bbc496283cb11c6da06a3c1b29f1900
256 megabytes
["2\n17\n5"]
PASSED
for _ in range(int(input())): print(2,int(input())-1,sep=" ")
1627828500
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["3"]
e1ebaf64b129edb8089f9e2f89a0e1e1
NoteLet's have a look at the example. Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its memb...
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friends...
Output a single number — the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0.
The first line of input contains an integer n — the number of the Beaver's acquaintances. The second line contains an integer k — the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi — indices of people who form the i-th pair of friends. The next line contains an integer m —...
standard output
standard input
Python 3
Python
1,500
train_030.jsonl
c2811e69a9d6318588311d70488e632b
256 megabytes
["9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9"]
PASSED
# maa chudaaye duniya n = int(input()) parents = [i for i in range(n+1)] ranks = [1 for i in range(n+1)] def find(x): if parents[x] != x: parents[x] = find(parents[x]) return parents[x] def union(x, y): xs = find(x) ys = find(y) if xs == ys: return if ranks[xs] > ranks[ys]: parents[ys] = xs elif ranks[ys...
1335016800
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["3", "4"]
0aed14262c135d1624df9814078031ae
NoteIn the first sample test sequence of removing made by Nastya looks like this:"ababcba" "ababcba" "ababcba" "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".So, Nastya will remove only three letters.
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain or...
Print a single integer number, the maximum number of letters that Nastya can remove.
The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| &lt; |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a1, a2, ..., a|t| of letter ...
standard output
standard input
Python 3
Python
1,700
train_003.jsonl
fe64d9b8710f1fcb265559c438395a59
512 megabytes
["ababcba\nabb\n5 3 4 1 7 6 2", "bbbabb\nbb\n1 6 3 4 2 5"]
PASSED
a=input() b=input() c=[i-1 for i in list(map(int,input().split()))] l=0 r=len(a) while r-l>1 : m=l+(r-l)//2#two pointer d=list(a) j=0 for o in range(m):#first half delete value replace with "" d[c[o]]="" for i in range(int(len(a))): if(d[i]==b[j]): j+=1 ...
1488096300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["ababababa", "catcat"]
34dd4c8400ff7a67f9feb1487f2669a6
null
You are given a string $$$t$$$ consisting of $$$n$$$ lowercase Latin letters and an integer number $$$k$$$.Let's define a substring of some string $$$s$$$ with indices from $$$l$$$ to $$$r$$$ as $$$s[l \dots r]$$$.Your task is to construct such string $$$s$$$ of minimum possible length that there are exactly $$$k$$$ po...
Print such string $$$s$$$ of minimum possible length that there are exactly $$$k$$$ substrings of $$$s$$$ equal to $$$t$$$. It is guaranteed that the answer is always unique.
The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 50$$$) — the length of the string $$$t$$$ and the number of substrings. The second line of the input contains the string $$$t$$$ consisting of exactly $$$n$$$ lowercase Latin letters.
standard output
standard input
PyPy 3
Python
1,300
train_008.jsonl
18597ff58ce327c82f61600bc4f9226d
256 megabytes
["3 4\naba", "3 2\ncat"]
PASSED
# -*- coding: utf-8 -*- import sys from itertools import accumulate def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] fo...
1535122200
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["YES\nNO\nYES"]
5afb904f611d963ed3e302faefef3305
NoteIn the first query of the third type $$$k = 3$$$, we can, for example, choose a sequence $$$[1, 2, 3]$$$, since $$$1 \xrightarrow{\text{a}} 2 \xrightarrow{\text{b}} 3$$$ and $$$3 \xrightarrow{\text{a}} 2 \xrightarrow{\text{b}} 1$$$.In the second query of the third type $$$k = 2$$$, and we can't find sequence $$$p_1...
You are given a directed graph consisting of $$$n$$$ vertices. Each directed edge (or arc) labeled with a single character. Initially, the graph is empty.You should process $$$m$$$ queries with it. Each query is one of three types: "$$$+$$$ $$$u$$$ $$$v$$$ $$$c$$$" — add arc from $$$u$$$ to $$$v$$$ with label $$$c$$$...
For each query of the third type, print YES if there exist the sequence $$$v_1, v_2, \dots, v_k$$$ described above, or NO otherwise.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$1 \le m \le 2 \cdot 10^5$$$) — the number of vertices in the graph and the number of queries. The next $$$m$$$ lines contain queries — one per line. Each query is one of three types: "$$$+$$$ $$$u$$$ $$$v$$$ $$$c$$$" ($$$1 \...
standard output
standard input
PyPy 3-64
Python
2,400
train_094.jsonl
504e29b459e6cdcae98ee1b8e3613d53
256 megabytes
["3 11\n+ 1 2 a\n+ 2 3 b\n+ 3 2 a\n+ 2 1 b\n? 3\n? 2\n- 2 1\n- 3 2\n+ 2 1 c\n+ 3 2 d\n? 5"]
PASSED
import os, sys from io import BytesIO, IOBase from collections import defaultdict, deque, Counter from bisect import bisect_left, bisect_right from heapq import heappush, heappop from functools import lru_cache from itertools import accumulate import math import sys # sys.setrecursionlimit(10 ** 6) # Fast...
1614696300
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["11", "11010"]
133eaf241bb1557ba9a3f59c733d34bf
NoteIn the first sample the best strategy is to delete the second digit. That results in number 112 = 310.In the second sample the best strategy is to delete the third or fourth digits — that results in number 110102 = 2610.
The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper.To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of th...
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
standard output
standard input
PyPy 2
Python
1,100
train_009.jsonl
ff02f8a871c066fb6ad910a6c744cabe
256 megabytes
["101", "110010"]
PASSED
a = list(raw_input()) idx = -1 for i in range(len(a)): if a[i] == '0': a.pop(i) idx = i print ''.join(a) break if idx == -1: print ''.join(a[:-1])
1356190200
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["Yes\nNo\nNo\nYes"]
a97e70ad20a337d12dcf79089c16c9f0
NoteIn the first test case, we can simply swap $$$31$$$ and $$$14$$$ ($$$31 + 14 = 45$$$ which is odd) and obtain the non-decreasing array $$$[1,6,14,31]$$$.In the second test case, the only way we could sort the array is by swapping $$$4$$$ and $$$2$$$, but this is impossible, since their sum $$$4 + 2 = 6$$$ is even.I...
You are given an array $$$a_1, a_2, \dots, a_n$$$. You can perform operations on the array. In each operation you can choose an integer $$$i$$$ ($$$1 \le i &lt; n$$$), and swap elements $$$a_i$$$ and $$$a_{i+1}$$$ of the array, if $$$a_i + a_{i+1}$$$ is odd.Determine whether it can be sorted in non-decreasing order usi...
For each test case, print "Yes" or "No" depending on whether you can or can not sort the given array. You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array. The second line of e...
standard output
standard input
Python 3
Python
1,100
train_106.jsonl
a78555172afa167b42e6b761027146a4
256 megabytes
["4\n\n4\n\n1 6 31 14\n\n2\n\n4 2\n\n5\n\n2 9 6 7 10\n\n3\n\n6 6 6"]
PASSED
# cook your dish here # cook your dish here #!/usr/bin/env python from cmath import inf import os from math import ceil, factorial, floor, log, sqrt import re import sys from collections import Counter, defaultdict from itertools import permutations from io import BytesIO, IOBase class newNode: def ...
1644849300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["5", "6", "6", "11"]
40002052843ca0357dbd3158b16d59f4
NoteConsidering the first $$$24$$$ nodes of the system, the node network will look as follows (the nodes $$$1!$$$, $$$2!$$$, $$$3!$$$, $$$4!$$$ are drawn bold):For the first example, Ivy will place the emotion samples at the node $$$1$$$. From here: The distance from Vanessa's first fragment to the node $$$1$$$ is $$$...
Æsir - CHAOS Æsir - V."Everything has been planned out. No more hidden concerns. The condition of Cytus is also perfect.The time right now...... 00:01:12......It's time."The emotion samples are now sufficient. After almost 3 years, it's time for Ivy to awake her bonded sister, Vanessa.The system inside A.R.C.'s Library...
Print a single integer, denoting the minimal sum of path from every fragment to the node with the emotion samples (a.k.a. node $$$P$$$). As a reminder, if there are multiple fragments at the same node, the distance from that node to $$$P$$$ needs to be counted multiple times as well.
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — number of fragments of Vanessa's mind. The second line contains $$$n$$$ integers: $$$k_1, k_2, \ldots, k_n$$$ ($$$0 \le k_i \le 5000$$$), denoting the nodes where fragments of Vanessa's mind are located: the $$$i$$$-th fragment is at the node with a ...
standard output
standard input
PyPy 3
Python
2,700
train_043.jsonl
79d3d1fb0ab362b14234d83001540a9b
512 megabytes
["3\n2 1 4", "4\n3 1 4 4", "4\n3 1 4 1", "5\n3 1 4 1 5"]
PASSED
from sys import stdin, stdout prime = list() factor = list() count = list() dist = list() N = 0 def find_prime(): global prime for i in range(2, 5010): is_prime = True for j in prime: if i % j == 0: is_prime = False break if is_prime is True:...
1579440900
[ "number theory", "math", "trees", "graphs" ]
[ 0, 0, 1, 1, 1, 0, 0, 1 ]
1 second
["? 2 3 4\n? 1 3 4\n? 1 2 4\n? 1 2 3\n! 3"]
712bef1b0f737cb9c2b35a96498d50bc
NoteIn the example, $$$n = 4$$$, $$$k = 3$$$, $$$m = 3$$$, $$$a = [2, 0, 1, 9]$$$.
This problem is interactive.We have hidden an array $$$a$$$ of $$$n$$$ pairwise different numbers (this means that no two numbers are equal). You can get some information about this array using a new device you just ordered on Amazon. This device can answer queries of the following form: in response to the positions of...
null
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1\le k &lt; n \le 500$$$) — the length of the array and the number of the elements in the query. It is guaranteed that number $$$m$$$ satisfies $$$1\le m \le k$$$, elements $$$a_1, a_2, \dots, a_n$$$ of the array satisfy $$$0\le a_i \le 10^9$$$, and all of th...
standard output
standard input
PyPy 3
Python
1,900
train_006.jsonl
18d1f2aa8e6deaa9456d0003de0cfe7c
256 megabytes
["4 3\n4 9\n4 9\n4 9\n1 2"]
PASSED
import sys n, k = map(int, input().split()) k1 = 0 k2 = 0 b1 = 0 b2 = 0 for i in range(k + 1): print('?', end=' ') for j in range(k + 1): if i != j: print(j + 1, end=' ') sys.stdout.flush() a, x = map(int, input().split()) if i == 0: b1 = x if x == b1: k1 += ...
1577628300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["0\n1\n3\n1"]
7226a7d2700ee52f52d417f404c42ab7
NoteIn the first test case, we have $$$s=0$$$ so all numbers are equal to $$$0$$$ and there isn't any number equal to $$$49$$$.In the second test case, we have $$$s=1$$$. There are two possible sequences: $$$[0, 1]$$$ or $$$[1, 0]$$$. In both cases, the number $$$1$$$ appears just once. In the third test case, we have ...
Luis has a sequence of $$$n+1$$$ integers $$$a_1, a_2, \ldots, a_{n+1}$$$. For each $$$i = 1, 2, \ldots, n+1$$$ it is guaranteed that $$$0\leq a_i &lt; n$$$, or $$$a_i=n^2$$$. He has calculated the sum of all the elements of the sequence, and called this value $$$s$$$. Luis has lost his sequence, but he remembers the v...
For each test case, print one integer — the number of elements in the sequence which are equal to $$$n^2$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2\cdot 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$n$$$ and $$$s$$$ ($$$1\le n&lt; 10^6$$$, $$$0\le s \le 10^{18}$$$). It is guaranteed that the ...
standard output
standard input
Python 3
Python
800
train_110.jsonl
ddf7915b016cb6be917db4bc7de960b2
256 megabytes
["4\n\n7 0\n\n1 1\n\n2 12\n\n3 12"]
PASSED
t=int(input()) for i in range(t): x=input() a=x.split() print(int(a[1])//(int(a[0]))**2)
1646408100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["3\n1 4 5", "8\n1 5 4 8 10 6 3 7"]
0dd041c0665d3ec4c46c2c791c17192d
NoteThe first example case achieves a strength of 1/2. No other subset is strictly better.The second example case achieves a strength of 1. Note that the subset doesn't necessarily have to be connected.
Nudist Beach is planning a military operation to attack the Life Fibers. In this operation, they will attack and capture several cities which are currently under the control of the Life Fibers.There are n cities, labeled from 1 to n, and m bidirectional roads between them. Currently, there are Life Fibers in every city...
The first line should contain an integer r, denoting the size of an optimum set (1 ≤ r ≤ n - k). The second line should contain r integers, denoting the cities in the set. Cities may follow in an arbitrary order. This line should not contain any of the cities with fortresses. If there are multiple possible answers, pr...
The first line of input contains three integers n, m, k (2  ≤  n  ≤ 100 000, 1 ≤ m ≤ 100 000, 1 ≤ k ≤ n - 1). The second line of input contains k integers, representing the cities with fortresses. These cities will all be distinct. The next m lines contain the roads. The i-th of these lines will have 2 integers ai, bi...
standard output
standard input
Python 3
Python
2,300
train_052.jsonl
8817438774cfd979a67caada560555f8
256 megabytes
["9 8 4\n3 9 6 8\n1 2\n1 3\n1 4\n1 5\n2 6\n2 7\n2 8\n2 9", "10 8 2\n2 9\n1 3\n2 9\n4 5\n5 6\n6 7\n7 8\n8 10\n10 4"]
PASSED
import heapq def read_data(): ''' n: number of cities m: number of roads k: initial numuber of fortresses of Life Fibers Es: list of edges fs: fs[i] = True -> city i is under control of Life Fibers gs: gs[i] number of edges connected to city i hs: hs[i] number of adjacent cities under c...
1435163400
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
3 seconds
["YES\n1 3 5\nNO\nNO"]
7f5269f3357827b9d8682d70befd3de1
null
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to...
For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The di...
The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of elements in the array and the number of subsegments, respectivel...
standard output
standard input
PyPy 3
Python
1,200
train_007.jsonl
8c040a7744f61d6ad7a8755fac6e80f0
256 megabytes
["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"]
PASSED
from sys import stdin,stdout t=int(stdin.readline()) for _ in range(t): n,k=map(int,stdin.readline().split()) l=list(map(int,stdin.readline().strip().split())) count=0 i,m=0,0 ans=[] while i<n: if l[i]%2==1: ans.append(i+1) i+=1 ...
1563978900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["2\n4\n830690567"]
0b3f93005a639a9a51279fae65c15301
NoteFor $$$n = 2$$$, both permutations $$$[1, 2]$$$, and $$$[2, 1]$$$ are almost perfect.For $$$n = 3$$$, there are only $$$6$$$ permutations. Having a look at all of them gives us: $$$[1, 2, 3]$$$ is an almost perfect permutation. $$$[1, 3, 2]$$$ is an almost perfect permutation. $$$[2, 1, 3]$$$ is an almost perfec...
A permutation $$$p$$$ of length $$$n$$$ is called almost perfect if for all integer $$$1 \leq i \leq n$$$, it holds that $$$\lvert p_i - p^{-1}_i \rvert \le 1$$$, where $$$p^{-1}$$$ is the inverse permutation of $$$p$$$ (i.e. $$$p^{-1}_{k_1} = k_2$$$ if and only if $$$p_{k_2} = k_1$$$).Count the number of almost perfec...
For each test case, output a single integer — the number of almost perfect permutations of length $$$n$$$ modulo $$$998244353$$$.
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The description of each test case follows. The first and only line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 3 \cdot 10^5$$$) — the length of the permutation. It is guaranteed that the sum...
standard output
standard input
PyPy 3-64
Python
2,400
train_106.jsonl
53ea8df8ffb5e9f51cdc8c8ef7db7ad8
256 megabytes
["3\n\n2\n\n3\n\n50"]
PASSED
mod = 998244353 def main(): import sys input = sys.stdin.readline # comb init nmax = 3 * 10 ** 5 + 10 # change here fac = [0] * nmax finv = [0] * nmax inv = [0] * nmax fac[0] = 1 fac[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2, nmax...
1662474900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["3\n6\n1\n1"]
d107db1395ded62904d0adff164e5c1e
NoteIn the first test case we can divide the elements as follows: $$$[4, 8]$$$. It is a $$$4$$$-divisible array because $$$4+8$$$ is divisible by $$$4$$$. $$$[2, 6, 2]$$$. It is a $$$4$$$-divisible array because $$$2+6$$$ and $$$6+2$$$ are divisible by $$$4$$$. $$$[9]$$$. It is a $$$4$$$-divisible array because it c...
You are given an array $$$a_1, a_2, \ldots, a_n$$$ consisting of $$$n$$$ positive integers and a positive integer $$$m$$$.You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.Let's call an array $$$m$$$-divisible if for each two adjacent numbers in the arra...
For each test case print the answer to the problem.
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 two integers $$$n$$$, $$$m$$$ $$$(1 \le n \le 10^5, 1 \le m \le 10^5)$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i...
standard output
standard input
Python 3
Python
1,200
train_087.jsonl
ba3005307e031255389f78c6f868f846
256 megabytes
["4\n6 4\n2 2 8 6 9 4\n10 8\n1 1 1 5 2 4 4 8 6 7\n1 1\n666\n2 2\n2 4"]
PASSED
t = int(input()) for p in range(t): l = list(map(int, input().rstrip().split())) n = l[0] m = l[1] res = [] l1 = list(map(int, input().rstrip().split())) mydict = {} count = 0 for a in range(m): mydict[a] = 0 for i in l1: mydict[i % m] += 1 for j in...
1615991700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["202\n13\n19"]
fe9279aa95148f0887cc7eeb89afbac6
NoteIn the first test case, to reach $$$(2, 2)$$$ you need to make at least one turn, so your path will consist of exactly $$$2$$$ segments: one horizontal of length $$$2$$$ and one vertical of length $$$2$$$. The cost of the path will be equal to $$$2 \cdot c_1 + 2 \cdot c_2 = 26 + 176 = 202$$$.In the second test case...
Let's say you are standing on the $$$XY$$$-plane at point $$$(0, 0)$$$ and you want to reach point $$$(n, n)$$$.You can move only in two directions: to the right, i. e. horizontally and in the direction that increase your $$$x$$$ coordinate, or up, i. e. vertically and in the direction that increase your $$$y$$$ coo...
For each test case, print the minimum possible cost of the path from $$$(0, 0)$$$ to $$$(n, n)$$$ consisting of at most $$$n$$$ alternating segments.
The first line contains the single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$2 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 10^9$$$) — the c...
standard output
standard input
PyPy 3-64
Python
1,500
train_104.jsonl
0c0aaa7349c8d7260c199b8c4ecbbeb0
256 megabytes
["3\n2\n13 88\n3\n2 3 1\n5\n4 3 2 1 4"]
PASSED
import random from datetime import datetime import math now = datetime.now() cazuri=int(input()) for tt in range(cazuri): #n,c=map(int,input().split()) n=int(input()) #stringul=input() bloc=list(map(int,input().split())) pare=[] impare=[] suma_pare=0 suma_impare=0 cate...
1616079000
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1 7\n3 9\n5 10"]
a9cd97046e27d799c894d8514e90a377
null
You are given a range of positive integers from $$$l$$$ to $$$r$$$.Find such a pair of integers $$$(x, y)$$$ that $$$l \le x, y \le r$$$, $$$x \ne y$$$ and $$$x$$$ divides $$$y$$$.If there are multiple answers, print any of them.You are also asked to answer $$$T$$$ independent queries.
Print $$$T$$$ lines, each line should contain the answer — two integers $$$x$$$ and $$$y$$$ such that $$$l \le x, y \le r$$$, $$$x \ne y$$$ and $$$x$$$ divides $$$y$$$. The answer in the $$$i$$$-th line should correspond to the $$$i$$$-th query from the input. If there are multiple answers, print any of them.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 1000$$$) — the number of queries. Each of the next $$$T$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 998244353$$$) — inclusive borders of the range. It is guaranteed that testset only includes queries, which have at least one s...
standard output
standard input
Python 3
Python
800
train_006.jsonl
a18b61278f52aa0381e702af35798055
256 megabytes
["3\n1 10\n3 14\n1 10"]
PASSED
t=int(input()) for _ in range(t): l,r=map(int,input().split()) print(l,l*2)
1546007700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["4\n2 1 3\n1 2\n2 4 6\n1 5", "1\n6 1 2 3 4 5 6"]
159365b2f037647fbaa656905e6f5252
NoteIn the first sample output:After sorting the first subsequence we will get sequence 1 2 3 6 5 4.Sorting the second subsequence changes nothing.After sorting the third subsequence we will get sequence 1 2 3 4 5 6.Sorting the last subsequence changes nothing.
You are given a sequence a1, a2, ..., an consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order.Sorting integers in a subsequence is a...
In the first line print the maximum number of subsequences k, which the original sequence can be split into while fulfilling the requirements. In the next k lines print the description of subsequences in the following format: the number of elements in subsequence ci (0 &lt; ci ≤ n), then ci integers l1, l2, ..., lci (1...
The first line of input data contains integer n (1 ≤ n ≤ 105) — the length of the sequence. The second line of input data contains n different integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct.
standard output
standard input
Python 3
Python
1,400
train_036.jsonl
eafee7208e6d2f9ec2cacfff6cfbab04
256 megabytes
["6\n3 2 1 6 5 4", "6\n83 -75 -49 11 37 62"]
PASSED
def binSearch(arr, el): if len(arr) == 0: return -1 l, p = 0, len(arr)-1 while l != p: s = (l+p) // 2 if arr[s] < el: l = s + 1 else: p = s return l if arr[l] == el else -1 n = int(input()) a = [int(i) for i in input().split()] s = sorted(a) subsList = [...
1503592500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1 2 3 4\n1 3\n-1\n1 2 2 5 5"]
91d510b68f04971b871718460663ca3b
null
You are asked to build an array $$$a$$$, consisting of $$$n$$$ integers, each element should be from $$$1$$$ to $$$k$$$.The array should be non-decreasing ($$$a_i \le a_{i+1}$$$ for all $$$i$$$ from $$$1$$$ to $$$n-1$$$). You are also given additional constraints on it. Each constraint is of one of three following type...
For each testcase, determine if there exists a non-decreasing array that satisfies all conditions. If there is no such array, then print -1. Otherwise, print any valid array — $$$n$$$ integers from $$$1$$$ to $$$k$$$.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains three integers $$$n, m$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^4$$$; $$$0 \le m \le 2 \cdot 10^4$$$; $$$2 \le k \le 10$$$). The $$$i$$$-th of the next $$$m$$$ lines contains a ...
standard output
standard input
PyPy 3-64
Python
2,800
train_083.jsonl
a7700d58ffbd8fbbf545a770cbb2fdb8
512 megabytes
["4\n\n4 0 4\n\n2 2 3\n\n3 1 2 3\n\n1 2 2\n\n3 3 2\n\n1 1 1\n\n2 2 3 2\n\n3 2 3 2\n\n5 5 5\n\n3 2 5 7\n\n2 4 5 10\n\n3 4 5 6\n\n3 3 4 7\n\n2 1 5 7"]
PASSED
import sys input = sys.stdin.readline # TwoSat code from PyRival: https://github.com/cheran-senthil/PyRival/blob/9947ae98b7884614d98a5860764e85798c0cddfa/pyrival/data_structures/TwoSat.py def find_SCC(graph): SCC, S, P = [], [], [] depth = [0] * len(graph) stack = list(range(len(graph))) while stack: ...
1655044500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["YES", "NO", "NO", "NO", "NO", "NO"]
6405161be280fea943201fa00ef6f448
NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the...
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In oth...
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower).
The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
standard output
standard input
Python 3
Python
1,300
train_000.jsonl
37ede566651e9e71eb35d9e137c401fa
256 megabytes
["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."]
PASSED
n,m=map(int,input().split()) a=[] for i in range(n): a.append(list(input())) b=0 for i in a: b+=i.count('*') x=y=-1 for i in range(1,n-1): for j in range(1,m-1): if a[i][j]==a[i][j-1]==a[i][j+1]==a[i-1][j]==a[i+1][j]=='*': x=i y=j break if x==y==-1: exit(print...
1560258300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 2 2 3\n\n! 1 3"]
28a14d68fe01c4696ab1ccb7f3932901
NoteThe tree from the first test is shown below, and the hidden nodes are $$$1$$$ and $$$3$$$.
Note that the only difference between the easy and hard version is the constraint on the number of queries. You can make hacks only if all versions of the problem are solved.This is an interactive problem.You are given a tree consisting of $$$n$$$ nodes numbered with integers from $$$1$$$ to $$$n$$$. Ayush and Ashish c...
null
The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. Please note, how the interaction process is organized. The first line of each test case consists of a single integer $$$n$$$ $$$(2 \le n \le 1000)$$$ — the number of nodes in the tree. The next $$$n - 1$$$ lines consis...
standard output
standard input
Python 3
Python
2,400
train_005.jsonl
9375afcca41149cfb5fbe1002e9e7a02
256 megabytes
["1\n3\n1 2\n1 3\n\n1 1\n\n2 3\n\n3 1\n\n3 1\n\nCorrect"]
PASSED
from collections import deque def NC_Dij(lis,start): ret = [float("inf")] * len(lis) ret[start] = 0 q = deque([start]) plis = [i for i in range(len(lis))] while len(q) > 0: now = q.popleft() for nex in lis[now]: if ret[nex] > ret[now] + 1: ret[nex...
1592663700
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
3 seconds
["1 0 1 1", "1 1 2 3 4 3 1"]
fa71dbe5a8399c963bb2dda121a9bec0
NoteHere are all possible ways to separate all computers into $$$4$$$ groups in the second example: $$$\{1, 2\}, \{3, 4\}, \{5\}, \{6, 7\}$$$; $$$\{1\}, \{2\}, \{3, 4\}, \{5, 6, 7\}$$$; $$$\{1, 2\}, \{3\}, \{4\}, \{5, 6, 7\}$$$.
There are $$$n$$$ computers in the company network. They are numbered from $$$1$$$ to $$$n$$$.For each pair of two computers $$$1 \leq i &lt; j \leq n$$$ you know the value $$$a_{i,j}$$$: the difficulty of sending data between computers $$$i$$$ and $$$j$$$. All values $$$a_{i,j}$$$ for $$$i&lt;j$$$ are different.You wa...
Print $$$n$$$ integers: the $$$k$$$-th of them should be equal to the number of possible ways to divide computers into $$$k$$$ groups, such that all required conditions are satisfied, modulo $$$998\,244\,353$$$.
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1500$$$): the number of computers. The $$$i$$$-th of the next $$$n$$$ lines contains $$$n$$$ integers $$$a_{i,1}, a_{i,2}, \ldots, a_{i,n}$$$($$$0 \leq a_{i,j} \leq \frac{n (n-1)}{2}$$$). It is guaranteed that: for all $$$1 \leq i \leq n$$$ $$$a_{i,i...
standard output
standard input
PyPy 3
Python
2,700
train_041.jsonl
760f91f2cf5fbaee4a8dc55fce18e84b
256 megabytes
["4\n0 3 4 6\n3 0 2 1\n4 2 0 5\n6 1 5 0", "7\n0 1 18 15 19 12 21\n1 0 16 13 17 20 14\n18 16 0 2 7 10 9\n15 13 2 0 6 8 11\n19 17 7 6 0 4 5\n12 20 10 8 4 0 3\n21 14 9 11 5 3 0"]
PASSED
# import itertools as it # import functools as ft import math teststring = """4 0 3 4 6 3 0 2 1 4 2 0 5 6 1 5 0 """ online = __file__ != "/home/jhli/py/Grakn/Problem_G2.py" true, false = True, False if True: def spitout(): for c in teststring.splitlines(): yield c _ito = spitout() ...
1601476500
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1 second
["4.2426406871", "6.1622776602"]
900a509495f4f63f4fa5b66b7edd84f7
NoteThe first example is shown on the left picture while the second example us shown on the right picture below. The avenue is shown with blue, the origin is shown with the black dot.
In this problem we consider a very simplified model of Barcelona city.Barcelona can be represented as a plane with streets of kind $$$x = c$$$ and $$$y = c$$$ for every integer $$$c$$$ (that is, the rectangular grid). However, there is a detail which makes Barcelona different from Manhattan. There is an avenue called A...
Find the minimum possible travel distance between $$$A$$$ and $$$B$$$. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 1...
The first line contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$-10^9\leq a, b, c\leq 10^9$$$, at least one of $$$a$$$ and $$$b$$$ is not zero) representing the Diagonal Avenue. The next line contains four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$ and $$$y_2$$$ ($$$-10^9\leq x_1, y_1, x_2, y_2\leq 10^9$$$) denot...
standard output
standard input
Python 3
Python
1,900
train_005.jsonl
701fb48b8a43d491c2907c65e77732ea
256 megabytes
["1 1 -3\n0 3 3 0", "3 1 -9\n0 3 3 -1"]
PASSED
from math import ceil,floor a,b,c = (int(e) for e in input().split(' ')) x1,y1,x2,y2 = (int(e) for e in input().split(' ')) def dist(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**.5 def m_dist(x1,y1,x2,y2): return abs(x1-x2)+abs(y1-y2) def project(x,y): if(a==0 and b==0):return (float('inf'),float('inf')) r...
1542557100
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
1 second
["? 5 6\n\n? 3 1\n\n? 1 2\n\n! 4"]
a291ee66980d8b5856b24d1541e66fd0
NoteNote that the example interaction contains extra empty lines so that it's easier to read. The real interaction doesn't contain any empty lines and you shouldn't print any extra empty lines as well.The image below demonstrates the tree in the sample test:
This is an interactive problem.After getting AC after 13 Time Limit Exceeded verdicts on a geometry problem, Kuroni went to an Italian restaurant to celebrate this holy achievement. Unfortunately, the excess sauce disoriented him, and he's now lost!The United States of America can be modeled as a tree (why though) with...
null
null
standard output
standard input
Python 3
Python
1,900
train_026.jsonl
ba187886f099ff7620afdc75f4593b91
256 megabytes
["6\n1 4\n4 2\n5 3\n6 3\n2 3\n\n3\n\n4\n\n4"]
PASSED
import collections import sys def getAnc(u,v): print('? {} {}'.format(u,v)) w = int(input()) sys.stdout.flush() return w def f(): n = int(input()) neibors = [set() for i in range(n+1)] for i in range(n-1): a, b = [int(s) for s in input().split()] neibors[a].add(b) nei...
1583246100
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["YES\nabacaba", "NO", "YES\naaaaaaaaa"]
02845c8982a7cb6d29905d117c4a1079
null
While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the password on pieces of paper, one for each piece of paper, and threw the password ...
If Tanya made a mistake somewhere during the game and the strings that correspond to the given set of substrings don't exist, print "NO". If it is possible to restore the string that corresponds to given set of substrings, print "YES", and then print any suitable password option.
The first line contains integer n (1 ≤ n ≤ 2·105), the number of three-letter substrings Tanya got. Next n lines contain three letters each, forming the substring of dad's password. Each character in the input is a lowercase or uppercase Latin letter or a digit.
standard output
standard input
Python 3
Python
2,500
train_043.jsonl
504146461e3f019f8702cff9d68b165b
256 megabytes
["5\naca\naba\naba\ncab\nbac", "4\nabc\nbCb\ncb1\nb13", "7\naaa\naaa\naaa\naaa\naaa\naaa\naaa"]
PASSED
n = int(input()) g = {} ins = {} outs = {} vs = set() for _ in range(n): s = input().strip() left = s[:-1] right = s[1:] g.setdefault(left, []).append(right) outs[left] = outs.get(left, 0) + 1 ins[right] = ins.get(right, 0) + 1 vs.add(left) vs.add(right) # print(g) # print(outs) #...
1422376200
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["3\naca\nba\nca", "0"]
dd7ccfee8c2a19bf47d65d5a62ac0071
NoteThe first test was analysed in the problem statement. In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix.
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know lin...
On the first line print integer k — a number of distinct possible suffixes. On the next k lines print suffixes. Print suffixes in lexicographical (alphabetical) order.
The only line contains a string s (5 ≤ |s| ≤ 104) consisting of lowercase English letters.
standard output
standard input
Python 3
Python
1,800
train_006.jsonl
f48d2bfb0aa9858161bdb7fd198e3620
256 megabytes
["abacabaca", "abaca"]
PASSED
s = input() n = len(s) res = set() from collections import defaultdict two = ["$", "", "$"] thr = ["$", "", "$"] works = lambda w, i : (two[i] != "$" and w != two[i]) or (thr[i] != "$" and w != thr[i]) i = n - 2 while i > 4: ntwo = s[i: i + 2] if works(ntwo, 1): res.add(ntwo) else: ntwo ...
1461947700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["3", "1"]
c547e32f114546638973e0f0dd16d1a4
NoteIn the first sample any pair (i, j) will do, so the answer is 3.In the second sample only pair (1, 2) will do.
Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence: f(0) = 0; f(2·x) = f(x); f(2·x + 1) = f(x) + 1. Dima wonders, how many pairs of indexes (i, j) (1 ≤ i &lt; j ≤ n) are there...
In a single line print the answer to the problem. Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
The first line contains integer n (1 ≤ n ≤ 105). The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). The numbers in the lines are separated by single spaces.
standard output
standard input
Python 3
Python
1,400
train_039.jsonl
895a477819d71788a14add9a33757af1
256 megabytes
["3\n1 2 4", "3\n5 3 1"]
PASSED
def f(x): return str(bin(x)).count('1') n = int(input()) a = list(map(int, input().split())) ans = [f(x) for x in a] # print(ans) s = set(ans) counts = {x:ans.count(x) for x in s} # print(counts) count = 0 for item in counts: count += (counts[item]*(counts[item]-1))//2 print(count)
1360769400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2\n0\n3"]
bfc2e7de37db4a0a74cdd55f2124424a
NoteIn the first test case, if you select indices $$$3, 4$$$ at the $$$1$$$-st second and $$$4$$$ at the $$$2$$$-nd second, then $$$a$$$ will become $$$[1, 7, 7, 8]$$$. There are some other possible ways to make $$$a$$$ nondecreasing in $$$2$$$ seconds, but you can't do it faster.In the second test case, $$$a$$$ is alr...
You have an array $$$a$$$ of length $$$n$$$. For every positive integer $$$x$$$ you are going to perform the following operation during the $$$x$$$-th second: Select some distinct indices $$$i_{1}, i_{2}, \ldots, i_{k}$$$ which are between $$$1$$$ and $$$n$$$ inclusive, and add $$$2^{x-1}$$$ to each corresponding posi...
For each test case, print the minimum number of seconds in which you can make $$$a$$$ nondecreasing.
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 single integer $$$n$$$ ($$$1 \le n \le 10^{5}$$$) — the length of array $$$a$$$. It is guaranteed that the sum of values of $$$n$$$ over all test cases in the input does not ...
standard output
standard input
Python 3
Python
1,500
train_010.jsonl
199130a00997bbfa57cd8fe0621e5b2f
256 megabytes
["3\n4\n1 7 6 5\n5\n1 2 3 4 5\n2\n0 -4"]
PASSED
#logic#####maintain two pointer that will maintain the maximum difference between #two values and values that are not follwing the a<=b condition def powerof2(x): i=0 while 2**i<=x: i+=1 return i from sys import stdout for _ in range(int(input())): n=int(input()) l=list(map(int,input().split...
1586700300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["144", "48", "4", "9"]
c9b4ff8729ab152b7c58dd9fdb5d89a7
null
You have a large rectangular board which is divided into $$$n \times m$$$ cells (the board has $$$n$$$ rows and $$$m$$$ columns). Each cell is either white or black.You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $$$2^w$$$, where $$$w$$$ is the number of white cell...
Print one integer — the sum of values of the board over all $$$2^w$$$ possible ways to paint it, taken modulo $$$998\,244\,353$$$.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 3 \cdot 10^5$$$; $$$nm \le 3 \cdot 10^5$$$) — the number of rows and columns, respectively. Then $$$n$$$ lines follow, each line contains a string of $$$m$$$ characters. The $$$j$$$-th character in the $$$i$$$-th string is * if the $$$j$$$-th c...
standard output
standard input
PyPy 3-64
Python
2,100
train_089.jsonl
fa702afe87e2c0e29056f9360786072d
512 megabytes
["3 4\n**oo\noo*o\n**oo", "3 4\n**oo\noo**\n**oo", "2 2\noo\no*", "1 4\noooo"]
PASSED
import sys input = sys.stdin.readline I = lambda : list(map(int,input().split())) n,m = I() l = [] w = 0 mod = 998244353 an = 0 N = 3*10**5 + 20 dp = [0]*(N) s = prev = dp[2] = 1 for i in range(n): l.append(input().strip()) w += l[-1].count('o') for i in range(w-2): dp[i+3] = (2*prev + ...
1618238100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["aaa", "nisteaadddiiklooprrvz", "ababacabcc"]
9dc956306e2826229e393657f2d0d9bd
NoteIn the third sample, this optimal solutions has three non-overlaping substrings equal to either b or c on positions 1 – 2 (ab), 3 – 4 (ab), 5 – 7 (aca). In this sample, there exist many other optimal solutions, one of them would be acaababbcc.
Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping substrings equal either to b or c as possible. Substring of string x i...
Find one of possible strings k, as described in the problem statement. If there are multiple possible answers, print any of them.
The first line contains string a, the second line contains string b, and the third line contains string c (1 ≤ |a|, |b|, |c| ≤ 105, where |s| denotes the length of string s). All three strings consist only of lowercase English letters. It is possible that b and c coincide.
standard output
standard input
PyPy 2
Python
1,800
train_008.jsonl
0e795f753c9fd7ab66ee9b3145a19008
256 megabytes
["aaa\na\nb", "pozdravstaklenidodiri\nniste\ndobri", "abbbaaccca\nab\naca"]
PASSED
__author__ = 'trunghieu11' from string import ascii_lowercase def main(): s = raw_input() a = raw_input() b = raw_input() totalS = dict() totalA = dict() totalB = dict() for c in ascii_lowercase: totalS.setdefault(c, s.count(c)) totalA.setdefault(c, a.count(c)) tot...
1434127500
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["1\n1\n-1\n6\n1 2 3 5 6 7"]
afe8710473db82f8d53d28dd32646774
NoteIn the first test case, you can take the item of weight $$$3$$$ and fill the knapsack just right.In the second test case, all the items are larger than the knapsack's capacity. Therefore, the answer is $$$-1$$$.In the third test case, you fill the knapsack exactly in half.
You have a knapsack with the capacity of $$$W$$$. There are also $$$n$$$ items, the $$$i$$$-th one has weight $$$w_i$$$. You want to put some of these items into the knapsack in such a way that their total weight $$$C$$$ is at least half of its size, but (obviously) does not exceed it. Formally, $$$C$$$ should satisfy:...
For each test case, if there is no solution, print a single integer $$$-1$$$. If there exists a solution consisting of $$$m$$$ items, print $$$m$$$ in the first line of the output and $$$m$$$ integers $$$j_1$$$, $$$j_2$$$, ..., $$$j_m$$$ ($$$1 \le j_i \le n$$$, all $$$j_i$$$ are distinct) in the second line of the out...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains integers $$$n$$$ and $$$W$$$ ($$$1 \le n \le 200\,000$$$, $$$1\le W \le 10^{18}$$$). The second line of each test c...
standard output
standard input
PyPy 3
Python
1,300
train_003.jsonl
f5f0a75f2b5579756d5a897ff38c4d90
256 megabytes
["3\n1 3\n3\n6 2\n19 8 19 69 9 4\n7 12\n1 1 1 17 1 1 1"]
PASSED
from sys import stdin,stdout from math import ceil for _ in range(int(stdin.readline())): # n=int(stdin.readline()) n,w=list(map(int,stdin.readline().split())) a=list(map(int,stdin.readline().split())) l=[] for i in range(n): if a[i]>w:continue l+=[[a[i],i]] l.sort();n=len(l) ...
1605450900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
6 seconds
["2\n5"]
951437dba30c662838b6832b194b5efe
null
You are given a rooted tree consisting of n vertices. Each vertex has a number written on it; number ai is written on vertex i.Let's denote d(i, j) as the distance between vertices i and j in the tree (that is, the number of edges in the shortest path from i to j). Also let's denote the k-blocked subtree of vertex x as...
Print m integers. i-th of them has to be equal to the answer to i-th query.
The first line contains two integers n and r (1 ≤ r ≤ n ≤ 100000) — the number of vertices in the tree and the index of the root, respectively. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers written on the vertices. Then n - 1 lines follow, each containing two integers x and y (1 ≤ x, ...
standard output
standard input
PyPy 2
Python
2,300
train_060.jsonl
636ee8d926b7ae419532b091e83824c8
512 megabytes
["5 2\n1 3 2 3 5\n2 3\n5 1\n3 4\n4 1\n2\n1 2\n2 3"]
PASSED
py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange def sync_with_stdio(b): if b: return import os, sys from io import BytesIO, IOBase # FastIO for PyPy2 and PyPy3 (works with interactive) by Pajenegod class FastI(object): def ...
1511449500
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["Yes\nYes\nYes\nYes\nNo\nNo\nNo\nNo"]
02a94c136d3fb198025242e91264823b
null
A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are n...
Print $$$n$$$ lines, one line per a string in the input. The line should contain "Yes" if the corresponding string is diverse and "No" if the corresponding string is not diverse. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.
The first line contains integer $$$n$$$ ($$$1 \le n \le 100$$$), denoting the number of strings to process. The following $$$n$$$ lines contains strings, one string per line. Each string contains only lowercase Latin letters, its length is between $$$1$$$ and $$$100$$$, inclusive.
standard output
standard input
PyPy 2
Python
800
train_012.jsonl
ead1164382ae45ce5521ff61c97a23fb
256 megabytes
["8\nfced\nxyz\nr\ndabcef\naz\naa\nbad\nbabc"]
PASSED
from sys import stdin lines = stdin.readlines() n = int(lines[0]) dikte = {} alphabet = "abcdefghijklmnopqrstuvwxyz" j = 1 for i in alphabet: dikte[i] = j j += 1 for i in range(1,n+1): c = lines[i][:-1] c2 = (sorted(c)) liste = [] flag = True for j in c2: if j not in liste: ...
1554041100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
3 seconds
["1", "2"]
2535fc09ce74b829c26e1ebfc1ee17c6
NoteIn the first sample, Daru should reorder the boxes after adding box 3 to the stack.In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack.
Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the stack, and n of which are to remove a box from the top of the stack and throw...
Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands.
The first line of input contains the integer n (1 ≤ n ≤ 3·105) — the number of boxes. Each of the next 2n lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer x (1 ≤ x ≤ n) follows, indicating that Daru should add the box with number x to the top of the stack. It is guar...
standard output
standard input
Python 3
Python
1,500
train_026.jsonl
2b55fadeb0f40cb59bef1a182aaf4c1d
256 megabytes
["3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove"]
PASSED
n=int(input()) st=[] ans=0 c=0 for _ in range(2*n): s=input() if s=="remove": if len(st)==0 or c+1==st[-1] : if len(st)!=0: st.pop(-1) c+=1 else: ans+=1 c+=1 st=[] else: st.append(int(s[4:])) #print (st,end=" ") #print (ans) print (ans)
1498401300
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["4\n10\n0\n-1"]
589f3f7366d1e0f9185ed0926f5a10bb
NoteIn the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.In the third example, there is no need to make any new submiss...
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the sma...
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y &gt; 0; q &gt; 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≤ 5 must be ...
standard output
standard input
Python 3
Python
1,700
train_022.jsonl
3250c5ec22718575ee713bdced1eae72
256 megabytes
["4\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1"]
PASSED
def check(k): n1 = k*p - x n2 = k*q - y assert(n1 >= 0) return n1 <= n2 t = int(input()) for _ in range(t): [x, y, p, q] = list(map(int, input().split(" "))) if p == 0 and x > 0: print(-1) continue if p == 0 and x == 0: print(0) continue st = max((x+p-1)//p, (y+q-1)//q) ...
1494171900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
4 seconds
["OR 1 2\n\nOR 2 3\n\nXOR 2 4\n\n! 0 0 2 3"]
efa7be3ab630a3797d5eb7a37202fb76
NoteThe array $$$a$$$ in the example is $$$[0, 0, 2, 3]$$$.
The only difference between the easy and hard versions is the constraints on the number of queries.This is an interactive problem.Ridbit has a hidden array $$$a$$$ of $$$n$$$ integers which he wants Ashish to guess. Note that $$$n$$$ is a power of two. Ashish is allowed to ask three different types of queries. They are...
null
The first line of input contains one integer $$$n$$$ $$$(4 \le n \le 2^{16})$$$ — the length of the array. It is guaranteed that $$$n$$$ is a power of two.
standard output
standard input
PyPy 2
Python
null
train_027.jsonl
21d612f8faf5e09689e4e985373742d7
256 megabytes
["4\n\n0\n\n2\n\n3"]
PASSED
from collections import Counter, defaultdict, deque import bisect import heapq from sys import stdin, stdout from itertools import repeat import math import random # sys.stdin = open('input') def mod(x, y, mod): re = 1 now = x while y: if y&1: re *= now re %= mod ...
1605969300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["4\naabbbbbba"]
3ffb3a2ae3e96fc26d539c9676389ae5
NoteThe tree from the sample is shown below: The tree after assigning characters to every node (according to the output) is the following: Strings for all nodes are the following: string of node $$$1$$$ is: a string of node $$$2$$$ is: aa string of node $$$3$$$ is: aab string of node $$$4$$$ is: aab string of n...
Kilani and Abd are neighbors for 3000 years, but then the day came and Kilani decided to move to another house. As a farewell gift, Kilani is going to challenge Abd with a problem written by their other neighbor with the same name Abd. The problem is:You are given a connected tree rooted at node $$$1$$$.You should ass...
In the first line, print the minimum possible total number of distinct strings. In the second line, print $$$n$$$ characters, where all characters are either a or b and the $$$i$$$-th character is the character assigned to the $$$i$$$-th node. Make sure that the total number of a's is equal to $$$x$$$ and the total num...
The first line contains two integers $$$n$$$ and $$$x$$$ ($$$1 \leq n \leq 10^5$$$; $$$0 \leq x \leq n$$$) — the number of vertices in the tree the number of a's. The second line contains $$$n - 1$$$ integers $$$p_2, p_3, \dots, p_{n}$$$ ($$$1 \leq p_i \leq n$$$; $$$p_i \neq i$$$), where $$$p_i$$$ is the parent of node...
standard output
standard input
PyPy 2
Python
3,100
train_107.jsonl
5726db2b032796c9c35d4404b6a194cb
256 megabytes
["9 3\n1 2 2 4 4 4 3 1"]
PASSED
n, a = map(int, raw_input().split());p = [-1] + [int(x) - 1 for x in raw_input().split()];g = [[] for i in range(n)] for i in range(1, n): g[p[i]].append(i) d = [-1 for i in range(n)];d_all = [[] for i in range(n)];d_lv = [[] for i in range(n)];d_nlv = [[] for i in range(n)];q = [0];d[0] = 0 while len(q) > 0: v = ...
1612535700
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["Yes\nYes\nNo\nYes\nNo"]
2ff40423619cefd8c2fb35a18549c411
NoteIn the first test case of the sample, we can do the second operation with $$$i=2$$$: $$$[1,\color{red}{2,2},4,2]\to [1,\color{red}{4},4,2]$$$.In the second testcase of the sample, we can: do the second operation with $$$i=2$$$: $$$[1,\color{red}{2,2},8,2,2]\to [1,\color{red}{4},8,2,2]$$$. do the second operation ...
Fishingprince is playing with an array $$$[a_1,a_2,\dots,a_n]$$$. He also has a magic number $$$m$$$.He can do the following two operations on it: Select $$$1\le i\le n$$$ such that $$$a_i$$$ is divisible by $$$m$$$ (that is, there exists an integer $$$t$$$ such that $$$m \cdot t = a_i$$$). Replace $$$a_i$$$ with $$$m...
For each testcase, print Yes if it is possible to turn $$$a$$$ into $$$b$$$, and No otherwise. You can print each letter in any case (upper or lower).
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n\le 5\cdot 10^4$$$, $$$2\le m\le 10^9$$$). The second line of each test c...
standard output
standard input
PyPy 3-64
Python
1,400
train_105.jsonl
21502cf957cbeeb386dcda2a58c40020
512 megabytes
["5\n\n5 2\n\n1 2 2 4 2\n\n4\n\n1 4 4 2\n\n6 2\n\n1 2 2 8 2 2\n\n2\n\n1 16\n\n8 3\n\n3 3 3 3 3 3 3 3\n\n4\n\n6 6 6 6\n\n8 3\n\n3 9 6 3 12 12 36 12\n\n16\n\n9 3 2 2 2 3 4 12 4 12 4 12 4 12 4 4\n\n8 3\n\n3 9 6 3 12 12 36 12\n\n7\n\n12 2 4 3 4 12 56"]
PASSED
import sys input = sys.stdin.readline rounds=int(input()) for ii in range(rounds): out='Yes' length1,magic=map(int,input().split()) arr1=list(map(int,input().split())) length2=int(input()) arr2=list(map(int,input().split())) a1=[] a2=[] for a in arr1: ori=a while a%magic==0: ...
1656167700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["4 8", "6 9", "8 15", "500000 500000"]
3ea971165088fae130d866180c6c868b
NoteIn the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two pr...
Output two composite integers x and y (1 &lt; x, y &lt; n) such that x + y = n. If there are multiple solutions, you can output any of them.
The only line contains an integer n (12 ≤ n ≤ 106).
standard output
standard input
Python 2
Python
800
train_006.jsonl
f45d1a614ffc6cbc966f08be94557b5e
256 megabytes
["12", "15", "23", "1000000"]
PASSED
n = int(raw_input().strip()) if n%2==0: print '4 ' +str(n-4) else: print '9 ' +str(n-9)
1411918500
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]