prob_desc_time_limit
stringclasses
21 values
prob_desc_sample_outputs
stringlengths
5
329
src_uid
stringlengths
32
32
prob_desc_notes
stringlengths
31
2.84k
prob_desc_description
stringlengths
121
3.8k
prob_desc_output_spec
stringlengths
17
1.16k
prob_desc_input_spec
stringlengths
38
2.42k
prob_desc_output_to
stringclasses
3 values
prob_desc_input_from
stringclasses
3 values
lang
stringclasses
5 values
lang_cluster
stringclasses
1 value
difficulty
int64
-1
3.5k
file_name
stringclasses
111 values
code_uid
stringlengths
32
32
prob_desc_memory_limit
stringclasses
11 values
prob_desc_sample_inputs
stringlengths
5
802
exec_outcome
stringclasses
1 value
source_code
stringlengths
29
58.4k
prob_desc_created_at
stringlengths
10
10
tags
listlengths
1
5
hidden_unit_tests
stringclasses
1 value
labels
listlengths
8
8
2 seconds
["12"]
a18edcadb31f76e69968b0a3e1cb7e3e
NoteHere's a picture depicting the example. Each vertical column presents the stacked books.
New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is wi.As Jaehyun's house is not large enough to have a bookshelf, he keeps the n books by stacking them vertically. When he wants to read a c...
Print the minimum total weight of books he should lift, which can be achieved by rearranging the order of stacked books.
The first line contains two space-separated integers n (2 ≤ n ≤ 500) and m (1 ≤ m ≤ 1000) — the number of books, and the number of days for which Jaehyun would read books. The second line contains n space-separated integers w1, w2, ..., wn (1 ≤ wi ≤ 100) — the weight of each book. The third line contains m space separa...
standard output
standard input
PyPy 2
Python
1,600
train_015.jsonl
676e9cd287bcaefb21cc10bb73d7965d
256 megabytes
["3 5\n1 2 3\n1 3 2 3 1"]
PASSED
import copy n,m=map(int,raw_input().split()) w=map(int,raw_input().split()) b=map(int,raw_input().split()) initial=[] for i in range(len(b)): b[i]-=1 for bb in b: if bb not in initial: initial.append(bb) ans=0 for bb in b: num=initial.index(bb) for i in range(num): ans+=w[initial[i]] ...
1419951600
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["18\n14\n-1\n-1\n0\n11\n25599\n184470016815529983"]
10ec2bd27cbb7aaf7b52c281591cc043
NoteIn the first test case, $$$x=18$$$ is one of the possible solutions, since $$$39|18=55$$$ and $$$12|18=30$$$, both of which are multiples of $$$d=5$$$.In the second test case, $$$x=14$$$ is one of the possible solutions, since $$$8|14=6|14=14$$$, which is a multiple of $$$d=14$$$.In the third and fourth test cases,...
You are given three integers $$$a$$$, $$$b$$$, and $$$d$$$. Your task is to find any integer $$$x$$$ which satisfies all of the following conditions, or determine that no such integers exist: $$$0 \le x \lt 2^{60}$$$; $$$a|x$$$ is divisible by $$$d$$$; $$$b|x$$$ is divisible by $$$d$$$. Here, $$$|$$$ denotes the bit...
For each test case print one integer. If there exists an integer $$$x$$$ which satisfies all of the conditions from the statement, print $$$x$$$. Otherwise, print $$$-1$$$. If there are multiple solutions, you may print any of them.
Each test contains multiple test cases. The first line of input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line, containing three integers $$$a$$$, $$$b$$$, and $$$d$$$ ($$$1 \le a,b,d \lt 2^{30}$$$).
standard output
standard input
PyPy 3-64
Python
2,100
train_083.jsonl
08746a4516507a05dc1af0d5088faf90
256 megabytes
["8\n\n12 39 5\n\n6 8 14\n\n100 200 200\n\n3 4 6\n\n2 2 2\n\n18 27 3\n\n420 666 69\n\n987654321 123456789 999999999"]
PASSED
"""**************************************************************\ BISMILLAHIR RAHMANIR RAHIM **************************************************************** AUTHOR NAME: MD. TAHURUZZOHA TUHIN \**************************************************************""" #!/usr/bin/env...
1668263700
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["2 1\n2 1 5 3 4"]
f4779e16e0857e6507fdde55e6d4f982
null
You are given one integer $$$n$$$ ($$$n > 1$$$).Recall that a permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2, 3, 1, 5, 4]$$$ is a permutation of length $$$5$$$, but $$$[1, 2, 2]$$$ is not a permutation ($$$2$$$ appears ...
For each test case, print $$$n$$$ distinct integers $$$p_1, p_2, \ldots, p_n$$$ — a permutation that there is no index $$$i$$$ ($$$1 \le i \le n$$$) such that $$$p_i = i$$$ (so, for all $$$i$$$ from $$$1$$$ to $$$n$$$ the condition $$$p_i \ne i$$$ should be satisfied). If there are several answers, you can print any. I...
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of the permutation you have to find.
standard output
standard input
Python 3
Python
null
train_014.jsonl
50aa4e268859b2c39300847ce919ad31
256 megabytes
["2\n2\n5"]
PASSED
n = int(input()) list1 = [] a = 1 for i in range(0,n): list1.append(int(input())) for j in list1: if j%2==0: for num in range(j,0,-1): print(num,end=" ") else: print('2 3 1',end=" ") print(* [x for x in range(j,3,-1)]) if a in range(1,n): print("") a+=1
1606228500
[ "probabilities" ]
[ 0, 0, 0, 0, 0, 1, 0, 0 ]
2 seconds
["100", "120"]
f0633a45bf4dffda694d0b8041a6d743
NoteThe second sample is depicted above. The red beam gets 10 + 50 + 5 + 35 + 8 + 2 = 110 points and the blue one gets 120.The red beam on the picture given in the statement shows how the laser beam can go approximately, this is just illustration how the laser beam can gain score. So for the second sample there is no s...
Mirror Box is a name of a popular game in the Iranian National Amusement Park (INAP). There is a wooden box, 105 cm long and 100 cm high in this game. Some parts of the box's ceiling and floor are covered by mirrors. There are two negligibly small holes in the opposite sides of the box at heights hl and hr centimeters ...
The only line of output should contain a single integer — the maximum possible score a player could gain.
The first line of the input contains three space-separated integers hl, hr, n (0 < hl, hr < 100, 0 ≤ n ≤ 100) — the heights of the holes and the number of the mirrors. Next n lines contain the descriptions of the mirrors. The i-th line contains space-separated vi, ci, ai, bi; the integer vi (1 ≤ vi ≤ 1000) is the...
standard output
standard input
Python 2
Python
2,000
train_016.jsonl
4601f931f46377d38bfb0207cc262f5a
256 megabytes
["50 50 7\n10 F 1 80000\n20 T 1 80000\n30 T 81000 82000\n40 T 83000 84000\n50 T 85000 86000\n60 T 87000 88000\n70 F 81000 89000", "80 72 9\n15 T 8210 15679\n10 F 11940 22399\n50 T 30600 44789\n50 F 32090 36579\n5 F 45520 48519\n120 F 49250 55229\n8 F 59700 80609\n35 T 61940 64939\n2 T 92540 97769"]
PASSED
#!/usr/bin/python import sys L = 100000 a = 50.0 def getScore(uSide, lSide, uScore, lScore, d1, d2): mok = 1 finalScore = 0 for k in range(1, 2*min(len(uScore), len(lScore))+1): thisScore = 0 uValid = [1 for x in range(len(uScore))] lValid = [1 for x in range(len(lScore))] mok = - mok for j in range(1, k...
1351783800
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
3 seconds
["0\n8\n3"]
9cd7f058d4671b12b67babd38293a3fc
null
Easy and hard versions are actually different problems, so we advise you to read both statements carefully.You are given a weighted rooted tree, vertex $$$1$$$ is the root of this tree.A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a vertex $$$v$$$ is the las...
For each test case, print the answer: the minimum number of moves required to make the sum of weights of paths from the root to each leaf at most $$$S$$$.
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains two integers $$$n$$$ and $$$S$$$ ($$$2 \le n \le 10^5; 1 \le S \le 10^{16}$$$) — the number of vertices in the tree and the maxim...
standard output
standard input
PyPy 3
Python
2,000
train_041.jsonl
91eac377db5324482b95f806da962035
256 megabytes
["3\n3 20\n2 1 8\n3 1 7\n5 50\n1 3 100\n1 5 10\n2 3 123\n5 4 55\n2 100\n1 2 409"]
PASSED
import sys from heapq import heappop, heapify from collections import defaultdict input = sys.stdin.buffer.readline t = int(input()) for _ in range(t): n, S = map(int, input().split()) adj = [dict() for _ in range(n+1)] for _ in range(n-1): u, v, w = map(int, input().split()) adj[u][v] = w ...
1596638100
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["1\n3\n2\n0\n0"]
04e2e1ce3f0b4efd2d4dda69748a0a25
NoteIn the first test case there is only one pair: $$$(4,7)$$$: for it $$$4$$$ $$$\&$$$ $$$7 = 4$$$, and $$$4 \oplus 7 = 3$$$.In the second test case all pairs are good.In the third test case there are two pairs: $$$(6,5)$$$ and $$$(2,3)$$$.In the fourth test case there are no good pairs.
"You must lift the dam. With a lever. I will give it to you.You must block the canal. With a rock. I will not give the rock to you." Danik urgently needs rock and lever! Obviously, the easiest way to get these things is to ask Hermit Lizard for them.Hermit Lizard agreed to give Danik the lever. But to get a stone, Da...
For every test case print one non-negative integer — the answer to the problem.
Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10$$$) denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — length of the array. The second ...
standard output
standard input
PyPy 3
Python
1,200
train_012.jsonl
367b7532d3a271919a07eed2bc8fdc1b
256 megabytes
["5\n5\n1 4 3 7 10\n3\n1 1 1\n4\n6 2 5 3\n2\n2 4\n1\n1"]
PASSED
# from bisect import bisect_left TC = int(input()) for tc in range(TC): N = int(input()) A = list(map(int, input().split())) B = [0 for _ in range(32)] for i, a in enumerate(A): B[a.bit_length()] += 1 result = 0 for b in B: if b > 1: result += b * (b - 1) // 2 ...
1600958100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1"]
14a56443e48c52c118788bd5c0031b0c
NoteJust for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:QWER REWQ ASDF -> FDSAZXCV VCXZ
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j)....
For each of the p candies, print on a single line its space-separated new coordinates.
The first line of the input contains fix integers n, m, x, y, z, p (1 ≤ n, m ≤ 109; 0 ≤ x, y, z ≤ 109; 1 ≤ p ≤ 105). Each of the following p lines contains two integers xk, yk (1 ≤ xk ≤ n; 1 ≤ yk ≤ m) — the initial coordinates of the k-th candy. Two candies can lie on the same cell.
standard output
standard input
Python 2
Python
1,500
train_023.jsonl
47306be00d2d3c3742831a409b52e605
256 megabytes
["3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3"]
PASSED
a=raw_input().split() n=int(a[0]) m=int(a[1]) x=int(a[2]) y=int(a[3]) z=int(a[4]) p=int(a[5]) lis=[] for i in range(p): b=raw_input().split() c=int(b[0]) d=int(b[1]) lis.append((c,d)) def flip(lis,y,p,m): for i in range(y%2): for k in range(p): lis[k]=(lis[k][0],m+1-lis[k][1]) de...
1394033400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["-1", "2"]
1b83529ea4057c76ae8483f8aa506c56
null
A newspaper is published in Walrusland. Its heading is s1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After that walrus erase several letters from this string in order to get a new...
If it is impossible to get the word s2 in the above-described manner, print "-1" (without the quotes). Otherwise, print the least number of newspaper headings s1, which Fangy will need to receive the word s2.
The input data contain two lines. The first line contain the heading s1, the second line contains the word s2. The lines only consist of lowercase Latin letters (1 ≤ |s1| ≤ 104, 1 ≤ |s2| ≤ 106).
standard output
standard input
Python 3
Python
1,500
train_046.jsonl
665f65b7d658042e5783f4b435345ed2
256 megabytes
["abc\nxyz", "abcd\ndabc"]
PASSED
from bisect import bisect_right as bl s1, s2 = input(), input() try: inv_map = {} for k, v in enumerate(s1): inv_map[v] = inv_map.get(v, []) inv_map[v].append(k) pointer = inv_map[s2[0]][0] count = 1 for i in s2[1:]: pos = bl(inv_map[i],pointer) if len(inv_map[i])==pos: count+=1 ...
1308582000
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
3 seconds
["4\n-1\n5\n2\n0\n1"]
2005224ffffb90411db3678ac4996f84
NoteIn the first example query Vova can just play $$$4$$$ turns and spend $$$12$$$ units of charge and then one turn play and charge and spend $$$2$$$ more units. So the remaining charge of the battery will be $$$1$$$.In the second example query Vova cannot complete the game because even if he will play and charge the ...
Vova is playing a computer game. There are in total $$$n$$$ turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game) is $$$k$$$.During each turn Vova can choose what to do: If the current charge of his laptop battery is strict...
For each query print one integer: -1 if Vova cannot complete the game or the maximum number of turns Vova can just play (make the first type turn) otherwise.
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of queries. Each query is presented by a single line. The only line of the query contains four integers $$$k, n, a$$$ and $$$b$$$ ($$$1 \le k, n \le 10^9, 1 \le b < a \le 10^9$$$) — the initial charge of Vova's laptop batt...
standard output
standard input
Python 3
Python
1,400
train_012.jsonl
b5faae6e6654400d6329e59b0953c7be
256 megabytes
["6\n15 5 3 2\n15 5 4 3\n15 5 2 1\n15 5 5 1\n16 7 5 2\n20 5 7 3"]
PASSED
def f(k,n,a,b): m=(k-n*b)/(a-b) if m<=0: return -1 elif m==int(m): if m-1>=n: return n else: return m-1 else: if int(m)>=n: return n else: return int(m) n=int(input()) c=[] for i in range(n): b=input().split() ...
1561559700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2\n0\n7\n5"]
8bbec86e427e26158393bbfbf1a067fe
NoteIn the first test case Polycarp can earn two emeralds as follows: craft one sword and one shovel.In the second test case Polycarp does not have any diamonds, so he cannot craft anything.
Polycarp plays a well-known computer game (we won't mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and one stick.Each tool can be sold for exactly one emerald. How many e...
For each test case print one integer — the maximum number of emeralds Polycarp can earn.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^9$$$) — the number of sticks and the number of diamonds, respectively.
standard output
standard input
PyPy 3
Python
1,100
train_002.jsonl
7938ffd7e31965e5f74eed446125bec1
256 megabytes
["4\n4 4\n1000000000 0\n7 15\n8 7"]
PASSED
#------------------------------what is this I don't know....just makes my mess faster-------------------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self....
1591886100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["5.0000000000", "39.2846263444"]
afcd217811ca5853179e5a936b4633fe
NoteThe optimal strategy in the first sample is to guess friends alternately.
A MIPT student named Misha has a birthday today, and he decided to celebrate it in his country house in suburban Moscow. n friends came by, and after a typical party they decided to play blind man's buff.The birthday boy gets blindfolded and the other players scatter around the house. The game is played in several roun...
Print a single real value — the expectation of the number of rounds provided that Misha plays optimally. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your a...
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of Misha's friends. The second line contains n integers pi (), giving the probability to catch the i-th friend in one particular round in percent.
standard output
standard input
PyPy 3
Python
2,700
train_076.jsonl
ea801460d2e2ee74e4d930a8d2faf652
256 megabytes
["2\n50 50", "4\n50 20 20 10"]
PASSED
import random N = int(input()) prob = [float(x)/100 for x in input().strip().split()] prob_sum = [] cur = 0 for i in range(N): cur += prob[i] prob_sum.append(cur) def experiment(): cur_prob = [1.] * N cur_exp = 0 for i in range(200000): bp = [prob[i] * cur_prob[i] / (1-cur_prob[i]+1E-100)...
1454605500
[ "probabilities", "math" ]
[ 0, 0, 0, 1, 0, 1, 0, 0 ]
2 seconds
["4", "0"]
eaa768dc1024df6449e89773234cc0c3
NoteIn the first sample, one of the best permutations is $$$[1, 5, 5, 3, 10, 1, 1]$$$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.For instance, if we are given an array $$$[10, 20, 30, 40]$$$, we ca...
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.
standard output
standard input
Python 3
Python
1,300
train_017.jsonl
957e1a825015b4c3be9a8781b24bbba6
256 megabytes
["7\n10 1 1 1 5 5 3", "5\n1 1 1 1 1"]
PASSED
from collections import * print( int(input()) - max(Counter(map(int, input().split())).values()) )
1531492500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["22 3"]
ad50e2946470fa8e02eb70d8cef161c5
NoteConsider 6 possible routes: [2, 3, 5]: total distance traveled: |2 – 0| + |3 – 2| + |5 – 3| = 5; [2, 5, 3]: |2 – 0| + |5 – 2| + |3 – 5| = 7; [3, 2, 5]: |3 – 0| + |2 – 3| + |5 – 2| = 7; [3, 5, 2]: |3 – 0| + |5 – 3| + |2 – 5| = 8; [5, 2, 3]: |5 – 0| + |2 – 5| + |3 – 2| = 9; [5, 3, 2]: |5 – 0| + |3 – 5| + |2 – 3...
Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are n destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The n destinations are described by a non-negative integers sequence a1, a2, ..., an. The number ak represents t...
Output two integers — the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible.
The first line contains integer n (2 ≤ n ≤ 105). Next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 107).
standard output
standard input
Python 2
Python
1,600
train_055.jsonl
60e6912a6b1e4ff90a09b9ba3868af8d
256 megabytes
["3\n2 3 5"]
PASSED
import sys #sys.stdin = open('in.txt', 'r') def gcd(a, b): if b == 0: return a return gcd(b, a % b) n = input() a = map(int, raw_input().split()) a.sort() s = [0 for i in xrange(n+1)] for i in xrange(n): s[i+1] += s[i] + a[i] t = s[n] for i in xrange(2, n): t += a[i-1] * (i - 1) - s[i-1] ...
1377876600
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["3"]
8d911f79dde31f2c6f62e73b925e6996
NoteFor the first example, three groups are sufficient, for example: Employee 1 Employees 2 and 4 Employees 3 and 5
A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at least one of the following is true: Employee A is the immediate manager o...
Print a single integer denoting the minimum number of groups that will be formed in the party.
The first line contains integer n (1 ≤ n ≤ 2000) — the number of employees. The next n lines contain the integers pi (1 ≤ pi ≤ n or pi = -1). Every pi denotes the immediate manager for the i-th employee. If pi is -1, that means that the i-th employee does not have an immediate manager. It is guaranteed, that no employ...
standard output
standard input
Python 3
Python
900
train_007.jsonl
c21c612c3a68848a8a82fb7f7c6cde97
256 megabytes
["5\n-1\n1\n2\n1\n-1"]
PASSED
""" Solution to Challenge 115A. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at least one of the following is true: Emplo...
1316098800
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1 second
["Y 67.985071301 1.014928699\nY 0.000000000 0.000000000\nN\nY 2.000000000 2.000000000\nY 3.618033989 1.381966011\nY 997.998996990 1.001003010\nY 998.998997995 1.001002005"]
6f5d41346419901c830233b3bf5c9e65
null
Try guessing the statement from this picture: You are given a non-negative integer $$$d$$$. You have to find two non-negative real numbers $$$a$$$ and $$$b$$$ such that $$$a + b = d$$$ and $$$a \cdot b = d$$$.
For each test print one line. If there is an answer for the $$$i$$$-th test, print "Y", and then the numbers $$$a$$$ and $$$b$$$. If there is no answer for the $$$i$$$-th test, print "N". Your answer will be considered correct if $$$|(a + b) - a \cdot b| \le 10^{-6}$$$ and $$$|(a + b) - d| \le 10^{-6}$$$.
The first line contains $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. Each test case contains one integer $$$d$$$ $$$(0 \le d \le 10^3)$$$.
standard output
standard input
PyPy 3
Python
1,300
train_008.jsonl
542d8acdadc4b007b88f038024e3c45d
256 megabytes
["7\n69\n0\n1\n4\n5\n999\n1000"]
PASSED
for i in range(int(input())): d=int(input()) a=(d+(((d**2)-4*d)**.5))/2 b=(d-(((d**2)-4*d)**.5))/2 try: if a>=0 and b>=0: print('Y',a,b) else: print('N') except: print('N')
1542033300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["252", "0", "210"]
94559f08866b6136ba4791c440025a68
NoteIn the first example, all sequences ($$$4^4$$$) of length $$$4$$$ except the following are good: $$$[1, 1, 1, 1]$$$ $$$[2, 2, 2, 2]$$$ $$$[3, 3, 3, 3]$$$ $$$[4, 4, 4, 4]$$$ In the second example, all edges are red, hence there aren't any good sequences.
You are given a tree (a connected undirected graph without cycles) of $$$n$$$ vertices. Each of the $$$n - 1$$$ edges of the tree is colored in either black or red.You are also given an integer $$$k$$$. Consider sequences of $$$k$$$ vertices. Let's call a sequence $$$[a_1, a_2, \ldots, a_k]$$$ good if it satisfies the ...
Print the number of good sequences modulo $$$10^9 + 7$$$.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 10^5$$$, $$$2 \le k \le 100$$$), the size of the tree and the length of the vertex sequence. Each of the next $$$n - 1$$$ lines contains three integers $$$u_i$$$, $$$v_i$$$ and $$$x_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$x_i \in \{0, 1\}$$$), where ...
standard output
standard input
PyPy 3
Python
1,500
train_004.jsonl
de26e336b7059bba58e66584a3fed71e
256 megabytes
["4 4\n1 2 1\n2 3 1\n3 4 1", "4 6\n1 2 0\n1 3 0\n1 4 0", "3 5\n1 2 1\n2 3 0"]
PASSED
""" if num edges red <= k - 1: return (n choose k) # num edges red >= k """ def n_perm_k(n, k): return n ** k def ways(xs, k): total = n_perm_k(sum(xs), k) for x in xs: total -= n_perm_k(x, k) return total def dfs(i, graph, visited): stack = [i] count = 0 while stack: ...
1553182500
[ "math", "trees", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 1 ]
1 second
["abc\ndiane\nbbcaabbba\nyouarethecutestuwuu"]
21e361d7f907f2543a616c901e60c6f2
NoteIn the first test case, each substring of "abc" occurs exactly once.In the third test case, each substring of "bbcaabbba" occurs an odd number of times. In particular, "b" occurs $$$5$$$ times, "a" and "bb" occur $$$3$$$ times each, and each of the remaining substrings occurs exactly once.
You are given an integer $$$n$$$. Find any string $$$s$$$ of length $$$n$$$ consisting only of English lowercase letters such that each non-empty substring of $$$s$$$ occurs in $$$s$$$ an odd number of times. If there are multiple such strings, output any. It can be shown that such string always exists under the given ...
For each test case, print a single line containing the string $$$s$$$. If there are multiple such strings, output any. It can be shown that such string always exists under the given constraints.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
standard output
standard input
PyPy 3-64
Python
1,800
train_087.jsonl
4015c11356857e55f65cb7cea3e598ad
256 megabytes
["4\n3\n5\n9\n19"]
PASSED
import itertools import queue import math import sys from collections import * from random import * #sys.setrecursionlimit(99999) eps = sys.float_info.epsilon P = 2 INF = 1e9 + 1 MOD = 1000000007 def is_prime(n): if n == 0 or n == 1: return False d = 2 while d * d <= n: ...
1627569300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["0\n0\n4\n4\n12\n990998587\n804665184"]
43ace9254c5d879d11e3484eacb0bcc4
NoteIt's easy to see that the answer for RDB of level $$$1$$$ or $$$2$$$ is $$$0$$$.The answer for RDB of level $$$3$$$ is $$$4$$$ since there is only one claw we can choose: $$$\{1, 2, 3, 4\}$$$.The answer for RDB of level $$$4$$$ is $$$4$$$ since we can choose either single claw $$$\{1, 3, 2, 4\}$$$ or single claw $$...
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes...Let's define a Rooted Dead Bush (RDB) of level $$$n...
For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $$$10^9 + 7$$$.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ lines contain test cases — one per line. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^6$$$) — the level of Lee's RDB.
standard output
standard input
PyPy 3
Python
1,900
train_006.jsonl
3e28bedf4a6ff9813d8f457a0ba529da
256 megabytes
["7\n1\n2\n3\n4\n5\n100\n2000000"]
PASSED
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase import threading from math import floor from bisect import bisect_right from collections import Counter from math import gcd mod=10**9+7 def main(): size=2*10**6+1 ans=[0]*(size) a=0 b=0 for i in range(1,2*10**6+1): ...
1592921100
[ "math", "trees", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 1 ]
2 seconds
["2\n4\n12"]
f79a926e18a3f81b24f2fc3ae5c8f928
null
You have a list of numbers from $$$1$$$ to $$$n$$$ written from left to right on the blackboard.You perform an algorithm consisting of several steps (steps are $$$1$$$-indexed). On the $$$i$$$-th step you wipe the $$$i$$$-th number (considering only remaining numbers). You wipe the whole number (not one digit). When t...
Print $$$T$$$ integers (one per query) — the values of the $$$x$$$-th number after performing the algorithm for the corresponding queries.
The first line contains one integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. The next $$$T$$$ lines contain queries — one per line. All queries are independent. Each line contains two space-separated integers $$$n$$$ and $$$x$$$ ($$$1 \le x &lt; n \le 10^{9}$$$) — the length of the list and the position...
standard output
standard input
PyPy 3
Python
800
train_013.jsonl
81159d31a78b33f9ecdc3075459229c9
256 megabytes
["3\n3 1\n4 2\n69 6"]
PASSED
import sys import math from collections import defaultdict,deque input = sys.stdin.readline def inar(): return [int(el) for el in input().split()] def main(): t=int(input()) for _ in range(t): n,x=inar() print(x*2) if __name__ == '__main__': main()
1563115500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["5\n1 2 3 4 5", "2\n4 5", "1\n1"]
a704760d5ccd09d08558ea98d6007835
null
Valera's finally decided to go on holiday! He packed up and headed for a ski resort.Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has n objects (we will consider the objects indexed in some way by integers from 1 to n), each object...
In the first line print k — the maximum possible path length for Valera. In the second line print k integers v1, v2, ..., vk — the path. If there are multiple solutions, you can print any of them.
The first line contains integer n (1 ≤ n ≤ 105) — the number of objects. The second line contains n space-separated integers type1, type2, ..., typen — the types of the objects. If typei equals zero, then the i-th object is the mountain. If typei equals one, then the i-th object is the hotel. It is guaranteed that at l...
standard output
standard input
Python 2
Python
1,500
train_008.jsonl
9fb81725092eebfb874539680a7c25c8
256 megabytes
["5\n0 0 0 0 1\n0 1 2 3 4", "5\n0 0 1 0 1\n0 1 2 2 4", "4\n1 0 0 0\n2 3 4 2"]
PASSED
from collections import Counter n = input() v = [int(i) for i in raw_input().split()] a = [int(i) for i in raw_input().split()] cnt = Counter(a) pf = {} hotels = [] for i in range(len(a)): if v[i] == 1: hotels.append(i+1) if a[i] == 0: continue pf[i+1] = a[i] mp = [] for h in hotels: ...
1380641400
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["2 2 2\n7 5 3\n-1\n0 0 2"]
b43dee2f223c869a35b1b11ceb9d2b6b
null
Recently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apar...
For each test case, if a building with the new layout and the given number of windows just can't exist, print $$$-1$$$. Otherwise, print three non-negative integers — the possible number of three-room, five-room, and seven-room apartments. If there are multiple answers, print any of them.
Th first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The only line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of windows in the building.
standard output
standard input
Python 3
Python
900
train_023.jsonl
c432da3d979221707206cef5a29b7d7d
256 megabytes
["4\n30\n67\n4\n14"]
PASSED
for i in range(int(input())): n=int(input()) if n==1: print(-1) if n==2: print(-1) if n==4: print(-1) if n//3==(n-2)/3 and n>4: print(int(n//3-1),1,0) if n//3==n/3: print(int(n/3),0,0) elif n//3==(n-1)/3 and n>4: print(int(n//3-2),0,1)
1602407100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["0.6250000000\n0.5312500000"]
92feda270834af751ca37bd80083aafa
null
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who th...
Print t lines — the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
The first line contains integer t (1 ≤ t ≤ 10000) — amount of testcases. Each of the following t lines contain two space-separated integers a and b (0 ≤ a, b ≤ 106). Pretests contain all the tests with 0 &lt; a &lt; 10, 0 ≤ b &lt; 10.
standard output
standard input
Python 3
Python
1,800
train_000.jsonl
ced6afd8e24e4094feee1568c8dd79d7
256 megabytes
["2\n4 2\n1 2"]
PASSED
for i in range(int(input())): a, b = map(int, input().split()) print(0.5 + a / (b << 4) if 4 * b > a else 1 - b / a if a else 1)
1303226100
[ "probabilities", "math" ]
[ 0, 0, 0, 1, 0, 1, 0, 0 ]
2 seconds
["3 2", "3 3"]
4a55e76aa512b8ce0f3f84bc6da3f86f
NoteConsider the first sample. The tree contains three leaves: 3, 4 and 5. If we put the maximum number 3 at node 3, then the first player moves there and the result will be 3. On the other hand, it is easy to see that for any rearrangement the first player can guarantee the result of at least 2.In the second sample no...
Demiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game.There is a rooted tree on n nodes, m of which are leaves (a leaf is a nodes that does not have any children), edges of the tree are directed from parent to children. In the leaves of th...
Print two space-separated integers — the maximum possible and the minimum possible result of the game.
The first line contains a single integer n — the number of nodes in the tree (1 ≤ n ≤ 2·105). Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n) — the ends of the edge of the tree; the edge leads from node ui to node vi. It is guaranteed that the described graph is a rooted tree, and the root...
standard output
standard input
Python 2
Python
2,200
train_034.jsonl
d53024926b076561090d577dcfecb21a
256 megabytes
["5\n1 2\n1 3\n2 4\n2 5", "6\n1 2\n1 3\n3 4\n1 5\n5 6"]
PASSED
def readlist(f): return map(f, raw_input().split()) def readint(): return int(raw_input()) def printlist(l): print ' '.join(map(str, l)) N = readint() E = [[] for i in range(N)] for i in range(N-1): u, v = readlist(int) u -= 1 v -= 1 E[u].append(v) E[v].append(u) F = [None]*N C = [[] for i in range(N)] S = ...
1430064000
[ "math", "trees" ]
[ 0, 0, 0, 1, 0, 0, 0, 1 ]
2 seconds
["0 0\n\n\n\n3 1\n\n\n\n2 3\n\n\n\n4 4\n\n\n\n0 2\n\n\n\n1 3 4 1"]
574347ab83379e5b08618d2b275b0d96
NoteIn the sample input and output values are aligned only for simplicity of interpreting them chronologically. In real interaction no "extra" line breaks should appear.The following picture illustrates the first test.
This is an interactive problem.In good old times dwarves tried to develop extrasensory abilities: Exactly n dwarves entered completely dark cave. Each dwarf received a hat — white or black. While in cave, none of the dwarves was able to see either his own hat or hats of other Dwarves. Dwarves went out of the cave to...
null
null
standard output
standard input
Python 3
Python
1,900
train_008.jsonl
70d242f3d4bad87349b71ff235ef01b9
256 megabytes
["5\n\n\n\nblack\n\n\n\nblack\n\n\n\nwhite\n\n\n\nwhite\n\n\n\nblack"]
PASSED
n=int(input()) print(1,0) c=input() n-=1 L=1 R=999999999 while n>0: M=int((L+R)/2) print(1,M) if input()==c: L=M+1 else: R=M n-=1 print(0,R,2,R-1)
1539511500
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
2 seconds
["1", "3"]
71cead8cf45126902c518c9ce6e5e186
null
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: he chooses two elements of the array ai, aj (i ≠ j); he s...
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
standard output
standard input
Python 2
Python
1,300
train_004.jsonl
0fbcc88897ff6dfeefbf7a553dd6c5c6
256 megabytes
["2\n2 1", "3\n1 4 1"]
PASSED
def solve(n, a): s = sum(a) if s % n == 0: return n return n-1 n = int(raw_input()) a = map(int, raw_input().split()) print solve(n, a)
1353511800
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["5\n18\n10\n6\n75015"]
43b8e9fb2bd0ec5e0250a33594417f63
NoteIn the first test case, Santa can give $$$3$$$ and $$$2$$$ candies to kids. There $$$a=2, b=3,a+1=3$$$.In the second test case, Santa can give $$$5, 5, 4$$$ and $$$4$$$ candies. There $$$a=4,b=5,a+1=5$$$. The answer cannot be greater because then the number of kids with $$$5$$$ candies will be $$$3$$$.In the third ...
Santa has $$$n$$$ candies and he wants to gift them to $$$k$$$ kids. He wants to divide as many candies as possible between all $$$k$$$ kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.Suppose the kid who recieves the minimum number of candies has $$$a$$$ candies and the ki...
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The $$$i$$$-th test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^9$$$) — the number of candies and the number of kids.
standard output
standard input
PyPy 3
Python
900
train_002.jsonl
e3986c08bf98a582883c36ce23440295
256 megabytes
["5\n5 2\n19 4\n12 7\n6 2\n100000 50010"]
PASSED
for _ in range(int(input())): x, y = map(int, input().split()) print(x - max(0, x % y - y // 2))
1577552700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2\n3\n3\n4"]
3581b3a6bf7b122b49c481535491399d
NoteThe picture corresponding to the first test case of the example:There you can remove vertices $$$2$$$, $$$5$$$ and $$$3$$$ during the first move and vertices $$$1$$$, $$$7$$$ and $$$4$$$ during the second move.The picture corresponding to the second test case of the example:There you can remove vertices $$$7$$$, $$...
You are given a tree (connected graph without cycles) consisting of $$$n$$$ vertices. The tree is unrooted — it is just a connected undirected graph without cycles.In one move, you can choose exactly $$$k$$$ leaves (leaf is such a vertex that is connected to only one another vertex) connected to the same vertex and rem...
For each test case, print the answer — the maximum number of moves you can perform if you remove leaves optimally.
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 first line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$1 \le k &lt; n$$$) — the number of vertices in the tree and ...
standard output
standard input
PyPy 3
Python
2,300
train_011.jsonl
4b689ae5017bfa30bc5e1afef8a2fa4e
256 megabytes
["4\n8 3\n1 2\n1 5\n7 6\n6 8\n3 1\n6 4\n6 1\n10 3\n1 2\n1 10\n2 3\n1 5\n1 6\n2 4\n7 10\n10 9\n8 10\n7 2\n3 1\n4 5\n3 6\n7 4\n1 2\n1 4\n5 1\n1 2\n2 3\n4 3\n5 3"]
PASSED
from collections import defaultdict,deque import sys input=sys.stdin.readline t=int(input()) for ii in range(t): graph=defaultdict(list) n,k=map(int,input().split()) st=[] for i in range(n-1): u,v=map(int,input().split()) graph[u].append(v) graph[v].append(u) if k==1: ...
1594996500
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["2\n1 1 2", "2\n2 1 1 2"]
a99f5e08f3f560488ff979a3e9746e7f
NoteIn the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.Watson gave Sherlock a challenge to color these jewelry pieces such that two p...
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints. The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price. If ther...
The only line contains single integer n (1 ≤ n ≤ 100000) — the number of jewelry pieces.
standard output
standard input
Python 3
Python
1,200
train_006.jsonl
ed01f95b2750d1680e1e7293d3af8764
256 megabytes
["3", "4"]
PASSED
def f(n): if n==2: return True for i in range(2,int(n**0.5)+1): if n%i==0: return False return True s=int(input()) if s>2: print(2) q=[1]*(s) for i in range(2,s+2): if f(i): q[i-2]=2 print(' '.join([str(w)for w in q])) elif s==1: print(1) ...
1487861100
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
1 second
["2\n1\n2\n1"]
dd2cd365d7afad9c2b5bdbbd45d87c8a
NoteIn the first query of the example, there are $$$n=4$$$ students with the skills $$$a=[2, 10, 1, 20]$$$. There is only one restriction here: the $$$1$$$-st and the $$$3$$$-th students can't be in the same team (because of $$$|a_1 - a_3|=|2-1|=1$$$). It is possible to divide them into $$$2$$$ teams: for example, stud...
You are a coach of a group consisting of $$$n$$$ students. The $$$i$$$-th student has programming skill $$$a_i$$$. All students have distinct programming skills. You want to divide them into teams in such a way that: No two students $$$i$$$ and $$$j$$$ such that $$$|a_i - a_j| = 1$$$ belong to the same team (i.e. skil...
For each query, print the answer on it — the minimum number of teams you can form if no two students $$$i$$$ and $$$j$$$ such that $$$|a_i - a_j| = 1$$$ may belong to the same team (i.e. skills of each pair of students in the same team has the difference strictly greater than $$$1$$$)
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of students in the query. The second line of the query contains $$$n$$$ integers $$$a_1, a_...
standard output
standard input
Python 3
Python
800
train_003.jsonl
2e6885cd9e46112ca90c1b1c0ea47575
256 megabytes
["4\n4\n2 10 1 20\n2\n3 6\n5\n2 3 4 99 100\n1\n42"]
PASSED
q=int(input()) while q>0: q-=1 n=int(input()) a=list(map(int,input().split())) a.sort() s=1 z=1 i=0 while i<(n-1): if (a[i]-a[i+1])==-1: z=2 s=max(z,s) i+=1 z=1 print(s)
1571754900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["YES\n1000000007\n0 1 \n1 2 3", "YES\n3\n0 1 \n1 2", "NO"]
ddd246cbbd038ae3fc54af1dcb9065c3
NoteBy we denote the remainder of integer division of b by c.It is guaranteed that if there exists some set of numbers k, a1, ..., an, b1, ..., bm, that you could use to make matrix w, then there also exists a set of numbers that meets the limits 1 ≤ k ≤ 1018, 1 ≤ ai ≤ 1018, 1 ≤ bi ≤ 1018 in the output format. In othe...
Vasya had two arrays consisting of non-negative integers: a of size n and b of size m. Vasya chose a positive integer k and created an n × m matrix v using the following formula:Vasya wrote down matrix v on a piece of paper and put it in the table.A year later Vasya was cleaning his table when he found a piece of paper...
If the matrix w could not have been obtained in the manner described above, print "NO" (without quotes) in the single line of output. Otherwise, print four lines. In the first line print "YES" (without quotes). In the second line print an integer k (1 ≤ k ≤ 1018). Note that each element of table w should be in range be...
The first line contains integers n and m (1 ≤ n, m ≤ 100), separated by a space — the number of rows and columns in the found matrix, respectively. The i-th of the following lines contains numbers wi, 1, wi, 2, ..., wi, m (0 ≤ wi, j ≤ 109), separated by spaces — the elements of the i-th row of matrix w.
standard output
standard input
Python 3
Python
2,200
train_048.jsonl
ed496b6bd0cf54e4f3ac2a82ffcef1b7
256 megabytes
["2 3\n1 2 3\n2 3 4", "2 2\n1 2\n2 0", "2 2\n1 2\n2 1"]
PASSED
def main(): n, m = map(int, input().split()) l = list(tuple(map(int, input().split())) for _ in range(n)) ma = max(x for _ in l for x in _) bb = l[0] x = bb[0] aa = [_[0] - x for _ in l] err = set(map(abs, filter(None, (a + b - x for a, row in zip(aa, l) for b, x in zip(bb, row))))) if e...
1422705600
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["0", "13"]
2b6645cde74cc9fc6c927a6b1e709852
NoteFrom the fence from the first example it is impossible to cut exactly one piece so as the remaining fence was good.All the possible variants of the resulting fence from the second sample look as follows (the grey shows the cut out part):
Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecutively fastened vertical boards of centimeter width, the height of each in centimeters is a positive integer. The house owner remembers that the height of the i-th board to the left is hi.Today Vasily deci...
Print the remainder after dividing r by 1 000 000 007, where r is the number of ways to cut exactly one connected part so that the part consisted of the upper parts of the boards and the remaining fence was good.
The first line contains integer n (1 ≤ n ≤ 1 000 000) — the number of boards in Vasily's fence. The second line contains n space-separated numbers h1, h2, ..., hn (1 ≤ hi ≤ 109), where hi equals the height of the i-th board to the left.
standard output
standard input
Python 2
Python
2,300
train_049.jsonl
5119f26afc0c035c7e28724db037a174
256 megabytes
["2\n1 1", "3\n3 4 2"]
PASSED
from sys import stdin from itertools import repeat def main(): n = int(stdin.readline()) a = map(int, stdin.readline().split()) mod = 10 ** 9 + 7 for i in xrange(n): a[i] -= 1 lo, v = a[0], 0 px = a[0] ans = a[0] for x in a[1:]: if px > x: lo, v = x, (min(lo, ...
1459353900
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
1 second
["2 3 4 3\n2 3 4 3 5 4 6 5\n2 3 3 3 4 4 4 5"]
ca835eeb8f24de8860d6f5ac6c0af55d
NoteThe first test case is shown in the statement.After the $$$1$$$-st student enters the meeting hall, there are $$$2$$$ good rows and columns: the $$$1$$$-st row and the $$$1$$$-st column.After the $$$2$$$-nd student enters the meeting hall, there are $$$3$$$ good rows and columns: the $$$1$$$-st row, the $$$1$$$-st ...
Tokitsukaze is arranging a meeting. There are $$$n$$$ rows and $$$m$$$ columns of seats in the meeting hall.There are exactly $$$n \cdot m$$$ students attending the meeting, including several naughty students and several serious students. The students are numerated from $$$1$$$ to $$$n\cdot m$$$. The students will ente...
For each test case, print a single line with $$$n \cdot m$$$ integers — the number of good rows and columns just after the $$$i$$$-th student enters the meeting hall.
The first contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 10\,000$$$) — the number of test cases. For each test case, the first line contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n,m \leq 10^6$$$; $$$1 \leq n \cdot m \leq 10^6$$$), denoting there are $$$n$$$ rows and $$$m$$$ columns of seats in the mee...
standard output
standard input
PyPy 3-64
Python
1,700
train_097.jsonl
348bbd4d1769cd2578ec53497701444c
256 megabytes
["3\n\n2 2\n\n1100\n\n4 2\n\n11001101\n\n2 4\n\n11001101"]
PASSED
t = int(input()) for _ in range(t): n, m = list(map(int, input().split())) s = list(input()) if s[0] == '1': rw = [1] cn = [True] cnt = 1 ans = [2] else: rw = [0] cn = [False] cnt = 0 ans = [0] k = 0 for i in range(1,...
1652020500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["10", "1", "4", "4", "2", "7"]
f4a7c573ca0c129f241b415577a76ac2
NoteIn the first example, it is possible to break the $$$2$$$-nd and the $$$4$$$-th section in $$$10$$$ shots, for example, by shooting the third section $$$10$$$ times. After that, the durabilities become $$$[20, 0, 10, 0, 20]$$$. Another way of doing it is firing $$$5$$$ shots at the $$$2$$$-nd section, and another $...
Monocarp plays "Rage of Empires II: Definitive Edition" — a strategic computer game. Right now he's planning to attack his opponent in the game, but Monocarp's forces cannot enter the opponent's territory since the opponent has built a wall.The wall consists of $$$n$$$ sections, aligned in a row. The $$$i$$$-th section...
Print one integer — the minimum number of onager shots needed to break at least two sections of the wall.
The first line contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of sections. The second line contains the sequence of integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th section.
standard output
standard input
PyPy 3-64
Python
2,000
train_107.jsonl
e698e4010a0efc3ee49288a155a11e18
256 megabytes
["5\n20 10 30 10 20", "3\n1 8 1", "6\n7 6 6 8 5 8", "6\n14 3 8 10 15 4", "4\n1 100 100 1", "3\n40 10 10"]
PASSED
n = int(input()) arr = list(map(int, input().split())) min_two = [100000000, 100000000] result = 100000000 for i in range(n): if i < n - 1: x, y = arr[i], arr[i + 1] big, small = max(x, y), min(x, y) if big < small * 2: cnt = big - small big -= cnt * 2 ...
1651502100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["4 8\n10 5\n8 8\n10 6\n10 2\n1 8\n7 8\n10 6", "1 3\n2 1\n1 3"]
8f64c179a883047bf66ee14994364580
NoteThe first example corresponds to the initial setup in the legend, and the tracks of dancers are marked with different colours in the following figure. In the second example, no dancers collide.
Wherever the destination is, whoever we meet, let's render this song together.On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage.On the sides of the s...
Output n lines, the i-th of which contains two space-separated integers (xi, yi) — the stopping position of the i-th dancer in the input.
The first line of input contains three space-separated positive integers n, w and h (1 ≤ n ≤ 100 000, 2 ≤ w, h ≤ 100 000) — the number of dancers and the width and height of the stage, respectively. The following n lines each describes a dancer: the i-th among them contains three space-separated integers gi, pi, and ti...
standard output
standard input
Python 3
Python
1,900
train_001.jsonl
79e64c8079a75fa5e70a0c8718e7b366
256 megabytes
["8 10 8\n1 1 10\n1 4 13\n1 7 1\n1 8 2\n2 2 0\n2 5 14\n2 6 0\n2 6 1", "3 2 3\n1 1 2\n2 1 1\n1 1 5"]
PASSED
from collections import namedtuple Dancer = namedtuple('Dancer', ['category', 'x', 'y', 'idx', 'group']) def read_dancer(idx): group, pos, time = [int(x) for x in input().split(' ')] x, y = None, None if group == 1: x, y = pos, 0 else: x, y = 0, pos return Dancer(time-pos, x, y, idx, group) n, w, h = [int(x...
1504272900
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
1 second
["-2\n-2\n-5\n4\n-1"]
7eae40835f6e9580b985d636d5730e2d
NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$...
Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows: $$$a_1 = -1$$$ $$$a_2 = 2$$$ $$$a_3 = -3$$$ $$$a_4 = 4$$$ $$$a_5 = -5$$$ An...
Print $$$q$$$ lines, each containing one number — the answer to the query.
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.
standard output
standard input
PyPy 2
Python
900
train_024.jsonl
6a22b44bf3a95bf6e6e58e0ddae3dca1
256 megabytes
["5\n1 3\n2 5\n5 5\n4 4\n2 3"]
PASSED
from __future__ import division from sys import stdin, stdout def write(x): stdout.write(str(x) + "\n") q = int(stdin.readline()) for _ in xrange(q): l, r = map(int, stdin.readline().split()) elements = r - l + 1 if elements % 2 == 0: res = elements // 2 if l % 2 == 0: wr...
1543044900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["3", "-1", "2"]
a746bd2a212167ea85d00ffebd73fd9c
NoteIn the first sample test you can contract vertices 4 and 5 and obtain a chain of length 3.In the second sample test it is initially impossible to contract any pair of vertexes, so it is impossible to achieve the desired result.In the third sample test you can contract vertices 1 and 2 and obtain a chain of length 2...
Vova and Marina love offering puzzles to each other. Today Marina offered Vova to cope with the following task.Vova has a non-directed graph consisting of n vertices and m edges without loops and multiple edges. Let's define the operation of contraction two vertices a and b that are not connected by an edge. As a resul...
If it is impossible to obtain a chain from the given graph, print  - 1. Otherwise, print the maximum possible number of edges in the resulting chain.
The first line contains two integers n, m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 100 000) — the number of vertices and the number of edges in the original graph. Next m lines contain the descriptions of edges in the format ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that there is an edge between vertices ai and bi. It is guaranteed ...
standard output
standard input
PyPy 3
Python
2,600
train_019.jsonl
5e1ad00cb4c58cb6528f94491b22e465
256 megabytes
["5 4\n1 2\n2 3\n3 4\n3 5", "4 6\n1 2\n2 3\n1 3\n3 4\n2 4\n1 4", "4 2\n1 3\n2 4"]
PASSED
# lista doble enlazada o(1) operaciones en los bordes es mejor que si se implementa en el propio lenguaje from collections import deque def solve(): n, m = input().split() n = int(n) m = int(m) global maxValue maxValue = n*2 graph = [[] for _ in range(0, n)] for _ in range(0, m): u...
1430668800
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
3 seconds
["3\n4\n2\n7"]
0aa7c678bc06b0a305155b4a31176366
null
You are given $$$n$$$ segments on a coordinate axis $$$OX$$$. The $$$i$$$-th segment has borders $$$[l_i; r_i]$$$. All points $$$x$$$, for which $$$l_i \le x \le r_i$$$ holds, belong to the $$$i$$$-th segment.Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such th...
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 3000$$$) — the number of segments. The next $$$n$$$ lines describe segments. The $$$i$$$-th segment i...
standard output
standard input
PyPy 2
Python
2,300
train_007.jsonl
bd0af4785d19e9b3c44b0e59240fb814
256 megabytes
["4\n4\n1 5\n2 4\n2 3\n3 4\n5\n1 5\n2 3\n2 5\n3 5\n2 2\n3\n1 3\n2 4\n2 3\n7\n1 10\n2 8\n2 5\n3 4\n4 4\n6 8\n7 7"]
PASSED
import sys #sys.stdin=open("data.txt") input=sys.stdin.readline def solve(seg): # compress coordinates co=[] for a,b,_ in seg: co.append(a) co.append(b) co=sorted(set(co)) d={j:i for i,j in enumerate(co)} # get the best non-overlap answer dp=[0]*(len(co)+1) lo=0 for a,b,v in sorted(seg): ...
1596638100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["1\n2\n0\n1"]
b4183febe5ae61770368d2e16f273675
NoteConsider the queries of the example test. in the first query, the substring is baa, which can be changed to bac in one operation; in the second query, the substring is baacb, which can be changed to cbacb in two operations; in the third query, the substring is cb, which can be left unchanged; in the fourth quer...
Let's call the string beautiful if it does not contain a substring of length at least $$$2$$$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindrom...
For each query, print a single integer — the cost of the substring of the string $$$s$$$ from $$$l_i$$$-th to $$$r_i$$$-th position, inclusive.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the length of the string $$$s$$$ and the number of queries. The second line contains the string $$$s$$$, it consists of $$$n$$$ characters, each character one of the first $$$3$$$ Latin letters. The following $$$m$$$ lines co...
standard output
standard input
PyPy 3-64
Python
1,600
train_088.jsonl
18fb96a11cab9dcacc259de1cfe2bb45
256 megabytes
["5 4\nbaacb\n1 3\n1 5\n4 5\n2 3"]
PASSED
a = [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] stt = [3, 5, 1, 4, 0, 2] stt2 = [[3, 4, 0], [5, 2, 1], [1, 5, 2], [4, 0, 3], [0, 3, 4], [2, 1, 5]] # def query(l, r): # minimum = 9999999 # for ii in range(6): # if r >= n-1: # minimum = min(minimum, dp[l][ii]) # ...
1627655700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["0.666666666667"]
7b932b2d3ab65a353b18d81cf533a54e
null
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.Output the probability that SmallR will w...
Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.
A single line contains four integers .
standard output
standard input
Python 3
Python
1,300
train_000.jsonl
bfe1a027fe00a570cda1e07ea006e7bd
256 megabytes
["1 2 1 2"]
PASSED
a,b,c,d=list(map(int,input().split())) print((a/b)/(1-(1-(a/b))*(1-(c/d))))
1369582200
[ "probabilities", "math" ]
[ 0, 0, 0, 1, 0, 1, 0, 0 ]
2 seconds
["YES\nYES\nNO"]
6ae754639d96790c890f9d1ab259332a
NoteFor $$$n=2$$$, Phoenix can create a square like this: For $$$n=4$$$, Phoenix can create a square like this: For $$$n=6$$$, it is impossible for Phoenix to create a square.
Phoenix is playing with a new puzzle, which consists of $$$n$$$ identical puzzle pieces. Each puzzle piece is a right isosceles triangle as shown below. A puzzle piece The goal of the puzzle is to create a square using the $$$n$$$ pieces. He is allowed to rotate and move the pieces around, but none of them can overl...
For each test case, if Phoenix can create a square with the $$$n$$$ puzzle pieces, print YES. Otherwise, print NO.
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the number of puzzle pieces.
standard output
standard input
Python 3
Python
1,000
train_097.jsonl
b13f6f8f2f9a0076a40b7d36ef0d61db
256 megabytes
["3\n2\n4\n6"]
PASSED
t = int(input()) import math for j in range(1, t + 1): n = int(input()) if n % 2 != 0: print("NO") elif n % 2 == 0: n = n // 2 if math.sqrt(n)%1==0: print("YES") elif n % 2 == 0: n = n // 2 if math.sqrt(n)%1==0: ...
1619966100
[ "number theory", "geometry", "math" ]
[ 0, 1, 0, 1, 1, 0, 0, 0 ]
3 seconds
["333333338\n141946947\n329622137"]
206a9a83a1d143a1a8d8d3a7512f59e2
NoteExplanation of the first sample test case:Let's write out all possible sequences of light toggles, which will make the device complete its operation: $$$(1, 2)$$$  — $$$2$$$ lights are turned on $$$(1, 3, 2)$$$  — $$$3$$$ lights are turned on $$$(2, 1)$$$  — $$$2$$$ lights are turned on $$$(2, 3)$$$  — $$$2$$$ ...
To monitor cryptocurrency exchange rates trader William invented a wonderful device consisting of $$$n$$$ lights arranged in a row. The device functions in the following way:Initially, all lights on William's device are turned off. At the beginning of a new iteration the device randomly, with a uniform distribution, ...
For each test case print the answer, modulo $$$10^9+7$$$. Formally, let $$$M = 10^9+7$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the integer equal to $$$p \cdot q^{-1} \bmod M$$$. I...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10$$$). Description of the test cases follows. The only line for each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le k \le n \le 10^5$$$), which are the total number of lights and the length o...
standard output
standard input
PyPy 3-64
Python
2,600
train_082.jsonl
67f46963a9391958f0258af511247aa8
256 megabytes
["3\n3 2\n15 2\n40 15"]
PASSED
import os, sys from io import BytesIO, IOBase from collections import defaultdict, deque, Counter from bisect import bisect_left, bisect_right from heapq import heappush, heappop from functools import lru_cache from itertools import accumulate import math import sys # sys.setrecursionlimit(10 ** 6) # Fast...
1622385300
[ "probabilities", "math" ]
[ 0, 0, 0, 1, 0, 1, 0, 0 ]
1 second
["1\n2\n5\n3 3 3 1 2"]
ac248c83c99d8a2262772816b5f4ac6e
NoteIn the first case, adding $$$1$$$ candy to all bags except of the second one leads to the arrangement with $$$[2, 2]$$$ candies.In the second case, firstly you use first three operations to add $$$1+2+3=6$$$ candies in total to each bag except of the third one, which gives you $$$[7, 8, 3]$$$. Later, you add $$$4$$...
There are $$$n$$$ bags with candies, initially the $$$i$$$-th bag contains $$$i$$$ candies. You want all the bags to contain an equal amount of candies in the end. To achieve this, you will: Choose $$$m$$$ such that $$$1 \le m \le 1000$$$Perform $$$m$$$ operations. In the $$$j$$$-th operation, you will pick one bag and...
For each testcase, print two lines with your answer. In the first line print $$$m$$$ ($$$1\le m \le 1000$$$) — the number of operations you want to take. In the second line print $$$m$$$ positive integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_i \le n$$$), where $$$a_j$$$ is the number of bag you chose on the $$$j$$$...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of each test case contains one integer $$$n$$$ ($$$2 \le n\le 100$$$).
standard output
standard input
Python 3
Python
800
train_009.jsonl
4758625c1fd03dbac28aafdcc7ce1e09
256 megabytes
["2\n2\n3"]
PASSED
t = int(input()) def solve(): n = int(input()) print(n) arr = list(range(1, n + 1)) arr = [str(i) for i in arr] print(" ".join(arr)) for i in range(t): solve()
1605450900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2\n1\n3"]
adf024899fb2a684427463733358566a
NoteIn the first test case Alice has to swap $$$1$$$ and $$$2$$$. After that Bob removes the last digit, $$$1$$$, so the answer is $$$2$$$.In the second test case Alice can swap $$$3$$$ and $$$1$$$: $$$312$$$. After that Bob deletes the last digit: $$$31$$$. Then Alice swaps $$$3$$$ and $$$1$$$: $$$13$$$ and Bob delete...
There is an integer $$$n$$$ without zeros in its decimal representation. Alice and Bob are playing a game with this integer. Alice starts first. They play the game in turns.On her turn, Alice must swap any two digits of the integer that are on different positions. Bob on his turn always removes the last digit of the in...
For each test case output a single integer — the smallest integer Alice can get in the end of the game.
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Description of the test cases follows. The first and the only line of each test case contains the integer $$$n$$$ ($$$10 \le n \le 10^9$$$) — the integer for the game. $$$n$$$...
standard output
standard input
PyPy 3-64
Python
800
train_103.jsonl
ebd44a27bba39d1853585e060b7bf395
256 megabytes
["3\n\n12\n\n132\n\n487456398"]
PASSED
for _ in range(int(input())): n = list(map(int, ' '.join(input()).split())) if len(n) > 2: print(min(n)) else: print(n[-1])
1652970900
[ "math", "games", "strings" ]
[ 1, 0, 0, 1, 0, 0, 1, 0 ]
1 second
["1\n3 \n2\n2 1", "2\n3 6\n4\n1 2 4 5"]
fab438cef9eb5e9e4a4a2e3f9e4f9cec
NoteIn the first example Lesha can read the third note in $$$3$$$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $$$3$$$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day an...
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.Lesha knows that today he can study for at most $$$a$$$ hours, and he will have $$$b$$$ hours to stu...
In the first line print a single integer $$$n$$$ ($$$0 \leq n \leq a$$$) — the number of lecture notes Lesha has to read in the first day. In the second line print $$$n$$$ distinct integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \leq p_i \leq a$$$), the sum of all $$$p_i$$$ should not exceed $$$a$$$. In the third line print...
The only line of input contains two integers $$$a$$$ and $$$b$$$ ($$$0 \leq a, b \leq 10^{9}$$$) — the number of hours Lesha has today and the number of hours Lesha has tomorrow.
standard output
standard input
Python 3
Python
1,600
train_015.jsonl
d052e7cc2614c8ade1dc11ca1b67014d
256 megabytes
["3 3", "9 12"]
PASSED
def check(): a, b = [int(s) for s in input().split()] a1 = min(a, b) b1 = max(a, b) sum0=0 i=0 while(sum0<=a1): i += 1 sum0+=i ax=i-1 sum1=sum0-i r=a1-sum1 if(r==0): sum0 = 0 i = i - 1 while (sum0 <= b1): i += 1 ...
1540109400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["b\naabbbabaa\nbbbb\nabbaaa"]
351ffff1dfe1bc1762f062f612463759
NoteIn the first test case, both $$$\operatorname{AB}(s) = 0$$$ and $$$\operatorname{BA}(s) = 0$$$ (there are no occurrences of ab (ba) in b), so can leave $$$s$$$ untouched.In the second test case, $$$\operatorname{AB}(s) = 2$$$ and $$$\operatorname{BA}(s) = 2$$$, so you can leave $$$s$$$ untouched. In the third test ...
You are given a string $$$s$$$ of length $$$n$$$ consisting of characters a and/or b.Let $$$\operatorname{AB}(s)$$$ be the number of occurrences of string ab in $$$s$$$ as a substring. Analogically, $$$\operatorname{BA}(s)$$$ is the number of occurrences of ba in $$$s$$$ as a substring.In one step, you can choose any i...
For each test case, print the resulting string $$$s$$$ with $$$\operatorname{AB}(s) = \operatorname{BA}(s)$$$ you'll get making the minimum number of steps. If there are multiple answers, print any of them.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first and only line of each test case contains a single string $$$s$$$ ($$$1 \le |s| \le 100$$$, where $$$|s|$$$ is the length of the string $$$s$$$), con...
standard output
standard input
PyPy 3-64
Python
900
train_108.jsonl
80f3dbd9137db63a32ebd0e5be8f924f
256 megabytes
["4\nb\naabbbabaa\nabbb\nabbaab"]
PASSED
import sys inpu = sys.stdin.readline prin = sys.stdout.write for _ in range(int(inpu())) : s = inpu().rstrip('\n') ab = s.count('ab') ba = s.count('ba') s = list(s) if ab > ba: s[-1] = 'a' elif ba > ab : s[-1] = 'b' prin(''.join(map(str, s)) + '\n')
1635518100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["1\n3\n9\n13\n27\n6561\n19683"]
5953b898995a82edfbd42b6c0f7138af
null
The only difference between easy and hard versions is the maximum value of $$$n$$$.You are given a positive integer number $$$n$$$. You really love good numbers so you want to find the smallest good number greater than or equal to $$$n$$$.The positive integer is called good if it can be represented as a sum of distinct...
For each query, print such smallest integer $$$m$$$ (where $$$n \le m$$$) that $$$m$$$ is a good number.
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Then $$$q$$$ queries follow. The only line of the query contains one integer $$$n$$$ ($$$1 \le n \le 10^4$$$).
standard output
standard input
PyPy 3
Python
1,500
train_000.jsonl
699af83fb5e7dcd991f7e65beaa54eea
256 megabytes
["7\n1\n2\n6\n13\n14\n3620\n10000"]
PASSED
def main(): q = int(input()) for _ in [0]*q: n = int(input()) nn = n res = [0]*50 p = pow(3,49) idx = 49 ma = -1 while n != 0: if n >= p: pr = n//p res[idx] = pr n -= pr*p if pr =...
1571754900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["16\n16\n4\n9\n64\n9\n64\n40000"]
3bb093fb17d6b76ae340fab44b08fcb8
NoteBelow are the answers for the first two test cases:
Find the minimum area of a square land on which you can place two identical rectangular $$$a \times b$$$ houses. The sides of the houses should be parallel to the sides of the desired square land.Formally, You are given two identical rectangles with side lengths $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 100$$$) — positi...
Print $$$t$$$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $$$a \times b$$$.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) —the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$a$$$, $$$b$$$ ($$$1 \le a, b \le 100$$$) — side lengths of the rectangles.
standard output
standard input
PyPy 2
Python
800
train_002.jsonl
f2364062305578c1119af021d4563f6d
256 megabytes
["8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100"]
PASSED
import atexit import io import sys import math from collections import defaultdict _INPUT_LINES = sys.stdin.read().splitlines() raw_input = iter(_INPUT_LINES).next _OUTPUT_BUFFER = io.BytesIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) t=int(raw_inp...
1590327300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1 2 3", "2 6", "-1"]
eba76d0491f88ac8d8450e457610b067
null
You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal.Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.If th...
If the answer exists then output k numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.
The first line consists of two numbers n and k (1 ≤ n, k ≤ 1010).
standard output
standard input
Python 3
Python
1,900
train_004.jsonl
c34323ca47130ab761d999430febecd3
256 megabytes
["6 3", "8 2", "5 3"]
PASSED
import math n, k = map(int, input().split()) Ans = [] if n < (k+1)*k//2: print(-1) else: d = n nd = 1 for i in range(int(math.sqrt(n)), 1, -1): if n%i == 0: if i > nd and n//i >=(k+1)*k//2: nd = i if n//i > nd and i >=(k+1)*k//2: nd = n/...
1493391900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2\n1\n1", "2\n2\n2\n2\n2"]
3a767b3040f44e3e2148cdafcb14a241
NoteIn the first sample test:In Peter's first test, there's only one cycle with 1 vertex. First player cannot make a move and loses.In his second test, there's one cycle with 1 vertex and one with 2. No one can make a move on the cycle with 1 vertex. First player can replace the second cycle with two cycles of 1 vertex...
Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of vertices, such that first one is connected with the second, second is connected with third and so on, while the last one is connected with the first one again. Cycle may consist of a single isolated vertex.Initially the...
Print the result of all tests in order they are performed. Print 1 if the player who moves first wins or 2 otherwise.
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of tests Peter is about to make. The second line contains n space separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), i-th of them stands for the number of vertices in the cycle added before the i-th test.
standard output
standard input
Python 3
Python
1,100
train_042.jsonl
500194f3c55c3bb001e3a1e50a3203d8
256 megabytes
["3\n1 2 3", "5\n1 1 5 1 1"]
PASSED
def main(): n, l, v = int(input()), input().split(), 0 for i, a in enumerate(l): v ^= ord(a[-1]) - 1 l[i] = (('2', '1')[v & 1]) print('\n'.join(l)) if __name__ == '__main__': main()
1470578700
[ "math", "games" ]
[ 1, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["3", "5"]
3992602be20a386f0ec57c51e14b39c5
NoteIn the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.Optimal sequence of actions in the second sample case: In the first day Anastasia collects 8 pebbles of the third type. In the second day she co...
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.She has only two pockets. She can put at most k pebbles in each pocket at the same time. T...
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.
standard output
standard input
Python 3
Python
1,100
train_009.jsonl
a5423dac3e76300c3a7c7831a307e0e4
256 megabytes
["3 2\n2 3 4", "5 4\n3 1 8 9 7"]
PASSED
n, k = map(int, input().split()) w = list(map(int, input().split())) q=0 t=0 for i in range(n): a=w[i]//k w[i]%=k q+=(a//2) t+=(a%2) # print(a, w[i], t, q) if t==2: t=0 q+=1 if w[i]>0: if t==1: t=0 w[i]=0 q+=1 else: w[i]=0 t+=1 if t>0: q+=1 print(q)
1490803500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
6 seconds
["4", "2", "14", "1", "120"]
96fe0cd25dc0f6a76ebeb43834bae8de
null
You are given a tree, consisting of $$$n$$$ vertices. Each edge has an integer value written on it.Let $$$f(v, u)$$$ be the number of values that appear exactly once on the edges of a simple path between vertices $$$v$$$ and $$$u$$$.Calculate the sum of $$$f(v, u)$$$ over all pairs of vertices $$$v$$$ and $$$u$$$ such ...
Print a single integer — the sum of $$$f(v, u)$$$ over all pairs of vertices $$$v$$$ and $$$u$$$ such that $$$v &lt; u$$$.
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^5$$$) — the number of vertices in the tree. Each of the next $$$n-1$$$ lines contains three integers $$$v, u$$$ and $$$x$$$ ($$$1 \le v, u, x \le n$$$) — the description of an edge: the vertices it connects and the value written on it. The give...
standard output
standard input
PyPy 3-64
Python
2,300
train_087.jsonl
7c70d412cc7c61bc0c1692ea9b7c66d8
1024 megabytes
["3\n1 2 1\n1 3 2", "3\n1 2 2\n1 3 2", "5\n1 4 4\n1 2 3\n3 4 4\n4 5 5", "2\n2 1 1", "10\n10 2 3\n3 8 8\n4 8 9\n5 8 5\n3 10 7\n7 8 2\n5 6 6\n9 3 4\n1 6 3"]
PASSED
input = __import__('sys').stdin.readline n = int(input()) adj = [[] for _ in range(n)] for _ in range(n-1): u, v, x = map(lambda x: int(x)-1, input().split()) adj[u].append((v, x)) adj[v].append((u, x)) TRAVERSE = 0 UPDATE_DP = 1 prev_node_stack = [[0] for _ in range(n)] prev_node = [0...
1653316500
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["11", "1001"]
bcf75978c9ef6202293773cf533afadf
NoteThe first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome...
Print the n-th even-length palindrome number.
The only line of the input contains a single integer n (1 ≤ n ≤ 10100 000).
standard output
standard input
PyPy 3
Python
1,000
train_023.jsonl
dcfbf68f75aeed09adecdda29a8f97d8
256 megabytes
["1", "10"]
PASSED
s = input() print(s + ''.join(reversed(s)))
1467219900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES", "NO", "NO"]
113ae625e67c8ea5ab07be44c3b58a8f
null
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish stri...
Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.
The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106.
standard output
standard input
Python 3
Python
1,500
train_006.jsonl
9fdc67b1d35071ca736835762e199bc1
256 megabytes
["11\n10", "1\n01", "000\n101"]
PASSED
s1 = input() s2 = input() if len(s1) != len(s2): print("NO") exit() elif len(s1) == 1: if s1 != s2: print("NO") else: print("YES") exit() elif s1 == s2: print("YES") exit() if (s1.count("1") != 0) and (s2.count("1") != 0): print("YES") else: print("NO")
1363188600
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2"]
a1631f068c8da218243a9ab0aced4f16
null
Little penguin Polo has got a tree — a non-directed connected acyclic graph, containing n nodes and n - 1 edges. We will consider the tree nodes numbered by integers from 1 to n.Today Polo wonders, how to find the number of pairs of paths that don't have common nodes. More formally, he should find the number of groups ...
In a single line print a single integer — the answer to the problem. 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 integer n (1 ≤ n ≤ 80000) — the number of tree nodes. Each of the following n - 1 lines contains a pair of integers ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) — the i-th edge of the tree. It is guaranteed that the given graph is a tree.
standard output
standard input
Python 2
Python
2,400
train_035.jsonl
a3f396ce90df85dc8747e777579d7ee9
256 megabytes
["4\n1 2\n2 3\n3 4"]
PASSED
n=input() e=[[] for i in range(0,n+10)] sz,f=[0]*(n+10),[0]*(n+10) s=[] ans=n*n*(n-1)*(n-1)/4 for i in xrange(1,n): u,v=map(int,raw_input().split()) e[u].append(v) e[v].append(u) q=[1] for i in xrange(0,n): u=q[i] for v in e[u]: if (v==f[u]): continue q.append(v) f[v]=u for i in reversed(xrange(0,n)): u=q[i...
1364916600
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["6\n1\n9999999966"]
adcd813d4c45337bbd8bb0abfa2f0e00
NoteIn the first test case appropriate $$$x$$$-s are $$$[0, 1, 3, 4, 6, 7]$$$.In the second test case the only appropriate $$$x$$$ is $$$0$$$.
You are given two integers $$$a$$$ and $$$m$$$. Calculate the number of integers $$$x$$$ such that $$$0 \le x &lt; m$$$ and $$$\gcd(a, m) = \gcd(a + x, m)$$$.Note: $$$\gcd(a, b)$$$ is the greatest common divisor of $$$a$$$ and $$$b$$$.
Print $$$T$$$ integers — one per test case. For each test case print the number of appropriate $$$x$$$-s.
The first line contains the single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of test cases. Next $$$T$$$ lines contain test cases — one per line. Each line contains two integers $$$a$$$ and $$$m$$$ ($$$1 \le a &lt; m \le 10^{10}$$$).
standard output
standard input
PyPy 3
Python
1,800
train_002.jsonl
ece9037a7d3ed495182e3f0819d92139
256 megabytes
["3\n4 9\n5 10\n42 9999999967"]
PASSED
import math def cal(x, y, z): return z // x - y // x T = int(input()) while T: T -= 1 a, m = map(int, input().split()) k = math.gcd(a, m) x = (m - 1) // k n = m // k i = 2 p = [] while i * i <= m // k: if n % i == 0: while n % i == 0: n ...
1580308500
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["2 3\n1 2\n1 1"]
7af4eee2e9f60283c4d99200769c77ec
NoteIn the first case, for $$$i = 2$$$ and $$$j = 3$$$ the equality holds true for all $$$k$$$: $$$k = 1$$$: $$$|a_2 - a_1| + |a_1 - a_3| = |2 - 5| + |5 - 7| = 5 = |2 - 7| = |a_2-a_3|$$$, $$$k = 2$$$: $$$|a_2 - a_2| + |a_2 - a_3| = |2 - 2| + |2 - 7| = 5 = |2 - 7| = |a_2-a_3|$$$, $$$k = 3$$$: $$$|a_2 - a_3| + |a_3 -...
You are given an array $$$a_1, a_2, \ldots, a_n$$$ of positive integers. A good pair is a pair of indices $$$(i, j)$$$ with $$$1 \leq i, j \leq n$$$ such that, for all $$$1 \leq k \leq n$$$, the following equality holds:$$$$$$ |a_i - a_k| + |a_k - a_j| = |a_i - a_j|, $$$$$$ where $$$|x|$$$ denotes the absolute value of...
For each test case, print a single line with two space-separated indices $$$i$$$ and $$$j$$$ which form a good pair of the array. The case $$$i=j$$$ is allowed. It can be shown that such a pair always exists. If there are multiple good pairs, print any of them.
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line of ...
standard output
standard input
PyPy 3-64
Python
800
train_091.jsonl
42f9289222c3a343ac244d76a9b3a84f
256 megabytes
["3\n\n3\n\n5 2 7\n\n5\n\n1 4 2 2 3\n\n1\n\n2"]
PASSED
t = int(input()) for _ in range(t): n = int(input()) li = list(map(int,input().split())) i = li.index(min(li)) + 1 j = li.index(max(li)) + 1 print(i,j)
1648132500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["6\n9\n5\n0\n116461800"]
875851f43c7a6e09cd3d20f2a6980d40
NoteHere are the pairs for the first test case:
Berland year consists of $$$m$$$ months with $$$d$$$ days each. Months are numbered from $$$1$$$ to $$$m$$$. Berland week consists of $$$w$$$ days. The first day of the year is also the first day of the week. Note that the last week of the year might be shorter than $$$w$$$ days.A pair $$$(x, y)$$$ such that $$$x &lt; ...
Print $$$t$$$ integers — for each testcase output the number of pairs $$$(x, y)$$$ such that $$$x &lt; y$$$ and day $$$x$$$ of month $$$y$$$ is the same day of the week as day $$$y$$$ of month $$$x$$$.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$m$$$, $$$d$$$ and $$$w$$$ ($$$1 \le m, d, w \le 10^9$$$) — the number of months in a year, the number of days in a month and the number of days in a week.
standard output
standard input
PyPy 3
Python
2,200
train_053.jsonl
2cf8e7e0fc5f92884a9357ac811ab4b5
256 megabytes
["5\n6 7 4\n10 7 12\n12 30 7\n1 1 1\n3247834 10298779 625324"]
PASSED
def GCD(x, y): while(y):x,y=y,x%y return x for i in ' '*int(input()): m,d,w=map(int,input().split()) m=min(m,d) g=GCD(d-1,w) ww=w//g k=m//ww print(k*m-k*(k+1)//2*ww)
1596033300
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
4 seconds
["5\n2 1\n3 2\n5 3\n5 4\n6 5", "12\n2 1\n4 1\n5 4\n6 5\n7 1\n7 4\n8 3\n8 5\n9 3\n9 6\n10 4\n10 7"]
5a0f578ef7e9e9f28ee0b5b19be2ca76
null
Vus the Cossack has a simple graph with $$$n$$$ vertices and $$$m$$$ edges. Let $$$d_i$$$ be a degree of the $$$i$$$-th vertex. Recall that a degree of the $$$i$$$-th vertex is the number of conected edges to the $$$i$$$-th vertex.He needs to remain not more than $$$\lceil \frac{n+m}{2} \rceil$$$ edges. Let $$$f_i$$$ b...
In the first line, print one integer $$$k$$$ ($$$0 \leq k \leq \lceil \frac{n+m}{2} \rceil$$$) — the number of edges which you need to remain. In each of the next $$$k$$$ lines, print two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$) — the vertices, the edge between which, you need to remain. You can ...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^6$$$, $$$0 \leq m \leq 10^6$$$) — the number of vertices and edges respectively. Each of the next $$$m$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$) — vertices between which there is an edge. It is guar...
standard output
standard input
PyPy 2
Python
2,400
train_036.jsonl
2988cd95461f2897a821d65472a2da25
256 megabytes
["6 6\n1 2\n2 3\n3 4\n4 5\n5 3\n6 5", "10 20\n4 3\n6 5\n4 5\n10 8\n4 8\n5 8\n10 4\n9 5\n5 1\n3 8\n1 2\n4 7\n1 4\n10 7\n1 7\n6 1\n9 6\n3 9\n7 9\n6 2"]
PASSED
from __future__ import print_function from sys import stdin inp = [int(x) for x in stdin.read().split()] n, m = inp[0], inp[1] in_idx = 2 n += 1 adj = [[] for _ in range(n)] edge_index = [[] for _ in range(n)] for i in range(m): a = inp[in_idx] in_idx += 1 b = inp[in_idx] in_idx += 1 adj[a].append(b) edge_inde...
1561710000
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["4\n10\n143922563\n698570404"]
d8066e517678dfd6a11f2bfa9e0faed0
NoteIn the first test case, it can be proven that the maximum $$$F(a)$$$ among all good arrays $$$a$$$ is equal to $$$2$$$. The excellent arrays are: $$$[2, 1, 2]$$$; $$$[0, 3, 2]$$$; $$$[2, 3, 2]$$$; $$$[3, 0, 1]$$$.
Let's call an integer array $$$a_1, a_2, \dots, a_n$$$ good if $$$a_i \neq i$$$ for each $$$i$$$.Let $$$F(a)$$$ be the number of pairs $$$(i, j)$$$ ($$$1 \le i &lt; j \le n$$$) such that $$$a_i + a_j = i + j$$$.Let's say that an array $$$a_1, a_2, \dots, a_n$$$ is excellent if: $$$a$$$ is good; $$$l \le a_i \le r$$$...
For each test case, print the number of excellent arrays modulo $$$10^9 + 7$$$.
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 three integers $$$n$$$, $$$l$$$, and $$$r$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$-10^9 \le l \le 1$$$; $$$n \le r \le 10^9$$$). It's guaranteed that the sum of $$$n$$...
standard output
standard input
PyPy 3
Python
2,300
train_094.jsonl
a5bb98103cda5b3e586b09c2486192b8
256 megabytes
["4\n3 0 3\n4 -3 5\n42 -33 55\n69 -42 146"]
PASSED
from sys import stdin, stdout import sys # 1 2 3 4 # # 1+k, 2+k | 3-k, 4-k # 1-k >= l => k <= 1-l # n+k <= r => k <= r-n # if k <= min(1-l, r-n) # then C(n,n/2) even, C(n,n/2) + C(n, n/2+1) # MOD = 1000000007 def bpow(a, b): global MOD if b == 0: return 1 c = bpow(a, b//2) c *= c c %= M...
1626273300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1.5 seconds
["4\n8\n2\n2"]
79ecf771f4a54c2c9f988e069f7bfceb
NoteIn the first example, one valid way to select the elements is $$$[\underline{1}, 2, \underline{3}, \underline{4}, \underline{5}]$$$. All subsegments satisfy at least one of the criteria. For example, for the subsegment $$$l = 1$$$, $$$r = 2$$$ we have that the element $$$2$$$ is not selected, satisfying the first c...
You are given an array of integers $$$a_1, a_2, \ldots, a_n$$$ and an integer $$$x$$$.You need to select the maximum number of elements in the array, such that for every subsegment $$$a_l, a_{l + 1}, \ldots, a_r$$$ containing strictly more than one element $$$(l &lt; r)$$$, either: At least one element on this subseg...
For each test case, print one integer: the maximum number of elements that you can select.
The first line of input contains one integer $$$t$$$ ($$$1 \leq t \leq 10$$$): the number of test cases. The descriptions of $$$t$$$ test cases follow, three lines per test case. In the first line you are given one integer $$$n$$$ ($$$1 \leq n \leq 50\,000$$$): the number of integers in the array. The second line conta...
standard output
standard input
PyPy 3
Python
2,000
train_101.jsonl
417e5354077a49943fc76ea8463e6911
256 megabytes
["4\n5\n1 2 3 4 5\n2\n10\n2 4 2 4 2 4 2 4 2 4\n3\n3\n-10 -5 -10\n-8\n3\n9 9 -3\n5"]
PASSED
inf=float("inf") for _ in range(int(input())): n=int(input()) xx=[int(x) for x in input().split()] x=int(input()) m=inf a=0 for i in range(n): a+=1 if xx[i]+m<x*a: xx[i]=inf m=inf a=0 else: if m+xx[i] - x*a <...
1640792100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["FTT\n\nTTF", "FTFF\n\nTTTT\n\nTFTT"]
f4a5815ecbdf744b80791cf728abf8c6
NoteThe empty lines in the example are just for you to better understand the interaction process. You're not required to print them.In the first example, there are $$$3$$$ questions, and the answer to each question is 'true', 'true', and 'false', respectively. The first query, guessing the answers to be 'false', 'tru...
Mark is administering an online exam consisting of $$$n$$$ true-false questions. However, he has lost all answer keys. He needs a way to retrieve the answers before his client gets infuriated.Fortunately, he has access to the grading system. Thus, for each query, you can input the answers to all $$$n$$$ questions, and ...
null
The first line of the input consists of an integer $$$n$$$ ($$$1\leq n\leq 1000$$$) — the number of questions.
standard output
standard input
PyPy 3-64
Python
2,900
train_100.jsonl
ca36f072329928a1e913611d4699aa74
256 megabytes
["3\n\n1\n\n3", "4\n\n0\n\n3\n\n4"]
PASSED
#from math import ceil, floor #, gcd, log, factorial, comb, perm, #log10, log2, log, sin, asin, tan, atan, #from heapq import heappop,heappush,heapify #heappop(hq), heapify(list) #from collections import defaultdict as dd #mydd=dd(list) for .append #from collections import deque as dq #deque e.g. myqueue=dq(list)...
1657892100
[ "probabilities" ]
[ 0, 0, 0, 0, 0, 1, 0, 0 ]
2 seconds
["cfmailru", "NO"]
02fe37c2e31ca4e278d493fc2e3e35e0
NoteOne can show that in the first sample only two good strings with minimum length exist: "cfmailru" and "mailrucf". The first string is lexicographically minimum.
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Resto...
Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings.
The first line contains integer n (1 ≤ n ≤ 105) — the number of strings in the set. Each of the next n lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct. The total length of the strings doesn't exceed 105.
standard output
standard input
Python 3
Python
2,000
train_017.jsonl
bdef7a376f448f5856521e8115c34918
256 megabytes
["4\nmail\nai\nlru\ncf", "3\nkek\npreceq\ncheburek"]
PASSED
def cm(s1,s2): for i in range(1, len(s1)): if s1[:i] == s2[-i:] : s = s2 + s1[i:] if len(s) == len(set(list(s))): return s if s2[:i] == s1[-i:]: s = s1 + s2[i:] if len(s) == len(set(list(s))): return s return None n...
1510502700
[ "strings", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 1, 0 ]
1 second
["Poor Dima!", "Poor Inna!", "4"]
80fdfeba87b7075c70671b3fd3a1199c
NoteNotes to the samples:In the first test sample, Inna cannot go through name DIMA a single time.In the second test sample, Inna can go through the infinite number of words DIMA. For that, she should move in the clockwise direction starting from the lower right corner.In the third test sample the best strategy is to s...
Inna and Dima bought a table of size n × m in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A".Inna loves Dima, so she wants to go through his name as many times as possible as she moves through the table. For that, Inna acts as follows: initially, Inna chooses some cell of the table where...
If Inna cannot go through name DIMA once, print on a single line "Poor Dima!" without the quotes. If there is the infinite number of names DIMA Inna can go through, print "Poor Inna!" without the quotes. Otherwise print a single integer — the maximum number of times Inna can go through name DIMA.
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 103). Then follow n lines that describe Inna and Dima's table. Each line contains m characters. Each character is one of the following four characters: "D", "I", "M", "A". Note that it is not guaranteed that the table contains at least one letter "...
standard output
standard input
PyPy 3
Python
1,900
train_015.jsonl
d31f9145e86db5f0b2879a9c6717f390
256 megabytes
["1 2\nDI", "2 2\nMA\nID", "5 5\nDIMAD\nDIMAI\nDIMAM\nDDMAA\nAAMID"]
PASSED
import sys n, m = map(int, input().split()) m += 1 d = {'I': 0, 'M': 1, 'A': 2, 'D': 3, '\n': -7} t = list(map(d.get, sys.stdin.read())) + [-7] * m p = [[] for q in t] c = [0] * len(t) for a in range(n * m): for b in (a - m, a + m, a - 1, a + 1): if abs(t[b] - t[a] + 1) == 2: p[a].append(b) ...
1387380600
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["32", "4", "1920", "10"]
4ca7837d1ddf80f0bde4aac2fb37d60b
NoteIn the first case, $$$a = 19305$$$. Its divisors are $$$1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305$$$ — a total of $$$32$$$.In the second case, $$$a$$$ has four divisors: $$$1$$$, $$$86028121$$$, $$$86028157$$$...
You are given $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$. Each of $$$a_i$$$ has between $$$3$$$ and $$$5$$$ divisors. Consider $$$a = \prod a_i$$$ — the product of all input integers. Find the number of divisors of $$$a$$$. As this number may be very large, print it modulo prime number $$$998244353$$$.
Print a single integer $$$d$$$ — the number of divisors of the product $$$a_1 \cdot a_2 \cdot \dots \cdot a_n$$$ modulo $$$998244353$$$. Hacks input For hacks, the input needs to be provided in a special format. The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 500$$$) — the number of numbers. Each of the ne...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 500$$$) — the number of numbers. Each of the next $$$n$$$ lines contains an integer $$$a_i$$$ ($$$1 \leq a_i \leq 2\cdot 10^{18}$$$). It is guaranteed that the number of divisors of each $$$a_i$$$ is between $$$3$$$ and $$$5$$$.
standard output
standard input
PyPy 3
Python
2,000
train_028.jsonl
2247664b54bb0a1424d3f8df865c68c6
256 megabytes
["3\n9\n15\n143", "1\n7400840699802997", "8 \n4606061759128693\n4606066102679989\n4606069767552943\n4606063116488033\n4606063930903637\n4606064745319241\n4606063930904021\n4606065559735517", "3\n4\n8\n16"]
PASSED
import math import sys from decimal import Decimal n=int(input()) d={} f={} s=set() for j in range(n): i=int(input()) f.setdefault(i,0) f[i]+=1 x=i**.25 x=int(x) y=i**.5 y=int(y) if x**4==i: d.setdefault(x,0) d[x]+=4 elif y*y==i: x=int(i**.5) d.setd...
1538931900
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["11", "66"]
f350de23c9750b6e95b8cad80dde77c9
NoteIn the first test, you can make such operations: Delete element $$$1$$$ from set $$$1$$$. You should pay $$$a_1 + b_1 = 5$$$ coins for that. Delete element $$$1$$$ from set $$$2$$$. You should pay $$$a_2 + b_1 = 6$$$ coins for that. You pay $$$11$$$ coins in total. After these operations, the first and the second...
You are given $$$m$$$ sets of integers $$$A_1, A_2, \ldots, A_m$$$; elements of these sets are integers between $$$1$$$ and $$$n$$$, inclusive.There are two arrays of positive integers $$$a_1, a_2, \ldots, a_m$$$ and $$$b_1, b_2, \ldots, b_n$$$. In one operation you can delete an element $$$j$$$ from the set $$$A_i$$$ ...
Print one integer: the minimum number of coins you should pay for operations to avoid rainbow cycles in the obtained graph.
The first line contains two integers $$$m$$$ and $$$n$$$ ($$$1 \leq m, n \leq 10^5$$$), the number of sets and the number of vertices in the graph. The second line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \leq a_i \leq 10^9$$$). The third line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$...
standard output
standard input
PyPy 3
Python
2,400
train_044.jsonl
6bc454ac3728b5c16e8e43544bc0f16c
256 megabytes
["3 2\n1 2 3\n4 5\n2 1 2\n2 1 2\n2 1 2", "7 8\n3 6 7 9 10 7 239\n8 1 9 7 10 2 6 239\n3 2 1 3\n2 4 1\n3 1 3 7\n2 4 3\n5 3 4 5 6 7\n2 5 7\n1 8"]
PASSED
import sys int1 = lambda x: int(x)-1 def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def root(u): stack=[] while 1: if uf[u]<0: for v i...
1601476500
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1 second
["3\nabout proud\nhooray round\nwow first\nthis is\ni that\nmcdics am", "0", "1\nsame differ\nsame same"]
f06f7d0dcef10f064f5ce1e9eccf3928
NoteIn the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both ...
You are given $$$n$$$ words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.Each lyric consists of two lines. Each line consists of two words separated by whitespace. A lyric is be...
In the first line, print $$$m$$$ — the number of maximum possible beautiful lyrics. In next $$$2m$$$ lines, print $$$m$$$ beautiful lyrics (two lines per lyric). If there are multiple answers, print any.
The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^{5}$$$) — the number of words. The $$$i$$$-th of the next $$$n$$$ lines contains string $$$s_{i}$$$ consisting lowercase alphabet letters — the $$$i$$$-th word. It is guaranteed that the sum of the total word length is equal or less than $$$10^{6}$$$. Ea...
standard output
standard input
PyPy 2
Python
1,700
train_034.jsonl
fd891599d2896e0e2c5c0dda0f8aa7a5
256 megabytes
["14\nwow\nthis\nis\nthe\nfirst\nmcdics\ncodeforces\nround\nhooray\ni\nam\nproud\nabout\nthat", "7\narsijo\nsuggested\nthe\nidea\nfor\nthis\nproblem", "4\nsame\nsame\nsame\ndiffer"]
PASSED
from sys import stdin, stdout import sys, atexit, io buffer = io.BytesIO() sys.stdout = buffer @atexit.register def write(): sys.__stdout__.write(buffer.getvalue()) @atexit.register def main(): dici = {} n = int(stdin.readline()) for k in xrange(n): word = stdin.readline() vog = "" cont = 0 for l in w...
1560258300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["25200.0000", "1365.0000"]
937acacc6d5d12d45c08047dde36dcf0
NoteIn the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per ...
After waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is H points, moreover each minute without food increases his hunger by D points.At any time Andrew can visit the store where tasty buns are sold (you...
Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10 - 4. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if .
The first line contains two integers hh and mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59) — the time of Andrew's awakening. The second line contains four integers H, D, C and N (1 ≤ H ≤ 105, 1 ≤ D, C, N ≤ 102).
standard output
standard input
PyPy 2
Python
1,100
train_007.jsonl
21e90debf5cf80907d1af47860f845fa
256 megabytes
["19 00\n255 1 100 1", "17 41\n1000 6 15 11"]
PASSED
import math hh, mm = map(int, raw_input().split(" ")) H, D, C, N = map(int, raw_input().split(" ")) result = 0 if hh >= 20: result = int(math.ceil(H/float(N))) * ((4*C)/5.0) else: rem = (20-hh-1)*60 + (60 - mm) now = int(math.ceil(H/float(N))) * C result = int(math.ceil((H+rem*D)/float(N))) * ((4*C)...
1521822900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["3", "1"]
7030441bd7f8f34b007f959698f4739d
NoteFor example $$$1$$$, by disturbing both blocks of sand on the first row from the top at the first and sixth columns from the left, and the block of sand on the second row from the top and the fourth column from the left, it is possible to have all the required amounts of sand fall in each column. It can be proved t...
This is the easy version of the problem. The difference between the versions is the constraints on $$$a_i$$$. You can make hacks only if all versions of the problem are solved.Little Dormi has recently received a puzzle from his friend and needs your help to solve it. The puzzle consists of an upright board with $$$n$$...
Print one non-negative integer, the minimum amount of operations needed to solve the puzzle.
The first line consists of two space-separated positive integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \cdot m \leq 400\,000$$$). Each of the next $$$n$$$ lines contains $$$m$$$ characters, describing each row of the board. If a character on a line is '.', the corresponding cell is empty. If it is '#', the cell contains a b...
standard output
standard input
PyPy 3
Python
2,500
train_091.jsonl
3e6964a55e920a90c55b94111a40cc66
512 megabytes
["5 7\n#....#.\n.#.#...\n#....#.\n#....##\n#.#....\n4 1 1 1 0 3 1", "3 3\n#.#\n#..\n##.\n3 1 1"]
PASSED
import io,os from collections import deque input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def find_scc(graph): # print(graph) SCC, S, P = [], [], [] depth = [0] * len(graph) stack = list(range(len(graph))) while stack: node = stack.pop() if node < 0: ...
1623598500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["1/6\n7/30"]
f4c743af8e8a1f90b74a27ca9bbc8b7b
null
Let's assume that v(n) is the largest prime number, that does not exceed n; u(n) is the smallest prime number strictly greater than n. Find .
Print t lines: the i-th of them must contain the answer to the i-th test as an irreducible fraction "p/q", where p, q are integers, q &gt; 0.
The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases. Each of the following t lines of the input contains integer n (2 ≤ n ≤ 109).
standard output
standard input
Python 3
Python
null
train_001.jsonl
86fdc66c4e439679e2f17b127c381fc3
256 megabytes
["2\n2\n3"]
PASSED
T = int( input() ) #for every prime x #(b-a)/ab #1/a-1/b MAX = 33000 bePrime = [0] * MAX; primNum = [] for j in range(2, MAX): if bePrime[j] == 0: primNum.append( j ) i = j while i < MAX: bePrime[i] = 1 i = i + j def isPrime( a ): for j in primNum: i...
1393428600
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["1\n2\n0\n1\n1\n1"]
fd85ebe1dc975a71c72fac7eeb944a4a
NoteThe first test case is explained in the statement.In the second test case, the answer is $$$2$$$, since you can choose the first and the sixth table.In the third test case, you cannot take any free table without violating the rules of the restaurant.
Polycarp and his friends want to visit a new restaurant. The restaurant has $$$n$$$ tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from $$$1$$$ to $$$n$$$ in the order from left to right. The state of the restaurant is described by a string of length $$$n$$$ wh...
For each test case output one integer — the number of tables that you can occupy so as not to violate the rules of the restaurant. If additional tables cannot be taken, then, obviously, you need to output $$$0$$$.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case starts with a line containing two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2\cdot 10^5$$$) — the number of tables in the restaurant and the minimum a...
standard output
standard input
Python 3
Python
1,300
train_000.jsonl
6d760167b3b033669bf2d67d5ed37ae9
256 megabytes
["6\n6 1\n100010\n6 2\n000000\n5 1\n10101\n3 1\n001\n2 2\n00\n1 1\n0"]
PASSED
import math for _ in range(int(input())): n,k = map(int, input().split()) s = input() #print(s[::-1]) if s.count('0') == len(s): print(math.ceil(len(s)/(k+1))) else: anz = 0 st = s.index('1') en = n - s[::-1].index('1') #print(st,en) if (st) > 0: ...
1592318100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["4 7\nDDDDDDD\nDABACAD\nDBABACD\nDDDDDDD", "4 50\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nABABABABABABABABABABABABABABABABABABABABABABABABAB\nBABABABABABABABABABABABABABABABABABABABABABABABABA\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", "7 7\nDDDDDDD\nDDDBDBD\nDDCDCDD\nDBDADBD\nDDCDCDD\nDBDBDDD\n...
637b0a757223521c44674bf1663a1114
NoteIn the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one.
As the boat drifts down the river, a wood full of blossoms shows up on the riverfront."I've been here once," Mino exclaims with delight, "it's breathtakingly amazing.""What is it like?""Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?" There are four kinds of flowers in the wood, A...
In the first line, output two space-separated integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 50$$$) — the number of rows and the number of columns in the grid respectively. Then output $$$n$$$ lines each consisting of $$$m$$$ consecutive English letters, representing one row of the grid. Each letter should be among ...
The first and only line of input contains four space-separated integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$1 \leq a, b, c, d \leq 100$$$) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively.
standard output
standard input
Python 3
Python
1,800
train_044.jsonl
1fa5609157b8023029804d9bc946d6d3
256 megabytes
["5 3 2 1", "50 50 1 1", "1 6 4 5"]
PASSED
a, b, c, d = map(int, input().split()) res = [['A'] * 50 for i in range(25)] + [['B'] * 50 for i in range(25)] a, b = a - 1, b - 1 for i in range(0, 24, 2): for j in range(0, 50, 2): if b > 0: b -= 1 res[i][j] = 'B' elif c > 0: c -= 1 res[i][j] = 'C' ...
1528724100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["1", "3", "0"]
d549f70d028a884f0313743c09c685f1
NoteIn the first sample you need to increase number 1 in cell (1, 1). Thus, the first row will consist of prime numbers: 2, 2, 3.In the second sample you need to increase number 8 in cell (1, 2) three times. Thus, the second column will consist of prime numbers: 11, 2.In the third sample you don't have to do anything a...
You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times.You are really curious about prime numbers. Let us remind you that a p...
Print a single integer — the minimum number of moves needed to get a prime matrix from the one you've got. If you've got a prime matrix, print 0.
The first line contains two integers n, m (1 ≤ n, m ≤ 500) — the number of rows and columns in the matrix, correspondingly. Each of the following n lines contains m integers — the initial matrix. All matrix elements are positive integers. All numbers in the initial matrix do not exceed 105. The numbers in the lines are...
standard output
standard input
PyPy 2
Python
1,300
train_015.jsonl
10407d83aa537c4dc72ef9684f52626e
256 megabytes
["3 3\n1 2 3\n5 6 1\n4 4 1", "2 3\n4 8 8\n9 2 9", "2 2\n1 3\n4 2"]
PASSED
n, m = [int(s) for s in raw_input().split()] A = [None] * n for i in range(n): row = [int(s) for s in raw_input().split()] A[i] = row Amax = max([i for a in A for i in a]) def generate_primes(Amax): Amax = max(Amax, 10) numbers = [i for i in range(100004)] mapping = {n: True for n in numbers} mapping[0]...
1360596600
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["1\n1", "2\n2 2", "3\n9 9 9"]
7c483498f497f4291e3d33375c0ebd53
NoteIn the first test, the number $$$1$$$ can be divided into $$$1$$$ digit equal to $$$1$$$.In the second test, there are $$$3$$$ partitions of the number $$$4$$$ into digits in which the number of different digits is $$$1$$$. This partitions are $$$[1, 1, 1, 1]$$$, $$$[2, 2]$$$ and $$$[4]$$$. Any of these partitions ...
Vasya has his favourite number $$$n$$$. He wants to split it to some non-zero digits. It means, that he wants to choose some digits $$$d_1, d_2, \ldots, d_k$$$, such that $$$1 \leq d_i \leq 9$$$ for all $$$i$$$ and $$$d_1 + d_2 + \ldots + d_k = n$$$.Vasya likes beauty in everything, so he wants to find any solution wit...
In the first line print one integer $$$k$$$ — the number of digits in the partition. Note that $$$k$$$ must satisfy the inequality $$$1 \leq k \leq n$$$. In the next line print $$$k$$$ digits $$$d_1, d_2, \ldots, d_k$$$ separated by spaces. All digits must satisfy the inequalities $$$1 \leq d_i \leq 9$$$. You should fi...
The first line contains a single integer $$$n$$$ — the number that Vasya wants to split ($$$1 \leq n \leq 1000$$$).
standard output
standard input
Python 3
Python
800
train_001.jsonl
6f66d62b6d28a5bccbfe768b70ecc33f
256 megabytes
["1", "4", "27"]
PASSED
n = int(input()) print(n) for i in range(n): print('1',end = ' ')
1548167700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["YES\nYES\nNO\nYES\nNO\nYES\nYES"]
b3978805756262e17df738e049830427
null
Recently Petya walked in the forest and found a magic stick.Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: If the chosen number $$$a$$$ is even, then the spell will turn it into $$$\frac{3a}{2}$$...
For the $$$i$$$-th test case print the answer on it — YES if Petya can get the number $$$y$$$ from the number $$$x$$$ using known spells, 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 positive answer).
The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 10^9$$$) — the current number and the number that Petya wants to get.
standard output
standard input
PyPy 3
Python
1,000
train_001.jsonl
3b162a0bdd1311e1760328ce3caa8709
256 megabytes
["7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234"]
PASSED
for _ in range(int(input())): x, y = map(int, input().split()) if x >= y: print("YES") elif x <= 3 and y > 3: print("NO") elif x <= 3 and x > 0 and x % 2: print("NO") else: print("YES")
1573655700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2\n0\n0"]
5de66fbb594bb317654366fd2290c4d3
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may er...
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
standard output
standard input
Python 3
Python
800
train_001.jsonl
d555ef4c641c7aef75cb0f6a09ab8b17
256 megabytes
["3\n010011\n0\n1111000"]
PASSED
for _ in range(int(input())): s = str(input()) n = len(s) print(s.strip('0').count('0'))
1581518100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
3 seconds
["0\n2", "2\n1 2 3"]
fb5c6182b9cad133d8b256f8e72e7e3b
null
The country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Overall there are n - 1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one.The council of the elders has recently decided to ch...
In the first line print the minimum number of roads to be inversed if the capital is chosen optimally. In the second line print all possible ways to choose the capital — a sequence of indexes of cities in the increasing order.
The first input line contains integer n (2 ≤ n ≤ 2·105) — the number of cities in Treeland. Next n - 1 lines contain the descriptions of the roads, one road per line. A road is described by a pair of integers si, ti (1 ≤ si, ti ≤ n; si ≠ ti) — the numbers of cities, connected by that road. The i-th road is oriented fro...
standard output
standard input
Python 3
Python
1,700
train_033.jsonl
ca3fcd27ca7dcc7ec54b29175d736498
256 megabytes
["3\n2 1\n2 3", "4\n1 4\n2 4\n3 4"]
PASSED
n=int(input()) t=[0]*(n+1) u,v=[[]for i in range(n+1)],[[]for i in range(n+1)] for i in range(n-1): x,y=map(int,input().split()) t[y]=1 u[x].append(y) v[y].append(x) d, s = u[1] + v[1], len(v[1]) for i in u[1]: t[i]=1 v[i].remove(1) for i in v[1]: t[i]=-1 u[i].remove(1) while d: b=d....
1346081400
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
3.5 seconds
["3\n1\n78975\n969\n109229059713337"]
2cc753baa293ee832054de494dee0f15
NoteIn the first test case, there are $$$3$$$ suitable triplets: $$$(1,2,3)$$$, $$$(1,3,4)$$$, $$$(2,3,4)$$$. In the second test case, there is $$$1$$$ suitable triplet: $$$(3,4,5)$$$.
We are sum for we are manySome NumberThis version of the problem differs from the next one only in the constraint on $$$t$$$. You can make hacks only if both versions of the problem are solved.You are given two positive integers $$$l$$$ and $$$r$$$.Count the number of distinct triplets of integers $$$(i, j, k)$$$ such ...
For each test case print one integer — the number of suitable triplets.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$\bf{1 \le t \le 5}$$$). Description of the test cases follows. The only line for each test case contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 2 \cdot 10^5$$$, $$$l + 2 \le r$$$).
standard output
standard input
PyPy 3-64
Python
2,300
train_102.jsonl
6f7932999e4e73ee4a63a3d557dc46e6
512 megabytes
["5\n\n1 4\n\n3 5\n\n8 86\n\n68 86\n\n6 86868"]
PASSED
import sys input = sys.stdin.buffer.readline # from collections import defaultdict, deque, Counter from math import gcd, lcm from functools import reduce # from itertools import accumulate, chain, islice, starmap # from operator import add, sub, mul, floordiv, truediv # def f(L,R,tup): def lcm3(tup): ...
1660401300
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
4 seconds
["26", "-1"]
ed0765719bfc3903701c0c14b7ad15c7
NoteThe best option in the first example is to take the first course $$$2$$$, the second course $$$1$$$, the drink $$$2$$$ and the dessert $$$1$$$.In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.There are $$$n_1$$$ different types of first courses Ivan can buy (the $$$i$$$-th of them costs $$$a_i$$$ coins), $$$n_2$$$ different types of second courses (the $$$i$$$-th of them costs $$$b_i$$$ ...
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print $$$-1$$$. Otherwise, print one integer — the minimum total cost of the dinner.
The first line contains four integers $$$n_1$$$, $$$n_2$$$, $$$n_3$$$ and $$$n_4$$$ ($$$1 \le n_i \le 150000$$$) — the number of types of first courses, second courses, drinks and desserts, respectively. Then four lines follow. The first line contains $$$n_1$$$ integers $$$a_1, a_2, \dots, a_{n_1}$$$ ($$$1 \le a_i \le ...
standard output
standard input
PyPy 3-64
Python
2,000
train_082.jsonl
7c28910e12ef8a4cf5693e0ead9c7784
512 megabytes
["4 3 2 1\n1 2 3 4\n5 6 7\n8 9\n10\n2\n1 2\n1 1\n2\n3 1\n3 2\n1\n1 1", "1 1 1 1\n1\n1\n1\n1\n1\n1 1\n0\n0"]
PASSED
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase from collections import defaultdict def main(): INF = int(1e18) n1, n2, n3, n4 = map(int, input().split()) aa = list(map(int, input().split())) bb = list(map(int, input().split())) cc = list(map(int, input().sp...
1613399700
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["01100", "110010"]
cac8ca5565e06021a44bb4388b5913a5
NoteIn the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions; in the segment $$$[1\ldots3]$$$, there are one rose and two lilies, so the beauty is equal to $$$1\cdot 2=2$$$; in the segment $$$[2\ldots4]$$$, there are one rose and two lilies, so ...
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.There are $$$n$$$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $$$i$$$-th position. Thus each of $$$n$$$ posit...
Print the string of $$$n$$$ characters. The $$$i$$$-th symbol should be «0» if you want to put a rose in the $$$i$$$-th position, otherwise «1» if you want to put a lily. If there are multiple answers, print any.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\leq n, m\leq 10^3$$$) — the number of flowers and visitors respectively. Each of the next $$$m$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1\leq l_i\leq r_i\leq n$$$), meaning that $$$i$$$-th visitor will visit all flowers from $$$l_i$$$ to $...
standard output
standard input
PyPy 3
Python
1,300
train_045.jsonl
c6b7241e65f70fd52aa17c746cd65c0b
256 megabytes
["5 3\n1 3\n2 4\n2 5", "6 3\n5 6\n1 4\n4 6"]
PASSED
n,m=map(int,input().split()) arr=["01" for _ in range(n//2)] if n%2==1: arr.append("0") print("".join(arr))
1530808500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["6 2", "0 1"]
91c3af92731cd7d406674598c0dcbbbc
null
This is yet another problem dealing with regular bracket sequences.We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. Y...
Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1".
The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106.
standard output
standard input
PyPy 3
Python
1,900
train_019.jsonl
d388222e448b2e918b109ea56eaf37fb
256 megabytes
[")((())))(()())", "))("]
PASSED
s = input() ans = dict() stack = [-1] res = 0 for i in range(len(s)): c = s[i] if c == ')' and stack[-1] != -1 and s[stack[-1]] == '(': stack.pop() ans[i-stack[-1]] = ans.get(i-stack[-1],0)+1 res = max(i-stack[-1], res) else: stack.append(i) if res not in ans.keys(): pr...
1269100800
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["YES\nYES\nNO\nNO\nYES"]
bc5fb5d6882b86d83e5c86f21d806a52
null
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has $$$a$$$ coins, Barbara has $$$b$$$ coins and Cerene has $$$c$$$ coins. Recently Polycarp has returned from the trip around the world and brought $$$n$$$ coins.He wants to distribute all these $$$n$$$ coins between his...
For each test case, print "YES" if Polycarp can distribute all $$$n$$$ coins between his sisters and "NO" otherwise.
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. Each test case is given on a new line and consists of four space-separated integers $$$a, b, c$$$ and $$$n$$$ ($$$1 \le a, b, c, n \le 10^8$$$) — the number of coins ...
standard output
standard input
Python 3
Python
800
train_000.jsonl
01617e2eb58b355f44572170c03385c0
256 megabytes
["5\n5 3 2 8\n100 101 102 105\n3 2 1 100000000\n10 20 15 14\n101 101 101 3"]
PASSED
t = int(input()) for _ in range(t): a,b,c,n = map(int, input().split()) m = max(a,b,c) for i in [a,b,c]: p = m-i i+=p n-=p if n%3==0 and n>=0: print("YES") else: print("NO")
1579703700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["8\n1 2\n4 3\n3 2\n4 1\n-1\n12\n3 2\n1 2\n3 1"]
f6e219176e846b16c5f52dee81601c8e
null
Hanh lives in a shared apartment. There are $$$n$$$ people (including Hanh) living there, each has a private fridge. $$$n$$$ fridges are secured by several steel chains. Each steel chain connects two different fridges and is protected by a digital lock. The owner of a fridge knows passcodes of all chains connected to i...
For each test case: If there is no solution, print a single integer $$$-1$$$. Otherwise, print a single integer $$$c$$$ — the minimum total cost. The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \ne v_i$$$), meaning that the $$$i$$$-th steel c...
Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 10$$$). Then the descriptions of the test cases follow. The first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$2 \le n \le 1000$$$, $$$1 \le m \le n$$$) — the number of people living in ...
standard output
standard input
PyPy 3
Python
1,100
train_008.jsonl
12f858c06350edeb93ea73cac79c9704
256 megabytes
["3\n4 4\n1 1 1 1\n3 1\n1 2 3\n3 3\n1 2 3"]
PASSED
t=int(input()) while t>0: n,m =map(int,input().split()) a=[int(x) for x in input().split()] if(n==2): print(-1) elif(n>m): print(-1) else: print(2*sum(a)) for _ in range(0,n): print(_+1,(_+1)%n+1) t-=1
1574174100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["12339\n0\n15\n54306\n999999995\n185\n999999998"]
2589e832f22089fac9ccd3456c0abcec
NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$.
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you nee...
For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists.
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y &lt; x;~ y \le n \le 10^9$$$). It can be shown tha...
standard output
standard input
Python 3
Python
800
train_001.jsonl
e6633cf1e52b2fbed347e696ec4d0ac9
256 megabytes
["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"]
PASSED
for i in range(int(input())): x,y,n=map(int,input().split()) for i in range(n//x,-1,-1): if x*i+y<=n: print(x*i+y) break
1593354900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["4\n6\n41\n4\n4\n2\n334"]
6422d76f71702e77808b1cc041962bb8
Note An example of a possible shortest path for the first test case. An example of a possible shortest path for the second test case.
There are three cells on an infinite 2-dimensional grid, labeled $$$A$$$, $$$B$$$, and $$$F$$$. Find the length of the shortest path from $$$A$$$ to $$$B$$$ if: in one move you can go to any of the four adjacent cells sharing a side; visiting the cell $$$F$$$ is forbidden (it is an obstacle).
Output $$$t$$$ lines. The $$$i$$$-th line should contain the answer for the $$$i$$$-th test case: the length of the shortest path from the cell $$$A$$$ to the cell $$$B$$$ if the cell $$$F$$$ is not allowed to be visited.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Before each test case, there is an empty line. Each test case contains three lines. The first one contains two integers $$$x_A, y_A$$$ ($$$1 \le x_A, y_A \le 1000$$$) — coordinate...
standard output
standard input
PyPy 3
Python
800
train_103.jsonl
fb09d658c0d2ebcb32039a913d5189bb
512 megabytes
["7\n\n1 1\n3 3\n2 2\n\n2 5\n2 1\n2 3\n\n1000 42\n1000 1\n1000 1000\n\n1 10\n3 10\n2 10\n\n3 8\n7 8\n3 7\n\n2 1\n4 1\n1 1\n\n1 344\n1 10\n1 1"]
PASSED
import sys from sys import stdin, stdout # input = stdin.readline # def invr(): # return(map(int,input().split())) def main(): t = int(stdin.readline()) a = b = f = [0]*2 for u in range(0,t): stdin.readline() # for i in range(0,2): a = stdin.readline(...
1625927700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES\n1\n2\n2\n3\n2\n2\n4\n1"]
b6608fadf1677e5cb78b6ed092a23777
null
One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.Help Timofey to color his rectangles in 4 different c...
Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color. Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 ≤ ci ≤ 4) — the color...
The first line contains single integer n (1 ≤ n ≤ 5·105) — the number of rectangles. n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 ≤ x1 &lt; x2 ≤ 109,  - 109 ≤ y1 &lt; y2 ≤ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-...
standard output
standard input
Python 3
Python
2,100
train_071.jsonl
f7999fe7238c083df300f8e2aff6fe10
256 megabytes
["8\n0 0 5 3\n2 -1 5 0\n-3 -4 2 -1\n-1 -1 2 0\n-3 0 0 5\n5 2 10 3\n7 -3 10 2\n4 -2 7 -1"]
PASSED
'''plan noticed that if both upperle ''' from sys import stdin, stdout # n = int(stdin.readline().rstrip()) # n = int(input()) all_lines = stdin.read().split('\n') stdout.write('YES\n') for line in all_lines[1:-1]: x1, y1, x2, y2 = (int(x) % 2 for x in line.split()) num = 2 * x2 + y2 + 1 # stdout.write...
1486042500
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
3 seconds
["3", "7"]
3fd58cef6d06400992088da9822ff317
NoteThe optimal way in the first example is $$$2 \to 1 \to 3$$$. The optimal way in the second example is $$$2 \to 4$$$.
The Fair Nut is going to travel to the Tree Country, in which there are $$$n$$$ cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent a car in the city $$$u$$$ and go by a simple path to city $$$v$$$. He hasn't ...
Print one number — the maximum amount of gasoline that he can have at the end of the path.
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 3 \cdot 10^5$$$) — the number of cities. The second line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$0 \leq w_{i} \leq 10^9$$$) — the maximum amounts of liters of gasoline that Nut can buy in cities. Each of the next $$$n - 1$$$ lines desc...
standard output
standard input
Python 3
Python
1,800
train_048.jsonl
e4721c15cbbdb067e6b3225681791dd9
256 megabytes
["3\n1 3 3\n1 2 2\n1 3 2", "5\n6 3 2 5 0\n1 2 10\n2 3 3\n2 4 1\n1 5 1"]
PASSED
from collections import deque def recurse(x,d,w,parent,v,vb): best = 0 bestt = 0 ans = 0 for t in d[x]: node = t[0] if node == parent: continue weight = int(w[node-1])-t[1] ans = max(ans,v[node]) tot = weight+vb[node] if tot > best: ...
1544459700
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["2\n1 0", "-1", "3\n9 4 0"]
6f8de802d2b6b0f48f2be0531b3ac8d4
NoteIn the first example, Gorf is on the bottom of the well and jump to the height $$$1$$$ meter below ground level. After that he slip down by meter and stays on height $$$2$$$ meters below ground level. Now, from here, he can reach ground level in one jump.In the second example, Gorf can jump to one meter below groun...
Frog Gorf is traveling through Swamp kingdom. Unfortunately, after a poor jump, he fell into a well of $$$n$$$ meters depth. Now Gorf is on the bottom of the well and has a long way up.The surface of the well's walls vary in quality: somewhere they are slippery, but somewhere have convenient ledges. In other words, if ...
If Gorf can't reach ground level, print $$$-1$$$. Otherwise, firstly print integer $$$k$$$ — the minimum possible number of jumps. Then print the sequence $$$d_1,\,d_2,\,\ldots,\,d_k$$$ where $$$d_j$$$ is the depth Gorf'll reach after the $$$j$$$-th jump, but before he'll slip down during the break. Ground level is equ...
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 300\,000$$$) — the depth of the well. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le i$$$), where $$$a_i$$$ is the maximum height Gorf can jump from $$$i$$$ meters below ground level. The third line contains $$$n$$...
standard output
standard input
PyPy 3-64
Python
1,900
train_092.jsonl
fbae864d06746c3b0087d32e74821964
512 megabytes
["3\n0 2 2\n1 1 0", "2\n1 1\n1 0", "10\n0 1 2 3 5 5 6 7 8 5\n9 8 7 1 5 4 3 2 0 0"]
PASSED
from sys import stdin, stdout import sys import heapq from collections import defaultdict import math import bisect import io, os # from cffi import FFI import copy import itertools # for interactive problem # n = int(stdin.readline()) # print(x, flush=True) input = io.BytesIO(os.read(0, os.fstat(0).st...
1635143700
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["0.5000000000", "1.3000000000"]
1df8aad60e5dff95bffb9adee5f8c460
null
One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize — big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The target...
Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10 - 6.
The first line contains integer n (1 ≤ n ≤ 1000) — amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti — integers,  - 1000 ≤ xi, yi ≤ 1000, 0 ≤ ti ≤ 109, real number pi is given with no more than 6 digits ...
standard output
standard input
Python 3
Python
1,800
train_007.jsonl
1afcb8d7042fea594f7eff8931e0bc4b
256 megabytes
["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7"]
PASSED
import heapq def is_reachable(from_state, target): return (from_state[0]-target[0])**2 + (from_state[1]-target[1])**2 <= (target[2] - from_state[2])**2 num_iter = int(input()) targets = sorted([list(map(float, input().strip().split(' '))) for dummy in range(0, num_iter)], key=lambda single_target: single_tar...
1285340400
[ "probabilities" ]
[ 0, 0, 0, 0, 0, 1, 0, 0 ]
1 second
["0\n1\n342"]
0690e2df87f60e5be34505d9e2817032
NoteIn the image below you can see the example solutions for the first two test cases. Chosen days off are shown in purple. Working segments are underlined in green.In test case $$$1$$$, the only options for days off are days $$$2$$$, $$$3$$$, and $$$4$$$ (because $$$1$$$ and $$$5$$$ are next to day $$$n$$$). So the on...
Your working week consists of $$$n$$$ days numbered from $$$1$$$ to $$$n$$$, after day $$$n$$$ goes day $$$1$$$ again. And $$$3$$$ of them are days off. One of the days off is the last day, day $$$n$$$. You have to decide when the other two are.Choosing days off, you pursue two goals: No two days should go one after ...
For each test case, output one integer — the maximum possible obtained value.
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains the integer $$$n$$$ ($$$6 \le n \le 10^9$$$).
standard output
standard input
Python 3
Python
800
train_098.jsonl
0a7aeb817beb26231dd6f9b1cac9c774
256 megabytes
["3\n\n6\n\n10\n\n1033"]
PASSED
t = int(input()) for i in range(t): n = int(input()) print ((n-6)//3)
1664721300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["YES\nNO\nNO\nYES", "YES\nNO\nYES\nYES"]
9c84eb518c273942650c7262e5d8b45f
NoteThe cornfield from the first example is pictured above. Grasshoppers with indices $$$1$$$ (coordinates $$$(2, 4)$$$) and $$$4$$$ (coordinates $$$(4, 5)$$$) are inside the cornfield.The cornfield from the second example is pictured below. Grasshoppers with indices $$$1$$$ (coordinates $$$(4, 4)$$$), $$$3$$$ (coordin...
Vasya owns a cornfield which can be defined with two integers $$$n$$$ and $$$d$$$. The cornfield can be represented as rectangle with vertices having Cartesian coordinates $$$(0, d), (d, 0), (n, n - d)$$$ and $$$(n - d, n)$$$. An example of a cornfield with $$$n = 7$$$ and $$$d = 2$$$. Vasya also knows that there ar...
Print $$$m$$$ lines. The $$$i$$$-th line should contain "YES" if the position of the $$$i$$$-th grasshopper lies inside or on the border of the cornfield. Otherwise the $$$i$$$-th line should contain "NO". You can print each letter in any case (upper or lower).
The first line contains two integers $$$n$$$ and $$$d$$$ ($$$1 \le d &lt; n \le 100$$$). The second line contains a single integer $$$m$$$ ($$$1 \le m \le 100$$$) — the number of grasshoppers. The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$0 \le x_i, y_i \le n$$$) — position ...
standard output
standard input
PyPy 3
Python
1,100
train_000.jsonl
3efa832d96b478d2c89d224af50d44e6
256 megabytes
["7 2\n4\n2 4\n4 1\n6 3\n4 5", "8 7\n4\n4 4\n2 8\n8 1\n6 1"]
PASSED
#------------------------------what is this I don't know....just makes my mess faster-------------------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer ...
1537707900
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
2 seconds
["7\n6\n1000\n5"]
ee8ca9b2c6104d1ff9ba1fc39e9df277
NoteThe first test case is explained in the statement.In the second test case, the maximum score can be achieved by choosing $$$i = 1$$$.In the third test case, the maximum score can be achieved by choosing $$$i = 2$$$.In the fourth test case, the maximum score can be achieved by choosing $$$i = 1$$$.
Polycarp found under the Christmas tree an array $$$a$$$ of $$$n$$$ elements and instructions for playing with it: At first, choose index $$$i$$$ ($$$1 \leq i \leq n$$$) — starting position in the array. Put the chip at the index $$$i$$$ (on the value $$$a_i$$$). While $$$i \leq n$$$, add $$$a_i$$$ to your score and...
For each test case, output on a separate line one number — the maximum score that Polycarp can get by playing the game on the corresponding array according to the instruction from the statement. Note that Polycarp chooses any starting position from $$$1$$$ to $$$n$$$ in such a way as to maximize his result.
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of the array $$$a$$$. The next line contains $$$n$$$ integers $$$a_1, a_2, \dot...
standard output
standard input
PyPy 3-64
Python
1,100
train_090.jsonl
46f0e18c29c4fe33381add15b7217029
256 megabytes
["4\n5\n7 3 1 2 3\n3\n2 1 4\n6\n2 1000 2 3 995 1\n5\n1 1 1 1 1"]
PASSED
if __name__ == '__main__': t = int(input()) for _ in range(t): n = int(input()) nums = list(map(int, input().split())) result, max_found = [], -float('inf') for x in nums: result.append(x) max_found = max(max_found, x) parent = {i:i for i in rang...
1609770900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["8", "1", "25", "29"]
373412134b2afd00618b19e4bf652d26
NoteIn the first example the diameter of the given tree is already less than or equal to $$$k$$$. Thus, you can choose any set of edges to remove and the resulting trees will have diameter less than or equal to $$$k$$$. There are $$$2^3$$$ sets, including the empty one.In the second example you have to remove the only ...
You are given an integer $$$k$$$ and an undirected tree, consisting of $$$n$$$ vertices.The length of a simple path (a path in which each vertex appears at most once) between some pair of vertices is the number of edges in this path. A diameter of a tree is the maximum length of a simple path between all pairs of verti...
Print a single integer — the number of valid sets of edges modulo $$$998\,244\,353$$$.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 5000$$$, $$$0 \le k \le n - 1$$$) — the number of vertices of the tree and the maximum allowed diameter, respectively. Each of the next $$$n-1$$$ lines contains a description of an edge: two integers $$$v$$$ and $$$u$$$ ($$$1 \le v, u \le n$$$, $$...
standard output
standard input
PyPy 3
Python
2,400
train_104.jsonl
f5750a30e3e6a7bd3b68cdde1521e874
256 megabytes
["4 3\n1 2\n1 3\n1 4", "2 0\n1 2", "6 2\n1 6\n2 4\n2 6\n3 6\n5 6", "6 3\n1 2\n1 5\n2 3\n3 4\n5 6"]
PASSED
import sys from collections import deque input = lambda :sys.stdin.buffer.readline() mi = lambda :map(int,input().split()) li = lambda :list(mi()) mod = 998244353 N,K = mi() edge = [[] for i in range(N)] for _ in range(N-1): a,b = mi() edge[a-1].append(b-1) edge[b-1].append(a-1) parent =...
1616079000
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["2", "1", "-1", "3"]
20e13f21610c5614310bcd764662231c
NoteImagine we have string a = a1a2a3...a|a|, where |a| is the length of string a, and ai is the ith letter of the string. We will call string alal + 1al + 2...ar (1 ≤ l ≤ r ≤ |a|) the substring [l, r] of the string a. The substring [l, r] is unique in a if and only if there is no pair l1, r1 such that l1 ≠ l and the s...
Police headquarter is monitoring signal on different frequency levels. They have got two suspiciously encoded strings s1 and s2 from two different frequencies as signals. They are suspecting that these two strings are from two different criminals and they are planning to do some evil task.Now they are trying to find a ...
Print the length of the smallest common unique substring of s1 and s2. If there are no common unique substrings of s1 and s2 print -1.
The first line of input contains s1 and the second line contains s2 (1 ≤ |s1|, |s2| ≤ 5000). Both strings consist of lowercase Latin letters.
standard output
standard input
Python 2
Python
2,200
train_045.jsonl
d03cd113f1d50fdebcc833d4e601fe15
512 megabytes
["apple\npepperoni", "lover\ndriver", "bidhan\nroy", "testsetses\nteeptes"]
PASSED
import sys import bisect class suffixautomaton: def __init__(self, words, symbol = "#"): self.words = [] self.sequence = "" self.terminal = set() self.nCounters = len(words) self.states = [[0, None, {}]] self.counters = [[0] * self.nCounters] for w in words:...
1399044600
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["3.650281539872885\n18.061819283610362\n32.052255376143336"]
ba27ac62b84705d80fa580567ab64c3b
NoteIn the first test case, the miners are at $$$(0,1)$$$ and $$$(0,-1)$$$, while the diamond mines are at $$$(1,0)$$$ and $$$(-2,0)$$$. If you arrange the miners to get the diamond mines in the way, shown in the picture, you can get the sum of the energy $$$\sqrt2 + \sqrt5$$$.
Diamond Miner is a game that is similar to Gold Miner, but there are $$$n$$$ miners instead of $$$1$$$ in this game.The mining area can be described as a plane. The $$$n$$$ miners can be regarded as $$$n$$$ points on the y-axis. There are $$$n$$$ diamond mines in the mining area. We can regard them as $$$n$$$ points on...
For each test case, print a single real number — the minimal sum of energy that should be spent. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-9}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a -...
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10$$$) — 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 \le n \le 10^5$$$) — the number of miners and mines. Each of th...
standard output
standard input
Python 3
Python
1,200
train_085.jsonl
1652e275a552117ec7b198955d3cc277
256 megabytes
["3\n2\n0 1\n1 0\n0 -1\n-2 0\n4\n1 0\n3 0\n-5 0\n6 0\n0 3\n0 1\n0 2\n0 4\n5\n3 0\n0 4\n0 -3\n4 0\n2 0\n1 0\n-3 0\n0 -10\n0 -2\n0 -10"]
PASSED
mas = list(map(int, input().split())) t = mas[0] for j in range(t): mas = list(map(int, input().split())) n = mas[0] lst1 = [0 for i in range(n)] lst2 = [0 for i in range(n)] i1 = 0 i2 = 0 for i in range(2 * n): mas = list(map(int, input().split())) if (mas[0...
1615377900
[ "geometry", "math" ]
[ 0, 1, 0, 1, 0, 0, 0, 0 ]
1 second
["4\n14\n26\n48"]
8775da9b78d8236c4606d150df450952
NoteIn the second test case: The best partition for the subsegment $$$[2, 0, 1]$$$: $$$[2], [0, 1]$$$. The cost of this partition equals to $$$2 + \operatorname{mex}(\{2\}) + \operatorname{mex}(\{0, 1\}) = 2 + 0 + 2 = 4$$$. The best partition for the subsegment $$$[2, 0]$$$: $$$[2], [0]$$$. The cost of this partitio...
Let there be an array $$$b_1, b_2, \ldots, b_k$$$. Let there be a partition of this array into segments $$$[l_1; r_1], [l_2; r_2], \ldots, [l_c; r_c]$$$, where $$$l_1 = 1$$$, $$$r_c = k$$$, and for any $$$2 \leq i \leq c$$$ holds that $$$r_{i-1} + 1 = l_i$$$. In other words, each element of the array belongs to exactly...
For each test case print a single integer — the answer to the problem.
The input contains several test cases. The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 30$$$) — the number of test cases. The first line for each test case contains one integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the length of the array. The second line contains a sequence of integers $$$a_1, a_2, \ldots,...
standard output
standard input
Python 3
Python
1,100
train_090.jsonl
9068b9ec11a55bab8da6fbd3cfb2372d
256 megabytes
["4\n2\n1 2\n3\n2 0 1\n4\n2 0 5 1\n5\n0 1 1 0 1"]
PASSED
def max(array): count = 0 for i in array: if i==0: count +=2 else: count +=1 return count for line in [*open(0)][2::2]: array = list(map(int,line.split())) maximum = 0 for i in range(len(array)): for j in range(i +1,len(array)+1):...
1644676500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1/2", "0/1"]
7afa48f3411521ce49ba9595b0bef079
null
As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. Then at one turn Barney swaps the cup in the middle with a...
In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7.
The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array.
standard output
standard input
Python 3
Python
2,000
train_009.jsonl
c629b9e68106c7576bc6fbddfd056d70
256 megabytes
["1\n2", "3\n1 1 1"]
PASSED
k = int(input()) MOD = 10 ** 9 + 7 antithree = pow(3, MOD - 2, MOD) antitwo = pow(2, MOD - 2, MOD) power = 1 parity = False for t in map(int, input().split()): power *= t power %= MOD - 1 if t % 2 == 0: parity = True q = pow(2, power, MOD) * antitwo q %= MOD if parity: p = (q + 1) * antithree ...
1468514100
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["1\n2", "2\n3 4", "-1"]
5bb8347fd91f00245c3acb4a5eeaf17f
null
You are given an undirected graph that consists of n vertices and m edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges with an endpoint in this vertex change the color to blue, while all blue edge...
If there is no way to make the colors of all edges equal output  - 1 in the only line of the output. Otherwise first output k — the minimum number of moves required to achieve the goal, then output k integers a1, a2, ..., ak, where ai is equal to the index of the vertex that should be used at the i-th move. If there ar...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the number of vertices and edges, respectively. The following m lines provide the description of the edges, as the i-th of them contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the indices of the vertices connected by the i-th e...
standard output
standard input
Python 3
Python
2,200
train_002.jsonl
aecfdaee4114ac7d34901855415dcc66
256 megabytes
["3 3\n1 2 B\n3 1 R\n3 2 B", "6 5\n1 3 R\n2 3 R\n3 4 B\n4 5 R\n4 6 R", "4 5\n1 2 R\n1 3 R\n2 3 B\n3 4 B\n1 4 B"]
PASSED
from collections import deque n, m = map(int, input().split()) adj = [[] for i in range(n)] for i in range(m): u, v, c = input().split() u, v = int(u)-1, int(v)-1 adj[u].append((v, c)) adj[v].append((u, c)) visited = S = T = None def bfs(i, k): q = deque([(i, 0)]) while q: u, p = q...
1460729700
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["0\n3\n11\n72\n63244"]
d78cd4a06fb566d58275e92f976166f2
null
Initially, you have the array $$$a$$$ consisting of one element $$$1$$$ ($$$a = [1]$$$).In one move, you can do one of the following things: Increase some (single) element of $$$a$$$ by $$$1$$$ (choose some $$$i$$$ from $$$1$$$ to the current length of $$$a$$$ and increase $$$a_i$$$ by one); Append the copy of some (...
For each test case, print the answer: the minimum number of moves required to obtain the array with the sum at least $$$n$$$.
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the lower bound on the sum of the array.
standard output
standard input
Python 3
Python
1,100
train_005.jsonl
448b264d1586de8f2cc29330307ee72c
256 megabytes
["5\n1\n5\n42\n1337\n1000000000"]
PASSED
import math t=int(input()) while t: t-=1 n=int(input()) if n==1 : print(0) elif n==2: print(1) else: mx=n c=0 for i in range(max(2,round(math.sqrt(n))-1),round(math.sqrt(n))+1): tem=i-1+math.ceil((n-i)/i) mx=min(tem,mx) prin...
1601280300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2\n1212212", "0\n1212212", "2\n1212212"]
ad3f798f00cc9f3e3c9df932c2459ca3
NoteExplanation for the first sample: vertices $$$2$$$ and $$$5$$$ are Oddyseys. Explanation for the third sample: vertices $$$1$$$ and $$$6$$$ are Oddyseys.
Lee was planning to get closer to Mashtali's heart to proceed with his evil plan(which we're not aware of, yet), so he decided to beautify Mashtali's graph. But he made several rules for himself. And also he was too busy with his plans that he didn't have time for such minor tasks, so he asked you for help.Mashtali's g...
In the first line print a single integer — the maximum beauty of the graph Lee can achieve. In the second line print a string of length $$$m$$$ consisting of $$$1$$$s and $$$2$$$s — directions of the edges. If you decide to direct the $$$i$$$-th edge from vertex $$$u_i$$$ to vertex $$$v_i$$$, $$$i$$$-th character of th...
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n \le 10^5;\; 1 \le m \le 10^5)$$$ — the numbers of vertices and edges in the graph. The $$$i$$$-th line of the following $$$m$$$ lines contains three integers $$$u_i$$$, $$$v_i$$$ and $$$w_i$$$ $$$( 1 \le u_i , v_i \le n;\; u_i \neq v_i;\; \bf{w_i \in ...
standard output
standard input
PyPy 3-64
Python
3,000
train_085.jsonl
7b448deff90878934c7945b456799622
256 megabytes
["6 7\n1 2 1\n1 3 2\n2 3 2\n1 4 1\n4 5 1\n2 5 2\n2 6 2", "6 7\n1 2 2\n1 3 2\n2 3 2\n1 4 2\n4 5 2\n2 5 2\n2 6 2", "6 7\n1 2 1\n1 3 1\n2 3 1\n1 4 1\n4 5 1\n2 5 1\n2 6 1"]
PASSED
import sys input = sys.stdin.readline n, m = map(int, input().split()) adj1 = [[] for _ in range(n)] adj2 = [[] for _ in range(n)] edges = [] outv = 0 outvv = 0 deg1 = [0] * n deg2 = [0] * n parO = [] parP = [] for e in range(m): u, v, w = map(int, input().split()) u -= 1 v -= 1 ...
1637678100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["-1\n2\n2\n1\n2\n0"]
8e7c0b703155dd9b90cda706d22525c9
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the seco...
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ is picked, which is then used to perform one of the following operations: (note, that for each operation yo...
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants...
standard output
standard input
PyPy 3-64
Python
800
train_107.jsonl
e6592197408f88075d44bee115a12e51
256 megabytes
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
PASSED
for _ in range(int(input())): a,b=map(int,input().split()) if a==0 and b==0: print(0) elif a==b: print(1) elif abs(a-b)&1==0: print(2) else: print(-1)
1630247700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]