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
["aaabb\naabab\nbaaba\nbbaaa\nabb\nbab\naaaaabaaaaabaaaaaaaa"]
e32f0615541d97a025bc99c3cbf5380e
null
For the given integer $$$n$$$ ($$$n > 2$$$) let's write down all the strings of length $$$n$$$ which contain $$$n-2$$$ letters 'a' and two letters 'b' in lexicographical (alphabetical) order.Recall that the string $$$s$$$ of length $$$n$$$ is lexicographically less than string $$$t$$$ of length $$$n$$$, if there exi...
For each test case print the $$$k$$$-th string from the list of all described above strings of length $$$n$$$. Strings in the list are sorted lexicographically (alphabetically).
The input contains one or more test cases. The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case is written on the the separate line containing two integers $$$n$$$ and $$$k$$$ ($$$3 \le n \le 10^5, 1 \le k \le \min(2\...
standard output
standard input
Python 3
Python
1,300
train_003.jsonl
ff78c11ac46c3813ce36875ec6cedb13
256 megabytes
["7\n5 1\n5 2\n5 8\n5 10\n3 1\n3 2\n20 100"]
PASSED
t = int(input()) for num in range(t): n, k = map(int, input().split()) b1 = n - 2 b2 = n - 1 if k < 1000: i = 0 elif k == (n*(n-1))//2: b1 = 0 b2 = 1 i = k-1 else: i = int((1 + (1 - (4 * -1 * k * 2)) ** (1 / 2)) // 2) b1 = n - i - 1 i *= (i...
1585233300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["13-12-2013"]
dd7fd84f7915ad57b0e21f416e2a3ea0
null
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say that ...
In a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique.
The first line contains the Prophesy: a non-empty string that only consists of digits and characters "-". The length of the Prophesy doesn't exceed 105 characters.
standard output
standard input
Python 2
Python
1,600
train_007.jsonl
e2843da249328fdaa98f52fb3d8dbeb1
256 megabytes
["777-444---21-12-2013-12-2013-12-2013---444-777"]
PASSED
import re def c(d): d,m,y=map(int,d.split('-')) M=set([1,3,5,7,8,10,12]) return y > 2012 and y< 2016 and d>0and(d<29 and m==2 or d<32 and m in M or d<30 and m in (set(range(4,13))-M)) d=re.findall("(?=(\d\d-\d\d-\d{4}))", raw_input()) r={} for i in d: r[i]=r.get(i,0)+c(i) print max(r.items()...
1356622500
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["0\n3\n2\n92\n87654322\n9150"]
d67a97a3b69d599b03d3fce988980646
NoteIn the first test case of the example, you don't need to do anything.In the second test case of the example, the following sequence of moves can be applied: $$$13 \rightarrow 23 \rightarrow 32 \rightarrow 42$$$ (add $$$10$$$, add $$$9$$$, add $$$10$$$).In the third test case of the example, the following sequence o...
You are given two integers $$$a$$$ and $$$b$$$.In one move, you can choose some integer $$$k$$$ from $$$1$$$ to $$$10$$$ and add it to $$$a$$$ or subtract it from $$$a$$$. In other words, you choose an integer $$$k \in [1; 10]$$$ and perform $$$a := a + k$$$ or $$$a := a - k$$$. You may use different values of $$$k$$$ ...
For each test case, print the answer: the minimum number of moves required to obtain $$$b$$$ from $$$a$$$.
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9$$$).
standard output
standard input
PyPy 3
Python
800
train_000.jsonl
6b6b23dc5767f0e13b03c02b44160c2f
256 megabytes
["6\n5 5\n13 42\n18 4\n1337 420\n123456789 1000000000\n100500 9000"]
PASSED
n = int(input()) tests = [input() for _ in range(n)] for test in tests: a, b = [int(x) for x in test.split(' ')] count = 0 while True: if a == b: print(count) break else: diff = a - b tens = abs(diff / 10) if tens.is_integer(): ...
1599230100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2 7 42", "7 8 56"]
f60ea0f2caaec16894e84ba87f90c061
null
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction as a sum of three distinct positive fractions in form .Help Vladik with that, i.e for a given n find three distinct positive integers x, y and z such that . Because Chloe can't ...
If the answer exists, print 3 distinct numbers x, y and z (1 ≤ x, y, z ≤ 109, x ≠ y, x ≠ z, y ≠ z). Otherwise print -1. If there are multiple answers, print any of them.
The single line contains single integer n (1 ≤ n ≤ 104).
standard output
standard input
Python 2
Python
1,500
train_001.jsonl
c895b235e69dc87b0dc8de74ca386d10
256 megabytes
["3", "7"]
PASSED
n = int(raw_input()) if n==1: print "-1" elif n==2: print "2 3 6" else: isAnswered = False x = (n+1)/2 while x*2 < 3*n: c = x*2-n d = x*n y = x + 1 while True: if (2*x*y-n*x-n*y) <= 0: y += 1 break if (n*x*y) % (2*x*y-n*...
1481726100
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["0", "2", "1"]
f8315dc903b0542c453cab4577bcb20d
NoteIn the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the tw...
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f...
Print the single number — the number of groups of students that will be kicked out from the club.
The first line contains two integers n and m — the initial number of students and laces (). The students are numbered from 1 to n, and the laces are numbered from 1 to m. Next m lines each contain two integers a and b — the numbers of students tied by the i-th lace (1 ≤ a, b ≤ n, a ≠ b). It is guaranteed that no two st...
standard output
standard input
Python 2
Python
1,200
train_012.jsonl
b9995c62b01c0c0cd01443e59dba4849
256 megabytes
["3 3\n1 2\n2 3\n3 1", "6 3\n1 2\n2 3\n3 4", "6 5\n1 4\n2 4\n3 4\n5 4\n6 4"]
PASSED
r = lambda: raw_input().strip() n,m = map(int,r().split()) ties = [map(int,r().split()) for _ in xrange(m)] count = 0 while len(ties)>0: all_ties = [] l1 = len(ties) for t in ties: all_ties.append(t[0]) all_ties.append(t[1]) for i in xrange(n): if all_ties.count(i+1)==1: ...
1321337400
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
3 seconds
["3\n5\n14\n16\n24\n24\n24\n57\n54\n36\n36\n6\n18\n27\n28"]
560e26bdfab14b919a7deadefa57f2de
NoteIn the first test case, initially and after each request, the answer is achieved at $$$s = 1$$$, $$$k = 1$$$ or $$$s = 2$$$, $$$k = 1$$$.In the second test case, initially, the answer is achieved when $$$s = 1$$$, $$$k = 2$$$ or $$$s = 3$$$, $$$k = 2$$$. After the first request, the answer is achieved at $$$s = 2$$...
Tonya was given an array of $$$a$$$ of length $$$n$$$ written on a postcard for his birthday. For some reason, the postcard turned out to be a cyclic array, so the index of the element located strictly to the right of the $$$n$$$-th is $$$1$$$. Tonya wanted to study it better, so he bought a robot "Burenka-179".A progr...
For each test case, output $$$q+1$$$ numbers — the maximum usefulness of a program initially and after each of the changes.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) is the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$0 \le q \le 2 \cdot 10^5$$$). The second line of each test case...
standard output
standard input
PyPy 3-64
Python
2,400
train_087.jsonl
cb2c1c6aaea9b558ff8c0782fbb9e07c
256 megabytes
["4\n\n2 1\n\n1 2\n\n1 3\n\n4 4\n\n4 1 3 2\n\n2 6\n\n4 6\n\n1 1\n\n3 11\n\n9 3\n\n1 7 9 4 5 2 3 6 8\n\n3 1\n\n2 1\n\n9 1\n\n6 3\n\n1 1 1 1 1 1\n\n1 5\n\n4 4\n\n3 8"]
PASSED
import heapq class segtree(): def __init__(self,init,func,ide): self.n=len(init) self.func=func self.ide=ide self.size=1<<(self.n-1).bit_length() self.tree=[self.ide for i in range(2*self.size)] for i in range(self.n): self.tree[self.size+i]=init[i] for i in range(self.size...
1660660500
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["7\n10\n9\n3\n0"]
6f819ce1d88d5211cd475a8673edba97
NoteIn the first example, the floor has the size of $$$10\times 10$$$. The initial position of the robot is $$$(6, 1)$$$ and the position of the dirty cell is $$$(2, 8)$$$. See the illustration of this example in the problem statement.In the second example, the floor is the same, but the initial position of the robot i...
A robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of $$$n$$$ rows and $$$m$$$ columns. The rows of the floor are numbered from $$$1$$$ to $$$n$$$ from top to bottom, and columns of the floor are numbered from $$$1$$$ to $$$m$$$ from left to right. The cell on the inters...
For each test case, print an integer — the time for the robot to clean the dirty cell. We can show that the robot always cleans the dirty cell eventually.
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. A test case consists of only one line, containing six integers $$$n$$$, $$$m$$$, $$$r_b$$$, $$$c_b$$$, $$$r_d$$$, and $$$c_d$$$ ($$$1 \le n, m \le 100$$$, $$$...
standard output
standard input
Python 3
Python
800
train_106.jsonl
8345e314f8b03e0919bb38a1cd3d5bb9
256 megabytes
["5\n10 10 6 1 2 8\n10 10 9 9 1 1\n9 8 5 6 2 1\n6 9 2 2 5 8\n2 2 1 1 2 1"]
PASSED
#lista=list(map(int,input().split())) #x=lista[0] #n=lista[0] import math import sys from collections import deque #from sys import stdin, stdout from decimal import * #lista=list(map(int,input().split())) #x=lista[0] #n=lista[0] rasp_final="" #my_set=set() #for x in range(1, 100000): #my_set.add(2*...
1640698500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["6 3", "1 4 3 3"]
015d7871f6560b90d9efe3375f91cce7
NoteThe picture below show the game before it started, the game after the first round and game after the second round in the first example: In the second example, the first player is "blocked" so he will not capture new cells for the entire game. All other player will expand up during the first two rounds and in the t...
Kilani is playing a game with his friends. This game can be represented as a grid of size $$$n \times m$$$, where each cell is either empty or blocked, and every player has one or more castles in some cells (there are no two castles in one cell).The game is played in rounds. In each round players expand turn by turn: f...
Print $$$p$$$ integers — the number of cells controlled by each player after the game ends.
The first line contains three integers $$$n$$$, $$$m$$$ and $$$p$$$ ($$$1 \le n, m \le 1000$$$, $$$1 \le p \le 9$$$) — the size of the grid and the number of players. The second line contains $$$p$$$ integers $$$s_i$$$ ($$$1 \le s \le 10^9$$$) — the speed of the expansion for every player. The following $$$n$$$ lines d...
standard output
standard input
PyPy 2
Python
1,900
train_027.jsonl
d9494d760c903dc0fd1a4913956f5f33
256 megabytes
["3 3 2\n1 1\n1..\n...\n..2", "3 4 4\n1 1 1 1\n....\n#...\n1234"]
PASSED
import sys from collections import deque as dq range = xrange input = raw_input h,w,P = [int(x) for x in input().split()] S = [int(x) for x in input().split()] S = [min(h*w,s) for s in S] board = [] for b in sys.stdin.read(): for c in b: if c=='.': board.append(-1) elif c=='#': ...
1547985900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["1", "3", "4"]
a4563e6aea9126e20e7a33df664e3171
NoteIn first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.In the second example Arcady will be able to collect 3 apples. First one is one initi...
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i &gt; 1) is situated at the top of bra...
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
First line of input contains single integer number n (2 ≤ n ≤ 100 000)  — number of inflorescences. Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 ≤ pi &lt; i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.
standard output
standard input
Python 3
Python
1,500
train_001.jsonl
8307a43bb8a8d8bfd421732bf258027e
256 megabytes
["3\n1 1", "5\n1 2 2 2", "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4"]
PASSED
import sys from math import sqrt, gcd, ceil, log # from bisect import bisect, bisect_left from collections import defaultdict, Counter, deque # from heapq import heapify, heappush, heappop input = sys.stdin.readline read = lambda: list(map(int, input().strip().split())) sys.setrecursionlimit(10**6) def main(): n = ...
1520177700
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
2 seconds
["100", "-1", "2", "2"]
a9ccc8ab91d7ea2a2de074fdc305c3c8
NoteIn the first test it is possible to place a detachment in $$$(0, 0)$$$, so that it is possible to check all the detachments for $$$t = 100$$$. It can be proven that it is impossible to check all detachments for $$$t &lt; 100$$$; thus the answer is $$$100$$$.In the second test, there is no such $$$t$$$ that it is po...
There are $$$n$$$ detachments on the surface, numbered from $$$1$$$ to $$$n$$$, the $$$i$$$-th detachment is placed in a point with coordinates $$$(x_i, y_i)$$$. All detachments are placed in different points.Brimstone should visit each detachment at least once. You can choose the detachment where Brimstone starts.To m...
Output such minimal integer $$$t$$$ that it is possible to check all the detachments adding at most one new detachment. If there is no such $$$t$$$, print $$$-1$$$.
The first line contains a single integer $$$n$$$ $$$(2 \le n \le 1000)$$$ — the number of detachments. In each of the next $$$n$$$ lines there is a pair of integers $$$x_i$$$, $$$y_i$$$ $$$(|x_i|, |y_i| \le 10^9)$$$ — the coordinates of $$$i$$$-th detachment. It is guaranteed that all points are different.
standard output
standard input
PyPy 3
Python
2,800
train_043.jsonl
0eaf4f1cc58548705d07d08061346718
256 megabytes
["4\n100 0\n0 100\n-100 0\n0 -100", "7\n0 2\n1 0\n-3 0\n0 -2\n-1 -1\n-1 -3\n-2 -3", "5\n0 0\n0 -1\n3 0\n-2 0\n-2 1", "5\n0 0\n2 0\n0 -1\n-2 0\n-2 1"]
PASSED
# import numpy as npy import functools import math n=int(input()) x=[0 for i in range(n+2)] y=[0 for i in range(n+2)] adj=[[] for i in range(n+2)] idx=[] idy=[] for i in range(n): x[i],y[i]=map(int,input().split()) idx.append(i) idy.append(i) def cmpx(a,b): if x[a]!=x[b]: if x[a]<x[b]: ...
1600526100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["t \nabs((t-10))"]
79c337ca7397eac500ca8e6693f83fb6
NoteCorrect functions: 10 (1+2) ((t-3)+(t*4)) abs((t-10)) (abs((((23-t)*(t*t))+((45+12)*(t*t))))*((5*t)+((12*t)-13))) abs((t-(abs((t*31))+14))))Incorrect functions: 3+5+7 (not enough brackets, it should be ((3+5)+7) or (3+(5+7))) abs(t-3) (not enough brackets, it should be abs((t-3)) 2+(2-3 (one bracket too many) 1(t+...
Every day Ruslan tried to count sheep to fall asleep, but this didn't help. Now he has found a more interesting thing to do. First, he thinks of some set of circles on a plane, and then tries to choose a beautiful set of points, such that there is at least one point from the set inside or on the border of each of the i...
In the first line print a correct function f(t). In the second line print a correct function g(t). The set of the points (xt = f(t), yt = g(t)) (0 ≤ t ≤ 50) must satisfy the condition, that there is at least one point inside or on the border of each of the circles, Ruslan thinks of at the beginning.
The first line of the input contains number n (1 ≤ n ≤ 50) — the number of circles Ruslan thinks of. Next follow n lines, each of them containing three integers xi, yi and ri (0 ≤ xi, yi ≤ 50, 2 ≤ ri ≤ 50) — the coordinates of the center and the raduis of the i-th circle.
standard output
standard input
Python 3
Python
2,200
train_043.jsonl
f449fd4a7043dbd7ad499da8d45e86ae
256 megabytes
["3\n0 10 4\n10 0 4\n20 10 4"]
PASSED
def f(x): if x == n: return "0" if x == 0: return "(" + str(X[0]) + "+" + f(1) + ")" ss = "(abs((t-" + str(x-1) + "))-abs((t-" + str(x) + ")))" tmp = (X[x] - X[x - 1]) // 2 re = (X[x] - X[x - 1]) - 2 * tmp X[x] -= re if tmp < 0: ...
1446655500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["14", "6", "0"]
8c2e0cd780cf9390e933e28e57643cba
NoteIn the first example: In the second example: Note that the three poles $$$(0, 0)$$$, $$$(0, 2)$$$ and $$$(0, 4)$$$ are connected by a single wire.In the third example:
This problem is same as the next one, but has smaller constraints.It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consis...
Print a single integer — the number of pairs of wires that are intersecting.
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 50$$$) — the number of electric poles. Each of the following $$$n$$$ lines contains two integers $$$x_i$$$, $$$y_i$$$ ($$$-10^4 \le x_i, y_i \le 10^4$$$) — the coordinates of the poles. It is guaranteed that all of these $$$n$$$ points are distinct.
standard output
standard input
PyPy 2
Python
1,900
train_014.jsonl
26ecf2ed6785777a4abe6ac1c779131d
256 megabytes
["4\n0 0\n1 1\n0 3\n1 2", "4\n0 0\n0 2\n0 4\n2 0", "3\n-1 -1\n1 0\n3 1"]
PASSED
from itertools import combinations from collections import Counter n = input() points = [map(float, raw_input().split()) for _ in xrange(n)] lines = set() #for p1, p2 in combinations(points, 2): for i in xrange(n): for j in xrange(i+1, n): x1, y1 = points[i] x2, y2 = points[j] if x1 == x2: slope = float('i...
1557414300
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
1 second
["1 1 \n-1\n3 4\n4 2\n2 4\n-3 -6 -6"]
d15a758cfdd7a627822fe8be7db4f60b
null
You are given an array $$$a$$$ of $$$n$$$ integers.You want to make all elements of $$$a$$$ equal to zero by doing the following operation exactly three times: Select a segment, for each number in this segment we can add a multiple of $$$len$$$ to it, where $$$len$$$ is the length of this segment (added integers can b...
The output should contain six lines representing three operations. For each operation, print two lines: The first line contains two integers $$$l$$$, $$$r$$$ ($$$1 \le l \le r \le n$$$): the bounds of the selected segment. The second line contains $$$r-l+1$$$ integers $$$b_l, b_{l+1}, \dots, b_r$$$ ($$$-10^{18} \le ...
The first line contains one integer $$$n$$$ ($$$1 \le n \le 100\,000$$$): the number of elements of the array. The second line contains $$$n$$$ elements of an array $$$a$$$ separated by spaces: $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$).
standard output
standard input
PyPy 3
Python
1,600
train_001.jsonl
c1a8e9760d34fbeeca7152c0cd339db0
256 megabytes
["4\n1 3 2 4"]
PASSED
# -*- coding: utf-8 -*- import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def re...
1598798100
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["YES\nNO\nYES\nNO\nNO"]
f853a61741518cb884c00c8b760692aa
NoteIn the first test case, the graph's diameter equal to 0.In the second test case, the graph's diameter can only be 2.In the third test case, the graph's diameter can only be 1.
CQXYM wants to create a connected undirected graph with $$$n$$$ nodes and $$$m$$$ edges, and the diameter of the graph must be strictly less than $$$k-1$$$. Also, CQXYM doesn't want a graph that contains self-loops or multiple edges (i.e. each edge connects two different vertices and between each pair of vertices there...
For each test case, print YES if it is possible to create the graph, or print NO if it is impossible. You can print each letter in any case (upper or lower).
The input consists of multiple test cases. The first line contains an integer $$$t (1 \leq t \leq 10^5)$$$ — the number of test cases. The description of the test cases follows. Only one line of each test case contains three integers $$$n(1 \leq n \leq 10^9)$$$, $$$m$$$, $$$k$$$ $$$(0 \leq m,k \leq 10^9)$$$.
standard output
standard input
PyPy 3-64
Python
1,200
train_089.jsonl
20bd24ecfe50ad89afa33475b6144462
256 megabytes
["5\n1 0 3\n4 5 3\n4 6 3\n5 4 1\n2 1 1"]
PASSED
""" Cases: """ for t in range(int(input())): n,m,k = map(int,input().split()) req = ((n)*(n-1))//2 if(m>req or m<(n-1)): print('NO') else: if(n == 1): if(k>1): print('YES') else: print('NO') elif(m<req): ...
1632996900
[ "math", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
2 seconds
["A 1\nB 2\nC 1", "B 2\nC 1\nA 1\nC -1"]
f23d3e6ca1e4d7fbe5a2ca38ebb37c46
NoteFor the first sample, Li Chen's hidden permutation is $$$[2, 3, 1]$$$, and for the second, his hidden permutation is $$$[5, 3, 2, 4, 1, 6]$$$ for both cases.In the first sample, there is a tree with three nodes in a line. On the top, is how you labeled the tree and the subtree you chose, and the bottom is how Li Ch...
You are playing a strange game with Li Chen. You have a tree with $$$n$$$ nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices from $$$1$$$ to $$$n$$$. Neither of you know the other's labelling of the tree.You and Li Chen each chose a subtree (i.e....
null
null
standard output
standard input
Python 3
Python
1,900
train_050.jsonl
ba28e399d6d12beab211db16bf04d931
256 megabytes
["1\n3\n1 2\n2 3\n1\n1\n1\n2\n2\n1", "2\n6\n1 2\n1 3\n1 4\n4 5\n4 6\n4\n1 3 4 5\n3\n3 5 2\n3\n6\n1 2\n1 3\n1 4\n4 5\n4 6\n3\n1 2 3\n3\n4 1 6\n5"]
PASSED
import sys from math import * from random import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def solve(): n = mint() e = [[] for i in range(n+1)] p = [None]*(n+1) my = [False]*(n+1) for i in range(n-1): a,b = mints() e[a]....
1541355000
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["Yes", "Yes", "No"]
c0c7b1900e6be6d14695477355e4d87b
NoteIn the first sample, computer set a0 to  - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.The following game was chosen for the fights: initially there is a polynomia...
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k. The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ...
standard output
standard input
Python 3
Python
2,400
train_029.jsonl
92088896b294f7f6b0bd760a939cf360
256 megabytes
["1 2\n-1\n?", "2 100\n-10000\n0\n1", "4 5\n?\n1\n?\n1\n?"]
PASSED
def solve(): modx = 179426080107 n,m = map(int,input().split()) cnt = 0 a = [] for i in range(n + 1): s = input() if(s == '?'): cnt += 1 a.append(s) #print(cnt) if (m == 0): if (a[0] == '0') : return 1 if (a[0] == '?' and (n + 1 - cnt)% 2 == 1): return 1 return 0 if(cnt): if (n % 2 == 1):ret...
1464188700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["4", "7"]
6b0d00ecfa260a33e313ae60d8f9ee06
NoteFor the first sample testcase, the pretty substrings of s are: "(?" which can be transformed to "()". "?)" which can be transformed to "()". "((?)" which can be transformed to "(())". "(?))" which can be transformed to "(())". For the second sample testcase, the pretty substrings of s are: "??" which can be t...
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him. Thus, he came up with a puzzle to te...
Print the answer to Will's puzzle in the first and only line of output.
The first and only line of input contains string s, consisting only of characters '(', ')' and '?' (2 ≤ |s| ≤ 5000).
standard output
standard input
PyPy 2
Python
1,800
train_041.jsonl
11bc0353336c827652f9af16c25210cc
256 megabytes
["((?))", "??()??"]
PASSED
S = raw_input() N = len(S) A = 0 for i in xrange(N): D = 0 Q = 0 for j in xrange(i, N): D += S[j] == '(' D -= S[j] == ')' Q += S[j] == '?' if D + Q < 0: break if Q > D: D, Q = Q, D if Q == D: A += 1 print A
1517236500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["34"]
13b9b9c47ae7e8cfdcaee50f9c187d84
NoteThe picture corresponding to the first example:
You are given a tree (an undirected connected acyclic graph) consisting of $$$n$$$ vertices and $$$n - 1$$$ edges. A number is written on each edge, each number is either $$$0$$$ (let's call such edges $$$0$$$-edges) or $$$1$$$ (those are $$$1$$$-edges).Let's call an ordered pair of vertices $$$(x, y)$$$ ($$$x \ne y$$$...
Print one integer — the number of valid pairs of vertices.
The first line contains one integer $$$n$$$ ($$$2 \le n \le 200000$$$) — the number of vertices in the tree. Then $$$n - 1$$$ lines follow, each denoting an edge of the tree. Each edge is represented by three integers $$$x_i$$$, $$$y_i$$$ and $$$c_i$$$ ($$$1 \le x_i, y_i \le n$$$, $$$0 \le c_i \le 1$$$, $$$x_i \ne y_i$...
standard output
standard input
Python 3
Python
2,200
train_040.jsonl
e8ef59f05401fca7d239d8afcc917d02
256 megabytes
["7\n2 1 1\n3 2 0\n4 2 1\n5 2 0\n6 7 1\n7 2 1"]
PASSED
import sys readline = sys.stdin.buffer.readline read = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') class UnionFind: def __init__(self, n): ...
1556721300
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["3", "-1"]
0372790cbc07605c7e618dc14196fc67
NoteThis is the picture for the first example. $$$1$$$, $$$5$$$, $$$7$$$ also can be a valid answer. This is the picture for the second example. You can see that it's impossible to find such root vertex.
You have given tree consist of $$$n$$$ vertices. Select a vertex as root vertex that satisfies the condition below. For all vertices $$$v_{1}$$$ and $$$v_{2}$$$, if $$$distance$$$($$$root$$$, $$$v_{1}$$$) $$$= distance$$$($$$root$$$, $$$v_{2})$$$ then $$$degree$$$($$$v_{1}$$$) $$$= degree$$$($$$v_{2}$$$), where $$$deg...
If there is such root vertex exists, print any of them. Otherwise, print $$$-1$$$.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^{5}$$$) — the number of vertices. Each of the next $$$n-1$$$ lines contains two integers $$$v_{i}$$$ and $$$u_{i}$$$ ($$$1 \le v_{i} \lt u_{i} \le n$$$) — it means there is an edge exist between $$$v_{i}$$$ and $$$u_{i}$$$. It is guaranteed that the gr...
standard output
standard input
Python 3
Python
2,400
train_021.jsonl
55ba2d74977865c675ef56e79721ad5c
256 megabytes
["7\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7", "6\n1 3\n2 3\n3 4\n4 5\n4 6"]
PASSED
#!/usr/bin/env python def longest_path(): try: d = [-1 for _ in range(n)] d[0] = 0; q = [0] for i in range(n): f = q[i] for t in g[f]: if d[t] == -1: q.append(t) d[t] = d[f] + 1 u = q[-1] d = [-1 ...
1560258300
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["errorgorn\nmaomao90"]
fc75935b149cf9f4f2ddb9e2ac01d1c2
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2...
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pie...
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
Each test contains multiple test cases. The first line contains a single 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 a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of...
standard output
standard input
Python 3
Python
800
train_108.jsonl
6c8ccd5d42397179980029437b62f01b
256 megabytes
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
PASSED
num_cases = int(input()) for i in range(num_cases): count = 0 num_logs = int(input()) logs = [int(log) for log in input().split(' ')] for log in logs: count += log - 1 if count % 2 == 0: print('maomao90') else: print('errorgorn')
1650722700
[ "math", "games" ]
[ 1, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["YES\nNO\nNO\nYES"]
e2434fd5f9d16d59e646b6e69e37684a
null
You have $$$a$$$ coins of value $$$n$$$ and $$$b$$$ coins of value $$$1$$$. You always pay in exact change, so you want to know if there exist such $$$x$$$ and $$$y$$$ that if you take $$$x$$$ ($$$0 \le x \le a$$$) coins of value $$$n$$$ and $$$y$$$ ($$$0 \le y \le b$$$) coins of value $$$1$$$, then the total value of ...
For the $$$i$$$-th test case print the answer on it — YES (without quotes) if there exist such $$$x$$$ and $$$y$$$ that if you take $$$x$$$ coins of value $$$n$$$ and $$$y$$$ coins of value $$$1$$$, then the total value of taken coins will be $$$S$$$, and NO otherwise. You may print every letter in any case you want (s...
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases. Then $$$q$$$ test cases follow. The only line of the test case contains four integers $$$a$$$, $$$b$$$, $$$n$$$ and $$$S$$$ ($$$1 \le a, b, n, S \le 10^9$$$) — the number of coins of value $$$n$$$, the number o...
standard output
standard input
PyPy 2
Python
1,000
train_010.jsonl
383a1e58963802ddcc161b61b9ff3fa4
256 megabytes
["4\n1 2 3 4\n1 2 3 6\n5 2 6 27\n3 3 5 18"]
PASSED
q = int(raw_input()) for _ in range(q): a, b, n, S = map(int, raw_input().split()) if b >= S: print "YES" continue total = S need = S/n if need <= a: total -= need * n else: total -= a * n if b < total: print "NO" else: print "YES"
1572873300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["3"]
cf7cd545a48b050354ae786a263e2847
NoteIn the first example: $$$1100\oplus \mbox{shift}^1(1100) = 1010$$$ $$$1000\oplus \mbox{shift}^2(1000) = 1010$$$ $$$0110\oplus \mbox{shift}^3(0110) = 1010$$$ There is no $$$x$$$ such that $$$x \oplus x = 1010$$$, hence the answer is $$$3$$$.
After learning about polynomial hashing, Heidi decided to learn about shift-xor hashing. In particular, she came across this interesting problem.Given a bitstring $$$y \in \{0,1\}^n$$$ find out the number of different $$$k$$$ ($$$0 \leq k &lt; n$$$) such that there exists $$$x \in \{0,1\}^n$$$ for which $$$y = x \oplus...
Output a single integer: the number of suitable values of $$$k$$$.
The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$), the length of the bitstring $$$y$$$. The second line contains the bitstring $$$y$$$.
standard output
standard input
PyPy 2
Python
2,100
train_016.jsonl
59b7975d7ee1c0de558d2731605fd666
256 megabytes
["4\n1010"]
PASSED
import sys range = xrange n = int(raw_input()) y = [int(x) for x in raw_input()] def poss(k): x = [0]*n for i in range(n-k): x[i + k] = x[i] ^ y[i] for i in range(n-k,n): if x[i] ^ x[i + k - n] != y[i]: return 0 return 1 possible = [0]*(n+1) i = 1 while i * i < n: if n %...
1562483100
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
1 second
["? 3\n\n? 2\n\n? 4\n\n! 4 2 1 3\n\n? 2\n\n? 3\n\n? 2\n\n! 1 3 4 2"]
96ec983bfadc9e96e36ebb8ffc5279d3
NoteIn the first test case the hidden permutation $$$p = [4, 2, 1, 3]$$$.Before the first query $$$q = [1, 2, 3, 4]$$$ so answer for the query will be $$$q_3 = 3$$$.Before the second query $$$q = [4, 2, 1, 3]$$$ so answer for the query will be $$$q_2 = 2$$$.Before the third query $$$q = [3, 2, 4, 1]$$$ so answer for th...
This is an interactive problem.The jury has a permutation $$$p$$$ of length $$$n$$$ and wants you to guess it. For this, the jury created another permutation $$$q$$$ of length $$$n$$$. Initially, $$$q$$$ is an identity permutation ($$$q_i = i$$$ for all $$$i$$$).You can ask queries to get $$$q_i$$$ for any $$$i$$$ you ...
null
The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases.
standard output
standard input
PyPy 3-64
Python
1,700
train_092.jsonl
c8a94476bea447a91eff8d62bcd135f4
256 megabytes
["2\n4\n\n3\n\n2\n\n1\n\n4\n\n2\n\n4\n\n4"]
PASSED
import sys t = int(input()) for _ in range(t): n = int(input()) p = [0] * n todo = {j for j in range(1, n + 1)} while todo: x = todo.pop() todo.add(x) st, ls = set(), [] while True: print('?', x) sys.stdout.flush() y = int(input()) ...
1641220500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES\nYES\nYES\nYES\nNO\nNO"]
8dcf63e0e4584df7a471c84ce3ca8fe1
NoteThe picture corresponding to the example:Consider the queries.The first query is $$$[3, 8, 9, 10]$$$. The answer is "YES" as you can choose the path from the root $$$1$$$ to the vertex $$$u=10$$$. Then vertices $$$[3, 9, 10]$$$ belong to the path from $$$1$$$ to $$$10$$$ and the vertex $$$8$$$ has distance $$$1$$$ ...
You are given a rooted tree consisting of $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$. The root of the tree is a vertex number $$$1$$$.A tree is a connected undirected graph with $$$n-1$$$ edges.You are given $$$m$$$ queries. The $$$i$$$-th query consists of the set of $$$k_i$$$ distinct vertices $$$v_i[1], v_i[2...
For each query, print the answer — "YES", if there is a path from the root to some vertex $$$u$$$ such that each of the given $$$k$$$ vertices is either belongs to this path or has the distance $$$1$$$ to some vertex of this path and "NO" otherwise.
The first line of the input 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 tree and the number of queries. Each of the next $$$n-1$$$ lines describes an edge of the tree. Edge $$$i$$$ is denoted by two integers $$$u_i$$$ and $$$...
standard output
standard input
PyPy 2
Python
1,900
train_010.jsonl
7c04391a26ce8a094f9c50b92a0f972f
256 megabytes
["10 6\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n7 8\n7 9\n9 10\n4 3 8 9 10\n3 2 4 6\n3 2 1 5\n3 4 8 2\n2 6 10\n3 5 4 7"]
PASSED
from __future__ import division, print_function import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def main(): from types import GeneratorType def bootstrap(f, stack=[])...
1585233300
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1 second
["5\n2\n1\n3"]
a28b84c9d1a54e322ab2d54bd5ab45c8
NoteIn the first test case $$$n = 1$$$, so the array consists of one element $$$a_1$$$ and if we make $$$a_1 = 5$$$ it will be divisible by $$$k = 5$$$ and the minimum possible.In the second test case, we can create array $$$a = [1, 2, 1, 2]$$$. The sum is divisible by $$$k = 3$$$ and the maximum is equal to $$$2$$$.In...
You are given two integers $$$n$$$ and $$$k$$$.You should create an array of $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ such that the sum $$$(a_1 + a_2 + \dots + a_n)$$$ is divisible by $$$k$$$ and maximum element in $$$a$$$ is minimum possible.What is the minimum possible maximum element in $$$a$$$?
For each test case, print one integer — the minimum possible maximum element in array $$$a$$$ such that the sum $$$(a_1 + \dots + a_n)$$$ is divisible by $$$k$$$.
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 two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^9$$$; $$$1 \le k \le 10^9$$$).
standard output
standard input
Python 3
Python
1,000
train_102.jsonl
6bd59c9c0e2a869f240d45d4b287f4fe
256 megabytes
["4\n1 5\n4 3\n8 8\n8 17"]
PASSED
t = int(input()) for i in range(t): n, k = list(map(int, input().split())) if k % n == 0: print(k//n) elif n % k == 0: print(1) else: if k > n: print((k//n) + 1) elif k < n: print(2) else: ...
1611930900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["3\n0\n249561107"]
2b391638a9fea31986fe8e41c97b640a
NoteConsider the first test case. If the pair of indices $$$(2, 3)$$$ will be chosen, these elements will be swapped and array will become sorted. Otherwise, if one of pairs $$$(1, 2)$$$ or $$$(1, 3)$$$ will be selected, nothing will happen. So, the probability that the array will become sorted after one operation is $...
You are given a binary array $$$a$$$ (all elements of the array are $$$0$$$ or $$$1$$$) of length $$$n$$$. You wish to sort this array, but unfortunately, your algorithms teacher forgot to teach you sorting algorithms. You perform the following operations until $$$a$$$ is sorted: Choose two random indices $$$i$$$ and ...
For each test case print one integer — the value $$$p \cdot q^{-1} \bmod 998\,244\,353$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of elements in the binary array. The second line of eac...
standard output
standard input
PyPy 3-64
Python
2,000
train_100.jsonl
7f9dbb50633c187348ece78d06295258
256 megabytes
["3\n\n3\n\n0 1 0\n\n5\n\n0 0 1 1 1\n\n6\n\n1 1 1 0 0 1"]
PASSED
for _ in range(int(input())): n = int(input()) a = [int(x) for x in input().split()] zeros = n - sum(a) ones = sum(a[:zeros]) rv = n * (n - 1) // 2 * sum(pow(i, -2, 998244353) for i in range(1, ones + 1)) % 998244353 print(rv)
1666511400
[ "probabilities", "math" ]
[ 0, 0, 0, 1, 0, 1, 0, 0 ]
1 second
["14\n3", "3\n1"]
88961744a28d7c890264a39a0a798708
NoteIn the first example: For query $$$1$$$: One of the best ways for JATC to eats those parts is in this order: $$$1$$$, $$$4$$$, $$$3$$$, $$$2$$$. For query $$$2$$$: Both $$$3$$$, $$$4$$$ and $$$4$$$, $$$3$$$ ordering give the same answer. In the second example, any order of eating parts leads to the same answer.
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way.First, he splits the Banh-mi into $$$n$$$ parts, places them on a row and numbers them from $$$1$$$ through $$$n$$$. For ea...
Print $$$q$$$ lines, where $$$i$$$-th of them contains a single integer — the answer to the $$$i$$$-th query modulo $$$10^9 + 7$$$.
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 100\,000$$$). The second line contains a string of $$$n$$$ characters, each character is either '0' or '1'. The $$$i$$$-th character defines the deliciousness of the $$$i$$$-th part. Each of the following $$$q$$$ lines contains two integers $$$...
standard output
standard input
Python 3
Python
1,600
train_017.jsonl
e3dd183fcc82ad86f8c1d165a9e2d2b7
256 megabytes
["4 2\n1011\n1 4\n3 4", "3 2\n111\n1 2\n3 3"]
PASSED
import sys input = sys.stdin.readline n, q = map(int, input().split()) s = input() pref = [0 for i in range(n + 1)] for i in range(1, n + 1): pref[i] = pref[i - 1] + (s[i - 1] == '1') mod = 1000000007 ans = [] for i in range(q): a, b = map(int, input().split()) k = pref[b] - pref[a - 1]; N = b - a + 1 ...
1542209700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["YES\nNO\nYES"]
55595ff38a08b80bc86cf1ebae6f55af
NoteFor the first test case, this is an example solution: For the second test case, we can show that no solution exists.For the third test case, this is an example solution:
You are given a special jigsaw puzzle consisting of $$$n\cdot m$$$ identical pieces. Every piece has three tabs and one blank, as pictured below. The jigsaw puzzle is considered solved if the following conditions hold: The pieces are arranged into a grid with $$$n$$$ rows and $$$m$$$ columns. For any two pieces that...
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
The test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 1000$$$) — the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. Each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 10^5$$$).
standard output
standard input
PyPy 2
Python
800
train_022.jsonl
4b6f7f740038c4bd7b5c96425fc0c4a7
256 megabytes
["3\n1 3\n100000 100000\n2 2"]
PASSED
T = input() for _ in xrange(T): n, m = map(int, raw_input().split()) if n > 2 and m > 2: print "NO" else: if (n == 2 and m > 2) or (m == 2 and n > 2): print "NO" else: print "YES"
1588775700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2 4\n4 3\n1 3\n2 1\n1 1\n1 2\n31623 14130"]
f8335c59cd05988c8053f138c4df06aa
null
Polycarp has found a table having an infinite number of rows and columns. The rows are numbered from $$$1$$$, starting from the topmost one. The columns are numbered from $$$1$$$, starting from the leftmost one.Initially, the table hasn't been filled and Polycarp wants to fix it. He writes integers from $$$1$$$ and so ...
For each test case, output in a separate line two integers $$$r$$$ and $$$c$$$ ($$$r, c \ge 1$$$) separated by spaces — the indices of the row and the column containing the cell filled by the number $$$k$$$, respectively.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing one integer $$$k$$$ ($$$1 \le k \le 10^9$$$) which location must be found.
standard output
standard input
PyPy 3-64
Python
800
train_103.jsonl
57942d47c8abf07a8d4e261bbf1d221b
256 megabytes
["7\n11\n14\n5\n4\n1\n2\n1000000000"]
PASSED
t = int(input()) def main() : n = int(input()) if n==1 : return("1 1") else : k = int(n**0.5) if k*k==n : k=k-1 pojok = k*k+k+1 if n<=pojok : baris = k+n-pojok+1 kolom = k+1 else : baris = k+1 ...
1629297300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["4", "24000", "-1"]
4dce15ff1446b5af2c5b49ee2d30bbb8
NoteThe tree corresponding to samples $$$1$$$ and $$$2$$$ are: In sample $$$1$$$, we can choose node $$$1$$$ and $$$k = 4$$$ for a cost of $$$4 \cdot 1$$$ = $$$4$$$ and select nodes $$${1, 2, 3, 5}$$$, shuffle their digits and get the desired digits in every node.In sample $$$2$$$, we can choose node $$$1$$$ and $$$k =...
Ashish has a tree consisting of $$$n$$$ nodes numbered $$$1$$$ to $$$n$$$ rooted at node $$$1$$$. The $$$i$$$-th node in the tree has a cost $$$a_i$$$, and binary digit $$$b_i$$$ is written in it. He wants to have binary digit $$$c_i$$$ written in the $$$i$$$-th node in the end.To achieve this, he can perform the follo...
Print the minimum total cost to make every node reach its target digit, and $$$-1$$$ if it is impossible.
First line contains a single integer $$$n$$$ $$$(1 \le n \le 2 \cdot 10^5)$$$ denoting the number of nodes in the tree. $$$i$$$-th line of the next $$$n$$$ lines contains 3 space-separated integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$ $$$(1 \leq a_i \leq 10^9, 0 \leq b_i, c_i \leq 1)$$$  — the cost of the $$$i$$$-th node, i...
standard output
standard input
PyPy 3
Python
2,000
train_020.jsonl
70c3b97d4d35c113382d265d2e48e5a4
256 megabytes
["5\n1 0 1\n20 1 0\n300 0 1\n4000 0 0\n50000 1 0\n1 2\n2 3\n2 4\n1 5", "5\n10000 0 1\n2000 1 0\n300 0 1\n40 0 0\n1 1 0\n1 2\n2 3\n2 4\n1 5", "2\n109 0 1\n205 0 1\n1 2"]
PASSED
""" Python 3 compatibility tools. """ from __future__ import division, print_function import itertools import sys, threading import os from io import BytesIO, IOBase from types import GeneratorType def is_it_local(): script_dir = str(os.getcwd()).split('/') username = "dipta007" return username in script_dir d...
1590935700
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["2", "112"]
43d877e3e1c1fd8ee05dc5e5e3067f93
NoteIn the first test, there is only one mirror and it tells, that Creatnx is beautiful with probability $$$\frac{1}{2}$$$. So, the expected number of days until Creatnx becomes happy is $$$2$$$.
Creatnx has $$$n$$$ mirrors, numbered from $$$1$$$ to $$$n$$$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $$$i$$$-th mirror will tell Creatnx that he is beautiful with probability $$$\frac{p_i}{100}$$$ for all $$$1 \le i \le n$$$.Creatnx asks the mirrors one by one, starting from the $$$1$$$-st m...
Print the answer modulo $$$998244353$$$ in a single line.
The first line contains one integer $$$n$$$ ($$$1\le n\le 2\cdot 10^5$$$) — the number of mirrors. The second line contains $$$n$$$ integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \leq p_i \leq 100$$$).
standard output
standard input
PyPy 2
Python
2,100
train_017.jsonl
d758adcba0dbcc2f1a20044052ecfef4
256 megabytes
["1\n50", "3\n10 20 50"]
PASSED
n=input() l=map(int,raw_input().split()) num=0 p=1 for i in range(n): num=(num+(p*pow(100,n-i,998244353))%998244353)%998244353 p=(p*l[i])%998244353 print (num*pow(p,998244351,998244353))%998244353
1575556500
[ "probabilities", "math" ]
[ 0, 0, 0, 1, 0, 1, 0, 0 ]
2 seconds
["6", "7", "0"]
75e6bc042f61d2dd61165866a13d1c6d
NoteIn the first sample the following subsequences are possible: If we delete characters at the positions 1 and 5 (numbering starts with one), we will get the subsequence "(())". If we delete characters at the positions 1, 2, 3 and 4, we will get the subsequence "()". If we delete characters at the positions 1, 2, 4...
As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)).On the last lesson Anton learned about the regular simple bracket seq...
Output one number — the answer for the task modulo 109 + 7.
The only line of the input contains a string s — the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed 200 000.
standard output
standard input
Python 3
Python
2,300
train_037.jsonl
fde78457fa8cf2cbc6248a002cdfffc7
256 megabytes
[")(()()", "()()()", ")))"]
PASSED
mod = 10 ** 9 + 7 fact, inv, invfact = [1, 1], [0, 1], [1, 1] for i in range(2, 200200): fact.append(fact[-1] * i % mod) inv.append(inv[mod % i] * (mod - mod // i) % mod) invfact.append(invfact[-1] * inv[-1] % mod) def C(n, k): if k < 0 or k > n: return 0 return fact[n] * invfact[k] * invf...
1489590300
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["3.500000000000", "4.958333333333", "1.750000000000"]
f70ac2c4e0f62f9d6ad1e003aedd86b2
NoteConsider the third test example. If you've made two tosses: You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. You can get 2 in the first ...
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.The dice has m faces: the first face of the dice contains a dot, the second one contains two dots, an...
Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10  - 4.
A single line contains two integers m and n (1 ≤ m, n ≤ 105).
standard output
standard input
Python 3
Python
1,600
train_011.jsonl
05a23b579b77eff8fb269d6721c53d91
256 megabytes
["6 1", "6 3", "2 2"]
PASSED
n,m = map(int, input().split()) s=0 for i in range(n): s+=(i+1)*(pow((i+1)/n,m)-pow(i/n,m)) print(s)
1406907000
[ "probabilities" ]
[ 0, 0, 0, 0, 0, 1, 0, 0 ]
1 second
["YES\n0 1 1", "YES\n0 1 1 3 3", "NO"]
2354852d9cc911ac4a307dee5b75d6fc
NoteIn the first example case one can have a construction with 3 people, where 1 person has 2 parents.In the second example case one can use the following construction: Only person 1 is imbalanced, because one of their parents has 1 ancestor in total, and the other parent has 3 ancestors.
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
If there are no constructions with $$$n$$$ people and $$$k$$$ imbalanced people, output NO. Otherwise output YES on the first line, and then $$$n$$$ integers $$$s_1, s_2, \ldots, s_n$$$ ($$$0 \leq s_i \leq n$$$), which describes the construction and specify the child of each node (or 0, if the person does not have any ...
The input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 100\,000$$$, $$$0 \leq k \leq n$$$), the total number of people and the number of imbalanced people.
standard output
standard input
Python 3
Python
2,800
train_065.jsonl
a139305188c4f2aa7b001886cf4cf79c
512 megabytes
["3 0", "5 1", "3 2"]
PASSED
from heapq import * import sys int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)]...
1595149200
[ "math", "trees" ]
[ 0, 0, 0, 1, 0, 0, 0, 1 ]
1 second
["3 1 2 1\n6 5 2 5 3 1 2\n0\n9 4 1 2 10 4 1 2 1 5\n1 1"]
46c5ebf1ddf5547352e84ba0171eacbc
NoteIn the first test case, we have $$$01\to 11\to 00\to 10$$$.In the second test case, we have $$$01011\to 00101\to 11101\to 01000\to 10100\to 00100\to 11100$$$.In the third test case, the strings are already the same. Another solution is to flip the prefix of length $$$2$$$, which will leave $$$a$$$ unchanged.
This is the hard version of the problem. The difference between the versions is the constraint on $$$n$$$ and the required number of operations. You can make hacks only if all versions of the problem are solved.There are two binary strings $$$a$$$ and $$$b$$$ of length $$$n$$$ (a binary string is a string consisting of...
For each test case, output an integer $$$k$$$ ($$$0\le k\le 2n$$$), followed by $$$k$$$ integers $$$p_1,\ldots,p_k$$$ ($$$1\le p_i\le n$$$). Here $$$k$$$ is the number of operations you use and $$$p_i$$$ is the length of the prefix you flip in the $$$i$$$-th operation.
The first line contains a single integer $$$t$$$ ($$$1\le t\le 1000$$$)  — the number of test cases. Next $$$3t$$$ lines contain descriptions of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 10^5$$$)  — the length of the binary strings. The next two lines contain two binar...
standard output
standard input
PyPy 3
Python
1,700
train_005.jsonl
669d8046b27ef2616d52afa1b5e15189
256 megabytes
["5\n2\n01\n10\n5\n01011\n11100\n2\n01\n01\n10\n0110011011\n1000110100\n1\n0\n1"]
PASSED
t = int(input()) for _ in range(t): l = int(input()) a = input().rstrip() b = input().rstrip() ans = [] c = 0 if a[0]=='1': c += 1 for i in range(len(a)-1): if a[i+1] != a[i]: ans.append(i+1) c+= 1 bns = [] d = 0 if ...
1595342100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1.5 seconds
["15", "30"]
ab23517c489717ac200821f1041368a2
null
In a medieval kingdom, the economic crisis is raging. Milk drops fall, Economic indicators are deteriorating every day, money from the treasury disappear. To remedy the situation, King Charles Sunnyface decided make his n sons-princes marry the brides with as big dowry as possible.In search of candidates, the king aske...
Print the only integer — the maximum number of gold coins that a king can get by playing the right weddings.
The first line contains two integers n, m (2 ≤ n ≤ 200 000, 1 ≤ m ≤ 200 000) — number of princes and princesses respectively. Each of following m lines contains three integers ai, bi, wi (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ wi ≤ 10 000) — number of princes, which i-th princess is ready to marry and the value of her dowry.
standard output
standard input
Python 2
Python
2,500
train_079.jsonl
5dadc7361e08f7b582a1b8de124cc35c
512 megabytes
["2 3\n1 2 5\n1 2 1\n2 1 10", "3 2\n1 2 10\n3 2 20"]
PASSED
from sys import stdin from itertools import repeat def main(): n, m = map(int, stdin.readline().split()) dat = map(int, stdin.read().split(), repeat(10, 3 * m)) e = [(-dat[i*3+2], dat[i*3+1], dat[i*3]) for i in xrange(m)] e.sort() par = range(n + 1) c = [1] * (n + 1) st = [] po = st.pop ...
1508151900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["YES\nNO\nNO\nYES"]
bdbd3420d9aa85b3143a87c5fa530f31
NoteFor the first and the second test case, the only possible combination is $$$[1]$$$ so there always will be a subsegment with $$$1$$$ animal but not with $$$2$$$ animals.
Theofanis decided to visit his uncle's farm. There are $$$s$$$ animals and $$$n$$$ animal pens on the farm. For utility purpose, animal pens are constructed in one row.Uncle told Theofanis that a farm is lucky if you can distribute all animals in all pens in such a way that there are no empty pens and there is at least...
For each test case, print YES (case-insensitive), if the farm is ideal, or NO (case-insensitive) otherwise.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The first and only line of each test case contains three integers $$$s$$$, $$$n$$$, and $$$k$$$ ($$$1 \le s, n, k \le 10^{18}$$$; $$$n \le s$$$).
standard output
standard input
PyPy 3-64
Python
2,400
train_097.jsonl
880979acd4ec34ac767c86a05ce7a10a
256 megabytes
["4\n1 1 1\n1 1 2\n100 50 200\n56220 47258 14497"]
PASSED
import sys input = sys.stdin.buffer.readline def process(s, n, k): if k==0 or k==s: sys.stdout.write("YES\n") return if k > s: sys.stdout.write("NO\n") return a = s % k b = s//k """ Normally a blocks of size b+1 corresponding to 0, 1, ..,...
1633705500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["3", "0", "-1", "1"]
79b0794f81acc1c882649d96b1c7f8da
NoteIn the first example Polycarp should increase the first number on $$$1$$$, decrease the second number on $$$1$$$, increase the third number on $$$1$$$, and the fourth number should left unchanged. So, after Polycarp changed three elements by one, his sequence became equals to $$$[25, 20, 15, 10]$$$, which is an ari...
Polycarp likes arithmetic progressions. A sequence $$$[a_1, a_2, \dots, a_n]$$$ is called an arithmetic progression if for each $$$i$$$ ($$$1 \le i &lt; n$$$) the value $$$a_{i+1} - a_i$$$ is the same. For example, the sequences $$$[42]$$$, $$$[5, 5, 5]$$$, $$$[2, 11, 20, 29]$$$ and $$$[3, 2, 1, 0]$$$ are arithmetic pr...
If it is impossible to make an arithmetic progression with described operations, print -1. In the other case, print non-negative integer — the minimum number of elements to change to make the given sequence becomes an arithmetic progression. The only allowed operation is to add/to subtract one from an element (can't us...
The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100\,000)$$$ — the number of elements in $$$b$$$. The second line contains a sequence $$$b_1, b_2, \dots, b_n$$$ $$$(1 \le b_i \le 10^{9})$$$.
standard output
standard input
PyPy 2
Python
1,500
train_044.jsonl
e7fb35a704ec1f46b5b168e7d759f335
256 megabytes
["4\n24 21 14 10", "2\n500 500", "3\n14 5 1", "5\n1 3 6 9 12"]
PASSED
import sys n = raw_input() a = map(int,raw_input().split()) ans = sys.maxint if len(a) > 2: check = [(0,0,0), (1,0,1), (0,1,1), (-1,0,1), (0,-1,1), (1,-1,2), (-1,1,2), (1,1,2), (-1,-1,2)] for e in check: ...
1526202300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2\n4 1 2\n2 3 3\n-1\n4\n1 2 4\n2 4 5\n2 3 3\n4 5 1"]
b6fb4d868e3f496466746f5e776ae2cc
null
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers, numbered from $$$1$$$ to $$$n$$$. You can perform the following operation no more than $$$3n$$$ times: choose three integers $$$i$$$, $$$j$$$ and $$$x$$$ ($$$1 \le i, j \le n$$$; $$$0 \le x \le 10^9$$$); assign $$$a_i := a_i - x \cdot i$$$, $$$a_...
For each test case print the answer to it as follows: if there is no suitable sequence of operations, print $$$-1$$$; otherwise, print one integer $$$k$$$ ($$$0 \le k \le 3n$$$) — the number of operations in the sequence. Then print $$$k$$$ lines, the $$$m$$$-th of which should contain three integers $$$i$$$, $$$j$$...
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n...
standard output
standard input
PyPy 2
Python
2,000
train_012.jsonl
66e0e33abcefa54d09a178184e2270f8
256 megabytes
["3\n4\n2 16 4 18\n6\n1 2 3 4 5 6\n5\n11 19 1 1 3"]
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 ...
1601219100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["3\n5\n4\n28010\n110"]
f7cde36c9cd0131478a5e3b990c64084
NoteIn the first test case: At time $$$0$$$, the values of the nodes are $$$[1, 1, 1]$$$. At time $$$1$$$, the values of the nodes are $$$[0, 1, 1]$$$. At time $$$2$$$, the values of the nodes are $$$[0, 0, 1]$$$. At time $$$3$$$, the values of the nodes are $$$[0, 0, 0]$$$.So the answer is $$$3$$$. In the second te...
Cirno has a DAG (Directed Acyclic Graph) with $$$n$$$ nodes and $$$m$$$ edges. The graph has exactly one node that has no out edges. The $$$i$$$-th node has an integer $$$a_i$$$ on it.Every second the following happens: Let $$$S$$$ be the set of nodes $$$x$$$ that have $$$a_x &gt; 0$$$. For all $$$x \in S$$$, $$$1$$$ i...
For each test case, print an integer in a separate line — the first moment of time when all $$$a_i$$$ become $$$0$$$, modulo $$$998\,244\,353$$$.
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Description of test cases follows. The first line of each test case contains two integers $$$n, m$$$ ($$$1 \leq n, m \leq 1000$$$) — the number of vertices and edges in the graph. The second line of each test case co...
standard output
standard input
PyPy 3-64
Python
2,200
train_089.jsonl
dcd64739b98b3f8d94d45f90ba9d653e
256 megabytes
["5\n\n3 2\n\n1 1 1\n\n1 2\n\n2 3\n\n5 5\n\n1 0 0 0 0\n\n1 2\n\n2 3\n\n3 4\n\n4 5\n\n1 5\n\n10 11\n\n998244353 0 0 0 998244353 0 0 0 0 0\n\n1 2\n\n2 3\n\n3 4\n\n4 5\n\n5 6\n\n6 7\n\n7 8\n\n8 9\n\n9 10\n\n1 3\n\n7 9\n\n5 6\n\n1293 1145 9961 9961 1919\n\n1 2\n\n2 3\n\n3 4\n\n5 4\n\n1 4\n\n2 4\n\n6 9\n\n10 10 10 10 10 10\...
PASSED
from sys import stdin, stdout N = 998244353 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 sta...
1659276300
[ "math", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
2 seconds
["1\n-1\n-1\n2", "1\n-1\n-1\n2\n5\n-1", "13\n2\n9\n5\n-1"]
27a521d4d59066e50e870e7934d4b190
NoteIn the first sample, the ray will consequently pass through the points (0, 0), (1, 1), (2, 2), (3, 3). Thus, it will stop at the point (3, 3) after 3 seconds. In the second sample, the ray will consequently pass through the following points: (0, 0), (1, 1), (2, 2), (3, 3), (2, 4), (1, 3), (0, 2), (1, 1), (2, 0), (...
There are k sensors located in the rectangular room of size n × m meters. The i-th sensor is located at point (xi, yi). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at points (0, 0) and (n, m). Walls of the room are parallel to coordinate axes.At the...
Print k integers. The i-th of them should be equal to the number of seconds when the ray first passes through the point where the i-th sensor is located, or  - 1 if this will never happen.
The first line of the input contains three integers n, m and k (2 ≤ n, m ≤ 100 000, 1 ≤ k ≤ 100 000) — lengths of the room's walls and the number of sensors. Each of the following k lines contains two integers xi and yi (1 ≤ xi ≤ n - 1, 1 ≤ yi ≤ m - 1) — coordinates of the sensors. It's guaranteed that no two sensors a...
standard output
standard input
Python 3
Python
1,800
train_063.jsonl
cf43eaa817548eba4715c30cc993ea58
256 megabytes
["3 3 4\n1 1\n1 2\n2 1\n2 2", "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3", "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3"]
PASSED
n, m, k = map(int,input().split()) dm, dp = {}, {} vis = {} sensors = [] border = set() for el in [(0, m), (n, 0), (0, 0), (n, m)]: border.add(el) for _ in range(k): x, y = map(int, input().split()) if not (x - y) in dm: dm[x - y] = [] dm[x - y].append((x, y)) if not (x + y) in dp: ...
1475928900
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
3 seconds
["2\n5 10", "1\n10", "3\n2 3 4", "3\n42 13 37"]
0fd45a1eb1fc23e579048ed2beac7edd
NoteLet's consider the examples from the statement. In the first example, Monocarp pins the messages $$$5$$$ and $$$10$$$. if the first student reads the message $$$5$$$, the second student reads the messages $$$5$$$ and $$$10$$$, and the third student reads the messages $$$5$$$ and $$$10$$$, the number of students wh...
Monocarp is a tutor of a group of $$$n$$$ students. He communicates with them using a conference in a popular messenger.Today was a busy day for Monocarp — he was asked to forward a lot of posts and announcements to his group, that's why he had to write a very large number of messages in the conference. Monocarp knows ...
In the first line, print one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^5$$$) — the number of messages Monocarp should pin. In the second line, print $$$t$$$ distinct integers $$$c_1$$$, $$$c_2$$$, ..., $$$c_t$$$ ($$$1 \le c_i \le 2 \cdot 10^5$$$) — the indices of the messages Monocarp should pin. The messages can be l...
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students in the conference. Then $$$n$$$ lines follow. The $$$i$$$-th line contains two integers $$$m_i$$$ and $$$k_i$$$ ($$$1 \le m_i \le 2 \cdot 10^5$$$; $$$1 \le k_i \le 20$$$) — the index of the message which Monocarp wants...
standard output
standard input
PyPy 3-64
Python
2,000
train_098.jsonl
4a59cdfe0932d6b7a10853628c6b7652
512 megabytes
["3\n10 1\n10 2\n5 2", "3\n10 1\n5 2\n10 1", "4\n1 1\n2 2\n3 3\n4 4", "3\n13 2\n42 2\n37 2"]
PASSED
import io,os import heapq input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def calculate_maximum(tot,dic,wmax,wkey): n = len(dic) if n<tot: return [-1,[]] indexes = [i for i in range(n)] for i,key in enumerate(wkey): wmax[i] += dic[key][tot] heap = [] for i in ra...
1637573700
[ "probabilities" ]
[ 0, 0, 0, 0, 0, 1, 0, 0 ]
1 second
["2", "1", "Impossible", "1"]
ffdef277d0ff8e8579b113f5bd30f52a
NoteIn the first example, you can cut the string in those positions: no|l|on, and then unite them as follows on|l|no. It can be shown that there is no solution with one cut.In the second example, you can cut the string right in the middle, and swap peaces, so you get toot.In the third example, you can't make a string, ...
Reading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my names in many countries. Mithrandir among the Elves, Tharkûn to the Dwarves, Olórin I was in my youth in the West that is forgotten, in t...
Print one integer $$$k$$$ — the minimum number of cuts needed to get a new name, or "Impossible" (without quotes).
The first line contains one string $$$s$$$ ($$$1 \le |s| \le 5\,000$$$) — the initial name, which consists only of lowercase Latin letters. It is guaranteed that $$$s$$$ is a palindrome.
standard output
standard input
PyPy 3
Python
1,800
train_026.jsonl
058ccfdebd5a9712cf3f552d47330ca2
256 megabytes
["nolon", "otto", "qqqq", "kinnikkinnik"]
PASSED
s = input() l = len(s) c = s[0] diff = False for i in range(0,int(l/2)): if s[i] != c: diff = True if not diff: print('Impossible') exit() s_2 = s + s for i in range(1,l): is_palendrome = True for j in range(int(l/2)): if s_2[j + i] != s_2[i + l - j-1]: is_palendrom...
1550334900
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["3", "1"]
63e130256e23bd0693c6a1bede5e937e
null
There are less than 60 years left till the 900-th birthday anniversary of a famous Italian mathematician Leonardo Fibonacci. Of course, such important anniversary needs much preparations.Dima is sure that it'll be great to learn to solve the following problem by the Big Day: You're given a set A, consisting of numbers ...
Print a single integer — the residue from dividing the sought greatest common divisor by m.
The first line contains four space-separated integers m, l, r and k (1 ≤ m ≤ 109; 1 ≤ l &lt; r ≤ 1012; 2 ≤ k ≤ r - l + 1). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
standard output
standard input
Python 2
Python
2,400
train_043.jsonl
44a15a661135a9b3ad098d554c01034b
256 megabytes
["10 1 8 2", "10 1 8 3"]
PASSED
def recfib(n,m): if n==0: return (0,1,) a, b = recfib(n / 2,m) return ((b*b+a*a)%m, b*(2*a+b)%m) if n%2 else (a*((2*b)-a)%m, ((b*b+a*a))%m) m,l,r,k = map(long, raw_input().split()) D = (r-l)/(k-1) while D > 1 and (1+(r/D)-((l+D-1)/D))<k: N = 1 + (r/D) D -= ( ((N*D)-r) + (N-1) ) / N print(recfib(D, m...
1348500600
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["2.0000000000", "-1", "0.5000000000"]
1c2fc9449989d14d9eb02a390f36b7a6
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to char...
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single...
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker prog...
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the de...
standard output
standard input
Python 2
Python
1,800
train_000.jsonl
64f5b4b8ec180aeaf58314d8bfe51fdf
256 megabytes
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
PASSED
n, p = map(int, raw_input().strip().split()) d = [None] * n for i in range(n): d[i] = map(int, raw_input().strip().split()) if p >= sum(map(lambda x:x[0], d)): print -1 else: d.sort(cmp=lambda x,y:1 if x[1] * y[0] > y[1] * x[0] else -1) res = 1e100 a_s, b_s = 0.0, 0.0 for i in range(n): ...
1492356900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
4 seconds
["2 1 4 3 \n1 2 \n3 4 2 1 5 \n3 2 1"]
5481863fd03c37cdcb7d6ee40f973cb9
null
Monocarp had a permutation $$$a$$$ of $$$n$$$ integers $$$1$$$, $$$2$$$, ..., $$$n$$$ (a permutation is an array where each element from $$$1$$$ to $$$n$$$ occurs exactly once).Then Monocarp calculated an array of integers $$$b$$$ of size $$$n$$$, where $$$b_i = \left\lfloor \frac{i}{a_i} \right\rfloor$$$. For example,...
For each test case, print $$$n$$$ integers — a permutation $$$a$$$ that corresponds to the given array $$$b$$$. If there are multiple possible permutations, then print any of them.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$0 \le b_i \le n$$$). Additional constrains on th...
standard output
standard input
PyPy 3-64
Python
1,900
train_098.jsonl
3babb8db54ba1568e0011deb4af2f572
256 megabytes
["4\n\n4\n\n0 2 0 1\n\n2\n\n1 1\n\n5\n\n0 0 1 4 1\n\n3\n\n0 1 3"]
PASSED
import heapq import sys input = sys.stdin.readline rounds=int(input()) for ii in range(rounds): out=0 length=int(input()) arr=list(map(int,input().split())) small=[] for l in range(length): if arr[l]==0: small.append([l+2,length,l]) else: little=(l+1)//(arr[l]+1)+1 bi...
1657290900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
ea620a8dbef506567464dcaddcc2b34f
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x ...
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ ...
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
standard output
standard input
PyPy 3-64
Python
1,900
train_109.jsonl
158e3bd13e626daa40efa4dd7f3ebc86
512 megabytes
["4 2 3", "3 2 1", "3 2 5"]
PASSED
try: import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush from math import * from collections import defaultdict as dd, deque, Counter as Cntr from itertools import combinations as comb, permutations as perm ...
1614071100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1 0 1 0 0", "4 3 2 1 0"]
5a146d9d360228313006d54cd5ca56ec
NoteIn the example test case the vertex 1 controls the vertex 3, the vertex 3 controls the vertex 5 (note that is doesn't mean the vertex 1 controls the vertex 5).
Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges).Let's define dist(v, u) as the sum of the intege...
Print n integers — the i-th of these numbers should be equal to the number of vertices that the i-th vertex controls.
The first line contains single integer n (1 ≤ n ≤ 2·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the integers written in the vertices. The next (n - 1) lines contain two integers each. The i-th of these lines contains integers pi and wi (1 ≤ pi ≤ n, 1 ≤ wi ≤ 109) — the parent of the (i + 1...
standard output
standard input
Python 3
Python
1,900
train_016.jsonl
c82fabffe6d157144eb9e897b2f1a629
256 megabytes
["5\n2 5 1 4 6\n1 7\n1 1\n3 5\n3 6", "5\n9 7 8 6 5\n1 1\n2 1\n3 1\n4 1"]
PASSED
import sys import threading from bisect import bisect_left n = int(input()) a = list(map(int, input().split())) e = {} g = [[] for i in range(n)] d = [0]*(n+5) ans = [0]*n p = [0]*(n+5) for i in range(n-1): c, w = map(int, input().split()) c-= 1 g[c].append(i+1) e[i+1] = w ...
1479918900
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1 second
["5.0000000000", "4.7142857143"]
620a9baa531f0c614cc103e70cfca6fd
NoteIn the first sample we should immediately put all five pupils to the bus. The speed of the bus equals 2 and the distance is equal to 10, so the pupils will reach the place of excursion in time 10 / 2 = 5.
On vacations n pupils decided to go on excursion and gather all together. They need to overcome the path with the length l meters. Each of the pupils will go with the speed equal to v1. To get to the excursion quickly, it was decided to rent a bus, which has seats for k people (it means that it can't fit more than k pe...
Print the real number — the minimum time in which all pupils can reach the place of excursion. Your answer will be considered correct if its absolute or relative error won't exceed 10 - 6.
The first line of the input contains five positive integers n, l, v1, v2 and k (1 ≤ n ≤ 10 000, 1 ≤ l ≤ 109, 1 ≤ v1 &lt; v2 ≤ 109, 1 ≤ k ≤ n) — the number of pupils, the distance from meeting to the place of excursion, the speed of each pupil, the speed of bus and the number of seats in the bus.
standard output
standard input
PyPy 3
Python
1,900
train_025.jsonl
e7e932d739db0522d3114f2c1d99ae6b
256 megabytes
["5 10 1 2 5", "3 6 1 2 1"]
PASSED
#!/usr/bin/python3 import sys sys.setrecursionlimit(10 ** 9) def bscheck(n, l, v1, v2, k, t): while True: if k > n: k = n if n == 0: return True if l / v2 > t: return False # v2 * tx + v1 * (t - tx) = l # (v2 - v1) * tx = l - v1 * t ...
1469205300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["16", "24"]
6992db71923a01211b5073ee0f8a193a
NoteThe 16 triples of vertexes from the first sample are: (1, 2, 4), (1, 4, 2), (2, 1, 3), (2, 1, 4), (2, 3, 1), (2, 3, 4), (2, 4, 1), (2, 4, 3), (3, 2, 4), (3, 4, 2), (4, 1, 2), (4, 1, 3), (4, 2, 1), (4, 2, 3), (4, 3, 1), (4, 3, 2).In the second sample all the triples should be counted: 4·3·2 = 24.
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.One day Petya encountered a tree with n vertexes. Besides, the tree was weighted, i. e. each edge of t...
On the single line print the single number — the answer. Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is recommended to use the cin, cout streams or the %I64d specificator.
The first line contains the single integer n (1 ≤ n ≤ 105) — the number of tree vertexes. Next n - 1 lines contain three integers each: ui vi wi (1 ≤ ui, vi ≤ n, 1 ≤ wi ≤ 109) — the pair of vertexes connected by the edge and the edge's weight.
standard output
standard input
Python 3
Python
1,900
train_028.jsonl
244ee45df1ec1d287197caab255065a1
256 megabytes
["4\n1 2 4\n3 1 2\n1 4 7", "4\n1 2 4\n1 3 47\n1 4 7447"]
PASSED
from sys import stdin, stdout import re from random import randrange from pprint import PrettyPrinter pprint = PrettyPrinter(width=55).pprint def is_lucky(num): return re.fullmatch("[47]+", num) is not None gr = None def topo_order(u): res = [(u, None, None)] i = 0 while i < len(res): u, p, _ ...
1314633600
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["-1\n-4\n3\n12"]
3a45b6acdcf3800d1cb4ef8ac96ed4cf
NoteLet $$$f(i, j) = i \cdot j - k \cdot (a_i | a_j)$$$.In the first test case, $$$f(1, 2) = 1 \cdot 2 - k \cdot (a_1 | a_2) = 2 - 3 \cdot (1 | 1) = -1$$$. $$$f(1, 3) = 1 \cdot 3 - k \cdot (a_1 | a_3) = 3 - 3 \cdot (1 | 3) = -6$$$. $$$f(2, 3) = 2 \cdot 3 - k \cdot (a_2 | a_3) = 6 - 3 \cdot (1 | 3) = -3$$$. So the m...
You are given $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ and an integer $$$k$$$. Find the maximum value of $$$i \cdot j - k \cdot (a_i | a_j)$$$ over all pairs $$$(i, j)$$$ of integers with $$$1 \le i &lt; j \le n$$$. Here, $$$|$$$ is the bitwise OR operator.
For each test case, print a single integer  — the maximum possible value of $$$i \cdot j - k \cdot (a_i | a_j)$$$.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains two integers $$$n$$$ ($$$2 \le n \le 10^5$$$) and $$$k$$$ ($$$1 \le k \le \min(n, 100)$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots,...
standard output
standard input
PyPy 3
Python
1,700
train_087.jsonl
94e29cff4e92f511067e34ac4ff4ad6e
256 megabytes
["4\n3 3\n1 1 3\n2 2\n1 2\n4 3\n0 1 2 3\n6 6\n3 2 0 0 5 6"]
PASSED
import sys from collections import deque input = lambda: sys.stdin.readline().rstrip() write = lambda: sys.stdout.write() def driver(): T = int(input()) for _ in range(T): x, y = deque([int(g) for g in input().split()]) maxi = -1000000000 item = deque([int(h) for h in input().sp...
1627569300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2 7 1 3 6 5 4\n7 1 5 4 6 2 3", "-1"]
6b398790adbd26dd9af64e9086e38f7f
NoteIn the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each...
Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d. Two pa...
The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively. The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).
standard output
standard input
Python 3
Python
1,600
train_029.jsonl
c8510bfa3202763e2eb9e78d27022af9
256 megabytes
["7 11\n2 4 7 3", "1000 999\n10 20 30 40"]
PASSED
n, k = input().split(' ') n = int(n) k = int(k) a,b,c,d = input().split(' ') a,b,c,d = int(a),int(b),int(c),int(d) if k <= n: print(-1) exit() if n == 4: print(-1) exit() city = list(range(1,n+1)) road = [a,c] for i in range(len(city)): if city[i] not in (a,b,c,d): road.append(city[i]) road += [d,b] t = '' ...
1462633500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
10 seconds
["BC23\nR23C55"]
910c0e650d48af22fa51ab05e8123709
null
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow th...
Write n lines, each line should contain a cell coordinates in the other numeration system.
The first line of the input contains integer number n (1 ≤ n ≤ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .
standard output
standard input
Python 2
Python
1,600
train_001.jsonl
9bd7e1fbe00260b45a7638c7cd3bc5e2
64 megabytes
["2\nR23C55\nBC23"]
PASSED
m = {} for k in range(26): m[chr(65+k)] = 1+k for abcdd in range(int(raw_input())): a = raw_input() for k in range(len(a)): if a[k].isdigit(): a, b = a[:k], a[k:] break if b.isdigit(): n = 0 for k in a: n = n * 26 + m[k] print 'R' + b ...
1266580800
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
5 seconds
["162", "102"]
ee32db0f67954ed0eccae1429819f4d7
null
You are given $$$n$$$ segments on the coordinate axis. The $$$i$$$-th segment is $$$[l_i, r_i]$$$. Let's denote the set of all integer points belonging to the $$$i$$$-th segment as $$$S_i$$$.Let $$$A \cup B$$$ be the union of two sets $$$A$$$ and $$$B$$$, $$$A \cap B$$$ be the intersection of two sets $$$A$$$ and $$$B$...
Print one integer — the sum of $$$|(((S_1\ \mathbin{op}_1\ S_2)\ \mathbin{op}_2\ S_3)\ \mathbin{op}_3\ S_4)\ \dots\ \mathbin{op}_{n-1}\ S_n|$$$ over all possible ways to choose $$$[\mathbin{op}_1, \mathbin{op}_2, \dots, \mathbin{op}_{n-1}]$$$. Since the answer can be huge, print it modulo $$$998244353$$$.
The first line contains one integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$). Then, $$$n$$$ lines follow. The $$$i$$$-th of them contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$0 \le l_i \le r_i \le 3 \cdot 10^5$$$).
standard output
standard input
PyPy 3-64
Python
2,300
train_089.jsonl
3b8e9b7f182f5f2df6f60cabd91f646e
512 megabytes
["4\n3 5\n4 8\n2 2\n1 9", "4\n1 9\n3 5\n4 8\n2 2"]
PASSED
import cProfile import sys import io import os import traceback from collections import deque from itertools import accumulate # region IO BUFSIZE = 8192 class FastIO(io.IOBase): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self....
1666017300
[ "probabilities" ]
[ 0, 0, 0, 0, 0, 1, 0, 0 ]
2 seconds
["Yes\n3 3 2 1 0", "No", "Yes\n-1 -1"]
39e4bae5abbc0efac5316bec0d540665
NoteSample 1:23 + 23 + 22 + 21 + 20 = 8 + 8 + 4 + 2 + 1 = 23Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.Answers like (4, 1, 1, 1, 0) do not have the minimum y value.Sample 2:It can be shown there does not exist a sequence with length 2.Sample 3:Powers of 2:If x &gt; 0, then 2x = 2·...
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As the...
Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and k numbers separated by space in the second line — the required sequence. It is guaranteed that the integers in the answer sequence fit the range [ - 1018, 1018].
The first line consists of two integers n and k (1 ≤ n ≤ 1018, 1 ≤ k ≤ 105) — the required sum and the length of the sequence.
standard output
standard input
Python 3
Python
2,000
train_008.jsonl
c7ec006127bc6f8e5c08be3eb9f0beae
256 megabytes
["23 5", "13 2", "1 2"]
PASSED
import math x, k = map(int, input().split()) kori = k a = bin(x) # s = a[2:len(a)] qtz = 0; s = [] for i in range(2, len(a)): if a[i] == "1": k-=1 s.append(1) else: qtz+=1 s.append(0) v = [] for i in range(len(s)): if s[i] != 0: v.append((len(s)-1)-i) # else: ...
1516372500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["5\n1 8 6"]
1e0148d417f80b995cac18c2f4cea32e
NoteThe picture corresponding to the first example (and another one correct answer):If you choose vertices $$$1, 5, 6$$$ then the path between $$$1$$$ and $$$5$$$ consists of edges $$$(1, 2), (2, 3), (3, 4), (4, 5)$$$, the path between $$$1$$$ and $$$6$$$ consists of edges $$$(1, 2), (2, 3), (3, 4), (4, 6)$$$ and the p...
You are given an unweighted tree with $$$n$$$ vertices. Recall that a tree is a connected undirected graph without cycles.Your task is to choose three distinct vertices $$$a, b, c$$$ on this tree such that the number of edges which belong to at least one of the simple paths between $$$a$$$ and $$$b$$$, $$$b$$$ and $$$c...
In the first line print one integer $$$res$$$ — the maximum number of edges which belong to at least one of the simple paths between $$$a$$$ and $$$b$$$, $$$b$$$ and $$$c$$$, or $$$a$$$ and $$$c$$$. In the second line print three integers $$$a, b, c$$$ such that $$$1 \le a, b, c \le n$$$ and $$$a \ne, b \ne c, a \ne c$...
The first line contains one integer number $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. Next $$$n - 1$$$ lines describe the edges of the tree in form $$$a_i, b_i$$$ ($$$1 \le a_i$$$, $$$b_i \le n$$$, $$$a_i \ne b_i$$$). It is guaranteed that given graph is a tree.
standard output
standard input
PyPy 3
Python
2,000
train_022.jsonl
7fe5ed1ab433407e763996b788053068
256 megabytes
["8\n1 2\n2 3\n3 4\n4 5\n4 6\n3 7\n3 8"]
PASSED
import sys input = sys.stdin.readline from collections import * def bfs(sta): dist = [-1]*n dist[sta] = 0 par = [-1]*n q = deque([sta]) while q: v = q.popleft() for nv in G[v]: if dist[nv]==-1: dist[nv] = dist[v]+1 par[nv] = ...
1579703700
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
3 seconds
["2\n-\n2\n+", "6\n++-\n2\n+-+"]
d39359344dc38b3c94c6d304880804b4
null
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans: to orient each undirected edge in one of two possible directions to maximize number...
The first two lines should describe the plan which maximizes the number of reachable vertices. The lines three and four should describe the plan which minimizes the number of reachable vertices. A description of each plan should start with a line containing the number of reachable vertices. The second line of a plan sh...
The first line contains three integers n, m and s (2 ≤ n ≤ 3·105, 1 ≤ m ≤ 3·105, 1 ≤ s ≤ n) — number of vertices and edges in the graph, and the vertex Vasya has picked. The following m lines contain information about the graph edges. Each line contains three integers ti, ui and vi (1 ≤ ti ≤ 2, 1 ≤ ui, vi ≤ n, ui ≠ vi)...
standard output
standard input
Python 2
Python
1,900
train_039.jsonl
e6d0b4aa4d1e9bbaddb958342e70f834
256 megabytes
["2 2 1\n1 1 2\n2 2 1", "6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3"]
PASSED
I = lambda:map(int, raw_input().split()) n, m, s = I() E = [I() for i in range(m)] w = ['+'] * sum(a[0] == 2 for a in E) e = [[] for i in range(n)] v, s, p = [0] * n, s - 1, 0 for i in range(m): E[i][1] -= 1 E[i][2] -= 1 if E[i][0] == 2: e[E[i][1]].append([E[i][2], p * 2 + 1]) e[E[i][2]].append([E[i][1], p * 2])...
1508573100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["2\n4\n2\n7\n4"]
19a3247ef9d10563db821ca19b0f9004
NoteThe following are the promising substrings for the first three test cases in the example: $$$s[1 \dots 2]$$$="+-", $$$s[2 \dots 3]$$$="-+"; $$$s[1 \dots 2]$$$="-+", $$$s[2 \dots 3]$$$="+-", $$$s[1 \dots 5]$$$="-+---", $$$s[3 \dots 5]$$$="---"; $$$s[1 \dots 3]$$$="---", $$$s[2 \dots 4]$$$="---".
This is the hard version of Problem F. The only difference between the easy version and the hard version is the constraints.We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balan...
For each test case, print a single number: the number of the promising non-empty substrings of string $$$s$$$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $$$s$$$.
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$): the length of $$$s$$$. T...
standard output
standard input
PyPy 3-64
Python
2,100
train_105.jsonl
e7954c49622720cbf6a1cfb96c101187
256 megabytes
["5\n\n3\n\n+-+\n\n5\n\n-+---\n\n4\n\n----\n\n7\n\n--+---+\n\n6\n\n+++---"]
PASSED
import sys def Print( m ): for r in m: print( r ) print() def Solve( size, s ): cntM = 0 delta = [ 0 ] for idx in range( size ): c = s[idx] if c == '+': cntM -= 1 else : cntM += 1 delta.append( cntM ) m...
1648737300
[ "math", "strings" ]
[ 0, 0, 0, 1, 0, 0, 1, 0 ]
2 seconds
["4 3 6 2", "42", "1 1"]
71dc07f0ea8962f23457af1d6509aeee
null
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 ...
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed t...
standard output
standard input
Python 3
Python
1,700
train_033.jsonl
e5831c25389a89dbda88183639885ac5
256 megabytes
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
PASSED
def getDictionary(myList): myDict = {} for i in range(0, len(myList)): if (myList[i] in myDict): myDict[myList[i]] = myDict[myList[i]] + 1; else: myDict[myList[i]] = 1; return myDict def counting(sizeOfMother, myDict): winTable = [] for i in range(0, sizeOfM...
1443890700
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
2 seconds
["2\n0\n100\n0\n3"]
e6c91f6872c4dd845cb7a156aacab7c7
null
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. You have to choose a positive integer $$$d$$$ and paint all elements into two colors. All elements which are divisible by $$$d$$$ will be painted red, and all other elements will be painted blue.The coloring is called beautiful if there are no pair...
For each testcase print a single integer. If there is no such value of $$$d$$$ that yields a beautiful coloring, print $$$0$$$. Otherwise, print any suitable value of $$$d$$$ ($$$1 \le d \le 10^{18}$$$).
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. The first line of each testcase contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of elements of the array. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le...
standard output
standard input
Python 3
Python
1,100
train_087.jsonl
63640673ff7c24fa3e4638234cddd0c7
256 megabytes
["5\n5\n1 2 3 4 5\n3\n10 5 15\n3\n100 10 200\n10\n9 8 2 6 6 2 8 6 5 4\n2\n1 3"]
PASSED
def GCD(divisor,num): if num == 0: return divisor else: return GCD(num , divisor % num) def solve(array): even_divisor = 0 odd_divisor = 0 for index in range (0 , len(array)): if index % 2 == 0 : even_divisor = GCD(even_divisor , array[index]) ...
1639492500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["3", "3"]
c35102fa418cbfdcb150b52d216040d9
NoteHere are the heights of some valid castles: n = 5, H = 2, [2, 2, 1, 0, ...], [2, 1, 1, 1, 0, ...], [1, 0, 1, 2, 1, 0, ...] n = 6, H = 8, [3, 2, 1, 0, ...], [2, 2, 1, 1, 0, ...], [0, 1, 0, 1, 2, 1, 1, 0...] (this one has 5 spots occupied) The first list for both cases is the optimal answer, 3 spots are occupied i...
You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right. Obviously, there is not enough sand on ...
Print the minimum number of spots you can occupy so the all the castle building conditions hold.
The only line contains two integer numbers n and H (1 ≤ n, H ≤ 1018) — the number of sand packs you have and the height of the fence, respectively.
standard output
standard input
Python 3
Python
2,100
train_007.jsonl
9030d418648a4c6a426f8fc18204cacc
256 megabytes
["5 2", "6 8"]
PASSED
n, H = map(int, input().split()) l = 1 r = n while l < r: mid = int((l + r) / 2) ans = 0 if mid <= H: ans = int(mid * (mid + 1) // 2) pass else : R = int(mid - (H - 1)) Len = int(R - 2) ans = ans + int(H * (H - 1) // 2) tmp = int(R / 2) #print("%d %d %d" % (R, Len, tmp)) ans = ans + (H + H + tmp - 1...
1526913900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1", "-1", "2"]
51ad613842de8eff6226c97812118b61
NoteIn the first example you can select $$$2$$$ and $$$5$$$ and the array becomes $$$[7, 6, 8]$$$.In the second example you can only obtain arrays $$$[1, 1]$$$, $$$[3, 3]$$$ and $$$[0]$$$ which are all non-decreasing.In the third example you can select $$$1$$$ and $$$2$$$ and the array becomes $$$[3, 4, 6, 20]$$$. Then...
Arkady owns a non-decreasing array $$$a_1, a_2, \ldots, a_n$$$. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.In one step you can select two consecutive elements of the array, let's say $$$x$$$ and $$$y$$$, remove them from the array and...
Print a single integer — the minimum number of steps needed. If there is no solution, print $$$-1$$$.
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that $$$a_i \le a_{i + 1}$$$ for all $$$1 \le i &lt; n$$$.
standard output
standard input
Python 2
Python
null
train_003.jsonl
d87b1149bf8218f23d77e1a905b1311c
256 megabytes
["4\n2 5 6 8", "3\n1 2 3", "5\n1 2 4 6 20"]
PASSED
from sys import stdin def main(): n = int(stdin.readline()) a = map(int, stdin.readline().split()) for i in xrange(n - 1): x = a[i] ^ a[i+1] if (i and x < a[i-1]) or (i + 2 < n and x > a[i+2]): print 1 return d = [[0] * n for i in xrange(n)] for i in xrange(n)...
1606633500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1.5 seconds
["5", "60"]
d38c18b0b6716cccbe11eab7b4df8c3a
null
Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance between...
Print one number — $$$p \cdot 2^{n - 1}$$$, taken modulo $$$998244353$$$.
The first line contains one number $$$n$$$ ($$$1 \le n \le 10^6$$$) — the distance from Moscow to Saratov. The second line contains $$$n$$$ integer numbers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_1 \le a_2 \le \dots \le a_n \le 10^6$$$), where $$$a_i$$$ is the difficulty of $$$i$$$-th kilometer after Leha has ...
standard output
standard input
Python 3
Python
2,000
train_006.jsonl
ad03c90f3bc92096a151071fb4a1de1d
256 megabytes
["2\n1 2", "4\n1 3 3 7"]
PASSED
a = int(input()) b = list(map(int,input().split())) c = b[0]%998244353 d = b[0]%998244353 for i in range(1,a): c = (2*c + d + b[i])%998244353 d = (2*d + b[i])%998244353 print(c)
1531578900
[ "probabilities", "math" ]
[ 0, 0, 0, 1, 0, 1, 0, 0 ]
2 seconds
["YES\nNO\nYES\nNO"]
bf89bc12320f635cc121eba99c542444
NoteIn the first test case, regardless of the strategy of his friends, Vlad can win by going to room $$$4$$$. The game may look like this: The original locations of Vlad and friends. Vlad is marked in green, friends — in red. Locations after one unit of time. End of the game. Note that if Vlad tries to reach the e...
The only difference with E2 is the question of the problem..Vlad built a maze out of $$$n$$$ rooms and $$$n-1$$$ bidirectional corridors. From any room $$$u$$$ any other room $$$v$$$ can be reached through a sequence of corridors. Thus, the room system forms an undirected tree.Vlad invited $$$k$$$ friends to play a gam...
Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to a test case should be "YES" if Vlad can guarantee himself a victory and "NO" otherwise. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" will all be recognized as...
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. The input contains an empty string before each test case. The first line of the test case contains two numbers $$$n$$$ and $$$k$$$ ($$$1 \le k &lt; n \le 2\cdot 10^5$$$) — the number of rooms and fr...
standard output
standard input
PyPy 3-64
Python
1,700
train_093.jsonl
14aba60c00471c41a7eab00823af4f35
256 megabytes
["4\n\n8 2\n5 3\n4 7\n2 5\n1 6\n3 6\n7 2\n1 7\n6 8\n\n3 1\n2\n1 2\n2 3\n\n3 1\n2\n1 2\n1 3\n\n3 2\n2 3\n3 1\n1 2"]
PASSED
# RANK1ZEN; 3966 PEAK NA FLEX SUPPORT; Battlenet ID: Knuckles#11791 # region -----------------------------------------------------------------------------------------| # oooo+oshdy+/smooyNMNNMMMmo/::----/dNsomMMMNNMy/::--::/mNoodNdmdo/:-://////::::::::. # ooooyNMMMyssNyosmMMMMMMNs+::----::++//+oooooo/::----:...
1637850900
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["10\n4975\n38\n0\n0"]
20dd260775ea71b1fb5b42bcac90a6f2
NoteFor the first test case, you can eat $$$1$$$ candy from the second box, $$$2$$$ candies from the third box, $$$3$$$ candies from the fourth box and $$$4$$$ candies from the fifth box. Now the boxes have $$$[1, 1, 1, 1, 1]$$$ candies in them and you ate $$$0 + 1 + 2 + 3 + 4 = 10$$$ candies in total so the answer is ...
There are $$$n$$$ boxes with different quantities of candies in each of them. The $$$i$$$-th box has $$$a_i$$$ candies inside.You also have $$$n$$$ friends that you want to give the candies to, so you decided to give each friend a box of candies. But, you don't want any friends to get upset so you decided to eat some (...
For each test case, print a single integer denoting the minimum number of candies you have to eat to satisfy the requirements.
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 50$$$) — the number of boxes you have. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \l...
standard output
standard input
Python 3
Python
800
train_106.jsonl
2360f6064ac5af26395eaef07e640a70
256 megabytes
["5\n\n5\n\n1 2 3 4 5\n\n6\n\n1000 1000 5 1000 1000 1000\n\n10\n\n1 2 3 5 1 2 7 9 13 5\n\n3\n\n8 8 8\n\n1\n\n10000000"]
PASSED
test_cases = int(input()) for i in range(test_cases): l = int(input()) arr = list(map(int, input().split())) arr.sort() print(sum(arr) - (arr[0]*l))
1652193900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["3 0", "5 5 3 2 0", "1"]
75d05c16baaba4b17ad6a9c1dd641bc0
null
SaMer has written the greatest test case of all time for one of his problems. For a given array of integers, the problem asks to find the minimum number of groups the array can be divided into, such that the product of any pair of integers in the same group is a perfect square. Each integer must be in exactly one group...
Output $$$n$$$ space-separated integers, the $$$k$$$-th integer should be the number of contiguous subarrays of $$$A$$$ that have an answer to the problem equal to $$$k$$$.
The first line of input contains a single integer $$$n$$$ ($$$1 \leq n \leq 5000$$$), the size of the array. The second line contains $$$n$$$ integers $$$a_1$$$,$$$a_2$$$,$$$\dots$$$,$$$a_n$$$ ($$$-10^8 \leq a_i \leq 10^8$$$), the values of the array.
standard output
standard input
PyPy 2
Python
2,100
train_044.jsonl
b41f474e2dc386ff02d7e818c0795b3a
256 megabytes
["2\n5 5", "5\n5 -4 2 1 8", "1\n0"]
PASSED
#n=input() #l=map(int, raw_input().split()) #pr=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, ...
1525791900
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["1001", "32"]
14c37283d16cb3aa8dd8fc7ea8f1096d
null
Given an array $$$a$$$, consisting of $$$n$$$ integers, find:$$$$$$\max\limits_{1 \le i &lt; j \le n} LCM(a_i,a_j),$$$$$$where $$$LCM(x, y)$$$ is the smallest positive integer that is divisible by both $$$x$$$ and $$$y$$$. For example, $$$LCM(6, 8) = 24$$$, $$$LCM(4, 12) = 12$$$, $$$LCM(2, 3) = 6$$$.
Print one integer, the maximum value of the least common multiple of two elements in the array $$$a$$$.
The first line contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — the elements of the array $$$a$$$.
standard output
standard input
PyPy 2
Python
2,900
train_017.jsonl
6f15819de120d5fa08b2af49cab75436
256 megabytes
["3\n13 35 77", "6\n1 2 4 8 16 32"]
PASSED
import sys from fractions import gcd input = sys.stdin.readline n = int(input()) A = map(int, input().split()) divisors = [[] for _ in range(10**5+2)] mobius = [1 for _ in range(10**5+2)] for i in range(1,10**5+1): for j in range(i,10**5+1,i): divisors[j].append(i) for i in range(1,10**5+1): for d i...
1578665100
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
1 second
["2\n1 0\n1 3", "0"]
4a50c4147becea13946272230f3dde6d
NoteIn the first example, you can solve the problem in two operations: Swap the prefix of the first string with length 1 and the prefix of the second string with length 0. After this swap, you'll have strings ab and bbb. Swap the prefix of the first string with length 1 and the prefix of the second string with length...
There are two strings s and t, consisting only of letters a and b. You can make the following operation several times: choose a prefix of s, a prefix of t and swap them. Prefixes can be empty, also a prefix can coincide with a whole string. Your task is to find a sequence of operations after which one of the strings co...
The first line should contain a single integer n (0 ≤ n ≤ 5·105) — the number of operations. Each of the next n lines should contain two space-separated integers ai, bi — the lengths of prefixes of s and t to swap, respectively. If there are multiple possible solutions, you can print any of them. It's guaranteed that a...
The first line contains a string s (1 ≤ |s| ≤ 2·105). The second line contains a string t (1 ≤ |t| ≤ 2·105). Here |s| and |t| denote the lengths of s and t, respectively. It is guaranteed that at least one of the strings contains at least one a letter and at least one of the strings contains at least one b letter.
standard output
standard input
PyPy 3
Python
2,800
train_017.jsonl
f77d6d60de956907fe5e3250711dadbc
256 megabytes
["bab\nbb", "bbbb\naaa"]
PASSED
from sys import exit def blokovi(x): ret = [0] for i in range(len(x) - 1): if x[i] != x[i + 1]: ret.append(i + 1) return ret + [len(x)] s = input() t = input() ss = blokovi(s) tt = blokovi(t) if s[-1] == 'a': s += 'b' else: s += 'a' if t[-1] == 'a': t += 'b' else: t ...
1532938500
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
5 seconds
["56"]
a6ca373007dc86193721b52bf35f5af8
NoteThe following explanation assumes $$$b = [2, 1]$$$ and $$$c=[2, 3, 4]$$$ (as in the sample).Examples of arrays $$$a$$$ that are not good: $$$a = [3, 2, 3]$$$ is not good because $$$a_1 &gt; c_1$$$; $$$a = [0, -1, 3]$$$ is not good because $$$a_2 &lt; 0$$$. One possible good array $$$a$$$ is $$$[0, 2, 4]$$$. We c...
This is the easy version of the problem. The only difference is that in this version $$$q = 1$$$. You can make hacks only if both versions of the problem are solved.There is a process that takes place on arrays $$$a$$$ and $$$b$$$ of length $$$n$$$ and length $$$n-1$$$ respectively. The process is an infinite sequence ...
Output $$$q$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th query, i. e. the number of good arrays $$$a$$$ where $$$F(a, b) \geq x_i$$$ modulo $$$10^9+7$$$.
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$). The second line contains $$$n$$$ integers $$$c_1, c_2 \ldots, c_n$$$ ($$$0 \le c_i \le 100$$$). The third line contains $$$n-1$$$ integers $$$b_1, b_2, \ldots, b_{n-1}$$$ ($$$0 \le b_i \le 100$$$). The fourth line contains a single integer $$$q$$...
standard output
standard input
PyPy 3
Python
2,700
train_092.jsonl
ed9a76a4f4822e2bab009c9afaae44c4
256 megabytes
["3\n2 3 4\n2 1\n1\n-1"]
PASSED
def putin(): return map(int, input().split()) def sol(): n = int(input()) C = list(putin()) B = list(putin()) q = int(input()) x = int(input()) min_arr = [x] min_part_sums = [x] part_sums = [C[0]] for i in range(1, n): part_sums.append(part_sums[-1] + C[i]...
1624635300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2\n1 0\n2 0", "1\n0 1"]
14ad30e33bf8cad492e665b0a486008e
NoteThe XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor".
Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the first integer is the number of vertices adjacent to vertex v, and the secon...
In the first line print number m, the number of edges of the graph. Next print m lines, each containing two distinct numbers, a and b (0 ≤ a ≤ n - 1, 0 ≤ b ≤ n - 1), corresponding to edge (a, b). Edges can be printed in any order; vertices of the edge can also be printed in any order.
The first line contains integer n (1 ≤ n ≤ 216), the number of vertices in the graph. The i-th of the next lines contains numbers degreei and si (0 ≤ degreei ≤ n - 1, 0 ≤ si &lt; 216), separated by a space.
standard output
standard input
Python 3
Python
1,500
train_003.jsonl
25c48b28e0b8a426282835b0866fcf9e
256 megabytes
["3\n2 3\n1 0\n1 0", "2\n1 1\n1 0"]
PASSED
from collections import deque n = int(input()) process = deque() vs = [] for i in range(n): d, s = map(int, input().split()) if d == 1: process.append(i) vs.append((d, s)) edges = [] while process: a = process.popleft() d, s = vs[a] if d == 0: continue dd, ss = vs[s] vs[s...
1421053200
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["4", "4"]
0f8ad0ea2befbbe036fbd5e5f6680c21
NoteIn the first example, the following sequences are examples of good sequences: [2; 4; 6; 9], [2; 4; 6], [3; 9], [6]. The length of the longest good sequence is 4.
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a1, a2, ..., an are good.Now she is interested in good sequences. A sequence x1, x2, ..., xk is called good if it satisfies the following three conditions: The sequence is strictly increasing, i.e. xi &lt; xi + 1 for ...
Print a single integer — the length of the longest good sequence.
The input consists of two lines. The first line contains a single integer n (1 ≤ n ≤ 105) — the number of good integers. The second line contains a single-space separated list of good integers a1, a2, ..., an in strictly increasing order (1 ≤ ai ≤ 105; ai &lt; ai + 1).
standard output
standard input
Python 3
Python
1,500
train_007.jsonl
e7abb1a8a03e90e76ee27274635721a3
256 megabytes
["5\n2 3 4 6 9", "9\n1 2 3 5 6 7 8 9 10"]
PASSED
n = 100001 m = int(input()) div = [[] for _ in range(n)] div[1] = [1] for i in range(2, n): if not div[i]: div[i] = [i] for j in range(2 * i, n, i): div[j].append(i) a = list(map(int, input().rstrip().split())) dp = [0] * (n + 1) for i in a: x = max(dp[j] for j in div[i]) + 1 for...
1358686800
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
2 seconds
["1\n10\n22"]
fa11eb753c2cae620c139030f5ca5850
NoteIn the first test case, we can swap person $$$4$$$ and person $$$1$$$ (who are adjacent) in the initial configuration and get the order $$$[4, 2, 3, 1]$$$ which is equivalent to the desired one. Hence in this case a single swap is sufficient.
There are $$$n$$$ people, numbered from $$$1$$$ to $$$n$$$, sitting at a round table. Person $$$i+1$$$ is sitting to the right of person $$$i$$$ (with person $$$1$$$ sitting to the right of person $$$n$$$).You have come up with a better seating arrangement, which is given as a permutation $$$p_1, p_2, \dots, p_n$$$. Mo...
For each test case, print the minimum number of swaps necessary to achieve the desired order.
Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1\le t\le 10\,000$$$) — the number of test cases. The descriptions of the $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 200\,000$$$) — the number of people sitting at th...
standard output
standard input
PyPy 3-64
Python
-1
train_085.jsonl
f0a1d0101ac35c51b72032a4aea9cba5
256 megabytes
["3\n\n4\n\n2 3 1 4\n\n5\n\n5 4 3 2 1\n\n7\n\n4 1 6 5 3 7 2"]
PASSED
import sys input = sys.stdin.readline class SegmentTree: def __init__(self, data, default=0, func=lambda x, y: x + y): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - ...
1650798300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["? 0000\n\n? 1110\n\n? 1111\n\n? 1101\n\n! 7"]
003b7257b35416ec93f189cb29e458e6
NoteHere is the graph of the example, satisfying $$$l_i=i$$$.
As for the technology in the outside world, it is really too advanced for Gensokyo to even look up to.—Yasaka Kanako, Symposium of Post-mysticismThis is an interactive problem.Under the direct supervision of Kanako and the Moriya Shrine, the railway system of Gensokyo is finally finished. GSKR (Gensokyo Railways) consi...
null
The first and only line of input contains two integers $$$n,m$$$ ($$$2 \leq n \leq 200$$$, $$$1\le m \le 500$$$) — the number of stations and tracks.
standard output
standard input
Python 3
Python
1,700
train_091.jsonl
d95e7973957489e08018b96a05bdbdb4
256 megabytes
["5 4\n\n0\n\n5\n\n9\n\n7"]
PASSED
def ask(ii): aa = [0]*m for i in ii: aa[i] = 1 print("? ", *aa, sep="", flush=True) return int(input()) n, m = map(int, input().split()) ll = [] for i in range(m): ll.append(ask([i])) il = sorted(enumerate(ll), key=lambda x: x[1]) ans = il[0][1] ii = [il[0][0]] for i, l in il[1:]: ...
1654266900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["YES\nYES\nNO\nYES"]
6e6356adb23da0dfa38834a0e157524c
null
You are given an array $$$a$$$ of $$$n$$$ positive integers.You can use the following operation as many times as you like: select any integer $$$1 \le k \le n$$$ and do one of two things: decrement by one $$$k$$$ of the first elements of the array. decrement by one $$$k$$$ of the last elements of the array. For exam...
For each test case, output on a separate line: YES, if it is possible to make all elements of the array equal to zero by applying a certain number of operations. NO, otherwise. The letters in the words YES and NO can be outputed in any case.
The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 30000$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case begins with a line containing one integer $$$n$$$ ($$$1 \le n \le 30000$$$) — the number of elements in the array. The second line of each test case contains $$$n$$$ ...
standard output
standard input
Python 3
Python
1,800
train_004.jsonl
d0612e48f0888fb311666dc7b62a70c0
256 megabytes
["4\n3\n1 2 1\n5\n11 7 9 6 8\n5\n1 3 1 3 1\n4\n5 2 1 10"]
PASSED
t = int(input()) for i in range(t): n = int(input()) a = [0] + list(map(int, input().split())) ans = [a[i] - a[i-1] for i in range(1, n+1)] result = 0 for i in range(1, n): if ans[i] < 0: result = result + (-1)*ans[i] if result <= a[1]: print("YES") el...
1604327700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
0.5 seconds
["108.395919545675"]
fd92081afd795789b738009ff292a25c
null
It was decided in IT City to distinguish successes of local IT companies by awards in the form of stars covered with gold from one side. To order the stars it is necessary to estimate order cost that depends on the area of gold-plating. Write a program that can calculate the area of a star.A "star" figure having n ≥ 5 ...
Output one number — the star area. The relative error of your answer should not be greater than 10 - 7.
The only line of the input contains two integers n (5 ≤ n &lt; 109, n is prime) and r (1 ≤ r ≤ 109) — the number of the star corners and the radius of the circumcircle correspondingly.
standard output
standard input
Python 3
Python
2,100
train_019.jsonl
eb113dd3b5571bfd534005991d451e00
64 megabytes
["7 10"]
PASSED
import math n, r = map(int, input().split()) a = math.pi / n b = a / 2 print(r * math.sin(b) / math.sin(math.pi - a - b) * math.sin(a) * r * n)
1455807600
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
1 second
["3", "1", "0"]
2be73aa00a13be5274cf840ecd3befcb
NoteIn the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.If you give the order to change the leg to the third ...
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits beg...
Print single integer k — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached. Consider that columns are numbered from 1 to n in the order they are given in the input data. If there are several answers, print any of them.
The first line contains single integer n (1 ≤ n ≤ 105) — the number of columns. The next n lines contain the pairs of integers li and ri (1 ≤ li, ri ≤ 500) — the number of soldiers in the i-th column which start to march from the left or the right leg respectively.
standard output
standard input
Python 3
Python
1,100
train_001.jsonl
8b52ffbf0852fbb099c83c2c6a81cf5a
256 megabytes
["3\n5 6\n8 9\n10 3", "2\n6 5\n5 6", "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32"]
PASSED
from copy import deepcopy def f(n, m): return abs(n - m) n = int(input()) mas = [] L = 0 R = 0 for i in range(n): l, r = map(int, input().split()) mas.append((l, r)) L += l R += r sum = f(L, R) old = deepcopy(sum) new = deepcopy(old) #print(L, R) for i in range(n): L -= mas[i][0] R -= mas[...
1477922700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["YES\nNO\nNO\nYES\nYES\nYES\nYES"]
78f25e2bc4ff22dbac94f72af68a745f
NoteOne possible casting sequence of the first test case is shown below: Void Absorption $$$\left\lfloor \frac{100}{2} \right\rfloor + 10=60$$$. Lightning Strike $$$60-10=50$$$. Void Absorption $$$\left\lfloor \frac{50}{2} \right\rfloor + 10=35$$$. Void Absorption $$$\left\lfloor \frac{35}{2} \right\rfloor + 10=27$$$. ...
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic. One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon. The dragon has a hit point of $$$x...
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower).
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$)  — the number of test cases. The next $$$t$$$ lines describe test cases. For each test case the only line contains three integers $$$x$$$, $$$n$$$, $$$m$$$ ($$$1\le x \le 10^5$$$, $$$0\le n,m\le30$$$)  — the dragon's intitial hit point, the max...
standard output
standard input
PyPy 2
Python
900
train_001.jsonl
134edbe2dba84432cdd1bf3d7310f3d9
256 megabytes
["7\n100 3 4\n189 3 4\n64 2 3\n63 2 3\n30 27 7\n10 9 1\n69117 21 2"]
PASSED
import atexit, io, sys # A stream implementation using an in-memory bytes # buffer. It inherits BufferedIOBase. buffer = io.BytesIO() sys.stdout = buffer # print via here @atexit.register def write(): sys.__stdout__.write(buffer.getvalue()) for _ in range(input()): x,n,m=map(int,raw_input(...
1586961300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["NO", "YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24"]
1bd1a7fd2a07e3f8633d5bc83d837769
null
Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.Initially you have a sequence of n integers: 1, 2, ..., n. In a single step, you can pick two of them, let's denote them a and b, erase them from the sequence, and append to the sequence either a + b, or...
If it's possible, print "YES" in the first line. Otherwise, print "NO" (without the quotes). If there is a way to obtain 24 as the result number, in the following n - 1 lines print the required operations an operation per line. Each operation should be in form: "a op b = c". Where a and b are the numbers you've picked ...
The first line contains a single integer n (1 ≤ n ≤ 105).
standard output
standard input
Python 2
Python
1,500
train_002.jsonl
cbddec7a8c3aa62a8596bba43292afea
256 megabytes
["1", "8"]
PASSED
a=input() if(a<4): print "NO" elif(a==4): print "YES" print "4 * 3 = 12" print "2 * 1 = 2" print "12 * 2 = 24" elif(a==5): print "YES" print "5 - 3 = 2" print "2 + 1 = 3" print "2 * 3 = 6" print "6 * 4 = 24" elif(a>5): print "YES" print "6 * 4 = 24" print "3 - 2 = 1" print "1 - 1 = 0" print "0 * 5 = 0" ...
1411218000
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2\n-1\n0\n3\n2"]
8ca8317ce3f678c99dc746cb9b058993
NoteIn the first test case, you can choose a letter 'a' and erase its first and last occurrences, you will get a string 'bcaacb', which is a palindrome. You can also choose a letter 'b' and erase all its occurrences, you will get a string 'acaaca', which is a palindrome as well.In the second test case, it can be shown ...
Grandma Capa has decided to knit a scarf and asked Grandpa Sher to make a pattern for it, a pattern is a string consisting of lowercase English letters. Grandpa Sher wrote a string $$$s$$$ of length $$$n$$$.Grandma Capa wants to knit a beautiful scarf, and in her opinion, a beautiful scarf can only be knit from a strin...
For each test case print the minimum number of erased symbols required to make the string a palindrome, if it is possible, and $$$-1$$$, if it is impossible.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$2 \cdot t$$$ lines contain the description of test cases. The description of each test case consists of two lines. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) ...
standard output
standard input
PyPy 3-64
Python
1,200
train_106.jsonl
541454725187f77fba935aedfe1b20e8
256 megabytes
["5\n8\nabcaacab\n6\nxyzxyz\n4\nabba\n8\nrprarlap\n10\nkhyyhhyhky"]
PASSED
import os, sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if ...
1635069900
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["2\n3"]
63108f3cc494df3c7bb62381c03801b3
NoteIn the first test case, the initial array contains elements $$$[6, 8, 4, 2]$$$. Element $$$a_4=2$$$ in this array is adjacent to $$$a_4=2$$$ (since $$$\frac{lcm(2, 2)}{gcd(2, 2)}=\frac{2}{2}=1=1^2$$$) and $$$a_2=8$$$ (since $$$\frac{lcm(8,2)}{gcd(8, 2)}=\frac{8}{2}=4=2^2$$$). Hence, $$$d_4=2$$$, and this is the max...
Let us call two integers $$$x$$$ and $$$y$$$ adjacent if $$$\frac{lcm(x, y)}{gcd(x, y)}$$$ is a perfect square. For example, $$$3$$$ and $$$12$$$ are adjacent, but $$$6$$$ and $$$9$$$ are not.Here $$$gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$, and $$$lcm(x, y)$$$ denotes the ...
For each query output a single integer — the beauty of the array at the corresponding moment.
The first input line contains a single 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 3 \cdot 10^5$$$) — the length of the array. The following line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$1 \le a_i \le...
standard output
standard input
PyPy 3-64
Python
1,900
train_084.jsonl
0b5434ac898e94510e93f67531bd6ba9
256 megabytes
["2\n4\n6 8 4 2\n1\n0\n6\n12 3 20 5 80 1\n1\n1"]
PASSED
import sys, random input = lambda : sys.stdin.readline().rstrip() write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x)) debug = lambda x: sys.stderr.write(x+"\n") YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); inf=10**18 LI = lambda : list(map(int, input().split())) d...
1609857300
[ "number theory", "math", "graphs" ]
[ 0, 0, 1, 1, 1, 0, 0, 0 ]
2 seconds
["2\n1\n2\n0"]
130fd7f40d879e25b0bff886046bf699
NoteExamples for the queries $$$1-3$$$ are shown at the image in the legend section.The Russian meme to express the quality of the ladders:
Let's denote a $$$k$$$-step ladder as the following structure: exactly $$$k + 2$$$ wooden planks, of which two planks of length at least $$$k+1$$$ — the base of the ladder; $$$k$$$ planks of length at least $$$1$$$ — the steps of the ladder; Note that neither the base planks, nor the steps planks are required to be e...
Print $$$T$$$ integers — one per query. The $$$i$$$-th integer is the maximum number $$$k$$$, such that you can choose some subset of the planks given in the $$$i$$$-th query and assemble a $$$k$$$-step ladder using them. Print $$$0$$$ if you can't make even $$$1$$$-step ladder from the given set of planks.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. The queries are independent. Each query consists of two lines. The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of planks you have. The second line contains $$$n$$$ integers $$$a_1, a_...
standard output
standard input
Python 3
Python
900
train_002.jsonl
a17acec868989cd3e7169b864141978b
256 megabytes
["4\n4\n1 3 1 3\n3\n3 3 2\n5\n2 3 3 4 2\n3\n1 1 2"]
PASSED
t=int((input())) l2=[] for i in range(t): n=int(input()) l1=[int(a) for a in input().split()] max1=0 max2=0 for k in range(n): if(l1[k]>=max1): max2=max1 max1=l1[k] elif(l1[k]>max2): max2=l1[k] else: continue c=0 for k in range(n): if(l1[k]<=max1): c+=1 if(c-2<max2): l2.append(c-2) ...
1563806100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["4\n-1\n0\n-1"]
61bbe7bc4698127511a0bdbc717e2526
NoteConsider the first test.In the first test case, you can act like this (the vertex to which the operation is applied at the current step is highlighted in purple): It can be shown that it is impossible to make a tree beautiful in fewer operations.In the second test case, it can be shown that it is impossible to m...
The girl named Masha was walking in the forest and found a complete binary tree of height $$$n$$$ and a permutation $$$p$$$ of length $$$m=2^n$$$.A complete binary tree of height $$$n$$$ is a rooted tree such that every vertex except the leaves has exactly two sons, and the length of the path from the root to any of th...
For each test case in a separate line, print the minimum possible number of operations for which Masha will be able to make the tree beautiful or -1, if this is not possible.
The first line contains single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. In each test case, the first line contains an integer $$$m$$$ ($$$1 \le m \le 262144$$$), which is a power of two  — the size of the permutation $$$p$$$. The second line contains $$$m$$$ integers: $$$p_1, p_2, \dots, p_m$$$ ...
standard output
standard input
Python 3
Python
1,300
train_084.jsonl
64ac2d97b70a65370b059664439d2ced
256 megabytes
["4\n\n8\n\n6 5 7 8 4 3 1 2\n\n4\n\n3 1 4 2\n\n1\n\n1\n\n8\n\n7 8 4 3 1 2 6 5"]
PASSED
def greater(a ,b): if len(a) > len(b): return True if len(a) < len(b): return False for i in range(len(a)): if a[i] > b[i]: return True elif a[i] < b[i]: return False return False for _ in range(int(input())): f = False n = int(input()) a...
1665498900
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1 second
["2\n3 4\n1 4\n4\n1 2\n2 2\n2 4\n5 4\n1\n5 1", "1\n1 1\n1\n1 2\n1\n1 3", "1\n1 1\n1\n2 2\n1\n3 1"]
29476eefb914b445f1421d99d928fd5a
NoteRooks arrangements for all three examples (red is color $$$1$$$, green is color $$$2$$$ and blue is color $$$3$$$).
Ivan is a novice painter. He has $$$n$$$ dyes of different colors. He also knows exactly $$$m$$$ pairs of colors which harmonize with each other.Ivan also enjoy playing chess. He has $$$5000$$$ rooks. He wants to take $$$k$$$ rooks, paint each of them in one of $$$n$$$ colors and then place this $$$k$$$ rooks on a ches...
Print $$$n$$$ blocks, $$$i$$$-th of them describes rooks of $$$i$$$-th color. In the first line of block print one number $$$a_{i}$$$ ($$$1 \le a_{i} \le 5000$$$) — number of rooks of color $$$i$$$. In each of next $$$a_{i}$$$ lines print two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, \,\, y \le 10^{9}$$$) — coordinates...
The first line of input contains $$$2$$$ integers $$$n$$$, $$$m$$$ ($$$1 \le n \le 100$$$, $$$0 \le m \le min(1000, \,\, \frac{n(n-1)}{2})$$$) — number of colors and number of pairs of colors which harmonize with each other. In next $$$m$$$ lines pairs of colors which harmonize with each other are listed. Colors are nu...
standard output
standard input
Python 3
Python
1,700
train_025.jsonl
9c035837e10c647a0aa1649a7ade52d4
256 megabytes
["3 2\n1 2\n2 3", "3 3\n1 2\n2 3\n3 1", "3 1\n1 3"]
PASSED
n, m = list(map(int, input().split())) G = [[] for _ in range(n + 1)] final = [[] for _ in range(n + 1)] seen = {} for _ in range(m): a, b = list(map(int, input().split())) if a > b: a,b = b,a seen[a] = True seen[b] = True G[a].append(b) step = 1 for i in range(1, n + 1): hrmny = G[i...
1540398900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["17", "4"]
a9473e6ec81c10c4f88973ac2d60ad04
NoteFor the first test case, here's how a circular value of $$$17$$$ is obtained:Pick the number at index $$$3$$$. The sum of adjacent elements equals $$$17$$$. Delete $$$7$$$ and $$$10$$$ from the circle and replace $$$2$$$ with $$$17$$$.Note that the answer may not fit in a $$$32$$$-bit integer.
Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!You are given $$$n$$$ nonnegative integers $$$a_1, a_2, \dots, a_n$$$ arranged in a circle, where $$$n$$$ must be odd (ie. $$$n-1$$$ is divisible by $$$2$$$). Formally, for all $$$i$$$ such that $$$2...
Output the maximum possible circular value after applying some sequence of operations to the given circle.
The first line contains one odd integer $$$n$$$ ($$$1 \leq n &lt; 2 \cdot 10^5$$$, $$$n$$$ is odd)  — the initial size of the circle. The second line contains $$$n$$$ integers $$$a_{1},a_{2},\dots,a_{n}$$$ ($$$0 \leq a_{i} \leq 10^9$$$)  — the initial numbers in the circle.
standard output
standard input
PyPy 3
Python
2,100
train_001.jsonl
5730229839b896fb668424c586bd0a78
256 megabytes
["3\n7 10 2", "1\n4"]
PASSED
## necessary imports import sys input = sys.stdin.readline # from math import ceil, floor, factorial; def ceil(x): if x != int(x): x = int(x) + 1; return x; # swap_array function def swaparr(arr, a,b): temp = arr[a]; arr[a] = arr[b]; arr[b] = temp; ## gcd function def gcd(a,b): if...
1594479900
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
2 seconds
["3\n1\n1"]
16c4160d1436206412ce51315cb6140b
NoteIn the first test case, there is only one tree with the given visiting order: In the second test case, there is only one tree with the given visiting order as well: In the third test case, an optimal tree with the given visiting order is shown below:
Monocarp had a tree which consisted of $$$n$$$ vertices and was rooted at vertex $$$1$$$. He decided to study BFS (Breadth-first search), so he ran BFS on his tree, starting from the root. BFS can be described by the following pseudocode:a = [] # the order in which vertices were processedq = Queue()q.put(1) # place the...
For each test case print the minimum possible height of a tree with the given visiting order $$$a$$$.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, ...
standard output
standard input
PyPy 3
Python
1,600
train_018.jsonl
c6512aa0f0df7821a149c814cbe660c9
256 megabytes
["3\n4\n1 4 3 2\n2\n1 2\n3\n1 2 3"]
PASSED
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) d,c = [0]*n,0 for i in range(1,n): if l[i-1] > l[i]: c += 1 d[i] = d[c] + 1 print(d[n-1]) ''' 5 1 2 5 4 3 '''
1603809300
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
2 seconds
["3\n2\n2", "401\n4\n3"]
b56e70728d36c41134c39bd6ad13d059
NoteIn the first example the three ways to split the message are: a|a|b aa|b a|ab The longest substrings are "aa" and "ab" of length 2.The minimum number of substrings is 2 in "a|ab" or "aa|b".Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alpha...
Print three lines. In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo 109  +  7. In the second line print the length of the longest substring over all the ways. In the third line print the minimum number of substrings over all the w...
The first line contains an integer n (1 ≤ n ≤ 103) denoting the length of the message. The second line contains the message s of length n that consists of lowercase English letters. The third line contains 26 integers a1, a2, ..., a26 (1 ≤ ax ≤ 103) — the maximum lengths of substring each letter can appear in.
standard output
standard input
Python 3
Python
1,700
train_030.jsonl
a633f0f9026dbd51819f8731f8cb8762
256 megabytes
["3\naab\n2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10\nabcdeabcde\n5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1"]
PASSED
n=int(input()) s=input() l=list(map(int,input().split())) dp=[0]*(n+2) mn=[10**4]*(n+2) dp[0]=dp[n+1]=1 mn[0]=1 mn[n+1]=0 mod=10**9+7 maxx=1 for i in range(1,n): cur=10**4 for j in range(i,-1,-1): c=ord(s[j])-ord('a') cur=min(cur,l[c]) if cur<(i-j+1): break dp[i]=(dp[i]+dp[j-1])%mod mn[i]...
1486487100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["12330", "1115598"]
b4cd60296083ee2ae8a560209433dcaf
null
This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers $$$a_1, a_2, \dots, a_n$$$.A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, ...
Print the answer modulo $$$998\,244\,353$$$.
The first line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 100\,000$$$) — the number of elements in the array. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array.
standard output
standard input
Python 3
Python
1,800
train_024.jsonl
5f978c9edc3021dcd5c96aedb1cf1f43
256 megabytes
["3\n12 3 45", "2\n123 456"]
PASSED
import sys from collections import deque IS_LOCAL = False def read_one(dtype=int): return dtype(input()) def read_multiple(f, dtype=int): return f(map(dtype, input().split())) def swap(x, y): return y, x def main(): n = 3 a = [12, 3, 45] if not IS_LOCAL: n = read_one() ...
1563374100
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["2 3", "6 4 1 4 2"]
2c51fa9ddc72caaebb29dd65a2db030e
null
There are n cities in Berland. Each city has its index — an integer number from 1 to n. The capital has index r1. All the roads in Berland are two-way. The road system is such that there is exactly one path from the capital to each city, i.e. the road map looks like a tree. In Berland's chronicles the road map is kept ...
Output n - 1 numbers — new representation of the road map in the same format.
The first line contains three space-separated integers n, r1, r2 (2 ≤ n ≤ 5·104, 1 ≤ r1 ≠ r2 ≤ n) — amount of cities in Berland, index of the old capital and index of the new one, correspondingly. The following line contains n - 1 space-separated integers — the old representation of the road map. For each city, apart f...
standard output
standard input
Python 2
Python
1,600
train_006.jsonl
a731f2543ab28ad2e2d56ebc1ccc9e44
256 megabytes
["3 2 3\n2 2", "6 2 4\n6 1 2 4 2"]
PASSED
import sys import os import string (n,r1,r2)=[int(x) for x in raw_input().split()] line=[int(x) for x in raw_input().split()] fa=[0]*(n+1) j=0 for i in xrange(1,n+1): if (i==r1): continue; fa[i]=line[j] j+=1 ans=fa[:] p=r2 while p!=r1: ans[fa[p]]=p p=fa[p] ans[r2]=-1 for t in [str(x) for x i...
1286802000
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
3 seconds
["2", "11"]
bd7b85c0204f6b36dc07f8a96fc36161
NoteIn the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers ...
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
The first line of the input contains the single integer n (1 ≤ n ≤ 200 000) — the number of watchmen. Each of the following n lines contains two integers xi and yi (|xi|, |yi| ≤ 109). Some positions may coincide.
standard output
standard input
PyPy 3
Python
1,400
train_018.jsonl
f51dde9ddf8a351a16c54a1d9bc2c5a4
256 megabytes
["3\n1 1\n7 5\n1 5", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1"]
PASSED
points = [] row_count = int(input()) for _ in range(row_count): rawLine = input().split() points.append([int(rawLine[0]),int(rawLine[1])]) total = 0 for i in range(2): points.sort(key= lambda x : x[i]) previous = 1 for j in range(1,row_count+1): if j != row_count and points[j][i] == poin...
1457342700
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
3 seconds
["4\n10\n4\n0"]
afcd41492158e68095b01ff1e88c3dd4
NoteIn the first test case of the example, the optimal sequence of moves can be as follows: before making moves $$$a=[40, 6, 40, 3, 20, 1]$$$; choose $$$c=6$$$; now $$$a=[40, 3, 40, 3, 20, 1]$$$; choose $$$c=40$$$; now $$$a=[20, 3, 20, 3, 20, 1]$$$; choose $$$c=20$$$; now $$$a=[10, 3, 10, 3, 10, 1]$$$; choose $...
There are $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$. For the one move you can choose any even value $$$c$$$ and divide by two all elements that equal $$$c$$$.For example, if $$$a=[6,8,12,6,3,12]$$$ and you choose $$$c=6$$$, and $$$a$$$ is transformed into $$$a=[3,8,12,3,3,12]$$$ after the move.You need to fi...
For $$$t$$$ test cases print the answers in the order of test cases in the input. The answer for the test case is the minimal number of moves needed to make all numbers in the test case odd (i.e. not divisible by $$$2$$$).
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. The first line of a test case contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — the number of integers in the sequence $$$a$$$. The second line contains positive int...
standard output
standard input
Python 3
Python
1,200
train_000.jsonl
df0e2ae03513f2b9280e19a1df6c8d84
256 megabytes
["4\n6\n40 6 40 3 20 1\n1\n1024\n4\n2 4 8 16\n3\n3 1 7"]
PASSED
a = int(input()) for i in range(a): f = int(input()) k = list(map(int, input().split())) l = set() ch = 0 lol = 0 for i in range(len(k)): lol = k[i] while lol % 2 == 0: l.add(lol) lol /= 2 print(len(l))
1576321500
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
2 seconds
["abcda", "abc"]
94278e9c55f0fc82b48145ebecbc515f
NoteThe lexical comparison of strings is performed by the &lt; operator in modern programming languages. String a is lexicographically less than string b if exists such i (1 ≤ i ≤ n), that ai &lt; bi, and for any j (1 ≤ j &lt; i) aj = bj.
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each ind...
Print on the single line the lexicographically minimal lucky string whose length equals n.
The single line contains a positive integer n (1 ≤ n ≤ 105) — the length of the sought string.
standard output
standard input
Python 2
Python
1,100
train_014.jsonl
8c22943d44ee2f025a7662ac65bf3b5f
256 megabytes
["5", "3"]
PASSED
import sys n = int(sys.stdin.readline()) s = 'abcd' if n < 4: print s[:n] else: print s * (n/4) + s[:n%4]
1314633600
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["4", "2", "1"]
4c2d804bb2781abfb43558f8b2c6424f
NoteIn the first example Makes always chooses three ones out of four, and the number of ways to choose them is 4.In the second example a triple of numbers (1, 2, 3) is chosen (numbers, not indices). Since there are two ways to choose an element 3, then the answer is 2.In the third example a triple of numbers (1, 1, 2) ...
After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (i,  j,  k) (i &lt; j &lt; k), such that ai·aj·ak is minimum possible, are ther...
Print one number — the quantity of triples (i,  j,  k) such that i,  j and k are pairwise distinct and ai·aj·ak is minimum possible.
The first line of input contains a positive integer number n (3 ≤ n ≤ 105) — the number of elements in array a. The second line contains n positive integer numbers ai (1 ≤ ai ≤ 109) — the elements of a given array.
standard output
standard input
Python 3
Python
1,500
train_019.jsonl
970b06772d12071fc6967ac39b74625d
256 megabytes
["4\n1 1 1 1", "5\n1 3 2 3 4", "6\n1 3 3 1 3 2"]
PASSED
n = int(input()) a = sorted(list(map(int,input().split()))) min1 = a[0];min2 = a[1];min3 = a[2] t = True if(min1 == min2 and min2 == min3): cnt = 0 for i in a: if i == min1: cnt += 1 cnt = cnt * (cnt-1) * (cnt-2) print(cnt // 6) t = False if(min1 == min2 and t): cnt12 = 0 ...
1497539100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2", "-1", "3"]
fbfc333ad4b0a750f654a00be84aea67
NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one r...
Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output  - 1.
The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one ra...
standard output
standard input
Python 2
Python
1,600
train_003.jsonl
c17bef9e474f953bf3699980a800e06d
256 megabytes
["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"]
PASSED
import Queue as qq def bfs(start, target): LIMIT = 5000000 distances = [float('inf')] * LIMIT visited = [False] * LIMIT queue = qq.Queue() queue.put(start) visited[start] = True distances[start] = 0 while not queue.empty(): top = queue.get() for adjacent in xrange(le...
1448382900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["40\n34\n0"]
92bf30e66f4d5ddebb697d2fa4fa0689
NoteIn first query you have to sell two hamburgers and three chicken burgers. Your income is $$$2 \cdot 5 + 3 \cdot 10 = 40$$$.In second query you have to ell one hamburgers and two chicken burgers. Your income is $$$1 \cdot 10 + 2 \cdot 12 = 34$$$.In third query you can not create any type of burgers because because y...
There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburger you need two buns and a beef patty. To assemble a chicken burger you need two buns and a chicken cutlet. You have $$$b$$$ buns, $$$p$$$ beef patties and $$$f$$$ chicken cutlets in your restaurant. You can sell on...
For each query print one integer — the maximum profit you can achieve.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) – the number of queries. The first line of each query contains three integers $$$b$$$, $$$p$$$ and $$$f$$$ ($$$1 \le b, ~p, ~f \le 100$$$) — the number of buns, beef patties and chicken cutlets in your restaurant. The second line of each query contains...
standard output
standard input
Python 3
Python
800
train_008.jsonl
34afe74637c7894790adfd36cdd0d9ef
256 megabytes
["3\n15 2 3\n5 10\n7 5 2\n10 12\n1 100 100\n100 100"]
PASSED
n = int(input()) for i in range(n): b,p,f=map(int,input().split()) h,c=map(int,input().split()) p1=h*(min(b//2,p))+c*(min(f,max(0,(b-2*p)//2))) p2=c*(min(b//2,f))+h*(min(p,max(0,(b-2*f)//2))) print(max(p1,p2))
1566484500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2\nMasha\nPetya", "3\nLesha\nPasha\nVanya"]
b0301a2d79a1ec126511ed769ec0b743
null
When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team....
The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m () — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names — ...
standard output
standard input
Python 2
Python
1,500
train_018.jsonl
d90430691737d4a09ec876fdb32075b3
256 megabytes
["3 1\nPetya\nVasya\nMasha\nPetya Vasya", "3 0\nPasha\nLesha\nVanya"]
PASSED
import itertools def check(combination, enemies): for a in combination: for b in combination: if a != b: if (a, b) in enemies or (b, a) in enemies: return False return True def main(): n, m = map(int, raw_input().split()) names = [raw_input() f...
1315494000
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["1.154700538379 1.632993161855", "70710.678118654752"]
6f8a1a138ea2620f2013f426e29e4d98
NoteDefinition of isosceles triangle: https://en.wikipedia.org/wiki/Isosceles_triangle.
Igor the analyst has adopted n little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into n pieces of equal area. Formally, the carrot can be viewed as an isosceles triangle ...
The output should contain n - 1 real numbers x1, x2, ..., xn - 1. The number xi denotes that the i-th cut must be made xi units away from the apex of the carrot. In addition, 0 &lt; x1 &lt; x2 &lt; ... &lt; xn - 1 &lt; h must hold. Your output will be considered correct if absolute or relative error of every number in...
The first and only line of input contains two space-separated integers, n and h (2 ≤ n ≤ 1000, 1 ≤ h ≤ 105).
standard output
standard input
Python 3
Python
1,200
train_006.jsonl
c79f8bfd21d48d89311a3e7af2d24353
256 megabytes
["3 2", "2 100000"]
PASSED
n,h = map(int,input().split()) for x in range(1,n): print("%.10f"%(h*(x/n)**0.5),end=' ')
1494668100
[ "geometry", "math" ]
[ 0, 1, 0, 1, 0, 0, 0, 0 ]
1 second
["15\n15\n0\n299998\n340\n5\n5"]
f9287ed16ef943006ffb821ba3678545
Note In the first test case they can stick to the following plan: Megan (red circle) moves to the cell $$$(7, 3)$$$. Then she goes to the cell $$$(1, 3)$$$, and Stanley (blue circle) does the same. Stanley uses the portal in that cell (cells with portals are grey) to get to the cell $$$(7, 3)$$$. Then he moves to h...
Stanley and Megan decided to shop in the "Crossmarket" grocery store, which can be represented as a matrix with $$$n$$$ rows and $$$m$$$ columns. Stanley and Megan can move to an adjacent cell using $$$1$$$ unit of power. Two cells are considered adjacent if they share an edge. To speed up the shopping process, Megan b...
For each test case print a single integer on a new line – the answer.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The only line in the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$).
standard output
standard input
Python 3
Python
800
train_082.jsonl
08c2c4ab815526d60a728551ec88b1ea
256 megabytes
["7\n\n7 5\n\n5 7\n\n1 1\n\n100000 100000\n\n57 228\n\n1 5\n\n5 1"]
PASSED
# codeforces 816 # prob A from math import floor from math import ceil def solve(n, m): if m == n == 1: return 0 if m < n: return m * 2 - 1 + n - 1 else: return n * 2 - 1 + m - 1 num = int(input()) for i in range(num): n, m = map(int, input().split()) pr...
1661006100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["YES\ncbabac\nYES\naab\nYES\nzaza\nYES\nbaa\nNO\nYES\nnutforajarofatuna"]
e2dc3de62fc45c7e9ddb92daa5c5d8de
NoteThe first test case is described in the statement.In the second test case, we can make either "aab" or "aba". But "aba" is a palindrome, so "aab" is the only correct answer.In the third test case, "zaza" and "zzaa" are correct answers, but not "azza".In the fourth test case, "baa" is the only correct answer.In the ...
A palindrome is a string that reads the same backward as forward. For example, the strings "z", "aaa", "aba", and "abccba" are palindromes, but "codeforces" and "ab" are not. You hate palindromes because they give you déjà vu.There is a string $$$s$$$. You must insert exactly one character 'a' somewhere in $$$s$$$. If ...
For each test case, if there is no solution, output "NO". Otherwise, output "YES" followed by your constructed string of length $$$|s|+1$$$ on the next line. If there are multiple solutions, you may print any. You can print each letter of "YES" and "NO" in any case (upper or lower).
The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The only line of each test case contains a string $$$s$$$ consisting of lowercase English letters. The total length of all strings does not exceed $$$3\cdot 10^5$$$.
standard output
standard input
PyPy 3-64
Python
800
train_100.jsonl
ab1dbb8d79f77a098164763fec2327e7
256 megabytes
["6\ncbabc\nab\nzza\nba\na\nnutforajaroftuna"]
PASSED
n = int(input()) while n > 0: s = input() if "a" + s != s[::-1] + "a": print("YES") print("a" + s) elif s + "a" != "a" + s[::-1]: print("YES") print(s + "a") else: print("NO") n -= 1
1617460500
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
3 seconds
["2\n3\n4\n1"]
ff0b041d54755984df3706aae78d8ff2
NoteIn the first test case, $$$7$$$ can be represented as $$$7=1+6$$$, where $$$1$$$ and $$$6$$$ are powerful numbers. Because $$$7$$$ is not a powerful number, we know that the minimum possible value of $$$k$$$ in this case is $$$k=2$$$.In the second test case, a possible way to represent $$$11$$$ as the sum of three ...
A number is called powerful if it is a power of two or a factorial. In other words, the number $$$m$$$ is powerful if there exists a non-negative integer $$$d$$$ such that $$$m=2^d$$$ or $$$m=d!$$$, where $$$d!=1\cdot 2\cdot \ldots \cdot d$$$ (in particular, $$$0! = 1$$$). For example $$$1$$$, $$$4$$$, and $$$6$$$ are ...
For each test case print the answer on a separate line. If $$$n$$$ can not be represented as the sum of distinct powerful numbers, print $$$-1$$$. Otherwise, print a single positive integer  — the minimum possible value of $$$k$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. A test case consists of only one line, containing one integer $$$n$$$ ($$$1\le n\le 10^{12}$$$).
standard output
standard input
Python 3
Python
1,500
train_110.jsonl
b4a412dd3d11f90220e9c676d2d67545
256 megabytes
["4\n\n7\n\n11\n\n240\n\n17179869184"]
PASSED
from collections import deque powerful = [1] for i in range(2, 16): powerful.append( i * powerful[-1] ) powerful.append(4) for i in range(3, 41): powerful.append( 2 * powerful[-1] ) powerful.sort(reverse=True) for tcase in range(int(input())): q = deque() n, k, i = int(input()), 0, 0 ...
1646408100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1.916666666666666666666666666667"]
977aef0dfcf65b60bfe805757057aa73
null
You are given a permutation of integers from 1 to n. Exactly once you apply the following operation to this permutation: pick a random segment and shuffle its elements. Formally: Pick a random segment (continuous subsequence) from l to r. All segments are equiprobable. Let k = r - l + 1, i.e. the length of the chose...
Print one real value — the expected number of inversions. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 9. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the length of the permutation. The second line contains n distinct integers from 1 to n — elements of the permutation.
standard output
standard input
PyPy 3
Python
2,400
train_076.jsonl
a93f478b0633e05e0cef9e3684cc2c7f
256 megabytes
["3\n2 3 1"]
PASSED
# Python3 program to count inversions using # Binary Indexed Tree # Returns sum of arr[0..index]. This function # assumes that the array is preprocessed and # partial sums of array elements are stored # in BITree[]. def getSum( BITree, index): sum = 0 # Initialize result # Traverse anc...
1482165300
[ "probabilities" ]
[ 0, 0, 0, 0, 0, 1, 0, 0 ]