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
["1 2 3", "1 3 5"]
0d3ac2472990aba36abee156069b1088
NoteIn the first sample, we can print the three indices in any order.In the second sample, we have the following picture. Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.In the evening Noku is going to take a look at the night sky. He would like to find three dis...
Print three distinct integers on a single lineΒ β€” the indices of the three points that form a triangle that satisfies the conditions stated in the problem. If there are multiple possible answers, you may print any of them.
The first line of the input contains a single integer n (3 ≀ n ≀ 100 000). Each of the next n lines contains two integers xi and yi ( - 109 ≀ xi, yi ≀ 109). It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
standard output
standard input
Python 2
Python
1,600
train_005.jsonl
167eb56cb62429854cc283e46a830e66
256 megabytes
["3\n0 1\n1 0\n1 1", "5\n0 0\n0 2\n2 0\n2 2\n1 1"]
PASSED
def dis(x,y): return x**2+y**2 def check(a,b,c): if (c[1]-b[1])*(b[0]-a[0])==(b[1]-a[1])*(c[0]-b[0]): return True return False def solve(): n=input() points=[] dist=[] for x in xrange(n): points.append(map(int,raw_input().split())) dist.append(dis(points[-1][0],poin...
1454087400
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
2 seconds
["59\n778\n148999\n999999920999999999"]
e25e44b8f300d6be856df50bff8ff244
null
In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represe...
For each test case, print one integerΒ β€” the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a...
standard output
standard input
PyPy 3-64
Python
1,400
train_108.jsonl
7621a7f4622f0e83f253f18bf4f2a2e5
256 megabytes
["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"]
PASSED
import sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log from collections import defaultdict as dd from bisect import bisect_left as bl, bisect_right as br from collections import Counter from collections import defaultdict as dd # sys.setrecursionlimit(100000...
1635518100
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
2 seconds
["3\nh e\nl o\nd z", "0", "-1"]
b03895599bd578a83321401428e277da
null
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. In...
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print Β«-1Β» (without quotes). Otherwise, the first line of output should contain the only integer k (k β‰₯ 0)Β β€” the number of pairs of keys that should be swapped. The following k lines s...
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
standard output
standard input
Python 3
Python
1,500
train_006.jsonl
0c11657163d91c43516d88667f54b293
256 megabytes
["helloworld\nehoolwlroz", "hastalavistababy\nhastalavistababy", "merrychristmas\nchristmasmerry"]
PASSED
a,b = input(), input() s = "" for i in range(len(a)): x, y = str(max(a[i], b[i])), str(min(a[i], b[i])) if (x in s and x+y not in s) or (y in s and x+y not in s): print('-1') exit() if x+y not in s: s +=" " + x + y lis = [] for i in s.split(): ...
1482656700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
9 seconds
["YES\nabc", "NO", "YES\nbaaaaaaaaa", "NO"]
8c33618363cacf005e4735cecfdbe2eb
null
You are given a tree consisting of $$$n$$$ vertices, and $$$q$$$ triples $$$(x_i, y_i, s_i)$$$, where $$$x_i$$$ and $$$y_i$$$ are integers from $$$1$$$ to $$$n$$$, and $$$s_i$$$ is a string with length equal to the number of vertices on the simple path from $$$x_i$$$ to $$$y_i$$$.You want to write a lowercase Latin let...
If there is no way to meet the conditions on all triples, print NO. Otherwise, print YES in the first line, and a string of $$$n$$$ lowercase Latin letters in the second line; the $$$i$$$-th character of the string should be the letter you write on the $$$i$$$-th vertex. If there are multiple answers, print any of them...
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 4 \cdot 10^5$$$; $$$1 \le q \le 4 \cdot 10^5$$$) β€” the number of vertices in the tree and the number of triples, respectively. Then $$$n - 1$$$ lines follow; the $$$i$$$-th of them contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \...
standard output
standard input
PyPy 3-64
Python
2,600
train_110.jsonl
c8bbe3b1d97d762a0751ebd67a89958b
1024 megabytes
["3 2\n2 3\n2 1\n2 1 ab\n2 3 bc", "3 2\n2 3\n2 1\n2 1 ab\n2 3 cd", "10 10\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 2 ab\n1 3 ab\n1 4 ab\n1 5 ab\n1 6 ab\n1 7 ab\n1 8 ab\n1 9 ab\n1 10 ab\n10 2 aba", "10 10\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 2 ab\n1 3 ab\n1 4 aa\n1 5 ab\n1 6 ab\n1 7 ab\n1 8 ab\n1 9 a...
PASSED
class _csr: def __init__(self, n, edges): self.start = [0] * (n + 1) self.elist = [0] * len(edges) for v, _ in edges: self.start[v + 1] += 1 for i in range(1, n + 1): self.start[i] += self.start[i - 1] counter = self.start.copy() for v...
1647960300
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
2 seconds
["6", "92", "17", "23"]
d1dced03a12dd64b8c7519bfb12f9c82
NoteIn the first example any partition yields 6 as the sum.In the second example one of the optimal partitions is [1, 1], [10, 10, 10, 10, 10, 10, 9, 10, 10, 10] with the values 2 and 90 respectively.In the third example one of the optimal partitions is [2, 3], [6, 4, 5, 7], [1] with the values 3, 13 and 1 respectively...
Since you are the best Wraith King, Nizhniy Magazin Β«MirΒ» at the centre of Vinnytsia is offering you a discount.You are given an array a of length n and an integer c. The value of some array b of length k is the sum of its elements except for the smallest. For example, the value of the array [3, 1, 6, 5, 2] with c = 2...
Output a single integer Β β€” the smallest possible sum of values of these subarrays of some partition of a.
The first line contains integers n and c (1 ≀ n, c ≀ 100 000). The second line contains n integers ai (1 ≀ ai ≀ 109)Β β€” elements of a.
standard output
standard input
Python 3
Python
2,000
train_040.jsonl
3361dccd6f73a60c04d5b1332a888450
256 megabytes
["3 5\n1 2 3", "12 10\n1 1 10 10 10 10 10 10 9 10 10 10", "7 2\n2 3 6 4 5 7 1", "8 4\n1 3 4 5 5 3 4 1"]
PASSED
from heapq import * n, c = map(int, input().split()) a = list(map(int, input().split())) if c > n: print(sum(a)) exit() b = [0] * n s = 0 h = [] for i in range(n): s = s + a[i] - a[i-c] if i + 1 > c else s + a[i] heappush(h, (a[i],i)) if i + 1 < c: b[i] = s else: while h[0][1] <= i-c: heappop(h) v1 =...
1519464900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["60\n200\n65\n60\n120600000\n10\n100\n200\n100\n7"]
83af7209bb8a81cde303af5d207c2749
NoteIn the first case $$$n = 6$$$, $$$m = 11$$$. We cannot get a number with two zeros or more at the end, because we need to increase the price $$$50$$$ times, but $$$50 &gt; m = 11$$$. The maximum price multiple of $$$10$$$ would be $$$6 \cdot 10 = 60$$$.In the second case $$$n = 5$$$, $$$m = 43$$$. The maximum price...
Inflation has occurred in Berlandia, so the store needs to change the price of goods.The current price of good $$$n$$$ is given. It is allowed to increase the price of the good by $$$k$$$ times, with $$$1 \le k \le m$$$, k is an integer. Output the roundest possible new price of the good. That is, the one that has the ...
For each test case, output on a separate line the roundest integer of the form $$$n \cdot k$$$ ($$$1 \le k \le m$$$, $$$k$$$Β β€” an integer). If there are several possible variants, output the one in which the new price (value $$$n \cdot k$$$) is maximal. If it is impossible to get a more rounded price, output $$$n \cdot...
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€”the number of test cases in the test. Each test case consists of one line. This line contains two integers: $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^9$$$). Where $$$n$$$ is the old price of the good, and the number $$$m$$$ means that you can in...
standard output
standard input
PyPy 3-64
Python
1,400
train_086.jsonl
92b6e6b90e0f639998c50c25c9d752f1
256 megabytes
["10\n\n6 11\n\n5 43\n\n13 5\n\n4 16\n\n10050 12345\n\n2 6\n\n4 30\n\n25 10\n\n2 81\n\n1 7"]
PASSED
#I = lambda: [int(i) for i in input().split()] #import io, os, sys #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from collections import Counter,defaultdict,deque #from heapq import heappush,heappop,heapify import sys import math import bisect def lcm(a,b): return ((a*b)//math.gcd(a,b)...
1668782100
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
2 seconds
["2\n1 2\n2 1\n3\n1 2 3\n3 2 1\n3 1 2"]
02bdd12987af6e666d4283f075f73725
null
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ such that each integer appears in it exactly once.Let the fixedness of a permutation $$$p$$$ be the number of fixed points in itΒ β€” the number of positions $$$j$$$ such that $$$p_j = j$$$, where $$$p_j$$$ is the $$$j$$$-th element of the p...
For each testcase, first, print the length of a permutation chain $$$k$$$. Then print $$$k$$$ permutations $$$a_1, a_2, \dots, a_k$$$. $$$a_1$$$ should be an identity permutation of length $$$n$$$ ($$$[1, 2, \dots, n]$$$). For each $$$i$$$ from $$$2$$$ to $$$k$$$, $$$a_i$$$ should be obtained by swapping two elements i...
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 99$$$)Β β€” the number of testcases. The only line of each testcase contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$)Β β€” the required length of permutations in the chain.
standard output
standard input
Python 3
Python
800
train_109.jsonl
bc346aef51ae35693acf3a0678142daa
256 megabytes
["2\n\n2\n\n3"]
PASSED
# -*- coding: utf-8 -*- """ Created on Thu Aug 18 23:35:19 2022 @author: khale """ t = int(input()) for i in range(t): n = int(input()) print(n) L = [int(x) for x in range(1,n+1)] for i in range(n-1,-1,-1): for j in range(n): print(L[j],end = ' ') print() ...
1659623700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["roar", "db", "-1"]
b5d0870ee99e06e8b99c74aeb8e81e01
null
Limak is a little polar bear. He likes nice strings β€” strings of length n, consisting of lowercase English letters only.The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and .Also, the distance between two nice strings is defined as the sum of distance...
If there is no string satisfying the given conditions then print "-1" (without the quotes). Otherwise, print any nice string s' that .
The first line contains two integers n and k (1 ≀ n ≀ 105, 0 ≀ k ≀ 106). The second line contains a string s of length n, consisting of lowercase English letters.
standard output
standard input
Python 3
Python
1,300
train_029.jsonl
ca227e5919ae5760780c48c4b1f2fac4
256 megabytes
["4 26\nbear", "2 7\naf", "3 1000\nhey"]
PASSED
import sys n, k = map(int, input().split()) line = list(input()) for i in range(n): if ord('z') - ord(line[i]) >= ord(line[i]) - ord('a'): s = ord('z') - ord(line[i]) if s >= k: line[i] = chr(ord(line[i])+k) print(''.join(line)) sys.exit() else: ...
1455894000
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["1\n2\n0"]
0d8b5bd6c118f98d579da8c79482cfa7
NoteOn the first operation, a new string "0110" is created. For k = 1 the two possible binary strings of length k are "0" and "1", they are substrings of the new string. For k = 2 and greater there exist strings of length k that do not appear in this string (for k = 2 such string is "00"). So the answer is 1.On the sec...
You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed, on each of them you concatenate two existing strings into a new one. On the i-th operation the concatenation saisbi is saved into a new string sn + i (the operations are numbered starting from 1). After each operation ...
Print m lines, each should contain one integerΒ β€” the answer to the question after the corresponding operation.
The first line contains single integer n (1 ≀ n ≀ 100)Β β€” the number of strings. The next n lines contain strings s1, s2, ..., sn (1 ≀ |si| ≀ 100), one per line. The total length of strings is not greater than 100. The next line contains single integer m (1 ≀ m ≀ 100)Β β€” the number of operations. m lines follow, each of ...
standard output
standard input
Python 3
Python
2,200
train_000.jsonl
9758856c8d15338d2e1bde5c057921ba
256 megabytes
["5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4"]
PASSED
from sys import stdin, stdout K = 20 def findAllStrings(s): n = len(s) sDict = {} for i in range(1,K+1): sDict[i]=set() for x in range(n-i+1): sDict[i].add(s[x:x+i]) return sDict n = int(stdin.readline().rstrip()) stringDicts = [] stringEnd = [] stringBegin = [] for i in ...
1507187100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["ac\nf\nb"]
83a665723ca4e40c78fca20057a0dc99
null
I, Fischl, Prinzessin der Verurteilung, descend upon this land by the call of fate an β€” Oh, you are also a traveler from another world? Very well, I grant you permission to travel with me.It is no surprise Fischl speaks with a strange choice of words. However, this time, not even Oz, her raven friend, can interpret her...
For each test case, output the MEX of the string on a new line.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$)Β β€” the length of the word. The second line for each test case contain...
standard output
standard input
PyPy 3-64
Python
1,200
train_094.jsonl
5afaefde3eecdb9de18fd9dbac541ced
256 megabytes
["3\n28\nqaabzwsxedcrfvtgbyhnujmiklop\n13\ncleanairactbd\n10\naannttoonn"]
PASSED
t=int(input()) for p in range(t): n=int(input()) a=input() o=0 l=1 if len(set(a))==26: o=1 for i in 'abcdefghijklmnopqrstuvwxyz': if i not in a: print(i) break elif o==1: for j in 'abcdefghijklmnopqrstuvwxyz': ...
1622990100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["? 1 2\n\n? 3 2\n\n? 1 3\n\n? 2 1\n\n! 1 3 2"]
9bfbd68e61f4d2f3d404fd0413aded35
null
This is an interactive problem.We hid from you a permutation $$$p$$$ of length $$$n$$$, consisting of the elements from $$$1$$$ to $$$n$$$. You want to guess it. To do that, you can give us 2 different indices $$$i$$$ and $$$j$$$, and we will reply with $$$p_{i} \bmod p_{j}$$$ (remainder of division $$$p_{i}$$$ by $$$p...
null
The only line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) β€” length of the permutation.
standard output
standard input
PyPy 3
Python
1,600
train_000.jsonl
ee560325f27fefa25653b9210ee8221a
256 megabytes
["3\n\n1\n\n2\n\n1\n\n0"]
PASSED
import os from io import BytesIO, IOBase import sys from math import * from collections import Counter def main(): n=int(input()) ans=[n]*(n+1) z=set(range(1,n+1)) while len(z)!=1: a,b=z.pop(),z.pop() print('?',a,b,flush=True) x=int(input()) print('?',b,a,flush=True) ...
1599575700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["ccccc\ncccc\nkekeke"]
b8ffd93a80c840ea645c6797f8ee269c
NoteIn the first test case, "aaaaa" and "bbbbb" exchanged all positions, and "ccccc" is the stolen string.In the second test case, "aaaa" and "bbbb" exchanged two first positions, and "cccc" is the stolen string.This is the first test in the hack format: 33 5aaaaabbbbbccccc1 2 5 1 2 3 4 52 1 33 4aaaabbbbcccc1 2 2 1 22 ...
AquaMoon had $$$n$$$ strings of length $$$m$$$ each. $$$n$$$ is an odd number.When AquaMoon was gone, Cirno tried to pair these $$$n$$$ strings together. After making $$$\frac{n-1}{2}$$$ pairs, she found out that there was exactly one string without the pair!In her rage, she disrupted each pair of strings. For each pai...
For each test case print a single line with the stolen string.
This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you ...
standard output
standard input
PyPy 3-64
Python
1,200
train_086.jsonl
2c40c76404794e5e6d40c596c8e74062
256 megabytes
["3\n3 5\naaaaa\nbbbbb\nccccc\naaaaa\nbbbbb\n3 4\naaaa\nbbbb\ncccc\naabb\nbbaa\n5 6\nabcdef\nuuuuuu\nkekeke\nekekek\nxyzklm\nxbcklf\neueueu\nayzdem\nukukuk"]
PASSED
import sys;input=sys.stdin.readline for i in' '*int(input()): n,m=map(int,input().split()) l=[set()for i in' '*m] for i in range(n+n-1): s=input().strip() for i in range(m): l[i]^={s[i]} for i in l:print(*i,end='') print()
1626012300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2\n011", "3\n1101", "-1\n11111"]
f26a979dc042ec9564cfecce29e5a1cf
NoteFor the first sample, if we paint city $$$1$$$ white, the shortest path is $$$1 \rightarrow 3$$$. Otherwise, it's $$$1 \rightarrow 2 \rightarrow 3$$$ regardless of other cities' colors.For the second sample, we should paint city $$$3$$$ black, and there are both black and white roads going from $$$2$$$ to $$$4$$$. ...
Egor is a famous Russian singer, rapper, actor and blogger, and finally he decided to give a concert in the sunny Republic of Dagestan.There are $$$n$$$ cities in the republic, some of them are connected by $$$m$$$ directed roads without any additional conditions. In other words, road system of Dagestan represents an a...
In the first line output the length of the desired path (or $$$-1$$$, if it's possible to choose such schedule that there's no path from $$$1$$$ to $$$n$$$). In the second line output the desired schedule β€” a string of $$$n$$$ digits, where $$$i$$$-th digit is $$$0$$$, if the $$$i$$$-th city is a night one, and $$$1$$$...
The first line contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n \leq 500000$$$, $$$0 \leq m \leq 500000$$$) β€” the number of cities and the number of roads. The $$$i$$$-th of next $$$m$$$ lines contains three integers β€” $$$u_i$$$, $$$v_i$$$ and $$$t_i$$$ ($$$1 \leq u_i, v_i \leq n$$$, $$$t_i \in \{0, 1\}$$$) β€” number...
standard output
standard input
Python 3
Python
2,500
train_014.jsonl
4f9ced91d064181782cd36da35312be2
256 megabytes
["3 4\n1 2 0\n1 3 1\n2 3 0\n2 3 1", "4 8\n1 1 0\n1 3 0\n1 3 1\n3 2 0\n2 1 0\n3 4 1\n2 4 0\n2 4 1", "5 10\n1 2 0\n1 3 1\n1 4 0\n2 3 0\n2 3 1\n2 5 0\n3 4 0\n3 4 1\n4 2 1\n4 5 0"]
PASSED
import sys input = sys.stdin.readline from collections import deque n, m = map(int, input().split());back = [[] for i in range(n)] for _ in range(m):u, v, w = map(int, input().split());u -= 1;v -= 1;back[v].append((u,w)) out = [2] * n;outl = [-1] * n;outl[-1] = 0;q = deque([n - 1]) while q: v = q.popleft() for...
1599575700
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
3 seconds
["2"]
973044bfba063f34c956c0bbc042f903
NoteOnly the first and second persons are friends. The second can join Antihype and invite the first one, getting $$$2$$$ for it.
Kuroni isn't good at economics. So he decided to found a new financial pyramid called Antihype. It has the following rules: You can join the pyramid for free and get $$$0$$$ coins. If you are already a member of Antihype, you can invite your friend who is currently not a member of Antihype, and get a number of coins ...
Output exactly one integer Β β€” the maximum possible combined gainings of all $$$n$$$ people.
The first line contains a single integer $$$n$$$ ($$$1\le n \le 2\cdot 10^5$$$) Β β€” the number of people. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 2\cdot 10^5$$$) Β β€” the ages of the people.
standard output
standard input
PyPy 2
Python
3,500
train_081.jsonl
3cd652bf98eca7afce71c120fc3f628b
256 megabytes
["3\n1 2 3"]
PASSED
import sys range = xrange input = raw_input inp = [int(x) for x in sys.stdin.read().split()] n = inp[0] + 1 A = inp inp[0] = 0 # Dsu with O(1) lookup and O(log(n)) merge m = 2**18 count = [0]*m owner = list(range(m)) sets = [[i] for i in range(m)] for a in A: count[a] += 1 total = 0 for profit in reversed(ra...
1583246100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["2", "2", "0", "3"]
c083988d20f434d61134f7b376581eb6
NoteIn the first example, we may choose $$$d = -2$$$.In the second example, we may choose $$$d = -\frac{1}{13}$$$.In the third example, we cannot obtain any zero in array $$$c$$$, no matter which $$$d$$$ we choose.In the fourth example, we may choose $$$d = 6$$$.
You are given two arrays $$$a$$$ and $$$b$$$, each contains $$$n$$$ integers.You want to create a new array $$$c$$$ as follows: choose some real (i.e. not necessarily integer) number $$$d$$$, and then for every $$$i \in [1, n]$$$ let $$$c_i := d \cdot a_i + b_i$$$.Your goal is to maximize the number of zeroes in array ...
Print one integer β€” the maximum number of zeroes in array $$$c$$$, if you choose $$$d$$$ optimally.
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β€” the number of elements in both arrays. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). The third line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$-10^9 \le...
standard output
standard input
PyPy 2
Python
1,500
train_017.jsonl
e33e15a6ad498891794622e070b3f654
256 megabytes
["5\n1 2 3 4 5\n2 4 7 11 3", "3\n13 37 39\n1 2 3", "4\n0 0 0 0\n1 2 3 4", "3\n1 2 -1\n-6 -12 6"]
PASSED
# @-*- coding: utf-8 -*- # @Time: 2018-10-21T21:21:26+08:00 # @Email: ykaiwan@163.com import sys import math import bisect from collections import defaultdict MOD = int(1e9+7) # n = map(int, raw_input().split()) n = int(raw_input()) a = map(int, raw_input().split()) b = map(int, raw_input().split()) ck = defaul...
1551971100
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["3 3", "4", "0 1"]
2c51414eeb430ad06aac53a99ff95eff
NoteIn the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it co...
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of...
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
The first line contains two integers n, A (1 ≀ n ≀ 2Β·105, n ≀ A ≀ s) β€” the number of dice and the sum of shown values where s = d1 + d2 + ... + dn. The second line contains n integers d1, d2, ..., dn (1 ≀ di ≀ 106), where di is the maximum value that the i-th dice can show.
standard output
standard input
Python 3
Python
1,600
train_025.jsonl
689bd0a7dfe7f67fdcad310b6ce3c121
256 megabytes
["2 8\n4 4", "1 3\n5", "2 3\n2 3"]
PASSED
n, a = map(int, input().split()) d = list(map(int, input().split())) s = sum(d) def solve(): for x in d: yield max(x - (a - n + 1), 0) + max(a - (s - x) - 1, 0) print(' '.join(map(str, solve())))
1428854400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["10\n6\n7"]
690c28ef1275035895b9154ff0e17f4c
NoteIn the first testcase of the example, Monocarp can cast spells $$$3, 4, 5$$$ and $$$6$$$ seconds from the start with damages $$$1, 2, 3$$$ and $$$4$$$, respectively. The damage dealt at $$$6$$$ seconds is $$$4$$$, which is indeed greater than or equal to the health of the monster that appears.In the second testcase...
Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters.The level he's currently on contains $$$n$$$ monsters. The $$$i$$$-th of them appears $$$k_i$$$ seconds after the start of the level and has $$$h_i$$$ health points. As a...
For each testcase, print a single integerΒ β€” the least amount of mana required for Monocarp to kill all monsters.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of testcases. The first line of the testcase contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$)Β β€” the number of monsters in the level. The second line of the testcase contains $$$n$$$ integers $$$k_1 &lt; k_2 &lt; \dots &lt; k...
standard output
standard input
PyPy 3-64
Python
1,700
train_087.jsonl
5a2520d4c4647ad0fe9c7be5d546c1a4
256 megabytes
["3\n\n1\n\n6\n\n4\n\n2\n\n4 5\n\n2 2\n\n3\n\n5 7 9\n\n2 1 2"]
PASSED
import sys input = lambda: sys.stdin.readline().rstrip("\r\n") def solve(): n = int(input()) k = [0] for i in list(map(int, input().split())): k.append(i) h = [0] for i in list(map(int, input().split())): h.append(i) i = n ans = 0 while i > 0: ...
1642343700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["-1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3", "-1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1"]
a592b3cf7ecac3d56fe4e99e35d454f6
NoteIn the first sample input, let us see how to create $$$16$$$ number of bananas in three timesteps. Initially, $$$k=0$$$. In timestep 1, we choose $$$a_1=2$$$, so we apply the type 1 update β€” $$$k := \lceil(k+3)\rceil$$$ β€” two times. Hence, $$$k$$$ is now 6. In timestep 2, we choose $$$a_2=0$$$, hence value of $$$...
You have a malfunctioning microwave in which you want to put some bananas. You have $$$n$$$ time-steps before the microwave stops working completely. At each time-step, it displays a new operation.Let $$$k$$$ be the number of bananas in the microwave currently. Initially, $$$k = 0$$$. In the $$$i$$$-th operation, you a...
Print $$$m$$$ integers, where the $$$i$$$-th integer is the earliest time-step when you can obtain exactly $$$i$$$ bananas (or $$$-1$$$ if it is impossible).
The first line contains two space-separated integers $$$n$$$ $$$(1 \le n \le 200)$$$ and $$$m$$$ $$$(2 \le m \le 10^5)$$$. Then, $$$n$$$ lines follow, where the $$$i$$$-th line denotes the operation for the $$$i$$$-th timestep. Each such line contains three space-separated integers $$$t_i$$$, $$$x'_i$$$ and $$$y_i$$$ (...
standard output
standard input
PyPy 3-64
Python
2,200
train_107.jsonl
89db234b6a287feb13647d141e90091f
256 megabytes
["3 20\n1 300000 2\n2 400000 2\n1 1000000 3", "3 20\n1 399999 2\n2 412345 2\n1 1000001 3"]
PASSED
import math import sys def ceil(f,f1): return (f+f1-1)//f1 def main(): n, m = map(int, sys.stdin.readline().split()) dp = [math.inf] * (m + 1) dp[0] = 0 used = [0] * (m + 1) used[0] = 1 for i in range(n): t, x, y = map(int, sys.stdin.readline().split()) s ...
1617028500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["14\n13\n55\n105\n171\n253\n351\n465", "900057460\n712815817\n839861037\n756843750\n70840320\n66"]
1f13db0d8dcd292b55f49077b840e950
NoteConsider the first example and the first query in it. We can get only one string as a result of replacing the question marks Β β€” abaaaba. It has the following palindrome substrings: a Β β€” substring [$$$1$$$; $$$1$$$]. b Β β€” substring [$$$2$$$; $$$2$$$]. a Β β€” substring [$$$3$$$; $$$3$$$]. a Β β€” substring [$$$4$$$; ...
Today is a holiday in the residence hallΒ β€” Oleh arrived, in honor of which the girls gave him a string. Oleh liked the gift a lot, so he immediately thought up and offered you, his best friend, the following problem.You are given a string $$$s$$$ of length $$$n$$$, which consists of the first $$$17$$$ lowercase Latin l...
For each query print one numberΒ β€” the total numbers of palindromic substrings in all strings that can be obtained from the string $$$s$$$, modulo $$$998\,244\,353$$$.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1\,000$$$)Β β€” the length of the string $$$s$$$. The second line contains the string $$$s$$$, which consists of $$$n$$$ lowercase Latin letters and question marks. It is guaranteed that all letters in the string belong to the set {$$$a$$$, $$$b$$$, $$$c$$$,...
standard output
standard input
PyPy 3-64
Python
2,400
train_099.jsonl
0a9d039b11e85fe21d8ebf5faf5e5e1d
256 megabytes
["7\nab??aba\n8\na\nb\nab\nabc\nabcd\nabcde\nabcdef\nabcdefg", "11\n???????????\n6\nabcdefghijklmnopq\necpnkhbmlidgfjao\nolehfan\ncodef\nglhf\nq"]
PASSED
import sys;input=sys.stdin.readline m,mod=18,998244353 ch={chr(i+ord('a')):i for i in range(m)} n,s=int(input()),' '+input();tot=s.count('?') po=[[1]*(n+1) for i in range(m)] for i in range(1,m): for j in range(1,n+1): po[i][j]=po[i][j-1]*i%mod a=[[0]*(1<<m) for _ in range(m)] for mid in range(1,n+1): ...
1652520900
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["bc", "alvuw", "qoztvz"]
5f4009d4065f5ad39e662095f8f5c068
null
You are given two strings $$$s$$$ and $$$t$$$, both consisting of exactly $$$k$$$ lowercase Latin letters, $$$s$$$ is lexicographically less than $$$t$$$.Let's consider list of all strings consisting of exactly $$$k$$$ lowercase Latin letters, lexicographically not less than $$$s$$$ and not greater than $$$t$$$ (includ...
Print one string consisting exactly of $$$k$$$ lowercase Latin letters β€” the median (the middle element) of list of strings of length $$$k$$$ lexicographically not less than $$$s$$$ and not greater than $$$t$$$.
The first line of the input contains one integer $$$k$$$ ($$$1 \le k \le 2 \cdot 10^5$$$) β€” the length of strings. The second line of the input contains one string $$$s$$$ consisting of exactly $$$k$$$ lowercase Latin letters. The third line of the input contains one string $$$t$$$ consisting of exactly $$$k$$$ lowerca...
standard output
standard input
PyPy 2
Python
1,900
train_000.jsonl
79a2a90bd973d98b2309d06a12525932
256 megabytes
["2\naz\nbf", "5\nafogk\nasdji", "6\nnijfvj\ntvqhwp"]
PASSED
import sys, bisect, heapq, math sys.setrecursionlimit(10**9+7) def fi(): return int(sys.stdin.readline()) def fi2(): return map(int, sys.stdin.readline().split()) def fi3(): return sys.stdin.readline().rstrip() def fo(*args): for s in args: sys.stdout.write(str(s)+' ') sys.stdout.write('\n') ## sys.stdout.f...
1554041100
[ "number theory", "math", "strings" ]
[ 0, 0, 0, 1, 1, 0, 1, 0 ]
2 seconds
["15129", "51", "1099509530625"]
56fbdca75b69bf41d2a45a1dfe81d022
NoteIn the first sample no operation can be made, thus the answer is $$$123^2$$$.In the second sample we can obtain the collection $$$1, 1, 7$$$, and $$$1^2 + 1^2 + 7^2 = 51$$$.If $$$x$$$ and $$$y$$$ are represented in binary with equal number of bits (possibly with leading zeros), then each bit of $$$x~\mathsf{AND}~y$...
Gottfried learned about binary number representation. He then came up with this task and presented it to you.You are given a collection of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$. You are allowed to perform the following operation: choose two distinct indices $$$1 \leq i, j \leq n$$$. If before the operati...
Print a single integerΒ β€” the largest possible sum of squares that can be achieved after several (possibly zero) operations.
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$0 \leq a_i &lt; 2^{20}$$$).
standard output
standard input
PyPy 3
Python
1,700
train_004.jsonl
a9799663967c08989d5c153d5db9ae99
512 megabytes
["1\n123", "3\n1 3 5", "2\n349525 699050"]
PASSED
n = int(input()) l = list(map(int, input().split())) ans = [] for i in range(20): ans.append([]) for i in range(n): tmp = bin(l[i])[2: ] ln = 20 - len(tmp) tmp = '0' * ln + tmp for j in range(20): ans[j].append(tmp[j]) for i in range(20): ans[i].sort() fin = 0 for i in range(n): tmp = 0 for j in...
1592491500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["2\n1\n1", "3\n1\n0"]
81122f1a525ac6e80b1d9c2adc735f6f
NoteThe first test case of the first example is explained in the statement.In the second test case of the first example, two friends with cars live at vertex $$$5$$$, one can give a ride to friends from vertices $$$2$$$ and $$$3$$$, and the second from vertex $$$4$$$, only a friend from vertex $$$6$$$ will have to walk...
Kirill lives on a connected undirected graph of $$$n$$$ vertices and $$$m$$$ edges at vertex $$$1$$$. One fine evening he gathered $$$f$$$ friends, the $$$i$$$-th friend lives at the vertex $$$h_i$$$. So all friends are now in the vertex $$$1$$$, the $$$i$$$-th friend must get to his home to the vertex $$$h_i$$$.The ev...
Output $$$t$$$ lines, each of which contains the answer to the corresponding test case. As an answer, output a single integerΒ β€” the minimum possible number of friends who will have to walk.
The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^3$$$)Β β€” the number of test cases in the test. The first line of the test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 10^4$$$, $$$n-1 \le m \le min (10^4, $$$$$$ \frac{n \cdot (n - 1)}{2} $$$$$$)$$$)Β β€” the number of vertices a...
standard output
standard input
PyPy 3-64
Python
2,200
train_084.jsonl
bb756c9ea1ad831be9fc8eb2379cfa56
256 megabytes
["3\n\n6 7\n\n1 2\n\n2 3\n\n2 4\n\n3 5\n\n4 5\n\n3 6\n\n6 5\n\n5\n\n2 3 4 5 6\n\n4\n\n1 2 3 5\n\n6 7\n\n1 2\n\n2 3\n\n2 4\n\n3 5\n\n4 5\n\n3 6\n\n6 5\n\n6\n\n2 3 4 5 6 5\n\n4\n\n1 2 3 5\n\n4 4\n\n1 2\n\n1 3\n\n2 3\n\n3 4\n\n3\n\n3 4 2\n\n2\n\n1 3", "3\n\n2 1\n\n1 2\n\n3\n\n2 2 2\n\n3\n\n1 2 3\n\n3 3\n\n1 2\n\n1 3\n\n2 ...
PASSED
from collections import deque def solve(): n, m = map(int, input().split()) sl = [[] for _ in range(n)] for _ in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 sl[u] += [v] sl[v] += [u] f = int(input()) h = [int(x) - 1 for x in input...
1665498900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["YES\nYES\nNO"]
e65b2a81689bb13b90a02a9ccf1d4125
NoteIn the first test case, Adilbek decides not to optimize the program at all, since $$$d \le n$$$.In the second test case, Adilbek can spend $$$1$$$ day optimizing the program and it will run $$$\left\lceil \frac{5}{2} \right\rceil = 3$$$ days. In total, he will spend $$$4$$$ days and will fit in the limit.In the thi...
Adilbek was assigned to a special project. For Adilbek it means that he has $$$n$$$ days to run a special program and provide its results. But there is a problem: the program needs to run for $$$d$$$ days to calculate the results.Fortunately, Adilbek can optimize the program. If he spends $$$x$$$ ($$$x$$$ is a non-nega...
Print $$$T$$$ answers β€” one per test case. For each test case print YES (case insensitive) if Adilbek can fit in $$$n$$$ days or NO (case insensitive) otherwise.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) β€” the number of test cases. The next $$$T$$$ lines contain test cases – one per line. Each line contains two integers $$$n$$$ and $$$d$$$ ($$$1 \le n \le 10^9$$$, $$$1 \le d \le 10^9$$$) β€” the number of days before the deadline and the number of da...
standard output
standard input
PyPy 3
Python
1,100
train_001.jsonl
87b598a38701c5ded117c1949442731a
256 megabytes
["3\n1 1\n4 5\n5 11"]
PASSED
from math import * for _ in range(int(input())): n,d=map(int,input().split()) if d<=n: print("YES") else: for i in range(1,int(sqrt(d))+1): if ceil(d/(i+1))+i<=n: print("YES") break else: print("NO")
1579012500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......", "No", "Yes\n.S...\n...S.\nS.D..\n...S.\n.S..."]
f55c824d8db327e531499ced6c843102
NoteIn the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.In the second example, there are no empty spots to put dogs that would guard the lone sheep.In the third example, there are no wolves...
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.The pasture is a rectangle consisting of R × C cells. Each cell is either empty, contains a sheep, a wolf or a dog. ...
If it is impossible to protect all sheep, output a single line with the word "No". Otherwise, output a line with the word "Yes". Then print R lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a sheep ...
First line contains two integers R (1 ≀ R ≀ 500) and C (1 ≀ C ≀ 500), denoting the number of rows and the numbers of columns respectively. Each of the following R lines is a string consisting of exactly C characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' an empty cell.
standard output
standard input
PyPy 2
Python
900
train_008.jsonl
5033e6633f0171c8bee1cc2a9ec1b511
256 megabytes
["6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......", "1 2\nSW", "5 5\n.S...\n...S.\nS....\n...S.\n.S..."]
PASSED
r, c = map(int, raw_input().split()) m = [] for i in range(r): m.append(list(raw_input().replace('.', 'D'))) protected = True for i in range(r): if not protected: break for j in range(c): if (m[i][j] == 'S'): if(j + 1 < c and m[i][j + 1] == 'W'): protected = False if(i + 1 < r and m...
1520696100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["165\n108\n145\n234\n11\n3"]
83d0395cd3618b0fd02c1846dbcd92a2
NoteThe examples of possible divisions into arrays for all test cases of the first test:Test case $$$1$$$: $$$[0, 24], [34, 58], [62, 64], [69, 78]$$$. The medians are $$$0, 34, 62, 69$$$. Their sum is $$$165$$$.Test case $$$2$$$: $$$[27, 61], [81, 91]$$$. The medians are $$$27, 81$$$. Their sum is $$$108$$$.Test case ...
A median of an array of integers of length $$$n$$$ is the number standing on the $$$\lceil {\frac{n}{2}} \rceil$$$ (rounding up) position in the non-decreasing ordering of its elements. Positions are numbered starting with $$$1$$$. For example, a median of the array $$$[2, 6, 4, 1, 3, 5]$$$ is equal to $$$3$$$. There e...
For each test case print a single integerΒ β€” the maximum possible sum of medians of all $$$k$$$ arrays.
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)Β β€” the number of test cases. The next $$$2t$$$ lines contain descriptions of test cases. The first line of the description of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1 \leq n, k \leq 1000$$$). The second line of the description ...
standard output
standard input
PyPy 3
Python
900
train_011.jsonl
a3a8aac746adc118c9b0f2c854ddd7ac
256 megabytes
["6\n2 4\n0 24 34 58 62 64 69 78\n2 2\n27 61 81 91\n4 3\n2 4 16 18 21 27 36 53 82 91 92 95\n3 4\n3 11 12 22 33 35 38 67 69 71 94 99\n2 1\n11 41\n3 3\n1 1 1 1 1 1 1 1 1"]
PASSED
t = int(input()) for i10 in range(t): n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() c = n // 2 + 1 s = 0 j = 1 k1 = 0 for i in range(n * k - 1, -1, -1): if k1 == k: break if j == c: k1 += 1 j = 1 ...
1605623700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2\n1\n1100"]
57f0f36905d7769167b7ba9d3d9be351
null
This problem is a simplified version of D2, but it has significant differences, so read the whole statement.Polycarp has an array of $$$n$$$ ($$$n$$$ is even) integers $$$a_1, a_2, \dots, a_n$$$. Polycarp conceived of a positive integer $$$k$$$. After that, Polycarp began performing the following operations on the arra...
For each test case output on a separate line an integer $$$k$$$ ($$$k \ge 1$$$) β€” the maximum possible number that Polycarp used in operations on the array, or $$$-1$$$, if such a number can be arbitrarily large.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of two lines. The first line contains an even integer $$$n$$$ ($$$4 \le n \le 40$$$) ($$$n$$$ is even). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots a_n$...
standard output
standard input
PyPy 3-64
Python
1,100
train_093.jsonl
3f2ff5474b97f50ee3664def867f79bf
256 megabytes
["3\n6\n1 5 3 1 1 5\n8\n-1 0 1 -1 0 1 -1 0\n4\n100 -1000 -1000 -1000"]
PASSED
def hcf(a,b): if b>a: a,b=b,a if b==0: return a return hcf(b,a%b) for iiii in range(int(input())): n=int(input()) q=list(map(int,input().split())) maxx=-1 q1=[] q.sort() for i in range(1,n): if q[i]-q[i-1]>0: q1.append(q[i]-q[i-1]) ...
1634135700
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["3\n3\n2\n6"]
2f0cdacc14ac81249f30c8c231003a73
NoteIn the first test case, the array is $$$[1,5,2,4,6]$$$. The largest friend group is $$$[2,4,6]$$$, since all those numbers are congruent to $$$0$$$ modulo $$$2$$$, so $$$m=2$$$.In the second test case, the array is $$$[8,2,5,10]$$$. The largest friend group is $$$[8,2,5]$$$, since all those numbers are congruent to...
British mathematician John Littlewood once said about Indian mathematician Srinivasa Ramanujan that "every positive integer was one of his personal friends."It turns out that positive integers can also be friends with each other! You are given an array $$$a$$$ of distinct positive integers. Define a subarray $$$a_i, a_...
Your output should consist of $$$t$$$ lines. Each line should consist of a single integer, the size of the largest friend group in $$$a$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2\cdot 10^4$$$). Each test case begins with a line containing the integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$), the size of the array $$$a$$$. The next line contains $$$n$$$ positive integers $$$a_1, a_...
standard output
standard input
Python 3
Python
1,800
train_083.jsonl
8d23c115e90bb488be5861bc525a1f9d
256 megabytes
["4\n5\n1 5 2 4 6\n4\n8 2 5 10\n2\n1000 2000\n8\n465 55 3 54 234 12 45 78"]
PASSED
from math import gcd def solve(arr, n): if n == 1: print(1) return # check = False # for x in range(n-1): # a = arr[x] # arr[x] = abs(a - arr[x+1]) # if arr[x] != 1: # check = True # if not check: # print(1) # return ...
1627828500
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["0.828427125", "19.668384925"]
21432a74b063b008cf9f04d2804c1c3f
NoteThe second sample has been drawn on the picture above.
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side tha...
In a single line print a real number β€” the area of the region which belongs to both given rectangles. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
The first line contains three integers w, h, α (1 ≀ w, h ≀ 106;Β 0 ≀ α ≀ 180). Angle Ξ± is given in degrees.
standard output
standard input
Python 3
Python
2,000
train_015.jsonl
da3f3418fea80d0698d057aaa2dc77f4
256 megabytes
["1 1 45", "6 4 30"]
PASSED
from math import radians, cos, sin, atan2 def rotate(point, alpha): x = point[0] y = point[1] return (x * cos(alpha) - y * sin(alpha), x * sin(alpha) + y * cos(alpha)) def crs(a, b): return a[0] * b[1] - a[1] * b[0] def m(end, start): return (end[0] - start[0], end[1] - start[1]) def area(poly):...
1362929400
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
2 seconds
["1", "2", "0"]
ed1a2ae733121af6486568e528fe2d84
null
The only difference between easy and hard versions is the number of elements in the array.You are given an array $$$a$$$ consisting of $$$n$$$ integers. In one move you can choose any $$$a_i$$$ and divide it by $$$2$$$ rounding down (in other words, in one move you can set $$$a_i := \lfloor\frac{a_i}{2}\rfloor$$$).You ...
Print one integer β€” the minimum possible number of operations required to obtain at least $$$k$$$ equal numbers in the array.
The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 50$$$) β€” the number of elements in the array and the number of equal numbers required. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the ...
standard output
standard input
Python 3
Python
1,600
train_007.jsonl
20827176678794a9807f8b9258b034e0
256 megabytes
["5 3\n1 2 2 4 5", "5 3\n1 2 3 4 5", "5 3\n1 2 3 3 3"]
PASSED
n, k = [int(i) for i in input().split()] data = [int(i) for i in input().split()] dic = [[0]*20 for j in range(200001)] for d in data: s = 0 while d: dic[d][s] += 1 d >>= 1 s += 1 dic[0][s] += 1 mn = 1<<30 for d in dic: if sum(d) >= k: left = k val = 0 ...
1567175700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1\n3\n3\n7"]
322792a11d3eb1df6b54e8f89c9a0490
NoteConsider the example test: in the first test case, the array $$$[1]$$$ meets all conditions; in the second test case, the array $$$[3, 4, 1]$$$ meets all conditions; in the third test case, the array $$$[1, 2, 4]$$$ meets all conditions; in the fourth test case, the array $$$[1, 4, 6, 8, 10, 2, 11]$$$ meets all...
Let's call an array $$$a$$$ consisting of $$$n$$$ positive (greater than $$$0$$$) integers beautiful if the following condition is held for every $$$i$$$ from $$$1$$$ to $$$n$$$: either $$$a_i = 1$$$, or at least one of the numbers $$$a_i - 1$$$ and $$$a_i - 2$$$ exists in the array as well.For example: the array $$$...
Print $$$t$$$ integers, the $$$i$$$-th integer should be the answer for the $$$i$$$-th testcase: the minimum possible size of a beautiful array with the sum of elements equal to $$$s$$$.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) β€” the number of test cases. Then $$$t$$$ lines follow, the $$$i$$$-th line contains one integer $$$s$$$ ($$$1 \le s \le 5000$$$) for the $$$i$$$-th test case.
standard output
standard input
PyPy 3-64
Python
800
train_093.jsonl
b84662f5cecb5b3a841c41892f3bd014
256 megabytes
["4\n1\n8\n7\n42"]
PASSED
def maxSum(x): return x ** 2 def getAns(x): res = 1 while maxSum(res) < x: res += 1 return res def main(): t = int(input()) for i in range(t): print(getAns(int(input()))) main()
1626273300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["YES\n3\n6 54 321\nYES\n3\n1 3 37\nNO\nYES\n2\n21 22"]
9f87a89c788bd7c7b66e51db9fe47e46
null
You are given a sequence $$$s$$$ consisting of $$$n$$$ digits from $$$1$$$ to $$$9$$$.You have to divide it into at least two segments (segment β€” is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly o...
If the sequence of digits in the $$$i$$$-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print $$$k_i$$$ β€” the number of parts in your divisi...
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 300$$$) β€” the number of queries. The first line of the $$$i$$$-th query contains one integer number $$$n_i$$$ ($$$2 \le n_i \le 300$$$) β€” the number of digits in the $$$i$$$-th query. The second line of the $$$i$$$-th query contains one string $$$...
standard output
standard input
Python 2
Python
900
train_007.jsonl
52b0379bbe0d7ad240dc1bb55c8c6a79
256 megabytes
["4\n6\n654321\n4\n1337\n2\n33\n4\n2122"]
PASSED
'''input 4 6 654321 4 1337 2 33 4 2122 ''' RI = lambda : [int(x) for x in raw_input().split()] rw = lambda : raw_input().strip() for _ in range(input()): n=input() s=raw_input().strip() if n==2: if int(s[0])<int(s[1]): print "YES\n2" print s[0],s[1] else: print "NO" else: print "YES\n2" print s[...
1548516900
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["6\n4\n10\n7"]
0373262cf6c4c6d29fbf2177a1649cee
NoteFor the first query, $$$l = 2$$$ and $$$r = 5$$$, and the non-decreasing subarrays $$$[p,q]$$$ are $$$[2,2]$$$, $$$[3,3]$$$, $$$[4,4]$$$, $$$[5,5]$$$, $$$[2,3]$$$ and $$$[4,5]$$$.
Alice has recently received an array $$$a_1, a_2, \dots, a_n$$$ for her birthday! She is very proud of her array, and when she showed her friend Bob the array, he was very happy with her present too!However, soon Bob became curious, and as any sane friend would do, asked Alice to perform $$$q$$$ operations of two types...
For each query of type $$$2$$$, print a single integer, the answer to the query.
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$)Β β€” the size of the array, and the number of queries, respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)Β β€” the elements of Alice's array. The next $$$q$$$ lines consist o...
standard output
standard input
PyPy 3
Python
2,200
train_089.jsonl
dae7be27505f90ba6d946c0f0c8c02cf
256 megabytes
["5 6\n3 1 4 1 5\n2 2 5\n2 1 3\n1 4 4\n2 2 5\n1 2 6\n2 2 5"]
PASSED
# Based on https://codeforces.com/contest/1567/submission/127989410 # But use ffi for data layout and use double instead of big integer for answer import sys from cffi import FFI input = sys.stdin.buffer.readline ffi = FFI() ffi.cdef( """ typedef struct { int first; int last; int suf;...
1630852500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["Yes\n16 17 21", "No"]
e4f95b4124f38ea4f7153265591757c8
NoteConsider the first example and the timetable $$$b_1, b_2, \ldots, b_n$$$ from the output.To get $$$x_1 = 2$$$ the buses can arrive in the order $$$(2, 1, 3)$$$. To get $$$x_2 = 2$$$ and $$$x_3 = 3$$$ the buses can arrive in the order $$$(1, 2, 3)$$$. $$$x_1$$$ is not $$$3$$$, because the permutations $$$(3, 1, 2)$$...
There are two bus stops denoted A and B, and there $$$n$$$ buses that go from A to B every day. The shortest path from A to B takes $$$t$$$ units of time but some buses might take longer paths. Moreover, buses are allowed to overtake each other during the route.At each station one can find a sorted list of moments of t...
If a solution exists, print "Yes" (without quotes) in the first line of the output. In the second line print $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \leq b_1 &lt; b_2 &lt; \ldots &lt; b_n \leq 3 \cdot 10^{18}$$$). We can show that if there exists any solution, there exists a solution that satisfies such cons...
The first line of the input contains two integers $$$n$$$ and $$$t$$$ ($$$1 \leq n \leq 200\,000$$$, $$$1 \leq t \leq 10^{18}$$$)Β β€” the number of buses in timetable for and the minimum possible travel time from stop A to stop B. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_1 &lt; a...
standard output
standard input
Python 3
Python
2,300
train_026.jsonl
c6702a4148dd4efcfd206f924e73629f
512 megabytes
["3 10\n4 6 8\n2 2 3", "2 1\n1 2\n2 1"]
PASSED
n, t = map(int, input().split()) a = list(map(int, input().split())) x = list(map(int, input().split())) if n == 200000 and t == 10000 or n == 5000 and t == 100: print('No') exit(0) for i in range(len(x)): if x[i] < i + 1 or (i > 0 and x[i] < x[i - 1]): print('No') exit(0) b = [ 3 * 10 ** 18 ] for i in range(len...
1536165300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["4\n12\n0\n0\n2\n21"]
27998621de63e50a7d89cb1c1e30f67c
NoteIn the first example Monocarp can put out the dishes at minutes $$$3, 1, 5, 4, 6, 2$$$. That way the total unpleasant value will be $$$|4 - 3| + |2 - 1| + |4 - 5| + |4 - 4| + |6 - 5| + |2 - 2| = 4$$$.In the second example Monocarp can put out the dishes at minutes $$$4, 5, 6, 7, 8, 9, 10$$$.In the third example Mon...
Chef Monocarp has just put $$$n$$$ dishes into an oven. He knows that the $$$i$$$-th dish has its optimal cooking time equal to $$$t_i$$$ minutes.At any positive integer minute $$$T$$$ Monocarp can put no more than one dish out of the oven. If the $$$i$$$-th dish is put out at some minute $$$T$$$, then its unpleasant v...
Print a single integer for each testcaseΒ β€” the minimum total unpleasant value Monocarp can obtain when he puts out all the dishes out of the oven. Remember that Monocarp can only put the dishes out at positive integer minutes and no more than one dish at any minute.
The first line contains a single integer $$$q$$$ ($$$1 \le q \le 200$$$)Β β€” the number of testcases. Then $$$q$$$ testcases follow. The first line of the testcase contains a single integer $$$n$$$ ($$$1 \le n \le 200$$$)Β β€” the number of dishes in the oven. The second line of the testcase contains $$$n$$$ integers $$$t_1...
standard output
standard input
PyPy 3
Python
1,800
train_014.jsonl
f07039538318c14578142dc4628dbeea
256 megabytes
["6\n6\n4 2 4 4 5 2\n7\n7 7 7 7 7 7 7\n1\n1\n5\n5 1 2 4 3\n4\n1 4 4 4\n21\n21 8 1 4 1 5 21 1 8 21 11 21 11 3 12 8 19 15 9 11 13"]
PASSED
import sys original_stdout = sys.stdout var_for_sublime = False if var_for_sublime: fin = open('input.txt' , 'r') fout = open('output.txt' , 'w') sys.stdout = fout def give_string(): return fin.readline() else: fin = sys.stdin fout = sys.stdout def give_string(): return fin.buffer.readline() def give_...
1603809300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1", "0", "239"]
f146808eb6e0ee04d531e7222a53d275
NoteIn the first test, the expansion coefficient of the array $$$[6, 4, 5, 5]$$$ is equal to $$$1$$$ because $$$|i-j| \leq min(a_i, a_j)$$$, because all elements of the array satisfy $$$a_i \geq 3$$$. On the other hand, this array isn't a $$$2$$$-extension, because $$$6 = 2 \cdot |1 - 4| \leq min(a_1, a_4) = 5$$$ is fa...
Let's call an array of non-negative integers $$$a_1, a_2, \ldots, a_n$$$ a $$$k$$$-extension for some non-negative integer $$$k$$$ if for all possible pairs of indices $$$1 \leq i, j \leq n$$$ the inequality $$$k \cdot |i - j| \leq min(a_i, a_j)$$$ is satisfied. The expansion coefficient of the array $$$a$$$ is the max...
Print one non-negative integerΒ β€” expansion coefficient of the array $$$a_1, a_2, \ldots, a_n$$$.
The first line contains one positive integer $$$n$$$Β β€” the number of elements in the array $$$a$$$ ($$$2 \leq n \leq 300\,000$$$). The next line contains $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$, separated by spaces ($$$0 \leq a_i \leq 10^9$$$).
standard output
standard input
Python 3
Python
1,300
train_016.jsonl
82b4bece2bfe496218583016a1522f47
256 megabytes
["4\n6 4 5 5", "3\n0 1 2", "4\n821 500 479 717"]
PASSED
#n = int(input()) #n, m = map(int, input().split()) #d = list(map(int, input().split())) n = int(input()) d = list(map(int, input().split())) t = 10**9 for i in range(1, n+1): j = max(i - 1, n - i) t = min(t, d[i-1]//j) print(t)
1557671700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
4 seconds
["16", "0", "13"]
198b6e6b91c7b4655d133a78421ac249
NoteThe strange set with the maximum cost in the first example is $$$\{1, 2, 4, 8, 9\}$$$.The strange set with the maximum cost in the second example is empty.
Note that the memory limit is unusual.You are given an integer $$$n$$$ and two sequences $$$a_1, a_2, \dots, a_n$$$ and $$$b_1, b_2, \dots, b_n$$$.Let's call a set of integers $$$S$$$ such that $$$S \subseteq \{1, 2, 3, \dots, n\}$$$ strange, if, for every element $$$i$$$ of $$$S$$$, the following condition is met: for...
Print one integer β€” the maximum cost of a strange set.
The first line contains one integer $$$n$$$ ($$$1 \le n \le 3000$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$). The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-10^5 \le b_i \le 10^5$$$).
standard output
standard input
PyPy 3
Python
2,700
train_106.jsonl
89ff19c5e0c641bcdf901cd45d9c039e
32 megabytes
["9\n4 7 3 4 5 6 7 8 13\n-2 3 -19 5 -6 7 -8 9 1", "2\n42 42\n-37 13", "2\n42 42\n13 -37"]
PASSED
from collections import deque class Dinic: def __init__(self, N): self.N = N self.G = [[] for i in range(N)] # 1方向 def add_edge(self, fr, to, cap): forward = [to, cap, None] forward[2] = backward = [fr, 0, forward] self.G[fr].append(forward) self.G...
1610634900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["abac\nac\nbcdaf\nzzzzzz"]
ac77e2e6c86b5528b401debe9f68fc8e
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of stri...
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess ...
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β€” the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$)Β β€” the string Bob came u...
standard output
standard input
Python 3
Python
800
train_005.jsonl
38df8019a7fc4a197adffa8a3bf50b05
256 megabytes
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
PASSED
x = int (input()) z = [0 for i in range(x)] for y in range(0, x): z[y] = str (input()) for y in range(0, x): a = z[y] u = int (len(a) / 2) f = [0 for i in range(u + 1)] f[0] = a[0] for q in range(0, u): f[q] = a[q * 2] f[len(f) - 1] = a[len(a) - 1] z[y] = f for y in range(0, x): delim...
1592318100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["5\n38\n19"]
891fabbb6ee8a4969b6f413120f672a8
null
Today at the lesson of mathematics, Petya learns about the digital root.The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-dig...
Output $$$n$$$ lines, $$$i$$$-th line should contain a single integer β€” the answer to the $$$i$$$-th problem.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^3$$$) β€” the number of tasks in Petya's homework. The next $$$n$$$ lines contain two integers $$$k_i$$$ ($$$1 \le k_i \le 10^{12}$$$) and $$$x_i$$$ ($$$1 \le x_i \le 9$$$) β€” $$$i$$$-th Petya's task in which you need to find a $$$k_i$$$-th positive numbe...
standard output
standard input
Python 3
Python
1,000
train_003.jsonl
54f18e3d56e700b9926dc854bf0b244b
256 megabytes
["3\n1 5\n5 2\n3 1"]
PASSED
n = int(input()) for _ in range(n): k,x = map(int,input().split()) if (k==1): print(x) else: print(x+((k-1)%1000000000007)*9)
1548516900
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["? 1 4\n\n? 1 6\n\n? 5 7\n\n! 7"]
c9bc4fefa96b741843e54a8fb4b02877
NoteThe tournament in the first test case is shown below. The number of wins is $$$[1,0,0,2,0,1,3,0]$$$. In this example, the winner is the $$$7$$$-th contestant.
This is an interactive problem.There was a tournament consisting of $$$2^n$$$ contestants. The $$$1$$$-st contestant competed with the $$$2$$$-nd, the $$$3$$$-rd competed with the $$$4$$$-th, and so on. After that, the winner of the first match competed with the winner of second match, etc. The tournament ended when th...
null
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 2^{14}$$$) β€” the number of test cases. The only line of input contains a single integer $$$n$$$ ($$$1 \leq n \leq 17$$$). It is guaranteed that the sum of $$$2^n$$$ over all test cases does not exceed $$$2^{17}$$$.
standard output
standard input
Python 3
Python
1,800
train_088.jsonl
8c798b26dcec2420e69ead7ff40b4ea6
256 megabytes
["1\n3\n\n2\n\n0\n\n2"]
PASSED
t= int(input()) for _ in range(t): n=int(input()) P = [i for i in range(1,2**n+1)] while n>1: k=[] for i in range(0,2**(n)-1,4): print("? ", P[i], P[i+2], flush =True) a = int(input()) if a==0: k.extend([P[i+1],P[i+3]]) ...
1659796500
[ "probabilities", "number theory" ]
[ 0, 0, 0, 0, 1, 1, 0, 0 ]
2 seconds
["2", "1", "3"]
2d3af7ca9bf074d03408d5ade3ddd14c
NoteIn the first example, you can remove edges $$$(1, 2)$$$ and $$$(2, 3)$$$. $$$\mathit{in} = [0, 1, 2]$$$, $$$\mathit{out} = [2, 1, 0]$$$. $$$\mathit{in'} = [0, 0, 1]$$$, $$$\mathit{out'} = [1, 0, 0]$$$. You can see that for all $$$v$$$ the conditions hold. The maximum cute set $$$S$$$ is formed by vertices $$$1$$$ a...
You are given a directed acyclic graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The vertices are numbered from $$$1$$$ to $$$n$$$. There are no multiple edges and self-loops.Let $$$\mathit{in}_v$$$ be the number of incoming edges (indegree) and $$$\mathit{out}_v$$$ be the number of outgoing edges (outdegree) ...
Print a single integerΒ β€” the maximum possible size of a cute set $$$S$$$ after you remove some edges from the graph and both indegrees and outdegrees of all vertices either decrease or remain equal to $$$0$$$.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$0 \le m \le 2 \cdot 10^5$$$)Β β€” the number of vertices and the number of edges of the graph. Each of the next $$$m$$$ lines contains two integers $$$v$$$ and $$$u$$$ ($$$1 \le v, u \le n$$$; $$$v \neq u$$$)Β β€” the description of ...
standard output
standard input
PyPy 3-64
Python
2,000
train_107.jsonl
305b68a8a50ca10807d07a0e434f1b3d
256 megabytes
["3 3\n1 2\n2 3\n1 3", "5 0", "7 8\n7 1\n1 3\n6 2\n2 3\n7 2\n2 4\n7 3\n6 3"]
PASSED
import sys from collections import defaultdict n, m = tuple(map(int,input().split())) adj = defaultdict(list) indg = [0] * n outdg = [0] * n dp = [1] * n vis = set() finish = [] def dfs(u): vis.add(u) for v in adj[u]: if v not in vis: dfs(v) finish.append(u) for _ in r...
1651502100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["1 \n1 2 \n2 1 \n1 3 2"]
67de9506ac2458ee67346bae1a9e3926
NoteIn the first test case, the sequence $$$a = [1]$$$, there is only one permutation $$$p = [1]$$$.In the second test case, the sequence $$$a = [1, 2]$$$. There is no inversion in $$$a$$$, so there is only one permutation $$$p = [1, 2]$$$ which doesn't increase the number of inversions.In the third test case, $$$a = [...
You have a sequence $$$a$$$ with $$$n$$$ elements $$$1, 2, 3, \dots, k - 1, k, k - 1, k - 2, \dots, k - (n - k)$$$ ($$$k \le n &lt; 2k$$$).Let's call as inversion in $$$a$$$ a pair of indices $$$i &lt; j$$$ such that $$$a[i] &gt; a[j]$$$.Suppose, you have some permutation $$$p$$$ of size $$$k$$$ and you build a sequenc...
For each test case, print $$$k$$$ integersΒ β€” the permutation $$$p$$$ which maximizes $$$b$$$ lexicographically without increasing the total number of inversions. It can be proven that $$$p$$$ exists and is unique.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β€” the number of test cases. The first and only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$k \le n &lt; 2k$$$; $$$1 \le k \le 10^5$$$)Β β€” the length of the sequence $$$a$$$ and its maximum. It's guaranteed that the total s...
standard output
standard input
PyPy 3
Python
1,500
train_106.jsonl
c7b34f3059776d9d8cfb1a099e8a0994
256 megabytes
["4\n1 1\n2 2\n3 2\n4 3"]
PASSED
T=int(input()) for _ in range(T): n,k=map(int,input().split()) ans=[i for i in range(1,k+1)] temp=2*k-n-1;k1=k for i in range(temp,k): ans[i]=k1 k1-=1 print(*ans)
1610634900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["bus topology", "ring topology", "star topology", "unknown topology"]
7bb088ce5e4e2101221c706ff87841e4
null
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of n computers, some of them are...
In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topolo...
The first line contains two space-separated integers n and m (4 ≀ n ≀ 105;Β 3 ≀ m ≀ 105) β€” the number of nodes and edges in the graph, correspondingly. Next m lines contain the description of the graph's edges. The i-th line contains a space-separated pair of integers xi, yi (1 ≀ xi, yi ≀ n) β€” the numbers of nodes that ...
standard output
standard input
Python 3
Python
1,200
train_010.jsonl
90bcc734f243a7afd337c6088cce541a
256 megabytes
["4 3\n1 2\n2 3\n3 4", "4 4\n1 2\n2 3\n3 4\n4 1", "4 3\n1 2\n1 3\n1 4", "4 4\n1 2\n2 3\n3 1\n1 4"]
PASSED
# brute force baby !!!! from sys import stdin node,edge = map(int,input().split()) capt = [0]*node for l in stdin.readlines(): a,b = map(int,l.split()) capt[a-1] +=1; capt[b-1] += 1 ones,twos = capt.count(1),capt.count(2) if ones == node - 1: print('star topology') elif twos == node: print('ring topolog...
1366040100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["2", "0", "8"]
afd12d95b59b250a0a5af87e5277a3fb
null
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.In total the table Arthur bought has n legs, the length of the i-th leg is li.Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number diΒ β€”Β the amoun...
Print a single integer β€” the minimum number of energy units that Arthur needs to spend in order to make the table stable.
The first line of the input contains integer n (1 ≀ n ≀ 105)Β β€”Β the initial number of legs in the table Arthur bought. The second line of the input contains a sequence of n integers li (1 ≀ li ≀ 105), where li is equal to the length of the i-th leg of the table. The third line of the input contains a sequence of n integ...
standard output
standard input
Python 3
Python
1,900
train_058.jsonl
61009ee28122dbb2baea3ad2ff513c7d
256 megabytes
["2\n1 5\n3 2", "3\n2 4 4\n1 1 1", "6\n2 2 1 1 3 3\n4 3 5 5 2 1"]
PASSED
rr = lambda: map(int, input().split()) _, d, res, he = input(), {}, 0, list(zip(rr(), rr())) for h, e in he: f, x = d.get(h, (-1, 0)) d[h] = (f + 1, x + e) he.sort(key = lambda x: x[1], reverse=True) for h, (f, x) in d.items(): if not f: res = max(x, res) continue for h1, e in he: if h...
1435676400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["Yes\nNo\nYes\nNo\nYes"]
e0a3c678f6d1d89420c8162b0ddfcef7
NoteIn the first test case, $$$24$$$ is generated as follows: $$$1$$$ is in this set, so $$$3$$$ and $$$6$$$ are in this set; $$$3$$$ is in this set, so $$$9$$$ and $$$8$$$ are in this set; $$$8$$$ is in this set, so $$$24$$$ and $$$13$$$ are in this set. Thus we can see $$$24$$$ is in this set.The five smallest ele...
There is an infinite set generated as follows: $$$1$$$ is in this set. If $$$x$$$ is in this set, $$$x \cdot a$$$ and $$$x+b$$$ both are in this set. For example, when $$$a=3$$$ and $$$b=6$$$, the five smallest elements of the set are: $$$1$$$, $$$3$$$ ($$$1$$$ is in this set, so $$$1\cdot a=3$$$ is in this set), ...
For each test case, print "Yes" if $$$n$$$ is in this set, and "No" otherwise. You can print each letter in any case.
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t\leq 10^5$$$) β€” the number of test cases. The description of the test cases follows. The only line describing each test case contains three integers $$$n$$$, $$$a$$$, $$$b$$$ ($$$1\leq n,a,b\leq 10^9$$$) separated by a sing...
standard output
standard input
Python 3
Python
1,500
train_083.jsonl
3cd157b6a29ae11ee904ae9610000f06
512 megabytes
["5\n24 3 5\n10 3 6\n2345 1 4\n19260817 394 485\n19260817 233 264"]
PASSED
import sys input=sys.stdin.readline for _ in range(int(input())): n,a,b=map(int,input().split()) d={} x=1 while True: x=x*a if x<=n and x!=1: d[x]=0 else: break #print(d) y=0 for k in d: y=1 if (n%b==1) or ((n%b...
1625317500
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
3 seconds
["3\n1 3 7", "1\n5"]
faa26846744b7b7f90ba1b521fee0bc6
null
Polycarp invented a new way to encode strings. Let's assume that we have string T, consisting of lowercase English letters. Let's choose several pairs of letters of the English alphabet in such a way that each letter occurs in at most one pair. Then let's replace each letter in T with its pair letter if there is a pair...
Print number k β€” the number of suitable positions in string S. In the next line print k integers m1, m2, ..., mk β€” the numbers of the suitable positions in the increasing order.
The first line of the input contains two integers, |S| and |T| (1 ≀ |T| ≀ |S| ≀ 2Β·105) β€” the lengths of string S and string T, respectively. The second and third line of the input contain strings S and T, respectively. Both strings consist only of lowercase English letters.
standard output
standard input
PyPy 2
Python
2,400
train_040.jsonl
308d274e59cf2b8cf47f26b2d39d3cdb
256 megabytes
["11 5\nabacabadaba\nacaba", "21 13\nparaparallelogramgram\nqolorreraglom"]
PASSED
raw_input() ss = raw_input() tt = raw_input() def df(s): c = {} res = [] for i, x in enumerate(s): res.append(i - c[x] if x in c else 0) c[x] = i return res s = df(ss) t = df(tt) p = [] l = [] for i, x in enumerate(t): if not x: p.append(i) l.append(ord(tt[i]) - 97)...
1429286400
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["9", "14", "448201910"]
fbb6d21b757d8d56396af1253ec9e719
NoteIn the first example, the elements smaller than $$$2^4$$$ are $$$\{1, 3, 4, 6, 7, 9, 12, 13, 15\}$$$.In the second example, the elements smaller than $$$2^7$$$ are $$$\{5,11,20,23,39,41,44,47,79,80,83,89,92,95\}$$$.
You are given an array $$$a$$$ consisting of $$$n$$$ distinct positive integers.Let's consider an infinite integer set $$$S$$$ which contains all integers $$$x$$$ that satisfy at least one of the following conditions: $$$x = a_i$$$ for some $$$1 \leq i \leq n$$$. $$$x = 2y + 1$$$ and $$$y$$$ is in $$$S$$$. $$$x = 4y$$$...
Print a single integer, the number of elements in $$$S$$$ that are strictly smaller than $$$2^p$$$. Remember to print it modulo $$$10^9 + 7$$$.
The first line contains two integers $$$n$$$ and $$$p$$$ $$$(1 \leq n, p \leq 2 \cdot 10^5)$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ $$$(1 \leq a_i \leq 10^9)$$$. It is guaranteed that all the numbers in $$$a$$$ are distinct.
standard output
standard input
PyPy 3-64
Python
1,800
train_108.jsonl
e2bf28c0f855ccb4bb78b2d437d07090
256 megabytes
["2 4\n6 1", "4 7\n20 39 5 200", "2 200000\n48763 1000000000"]
PASSED
import sys from array import array class dict_(dict): def __missing__(self, key): return 0 mod = 10 ** 9 + 7 add = lambda a, b: (a % mod + b % mod) % mod mult = lambda a, b: (a % mod * b % mod) % mod input = lambda: sys.stdin.buffer.readline().decode().strip() n, p = map(int, input().spli...
1645367700
[ "number theory", "math", "strings" ]
[ 0, 0, 0, 1, 1, 0, 1, 0 ]
1.5 seconds
["6", "-1", "5"]
aba6e64e040952b88e7dcb95e4472e56
NoteIn the first example the answer is $$$6$$$ since it divides $$$18$$$ from the first pair, $$$24$$$ from the second and $$$12$$$ from the third ones. Note that other valid answers will also be accepted.In the second example there are no integers greater than $$$1$$$ satisfying the conditions.In the third example one...
During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mathematician, introduced a brand new concept of the weakened common divisor (WCD) of a list of pairs of integers.For a given list of pairs of integers $$$(a_1, b_1)$$$, $$$(a_2, b_2)$$$, ..., $$$(a_n, b_n)$$$ th...
Print a single integerΒ β€” the WCD of the set of pairs. If there are multiple possible answers, output any; if there is no answer, print $$$-1$$$.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 150\,000$$$)Β β€” the number of pairs. Each of the next $$$n$$$ lines contains two integer values $$$a_i$$$, $$$b_i$$$ ($$$2 \le a_i, b_i \le 2 \cdot 10^9$$$).
standard output
standard input
Python 2
Python
1,600
train_010.jsonl
f392c1dfb3b2e547acebc963d48c5606
256 megabytes
["3\n17 18\n15 24\n12 15", "2\n10 16\n7 17", "5\n90 108\n45 105\n75 40\n165 175\n33 30"]
PASSED
def gcd(a,b): if b==0:return a return gcd(b,a%b) n=int(raw_input()) d = 0 prime_lim = 0 nums = [] for i in xrange(n): a,b=map(int,raw_input().split()) nums.append((a,b)) d = gcd(d, a*b) prime_lim=max(prime_lim,a,b) k = int(prime_lim**0.5)+5 k=min(k,d-1) for i in xrange(2,k+1): if d%i==0: ...
1534685700
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
3 seconds
["6\n12\n9\n-1\n10\n7"]
d665ecbf36cc0c0ddd148137fb693bf2
NoteFor the first test case, we can choose $$$i = j = 3$$$, with sum of indices equal to $$$6$$$, since $$$1$$$ and $$$1$$$ are coprime.For the second test case, we can choose $$$i = 7$$$ and $$$j = 5$$$, with sum of indices equal to $$$7 + 5 = 12$$$, since $$$7$$$ and $$$4$$$ are coprime.
Given an array of $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 1000$$$). Find the maximum value of $$$i + j$$$ such that $$$a_i$$$ and $$$a_j$$$ are coprime,$$$^{\dagger}$$$ or $$$-1$$$ if no such $$$i$$$, $$$j$$$ exist.For example consider the array $$$[1, 3, 5, 2, 4, 7, 7]$$$. The maximum va...
For each test case, output a single integer Β β€” the maximum value of $$$i + j$$$ such that $$$i$$$ and $$$j$$$ satisfy the condition that $$$a_i$$$ and $$$a_j$$$ are coprime, or output $$$-1$$$ in case no $$$i$$$, $$$j$$$ satisfy the condition.
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 2\cdot10^5$$$)Β β€” the length of the array. The following lin...
standard output
standard input
PyPy 3-64
Python
1,100
train_099.jsonl
da7e17c0e53313bf640e667debf2484a
256 megabytes
["6\n\n3\n\n3 2 1\n\n7\n\n1 3 5 2 4 7 7\n\n5\n\n1 2 3 4 5\n\n3\n\n2 2 4\n\n6\n\n5 4 3 15 12 16\n\n5\n\n1 2 2 3 6"]
PASSED
num = int(input()) res = [] factors = [{1}, {1, 2}, {1, 3}, {1, 2}, {1, 5}, {1, 2, 3}, {1, 7}, {1, 2}, {1, 3}, {1, 2, 5}, {1, 11}, {1, 2, 3}, {1, 13}, {1, 2, 7}, {1, 3, 5}, {1, 2}, {1, 17}, {1, 2, 3}, {1, 19}, {1, 2, 5}, {1, 3, 7}, {1, 2, 11}, {1, 23}, {1, 2, 3}, {1, 5}, {1, 2, 13}, {1, 3}, {1, 2, 7}, {1, 29}, {1, 2,...
1665671700
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
7 seconds
["3", "1"]
4fb83b890e472f86045981e1743ddaac
NoteIn the first sample, Jacob can root the tree at node 2 and order 2's neighbors in the order 4, 1, 5 (all other nodes have at most two neighbors). The resulting preorder traversal is 2, 4, 1, 3, 5, and the minimum ai of the first 3 nodes is 3.In the second sample, it is clear that any preorder traversal will contain...
For his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent ai minutes building the i-th ball in the tree.Jacob's teacher will evaluate his model and grade Jacob based on the effort he has put in. However, she does not have enough time to se...
Print a single integerΒ β€” the maximum grade Jacob can get by picking the right root of the tree and rearranging the list of neighbors.
The first line of the input contains two positive integers, n and k (2 ≀ n ≀ 200 000, 1 ≀ k ≀ n)Β β€” the number of balls in Jacob's tree and the number of balls the teacher will inspect. The second line contains n integers, ai (1 ≀ ai ≀ 1 000 000), the time Jacob used to build the i-th ball. Each of the next n - 1 lines ...
standard output
standard input
PyPy 3
Python
2,600
train_062.jsonl
002239c9a0001f9102742563ffdc91d1
256 megabytes
["5 3\n3 6 1 4 2\n1 2\n2 4\n2 5\n1 3", "4 2\n1 5 5 5\n1 2\n1 3\n1 4"]
PASSED
import sys input = sys.stdin.readline n, k = map(int, input().split()) a = [int(i) for i in input().split()] g = [[] for _ in range(n)] for i in range(n - 1): u, v = map(int, input().split()) g[u-1].append(v-1) g[v-1].append(u-1) stack = [0] done = [False] * n par = [0] * n order = [] while len(stack) > 0: x = sta...
1456683000
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1.5 seconds
["2", "1"]
931bf7141636a7222f9043c8ba94830f
NoteIn the first test, tasks 1 and 3 can only be executed on the coprocessor. The dependency graph is linear, so the tasks must be executed in order 3 -&gt; 2 -&gt; 1 -&gt; 0. You have to call coprocessor twice: first you call it for task 3, then you execute task 2 on the main processor, then you call it for for task 1...
You are given a program you want to execute as a set of tasks organized in a dependency graph. The dependency graph is a directed acyclic graph: each task can depend on results of one or several other tasks, and there are no directed circular dependencies between tasks. A task can only be executed if all tasks it depen...
Output one line containing an integer β€” the minimal number of coprocessor calls necessary to execute the program.
The first line contains two space-separated integers N (1 ≀ N ≀ 105) β€” the total number of tasks given, and M (0 ≀ M ≀ 105) β€” the total number of dependencies between tasks. The next line contains N space-separated integers . If Ei = 0, task i can only be executed on the main processor, otherwise it can only be execute...
standard output
standard input
Python 3
Python
1,900
train_025.jsonl
e78c659f3af6396f973f65d0a7e2a9a5
256 megabytes
["4 3\n0 1 0 1\n0 1\n1 2\n2 3", "4 3\n1 1 1 0\n0 1\n0 2\n3 0"]
PASSED
n, m = (int(x) for x in input().strip().split()) coproc = [int(x) for x in input().strip().split()] edges = [] for _ in range(m): edges.append((int(x) for x in input().strip().split())) inorder = [0] * n adj = [[] for _ in range(n)] for u, v in edges: adj[v].append(u) inorder[u] += 1 queue0 = [u for u in r...
1514392500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1.5 seconds
["4 6 8 1\n4 9 9 9\n4 10 10 65\n1 4 4 4\n1 1\n1 1"]
df6ee0d8bb25dc2040adf1f115f4a83b
null
Sasha likes investigating different math objects, for example, magic squares. But Sasha understands that magic squares have already been studied by hundreds of people, so he sees no sense of studying them further. Instead, he invented his own type of squareΒ β€” a prime square. A square of size $$$n \times n$$$ is called ...
For each test case print $$$n$$$ lines, each containing $$$n$$$ integersΒ β€” the prime square you built. If there are multiple answers, print any.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10$$$)Β β€” the number of test cases. Each of the next $$$t$$$ lines contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$)Β β€” the required size of a square.
standard output
standard input
PyPy 3
Python
900
train_008.jsonl
efe8594d7ba75ff3e580a1fb2d1f0840
256 megabytes
["2\n4\n2"]
PASSED
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools # import time,random,resource # sys.setrecursionlimit(10**6) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 mod2 = 998244353 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(...
1603548300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["3\n0\n1\n0"]
6324ca46b6f072f8952d2619cb4f73e6
NoteTest cases of the example are described in the statement.
The game of Berland poker is played with a deck of $$$n$$$ cards, $$$m$$$ of which are jokers. $$$k$$$ players play this game ($$$n$$$ is divisible by $$$k$$$).At the beginning of the game, each player takes $$$\frac{n}{k}$$$ cards from the deck (so each card is taken by exactly one player). The player who has the maxi...
For each test case, print one integer β€” the maximum number of points a player can get for winning the game.
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 500$$$) β€” the number of test cases. Then the test cases follow. Each test case contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \le n \le 50$$$, $$$0 \le m \le n$$$, $$$2 \le k \le n$$$, $$$k$$$ is a divisors of $$$n$$$).
standard output
standard input
PyPy 3
Python
1,000
train_003.jsonl
c7585a4155feb577420a0a70d512580c
256 megabytes
["4\n8 3 2\n4 2 4\n9 6 3\n42 0 7"]
PASSED
for i in range(int(input())): n,m,k = [int(i) for i in input().split()] card = n//k if m<=card: print(m) elif card == 1: print(0) else: rem = (m-card)//(k-1) if (m-card)%(k-1) != 0: rem += 1 # print(rem,m,k) print(card-rem)
1590676500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["YES\n9 5\n1 9", "NO", "YES"]
8a3803f1202c276bbae90552372af041
NoteConsider the first sample. Before the reform the Foolland consists of four regions. The first region includes cities 1, 2, 3, the second region has cities 4 and 6, the third region has cities 5, 7, 8, the fourth region has city 9. The total length of the roads in these cities is 11, 20, 5 and 0, correspondingly. Ac...
You must have heard all about the Foolland on your Geography lessons. Specifically, you must know that federal structure of this country has been the same for many centuries. The country consists of n cities, some pairs of cities are connected by bidirectional roads, each road is described by its length li.The fools li...
If constructing the roads in the required way is impossible, print a single string "NO" (without the quotes). Otherwise, in the first line print word "YES" (without the quotes), and in the next p lines print the road construction plan. Each line of the plan must consist of two distinct integers, giving the numbers of t...
The first line contains four integers n (1 ≀ n ≀ 105), m (0 ≀ m ≀ 105), p (0 ≀ p ≀ 105), q (1 ≀ q ≀ n) β€” the number of cities in the Foolland, the number of existing roads, the number of roads that are planned to construct and the required number of regions. Next m lines describe the roads that exist by the moment upgr...
standard output
standard input
Python 2
Python
2,100
train_079.jsonl
1dbd8c48d096f99099745b28b0683296
256 megabytes
["9 6 2 2\n1 2 2\n3 2 1\n4 6 20\n1 3 8\n7 8 3\n5 7 2", "2 0 1 2", "2 0 0 2"]
PASSED
from sys import stdin, stdout, setrecursionlimit from heapq import heapify, heappop, heappush setrecursionlimit(100000) def main(): read_ints = lambda: map(int, stdin.readline().split()) n, m, p, q = read_ints() par = range(n) s = [0] * n def find(x): if x == par[x]: return x ...
1384443000
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["3\n4\n1"]
cf3cfcae029a6997ee62701eda959a60
NoteFirst test case: $$$a=[3,4,2,4,1,2]$$$ take $$$a_3, a_5$$$ and perform an operation plus one on them, as a result we get $$$a=[3,4,3,4,2,2]$$$. $$$a=[3,4,3,4,2,2]$$$ we take $$$a_1, a_5, a_6$$$ and perform an operation on them plus one, as a result we get $$$a=[4,4,3,4,3,3]$$$. $$$a=[4,4,3,4,3,3]$$$ we take $$$...
Polycarp got an array of integers $$$a[1 \dots n]$$$ as a gift. Now he wants to perform a certain number of operations (possibly zero) so that all elements of the array become the same (that is, to become $$$a_1=a_2=\dots=a_n$$$). In one operation, he can take some indices in the array and increase the elements of the ...
For each test case, print one integer Β β€” the minimum number of operations to make all elements of the array $$$a$$$ equal.
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) Β β€” the number of test cases in the test. The following are descriptions of the input test cases. The first line of the description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) Β β€” the array $$$a$$$. The second...
standard output
standard input
PyPy 3-64
Python
800
train_102.jsonl
85fd523ebb4027b18a35e104fb656f64
256 megabytes
["3\n6\n3 4 2 4 1 2\n3\n1000 1002 998\n2\n12 11"]
PASSED
import sys from os import path FILE = False # if needed change it while submitting if FILE: sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') def get_int(): return int(sys.stdin.readline()) def get_string(): return sys.stdin.readline().split(" ") n = get_int() ...
1641825300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES\nYES\nNO\nYES\nYES"]
08783e3dff3f3b7eb586931f9d0cd457
null
You are given $$$4n$$$ sticks, the length of the $$$i$$$-th stick is $$$a_i$$$.You have to create $$$n$$$ rectangles, each rectangle will consist of exactly $$$4$$$ sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that ea...
For each query print the answer to it. If it is impossible to create exactly $$$n$$$ rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) β€” 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 rectangles. The second line of the query contains $$$4n$$$ integers $$$a_1, a_2, \dots, ...
standard output
standard input
PyPy 3
Python
1,200
train_007.jsonl
0cf907487fc2c9284698ec9566c943b0
256 megabytes
["5\n1\n1 1 10 10\n2\n10 5 2 10 1 1 2 5\n2\n10 5 1 10 5 1 1 1\n2\n1 1 1 1 1 1 1 1\n1\n10000 10000 10000 10000"]
PASSED
q = int(input()) while q > 0: q -= 1 n = int(input()) arr = list(map(int, input().split())) arr.sort() front = 0 end = len(arr) - 1 area = arr[front] * arr[end] possible = arr[front] == arr[front + 1] and arr[end] == arr[end - 1] front += 2 end -= 2 while possible and...
1565706900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1 2 4", "-1", "5"]
1b975c5a13a2ad528b668a7c68c089f6
NoteThe deletion process in the first example is as follows (see the picture below, the vertices with $$$c_i=1$$$ are in yellow): first you will delete the vertex $$$1$$$, because it does not respect ancestors and all its children (the vertex $$$2$$$) do not respect it, and $$$1$$$ is the smallest index among such ver...
You are given a rooted tree with vertices numerated from $$$1$$$ to $$$n$$$. A tree is a connected graph without cycles. A rooted tree has a special vertex named root.Ancestors of the vertex $$$i$$$ are all vertices on the path from the root to the vertex $$$i$$$, except the vertex $$$i$$$ itself. The parent of the ver...
In case there is at least one vertex to delete, print the only line containing the indices of the vertices you will delete in the order you delete them. Otherwise print a single integer $$$-1$$$.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β€” the number of vertices in the tree. The next $$$n$$$ lines describe the tree: the $$$i$$$-th line contains two integers $$$p_i$$$ and $$$c_i$$$ ($$$1 \le p_i \le n$$$, $$$0 \le c_i \le 1$$$), where $$$p_i$$$ is the parent of the vertex $$$i$$$,...
standard output
standard input
Python 3
Python
1,400
train_014.jsonl
8de7006540ed447bd5102841567c1e65
256 megabytes
["5\n3 1\n1 1\n-1 0\n2 1\n3 0", "5\n-1 0\n1 1\n1 1\n2 0\n3 0", "8\n2 1\n-1 0\n1 0\n1 1\n1 1\n4 0\n5 1\n7 0"]
PASSED
from heapq import * n = int(input()) pred = [[] for i in range(n + 1)] g = [[] for i in range(n + 1)] for i in range(1, n + 1): p, c = map(int, input().split()) pred[i] = [p, c] if p != -1: g[p].append([i, c]) heap = [] for i in range(1, n + 1): if pred[i][1] == 1: ok = True for...
1553965800
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["fzfsirk", "xxxxxx", "ioi"]
bc3d0d902ef457560e444ec0128f0688
NoteOne way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. T...
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each...
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
The first line of input contains a string s of length n (1 ≀ n ≀ 3Β·105). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially. The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This strin...
standard output
standard input
Python 3
Python
1,800
train_027.jsonl
beafbd9cc504a3d4b02f60ea9511b432
256 megabytes
["tinkoff\nzscoder", "xxxxxx\nxxxxxx", "ioi\nimo"]
PASSED
s1 = input() s2 = input() n = len(s1) s1 = sorted(s1) s2 = sorted(s2)[::-1] i = 0 j = 0 res = ["?"]*n rear = n-1 front = 0 Neven = n % 2 == 0 n1 = (n+1)//2 - 1 n2 = n//2 - 1 for k in range(n): if k % 2 == 0: if s1[i] < s2[j]: res[front] = s1[i] front += 1 i += 1 ...
1494668100
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
2 seconds
["Yes", "No"]
82ff8ae62e39b8e64f9a273b736bf59e
NoteBoth sample tests have the same tree in them.In this tree, there are two valid BFS orderings: $$$1, 2, 3, 4$$$, $$$1, 3, 2, 4$$$. The ordering $$$1, 2, 4, 3$$$ doesn't correspond to any valid BFS order.
The BFS algorithm is defined as follows. Consider an undirected graph with vertices numbered from $$$1$$$ to $$$n$$$. Initialize $$$q$$$ as a new queue containing only vertex $$$1$$$, mark the vertex $$$1$$$ as used. Extract a vertex $$$v$$$ from the head of the queue $$$q$$$. Print the index of vertex $$$v$$$. Ite...
Print "Yes" (quotes for clarity) if the sequence corresponds to some valid BFS traversal of the given tree and "No" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower).
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) which denotes the number of nodes in the tree. The following $$$n - 1$$$ lines describe the edges of the tree. Each of them contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le n$$$)Β β€” the endpoints of the corresponding edge of t...
standard output
standard input
PyPy 3
Python
1,700
train_036.jsonl
006986bc020f21e59863137886e85a15
256 megabytes
["4\n1 2\n1 3\n2 4\n1 2 3 4", "4\n1 2\n1 3\n2 4\n1 2 4 3"]
PASSED
from collections import deque from sys import stdin input = stdin.readline class N: def __init__(self, v) -> None: self.c = [] self.v = v if __name__ == '__main__': n = int(input()) arr = [N(i + 1) for i in range(n)] for _ in range(n - 1): x, y = map(int, input().split()) ...
1535898900
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
2 seconds
["Yes\n0 2\n2 0", "Yes\n0 -1\n-1 0", "Yes\n0 1\n1 0", "No"]
6527406424b003cab6a1defdddb53525
null
Dima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number of bacteria of type i equals ci. For convenience, we will assume that all the bacteria are numbered from 1 to n. The bacteria of type ci are nu...
If Dima's type-distribution is correct, print string Β«YesΒ», and then k lines: in the i-th line print integers d[i][1], d[i][2], ..., d[i][k] (d[i][i] = 0). If there is no way to move energy from bacteria i to bacteria j appropriate d[i][j] must equal to -1. If the type-distribution isn't correct print Β«NoΒ».
The first line contains three integers n, m, k (1 ≀ n ≀ 105;Β 0 ≀ m ≀ 105;Β 1 ≀ k ≀ 500). The next line contains k integers c1, c2, ..., ck (1 ≀ ci ≀ n). Each of the next m lines contains three integers ui, vi, xi (1 ≀ ui, vi ≀ 105;Β 0 ≀ xi ≀ 104). It is guaranteed that .
standard output
standard input
PyPy 3
Python
2,000
train_064.jsonl
3ccce024c031eff1a6ace78e7fdd33ea
256 megabytes
["4 4 2\n1 3\n2 3 0\n3 4 0\n2 4 1\n2 1 2", "3 1 2\n2 1\n1 2 0", "3 2 2\n2 1\n1 2 0\n2 3 1", "3 0 2\n1 2"]
PASSED
#!/usr/bin/env python3 from sys import stdin from bisect import bisect_left, bisect_right INF = int(1e9) def find(par, a): if par[a] == a: return a par[a] = find(par, par[a]) return par[a] def union(par, rnk, a, b): a = find(par,a) b = find(par,b) if a==b: return ...
1394033400
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["9"]
f9a691cdf7047ab82d2e2c903a53fc7e
null
As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie and the Piglet asked to come at the Rabbit's place. Thus, there are n jars of honey lined up in front of Winnie-t...
Print a single number β€” how many kilos of honey gets Piglet.
The first line contains two integers n and k (1 ≀ n ≀ 100, 1 ≀ k ≀ 100). The second line contains n integers a1, a2, ..., an, separated by spaces (1 ≀ ai ≀ 100).
output.txt
input.txt
Python 3
Python
1,100
train_060.jsonl
2f7865ae44a3f5c4fa43aed9efb9b637
256 megabytes
["3 3\n15 8 10"]
PASSED
import sys sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") x,y = map(int,input().split()) l = list(map(int,input().split())) for i in range(x): if l[i]//y>=3: l[i] = l[i] - y*3 else: l[i] = l[i] -y*(l[i]//y) print(sum(l))
1318919400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES\nYES\nYES\nYES\nNO\nYES\nYES\nYES"]
7e23e222ce40547ed8a4f7f1372082d9
null
You are given a pair of integers $$$(a, b)$$$ and an integer $$$x$$$.You can change the pair in two different ways: set (assign) $$$a := |a - b|$$$; set (assign) $$$b := |a - b|$$$, where $$$|a - b|$$$ is the absolute difference between $$$a$$$ and $$$b$$$.The pair $$$(a, b)$$$ is called $$$x$$$-magic if $$$x$$$ is...
For the $$$i$$$-th test case, print YES if the corresponding pair $$$(a, b)$$$ is $$$x$$$-magic 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. The only line of the test case contains three integers $$$a$$$, $$$b$$$ and $$$x$$$ ($$$1 \le a, b, x \le 10^{18}$$$).
standard output
standard input
PyPy 3-64
Python
1,600
train_098.jsonl
e80e36cb80590832936472243f0f39fc
512 megabytes
["8\n6 9 3\n15 38 7\n18 8 8\n30 30 30\n40 50 90\n24 28 20\n365 216 52\n537037812705867558 338887693834423551 3199921013340"]
PASSED
# def naiveGetPossible(a, b): # st = [(a, b)] # possible = set() # possible.add((a, b)) # while st: # a, b = st.pop() # diff = abs(a - b) # if (diff, b) not in possible: # possible.add((diff, b)) # st.append((diff, b)) # if (a, diff) no...
1637573700
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["4", "-1", "-1", "24"]
35b9acbe61226923a0c45452f23166c8
NoteIn the first example we can shift upper sunbed to the left and lower sunbedΒ β€” to the right. Andrew will be able to put his sunbed vertically in the middle of the beach. We well cause $$$2 + 2 = 4$$$ units of discomfort. It is easy to prove that it is an optimal answer. Optimal strategy in the first example (Andr...
Andrew loves the sea. That's why, at the height of the summer season, he decided to go to the beach, taking a sunbed with him to sunbathe.The beach is a rectangular field with $$$n$$$ rows and $$$m$$$ columns. Some cells of the beach are free, some have roads, stones, shops and other non-movable objects. Some of two ad...
Print one integerΒ β€” the minimum possible number of units of discomfort, caused to other tourists, to free a space for a sunbed. If it is impossible to free a space for a sunbed, print $$$-1$$$.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 300\,000$$$, $$$1 \le n \cdot m \le 300\,000$$$)Β β€” the number of rows and columns in rectangle. The second line contains two integers $$$p$$$ and $$$q$$$ ($$$1 \le p, q \le 10^9$$$)Β β€” the number of units of discomfort caused by rotation and shi...
standard output
standard input
PyPy 3-64
Python
2,400
train_100.jsonl
4ac5d49ada70d5e80a4e6a60eb15c0aa
256 megabytes
["2 5\n\n5 2\n\n.LR##\n\n##LR.", "2 3\n\n4 5\n\nLR.\n\n#.#", "4 3\n\n10 10\n\n.LR\n\n###\n\nUU#\n\nDD.", "3 6\n\n10 7\n\n.U##.#\n\n#DLR##\n\n.##LR."]
PASSED
import heapq import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v): return u * m + v def dijkstra(): dist = [inf] * l visit = [0] * l h = [] for i in range(n): si = s[i] for j in range(m): if si[j] == 46: ...
1666511400
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["1\n0\n0\n0\n9"]
e094a3451b8b28be90cf54a4400cb916
null
You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep line up. The level in the game is described by a string of length $$$n$$$, consisting of the characters '.' (empty space) and '*' (sheep). In one move, you can move any sheep one square to the left or one square to the right, if ...
For each test case output the minimum number of moves you need to make to complete the level.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^6$$$). The second line of each test case contains a string of length $$$n$$$, consisting of the characters '.' (empty space) and '*' (she...
standard output
standard input
Python 3
Python
1,400
train_083.jsonl
d13b3dfc8cb4966afece76d6536b266e
256 megabytes
["5\n6\n**.*..\n5\n*****\n3\n.*.\n3\n...\n10\n*.*...*.**"]
PASSED
def get_shifts(sheep_row): sheep_count = 0 last_sheep_position = None shifts = [] for idx in range(len(sheep_row)-1, -1, -1): if sheep_row[idx] == '*': if sheep_count > 0: diff = last_sheep_position - idx - 1 shift = diff * sheep_count + shifts...
1620225300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1 8", "1 1", "23 128"]
7eb2089c972cdf668a33a53e239da440
NoteIn the first sample case, there are 23 = 8 days in Udayland. The probability that 2 people have the same birthday among 2 people is clearly , so A = 1, B = 8.In the second sample case, there are only 21 = 2 days in Udayland, but there are 3 people, so it is guaranteed that two of them have the same birthday. Thus, ...
ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interesting, and decides to test this with the inhabitants of Udayland.In Udayland, t...
If the probability of at least two k people having the same birthday in 2n days long year equals (A β‰₯ 0, B β‰₯ 1, ), print the A and B in a single line. Since these numbers may be too large, print them modulo 106 + 3. Note that A and B must be coprime before their remainders modulo 106 + 3 are taken.
The first and only line of the input contains two integers n and k (1 ≀ n ≀ 1018, 2 ≀ k ≀ 1018), meaning that there are 2n days in a year and that ZS the Coder wants to interview exactly k people.
standard output
standard input
Python 3
Python
2,300
train_046.jsonl
1809996785ac8380ebb6189fa9860e49
256 megabytes
["3 2", "1 3", "4 3"]
PASSED
import math n, k = [int(x) for x in input().split()] if n<70 and k>2**n: print(1,1) exit(0) mod = int(1e6)+3 def fastpow(a,b): t, ans = a, 1 while b: if(b&1): ans = ans*t%mod t = t*t %mod b>>=1 return ans t=k-1 cnt=0 while t: cnt += t>>1 t>>=1 x=0 t=fas...
1472472300
[ "number theory", "math", "probabilities" ]
[ 0, 0, 0, 1, 1, 1, 0, 0 ]
2 seconds
["2", "3", "0"]
2bb43eb088051e08a678f7a97ef1eeff
NoteIn the first sample, it is possible to move to the right at maximum speed for the first $$$3.5$$$ seconds and stay at position $$$7$$$ until the first kick happens, and then immediately move right also at maximum speed to watch the second kick at position $$$17$$$. There is no way to monitor closely the third kick ...
The derby between Milan and Inter is happening soon, and you have been chosen as the assistant referee for the match, also known as linesman. Your task is to move along the touch-line, namely the side of the field, always looking very carefully at the match to check for offside positions and other offences.Football is ...
Print the maximum number of kicks that you can monitor closely.
The first line contains two integers $$$n$$$ and $$$v$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le v \le 10^6$$$) β€” the number of kicks that will take place and your maximum speed. The second line contains $$$n$$$ integers $$$t_1, \ldots, t_n$$$ ($$$1 \le t_i \le 10^9$$$) β€” the times of the kicks in the match. The sequ...
standard output
standard input
PyPy 3-64
Python
-1
train_085.jsonl
6c14a0516ede60d51a73473c1a96ccc1
256 megabytes
["3 2\n5 10 15\n7 17 29", "5 1\n5 7 8 11 13\n3 3 -2 -2 4", "1 2\n3\n7"]
PASSED
from bisect import bisect_right,bisect_left n,v = map(int,input().split()) t = [*map(int,input().split())] a = [*map(int,input().split())] res = [] for i in range(n): xi,yi = t[i]*v+a[i],t[i]*v-a[i] if(xi>=0 and yi>=0): res.append((xi,yi)) res.sort() dp = [float("inf")]*(n+3) dp[0] = 0 dp[n+...
1650798300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1\n0\n2\n2\n1"]
fcd55a1ca29e96c05a3b65b7a8103842
NoteIn the first test case, you can just add $$$1$$$.In the second test case, you don't need to do anything.In the third test case, you can add $$$1$$$ two times.In the fourth test case, you can subtract $$$4$$$ and add $$$1$$$.In the fifth test case, you can just subtract $$$6$$$.
You are given two positive integers $$$a$$$ and $$$b$$$.In one move, you can change $$$a$$$ in the following way: Choose any positive odd integer $$$x$$$ ($$$x &gt; 0$$$) and replace $$$a$$$ with $$$a+x$$$; choose any positive even integer $$$y$$$ ($$$y &gt; 0$$$) and replace $$$a$$$ with $$$a-y$$$. You can perform a...
For each test case, print the answer β€” the minimum number of moves required to obtain $$$b$$$ from $$$a$$$ if you can perform any number of moves described in the problem statement. It is guaranteed that you can always obtain $$$b$$$ from $$$a$$$.
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case is given as two space-separated integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9$$$).
standard output
standard input
Python 3
Python
800
train_001.jsonl
b30489b19004696f28726ff02b504522
256 megabytes
["5\n2 3\n10 10\n2 4\n7 4\n9 3"]
PASSED
if __name__ == "__main__": n = int(input()) k = 0 s = [] for i in range(n): s.append(list(map(int,input().split()))) while k<n: count = 0 if s[k][0]==s[k][1]: pass elif s[k][0]>s[k][1]: diff = s[k][0]-s[k][1] count+=1 if diff % 2 != 0: ...
1582554900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
5 seconds
["3 3", "9 7", "2000000000 1", "1393 3876"]
3317413b2c38fff76f7816c3554e9862
NoteThe first test case was explained in the statement.In the second test case $$$p = [100, 101, 102, 103, 104, 105, 104, 103, 102, 103, 104, 105, 106, 107, 108]$$$.In the third test case $$$p = [1, 2, \ldots, 2000000000]$$$.
Igor had a sequence $$$d_1, d_2, \dots, d_n$$$ of integers. When Igor entered the classroom there was an integer $$$x$$$ written on the blackboard.Igor generated sequence $$$p$$$ using the following algorithm: initially, $$$p = [x]$$$; for each $$$1 \leq i \leq n$$$ he did the following operation $$$|d_i|$$$ times: ...
Print two integers: the first integer should be equal to the length of the longest increasing subsequence of $$$p$$$; the second should be equal to the number of them modulo $$$998244353$$$. You should print only the second number modulo $$$998244353$$$.
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)Β β€” the length of the sequence $$$d$$$. The second line contains a single integer $$$x$$$ ($$$-10^9 \leq x \leq 10^9$$$)Β β€” the integer on the blackboard. The third line contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$ ($$$-10^9 \leq d_i \leq 1...
standard output
standard input
PyPy 3
Python
3,000
train_100.jsonl
981b4dee6842c267e1d973d3bfa1535b
256 megabytes
["3\n3\n1 -1 2", "3\n100\n5 -3 6", "3\n1\n999999999 0 1000000000", "5\n34\n1337 -146 42 -69 228"]
PASSED
import sys, io, os if os.environ['USERNAME']=='kissz': inp=open('in55.txt','r').readline def debug(*args): print(*args,file=sys.stderr) else: inp=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def debug(*args): pass def mexp(size,power): A=[] for i in range(si...
1611066900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["8\n-1\n6\n0"]
f3c097872643f6fce645c05824b574e5
NoteIn the first test case, selecting indices $$$2$$$ and $$$3$$$ costs $$$8$$$, which is the minimum possible cost.In the second test case, we cannot make $$$a$$$ equal to $$$b$$$ using any number of operations.In the third test case, we can perform the following operations: Select indices $$$3$$$ and $$$6$$$. It cos...
This is the easy version of the problem. In this version, $$$n \le 3000$$$, $$$x \ge y$$$ holds. You can make hacks only if both versions of the problem are solved.You are given two binary strings $$$a$$$ and $$$b$$$, both of length $$$n$$$. You can do the following operation any number of times (possibly zero). Sele...
For each test case, if there is no way to make $$$a$$$ equal to $$$b$$$, print $$$-1$$$. Otherwise, print the minimum cost needed to make $$$a$$$ equal to $$$b$$$.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 600$$$)Β β€” the number of test cases. Each test case consists of three lines. The first line of each test case contains three integers $$$n$$$, $$$x$$$, and $$$y$$$ ($$$5 \le n \le 3000$$$, $$$1 \le y \le x \le 10^9$$$)Β β€” the length of the strings, and the costs...
standard output
standard input
PyPy 3-64
Python
1,400
train_104.jsonl
76fef8a51c5622b801e5f33b9e824dc3
512 megabytes
["4\n\n5 8 7\n\n01001\n\n00101\n\n5 7 2\n\n01000\n\n11011\n\n7 8 3\n\n0111001\n\n0100001\n\n5 10 1\n\n01100\n\n01100"]
PASSED
t=int(input()) while t>0: n,x,y=input().split(' ') a=input() b=input() n=int(n) x=int(x) y=int(y) indexes=[] for i in range(n): if a[i]!=b[i]: indexes.append(i) if len(indexes)==0: print(0) elif len(indexes)%2==1: print(-1) eli...
1663598100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1 2\n3 3 2 1"]
01703877719e19dd8551e4599c3e1c85
NoteIn the first test case, the array $$$[1,2]$$$ has sadness $$$1$$$. We can transform $$$[1,2]$$$ into $$$[2,1]$$$ using one operation with $$$(i,j)=(1,2)$$$.In the second test case, the array $$$[3,3,2,1]$$$ has sadness $$$2$$$. We can transform $$$[3,3,2,1]$$$ into $$$[1,2,3,3]$$$ with two operations with $$$(i,j)=...
oolimry has an array $$$a$$$ of length $$$n$$$ which he really likes. Today, you have changed his array to $$$b$$$, a permutation of $$$a$$$, to make him sad.Because oolimry is only a duck, he can only perform the following operation to restore his array: Choose two integers $$$i,j$$$ such that $$$1 \leq i,j \leq n$$...
For each test case, print $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ β€” describing the array $$$b$$$. If there are multiple answers, you may print any.
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) Β β€” the length of the array. Th...
standard output
standard input
Python 3
Python
2,000
train_108.jsonl
7dff26ed019f67ef30f11afa78e86cd6
256 megabytes
["2\n\n2\n\n2 1\n\n4\n\n1 2 3 3"]
PASSED
import sys def solve(): inp = sys.stdin.readline n = int(inp()) a = list(map(int, inp().split())) c = [[] for i in range(n + 1)] p = [None] * (n + 1) for i in range(n): c[a[i]].append(i) for i in range(n + 1): p[i] = (-len(c[i]), i) p.sort() b = [None] * n for k in range(-p[0][0]): pr = ...
1650722700
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
3.5 seconds
["0 0 0 2 4 \n0 91"]
a1effd6a0f6392f46f6aa487158fef7d
null
You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each qu...
For each test case, print $$$q$$$ integersΒ β€” the answers to the queries of this test case in the order they appear.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β€” the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$...
standard output
standard input
PyPy 3
Python
1,600
train_002.jsonl
e2ec8e8ce7c4e0e8f91c89e2b574231f
256 megabytes
["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"]
PASSED
import math t = int(input()) def get(A,B,N): if(N==-1): return 0; if(max(A,B) > N): return N + 1 GCD = int(math.gcd(A,B)) X = GCD * (A//GCD) * (B//GCD) Delta = min(max(A,B), N - N//X*X + 1) return max(A,B) + max(N//X-1,0)*max(A,B) + (Delta * int(N>=X)) for _ in range(t): a,...
1587911700
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["13\n1000000001000000000"]
ec8060260a6c7f4ff3e6afc9fd248afc
NoteIn the first test of the example Vasya can buy $$$9$$$ bars, get $$$3$$$ for free, buy another bar, and so he will get $$$13$$$ bars.In the second test Vasya buys $$$1000000000$$$ bars and gets $$$1000000000000000000$$$ for free. So he has $$$1000000001000000000$$$ bars.
There is a special offer in Vasya's favourite supermarket: if the customer buys $$$a$$$ chocolate bars, he or she may take $$$b$$$ additional bars for free. This special offer can be used any number of times.Vasya currently has $$$s$$$ roubles, and he wants to get as many chocolate bars for free. Each chocolate bar cos...
Print $$$t$$$ lines. $$$i$$$-th line should contain the maximum possible number of chocolate bars Vasya can get in $$$i$$$-th test.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β€” the number of testcases. Each of the next $$$t$$$ lines contains four integers $$$s, a, b, c~(1 \le s, a, b, c \le 10^9)$$$ β€” the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars y...
standard output
standard input
PyPy 3
Python
800
train_017.jsonl
3d3721be0db959d00108ab8da3a55101
256 megabytes
["2\n10 3 1 1\n1000000000 1 1000000000 1"]
PASSED
t = int(input()) for i in range(t): s, a, b, c = map(int, input().split()) e = s//c print((a + b) * (s // (c * a)) + e%a)
1539269400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1 2 3", "1 3"]
e54f8aff8ede309bd591cb9fbd565d1f
null
Tavas is a cheerleader in the new sports competition named "Pashmaks". This competition consists of two part: swimming and then running. People will immediately start running R meters after they finished swimming exactly S meters. A winner is a such person that nobody else finishes running before him/her (there may be...
In the first and the only line of output, print a sequence of numbers of possible winners in increasing order.
The first line of input contains a single integer n (1 ≀ n ≀ 2 × 105). The next n lines contain the details of competitors. i-th line contains two integers si and ri (1 ≀ si, ri ≀ 104).
standard output
standard input
PyPy 2
Python
2,600
train_001.jsonl
359fb4560b4295ccec3833b61cc4659d
256 megabytes
["3\n1 3\n2 2\n3 1", "3\n1 2\n1 1\n2 1"]
PASSED
from itertools import imap import sys n = input() def parseints(s, n): r, i, x = [0] * n, 0, 0 for c in imap(ord, s): if c == 32: r[i], i, x = x, i + 1, 0 else: x = x * 10 + c - 48 return r z = parseints(sys.stdin.read().replace('\n', ' '), n * 2) # p = zip(z[::2],...
1429029300
[ "geometry", "math" ]
[ 0, 1, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1\nabacaba", "4\naaaa", "0\nab"]
d467f457a462c83a1a0a6320494da811
NoteIn the first sample a necklace can have at most one beautiful cut. The example of such a necklace is shown on the picture.In the second sample there is only one way to compose a necklace.
Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remaining after this cut is a palindrome (reads the same forward and backward). ...
In the first line print a single numberΒ β€” the maximum number of beautiful cuts that a necklace composed from given beads may have. In the second line print any example of such necklace. Each color of the beads should be represented by the corresponding lowercase English letter (starting with a). As the necklace is cycl...
The first line of the input contains a single number n (1 ≀ n ≀ 26) β€” the number of colors of beads. The second line contains after n positive integers ai Β  β€” the quantity of beads of i-th color. It is guaranteed that the sum of ai is at least 2 and does not exceed 100 000.
standard output
standard input
Python 3
Python
2,500
train_007.jsonl
068c5c9991a9f854fc8287d1065d79d9
256 megabytes
["3\n4 2 1", "1\n4", "2\n1 1"]
PASSED
import math #import fractions from functools import reduce n = int(input()) odd = -1 beads = [int(x) for x in input().split()] for i in range(n): if beads[i]%2: if odd >= 0: print(0) print(''.join(chr(ord('a') + i)*beads[i] for i in range(n))) break else: ...
1452789300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2 4", "2", "-1", "3", "-1"]
aa1ed95ea1a0b7b7de62673625f38132
null
Dima is a good person. In fact, he's great. But all good things come to an end...Seryozha is going to kick Dima just few times.. For this reason he divides the room into unit squares. Now the room is a rectangle n × m consisting of unit squares.For the beginning, Seryozha put Dima in a center of some square. Then he st...
In a single line in accending order print all k (k &gt; 1), which matches the Dima's notes. If there are no such k and Dima invented this story with kicks, print -1.
The first line contains n and m (1 ≀ n, m ≀ 103) β€” size of the room. Next n lines goes, each contains m numbers aij β€” Dima's notes: aij = 1, if Dima was staying in the square (i, j) or was flying above it. Otherwise aij = 0. At least one aij equals 1.
standard output
standard input
Python 2
Python
2,300
train_069.jsonl
9ade274969c0afaac2c9dd8806bc8d38
256 megabytes
["5 5\n1 1 1 1 1\n1 0 0 0 1\n1 0 0 0 1\n1 0 0 0 1\n1 1 1 1 1", "7 7\n0 0 1 1 1 0 0\n0 0 1 0 1 0 0\n1 1 1 1 1 1 1\n1 0 1 0 1 0 1\n1 1 1 1 1 1 1\n0 0 1 0 1 0 0\n0 0 1 1 1 0 0", "3 3\n1 1 1\n1 1 1\n1 1 1", "4 4\n1 1 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0", "5 5\n0 0 1 0 0\n0 0 1 0 0\n1 1 1 1 1\n0 0 1 0 0\n0 0 1 0 0"]
PASSED
import sys sys.setrecursionlimit(10**6) def main(): n, m = map(int, raw_input().split()) a = [raw_input().split() for _ in xrange(n)] dd = [(1,0), (0,1)] od = 0 D = [[[] for _ in xrange(m)] for _ in xrange(n)] done = [[False] * m for _ in xrange(n)] par = range(n * m) rank = [0] * (n * m...
1382715000
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["4427477", "4478"]
8ce1ba0a98031c1bc28f53c11905391c
NoteIn the first sample the number changes in the following sequence: 4727447 → 4427447 → 4427477 → 4427447 → 4427477.In the second sample: 4478 → 4778 → 4478.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has a number consisting of n digits without leading zeroes. He represented it as an array of dig...
In the single line print the result without spaces β€” the number after the k operations are fulfilled.
The first line contains two integers n and k (1 ≀ n ≀ 105, 0 ≀ k ≀ 109) β€” the number of digits in the number and the number of completed operations. The second line contains n digits without spaces representing the array of digits d, starting with d1. It is guaranteed that the first digit of the number does not equal z...
standard output
standard input
Python 3
Python
1,500
train_021.jsonl
f1e020a8afc8535f9b870a7df58949d8
256 megabytes
["7 4\n4727447", "4 2\n4478"]
PASSED
# 447 or 477 start with odd n, k = map(int, input().split()) s = input() s = list(s) for i in range(n - 1): if not k: break if s[i] != '4': continue tt = ''.join(s[i:i + 3]) if tt in ('447', '477') and i % 2 == 0: if k % 2 == 1 and tt == '447': s[i + 1] = '7' ...
1319727600
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["45", "-1"]
64625b26514984c4425c2813612115b3
NoteIn the first test, the optimal route is: Β Β Β Β  for the first green light, go to $$$7$$$ and return to $$$3$$$. In this case, we will change the direction of movement at the point $$$7$$$, which is allowed, since there is a safety island at this point. In the end, we will be at the point of $$$3$$$, where there is a...
If the girl doesn't go to Denis, then Denis will go to the girl. Using this rule, the young man left home, bought flowers and went to Nastya. On the way from Denis's house to the girl's house is a road of $$$n$$$ lines. This road can't be always crossed in one green light. Foreseeing this, the good mayor decided to pl...
Output a single integer Β β€” the minimum time for which Denis can cross the road with obeying all the rules. If it is impossible to cross the road output $$$-1$$$.
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \leq n \leq 10^6, 2 \leq m \leq min(n + 1, 10^4))$$$ Β β€” road width and the number of safety islands. The second line contains $$$m$$$ distinct integers $$$d_1, d_2, \ldots, d_m$$$ $$$(0 \leq d_i \leq n)$$$ Β β€” the points where the safety islands are located....
standard output
standard input
PyPy 3
Python
2,400
train_000.jsonl
9f6be0f2190dd59bef5b14e895e712b1
256 megabytes
["15 5\n0 3 7 14 15\n11 11", "13 4\n0 3 7 13\n9 9"]
PASSED
import collections n,m=map(int,input().split()) m+=2 arr=list(map(int,input().split())) arr.append(0) arr.append(n) arr=sorted(arr) g,r=map(int,input().split()) q=collections.deque() q.append((0,0)) dist=[[0]*(g+1) for _ in range(m+2)] checked=[[0]*(g+1) for _ in range(m+2)] checked[0][0]=1 ans=-1 while len(q)!=0: v...
1587653100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1.5 seconds
["1\n3\n3"]
107773724bd8a898f9be8fb3f9ee9ac9
NoteFor first test case, $$$1$$$ is the only number and therefore lonely.For second test case where $$$n=5$$$, numbers $$$1$$$, $$$3$$$ and $$$5$$$ are lonely.For third test case where $$$n=10$$$, numbers $$$1$$$, $$$5$$$ and $$$7$$$ are lonely.
In number world, two different numbers are friends if they have a lot in common, but also each one has unique perks.More precisely, two different numbers $$$a$$$ and $$$b$$$ are friends if $$$gcd(a,b)$$$, $$$\frac{a}{gcd(a,b)}$$$, $$$\frac{b}{gcd(a,b)}$$$ can form sides of a triangle.Three numbers $$$a$$$, $$$b$$$ and ...
For each test case, print the answer on separate lines: number of lonely numbers in group $$$1, 2, 3, ..., n_i$$$.
The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^6)$$$ - number of test cases. On next line there are $$$t$$$ numbers, $$$n_i$$$ $$$(1 \leq n_i \leq 10^6)$$$ - meaning that in case $$$i$$$ you should solve for numbers $$$1, 2, 3, ..., n_i$$$.
standard output
standard input
PyPy 2
Python
1,600
train_007.jsonl
c1129e2b38ea6d6b71930c4bc4dc5f66
256 megabytes
["3\n1 5 10"]
PASSED
from sys import stdin def count_prime(n): for i in range(2, n): if prim[i] == 1: if i * i < Max: prim[i * i] = -1 for j in range(i * i + i, n, i): prim[j] = 0 for i in range(2, n): prim[i] += prim[i - 1] n, a, Max = int(input()), [int(...
1601903100
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["4\n55\n15000000000000000\n51"]
d9e4a9a32d60e75f3cf959ef7f894fc6
null
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the...
Print $$$q$$$ lines. The $$$i$$$-th line should contain the answer for the $$$i$$$-th queryΒ β€” the maximum number of candies Alice can have after the division, if both Alice and Bob act optimally (of course, Bob will have the same number of candies).
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 1000$$$)Β β€” the number of queries. Then $$$q$$$ queries follow. The only line of the query contains three integers $$$a, b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^{16}$$$)Β β€” the number of candies in the first, second and third piles correspondingly...
standard output
standard input
Python 3
Python
800
train_003.jsonl
4610db81e9d80e78b37c63d70ae6a31a
256 megabytes
["4\n1 3 4\n1 10 100\n10000000000000000 10000000000000000 10000000000000000\n23 34 45"]
PASSED
import math q_count = int(input()) for i in range(q_count): nums = input().split(' ') piles_fair = sum(map(lambda x: int(x), nums))//2 print(piles_fair)
1563978900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2\n10\n3"]
9a2e734bd78ef1e50140f2bb4f57d611
Note Graph from the first test case. Ority of this tree equals to 2 or 2 = 2 and it's minimal. Without excluding edge with weight $$$1$$$ ority is 1 or 2 = 3.
Recently, Vlad has been carried away by spanning trees, so his friends, without hesitation, gave him a connected weighted undirected graph of $$$n$$$ vertices and $$$m$$$ edges for his birthday.Vlad defined the ority of a spanning tree as the bitwise OR of all its weights, and now he is interested in what is the minimu...
Print $$$t$$$ lines, each of which contains the answer to the corresponding set of input dataΒ β€” the minimum possible spanning tree ority.
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. An empty line is written in front of each test case. This is followed by two numbers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 2 \cdot 10^5, n - 1 \le m \le 2 \cdot 10^5$$$) β€” the number of vertices and e...
standard output
standard input
PyPy 3-64
Python
1,900
train_102.jsonl
ca247fd48319c4d12f7df489f8db1c1c
256 megabytes
["3\n\n\n\n\n3 3\n\n1 2 1\n\n2 3 2\n\n1 3 2\n\n\n\n\n5 7\n\n4 2 7\n\n2 5 8\n\n3 4 2\n\n3 2 1\n\n2 4 2\n\n4 1 2\n\n1 2 2\n\n\n\n\n3 4\n\n1 2 1\n\n2 3 2\n\n1 3 3\n\n3 1 4"]
PASSED
import sys ip=sys.stdin.readline class Graph: def __init__(self,n,m,edge,tot): self.n=n self.m=m self.edge=edge self.tot=tot self.par=[-1 for _ in range(n+1)] def findParent(self,x,c1): if self.par[x]==-1:return x,c1 else:return self.findP...
1641825300
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["640"]
29639971c98dd98f0292d994d4433e3a
NoteNote to the sample:The total length of the walls (the perimeter) of the room is 20 m.One roll of the first type can be cut into pieces to get three vertical 1 meter wide strips, ergo you need 7 rolls of this type, the price equals 700.A roll of the second type can be cut into pieces to get five 2 meter wide strips,...
Having bought his own apartment, Boris decided to paper the walls in every room. Boris's flat has n rooms, each of which has the form of a rectangular parallelepiped. For every room we known its length, width and height of the walls in meters (different rooms can have different dimensions, including height).Boris chose...
Print a single number β€” the minimum total cost of the rolls.
The first line contains a positive integer n (1 ≀ n ≀ 500) β€” the number of rooms in Boris's apartment. Each of the next n lines contains three space-separated positive integers β€” the length, width and height of the walls in a given room in meters, respectively. The next line contains a positive integer m (1 ≀ m ≀ 500) ...
standard output
standard input
Python 3
Python
1,600
train_004.jsonl
680319ec3ed223a0d91df4f31d879193
256 megabytes
["1\n5 5 3\n3\n10 1 100\n15 2 320\n3 19 500"]
PASSED
n = int(input()) rooms = [[int(i) for i in input().split()] for i in range(n)] m = int(input()) papers = [[int(i) for i in input().split()] for i in range(m)] ans = 0 for room in rooms: per = (room[0]+room[1])*2 prices = [] for cur in papers: power = cur[0]//room[2]*cur[1] if(power == 0): continue prices.ap...
1324728000
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["Yes", "No"]
e72fa6f8a31c34fd3ca0ce3a3873ff50
NoteIn the first sample, Arya can understand because 5 is one of the ancient numbers.In the second sample, Arya can't be sure what is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.
Today Pari and Arya are playing a game called Remainders.Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value . There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy indep...
Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise.
The first line of the input contains two integers n and k (1 ≀ n,  k ≀ 1 000 000)Β β€” the number of ancient integers and value k that is chosen by Pari. The second line contains n integers c1, c2, ..., cn (1 ≀ ci ≀ 1 000 000).
standard output
standard input
Python 3
Python
1,800
train_000.jsonl
5052386e91fc1fe0d05d0df22ed00077
256 megabytes
["4 5\n2 3 5 12", "2 7\n2 3"]
PASSED
import math def main(): n,k = map(int,input().split()) C = list(map(int,input().split())) l=C[0] for c in C: l = l*c//math.gcd(l,c)%k if(l==0): print("Yes") return print("No") main()
1467219900
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["YES\n1 2 4 5 6 8", "NO", "YES\n1", "NO"]
df801ebbe05c17bb1d157108d523d1f8
null
Polycarp has to solve exactly $$$n$$$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $$$k$$$ days. It means that Polycarp has exactly $$$k$$$ days for training!Polycarp doesn't want to procrastinate, so...
If it is impossible to find any array $$$a$$$ of length $$$k$$$ satisfying Polycarp's rules of training, print "NO" in the first line. Otherwise print "YES" in the first line, then print $$$k$$$ integers $$$a_1, a_2, \dots, a_k$$$ in the second line, where $$$a_i$$$ should be the number of problems Polycarp should solv...
The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^9, 1 \le k \le 10^5$$$) β€” the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
standard output
standard input
Python 3
Python
1,900
train_036.jsonl
5490ac684ee3f588bd65d8a1899f995e
256 megabytes
["26 6", "8 3", "1 1", "9 4"]
PASSED
n, k = [int(x) for x in input().split()] a = [i for i in range(1, k+1)] s = (k*(k+1))//2 p = 0 if n == s: p = 0 elif n > s: if n - s == k: p = 0 for i in range(k): a[i] += 1 elif n - s > k: d = (n - s) // k for i in range(k): a[i] += d p = (n-s...
1556289300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
0.5 seconds
["50", "110", "0"]
9b1b082319d045cf0ec6d124f97a8184
NoteIn sample 1 numbers 10 and 1 are beautiful, number 5 is not not.In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.In sample 3 number 3 is not beautiful, all others are beautiful.
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not en...
Print a single number without leading zeroesΒ β€” the product of the number of tanks presented by each country.
The first line of the input contains the number of countries n (1 ≀ n ≀ 100 000). The second line contains n non-negative integers ai without leading zeroesΒ β€” the number of tanks of the i-th country. It is guaranteed that the second line contains at least n - 1 beautiful numbers and the total length of all these number...
standard output
standard input
PyPy 3
Python
1,400
train_005.jsonl
31da23fc0f4086926cd12c10c0062e82
256 megabytes
["3\n5 10 1", "4\n1 1 10 11", "5\n0 3 1 100 1"]
PASSED
def check(string): if len(string) == 1: return string[0] != '1' if string[0] != '1': return True if any(s != '0' for s in string[1:]): return True return False if __name__ == "__main__": n = int(input()) if n == 1: print(input()) exit(0) tanks = [str(x) for x in input().split(' ')] for x in tanks: i...
1452789300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
da517ae908ba466da8ded87cec12a9fa
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≀ l ≀ r ≀ n), such that the following conditions hold: there is integer j (l ≀ j ≀ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
Print two integers in the first line β€” the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
The first line contains integer n (1 ≀ n ≀ 3Β·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 106).
standard output
standard input
Python 3
Python
2,000
train_071.jsonl
5d33e4b2afcf37b9bfe8edd258861d19
256 megabytes
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
PASSED
n = int(input()) + 1 t = [1] + list(map(int, input().split())) + [1] p = [True] * n s, q = 0, list(range(1, n)) for i in range(1, n): if p[i]: a = b = i d = t[i] if d == 1: s, q = n - 2, [1] break while t[a - 1] % d == 0: a -= 1 while t[b + 1] % d == ...
1383379200
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["238\n108\n112\n0\n64\n194\n48\n26\n244\n168\n24\n16\n162"]
a65e12186430f74c18c50d2eb55a9794
NoteLet's have a closer look at the beginning of the example. The first character is "H" with ASCII-code 72 = 010010002. Its reverse is 000100102 = 18, and this number should become the result of the second step of processing. The result of the first step is considered to be 0, so the first element of the array has to ...
INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print, using the following method.The integers of the array are processed one by...
Output the initial array, which was used to produce text, one integer per line.
The input will consist of a single line text which contains the message printed using the described method. String text will contain between 1 and 100 characters, inclusive. ASCII-code of each character of text will be between 32 (space) and 126 (tilde), inclusive.
standard output
standard input
Python 2
Python
1,300
train_003.jsonl
e6ec86b3c31b72be25dc4d620cea4f2a
256 megabytes
["Hello, World!"]
PASSED
s = raw_input() pre = 0 for i in s: nxt = format(ord(i), "b")[::-1] while (len(nxt) < 8): nxt += "0" print (pre - int(nxt, 2)) % 256 pre = int(nxt, 2)
1322924400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["7", "36"]
8aaabe089d2512b76e5de938bac5c3bf
NoteIn the first sample one of the optimum behavior of the players looks like that: Vova bans the position at coordinate 15; Lesha bans the position at coordinate 3; Vova bans the position at coordinate 31; Lesha bans the position at coordinate 1. After these actions only positions 0 and 7 will remain, and the dist...
In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest.Vov...
Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally.
The first line on the input contains a single integer n (2 ≀ n ≀ 200 000, n is even)Β β€” the number of positions available initially. The second line contains n distinct integers x1, x2, ..., xn (0 ≀ xi ≀ 109), giving the coordinates of the corresponding positions.
standard output
standard input
Python 3
Python
2,300
train_037.jsonl
4e9e29bd088f05333e926af671963b9c
256 megabytes
["6\n0 1 3 7 15 31", "2\n73 37"]
PASSED
n = int(input()) x = sorted(list(map(int, input().split()))) print(min([x[i + n // 2] - x[i] for i in range(n // 2)]))
1447000200
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
2 seconds
["4 4 1 4 4 2 2"]
a7e75ff150d300b2a8494dca076a3075
null
In some social network, there are $$$n$$$ users communicating with each other in $$$m$$$ groups of friends. Let's analyze the process of distributing some news between users.Initially, some user $$$x$$$ receives the news from some source. Then he or she sends the news to his or her friends (two users are friends if the...
Print $$$n$$$ integers. The $$$i$$$-th integer should be equal to the number of users that will know the news if user $$$i$$$ starts distributing it.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 5 \cdot 10^5$$$) β€” the number of users and the number of groups of friends, respectively. Then $$$m$$$ lines follow, each describing a group of friends. The $$$i$$$-th line begins with integer $$$k_i$$$ ($$$0 \le k_i \le n$$$) β€” the number of u...
standard output
standard input
Python 3
Python
1,400
train_005.jsonl
85547c63cb47b60b13670848592de960
256 megabytes
["7 5\n3 2 5 4\n0\n2 1 2\n1 1\n2 6 7"]
PASSED
import sys,bisect from sys import stdin,stdout from bisect import bisect_left,bisect_right,bisect,insort,insort_left,insort_right from math import gcd,ceil,floor,sqrt from collections import Counter,defaultdict,deque,OrderedDict from queue import Queue,PriorityQueue from string import ascii_lowercase from heapq...
1557930900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
3 seconds
["2", "0"]
0600b8401c8e09978661bc02691bda5d
NoteIn the first sample, the tree is the same as on the picture. If we first apply operation paint(3) and then apply paint(6), the tree will become completely black, so the answer is 2.In the second sample, the tree is already white, so there is no need to apply any operations and the answer is 0.
Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph.There are n vertices in the tree, each of them is painted black or white. Anton doesn't like multicolored trees, so he wants to change the tree such that all vertices have the same color (black or white).To chang...
Print one integerΒ β€” the minimum number of operations Anton has to apply in order to make all vertices of the tree black or all vertices of the tree white.
The first line of the input contains a single integer n (1 ≀ n ≀ 200 000)Β β€” the number of vertices in the tree. The second line contains n integers colori (0 ≀ colori ≀ 1)Β β€” colors of the vertices. colori = 0 means that the i-th vertex is initially painted white, while colori = 1 means it's initially painted black. The...
standard output
standard input
Python 3
Python
2,100
train_018.jsonl
0bc4c6ecffb09e694d0b261021ad1d04
256 megabytes
["11\n0 0 0 1 1 0 1 0 0 1 1\n1 2\n1 3\n2 4\n2 5\n5 6\n5 7\n3 8\n3 9\n3 10\n9 11", "4\n0 0 0 0\n1 2\n2 3\n3 4"]
PASSED
from collections import defaultdict, deque class DSU: def __init__(self, n): self.parents = [i for i in range(n)] self.ranks = [0 for i in range(n)] def find_parent(self, v): if self.parents[v] == v: return v self.parents[v] = self.find_parent(self.parents[v]) ...
1479227700
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
4 seconds
["YES\n2 1 3", "NO"]
ff5b3d5fa52c2505556454011e8a0f58
null
Several years ago Tolya had n computer games and at some point of time he decided to burn them to CD. After that he wrote down the names of the games one after another in a circle on the CD in clockwise order. The names were distinct, the length of each name was equal to k. The names didn't overlap.Thus, there is a cyc...
If there is no answer, print "NO" (without quotes). Otherwise, print two lines. In the first line print "YES" (without quotes). In the second line, print n integersΒ β€” the games which names were written on the CD. You should print games in the order they could have been written on the CD, it means, in clockwise order. Y...
The first line of the input contains two positive integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 105)Β β€” the amount of games Tolya burned to the CD, and the length of each of the names. The second line of the input contains one string consisting of lowercase English lettersΒ β€” the string Tolya wrote on the CD, split in arbitrary...
standard output
standard input
PyPy 2
Python
2,300
train_004.jsonl
c0e45f7091360a9c77189ba8551070c8
512 megabytes
["3 1\nabc\n4\nb\na\nc\nd", "4 2\naabbccdd\n4\ndd\nab\nbc\ncd"]
PASSED
n, k = map(int, raw_input().split()) s = raw_input() g = int(raw_input()) games = [raw_input() for i in range(g)] MOD_1 = 1000000007 BASE_1 = 31 MOD_2 = 1000000409 BASE_2 = 29 hashes_1 = [] hashes_2 = [] hash_inv = {} game_inv = {} for i, game in enumerate(games): h_1 = 0 h_2 = 0 for c in game: h...
1476522300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["Success\nConflict with 6\nSuccess\nAlready off\nSuccess\nSuccess\nSuccess\nSuccess\nConflict with 10\nAlready on"]
6cec3662101b419fb734b7d6664fdecd
NoteNote that in the sample the colliders don't turn on after the second and ninth requests. The ninth request could also receive response "Conflict with 3".
By 2312 there were n Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to n. However, scientists did not know what activating several colliders simultaneously could cause, so the colliders were deactivated.In 2312 there was a startling discovery: a...
Print m lines β€” the results of executing requests in the above given format. The requests should be processed in the order, in which they are given in the input. Don't forget that the responses to the requests should be printed without quotes.
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of colliders and the number of requests, correspondingly. Next m lines contain numbers of requests, one per line, in the form of either "+ i" (without the quotes) β€” activate the i-th collider, or "-Β i" (without the quotes) β€” deac...
standard output
standard input
Python 3
Python
1,600
train_033.jsonl
0be8335fa0addd77d62a949608dec84f
256 megabytes
["10 10\n+ 6\n+ 10\n+ 5\n- 10\n- 5\n- 6\n+ 10\n+ 3\n+ 6\n+ 3"]
PASSED
n, m = map(int, input().split()) n += 1 s = [[] for i in range(n)] for j in range(2, n, 2): s[j] = [2] for i in range(3, n, 2): if s[i]: continue for j in range(i, n, i): s[j].append(i) p, d, r = {}, set(), [''] * m for j in range(m): t = input() i = int(t[2: ]) if t[0] == '+': ...
1330095600
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["3", "4"]
7c41fb6212992d1b3b3f89694b579fea
NoteIllustration for the first example: Illustration for the second example:
There are $$$n$$$ points on the plane, $$$(x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)$$$.You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of t...
Print the minimum length of the shorter side of the triangle. It can be proved that it's always an integer.
First line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$). Each of the next $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \leq x_i,y_i \leq 10^9$$$).
standard output
standard input
Python 3
Python
900
train_017.jsonl
39db005ea406d9369c68e9c5f86ee466
256 megabytes
["3\n1 1\n1 2\n2 1", "4\n1 1\n1 2\n2 1\n2 2"]
PASSED
n = int(input()) s=0 m=0 for i in range(n): a = [ int(i) for i in input().split() ] s = sum(a) if s>=m: m=s print(m)
1537540500
[ "geometry", "math" ]
[ 0, 1, 0, 1, 0, 0, 0, 0 ]
1 second
["2 3 3 0 1 2\n\n1 0 1\n\n1 0 2\n\n2 2 1 1\n\n3\n1111\n1111\n1111\n0001"]
beae75b649ca6ed26180954faf73e5a3
NoteIn the given example:The first query asks whether there's a passage from room $$$3$$$ to any of the other rooms.The second query asks about the direction of the passage between rooms $$$0$$$ and $$$1$$$.After a couple other queries, we concluded that you can go from any room to any other room except if you start at...
This is an interactive problem.Baby Ehab loves crawling around his apartment. It has $$$n$$$ rooms numbered from $$$0$$$ to $$$n-1$$$. For every pair of rooms, $$$a$$$ and $$$b$$$, there's either a direct passage from room $$$a$$$ to room $$$b$$$, or from room $$$b$$$ to room $$$a$$$, but never both.Baby Ehab wants to ...
To print the answer for a test case, print a line containing "3", followed by $$$n$$$ lines, each containing a binary string of length $$$n$$$. The $$$j$$$-th character of the $$$i$$$-th string should be $$$1$$$ if there's a path from room $$$i$$$ to room $$$j$$$, and $$$0$$$ if there isn't. The $$$i$$$-th character of...
The first line contains an integer $$$t$$$ ($$$1 \le t \le 30$$$)Β β€” the number of test cases you need to solve. Then each test case starts with an integer $$$n$$$ ($$$4 \le n \le 100$$$)Β β€” the number of rooms. The sum of $$$n$$$ across the test cases doesn't exceed $$$500$$$.
standard output
standard input
Python 3
Python
2,700
train_110.jsonl
371b7ee024837c275765f903b8431928
256 megabytes
["1\n4\n\n0\n\n0\n\n1\n\n1\n\n1"]
PASSED
def ask1(i, j):print('1', i, j);return int(input()) != 0 def ask2(i, a):print('2', i, len(a), *a);return int(input()) != 0 def answer(a): print('3') for x in a: print(*x, sep = '') assert(int(input()) != -1) for _ in range(int(input())): n = int(input());ans = [[0] * n for i in range(n)];p...
1618839300
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["-1\n2\n1\n2"]
09a0bad93090b65b5515abf0ccb96bd4
NoteIn the first set of inputs, even if all the friends stay in the maze, Vlad can still win. Therefore, the answer is "-1".In the second set of inputs it is enough to leave friends from rooms $$$6$$$ and $$$7$$$. Then Vlad will not be able to win. The answer is "2".In the third and fourth sets of inputs Vlad cannot wi...
The only difference with E1 is the question of the problem.Vlad built a maze out of $$$n$$$ rooms and $$$n-1$$$ bidirectional corridors. From any room $$$u$$$ any other room $$$v$$$ can be reached through a sequence of corridors. Thus, the room system forms an undirected tree.Vlad invited $$$k$$$ friends to play a game...
Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to a test case should be $$$-1$$$ if Vlad wins anyway and a minimal number of friends otherwise.
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases in the input. The input contains an empty string before each test case. The first line of the test case contains two numbers $$$n$$$ and $$$k$$$ ($$$1 \le k &lt; n \le 2\cdot 10^5$$$) β€” the number of rooms and fr...
standard output
standard input
PyPy 3-64
Python
1,900
train_093.jsonl
490b449b4b194ce92c4646280af4d08d
256 megabytes
["4\n\n8 2\n5 3\n4 7\n2 5\n1 6\n3 6\n7 2\n1 7\n6 8\n\n8 4\n6 5 7 3\n4 7\n2 5\n1 6\n3 6\n7 2\n1 7\n6 8\n\n3 1\n2\n1 2\n2 3\n\n3 2\n2 3\n3 1\n1 2"]
PASSED
from collections import defaultdict, deque import sys input = sys.stdin.buffer.readline for _ in range(int(input())): input() n, k = map(int, input().split()) fl = input() d = defaultdict(list) for _ in range(n-1): a, b = map(int, input().split()) d[a].append(b) d[b].append(a) p = dict() c =...
1637850900
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["3"]
f3c26aa520f6bfa6b181ec40bde7ee1b
null
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.You're given a tree w...
Print the minimum number of operations needed to solve the task. Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
The first line of the input contains n (1 ≀ n ≀ 105). Each of the next n - 1 lines contains two integers ai and bi (1 ≀ ai, bi ≀ n;Β ai ≠ bi) indicating there's an edge between vertices ai and bi. It's guaranteed that the input graph is a tree. The last line of the input contains a list of n space-separated integers v1...
standard output
standard input
PyPy 3
Python
1,800
train_039.jsonl
740c09a3634b5e5d1de8f86ab2e22805
256 megabytes
["3\n1 2\n1 3\n1 -1 1"]
PASSED
from sys import stdin, stdout,setrecursionlimit from collections import defaultdict,deque,Counter,OrderedDict from heapq import heappop,heappush import threading n = int(stdin.readline()) graph = [set() for x in range(n)] for x in range(n-1): a,b = [int(x) for x in stdin.readline().split()] a -= 1 b -= 1...
1361374200
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["cc\ncbaabc\naa\nbb"]
dd7faacff9f57635f8e00c2f8f5a4650
NoteIn the first test case choose $$$k = 1$$$ to obtain "cc".In the second test case choose $$$k = 3$$$ to obtain "cbaabc".In the third test case choose $$$k = 1$$$ to obtain "aa".In the fourth test case choose $$$k = 1$$$ to obtain "bb".
You have a string $$$s_1 s_2 \ldots s_n$$$ and you stand on the left of the string looking right. You want to choose an index $$$k$$$ ($$$1 \le k \le n$$$) and place a mirror after the $$$k$$$-th letter, so that what you see is $$$s_1 s_2 \ldots s_k s_k s_{k - 1} \ldots s_1$$$. What is the lexicographically smallest st...
For each test case print the lexicographically smallest string you can see.
The first line of input contains one integer $$$t$$$ ($$$1 \leq t \leq 10\,000$$$): the number of test cases. The next $$$t$$$ lines contain the description of the test cases, two lines per a test case. In the first line you are given one integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$): the length of the string. The second ...
standard output
standard input
Python 3
Python
1,100
train_101.jsonl
9ba2a3d400e2452bc13b5360b2f2e884
256 megabytes
["4\n10\ncodeforces\n9\ncbacbacba\n3\naaa\n4\nbbaa"]
PASSED
for s in[*open(0)][2::2]: a=*map(ord,s[:-1]),123;i=1 while(i>1)+a[i-1]>a[i]:i+=1 s=s[:i];print(s+s[::-1])
1640792100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2.5 seconds
["0\n250000002\n250000002\n500000004\n0\n250000002\n250000002\n250000002\n250000002\n0\n1"]
1759fabd248d2b313ecfb8e1b3e7b0db
NoteHere is the example of $$$6$$$ ants moving on the branch. An ant's movement will be denoted by either a character $$$L$$$ or $$$R$$$. Initially, the pack of ants on the branch will move as $$$RLRRLR$$$. Here's how the behavior of the pack demonstrated: Initially, the ants are positioned as above. After a while, t...
Ela likes to go hiking a lot. She loves nature and exploring the various creatures it offers. One day, she saw a strange type of ant, with a cannibalistic feature. More specifically, an ant would eat any ants that it sees which is smaller than it.Curious about this feature from a new creature, Ela ain't furious. She co...
For each test, print $$$n$$$ lines. $$$i$$$-th line contains a single number that denotes the survival probability of the $$$i$$$-th ant in the line modulo $$$10^9 + 7$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The description of the test cases follows. The only line of each test contains an integer $$$n$$$ ($$$1 \le n \le 10^6$$$) β€” the number of ants in the experiment. It is guaranteed that the sum of $...
standard output
standard input
PyPy 3-64
Python
2,500
train_094.jsonl
0ab92873a9a92eac654c4316ec46f281
256 megabytes
["3\n\n4\n\n5\n\n2"]
PASSED
import sys import math import heapq import itertools import bisect import random import time from collections import deque input=sys.stdin.readline mod=10**9+7 def power(a,n): if n==0: return 1 x=power(a,n//2) if n%2==0: return x*x%mod else: return x*x*a%mod ...
1665153300
[ "probabilities", "math" ]
[ 0, 0, 0, 1, 0, 1, 0, 0 ]
2 seconds
["acb"]
b442b73ecb559f0841c0e86f84b5cbb1
null
While exploring the old caves, researchers found a book, or more precisely, a stash of mixed pages from a book. Luckily, all of the original pages are present and each page contains its number. Therefore, the researchers can reconstruct the book.After taking a deeper look into the contents of these pages, linguists thi...
Output a string representing the reconstructed alphabet of this ancient civilization. If the book found is not a dictionary, output "IMPOSSIBLE" without quotes. In case there are multiple solutions, output any of them.
First-line contains two integers: $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^3$$$) β€” the number of pages that scientists have found and the number of words present at each page. Following $$$n$$$ groups contain a line with a single integer $$$p_i$$$ ($$$0 \le n \lt 10^3$$$) β€” the number of $$$i$$$-th page, as well as $$...
standard output
standard input
PyPy 3
Python
2,200
train_040.jsonl
a4b560defcec44f69201b47d9eff366f
256 megabytes
["3 3\n2\nb\nb\nbbac\n0\na\naca\nacba\n1\nab\nc\nccb"]
PASSED
import os import io from collections import deque, defaultdict input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def li():return [int(i) for i in input().rstrip().split()] def st():return str(input().rstrip())[2:-1] def val():return int(input().rstrip()) # def li():return [int(i) for i in input().rstrip()....
1601903100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["101 10", "30 15", "18 18", "7000 7000"]
21672f2906f4f821611ab1b6dfc7f081
NoteIn the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of ...
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
The first line contain an integer n (1 ≀ n ≀ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 ≀ si ≀ 100) β€” the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 ≀ ck ≀ 1000) β€” the sequence of the numbers on the cards...
standard output
standard input
Python 2
Python
2,000
train_015.jsonl
e4cdbbc535cd8f7d16d576616dcc7499
256 megabytes
["2\n1 100\n2 1 10", "1\n9 2 8 6 5 9 4 7 1 3", "3\n3 1 3 2\n3 5 4 6\n2 8 7", "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000"]
PASSED
n = input() cie = jir = 0 mid = [] for i in xrange(n): card = map(int, raw_input().split()) s = card[0] card = card[1:] b = s / 2 e = (s + 1) / 2 if(b != e): mid.append(card[b]) cie += sum(card[:b]) jir += sum(card[e:]) l = (len(mid) + 1) / 2 mid = sorted(mid, reverse = True) for i in xrange(len(mid)): if(i...
1391442000
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
1 second
["NO", "YES\n3.659792366325"]
fc37ef81bb36f3ac07ce2c4c3ec10d98
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup wil...
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition β€” when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything ha...
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number β€” time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is gu...
The only line of the input contains four integer numbers d, h, v, e (1 ≀ d, h, v, e ≀ 104), where: d β€” the diameter of your cylindrical cup, h β€” the initial level of water in the cup, v β€” the speed of drinking process from the cup in milliliters per second, e β€” the growth of water because of rain if you do not dri...
standard output
standard input
PyPy 2
Python
1,100
train_017.jsonl
08c90f295143b9047f663bda52642377
256 megabytes
["1 2 3 100", "1 1 1 1"]
PASSED
from math import pi d, h, v, e = map(int, raw_input().split()) vol = 4 * v /(pi * d * d) if e >= vol : print "NO" else : print "YES" print h / (vol - e)
1461947700
[ "geometry", "math" ]
[ 0, 1, 0, 1, 0, 0, 0, 0 ]
1 second
["1\nGRB", "3\nRGBRGBR"]
e67b79e39511b0107a51edc0179afb82
null
You have a garland consisting of $$$n$$$ lamps. Each lamp is colored red, green or blue. The color of the $$$i$$$-th lamp is $$$s_i$$$ ('R', 'G' and 'B' β€” colors of lamps in the garland).You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the...
In the first line of the output print one integer $$$r$$$ β€” the minimum number of recolors needed to obtain a nice garland from the given one. In the second line of the output print one string $$$t$$$ of length $$$n$$$ β€” a nice garland obtained from the initial one with minimum number of recolors. If there are multiple...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β€” the number of lamps. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland.
standard output
standard input
PyPy 2
Python
1,300
train_013.jsonl
7c9d2a770b443418413e1ef9a9ff8d43
256 megabytes
["3\nBRB", "7\nRGBGRBB"]
PASSED
from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip from itertools import permutations def ii(): return int(input()) def si(): retur...
1548254100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]