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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4 seconds | ["1"] | bd519efcfaf5b43bb737337004a1c2c0 | null | You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points. | Print the only integer c — the number of parallelograms with the vertices at the given points. | The first line of the input contains integer n (1 ≤ n ≤ 2000) — the number of points. Each of the next n lines contains two integers (xi, yi) (0 ≤ xi, yi ≤ 109) — the coordinates of the i-th point. | standard output | standard input | PyPy 3 | Python | 1,900 | train_042.jsonl | 82c99a94439adb77a2c7994a093e41c1 | 256 megabytes | ["4\n0 1\n1 0\n1 1\n2 0"] | PASSED | n = int(input())
points = [0] * n
D = {}
for i in range(n):
points[i] = tuple(int(x) for x in input().split())
for i in range(n):
for j in range(i+1, n):
x1, y1 = points[i]
x2, y2 = points[j]
u, v = x2 - x1, y2 - y1
if u < 0 or u == 0 and v < 0:
u, v = -u, -v
... | 1460127600 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
1 second | ["1 -1\n-1 5 1 -1 -1\n-10 2 2 -3 5 -1 -1"] | c4541021337252c7e2c4afd2de8cd766 | NoteIn the first test case, $$$5 \cdot 1 + 5 \cdot (-1)=5-5=0$$$. You could also print $$$3$$$ $$$-3$$$, for example, since $$$5 \cdot 3 + 5 \cdot (-3)=15-15=0$$$In the second test case, $$$5 \cdot (-1) + (-2) \cdot 5 + 10 \cdot 1 + (-9) \cdot (-1) + 4 \cdot (-1)=-5-10+10+9-4=0$$$. | Vupsen and Pupsen were gifted an integer array. Since Vupsen doesn't like the number $$$0$$$, he threw away all numbers equal to $$$0$$$ from the array. As a result, he got an array $$$a$$$ of length $$$n$$$.Pupsen, on the contrary, likes the number $$$0$$$ and he got upset when he saw the array without zeroes. To chee... | For each test case print $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ — elements of the array $$$b$$$ ($$$|b_1|+|b_2|+\ldots +|b_n| \le 10^9$$$, $$$b_i \neq 0$$$, $$$\sum_{i=1}^{n}a_i \cdot b_i=0$$$). It can be shown that the answer always exists. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$2 \cdot t$$$ lines contain the description of test cases. The description of each test case consists of two lines. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) ... | standard output | standard input | Python 3 | Python | 1,600 | train_106.jsonl | 14ae81da2993ef3457470fe65b705f94 | 256 megabytes | ["3\n2\n5 5\n5\n5 -2 10 -9 4\n7\n1 2 3 4 5 6 7"] | PASSED | def solve(n, aa):
head, tail = [], []
if n % 2 == 1:
a, b, c = aa[n-3], aa[n-2], aa[n-1]
if b + c != 0:
tail = [b+c, -a, -a]
else:
tail = [b-c, -a, a]
n -= 3
idx = 0
while idx < n:
factor = gcd(aa[idx], aa[idx+1])
head.append(aa[id... | 1635069900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
6 seconds | ["5\n2\n1\n4\n0\n4"] | c7f0fefd9616e4ba2d309a7c5c8a8a0a | NoteThe tree in the first example is shown in the following picture: Answers to the queries are obtained as follows: $$$v=1,k=0$$$: you can delete vertices $$$7$$$ and $$$3$$$, so the vertex $$$1$$$ has $$$5$$$ children (vertices $$$2$$$, $$$4$$$, $$$5$$$, $$$6$$$, and $$$8$$$), and the score is $$$5 - 2 \cdot 0 = 5$... | You are given a tree consisting of $$$n$$$ vertices. Recall that a tree is an undirected connected acyclic graph. The given tree is rooted at the vertex $$$1$$$.You have to process $$$q$$$ queries. In each query, you are given a vertex of the tree $$$v$$$ and an integer $$$k$$$.To process a query, you may delete any ve... | For each query, print one integer — the maximum value of $$$c(v) - m \cdot k$$$ you can achieve. | The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. Then $$$n-1$$$ lines follow, the $$$i$$$-th of them contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n$$$; $$$x_i \ne y_i$$$) — the endpoints of the $$$i$$$-th edge. These edges form a ... | standard output | standard input | PyPy 3-64 | Python | 2,800 | train_108.jsonl | d344a982851d811dfb4757119fd51e33 | 512 megabytes | ["8\n6 7\n3 2\n8 3\n5 7\n7 4\n7 1\n7 3\n6\n1 0\n1 2\n1 3\n7 1\n5 0\n7 200000"] | PASSED | import sys, collections
n = int(sys.stdin.readline())
e = [[] for i in range(n+1)]
for i in range(n-1):
a, b = [int(i) for i in sys.stdin.readline().split()]
e[a].append(b)
e[b].append(a)
o = [len(e[i])-1 for i in range(0, n+1)]
o[1]+=1
r = [[] for i in range(n+1)]
st = collections.deque([1])
d =... | 1635518100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["10", "1", "4", "0"] | a5d3c9ea1c9affb0359d81dae4ecd7c8 | NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the thi... | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You... | In the only line print the integer S — the minimum number of burles which are had to spend. | The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen. | standard output | standard input | Python 2 | Python | 800 | train_020.jsonl | 41e90df120ed623c64bb38d6e4f09d59 | 256 megabytes | ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12"] | PASSED | x=int(raw_input())
y=map(int,raw_input().split())
max=y[0]
sum=0
for i in range(len(y)):
if y[i]>max:
max=y[i]
for i in range(len(y)):
if y[i]!=max:
sum=sum+(max-y[i])
print(sum) | 1484838300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["6\n0"] | 66eb860613bf3def9c1b3f8bb3a6763a | Note In test case $$$1$$$, all possible subsegments of sequence $$$[1, 2, 1, 1]$$$ having size more than $$$1$$$ are: $$$[1, 2]$$$ having $$$0$$$ valid unordered pairs; $$$[2, 1]$$$ having $$$0$$$ valid unordered pairs; $$$[1, 1]$$$ having $$$1$$$ valid unordered pair; $$$[1, 2, 1]$$$ having $$$1$$$ valid unorder... | The weight of a sequence is defined as the number of unordered pairs of indexes $$$(i,j)$$$ (here $$$i \lt j$$$) with same value ($$$a_{i} = a_{j}$$$). For example, the weight of sequence $$$a = [1, 1, 2, 2, 1]$$$ is $$$4$$$. The set of unordered pairs of indexes with same value are $$$(1, 2)$$$, $$$(1, 5)$$$, $$$(2, 5... | For each test case, print a single integer — the sum of the weight of all subsegments of $$$a$$$. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_... | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_085.jsonl | 661caaec62312454f127c801003445fc | 256 megabytes | ["2\n4\n1 2 1 1\n4\n1 2 3 4"] | PASSED | import sys
input = sys.stdin.readline
def solve():
t = int(input())
for i in range(t):
n = int(input())
s = [int(x) for x in input().split()]
res, temp = 0, 0
idx_sum = {}
for j in range(n):
if s[j] in idx_sum:
temp += idx_sum[s[j]... | 1621521300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0\n1\n2"] | 58dfab2a45314bbf93c20604e047e7b7 | NoteIn the first test case, there is only one vertex, so you don't need any queries.In the second test case, you can ask a single query about the node $$$1$$$. Then, if $$$x = 1$$$, you will get $$$0$$$, otherwise you will get $$$1$$$. | The only difference between this problem and D1 is the bound on the size of the tree.You are given an unrooted tree with $$$n$$$ vertices. There is some hidden vertex $$$x$$$ in that tree that you are trying to find.To do this, you may ask $$$k$$$ queries $$$v_1, v_2, \ldots, v_k$$$ where the $$$v_i$$$ are vertices in ... | For each test case print a single nonnegative integer, the minimum number of queries you need, on its own line. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — the number of vertices in the tree. Each of the next $$$n... | standard output | standard input | PyPy 3-64 | Python | 2,300 | train_089.jsonl | 0785a932dfd5fe17a37d293ec3fe7321 | 256 megabytes | ["3\n\n1\n\n2\n\n1 2\n\n10\n\n2 4\n\n2 1\n\n5 7\n\n3 10\n\n8 6\n\n6 1\n\n1 3\n\n4 7\n\n9 6"] | PASSED | from collections import deque;I=input
def f(x,pre):
q=deque([(x,pre)]);dp=[0]*(n+1);R=[]
while q:
u,p=q.popleft()
R.append((u))
for v in g[u]:
if v!=p:g[v].remove(u);q.append((v,u))
for u in R[::-1]:
z=c=0
for v in g[u]:
z+=dp[v]
if dp[v]==0:c+=1
dp[u]=z+... | 1655562900 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
5 seconds | ["1", "0", "4", "1"] | 463d4e6badd3aa110cc87ae7049214b4 | null | The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep". Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number.In Shapur's opinion the weakness of... | A single integer number, the weakness of the Roman army. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | The first line of input contains a single number n (3 ≤ n ≤ 106) — the number of men in Roman army. Next line contains n different positive integers ai (1 ≤ i ≤ n, 1 ≤ ai ≤ 109) — powers of men in the Roman army. | standard output | standard input | PyPy 2 | Python | 1,900 | train_009.jsonl | 5eb189e0a0f8c3d0458ca836514d5fc5 | 256 megabytes | ["3\n3 2 1", "3\n2 3 1", "4\n10 8 3 1", "4\n1 5 4 3"] | PASSED | def fast2():
import os, sys, atexit
from cStringIO import StringIO as BytesIO
# range = xrange
sys.stdout = BytesIO()
atexit.register(lambda: os.write(1, sys.stdout.getvalue()))
return BytesIO(os.read(0, os.fstat(0).st_size)).readline
class order_tree:
def __init__(self, n):
self.t... | 1298390400 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
3 seconds | ["12", "39"] | 18b5557b282ebf7288de50ab8cb51c60 | NoteIn the first sample the clans are {1}, {2}, {1, 2} so the answer will be 1·3 + 1·3 + 2·3 = 12 | Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers.He has created a method to know how strong his army is. Let the i-th soldier’s strength b... | Print one integer — the strength of John Snow's army modulo 1000000007 (109 + 7). | The first line contains integer n (1 ≤ n ≤ 200000) — the size of the army. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000000) — denoting the strengths of his soldiers. | standard output | standard input | Python 3 | Python | 2,200 | train_012.jsonl | 8d3584bf33569a7ff9aeafcfbca49a4e | 256 megabytes | ["3\n3 3 1", "4\n2 3 4 6"] | PASSED | (input())
a=list(map(int,input().split()))
n,p=1000001,1000000007
cnt=[0]*n
curr=1
for i in a:
cnt[i]+=1
ans=[0]*n
tot=0
for i in range(n-1,1,-1):
k=sum(cnt[i::i])
if k>0:
ans[i]=(k*pow(2,k-1,p)-sum(ans[i::i]))%p
tot=(tot+i*ans[i])%p
print(tot)
| 1502548500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["0.300000000000", "1.000000000000"] | 23604db874ed5b7c007ea4a837bf9c88 | NoteIn the first sample we need either win no tour or win the third one. If we win nothing we wouldn't perform well. So, we must to win the third tour. Other conditions will be satisfied in this case. Probability of wining the third tour is 0.3.In the second sample we win the only tour with probability 1.0, and go back... | One must train much to do well on wizardry contests. So, there are numerous wizardry schools and magic fees.One of such magic schools consists of n tours. A winner of each tour gets a huge prize. The school is organised quite far away, so one will have to take all the prizes home in one go. And the bags that you've bro... | Print a single real number — the answer to the problem. The answer will be accepted if the absolute or relative error does not exceed 10 - 6. | The first line contains three integers n, l, k (1 ≤ n ≤ 200, 0 ≤ l, k ≤ 200) — the number of tours, the minimum number of tours to win, and the number of prizes that you can fit in the bags brought from home, correspondingly. The second line contains n space-separated integers, pi (0 ≤ pi ≤ 100) — the probability to wi... | standard output | standard input | Python 3 | Python | 1,800 | train_017.jsonl | f2ea202cdad0372ba7254ab303f9e2cc | 256 megabytes | ["3 1 0\n10 20 30\n-1 -1 2", "1 1 1\n100\n123"] | PASSED | from collections import *
f = lambda: list(map(int, input().split()))
n, l, a = f()
p, s = f(), f()
m = s.count(-1)
x = {(0, min(a, m)): 1}
d = [1]
for p, s in zip(p, s):
p /= 100
if s > 0:
y = defaultdict(int)
for (k, a), q in x.items():
y[(k, a)] += q - q * p
y[(min(l... | 1332860400 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
2 seconds | ["499122179", "0", "499122177"] | 2df2d5368f467e0427b1f6f57192e2ee | NoteIn the first example two resulting valid permutations are possible: $$$[3, 1, 2]$$$ — $$$2$$$ inversions; $$$[3, 2, 1]$$$ — $$$3$$$ inversions. The expected value is $$$\frac{2 \cdot 1 + 3 \cdot 1}{2} = 2.5$$$.In the second example no $$$-1$$$ are present, thus the only valid permutation is possible — the given o... | A permutation of size $$$n$$$ is an array of size $$$n$$$ such that each integer from $$$1$$$ to $$$n$$$ occurs exactly once in this array. An inversion in a permutation $$$p$$$ is a pair of indices $$$(i, j)$$$ such that $$$i > j$$$ and $$$a_i < a_j$$$. For example, a permutation $$$[4, 1, 3, 2]$$$ contains $$$4... | Print a single integer — the expected total number of inversions in the resulting valid permutation. It can be shown that it is in the form of $$$\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are non-negative integers and $$$Q \ne 0$$$. Report the value of $$$P \cdot Q^{-1} \pmod {998244353}$$$. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the sequence. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$-1 \le p_i \le n$$$, $$$p_i \ne 0$$$) — the initial sequence. It is guaranteed that all elements not equal to $$$-1$$$ are pairwise dis... | standard output | standard input | Python 3 | Python | 2,300 | train_049.jsonl | a7651e4321d0aa91c3ac029385913b22 | 256 megabytes | ["3\n3 -1 -1", "2\n1 2", "2\n-1 -1"] | PASSED | def merge(a,b):
inda=0
indb=0
lena=len(a)
lenb=len(b)
d=[a[-1]+b[-1]+1000]
a+=d
b+=d
c=[]
inversions=0
for i in range(lena+lenb):
if a[inda]<b[indb]:
c.append(a[inda])
inda+=1
else:
c.append(b[indb])
indb+=1
... | 1546007700 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
1 second | ["6\n1 5 3 6 2 4", "2\n1 3"] | a52ceb8a894809b570cbb74dc5ef76e1 | null | An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sur... | In the first line print integer k — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n), where ai is the number of the student on the i-th position. The students on adjacent posit... | A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam. | standard output | standard input | Python 2 | Python | 1,100 | train_016.jsonl | 5a7fb39e1ee0851c213f8b8206fa1b1c | 256 megabytes | ["6", "3"] | PASSED | n = input()
if n == 1:
print 1
print 1
elif n == 2:
print 1
print 1
elif n == 3:
print 2
print 1, 3
elif n == 4:
print 4
print 2, 4, 1, 3
else:
print n
B = []
for i in range(1, n + 1, 2):
B.append(i)
for i in range(2, n + 1, 2):
B.append(i)
for... | 1428854400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["NO", "YES", "NO", "YES"] | b1ef19d7027dc82d76859d64a6f43439 | null | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him;... | If Vasya can write the given anonymous letter, print YES, otherwise print NO | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 и s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of th... | standard output | standard input | Python 3 | Python | 1,100 | train_005.jsonl | e12f9ee8fd0abf259bb9bd8432f45b5d | 256 megabytes | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk... | PASSED | import collections
l=list(input())
p=list(input())
#print(p)
#print(l)
cl=collections.Counter(l)
pl=collections.Counter(p)
#print(cl)
#print(pl)
plk=list(pl.keys())
#print(plk)
if ' ' in plk:
plk.remove(' ')
else:
pass
n=len(plk)
i=0
er=0
#print(cl['s'])
while i<n:
h=plk[i]
t=cl[h]
q=pl[h]
#prin... | 1291046400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["1\n24\n300\n...5679392764\n111"] | b235128854812b3911f60e5007e451d7 | null | A Russian space traveller Alisa Selezneva, like any other schoolgirl of the late 21 century, is interested in science. She has recently visited the MIT (Moscow Institute of Time), where its chairman and the co-inventor of the time machine academician Petrov told her about the construction of a time machine.During the d... | For each query print the meaning of the expression if it contains at most 10 characters. Otherwise, print three characters "." (without the quotes), and then ten last digits of the time expression. Print the answer to each query on a single line. Follow the format, given in the sample as closely as possible. | The first input line contains a single integer t (1 ≤ t ≤ 105) — the number of test sets for which you should solve the problem. Each of the next t lines contains the description of a test — four positive integers x1, y1, x2 and y2 (1 ≤ x1 ≤ x2 ≤ 109, 1 ≤ y1 ≤ y2 ≤ 109), separated by spaces. | standard output | standard input | Python 2 | Python | 2,600 | train_012.jsonl | 078fd775f24ee84a923552d4fc50e7ce | 256 megabytes | ["5\n1 1 1 1\n2 2 3 3\n2 3 5 6\n100 87 288 2002\n4 2 5 4"] | PASSED |
def cal(x0, y0, x1, y1):
mini = min(x1, y1)
maxi = max(x0, y0)
res = 0
res += (x1 * (x1 + 1) * (x1 * 2 + 1) * (y1 - (y0 - 1)) - mini * (mini + 1) * (mini * 2 + 1) * y1 + (maxi - 1) * maxi * (maxi * 2 - 1) * (y0 - 1) + (y1 - 1) * y1 * (y1 * 2 - 1) * (x1 - (x0 - 1)) - (mini - 1) * mini * (mini * 2 - 1) * x1 + (... | 1353857400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\n5 8\n2\n1 11\n1\n9\n0\n1\n1\n2\n1 2\n1\n2\n2\n1 3\n1\n2\n2\n2 3\n1\n3\n1\n3\n2\n3 4\n1\n4"] | d0de903a70f8a18589eba60b1f2dd98e | NoteIn the first test case for the first query you can remove the rods numbered $$$5$$$ and $$$8$$$, then the following set of rods will remain: +--+--++-++-. It is easy to see that here the sign-variable sum is zero.In the second test case: For the first query, we can remove the rods numbered $$$1$$$ and $$$11$$$, th... | This is the hard version of the problem. The difference between the versions is that the hard version does require you to output the numbers of the rods to be removed. You can make hacks only if all versions of the problem are solved.Stitch likes experimenting with different machines with his friend Sparky. Today they ... | For each test case, print the answer in the following format: In the first line print a single integer $$$k$$$ — the minimal number of rods that can be removed. In the second line print $$$k$$$ numbers separated by a space — the numbers of rods to be removed. If there is more than one correct answer, you can print any. | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10^3$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains two positive integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 3 \cdot 10^5$$$) — the n... | standard output | standard input | PyPy 3-64 | Python | 2,200 | train_086.jsonl | a043d9e1d4632a0ab43333d2a5b7b5a9 | 512 megabytes | ["3\n14 1\n+--++---++-++-\n1 14\n14 3\n+--++---+++---\n1 14\n6 12\n3 10\n4 10\n+-+-\n1 1\n1 2\n1 3\n1 4\n2 2\n2 3\n2 4\n3 3\n3 4\n4 4"] | PASSED | import sys
from bisect import bisect_left
ipt=sys.stdin.readline
T=int(ipt())
for _ in range(T):
n, q=map(int, ipt().split())
s=sys.stdin.readline().strip()
a=[0 for i in range(n)]
for i in range(n):
if s[i]=='+':
a[i]=-1 if i&1 else 1
else:
a[i]=1 i... | 1629988500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["2", "3"] | e9f4582601a4296a53b77678589d09ef | NoteIn the first sample, one of the optimal p is [4, 3, 2, 1]. | DZY loves planting, and he enjoys solving tree problems.DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He defines the function g(x, y) (1 ≤ x, y ≤ n) as the longest edge in the shortest path between nodes x and y. Specially g(z, z) = 0 for every z... | Print a single integer representing the answer. | The first line contains an integer n (1 ≤ n ≤ 3000). Each of the next n - 1 lines contains three integers ai, bi, ci (1 ≤ ai, bi ≤ n; 1 ≤ ci ≤ 10000), denoting an edge between ai and bi with length ci. It is guaranteed that these edges form a tree. Each of the next n lines describes an element of sequence x. The j-th l... | standard output | standard input | Python 3 | Python | 2,700 | train_038.jsonl | 6ad40aae202ef155985c57e52078c11c | 256 megabytes | ["4\n1 2 1\n2 3 2\n3 4 3\n1\n1\n1\n1", "4\n1 2 1\n2 3 2\n3 4 3\n4\n4\n4\n4"] | PASSED | n = int(input())
edges = [[int(x) for x in input().split()] for i in range(n-1)]
edges = sorted(edges)
use_count = [0]+[int(input()) for i in range(n)]
lo,hi = 0,10000
def getpar(par,u):
if par[par[u]] == par[u]:
return par[u]
par[u] = getpar(par,par[u])
return par[u]
def unite(par,sz,use,u,v):
... | 1404651900 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
4 seconds | ["0\n1\n2\n4"] | 5defa8c72eaa0b71d120752de71d0df2 | NoteIn the first test case, we can apply the operation on each of the $$$4$$$s with $$$(p,q) = (2,2)$$$ and make the multiset $$$\{2,2,2,2,2,2,2\}$$$ with balance $$$\max(\{2,2,2,2,2,2,2\}) - \min(\{2,2,2,2,2,2,2\}) = 0$$$. It is obvious we cannot make this balance less than $$$0$$$.In the second test case, we can appl... | Ibti was thinking about a good title for this problem that would fit the round theme (numerus ternarium). He immediately thought about the third derivative, but that was pretty lame so he decided to include the best band in the world — Three Days Grace.You are given a multiset $$$A$$$ with initial size $$$n$$$, whose e... | For each test case, print a single integer — the minimum possible balance. | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The second line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^6$$$, $$$1 \le m \le 5 \cdot 10^6$$$) — the initial size of the multiset, and the maximum value of an element.... | standard output | standard input | PyPy 3-64 | Python | 2,600 | train_088.jsonl | c86b5418a41f764f89181ed96d035fba | 256 megabytes | ["4\n\n5 10\n\n2 4 2 4 2\n\n3 50\n\n12 2 3\n\n2 40\n\n6 35\n\n2 5\n\n1 5"] | PASSED | from sys import stdin
input=lambda :stdin.readline()[:-1]
def solve():
n,m=map(int,input().split())
a=list(set(map(int,input().split())))
n=len(a)
exist=[0]*(m+1)
for i in a:
exist[i]=1
dp=list(range(m+1))
cnt=0
ans=10**9
mx_cnt=[0]*(m+1)
mx=m
for i in range(m,0,-1):
if ex... | 1656945300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["2\n2\n2\n2\n1\n0"] | d34ffd75ef82111d1077db4b033d5195 | null | You and your friend are playing the game Mortal Kombat XI. You are trying to pass a challenge tower. There are $$$n$$$ bosses in this tower, numbered from $$$1$$$ to $$$n$$$. The type of the $$$i$$$-th boss is $$$a_i$$$. If the $$$i$$$-th boss is easy then its type is $$$a_i = 0$$$, otherwise this boss is hard and its ... | For each test case, print the answer: the minimum number of skip points your friend needs to use so you and your friend kill all $$$n$$$ bosses in the given order. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of bosses. The second line of the test case contains $$$n$$$ in... | standard output | standard input | PyPy 3 | Python | 1,500 | train_006.jsonl | 4230fc33b02c02feb394d87e9c7a851d | 256 megabytes | ["6\n8\n1 0 1 1 0 1 1 1\n5\n1 1 1 1 0\n7\n1 1 1 1 0 0 1\n6\n1 1 1 1 1 1\n1\n1\n1\n0"] | PASSED | for _ in range(int(input())):
n=int(input())
arr=[int(el) for el in input().split()]
him=[0]*(n+1)
us=[0]*(n+1)
for i in range(n-1,-1,-1):
him[i]=us[i+1]+arr[i]
if (i+2)<=n:
him[i]=min(him[i],us[i+2]+arr[i]+arr[i+1])
us[i]=him[i+1]
if (i+2)<=n:
... | 1600094100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["2\nabba", "0\nababab", "1\nba"] | 8ad06ac90b258a8233e2a1cf51f68078 | NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'. | Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f... | In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y... | The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. | standard output | standard input | PyPy 3 | Python | 800 | train_005.jsonl | b438a19e66ae7d78c39b64d8aa713c87 | 256 megabytes | ["4\nbbbb", "6\nababab", "2\naa"] | PASSED | n,a,b=int(input()),0,0
s=input()
tot = 0
l=list(s)
for i in range(len(s)):
if s[i] == 'a':a+=1
else:b+=1
# print(s[i],a,b)
if i&1:
tot+=1
if a>b:
a-=1
b+=1
# print(l)
l[i]='b'
# print(l,a,b,i)
elif b>a:
a+=1
... | 1569049500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["5", "10", "2"] | 5099a9ae62e82441c496ac37d92e99e3 | NoteConsider the first sample. First Vanya puts the piece of potato of height 5 into processor. At the end of the second there is only amount of height 2 remaining inside. Now Vanya puts the piece of potato of height 4. At the end of the second there is amount of height 3 remaining. Vanya puts the piece of height 3... | Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed h and the processor smashes k centimeters of potato each second. If there are less than k centimeters remaining, than during this second processor smashes all the remaining potato.Vanya has... | Print a single integer — the number of seconds required to smash all the potatoes following the process described in the problem statement. | The first line of the input contains integers n, h and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ h ≤ 109) — the number of pieces of potato, the height of the food processor and the amount of potato being smashed each second, respectively. The second line contains n integers ai (1 ≤ ai ≤ h) — the heights of the pieces. | standard output | standard input | Python 2 | Python | 1,400 | train_023.jsonl | 735b45a7a26e046080985accc5b12f5e | 256 megabytes | ["5 6 3\n5 4 3 2 1", "5 6 3\n5 5 5 5 5", "5 6 3\n1 2 1 1 1"] | PASSED | n,h,k=map(int,raw_input().split())
l=map(int,raw_input().split())
ans=chk=0
for i in l:
if chk+i<k:
chk+=i
elif chk+i<=h:
chk+=i
ans+=chk/k
chk%=k
else:
ans+=chk/k
chk%=k
if chk+i>h:
ans+=1
chk=i
else:
chk+=i... | 1464798900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["4\n888188", "0\n533", "3\n0000002223"] | cb082cbe9b34a45da851b6764bbc30c3 | NoteIn the first sample replacing the second digit with an "8" costs |9 - 8| = 1. Replacing the fifth digit with an "8" costs the same. Replacing the sixth digit costs |6 - 8| = 2. As a result, Vasya will pay 1 + 1 + 2 = 4 for a beautiful number "888188".The lexicographical comparison of strings is performed by the <... | A car number in Berland consists of exactly n digits. A number is called beautiful if it has at least k equal digits. Vasya wants to change the digits in his car's number so that the number became beautiful. To replace one of n digits Vasya has to pay the sum of money, equal to the absolute difference between the old d... | On the first line print the minimum sum of money Vasya needs to change the number. On the second line print the car's new number. If there are several solutions, print the lexicographically minimum one. | The first line contains two space-separated integers n and k (2 ≤ n ≤ 104, 2 ≤ k ≤ n) which represent how many digits the number has and how many equal digits a beautiful number should have. The second line consists of n digits. It describes the old number of Vasya's car. It is guaranteed that the number contains no sp... | standard output | standard input | PyPy 3 | Python | 1,900 | train_017.jsonl | 3152cb7947285181debb688adc1aa8cd | 256 megabytes | ["6 5\n898196", "3 2\n533", "10 6\n0001112223"] | PASSED | n,k = map(int,input().split())
s = list(map(int, input()))
e = list(enumerate(s))
min_cost = 9*n
a=[9]*n
for j in range(10):
r = s[:]
cost = 0
for x, y in sorted(e, key=lambda t : (abs(t[1] - j), -t[1], t[0]*(-1)**(j > t[1]) ))[:k]:
r[x]=j
cost += abs(y-j)
if cost < min_cost :
... | 1317999600 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["3", "0", "1"] | bf115b24d85a0581e709c012793b248b | NoteIn the first sample, $$$|8 - 5| = 3 \equiv 3 \bmod 10$$$.In the second sample, $$$|1 - 4|\cdot|1 - 5|\cdot|4 - 5| = 3\cdot 4 \cdot 1 = 12 \equiv 0 \bmod 12$$$.In the third sample, $$$|1 - 4|\cdot|1 - 9|\cdot|4 - 9| = 3 \cdot 8 \cdot 5 = 120 \equiv 1 \bmod 7$$$. | To become the king of Codeforces, Kuroni has to solve the following problem.He is given $$$n$$$ numbers $$$a_1, a_2, \dots, a_n$$$. Help Kuroni to calculate $$$\prod_{1\le i<j\le n} |a_i - a_j|$$$. As result can be very big, output it modulo $$$m$$$.If you are not familiar with short notation, $$$\prod_{1\le i<j\... | Output the single number — $$$\prod_{1\le i<j\le n} |a_i - a_j| \bmod m$$$. | The first line contains two integers $$$n$$$, $$$m$$$ ($$$2\le n \le 2\cdot 10^5$$$, $$$1\le m \le 1000$$$) — number of numbers and modulo. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). | standard output | standard input | PyPy 2 | Python | 1,600 | train_014.jsonl | bde2909ab5ae8852bb330295d5846e42 | 256 megabytes | ["2 10\n8 5", "3 12\n1 4 5", "3 7\n1 4 9"] | PASSED | from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout
from itertools import repeat
import math
# sys.stdin = open('input')
def inp():
return map(int, raw_input().split())
def inst():
return raw_input().strip()
def main():
n, m = inp()
da = inp()
... | 1583246100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["YES\nNO\nYES\nNO\nYES"] | 447c17cba953d6e2da50c242ac431ab4 | NoteIn the test case of the example, $$$m=3, s=13, b=[3,1,4]$$$. You can append to $$$b$$$ the numbers $$$6,2,5$$$, the sum of which is $$$6+2+5=13$$$. Note that the final array will become $$$[3,1,4,6,2,5]$$$, which is a permutation.In the second test case of the example, $$$m=1, s=1, b=[1]$$$. You cannot append one o... | A sequence of $$$n$$$ numbers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once. For example, the sequences [$$$3, 1, 4, 2$$$], [$$$1$$$] and [$$$2,1$$$] are permutations, but [$$$1,2,1$$$], [$$$0,1$$$] and [$$$1,3,4$$$] — are not.Polycarp lost his favorite permutation and found o... | Print $$$t$$$ lines, each of which is the answer to the corresponding test set. Print as the answer YES if you can append several elements to the array $$$b$$$, that their sum equals $$$s$$$ and the result will be a permutation. Output NO otherwise. You can output the answer in any case (for example, yEs, yes, Yes and ... | The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) —the number of test cases. Then the descriptions of the test cases follow. The first line of each test set contains two integers $$$m$$$ and $$$s$$$ ($$$1 \le m \le 50$$$, $$$1 \le s \le 1000$$$)—-the number of found elements and the sum... | standard output | standard input | Python 3 | Python | 800 | train_086.jsonl | fc7993bdf580184073f9227a0415db02 | 256 megabytes | ["5\n\n3 13\n\n3 1 4\n\n1 1\n\n1\n\n3 3\n\n1 4 2\n\n2 1\n\n4 3\n\n5 6\n\n1 2 3 4 5"] | PASSED | t=int(input())
for i in range(t):
u=input().split()
v=input().split()
u=[int(i) for i in u]
v=[int(t) for t in v]
sum=u[1]
mi=1
ma=max(v)
cursum=0
missing=[]
ii=None
for i in range(mi,ma):
if cursum==sum:
if len(v)==ma:
ii=True
break
if i not in v:
missing.append(i)
v.... | 1668782100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["6", "6", "3"] | 9693f60fc65065d00a1899df999405fe | NoteLet $$$s[l; r]$$$ be the substring of $$$s$$$ from the position $$$l$$$ to the position $$$r$$$ inclusive.Then in the first example you can remove the following substrings: $$$s[1; 2]$$$; $$$s[1; 3]$$$; $$$s[1; 4]$$$; $$$s[2; 2]$$$; $$$s[2; 3]$$$; $$$s[2; 4]$$$. In the second example you can remove the follo... | You are given a string $$$s$$$ of length $$$n$$$ consisting only of lowercase Latin letters.A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring of string "codeforces", but string "coder" is not.Your task is to calculate the number of ways to remove exactly one substring ... | Print one integer — the number of ways modulo $$$998244353$$$ to remove exactly one substring from $$$s$$$ in such way that all remaining characters are equal. | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of the string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$ consisting only of lowercase Latin letters. It is guaranteed that there is at least two different characters in $$$s$$$... | standard output | standard input | Python 3 | Python | 1,300 | train_009.jsonl | b5c2c26388616ec2aaed2b2a56281f36 | 256 megabytes | ["4\nabaa", "7\naacdeee", "2\naz"] | PASSED | n=int(input())
s=input()
sf=s[0]
sl=s[-1]
f=0
l=0
ans = 0
if(s.count(sf)!=n):
for i in range(n):
if(s[i]==sf):
ans+=1
f+=1
else:
ans+=1
break
for i in range(n)[::-1]:
if(s[i]==sl):
ans+=1
l+=1
else:
ans+=1
break
ans-=1
if(sf==sl):
ans+=f*l
else:
ans = n*(n+1)
ans //=2
ans+=1
pr... | 1546007700 | [
"math",
"strings"
] | [
0,
0,
0,
1,
0,
0,
1,
0
] | |
2 seconds | ["NO", "YES", "NO"] | faf79a485fe06f3081befde45471a569 | NoteIn the second example input, the initial statuses of the doors are [1, 0, 1] (0 means locked, 1 — unlocked).After toggling switch 3, we get [0, 0, 0] that means all doors are locked.Then, after toggling switch 1, we get [1, 1, 1] that means all doors are unlocked.It can be seen that for the first and for the third ... | Moriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlocked. But, there is a condition that the people in the hotel can only escape when all the doors are unlocked at the same time. There are m switches. Each switch control doors of some rooms, but each door is controlled by... | Output "YES" without quotes, if it is possible to open all doors at the same time, otherwise output "NO" without quotes. | First line of input contains two integers n and m (2 ≤ n ≤ 105, 2 ≤ m ≤ 105) — the number of rooms and the number of switches. Next line contains n space-separated integers r1, r2, ..., rn (0 ≤ ri ≤ 1) which tell the status of room doors. The i-th room is locked if ri = 0, otherwise it is unlocked. The i-th of next m l... | standard output | standard input | PyPy 3 | Python | 2,000 | train_008.jsonl | bb8667f262d39ca5ad354cb351f83ef3 | 256 megabytes | ["3 3\n1 0 1\n2 1 3\n2 1 2\n2 2 3", "3 3\n1 0 1\n3 1 2 3\n1 2\n2 1 3", "3 3\n1 0 1\n3 1 2 3\n2 1 2\n1 3"] | PASSED | import sys
from math import inf
time = 0
cc = 0
l = {}
d = {}
f = {}
conn_comp = {}
on_stack = {}
stack = []
color = []
def tarjan(graph):
global l
global d
global f
global pi
global stack
global on_stack
l = {key : inf for key in graph}
d = {key : -1 for key in graph}
f = {key : ... | 1487861100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
3 seconds | ["4", "2"] | 2fc19c3c9604e746a17a63758060c5d7 | NoteIn the first sample the pairs of vertexes at distance 2 from each other are (1, 3), (1, 5), (3, 5) and (2, 4). | A tree is a connected graph that doesn't contain any cycles.The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.You are given a tree with n vertices and a positive number k. Find the number of distinct pairs of the vertices which have a distance of exactly k ... | Print a single integer — the number of distinct pairs of the tree's vertices which have a distance of exactly k between them. Please do not use 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 contains two integers n and k (1 ≤ n ≤ 50000, 1 ≤ k ≤ 500) — the number of vertices and the required distance between the vertices. Next n - 1 lines describe the edges as "ai bi" (without the quotes) (1 ≤ ai, bi ≤ n, ai ≠ bi), where ai and bi are the vertices connected by the i-th edge. All given edges a... | standard output | standard input | Python 3 | Python | 1,800 | train_024.jsonl | d743fe195ea0d3d96e5a6a9db0797781 | 512 megabytes | ["5 2\n1 2\n2 3\n3 4\n2 5", "5 3\n1 2\n2 3\n3 4\n4 5"] | PASSED | n, k = map(int, input().split())
t, q = [[] for i in range(n + 1)], [1]
for j in range(n - 1):
a, b = map(int, input().split())
t[a].append(b)
t[b].append(a)
for x in q:
for y in t[x]: t[y].remove(x)
q.extend(t[x])
q.reverse()
a, s = {}, 0
for x in q:
a[x] = [1]
u = len(a[x])
for y i... | 1331478300 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["1", "6", "4", "-1"] | 6c5cf702d85ff25cf9e7bfd16534197d | NoteIn the first test case, the optimal strategy is as follows: Red chooses to color the subtrees of nodes $$$2$$$ and $$$3$$$. Blue chooses to color the subtree of node $$$4$$$. At the end of this process, nodes $$$2$$$ and $$$3$$$ are red, node $$$4$$$ is blue, and node $$$1$$$ is white. The score of the game is ... | Two players, Red and Blue, are at it again, and this time they're playing with crayons! The mischievous duo is now vandalizing a rooted tree, by coloring the nodes while playing their favorite game.The game works as follows: there is a tree of size $$$n$$$, rooted at node $$$1$$$, where each node is initially white. Re... | Print one integer — the resulting score if both Red and Blue play optimally. | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$1 \le k \le n$$$) — the number of vertices in the tree and the maximum number of red nodes. Next $$$n - 1$$$ lines contains description of edges. The $$$i$$$-th line contains two space separated integers $$$u_i$$$ and $$$v_i$$$... | standard output | standard input | PyPy 3 | Python | 2,400 | train_100.jsonl | 535b2792a219d2a75a8872e852b573ca | 256 megabytes | ["4 2\n1 2\n1 3\n1 4", "5 2\n1 2\n2 3\n3 4\n4 5", "7 2\n1 2\n1 3\n4 2\n3 5\n6 3\n6 7", "4 1\n1 2\n1 3\n1 4"] | PASSED | import sys
input = sys.stdin.buffer.readline
n, k = [*map(int, input().split())]
d = [[] for i in range(n)]
p, h, l, v = [0]*n, [-1]*n, [0]*n, [0]*n
for _ in range(n-1):
a, b = [int(i)-1 for i in input().split()]
d[a].append(b)
d[b].append(a)
q, p[0] = [0], -1
leaves = []
while q:
q1 = []
... | 1640356500 | [
"math",
"games",
"trees",
"graphs"
] | [
1,
0,
1,
1,
0,
0,
0,
1
] | |
3 seconds | ["1 1 0 1 6 -1 -1 -1"] | ab89b5642465e632547fb57b9895beb6 | NoteFor $$$k = 0$$$, to make the string $$$a$$$ have no occurrence of 101, you can do one character change as follows.100101011 $$$\rightarrow$$$ 100100011For $$$k = 1$$$, you can also change a single character.100101011 $$$\rightarrow$$$ 100001011For $$$k = 2$$$, no changes are needed. | The Winter holiday will be here soon. Mr. Chanek wants to decorate his house's wall with ornaments. The wall can be represented as a binary string $$$a$$$ of length $$$n$$$. His favorite nephew has another binary string $$$b$$$ of length $$$m$$$ ($$$m \leq n$$$).Mr. Chanek's nephew loves the non-negative integer $$$k$$... | Output $$$n - m + 2$$$ integers — the $$$(k+1)$$$-th integer denotes the minimal number of elements in $$$a$$$ that have to be changed so there are exactly $$$k$$$ occurrences of $$$b$$$ as a substring in $$$a$$$. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq m \leq n \leq 500$$$) — size of the binary string $$$a$$$ and $$$b$$$ respectively. The second line contains a binary string $$$a$$$ of length $$$n$$$. The third line contains a binary string $$$b$$$ of length $$$m$$$. | standard output | standard input | PyPy 3 | Python | 2,200 | train_102.jsonl | ff71665530d2b690ed550e27d5f5aeb7 | 512 megabytes | ["9 3\n100101011\n101"] | PASSED |
def main():
n, m = readIntArr()
a = input()
b = input()
maxCnt = n - m + 1
depthTxn = [[-1, -1] for _ in range(m + 1)] # depthTxn[currentDepth][0 or 1] = new maximum depth
def getMaxDepth(c):
# c : xxxxx
# b : yyyyy
# depth <->
for depth ... | 1633181700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["2\n1 2", "3\n1 3 4"] | 5c64671081f9f5332d0ad57503091a54 | null | Valera has n counters numbered from 1 to n. Some of them are connected by wires, and each of the counters has a special button.Initially, all the counters contain number 0. When you press a button on a certain counter, the value it has increases by one. Also, the values recorded in all the counters, directly connected ... | If Valera can't win the dispute print in the first line -1. Otherwise, print in the first line integer k (0 ≤ k ≤ n). In the second line print k distinct space-separated integers — the numbers of the counters, where Valera should push buttons to win the dispute, in arbitrary order. If there exists multiple answers, you... | The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105), that denote the number of counters Valera has and the number of pairs of counters connected by wires. Each of the following m lines contains two space-separated integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi), that mean that counters with numbe... | standard output | standard input | Python 2 | Python | 2,100 | train_018.jsonl | c8561010c7952d253b787470b827a6a0 | 256 megabytes | ["5 5\n2 3\n4 1\n1 5\n5 3\n2 1\n1 1 2 0 2", "4 2\n1 2\n3 4\n0 0 0 0"] | PASSED | def main():
n, m = map(int, raw_input().split())
data = {}
for pos in xrange(n):
data[pos] = [pos]
for i in xrange(m):
a, b = map(int, raw_input().split())
a, b = a - 1, b - 1
data[a].append(b)
data[b].append(a)
est = [0 for i in xrange(n)]
ar = map(int,... | 1352647800 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["14 0", "1995 1995"] | c19afaa6c46cd361e0e5ccee61f6f520 | null | You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according (for every natural number i). Here point B is symmetric to A according M, if M is the center of the l... | On a single line output the coordinates of Mj, space separated. | On the first line you will be given an integer n (1 ≤ n ≤ 105), which will be odd, and j (1 ≤ j ≤ 1018), where j is the index of the desired point. The next line contains two space separated integers, the coordinates of M0. After that n lines follow, where the i-th line contain the space separated integer coordinates o... | standard output | standard input | Python 2 | Python | 1,800 | train_007.jsonl | 5888d6e920262cae6ff75cf6e79c8617 | 256 megabytes | ["3 4\n0 0\n1 1\n2 3\n-5 3", "3 1\n5 5\n1000 1000\n-1000 1000\n3 100"] | PASSED | #!/usr/bin/env python
def mul(a, b):
res = []
for i in range(len(b)):
res.append(a*b[i])
return tuple(res)
def add(a, b):
res = []
for i in range(len(a)):
res.append(a[i]+b[i])
return tuple(res)
n, j = tuple(map(int, raw_input().split()))
m0 = tuple(map(int, raw_input().split... | 1280149200 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
1 second | ["Bicarp", "Bicarp", "Bicarp", "Monocarp"] | 028882706ed58b61b4672fc3e76852c4 | NoteSince there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp.In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replac... | Monocarp and Bicarp live in Berland, where every bus ticket consists of $$$n$$$ digits ($$$n$$$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even.Monocarp and Bicarp have decided to play a game wit... | If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). | The first line contains one even integer $$$n$$$ $$$(2 \le n \le 2 \cdot 10^{5})$$$ — the number of digits in the ticket. The second line contains a string of $$$n$$$ digits and "?" characters — the ticket which Monocarp and Bicarp have found. If the $$$i$$$-th character is "?", then the $$$i$$$-th digit is erased. Not... | standard output | standard input | Python 3 | Python | 1,700 | train_004.jsonl | 3bafa2be1a5dbf477c24e2809102146e | 256 megabytes | ["4\n0523", "2\n??", "8\n?054??0?", "6\n???00?"] | PASSED | n = int(input())
word = input()
tot = 0
for i in range(n):
if word[i] == '?':
inc = 9
else:
inc = 2 * int(word[i])
tot += (2 * (i < n//2) - 1) * inc
print(["Monocarp", "Bicarp"][tot == 0]) | 1568543700 | [
"math",
"games"
] | [
1,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["5\n6\n5\n2\n9"] | 8736df815ea0fdf390cc8d500758bf84 | null | The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th... | For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters fro... | The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The ... | standard output | standard input | Python 3 | Python | 1,300 | train_001.jsonl | cefa9829ec2c484aef797e8e4e06e0e9 | 256 megabytes | ["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"] | PASSED | n=int(input())
s=str(input())
f=int(input())
d={}
for i in range(n):
if s[i] not in d:
d[s[i]]=[i]
else:
d[s[i]].append(i)
for i in range(f):
c=str(input())
h={}
m=0
for j in range(len(c)):
if(c[j] not in h):
h[c[j]]=1
if(d[c[j]][0]>m):
m=d[c[j]][0]
else:
if(d[c[j]][h[c[j]]]>m):
m=d[c[j]]... | 1561905900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["4\n6 3 2 3", "-1"] | df0b20cf9b848f7406a13378126f301f | null | Welcome to another task about breaking the code lock! Explorers Whitfield and Martin came across an unusual safe, inside of which, according to rumors, there are untold riches, among which one can find the solution of the problem of discrete logarithm!Of course, there is a code lock is installed on the safe. The lock h... | If it is impossible to get string t from string s using no more than 6100 operations «shift», print a single number - 1. Otherwise, in the first line output the number of operations k (0 ≤ k ≤ 6100). In the next line output k numbers xi corresponding to the operations «shift xi» (0 ≤ xi ≤ n) in the order in which they... | The first line contains an integer n, the length of the strings s and t (1 ≤ n ≤ 2 000). After that, there are two strings s and t, consisting of n lowercase Latin letters each. | standard output | standard input | Python 3 | Python | 2,300 | train_040.jsonl | 8f004c223ab44ac6b47eec457ec2435d | 256 megabytes | ["6\nabacbb\nbabcba", "3\naba\nbba"] | PASSED | n = int(input())
s = input()
t = input()
if sorted(s) != sorted(t):
print(-1)
else:
ans = []
for i in t:
j = 0
for j in range(n):
if i == s[j]:
break
ans.append(n-j-1)
ans.append(1)
ans.append(n)
s = "".join(reversed(s[:j])) + s[j+... | 1519574700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["bbba", "cccccbba"] | 77e2a6ba510987ed514fed3bd547b5ab | NoteLet's look at samples and see what the sought subsequences look like (they are marked with uppercase bold letters).The first sample: aBaBBAThe second sample: abbCbCCaCbbCBaaBA | You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence.We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2... s|s|.String x = x1x2... x|x| is lexicographically larger than string y ... | Print the lexicographically maximum subsequence of string s. | The single line contains a non-empty string s, consisting only of lowercase English letters. The string's length doesn't exceed 105. | standard output | standard input | Python 3 | Python | 1,100 | train_013.jsonl | 40b3d7e774acf27016df11f5a7f0275b | 256 megabytes | ["ababba", "abbcbccacbbcbaaba"] | PASSED | s = input()
bigger = 'a'
res = ''
for i in range(len(s)-1,-1,-1):
if s[i] >= bigger:
res = s[i] + res
bigger = s[i]
print(res) | 1339506000 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["2\n4\n7"] | f3a27e4dc3085712608ecf844e663dfd | null | Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.The game is played on a tree having n nodes, numbered from 1 to n. Each node i has an initial value initi, which is... | In the first line output an integer number cnt, representing the minimal number of operations you perform. Each of the next cnt lines should contain an integer xi, representing that you pick a node xi. | The first line contains an integer n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) meaning there is an edge between nodes ui and vi. The next line contains n integer numbers, the i-th of them corresponds to initi (initi is either 0 or 1). The following line also ... | standard output | standard input | Python 3 | Python | 1,300 | train_011.jsonl | 6c2a1fd8b138ccd09bd98da0ccb5c34c | 256 megabytes | ["10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1"] | PASSED | import fileinput
def levels(n, e):
l = [0 for _ in range(n)]
q = [(0, -1, 0)]
while q:
v, u, d = q.pop()
l[v] = d
for w in e[v]:
if w != u: q.append((w, v, d+1))
return l
def solve(n, e, x, g):
l = levels(n, e)
f = [0, 0]
q = [(0, -1)]
z = []
while q:
v, u = q.pop()
if v == -1:
f = u
co... | 1399822800 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["Yes\nNo\nNo\nYes", "No"] | bda76c8ccd3ba7d073a8f923d772361c | NoteIn the first test case it is easy to see that the array is integral: $$$\left \lfloor \frac{1}{1} \right \rfloor = 1$$$, $$$a_1 = 1$$$, this number occurs in the arry $$$\left \lfloor \frac{2}{2} \right \rfloor = 1$$$ $$$\left \lfloor \frac{5}{5} \right \rfloor = 1$$$ $$$\left \lfloor \frac{2}{1} \right \rfloo... | You are given an array $$$a$$$ of $$$n$$$ positive integers numbered from $$$1$$$ to $$$n$$$. Let's call an array integral if for any two, not necessarily different, numbers $$$x$$$ and $$$y$$$ from this array, $$$x \ge y$$$, the number $$$\left \lfloor \frac{x}{y} \right \rfloor$$$ ($$$x$$$ divided by $$$y$$$ with rou... | For each test case print Yes if the array is integral and No otherwise. | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$c$$$ ($$$1 \le n \le 10^6$$$, $$$1 \le c \le 10^6$$$) — the size o... | standard output | standard input | PyPy 3-64 | Python | 1,800 | train_091.jsonl | e3581bc6269fd5004753d95079b9d865 | 512 megabytes | ["4\n\n3 5\n\n1 2 5\n\n4 10\n\n1 3 3 7\n\n1 2\n\n2\n\n1 1\n\n1", "1\n\n1 1000000\n\n1000000"] | PASSED | from collections import defaultdict, Counter,deque
from math import sqrt, log10, log, floor, factorial,gcd,ceil,log2
from bisect import bisect_left, bisect_right,insort
from itertools import permutations,combinations
import sys, io, os
input = sys.stdin.readline
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).re... | 1646560500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["Infinite\nFinite\nInfinite\nFinite"] | 388450021f2f33177d905879485bb531 | null | Consider the set of all nonnegative integers: $$${0, 1, 2, \dots}$$$. Given two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^4$$$). We paint all the numbers in increasing number first we paint $$$0$$$, then we paint $$$1$$$, then $$$2$$$ and so on.Each number is painted white or black. We paint a number $$$i$$$ a... | For each test case, print one line containing either "Infinite" or "Finite" (without the quotes). Output is case-insensitive (i.e. "infinite", "inFiNite" or "finiTE" are all valid answers). | The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then $$$t$$$ lines follow, each line contains two space-separated integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^4$$$). | standard output | standard input | PyPy 3 | Python | 1,000 | train_005.jsonl | 660aeacbab8aee24d13269408d58f40f | 256 megabytes | ["4\n10 10\n1 10\n6 9\n7 3"] | PASSED | tests = int(input())
for _ in range(tests):
n, k = map(int, input().split())
n, k = max(n, k), min(n, k)
while n % k != 0:
n %= k
n, k = k, n
if k == 1:
print("Finite")
else:
print("Infinite")
| 1572618900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["YES\nYES\nNO\nYES"] | c7e4f544ec8b4972291542e66aff5df5 | NoteIn the first test case, one can apply the operation with $$$x = 3$$$ to obtain the array $$$[2, 2, 0, 2]$$$, and then apply the operation with $$$x = 2$$$ to obtain $$$[0, 0, 0, 0]$$$.In the second test case, all numbers are already equal.In the fourth test case, applying the operation with $$$x = 4$$$ results in t... | You are given an array of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. You can make the following operation: choose an integer $$$x \geq 2$$$ and replace each number of the array by the remainder when dividing that number by $$$x$$$, that is, for all $$$1 \leq i \leq n$$$ set $$$a_i$$$ to $$$a_i \bmod x$$... | For each test case, print a line with YES if you can make all elements of the list equal by applying the operation. Otherwise, print NO. You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer). | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line of ... | standard output | standard input | PyPy 3-64 | Python | 1,200 | train_091.jsonl | c40085c9aac07680bff9d03432479d0b | 256 megabytes | ["4\n4\n2 5 6 8\n3\n1 1 1\n5\n4 1 7 0 8\n4\n5 9 17 5"] | PASSED | t=int(input())
for _ in range(t):
n=int(input())
lst=list(map(int,input().split()))
tempmax=max(lst)
temparr = lst.copy()
dct={}
for i in range(n):
if(temparr[i] not in dct):
dct[temparr[i]]=1
else:
dct[temparr[i]]+=1
if(n==1):
pri... | 1648132500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["-1\n0\n2\n2"] | 71ee54d8881f20ae4b1d8bb9783948c0 | null | You are given two strings $$$s$$$ and $$$t$$$ of equal length $$$n$$$. In one move, you can swap any two adjacent characters of the string $$$s$$$.You need to find the minimal number of operations you need to make string $$$s$$$ lexicographically smaller than string $$$t$$$.A string $$$a$$$ is lexicographically smaller... | For each test case, print in a separate line the minimal number of operations you need to make string $$$s$$$ lexicographically smaller than string $$$t$$$, or $$$-1$$$, if it's impossible. | The first line of input contains one integer $$$q$$$ ($$$1 \le q \le 10\,000$$$): the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains the string $$$s$$$ consisting of $$$n$$$ lowercase English letters. The thir... | standard output | standard input | PyPy 3-64 | Python | 2,200 | train_101.jsonl | 35c7f1c9d14502bce20fd854cbae6159 | 256 megabytes | ["4\n1\na\na\n3\nrll\nrrr\n3\ncaa\naca\n5\nababa\naabba"] | PASSED | import os,sys
from random import randint
import random
from io import BytesIO, IOBase
from collections import defaultdict,deque,Counter
from bisect import bisect_left,bisect_right
from heapq import heappush,heappop
from functools import lru_cache
from itertools import accumulate
import math
# Fast IO Regi... | 1640792100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1 4", "-1", "4 3", "1 2 3 6"] | 3afa68fbe090683ffe16c3141aafe76e | NoteIn the first example, one of the possible divisions into two performances is as follows: in the first performance artists $$$1$$$ and $$$4$$$ should take part. Then the number of artists in the first performance who can perform as clowns is equal to $$$1$$$. And the number of artists in the second performance who c... | Polycarp is a head of a circus troupe. There are $$$n$$$ — an even number — artists in the troupe. It is known whether the $$$i$$$-th artist can perform as a clown (if yes, then $$$c_i = 1$$$, otherwise $$$c_i = 0$$$), and whether they can perform as an acrobat (if yes, then $$$a_i = 1$$$, otherwise $$$a_i = 0$$$).Spli... | Print $$$\frac{n}{2}$$$ distinct integers — the indices of the artists that should play in the first performance. If there are multiple answers, print any. If there is no solution, print a single integer $$$-1$$$. | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 5\,000$$$, $$$n$$$ is even) — the number of artists in the troupe. The second line contains $$$n$$$ digits $$$c_1 c_2 \ldots c_n$$$, the $$$i$$$-th of which is equal to $$$1$$$ if the $$$i$$$-th artist can perform as a clown, and $$$0$$$ otherwise. The th... | standard output | standard input | PyPy 2 | Python | 1,800 | train_006.jsonl | 7b94f1abdd8ec6d193ce9ccc608808d6 | 256 megabytes | ["4\n0011\n0101", "6\n000000\n111111", "4\n0011\n1100", "8\n00100101\n01111100"] | PASSED | #!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>
"""
from __future__ import division, print_function
import itertools
import os
import sys
from atexit import register
from io import BytesIO
class dict(dict):
"""dict() ... | 1552035900 | [
"math",
"strings"
] | [
0,
0,
0,
1,
0,
0,
1,
0
] | |
3 seconds | ["1", "1 1 2", "0 1 1 1 2 2 2"] | 079382c58c726aaab21ca209ca3f4d2f | NoteIn the first test we can change $$$1$$$ to $$$2$$$, so the answer is $$$1$$$.In the second test: $$$[1]$$$ can be changed into $$$[2]$$$, $$$[1, 4]$$$ can be changed into $$$[3, 4]$$$, $$$[1, 4, 2]$$$ can be changed into $$$[2, 3, 2]$$$. | New Year is just around the corner, which means that in School 179, preparations for the concert are in full swing.There are $$$n$$$ classes in the school, numbered from $$$1$$$ to $$$n$$$, the $$$i$$$-th class has prepared a scene of length $$$a_i$$$ minutes.As the main one responsible for holding the concert, Idnar k... | Print a sequence of $$$n$$$ integers in a single line — $$$f(a_1)$$$, $$$f(a_1$$$,$$$a_2)$$$, $$$\ldots$$$, $$$f(a_1$$$,$$$a_2$$$,$$$\ldots$$$,$$$a_n)$$$. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of classes in the school. The second line contains $$$n$$$ positive integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the lengths of the class scenes. | standard output | standard input | PyPy 3-64 | Python | 2,000 | train_084.jsonl | f874b2c6f3ff65deaf6afb1b56072c85 | 256 megabytes | ["1\n1", "3\n1 4 2", "7\n2 12 4 8 18 3 6"] | PASSED | from math import gcd
import sys
class segmenttree:
def __init__(self, n, default=0, func=lambda a, b: a + b):
self.tree, self.n, self.func, self.default = [0] * (2 * n), n, func, default
def fill(self, arr):
self.tree[self.n:] = arr
for i in range(self.n - 1, 0, -1):
... | 1643553300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["1", "-1"] | 886029b385c099b3050b7bc6978e433b | NoteIn the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. | Ivan is collecting coins. There are only $$$N$$$ different collectible coins, Ivan has $$$K$$$ of them. He will be celebrating his birthday soon, so all his $$$M$$$ freinds decided to gift him coins. They all agreed to three terms: Everyone must gift as many coins as others. All coins given to Ivan must be different. ... | Print one number — minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes). | The only line of input contains 4 integers $$$N$$$, $$$M$$$, $$$K$$$, $$$L$$$ ($$$1 \le K \le N \le 10^{18}$$$; $$$1 \le M, \,\, L \le 10^{18}$$$) — quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection. | standard output | standard input | Python 3 | Python | 1,400 | train_001.jsonl | a6b477e341f3884a5de6da10a6c550fe | 256 megabytes | ["20 15 2 3", "10 11 2 4"] | PASSED | import sys
n,m,k,l= map(int, sys.stdin.readline().split(' '))
ans=(l+k)//m
if(ans*m<(l+k)):
ans+=1
if(ans*m<=n):
print(ans)
else:
print(-1) | 1540398900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1 5 9 21", "1 10 28 64 136"] | 2ae1a4d4f2e58b359c898d1ff38edb9e | NoteIn the first sample, we've already shown that picking $$$k = 4$$$ yields fun value $$$9$$$, as does $$$k = 2$$$. Picking $$$k = 6$$$ results in fun value of $$$1$$$. For $$$k = 3$$$ we get fun value $$$5$$$ and with $$$k = 1$$$ or $$$k = 5$$$ we get $$$21$$$. In the second sample, the values $$$1$$$, $$$10$$$, $$... | There are $$$n$$$ people sitting in a circle, numbered from $$$1$$$ to $$$n$$$ in the order in which they are seated. That is, for all $$$i$$$ from $$$1$$$ to $$$n-1$$$, the people with id $$$i$$$ and $$$i+1$$$ are adjacent. People with id $$$n$$$ and $$$1$$$ are adjacent as well.The person with id $$$1$$$ initially ha... | Suppose the set of all fun values is $$$f_1, f_2, \dots, f_m$$$. Output a single line containing $$$m$$$ space separated integers $$$f_1$$$ through $$$f_m$$$ in increasing order. | The only line consists of a single integer $$$n$$$ ($$$2 \leq n \leq 10^9$$$) — the number of people playing with the ball. | standard output | standard input | Python 3 | Python | 1,400 | train_019.jsonl | 9a73c26bf4c0b35b7a3db74305c97404 | 256 megabytes | ["6", "16"] | PASSED | from collections import Counter,defaultdict,deque
#alph = 'abcdefghijklmnopqrstuvwxyz'
#from math import factorial as fact
#import math
#tt = 1#int(input())
#total=0
#n = int(input())
#n,m,k = [int(x) for x in input().split()]
#n = int(input())
#n,m = [int(x) for x in input().split()]
def divisors(n):
i = 1
divs... | 1546180500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["1\n2\n3\n3"] | 6280a3373ab8fc34bb41fd98648019a6 | NoteSample explanation:In the first test case, the graph constructed from the bracket sequence (), is just a graph containing nodes $$$1$$$ and $$$2$$$ connected by a single edge. In the second test case, the graph constructed from the bracket sequence ()(()) would be the following (containing two connected components)... | Last summer, Feluda gifted Lalmohan-Babu a balanced bracket sequence $$$s$$$ of length $$$2 n$$$.Topshe was bored during his summer vacations, and hence he decided to draw an undirected graph of $$$2 n$$$ vertices using the balanced bracket sequence $$$s$$$. For any two distinct vertices $$$i$$$ and $$$j$$$ ($$$1 \le i... | For each test case, output a single integer — the number of connected components in Topshe's graph. | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of opening brackets in string $$$s... | standard output | standard input | Python 3 | Python | 1,300 | train_106.jsonl | cff1ed2636535a3247b2b608a1bf5168 | 256 megabytes | ["4\n\n1\n\n()\n\n3\n\n()(())\n\n3\n\n((()))\n\n4\n\n(())(())"] | PASSED |
n = int(input())
for i in range(n):
trash = int(input())
miew = input()
balance = 0
groups = 0
recently_closed = False
for j in range(len(miew)):
char = miew[j]
if char == '(':
balance += 1
recently_closed = False
else:
... | 1662474900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["2"] | 5db2ae5b2c91b29e4fe4a45ab864e3f1 | NoteThe subsegment $$$[3, 4]$$$ is the longest among all subsegments with maximum arithmetic mean. | You are given array $$$a_1, a_2, \dots, a_n$$$. Find the subsegment $$$a_l, a_{l+1}, \dots, a_r$$$ ($$$1 \le l \le r \le n$$$) with maximum arithmetic mean $$$\frac{1}{r - l + 1}\sum\limits_{i=l}^{r}{a_i}$$$ (in floating-point numbers, i.e. without any rounding).If there are many such subsegments find the longest one. | Print the single integer — the length of the longest subsegment with maximum possible arithmetic mean. | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — length of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the array $$$a$$$. | standard output | standard input | Python 3 | Python | 1,100 | train_013.jsonl | 99eb0d33ab3caad5421514caf206c448 | 256 megabytes | ["5\n6 1 6 6 0"] | PASSED | from sys import stdin
n=int(stdin.readline())
arr=list(map(int,stdin.readline().split()))
a=max(arr)
ans=[]
count=0
for i in range(n):
if arr[i]==a:
count+=1
else:
count=0
ans.append(count)
print(max(ans))
| 1550504400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2 4 1 3\n1 2 3"] | 0d5f4320fc2c7662d21e09a51baf21db | NoteIn the first test case the minimum absolute difference of consecutive elements equals $$$\min \{\lvert 4 - 2 \rvert, \lvert 1 - 4 \rvert, \lvert 3 - 1 \rvert \} = \min \{2, 3, 2\} = 2$$$. It's easy to prove that this answer is optimal.In the second test case each permutation of numbers $$$1, 2, 3$$$ is an optimal a... | For his birthday, Kevin received the set of pairwise distinct numbers $$$1, 2, 3, \ldots, n$$$ as a gift.He is going to arrange these numbers in a way such that the minimum absolute difference between two consecutive numbers be maximum possible. More formally, if he arranges numbers in order $$$p_1, p_2, \ldots, p_n$$$... | For each test case print a single line containing $$$n$$$ distinct integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \le p_i \le n$$$) describing the arrangement that maximizes the minimum absolute difference of consecutive elements. Formally, you have to print a permutation $$$p$$$ which maximizes the value $$$\min \limits_... | Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The only line of each test case contains an integer $$$n$$$ ($$$2 \le n \leq 1\,000$$$) — the size of the set. | standard output | standard input | Python 3 | Python | 800 | train_104.jsonl | 8d3b27312c36ca031f54acc6c8291afc | 256 megabytes | ["2\n\n4\n\n3"] | PASSED |
def sol(n1):
dt = [0] * n1
dt3 = [0] * n1
c = 0
i, cnt = 0, 0
h = (n1 // 2) +1
for i in range(0, n1//2):
dt[i * 2] = i + 1
# if ( i * 2 + 1 < n1 ):
if ( h + dt[i * 2] <= n1):
dt[i * 2 + 1] = h + dt[i * 2]
if n1+1 %2:
# dt[n1-1] =... | 1666511400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\na d\nb a", "7\nl e\ne d\nd c\nc p\np o\no r\nr a"] | f82f38972afa33e779c8fb7d34849db7 | NoteIn first example it's enough to buy two spells: ('a','d') and ('b','a'). Then first letters will coincide when we will replace letter 'a' with 'd'. Second letters will coincide when we will replace 'b' with 'a'. Third letters will coincide when we will at first replace 'b' with 'a' and then 'a' with 'd'. | Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her boyfriend because he came to her in t-shirt with lettering that differs from lettering on her pullover. Now she doesn't want to see him and Tolya is seating at his room and crying at her photos all day long.This story cou... | In the first line output a single integer — the minimum amount of mana t required for rescuing love of Valya and Tolya. In the next t lines output pairs of space-separated lowercase English letters — spells that Tolya's grandmother should buy. Spells and letters in spells can be printed in any order. If there are many ... | The first line contains a single integer n (1 ≤ n ≤ 105) — the length of the letterings. The second line contains a string with length n, consisting of lowercase English letters — the lettering on Valya's pullover. The third line contains the lettering on Tolya's t-shirt in the same format. | standard output | standard input | Python 3 | Python | 1,600 | train_032.jsonl | 32ab1d2a62af2a2e4e0e2a96b9799134 | 256 megabytes | ["3\nabb\ndad", "8\ndrpepper\ncocacola"] | PASSED | n = int(input())
t = input()
v = input()
s = list(set(list(t)).union(set(list(v))))
uf = [i for i in range(len(s))]
def find(uf,i):
p = uf[i]
return p if i==p else find(uf,p)
def union(uf,i,j):
uf[find(uf,i)] = find(uf,j)
res = []
for i in range(n):
ti = s.index(t[i])
vi = s.index(v[i])
... | 1518861900 | [
"strings",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
1,
0
] | |
2 seconds | ["3\n2\n4", "13\n3\n8\n9"] | 756866daf45951854d5400b209af3bb0 | NoteThe first example is shown in the picture.In the second example the final array is [1, 12, 2, 8, 3, 11, 4, 9, 5, 13, 6, 10, 7]. | Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he has come up with the following extravagant algorithm.Let's consider that ini... | For each of q queries output one integer number, the value that will appear in the corresponding array cell after Dima's algorithm finishes. | The first line contains two integers n and q (1 ≤ n ≤ 1018, 1 ≤ q ≤ 200 000), the number of elements in the array and the number of queries for which it is needed to find the answer. Next q lines contain integers xi (1 ≤ xi ≤ n), the indices of cells for which it is necessary to output their content after Dima's algori... | standard output | standard input | Python 3 | Python | 1,700 | train_058.jsonl | 87a75c29fa227028f017195276182e90 | 512 megabytes | ["4 3\n2\n3\n4", "13 4\n10\n5\n4\n8"] | PASSED | import math
from decimal import Decimal
def na():
n = int(input())
b = [int(x) for x in input().split()]
return n,b
def nab():
n = int(input())
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
return n,b,c
def dv():
n, m = map(int, input().split())
return n,m
def dva():
... | 1520583000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["+++-", "++-"] | 30f64b963310911196ebf5d624c01cc3 | null | Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai ≤ ai + 1 ≤ 2·ai for any positive integer i (i < n).Vasya wants to add either a "+" or a "-" before each number of array. Thus, Vasya will g... | In a single line print the sequence of n characters "+" and "-", where the i-th character is the sign that is placed in front of number ai. The value of the resulting expression s must fit into the limits 0 ≤ s ≤ a1. If there are multiple solutions, you are allowed to print any of them. | The first line contains integer n (1 ≤ n ≤ 105) — the size of the array. The second line contains space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the original array. It is guaranteed that the condition ai ≤ ai + 1 ≤ 2·ai fulfills for any positive integer i (i < n). | standard output | standard input | Python 3 | Python | 1,900 | train_003.jsonl | e0d6a42581e28d990fa0f1c946bb8979 | 256 megabytes | ["4\n1 2 3 5", "3\n3 3 5"] | PASSED | n = int(input())
arr = list(map(int, input().split()))
if n == 1:
print('+')
elif n == 2:
print('-+')
else:
ans = ['+']
cur = arr[-1]
for i in range(n - 2, -1, -1):
if cur > 0:
cur -= arr[i]
ans.append('-')
else:
cur += arr[i]
ans.appen... | 1357659000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["7", "76", "129"] | ef0ad7b228351a268c3f6bfac68b1002 | NoteIn the first sample there are three pairs of cells of same color: in cells $$$(1, 1)$$$ and $$$(2, 3)$$$, in cells $$$(1, 2)$$$ and $$$(2, 2)$$$, in cells $$$(1, 3)$$$ and $$$(2, 1)$$$. The manhattan distances between them are $$$3$$$, $$$1$$$ and $$$3$$$, the sum is $$$7$$$. | Egor has a table of size $$$n \times m$$$, with lines numbered from $$$1$$$ to $$$n$$$ and columns numbered from $$$1$$$ to $$$m$$$. Each cell has a color that can be presented as an integer from $$$1$$$ to $$$10^5$$$.Let us denote the cell that lies in the intersection of the $$$r$$$-th row and the $$$c$$$-th column a... | Print one integer — the the sum of manhattan distances between each pair of cells of the same color. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \le m$$$, $$$n \cdot m \leq 100\,000$$$) — number of rows and columns in the table. Each of next $$$n$$$ lines describes a row of the table. The $$$i$$$-th line contains $$$m$$$ integers $$$c_{i1}, c_{i2}, \ldots, c_{im}$$$ ($$$1 \le c_{ij} \le 100\,... | standard output | standard input | PyPy 3-64 | Python | 1,400 | train_091.jsonl | 16c7f3582cfab9ccb46038e0fbb1af7f | 256 megabytes | ["2 3\n1 2 3\n3 2 1", "3 4\n1 1 2 2\n2 1 1 2\n2 2 1 1", "4 4\n1 1 2 3\n2 1 1 2\n3 1 2 1\n1 1 2 1"] | PASSED | tiles = input()
tiles = tiles.split(" ")
n = int(tiles[0])
m = int(tiles[1])
def arr_man(arr):
arr = sorted(arr)
res = 0
sum = 0
for i, e in enumerate(arr):
res += (e * i - sum)
sum += e
return res
coords = {}
final_sum = 0
for i in range(n):
row = inpu... | 1646560500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["5", "3", "2"] | fead36831dbcb1c0bdf6b6965b751ad8 | NoteIn the first example the resulting string s is "winlosewinwinlwinwin"In the second example the resulting string s is "glorytoreorand". The last letter of the string can be arbitrary.In the third example occurrences of string t are overlapping. String s with maximal number of occurrences of t is "abcabcab". | Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible.He ha... | Output the maximum number of occurrences of string t you can achieve by replacing all the question marks in string s with small Latin letters. | The first line contains string of small Latin letters and question marks s (1 ≤ |s| ≤ 105). The second line contains string of small Latin letters t (1 ≤ |t| ≤ 105). Product of lengths of strings |s|·|t| won't exceed 107. | standard output | standard input | PyPy 3 | Python | 2,300 | train_080.jsonl | f6a5f910765c65c33514431661ca02e4 | 256 megabytes | ["winlose???winl???w??\nwin", "glo?yto?e??an?\nor", "??c?????\nabcab"] | PASSED | def prefix(st):
t = 0
p = [0] * (len(st) + 1)
o = [0] * (len(st) + 1)
for i in range(2, len(st)):
while t > 0 and st[i] != st[t + 1]:
t = p[t]
if st[i] == st[t + 1]:
t += 1
p[i] = t
while t > 0:
o[t] = 1
t = p[t]
return o
s = ' ' ... | 1494860700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["YES\n10100"] | 981e9991fb5dbd085db8a408c29564d4 | NoteThe picture corresponding to the first example: And one of possible answers: | You are given a connected undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. There are no self-loops or multiple edges in the given graph.You have to direct its edges in such a way that the obtained directed graph does not contain any paths of length two or greater (where the length of path is denoted a... | If it is impossible to direct edges of the given graph in such a way that the obtained directed graph does not contain paths of length at least two, print "NO" in the first line. Otherwise print "YES" in the first line, and then print any suitable orientation of edges: a binary string (the string consisting only of '0'... | The first line contains two integer numbers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$n - 1 \le m \le 2 \cdot 10^5$$$) — the number of vertices and edges, respectively. The following $$$m$$$ lines contain edges: edge $$$i$$$ is given as a pair of vertices $$$u_i$$$, $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$, ... | standard output | standard input | Python 3 | Python | 1,700 | train_000.jsonl | eec5ba0c7e518e8a79ad11d803d8c20b | 256 megabytes | ["6 5\n1 5\n2 1\n1 4\n3 1\n6 1"] | PASSED | import sys
sys.setrecursionlimit(10000000)
a, b = tuple([int(i) for i in input().split()])
save = {}
printl = ['']*(b)
data = ['']
for i in range(a):
data.append(set())
for i in range(b):
a = input().split()
c = int(a[0])
d = int(a[1])
save[(c,d)] = i
data[c].add(d)
data[d].add(c)
done = s... | 1554041100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["2\n1\n12"] | 59ec1518d55bf81ee7cadba3a918c890 | NoteThe greatest common divisor of a set of integers is the largest integer $$$g$$$ such that all elements of the set are divisible by $$$g$$$.In the first sample case vertices of the left half and vertices of the right half are pairwise connected, and $$$f(S)$$$ for any non-empty subset is $$$2$$$, thus the greatest c... | Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting task.You are given a bipartite graph with positive integers in all vertices of the right half. For a subset $$$S$$$ of vertices of the lef... | For each test case print a single integer — the required greatest common divisor. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 500\,000$$$) — the number of test cases in the given test set. Test case descriptions follow. The first line of each case description contains two integers $$$n$$$ and $$$m$$$ ($$$1~\leq~n,~m~\leq~500\,000$$$) — the number of vertices in either half of ... | standard output | standard input | PyPy 2 | Python | 2,300 | train_007.jsonl | 51b12d6f7c60d3623b7463c6d3ff09bd | 512 megabytes | ["3\n2 4\n1 1\n1 1\n1 2\n2 1\n2 2\n\n3 4\n1 1 1\n1 1\n1 2\n2 2\n2 3\n\n4 7\n36 31 96 29\n1 2\n1 3\n1 4\n2 2\n2 4\n3 1\n4 3"] | PASSED | from __future__ import print_function,division
#from sortedcontainers import SortedList
import sys
#sys.__stdout__.flush()
def gc(a,b):
while b:
a,b=b,a%b
return a
le=sys.__stdin__.read().split("\n")
le.pop()
le=le[::-1]
af=[]
for z in range(int(le.pop())):
if z:
le.pop()
n,m=map(int,le.... | 1583573700 | [
"number theory",
"math",
"graphs"
] | [
0,
0,
1,
1,
1,
0,
0,
0
] | |
2 seconds | ["2 2 2 2 2 2", "2 2 2", "1 2 1 2 2 2 1 2"] | 2c279b3065d8da8021051241677d9cf1 | null | Little Petya likes numbers a lot. Recently his mother has presented him a collection of n non-negative integers. There's only one thing Petya likes more than numbers: playing with little Masha. He immediately decided to give a part of his new collection to her. To make the game even more interesting, Petya decided to g... | Print n space-separated integers, the i-th of them should equal either 1, if Petya keeps the number that follows i-th in his collection, or it should equal 2, if Petya gives the corresponding number to Masha. The numbers are indexed in the order in which they are given in the input. | The first line contains integer n (1 ≤ n ≤ 105), showing how many numbers Petya's mother gave him. The second line contains the actual space-separated numbers. They are all integer, non-negative and do not exceed 1018. | standard output | standard input | PyPy 2 | Python | 2,700 | train_031.jsonl | 62b50314fc5253b6f92223e559a2845b | 256 megabytes | ["6\n1 2 3 4 5 6", "3\n1000000000000 1000000000000 1000000000000", "8\n1 1 2 2 3 3 4 4"] | PASSED | import sys
range = xrange
input = raw_input
n = int(input())
A = [int(x) for x in input().split()]
# Reorder the bits
big = 60
mapper = [0]*big
ind = big - 1
xor = 0
for a in A:
xor ^= a
for j in reversed(range(big)):
if xor & (1 << j) == 0:
mapper[j] = ind
ind -= 1
for j in reversed(range... | 1354807800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["6", "7"] | 274ae43b10bb15e270788d36590713c7 | NoteIn the first sample, in the new map all pairs of stations share a direct connection, so the sum of distances is $$$6$$$.In the second sample, the new map has a direct tunnel between all pairs of stations except for the pair $$$(1, 4)$$$. For these two stations the distance is $$$2$$$. | Sergey Semyonovich is a mayor of a county city N and he used to spend his days and nights in thoughts of further improvements of Nkers' lives. Unfortunately for him, anything and everything has been done already, and there are no more possible improvements he can think of during the day (he now prefers to sleep at nigh... | Print one integer that is equal to the sum of distances between all pairs of stations after Sergey Semyonovich draws new tunnels between all pairs of stations that share a common neighbor in the original map. | The first line of the input contains a single integer $$$n$$$ ($$$2 \leq n \leq 200\,000$$$) — the number of subway stations in the imaginary city drawn by mayor's assistants. Each of the following $$$n - 1$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \ne v_i$$$), meaning... | standard output | standard input | Python 2 | Python | 2,000 | train_030.jsonl | 4768a3c7934bfedb57ea18cfa295b226 | 512 megabytes | ["4\n1 2\n1 3\n1 4", "4\n1 2\n2 3\n3 4"] | PASSED | import collections
import sys
Stats = collections.namedtuple(
'Stats', [
'odd_paths_to_root',
'even_paths_to_root',
'result',
'sum_paths_to_root',
'size',
])
def _solve(children_stats):
sum_paths_to_root = 0
odd_paths_to_root = 0
even_paths_to_root = 1
result = 0
size = 1
for s in ... | 1538636700 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["26", "0"] | 9cd17c2617b6cde593ef12b2a0a807fb | NoteIn the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy.Here |x| denotes the length of string x.Please note that it's possible that there is no such string (answer is 0). | Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < ... | In a single line print the answer modulo 1000 000 007. | The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≤ n ≤ 106 and 0 ≤ m ≤ n - |p| + 1). The second line contains string p (1 ≤ |p| ≤ n). The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≤ y1 < y2 < ... <... | standard output | standard input | Python 3 | Python | 1,900 | train_008.jsonl | ad26e658856607edd1d011030c3f6763 | 256 megabytes | ["6 2\nioi\n1 3", "5 2\nioi\n1 2"] | PASSED | # -*- coding: utf-8 -*-
def solve():
n, m = map(int, input().split())
p = input()
if m == 0:
return powmod(n)
delta = len(p) - 1
ys = map(int, input().split())
tail = 0
free_chars = 0
for y in ys:
if y > tail:
free_chars += y - tail - 1
... | 1429029300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["3\n32767\n0\n0"] | 356bd72aa9143681f1efd695969a8c8e | NoteIn the first test case the resulting value of d is hhahahaha. | Polycarp came up with a new programming language. There are only two types of statements in it: "x := s": assign the variable named x the value s (where s is a string). For example, the statement var := hello assigns the variable named var the value hello. Note that s is the value of a string, not the name of a varia... | For each set of input data, output the number of occurrences of the haha substring in the string that was written to the variable in the last statement. | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^3$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of statements in the program. All variable names and strings are guaranteed to consist only of lowercase letters of ... | standard output | standard input | PyPy 3 | Python | 2,100 | train_097.jsonl | 12828bf63b0ff3e74d77f7ea39882a6b | 256 megabytes | ["4\n6\na := h\nb := aha\nc = a + b\nc = c + c\ne = c + c\nd = a + c\n15\nx := haha\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\n1\nhaha := hah\n5\nhaahh := aaaha\nahhhh = haahh + haahh\nhaahh = haahh + haahh\n... | PASSED |
def naiveSolve():
return
def countHaha(s):
n=len(s)
cnt=0
for i in range(n):
if s[i:i+4]=='haha':
cnt+=1
return cnt
def main():
t=int(input())
allans=[]
for _ in range(t):
n=int(input())
d=dict() # var:[pre,s... | 1623335700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["2", "2"] | 03d6b61be6ca0ac9dd8259458f41da59 | null | Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. Finally, there are k train routes in the country. One ... | Output a single integer representing the maximum number of the train routes which can be closed. | The first line contains three integers n, m, k (2 ≤ n ≤ 105; 1 ≤ m ≤ 3·105; 1 ≤ k ≤ 105). Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ n; ui ≠ vi; 1 ≤ xi ≤ 109). Each of the next k lines contains two integers si and yi (2 ≤ si ≤ n; 1 ≤ yi ≤ 109). It is guaranteed that there is at least one ... | standard output | standard input | PyPy 3 | Python | 2,000 | train_020.jsonl | 52bf62e6730c6c8583a3a54a5108ae71 | 256 megabytes | ["5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5", "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3"] | PASSED | import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
from future_builtins import ascii, filter, hex, map, oct, zip
range = xrange
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.wr... | 1405774800 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["3 4 6 5", "9 8 12 6 8", "3 3"] | 8b727bacddcf1db490982ec388903d29 | NoteConsider the first example:$$$x = [1, 2, 3, 4]$$$, so for the permutation $$$p_1(4) = [1, 2, 3, 4]$$$ the answer is $$$|1 - 2| + |2 - 3| + |3 - 4| = 3$$$; for the permutation $$$p_2(4) = [2, 1, 3, 4]$$$ the answer is $$$|2 - 1| + |1 - 3| + |3 - 4| = 4$$$; for the permutation $$$p_3(4) = [3, 1, 2, 4]$$$ the answe... | Let's define $$$p_i(n)$$$ as the following permutation: $$$[i, 1, 2, \dots, i - 1, i + 1, \dots, n]$$$. This means that the $$$i$$$-th permutation is almost identity (i.e. which maps every element to itself) permutation but the element $$$i$$$ is on the first position. Examples: $$$p_1(4) = [1, 2, 3, 4]$$$; $$$p_2(4)... | Print $$$n$$$ integers: $$$f(p_1(n)), f(p_2(n)), \dots, f(p_n(n))$$$. | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 2 \cdot 10^5$$$) — the number of elements in each permutation and the number of elements in $$$x$$$. The second line of the input contains $$$m$$$ integers ($$$m$$$, not $$$n$$$) $$$x_1, x_2, \dots, x_m$$$ ($$$1 \le x_i \le n$$$), ... | standard output | standard input | Python 3 | Python | 2,000 | train_005.jsonl | 24a26c27577bd071791f6d29a231e98a | 256 megabytes | ["4 4\n1 2 3 4", "5 5\n2 1 5 3 5", "2 10\n1 2 1 1 2 2 2 2 2 2"] | PASSED | import sys
n,m = [int(x) for x in input().split()]
X = [int(x) - 1 for x in input().split()]
s = 0
right = [[] for _ in range(n)]
left = [[] for _ in range(n)]
for j in range(m - 1):
a,b = X[j], X[j + 1]
if a == b:
continue
if a > b:
a,b = b,a
right[a].append(b)
left[b].append(a)... | 1569940500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n2 7 9 28"] | b0b4cadc46f9fd056bf7dc36d1cf51f2 | null | You are given an array of n elements, you must make it a co-prime array in as few moves as possible.In each move you can insert any positive integral number you want not greater than 109 in any place in the array.An array is co-prime if any two adjacent numbers of it are co-prime.In the number theory, two integers a an... | Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime. The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a. | standard output | standard input | PyPy 2 | Python | 1,200 | train_008.jsonl | d2e6e06be671ccf9377e1eb641e09220 | 256 megabytes | ["3\n2 7 28"] | PASSED | def gcd(a,b):
if b==0:return a
return gcd(b,a%b)
n=int(raw_input())
a=map(int,raw_input().split())
ind=0
co=0
while ind<len(a)-1:
if gcd(a[ind],a[ind+1])!=1:
u=gcd(a[ind],a[ind+1])
a.insert(ind+1,1)
ind+=2
co+=1
else:ind+=1
print co
print ' '.join(map(str,a))
| 1460127600 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000"] | 20f69ee5f04c8cbb769be3ab646031ab | null | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | The first line contains a single integer n — the number of records to restore (1 ≤ n ≤ 100). Each of the following n lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:". It is guaranteed that each short address is obtained by the way that is described i... | standard output | standard input | Python 2 | Python | 1,500 | train_036.jsonl | 0a6c3acf612476ba9543ee5703a916fc | 256 megabytes | ["6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0"] | PASSED | def do(t):
ret = ""
for item in t:
ret += "0"*(4-len(item)) + item + ":"
return ret
n = int(raw_input())
for i in range(n):
ip6 = str(raw_input()).split("::")
if len(ip6) == 2:
prefix,postfix = ip6[0].split(":"),ip6[1].split(":")
res = do(prefix) +"0000:"*(8-len(prefix) ... | 1353938400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["2\n3\n6"] | d70ce3b16614129c5d697a9597bcd2e3 | NoteIn the first example it is possible to construct these graphs: 1 - 2, 1 - 3; 1 - 2, 1 - 3, 2 - 4; 1 - 2, 1 - 3, 2 - 3, 1 - 4, 2 - 5, 3 - 6. | Ivan is developing his own computer game. Now he tries to create some levels for his game. But firstly for each level he needs to draw a graph representing the structure of the level.Ivan decided that there should be exactly ni vertices in the graph representing level i, and the edges have to be bidirectional. When con... | Output q numbers, i-th of them must be equal to the maximum number of edges in i-th graph. | The first line of input file contains a positive integer q (1 ≤ q ≤ 100 000) — the number of graphs Ivan needs to construct. Then q lines follow, i-th line contains one positive integer ni (1 ≤ ni ≤ 2·109) — the number of vertices in i-th graph. Note that in hacks you have to use q = 1. | standard output | standard input | Python 3 | Python | 2,100 | train_018.jsonl | d84386d74e18609a864cb73abe208a05 | 256 megabytes | ["3\n3\n4\n6"] | PASSED | #! /usr/bin/env python
# http://codeforces.com/problemset/problem/818/F
# Problem name ::: F. Level Generation
# submission number
#212055293
#508427854
def newest_approach(n):
from math import floor, ceil, sqrt
quad_solv = sqrt(2*n+1/4)-1/2
x = floor(quad_solv)
y = ceil(quad_solv)
xed = int(x... | 1498748700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3 1 2 3\n2 4 5\n3 4 5 2\n2 1 3\n\n2 6 2\n3 3 5 1\n3 4 7 8\n\n2 2 1\n2 2 1\n2 2 1"] | 7cc46ebe80756a5827f3b8ce06bc7974 | null | The Hat is a game of speedy explanation/guessing words (similar to Alias). It's fun. Try it! In this problem, we are talking about a variant of the game when the players are sitting at the table and everyone plays individually (i.e. not teams, but individual gamers play).$$$n$$$ people gathered in a room with $$$m$$$ t... | For each test case print a required schedule — a sequence of $$$k$$$ blocks of $$$m$$$ lines. Each block corresponds to one game, a line in a block corresponds to one table. In each line print the number of players at the table and the indices of the players (numbers from $$$1$$$ to $$$n$$$) who should play at this ta... | The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. Each test case consists of one line that contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \le n \le 2\cdot10^5$$$, $$$1 \le m \le \lfloor\frac{n}{2}\rfloor$$$, $$$1 \le k \le 10^5$$$) — the... | standard output | standard input | PyPy 3-64 | Python | 2,000 | train_093.jsonl | f14abe739c2c7bfc6183f00ef5a96907 | 256 megabytes | ["3\n5 2 2\n8 3 1\n2 1 3"] | PASSED |
import sys
ip = sys.stdin.readline
for _ in range(int(ip())):
n, m, k = map(int, ip().split())
for r in range(k):
index = 0
l1 = [(j + 1 - (r * (n % m) * (n // m + 1)) + n) % n if (j + 1 - (r * (n % m) * (n // m + 1)) + n) % n !=0 else n for j in range(n)]
for i in range(m):
... | 1640010900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nNO"] | 4c0b0cb8a11cb1fd40fef47616987029 | NoteThe first five test cases contain the strings "YES", "yES", "yes", "Yes", "YeS". All of these are equal to "YES", where each character is either uppercase or lowercase. | There is a string $$$s$$$ of length $$$3$$$, consisting of uppercase and lowercase English letters. Check if it is equal to "YES" (without quotes), where each letter can be in any case. For example, "yES", "Yes", "yes" are all allowable. | For each test case, output "YES" (without quotes) if $$$s$$$ satisfies the condition, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response). | The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of testcases. The description of each test consists of one line containing one string $$$s$$$ consisting of three characters. Each character of $$$s$$$ is either an uppercase or lowercase English letter. | standard output | standard input | Python 3 | Python | 800 | train_086.jsonl | 124e6973cf4a7a3d863a2ca716ff3bbb | 256 megabytes | ["10\n\nYES\n\nyES\n\nyes\n\nYes\n\nYeS\n\nNoo\n\norZ\n\nyEz\n\nYas\n\nXES"] | PASSED | n=int(input())
for i in range(0,n):
first=str(input());
if(first.upper()=="YES"):
print("YES")
else:
print("NO") | 1657636500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1", "3 4"] | c80cdf090685d40fd34c3fd082a81469 | null | While resting on the ship after the "Russian Code Cup" a boy named Misha invented an interesting game. He promised to give his quadrocopter to whoever will be the first one to make a rectangular table of size n × m, consisting of positive integers such that the sum of the squares of numbers for each row and each column... | Print the table that meets the condition: n lines containing m integers, separated by spaces. If there are multiple possible answers, you are allowed to print anyone. It is guaranteed that there exists at least one correct answer. | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the size of the table. | standard output | standard input | Python 2 | Python | 2,400 | train_048.jsonl | 4fd6f3b42ffeec2ce4fae8770f7d49e2 | 256 megabytes | ["1 1", "1 2"] | PASSED | n, m = map(int, raw_input().split())
def f(k):
if k == 1:
return [1]
elif k == 2:
return [3, 4]
elif k % 2:
return [2] + [1] * (k - 2) + [(k + 1) / 2]
else:
return [1] * (k - 1) + [(k - 1)/ 2]
for i in f(n):
for j in f(m):
print i * j,
print
| 1397749200 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3 3 1\n-1\n2 4 6\n69 420 666\n12345678 87654321 100000000"] | 43041076ddd0bbfac62cd4abf4536282 | NoteIn the first test case, $$$a=3$$$, $$$b=3$$$, $$$c=1$$$, so $$$(3 \oplus 3)+(3 \oplus 1) + (3 \oplus 1)=0+2+2=4$$$.In the second test case, there are no solutions.In the third test case, $$$(2 \oplus 4)+(4 \oplus 6) + (2 \oplus 6)=6+2+4=12$$$. | You are given a positive integer $$$n$$$. Your task is to find any three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$0 \le a, b, c \le 10^9$$$) for which $$$(a\oplus b)+(b\oplus c)+(a\oplus c)=n$$$, or determine that there are no such integers.Here $$$a \oplus b$$$ denotes the bitwise XOR of $$$a$$$ and $$$b$$$. For exam... | For each test case, print any three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$0 \le a, b, c \le 10^9$$$) for which $$$(a\oplus b)+(b\oplus c)+(a\oplus c)=n$$$. If no such integers exist, print $$$-1$$$. | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following lines contain the descriptions of the test cases. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^9$$$). | standard output | standard input | PyPy 3-64 | Python | 800 | train_088.jsonl | bd012ea6920bd4a6b0d9d7ed76b888a8 | 256 megabytes | ["5\n\n4\n\n1\n\n12\n\n2046\n\n194723326"] | PASSED | for i in range(int(input())):
a=int(input())
if a%2!=0:
print(-1)
else:
print(0,a//2,a//2)
| 1656945300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES", "YES", "NO"] | 2c58d94f37a9dd5fb09fd69fc7788f0d | NoteIn the first sample the initial array fits well.In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.In the third sample Yarosav can't get the array he needs. | Yaroslav has an array that consists of n integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.Help Yaroslav. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the array elements. | standard output | standard input | Python 3 | Python | 1,100 | train_006.jsonl | bca8c1127737176135c0149a92c5f935 | 256 megabytes | ["1\n1", "3\n1 1 2", "4\n7 7 7 7"] | PASSED | #!/usr/bin/env python
# coding: utf-8
# In[204]:
# # n = int(input())
# # line = list(map(int, input().split()))
# # line = list(str(input()))
# In[1]:
from collections import Counter
# In[ ]:
# 56
# 516 76 516 197 516 427 174 516 706 813 94 37 516 815 516 516 937 483 16 516 842 516 638 691 516 635 516 516 4... | 1365694200 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n2\n10 11", "0\n5\n14 9 28 11 16"] | b5eb2bbdba138a4668eb9736fb5258ac | NoteOperation represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: for all x the following inequality holds l ≤ x ≤ r; 1 ≤ |S| ≤ k; lets denote the i-th element of the set... | Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order. If there are multiple optimal sets, you can print any of them. | The first line contains three space-separated integers l, r, k (1 ≤ l ≤ r ≤ 1012; 1 ≤ k ≤ min(106, r - l + 1)). | standard output | standard input | Python 2 | Python | 2,300 | train_029.jsonl | 8167425a4277409614cdf123d68ac905 | 256 megabytes | ["8 15 3", "8 30 7"] | PASSED |
import sys
def numbers_of_one(n):
res=0
while n:
if n&1:res+=1
n>>=1
return res
def brute_force(l,r,k):
numbers=[i for i in range(l,r+1)]
n=len(numbers)
aux=r<<2
res=[]
# import ipdb;ipdb.set_trace()
for subset in range(1,1<<(r-l+1)):
if numbers_of_one(subset)<=k:
tmp,tmp_l=0,[]
for j i... | 1408548600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"] | 84e79bd83c51a4966b496bb767ec4f0d | NoteArray from sample: $$$[1, 2, 0, 3]$$$. | This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. ... | null | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that ... | standard output | standard input | PyPy 3-64 | Python | 2,000 | train_108.jsonl | 800f9dc80ec285a65de19b14bcb9801e | 256 megabytes | ["1\n\n4\n\n2\n\n3\n\n3\n\n2"] | PASSED | from sys import stdin, stdout, exit
input = stdin.readline
def f(i, j, k):
aaa = [i, j, k]
aaa.sort()
i, j, k = aaa[0], aaa[1], aaa[2]
if (i, j, k) in d.keys():
return d[(i, j, k)]
print('?', i, j, k)
stdout.flush()
a = int(input())
d[(i, j, k)] = a
... | 1644158100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1", "2"] | cf7520d88e10ba171de443f36fdd2b73 | NoteIn the first example only component $$$[3, 4, 5]$$$ is also a cycle.The illustration above corresponds to the second example. | You are given an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. Your task is to find the number of connected components which are cycles.Here are some definitions of graph theory.An undirected graph consists of two sets: set of nodes (called vertices) and set of edges. Each edge connects a pair of v... | Print one integer — the number of connected components which are also cycles. | The first line contains two integer numbers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) — number of vertices and edges. The following $$$m$$$ lines contains edges: edge $$$i$$$ is given as a pair of vertices $$$v_i$$$, $$$u_i$$$ ($$$1 \le v_i, u_i \le n$$$, $$$u_i \ne v_i$$$). T... | standard output | standard input | PyPy 3 | Python | 1,500 | train_003.jsonl | deaf6c00ab8765d764d4c1168f86e444 | 256 megabytes | ["5 4\n1 2\n3 4\n5 4\n3 5", "17 15\n1 8\n1 12\n5 11\n11 9\n9 15\n15 5\n4 13\n3 13\n4 3\n10 16\n7 10\n16 7\n14 3\n14 4\n17 6"] | PASSED | from sys import stdin
def main():
n, m = map(int, stdin.readline().split())
adj = [[] for _ in range(n)]
for _ in range(m):
v, u = map(int, stdin.readline().split())
adj[v - 1].append(u - 1)
adj[u - 1].append(v - 1)
check = [False] * n
stack = []
count = 0
for i in ... | 1525615500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1\n2 \n2\n1 3", "-1"] | 810f267655da0ad14538c275fd13821d | NoteIn the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).In the second sample, there is no way to satisfy both Pari and Arya. | Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.Suppose the graph G is given. Subset A of its vertices is called a vertex cover of this graph, if for each edge uv there is at least one endpoint of it in this set, i.e. or (or both).Pari ... | If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes). If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer k denoting the number of ... | The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — the number of vertices and the number of edges in the prize graph, respectively. Each of the next m lines contains a pair of integers ui and vi (1 ≤ ui, vi ≤ n), denoting an undirected edge between ui and vi. It's guaran... | standard output | standard input | Python 3 | Python | 1,500 | train_021.jsonl | 223444aaeb7e32c4d17c4332dc3b6329 | 256 megabytes | ["4 2\n1 2\n2 3", "3 3\n1 2\n2 3\n1 3"] | PASSED | n,m=map(int,input().split())
flag=False
f=[0]*100001
E=[[] for i in range(n+1)]
e=[tuple(map(int,input().split())) for _ in range(m)]
for u,v in sorted(e): E[u]+=[v]; E[v]+=[u]
def bfs(nom,col):
ch=[(nom,col)]
while ch:
v,c=ch.pop()
if f[v]==0:
f[v]=c
for u in E[v]:
if f[... | 1467219900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["3\n1 3\n3 2\n3 1", "0"] | e4dc319588cc8eca6a5c3d824e504c22 | NoteLet coin $$$i$$$ facing upwards be denoted as $$$i$$$ and coin $$$i$$$ facing downwards be denoted as $$$-i$$$.The series of moves performed in the first sample changes the coins as such: $$$[~~~2,~~~1,~~~3]$$$ $$$[-3,~~~1,-2]$$$ $$$[-3,~~~2,-1]$$$ $$$[~~~1,~~~2,~~~3]$$$ In the second sample, the coins are alre... | There are $$$n$$$ coins labeled from $$$1$$$ to $$$n$$$. Initially, coin $$$c_i$$$ is on position $$$i$$$ and is facing upwards (($$$c_1, c_2, \dots, c_n)$$$ is a permutation of numbers from $$$1$$$ to $$$n$$$). You can do some operations on these coins. In one operation, you can do the following:Choose $$$2$$$ distinc... | In the first line, output an integer $$$q$$$ $$$(0 \leq q \leq n+1)$$$ — the number of operations you used. In the following $$$q$$$ lines, output two integers $$$i$$$ and $$$j$$$ $$$(1 \leq i, j \leq n, i \ne j)$$$ — the positions you chose for the current operation. | The first line contains an integer $$$n$$$ ($$$3 \leq n \leq 2 \cdot 10^5$$$) — the number of coins. The second line contains $$$n$$$ integers $$$c_1,c_2,\dots,c_n$$$ ($$$1 \le c_i \le n$$$, $$$c_i \neq c_j$$$ for $$$i\neq j$$$). | standard output | standard input | PyPy 3 | Python | 2,800 | train_095.jsonl | 0bc3f723083d60933a9affb01c4deb52 | 256 megabytes | ["3\n2 1 3", "5\n1 2 3 4 5"] | PASSED | def swap(i, j):
graph[i], graph[j] = -graph[j], -graph[i]
ans.append((i, j))
def solve_pair(x, y):
swap(x, y)
i = x
while (graph[-graph[i]] > 0):
swap(i, -graph[i])
i = -graph[i]
while (graph[-graph[i]] > 0):
swap(i, -graph[i])
swap(i, -graph[i])
n = int(i... | 1614519300 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
2 seconds | ["24", "1574", "0", "667387032"] | 51406f6578e8de38100c6af082bfb05e | NoteIn the first example there are: $$$6$$$ pairs of substrings "a" and "b", each with valid merging sequences "01" and "10"; $$$3$$$ pairs of substrings "a" and "bb", each with a valid merging sequence "101"; $$$4$$$ pairs of substrings "aa" and "b", each with a valid merging sequence "010"; $$$2$$$ pairs of subs... | You are given two strings $$$x$$$ and $$$y$$$, both consist only of lowercase Latin letters. Let $$$|s|$$$ be the length of string $$$s$$$.Let's call a sequence $$$a$$$ a merging sequence if it consists of exactly $$$|x|$$$ zeros and exactly $$$|y|$$$ ones in some order.A merge $$$z$$$ is produced from a sequence $$$a$... | Print a single integer — the sum of $$$f(l_1, r_1, l_2, r_2)$$$ over $$$1 \le l_1 \le r_1 \le |x|$$$ and $$$1 \le l_2 \le r_2 \le |y|$$$ modulo $$$998\,244\,353$$$. | The first line contains a string $$$x$$$ ($$$1 \le |x| \le 1000$$$). The second line contains a string $$$y$$$ ($$$1 \le |y| \le 1000$$$). Both strings consist only of lowercase Latin letters. | standard output | standard input | PyPy 3-64 | Python | 2,400 | train_104.jsonl | ae7e9bae89e36a685ae40ec87ba72964 | 256 megabytes | ["aaa\nbb", "code\nforces", "aaaaa\naaa", "justamassivetesttocheck\nhowwellyouhandlemodulooperations"] | PASSED |
s=[0]+list(input())
t=[0]+list(input())
n=len(s)-1
m=len(t)-1
mod=998244353
for i in range(1,n+1):
s[i]=ord(s[i])-96
for i in range(1,m+1):
t[i]=ord(t[i])-96
def _(i,j,fs,ft,al):
if min(i,j)<0:return -1
return (((i*(m+1)+j)*2+fs)*2+ft)*2+al
dp=[0]*(n+3)*(m+3)*2*2*2
for i in range(n+1):
for j in r... | 1616079000 | [
"math",
"strings"
] | [
0,
0,
0,
1,
0,
0,
1,
0
] | |
1 second | ["YES\nNO", "YES\nNO"] | 5c1707b614dc3326a9bb092e6ca24280 | NoteIn the first set of the input of the first sample Philip must first go forward and go down to the third row of the field, then go only forward, then go forward and climb to the second row, go forward again and go up to the first row. After that way no train blocks Philip's path, so he can go straight to the end of ... | The mobile application store has a new game called "Subway Roller".The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and n columns. At the beginning of the game the hero is in some cell of the leftmost... | For each set of the input data print on a single line word YES, if it is possible to win the game and word NO otherwise. | Each test contains from one to ten sets of the input data. The first line of the test contains a single integer t (1 ≤ t ≤ 10 for pretests and tests or t = 1 for hacks; see the Notes section for details) — the number of sets. Then follows the description of t sets of the input data. The first line of the description o... | standard output | standard input | Python 3 | Python | 1,700 | train_011.jsonl | a43d3e942c8ca54d6c87d3423ee4b4a4 | 256 megabytes | ["2\n16 4\n...AAAAA........\ns.BBB......CCCCC\n........DDDDD...\n16 4\n...AAAAA........\ns.BBB....CCCCC..\n.......DDDDD....", "2\n10 4\ns.ZZ......\n.....AAABB\n.YYYYYY...\n10 4\ns.ZZ......\n....AAAABB\n.YYYYYY..."] | PASSED | T = int(input())
for t in range(T):
n, k = map(int, input().split(' ')[:2])
s = ["","",""]
for i in range(3):
s[i] = input()
s[0] += '.' * (n*3)
s[1] += '.' * (n*3)
s[2] += '.' * (n*3)
def top():
return [s[0][0] != '.', s[1][0] != '.', s[2][0] != '.']
def shift():
... | 1444641000 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
3 seconds | ["21 7 15 21 3", "0 0", "1 3 3"] | f94165f37e968442fa7f8be051018ad9 | NoteThe picture shows the tree from the first example: | You are given a weighted tree consisting of $$$n$$$ vertices. Recall that a tree is a connected graph without cycles. Vertices $$$u_i$$$ and $$$v_i$$$ are connected by an edge with weight $$$w_i$$$.You are given $$$m$$$ queries. The $$$i$$$-th query is given as an integer $$$q_i$$$. In this query you need to calculate ... | Print $$$m$$$ integers — the answers to the queries. The $$$i$$$-th value should be equal to the number of pairs of vertices $$$(u, v)$$$ ($$$u < v$$$) such that the maximum weight of an edge on a simple path between $$$u$$$ and $$$v$$$ doesn't exceed $$$q_i$$$. Queries are numbered from $$$1$$$ to $$$m$$$ in the or... | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the number of vertices in the tree and the number of queries. Each of the next $$$n - 1$$$ lines describes an edge of the tree. Edge $$$i$$$ is denoted by three integers $$$u_i$$$, $$$v_i$$$ and $$$w_i$$$ — the l... | standard output | standard input | Python 3 | Python | 1,800 | train_038.jsonl | 6276d6fe09749355a2c6c883c4ded9f2 | 256 megabytes | ["7 5\n1 2 1\n3 2 3\n2 4 1\n4 5 2\n5 7 4\n3 6 2\n5 2 3 4 1", "1 2\n1 2", "3 3\n1 2 1\n2 3 2\n1 3 2"] | PASSED | def find_ancestor(i, father):
if father[i] == i:
return i
father[i] = find_ancestor(father[i], father)
return father[i]
def connect(i, j, father, n_child):
i_anc = find_ancestor(i, father)
j_anc = find_ancestor(j, father)
if n_child[i_anc] > n_child[j_anc]:
n_child[i_anc] += n_c... | 1567175700 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["YES\nNO\nYES\nYES\nNO"] | eea15ff7e939bfcc7002cacbc8a1a3a5 | NoteThe first test case was explained in the statement.The answer to the second test case is NO, since a 1 in a cell ($$$1, 1$$$) flying out of any cannon would continue its flight further. | Polygon is not only the best platform for developing problems but also a square matrix with side $$$n$$$, initially filled with the character 0.On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exact... | For each test case print: YES if there is a sequence of shots leading to a given matrix; NO if such a sequence does not exist. The letters in the words YES and NO can be printed in any case. | The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case starts with a line containing an integer $$$n$$$ ($$$1 \le n \le 50$$$) — the size of the polygon. This is followed by $$$n$$$ lines of length $$$n$$$, consisting of 0 and 1 — t... | standard output | standard input | PyPy 2 | Python | 1,300 | train_002.jsonl | 134d8be64008fe6aadcf84c23931e120 | 256 megabytes | ["5\n4\n0010\n0011\n0000\n0000\n2\n10\n01\n2\n00\n00\n4\n0101\n1111\n0101\n0111\n4\n0100\n1110\n0101\n0111"] | PASSED | T = input()
for _ in xrange(T):
N = input()
ll = []
for _ in xrange(N):
ll.append(raw_input())
oc = 0
for i in xrange(N-1, -1, -1):
for j in xrange(N-1, -1, -1):
if ll[i][j] == "1":
oc += 1
seen = set()
for i in xrange(N-1, -1, -1):
for... | 1590327300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["17\n33\n401"] | 168dbc4994529f5407a440b0c71086da | null | There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downward... | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input. Please do not use the %lld specifier to read or write 64-bit ... | The first line contains integer t (1 ≤ t ≤ 104) — the number of test cases. The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample. | standard output | standard input | PyPy 2 | Python | 1,200 | train_003.jsonl | 8bc650809d3c38e40907508e9d622e6d | 256 megabytes | ["3\n4 8 100"] | PASSED |
n = int(raw_input())
parts = [int(x) for x in raw_input().split()]
for p in parts:
if p % 2 == 0:
print p * 4 + 1
else:
if (p + 3) % 4 == 0:
res = 1 + (((p + 3) / 4) - 1) * 4
print res * 2 + 1
elif (p + 1) % 4 == 0 :
res = 3 + (((p + 1) / 4) - 1) * 4
print res + 1
... | 1338737400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["NO", "cbd", "abda"] | 788ae500235ca7b7a7cd320f745d1070 | NoteString s is lexicographically larger (or simply larger) than string t with the same length, if there is number i, such that s1 = t1, ..., si = ti, si + 1 > ti + 1.The lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one.A palindrome is a str... | Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more.Paul has found a tolerable string s of length n. Help him find the lexicographically next tolerable stri... | If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes). | The first line contains two space-separated integers: n and p (1 ≤ n ≤ 1000; 1 ≤ p ≤ 26). The second line contains string s, consisting of n small English letters. It is guaranteed that the string is tolerable (according to the above definition). | standard output | standard input | Python 3 | Python | 1,700 | train_008.jsonl | a05a078168deb527aed10baa84d17216 | 256 megabytes | ["3 3\ncba", "3 4\ncba", "4 4\nabcd"] | PASSED | #!/usr/bin/python3
import sys
def solve(s, k):
l = len(s)
for i in range(l-1, -1, -1):
prev = s[max(i-2, 0):i]
z = s[i] + 1
while z in prev:
z += 1
if z >= k:
continue
# Gotcha!
ret = s[:i] + [z]
while len(ret) < l:
p... | 1410103800 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["2\n7\n47837"] | b7e36ca8a96dd7951359070d4953beec | NoteIn the first test case, $$$m = 2$$$, which is prime, and $$$n + m = 7 + 2 = 9$$$, which is not prime.In the second test case, $$$m = 7$$$, which is prime, and $$$n + m = 2 + 7 = 9$$$, which is not prime.In the third test case, $$$m = 47837$$$, which is prime, and $$$n + m = 75619 + 47837 = 123456$$$, which is not p... | Pak Chanek has a prime number$$$^\dagger$$$ $$$n$$$. Find a prime number $$$m$$$ such that $$$n + m$$$ is not prime.$$$^\dagger$$$ A prime number is a number with exactly $$$2$$$ factors. The first few prime numbers are $$$2,3,5,7,11,13,\ldots$$$. In particular, $$$1$$$ is not a prime number. | For each test case, output a line containing a prime number $$$m$$$ ($$$2 \leq m \leq 10^5$$$) such that $$$n + m$$$ is not prime. It can be proven that under the constraints of the problem, such $$$m$$$ always exists. If there are multiple solutions, you can output any of them. | Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The following lines contain the description of each test case. The only line of each test case contains a prime number $$$n$$$ ($$$2 \leq n \leq 10^5$$$). | standard output | standard input | PyPy 3-64 | Python | 800 | train_096.jsonl | 774f0c599354fb300cb5f0feecf78838 | 256 megabytes | ["3\n\n7\n\n2\n\n75619"] | PASSED | def solve():
j = int(input())
if j != 2: print(3)
else: print(2)
for t in range(int(input())): solve()
| 1667034600 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["2\n3 1\n1 3", "3\n1 1\n6 5\n8 7", "-1"] | c6c4a833843d479c94f9ebd3e2774775 | NoteIn the first sample string "cbaabc" = "cba" + "abc".In the second sample: "ayrat" = "a" + "yr" + "at". | A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art.First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track... | The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular... | First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100. | standard output | standard input | Python 3 | Python | 2,000 | train_078.jsonl | 5e81abdbd5f336c0f6a7e42c4ebd7e79 | 512 megabytes | ["abc\ncbaabc", "aaabrytaaa\nayrat", "ami\nno"] | PASSED | s = input()
t = input()
revS = s[::-1]
n = len(s)
cur=1
start=-1
end=-1
revFlag=0
errFlag=0
i=0
res=[]
while i < len(t):
if s.find(t[i:i+cur]) != -1 and i+cur <= len(t) and s.find(t[i:i+cur]) + cur <= n:
start = s.find(t[i:i+cur]) + 1
end = start + cur - 1
cur += 1
elif revS.find(t[i:i+c... | 1452261900 | [
"strings",
"trees"
] | [
0,
0,
0,
0,
0,
0,
1,
1
] | |
1 second | ["YES\n1 9\n1 5\n1 10\n1 6\n1 2", "NO", "YES\n3 5 1 3\n1 7\n1 2"] | 5185f842c7c24d4118ae3661f4418a1d | null | Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came up with an interesting question which he could not solve, can you please solve it for him?Given an array consisting of distinct integers. Is it possible to partition the whole array into k disjoint non-empty parts ... | In the first line print "YES" (without the quotes) if it is possible to partition the array in the required way. Otherwise print "NO" (without the quotes). If the required partition exists, print k lines after the first line. The ith of them should contain the content of the ith part. Print the content of the part in t... | The first line will contain three space separated integers n, k, p (1 ≤ k ≤ n ≤ 105; 0 ≤ p ≤ k). The next line will contain n space-separated distinct integers representing the content of array a: a1, a2, ..., an (1 ≤ ai ≤ 109). | standard output | standard input | Python 2 | Python | 1,700 | train_002.jsonl | c790b269a6f03e54a3cb4a99631ca2a4 | 256 megabytes | ["5 5 3\n2 6 10 5 9", "5 5 3\n7 14 2 9 5", "5 3 1\n1 2 3 7 5"] | PASSED | n,k,p=raw_input().strip().split(' ')
n,k,p=int(n),int(k),int(p)
arr=list(map(int,raw_input().strip().split(' ')))
odd=[j for j in arr if j&1]
even=[j for j in arr if not j&1]
if (k-p)>len(odd) or p>len(even)+(len(odd)-k+p)/2 or len(odd)%2!=(k-p)%2:
print 'NO'
else:
print 'YES'
count,j=0,0
while j<len(even) and co... | 1401895800 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
2 seconds | ["YES\n010001\n100100\n001010\nNO\nYES\n11\n11\nYES\n1100\n1100\n0011\n0011\nYES\n1\n1"] | 8aa648ff5adc0cf7b20fea52d2c34759 | null | You are given four positive integers $$$n$$$, $$$m$$$, $$$a$$$, $$$b$$$ ($$$1 \le b \le n \le 50$$$; $$$1 \le a \le m \le 50$$$). Find any such rectangular matrix of size $$$n \times m$$$ that satisfies all of the following conditions: each row of the matrix contains exactly $$$a$$$ ones; each column of the matrix co... | For each test case print: "YES" (without quotes) and the required matrix (if there are several answers, print any) if it exists, or "NO" (without quotes) if it does not exist. To print the matrix $$$n \times m$$$, print $$$n$$$ rows, each of which consists of $$$m$$$ numbers $$$0$$$ or $$$1$$$ describing a row of t... | The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case is described by four positive integers $$$n$$$, $$$m$$$, $$$a$$$, $$$b$$$ ($$$1 \le b \le n \le 50$$$; $$$1 \le a \le m \le 50$$$), where $$$n$$$ and $$$m$$$ are the sizes of th... | standard output | standard input | PyPy 3 | Python | 1,900 | train_000.jsonl | 94a7d72264d735562157d6bb6d342f3e | 256 megabytes | ["5\n3 6 2 1\n2 2 2 1\n2 2 2 2\n4 4 2 2\n2 1 1 2"] | PASSED | # python3 q7.py < test.txt
t = int(input())
for i in range(t):
n, m, a, b = map(int, input().split())
if n * a != m * b:
print('NO')
continue
print('YES')
shift = 0
for j in range(1, m):
if (j * n) % m == 0:
shift = j
break
col = [j for ... | 1590327300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["10", "12"] | f6be5319ad3733d07a8ffd089fc44c71 | Note Explaination for the first sample t = 0 t = 2 t = 3 t = 5 t = 6 t = 7 t = 9 t = 10 | You work in a big office. It is a 9 floor building with an elevator that can accommodate up to 4 people. It is your responsibility to manage this elevator.Today you are late, so there are queues on some floors already. For each person you know the floor where he currently is and the floor he wants to reach. Also, you k... | Print a single integer — the minimal possible time in seconds. | The first line contains an integer n (1 ≤ n ≤ 2000) — the number of employees. The i-th of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 9, ai ≠ bi) — the floor on which an employee initially is, and the floor he wants to reach. The employees are given in the order they came to the elevator. | standard output | standard input | Python 3 | Python | 2,400 | train_000.jsonl | f3b52703a3398876a22c97bbec7ae1b5 | 256 megabytes | ["2\n3 5\n5 3", "2\n5 3\n3 5"] | PASSED | # python3
import sys
from collections import namedtuple
def readline(): return map(int, input().split())
def readlines():
for line in sys.stdin.readlines():
yield map(int, line.split())
class State(namedtuple('State', 'payload time floor')):
def hook(self, pivot, a, b):
lo, up = min(pivot,... | 1526395500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["4\n0\n9"] | d638f524fe07cb8e822b5c6ec3fe8216 | NoteIn the first example, the array elements can be rearranged as follows: $$$[6, 3, 5, 3]$$$.In the third example, the array elements can be rearranged as follows: $$$[4, 4, 2, 1, 1]$$$. | You are given an array $$$a$$$ consisting of $$$n$$$ integers.Let's call a pair of indices $$$i$$$, $$$j$$$ good if $$$1 \le i < j \le n$$$ and $$$\gcd(a_i, 2a_j) > 1$$$ (where $$$\gcd(x, y)$$$ is the greatest common divisor of $$$x$$$ and $$$y$$$).Find the maximum number of good index pairs if you can reorder th... | For each test case, output a single integer — the maximum number of good index pairs if you can reorder the array $$$a$$$ in an arbitrary way. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of the test case contains a single integer $$$n$$$ ($$$2 \le n \le 2000$$$) — the number of elements in the array. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($... | standard output | standard input | PyPy 3-64 | Python | 900 | train_085.jsonl | 41f15511be886488a70eb56581aee085 | 256 megabytes | ["3\n4\n3 6 5 3\n2\n1 7\n5\n1 4 2 4 1"] | PASSED | from math import gcd
for _ in range(int(input())):
n = int(input())
cnt = 0
seq = tuple(map(int, input().split()))
for i in range(n):
for j in range(i + 1, n):
a, b = seq[i], seq[j]
if gcd(a, 2 * b) > 1 or gcd(b, a * 2) > 1:
cnt += 1
pr... | 1622817300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["1\n3", "2\n1 2", "0"] | 0df064fd0288c2ac4832efa227107a0e | null | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he d... | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible... | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | standard output | standard input | Python 3 | Python | 1,500 | train_021.jsonl | 44ef1bcdf34b51a2efb57835b1501269 | 256 megabytes | ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces"] | PASSED | s = input().strip()
t = input().strip()
diff = len(s) - 1
for i in range(len(t)):
if s[i] != t[i]:
diff = i
break
for i in range(diff + 1, len(s)):
if s[i] != t[i - 1]:
print(0)
import sys; sys.exit()
start = diff
while start != 0 and s[start - 1] == s[diff]:
start -= 1
print(diff - start + 1)
pri... | 1287904200 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2.5 seconds | ["4\n3\n4\n2\n3\n4\n1\n2\n3\n4", "5\n3\n3\n3"] | c90c7a562c8221dd428c807c919ae156 | NoteIn the first example Misha's mother is interested in the first $$$10$$$ years after the rule was introduced. The host cities these years are 4, 3, 4, 2, 3, 4, 1, 2, 3, 4.In the second example the host cities after the new city is introduced are 2, 3, 1, 2, 3, 5, 1, 2, 3, 4, 5, 1. | Misha was interested in water delivery from childhood. That's why his mother sent him to the annual Innovative Olympiad in Irrigation (IOI). Pupils from all Berland compete there demonstrating their skills in watering. It is extremely expensive to host such an olympiad, so after the first $$$n$$$ olympiads the organize... | Print $$$q$$$ integers. The $$$i$$$-th of them should be the city the olympiad will be hosted in the year $$$k_i$$$. | The first line contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$1 \leq n, m, q \leq 500\,000$$$) — the number of olympiads before the rule was introduced, the number of cities in Berland wishing to host the olympiad, and the number of years Misha's mother is interested in, respectively. The next line contains $... | standard output | standard input | PyPy 2 | Python | 2,200 | train_018.jsonl | 7fbfbf4d7b0928052a38ba6dd170f875 | 512 megabytes | ["6 4 10\n3 1 1 1 2 2\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16", "4 5 4\n4 4 5 1\n15\n9\n13\n6"] | PASSED | class seg:
def __init__(self, n):
self.n = n
m = 1
while m < n: m *= 2
self.m = m
self.data = [0]*(2 * m)
def add(self, ind):
ind += self.m
while ind:
self.data[ind] += 1
ind >>= 1
def binary(self,k):
ind = 1
... | 1560677700 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["8\n198\n-17\n2999999997\n0\n1"] | 1f435ba837f59b007167419896c836ae | NoteIn the first query frog jumps $$$5$$$ to the right, $$$2$$$ to the left and $$$5$$$ to the right so the answer is $$$5 - 2 + 5 = 8$$$.In the second query frog jumps $$$100$$$ to the right, $$$1$$$ to the left, $$$100$$$ to the right and $$$1$$$ to the left so the answer is $$$100 - 1 + 100 - 1 = 198$$$.In the third... | A frog is currently at the point $$$0$$$ on a coordinate axis $$$Ox$$$. It jumps by the following algorithm: the first jump is $$$a$$$ units to the right, the second jump is $$$b$$$ units to the left, the third jump is $$$a$$$ units to the right, the fourth jump is $$$b$$$ units to the left, and so on.Formally: if th... | Print $$$t$$$ integers. The $$$i$$$-th integer should be the answer for the $$$i$$$-th query. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. Each of the next $$$t$$$ lines contain queries (one query per line). The query is described as three space-separated integers $$$a, b, k$$$ ($$$1 \le a, b, k \le 10^9$$$) — the lengths of two types of jumps and th... | standard output | standard input | Python 3 | Python | 800 | train_006.jsonl | 3c33641a665dc5186fa005d089a543b4 | 256 megabytes | ["6\n5 2 3\n100 1 4\n1 10 5\n1000000000 1 6\n1 1 1000000000\n1 1 999999999"] | PASSED | from math import ceil as c
t = int(input())
while t != 0:
a, b, k = map(int, input().split())
j_right = c(k / 2)
j_left = k // 2
print((j_right * a) - (j_left * b))
t -= 1 | 1542378900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["Alice\nBob\nAlice\nAlice"] | 2bfd566ef883efec5211b01552b45218 | NoteIn the first test case, Alice can win by moving to vertex $$$1$$$. Then wherever Bob moves next, Alice will be able to move to the same vertex on the next move. In the second test case, Bob has the following strategy to win. Wherever Alice moves, Bob will always move to whichever of the two vertices $$$1$$$ or $$$... | Alice and Bob are playing a fun game of tree tag.The game is played on a tree of $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$. Recall that a tree on $$$n$$$ vertices is an undirected, connected graph with $$$n-1$$$ edges.Initially, Alice is located at vertex $$$a$$$, and Bob at vertex $$$b$$$. They take turns alte... | For each test case, output a single line containing the winner of the game: "Alice" or "Bob". | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains five integers $$$n,a,b,da,db$$$ ($$$2\le n\le 10^5$$$, $$$1\le a,b\le n$$$, $$$a\ne b$$$, $$$1\le da,db\le n-1$$$) ... | standard output | standard input | Python 3 | Python | 1,900 | train_023.jsonl | 9e32d7caaf92ef430521ff4df73027dc | 256 megabytes | ["4\n4 3 2 1 2\n1 2\n1 3\n1 4\n6 6 1 2 5\n1 2\n6 5\n2 3\n3 4\n4 5\n9 3 9 2 5\n1 2\n1 6\n1 9\n1 3\n9 5\n7 9\n4 8\n4 3\n11 8 11 3 3\n1 2\n11 9\n4 9\n6 5\n2 10\n3 2\n5 9\n8 3\n7 4\n7 10"] | PASSED | from collections import deque
def dfs(x):
length[x] = 0
queue = deque()
queue.append(x)
while queue:
y = queue.popleft()
for z in t[y]:
if length[z] is None:
length[z] = length[y]+1
queue.append(z)
for _ in range(int(input())):
n,a,b,da,db = list(map(int,input().split()))
t = [[] for i in range(... | 1599402900 | [
"games",
"trees"
] | [
1,
0,
0,
0,
0,
0,
0,
1
] | |
10 seconds | ["NO\nYES\n1 2\n6\n2 3\nYES\n1 1\n1\n1\nYES\n3 2\n3 7 4\n12 14"] | f596e0bcefde8227e8a7b9d923da828a | null | You are given two sets of positive integers $$$A$$$ and $$$B$$$. You have to find two non-empty subsets $$$S_A \subseteq A$$$, $$$S_B \subseteq B$$$ so that the least common multiple (LCM) of the elements of $$$S_A$$$ is equal to the least common multiple (LCM) of the elements of $$$S_B$$$. | For each test case, if there do not exist two subsets with equal least common multiple, output one line with NO. Otherwise, output one line with YES, followed by a line with two integers $$$|S_A|, |S_B|$$$ ($$$1 \leq |S_A| \leq n$$$, $$$1 \leq |S_B| \leq m$$$), the sizes of the subsets $$$S_A$$$ and $$$S_B$$$ The next ... | The input consists of multiple test cases. The first line of the input contains one integer $$$t$$$ ($$$1 \leq t \leq 200$$$), the number of test cases. For each test case, there is one line containing two integers $$$n, m$$$ ($$$1 \leq n, m \leq 1000$$$), the sizes of the sets $$$A$$$ and $$$B$$$, respectively. The ne... | standard output | standard input | PyPy 3 | Python | 3,200 | train_092.jsonl | f0c2aece285fddc23cc7af1d79bbbf3e | 512 megabytes | ["4\n3 4\n5 6 7\n2 8 9 10\n4 4\n5 6 7 8\n2 3 4 9\n1 3\n1\n1 2 3\n5 6\n3 4 9 7 8\n2 15 11 14 20 12"] | PASSED | import math
for _ in range(int(input())):
n, m = [*map(int, input().split())]
N, M = 1<<(len(bin(n-1))-2), 1<<(len(bin(m-1))-2)
a = [*map(int, input().split())]
b = [*map(int, input().split())]
d = [[math.gcd(i,j) for i in b] for j in a]
d1, d2 = [[0]*(M<<1) for i in range(n)], [[0]*(N<<1... | 1648132500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["5\n6\n2\n948683296\n2996666667"] | 10812427d3052ce91cd0951911d3acb9 | NoteIn the first test case, $$$5$$$ luxury numbers in range $$$[8, 19]$$$ are: $$$8, 9, 12, 15, 16$$$. | While working at DTL, Ela is very aware of her physical and mental health. She started to practice various sports, such as Archery, Yoga, and Football.Since she started engaging in sports activities, Ela switches to trying a new sport on days she considers being "Luxury" days. She counts the days since she started thes... | For each test case, output an integer that denotes the answer. | Each test contains multiple test cases. The first line has the number of test cases $$$t$$$ ($$$1 \le t \le 10\ 000$$$). The description of the test cases follows. The only line of each test case contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^{18}$$$) — the intervals at which you want to know how ma... | standard output | standard input | Python 3 | Python | 1,300 | train_094.jsonl | a646f1ee91fa92b98867c263fba6bb61 | 256 megabytes | ["5\n\n8 19\n\n8 20\n\n119 121\n\n1 100000000000000000\n\n1234567891011 1000000000000000000"] | PASSED | import sys,math
input=sys.stdin.readline
for _ in range(int(input())):
#n=int(input())
l,r=map(int,input().split())
#a=list(map(int,input().split()))
a=math.isqrt(l)
b=math.isqrt(r)
ans=0
if a==b:
if r>=a**2>=l:
ans+=1
if r>=(a**2)+2*a>=l:
... | 1665153300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
8 seconds | ["8.0000000000 0.0000000000\n5.0000000000 -3.0000000000\n4.2568551745 -2.6691306064\n4.2568551745 -3.6691306064"] | fb46e7a175719eabd9f82a116bccd678 | NoteThe following pictures shows the state of the arm after each operation. The coordinates of point F are printed after applying each operation. For simplicity, we only show the blue endpoints of a segment (with the exception for the red endpoint of the first segment). For instance, the point labeled B is the blue end... | Roger is a robot. He has an arm that is a series of n segments connected to each other. The endpoints of the i-th segment are initially located at points (i - 1, 0) and (i, 0). The endpoint at (i - 1, 0) is colored red and the endpoint at (i, 0) is colored blue for all segments. Thus, the blue endpoint of the i-th segm... | Print m lines. The i-th line should contain two real values, denoting the coordinates of the blue endpoint of the last segment after applying operations 1, ..., i. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer for a particular valu... | The first line of the input will contain two integers n and m (1 ≤ n, m ≤ 300 000) — the number of segments and the number of operations to perform. Each of the next m lines contains three integers xi, yi and zi describing a move. If xi = 1, this line describes a move of type 1, where yi denotes the segment number and ... | standard output | standard input | PyPy 3 | Python | 2,500 | train_064.jsonl | e6f2d9aa7a59ca5bcd62065bce87a4ee | 256 megabytes | ["5 4\n1 1 3\n2 3 90\n2 5 48\n1 4 1"] | PASSED | from cmath import rect
import sys
import math
from functools import reduce
class SegmentTree():
def __init__(self, L, function = lambda x,y: x+y):
self.function = function
N = self.size = len(L)
M = 1 << N.bit_length()
self.margin = 2*M - N
self.L = [None for i in range(self... | 1454087400 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["13\n1 0\n2 1\n3 2\n3 1\n2 2\n4 3\n4 1\n5 2\n5 1\n4 2\n2 3\n2 0\n1 1"] | b45e785361f3da9a56a0063cd4f97eaa | null | Denis came to Nastya and discovered that she was not happy to see him... There is only one chance that she can become happy. Denis wants to buy all things that Nastya likes so she will certainly agree to talk to him. The map of the city where they live has a lot of squares, some of which are connected by roads. There ... | In the first line output the integer $$$k$$$ $$$(1 \leq k \leq 10^6)$$$ — the length of the path of Denis. In the next $$$k$$$ lines output pairs $$$v_i, t_i$$$ — pairs that describe Denis's route (as in the statement). All route requirements described in the statements must be met. It is guaranteed that under given ... | The first line contains a single integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$ — the number of squares in the city. The next $$$n - 1$$$ lines contain two integers $$$u$$$ and $$$v$$$ $$$(1 \leq v, u \leq n, u \neq v)$$$ - the numbers of the squares connected by the road. It is guaranteed that the given graph is a tree... | standard output | standard input | PyPy 2 | Python | 2,600 | train_062.jsonl | 32a874cccbea623dcb665a32d92888f1 | 256 megabytes | ["5\n1 2\n2 3\n2 4\n4 5"] | PASSED | import sys
range = xrange
input = raw_input
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
... | 1587653100 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["First\nSecond\nSecond\nFirst\nFirst\nSecond\nFirst"] | 0c9030689394ad4e126e5b8681f1535c | NoteIn the first test case, the first player will win the game. His winning strategy is: The first player should take the stones from the first pile. He will take $$$1$$$ stone. The numbers of stones in piles will be $$$[1, 5, 4]$$$. The second player should take the stones from the first pile. He will take $$$1$$$ ... | There are $$$n$$$ piles of stones, where the $$$i$$$-th pile has $$$a_i$$$ stones. Two people play a game, where they take alternating turns removing stones.In a move, a player may remove a positive number of stones from the first non-empty pile (the pile with the minimal index, that has at least one stone). The first ... | For each test case, if the player who makes the first move will win, output "First". Otherwise, output "Second". | The first line contains a single integer $$$t$$$ ($$$1\le t\le 1000$$$) — the number of test cases. Next $$$2t$$$ lines contain descriptions of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 10^5$$$) — the number of piles. The second line of each test case contains $$$n$$... | standard output | standard input | Python 3 | Python | 1,100 | train_003.jsonl | 11990ae9d14d72d0413a6a13ca438076 | 256 megabytes | ["7\n3\n2 5 4\n8\n1 1 1 1 1 1 1 1\n6\n1 2 3 4 5 6\n6\n1 1 2 1 2 2\n1\n1000000000\n5\n1 2 2 1 1\n3\n1 1 1"] | PASSED |
for _ in range(int(input())):
n = input()
arr = input().split()
#
idx = 0
for v in arr:
if v != '1':
break
idx += 1
#
if idx != len(arr):
print('First' if (idx+1)%2==1 else 'Second')
else:
print('First' if len(arr)%2==1 else 'Second')
| 1595342100 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["1.0000000", "2.0000000", "1.3284271", "My poor head =("] | c4b0f9263e18aac26124829cf3d880b6 | NoteIn the first example the answer is restricted by the coffin's length (remember — coffin's widths should not be larger than it's length).In the second example it is possible to drag the coffin through the corridor thanks to rotating wheels: firstly, drag it forward by one side while it will not be hampered by the wa... | A very unusual citizen lives in a far away kingdom — Dwarf Gracula. However, his unusual name is not the weirdest thing (besides, everyone long ago got used to calling him simply Dwarf Greg). What is special about Dwarf Greg — he's been living for over 200 years; besides, he lives in a crypt on an abandoned cemetery an... | Print the maximally possible width of a coffin with absolute or relative error no more than 10 - 7. If a coffin with the given length and positive width (the coffin that would meet the conditions from the problem's statement) does not exist, print "My poor head =(" (without quotes). It is guaranteed that if the answer ... | The first line contains three space-separated integers a, b and l from the problem's statement (1 ≤ a, b, l ≤ 104). | standard output | standard input | Python 2 | Python | 2,500 | train_080.jsonl | 8f4f2271765b2d947686b1a8b2bbf9fb | 256 megabytes | ["2 2 1", "2 2 2", "2 2 3", "2 2 6"] | PASSED | EPS = 1e-8
def cross(a, b):
return (a[0] * b[1]) - (a[1] * b[0])
def f(a, b, l, x):
y = (l*l - x*x)**0.5
return cross( (a-x, b), (-x, y) )
def main():
a, b, l = map(int, raw_input().split())
if a > b:
a, b = b, a
if l <= a and a <= b:
print "%.9lf" % l
elif a < l and l <... | 1311346800 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
4 seconds | ["YES\nNO\nYES\nYES\nYES"] | bcd34e88bcd70ad36acbe6c3b70aa45d | NoteThe first example is explained in the statement.In the second example, it is impossible to get the value $$$31$$$ from the numbers of the multiset $$$b$$$ by available operations.In the third example, we can proceed as follows: Replace $$$2$$$ with $$$2 \cdot 2 = 4$$$. We get $$$b = \{4, 14, 14, 26, 42\}$$$. Rep... | Multiset —is a set of numbers in which there can be equal elements, and the order of the numbers does not matter. Two multisets are equal when each value occurs the same number of times. For example, the multisets $$$\{2,2,4\}$$$ and $$$\{2,4,2\}$$$ are equal, but the multisets $$$\{1,2,2\}$$$ and $$$\{1,1,2\}$$$ — are... | For each test case, print on a separate line: YES if you can make the multiset $$$b$$$ become equal to $$$a$$$, NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as positive answer). | The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases. Each test case consists of three lines. The first line of the test case contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) —the number of elements in the multisets $$$a$$$ and $$$b$$$. The second... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_089.jsonl | 6d5ac23ebf07c7e117684c2af2ff100d | 256 megabytes | ["5\n\n4\n\n2 4 5 24\n\n1 4 6 11\n\n3\n\n1 4 17\n\n4 5 31\n\n5\n\n4 7 10 13 14\n\n2 14 14 26 42\n\n5\n\n2 2 4 4 4\n\n28 46 62 71 98\n\n6\n\n1 2 10 16 64 80\n\n20 43 60 74 85 99"] | PASSED | #!/usr/bin/env python3
import io, os, sys
from sys import stdin, stdout
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def input(): return stdin.readline().strip()
def read_int_list(): return list(map(int, input().split()))
def read_int_tuple(): return tuple(map(int, input().split()))
def re... | 1657463700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["2\n3\n3\n319908071"] | 4e9dfc5e988cebb9a92f0c0b7ec06981 | NoteFor the first test case, the two valid assignments are$$$0000\\ 0000\\ 0000$$$and$$$0000\\ 0010\\ 0000$$$ | Omkar's most recent follower, Ajit, has entered the Holy Forest. Ajit realizes that Omkar's forest is an $$$n$$$ by $$$m$$$ grid ($$$1 \leq n, m \leq 2000$$$) of some non-negative integers. Since the forest is blessed by Omkar, it satisfies some special conditions: For any two adjacent (sharing a side) cells, the abso... | For each test case, print one integer: the number of valid configurations modulo $$$10^9+7$$$. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 100$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 2000, nm \geq 2$$$) – the dimensions of the forest. $$$n$$$ l... | standard output | standard input | PyPy 3-64 | Python | 2,300 | train_094.jsonl | bd602f37f0c4294d99c66cbd4a7f40b9 | 256 megabytes | ["4\n3 4\n0000\n00#0\n0000\n2 1\n#\n#\n1 2\n##\n6 29\n#############################\n#000##0###0##0#0####0####000#\n#0#0##00#00##00####0#0###0#0#\n#0#0##0#0#0##00###00000##00##\n#000##0###0##0#0##0###0##0#0#\n#############################"] | PASSED | import sys
input = sys.stdin.readline
inf = float('inf')
def getInt():
return int(input())
def getStr():
return input().strip()
def getList(split=True):
s = getStr()
if split:
s = s.split()
return map(int, s)
t = getInt()
# t = 1
M = 10 ** 9 + 7
def solve():
n, m = getList()
... | 1622990100 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nNO\nYES\nNO"] | 3d6cd0a82513bc2119c9af3d1243846f | NoteIn the first test case, you can do the following: Remove the third character of the first string and insert it after the second character of the second string, making the two strings "ca" and "cbab" respectively. Remove the second character of the second string and insert it after the second character of the firs... | You are given $$$n$$$ strings $$$s_1, s_2, \ldots, s_n$$$ consisting of lowercase Latin letters.In one operation you can remove a character from a string $$$s_i$$$ and insert it to an arbitrary position in a string $$$s_j$$$ ($$$j$$$ may be equal to $$$i$$$). You may perform this operation any number of times. Is it po... | If it is possible to make the strings equal, print "YES" (without quotes). Otherwise, print "NO" (without quotes). You can output each character in either lowercase or uppercase. | The first line contains $$$t$$$ ($$$1 \le t \le 10$$$): the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$): the number of strings. $$$n$$$ lines follow, the $$$i$$$-th line contains $$$s_i$$$ ($$$1 \le \lvert s_i \rvert \le 1000$$$). The sum of lengths ... | standard output | standard input | PyPy 3 | Python | 800 | train_003.jsonl | bc7743fd468905a1fe2b88aa56c6e06d | 256 megabytes | ["4\n2\ncaa\ncbb\n3\ncba\ncba\ncbb\n4\nccab\ncbac\nbca\nacbcc\n4\nacb\ncaf\nc\ncbafc"] | PASSED | for i in range(int(input())):
a = int(input())
d = {}
for i in range(a):
for x in input():
if x in d:
d[x] += 1
else:
d[x] = 1
key = True
for i in d:
if d[i] % a != 0:
key = False
if key: print("YES")
else: p... | 1598798100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["YES\nNO\nYES"] | 5172d358f1d451b42efff1019219a54d | NoteIn the first test case, you can take, for example, $$$a = 5$$$ as the size of the pack. Then if a customer wants to buy $$$3$$$ cans, he'll buy $$$5$$$ instead ($$$3 \bmod 5 = 3$$$, $$$\frac{5}{2} = 2.5$$$). The one who wants $$$4$$$ cans will also buy $$$5$$$ cans.In the second test case, there is no way to choose... | You got a job as a marketer in a pet shop, and your current task is to boost sales of cat food. One of the strategies is to sell cans of food in packs with discounts. Suppose you decided to sell packs with $$$a$$$ cans in a pack with a discount and some customer wants to buy $$$x$$$ cans of cat food. Then he follows a ... | For each test case, print YES if you can choose such size of pack $$$a$$$ that each customer buys more cans than they wanted initially. Otherwise, print NO. You can print each character in any case. | 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 $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the range of the number of cans customers can buy. | standard output | standard input | Python 3 | Python | 800 | train_002.jsonl | b3f64d711652286b538a3276b2613397 | 256 megabytes | ["3\n3 4\n1 2\n120 150"] | PASSED | t = int(input())
while(t>0):
l,r = map(int,input().split())
if (r-l) < l:
print("YES")
else:
print("NO")
t = t-1 | 1603809300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["Yes", "No", "No", "Yes"] | c54042eebaef01783a74d31521db9baa | NoteIn the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one.In the second example, while it's possible to draw two lines that cover all points... | Connect the countless points with lines, till we reach the faraway yonder.There are n points on a coordinate plane, the i-th of which being (i, yi).Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes throug... | Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). | The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points. The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point. | standard output | standard input | PyPy 3 | Python | 1,600 | train_009.jsonl | 5f5d6eabb2e1d6c2ebf1e8f7611a2e2d | 256 megabytes | ["5\n7 5 8 6 9", "5\n-1 -2 0 0 -5", "5\n5 4 3 2 1", "5\n1000000000 0 0 0 0"] | PASSED | n=int(input())
d=list(map(int,input().split()))
a,b,c=d[:3]
if b-a==c-b:
e=b-a
f=0
for i in range(3,n):
if (d[i]-c)/(i-2)!=e:
if f and(d[i]-g)/(i-h)!=e:print('No');exit()
else:g,h=d[i],i;f=1
print('Yes'if f else'No')
else:
p1=p2=p3=1
e,f,g=b-a,c,2
h,j,k=c-b,a,... | 1504272900 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["1", "4"] | 566adc43d2d6df257c26c5f5495a5745 | NoteIn both samples there are exactly 4 numbers of length 3 in binary number system. In the first sample Nick writes 3 numbers on the first page and 1 on the second page. In the second sample all the 4 numbers can be written on the first page. | Nick is attracted by everything unconventional. He doesn't like decimal number system any more, and he decided to study other number systems. A number system with base b caught his attention. Before he starts studying it, he wants to write in his notepad all the numbers of length n without leading zeros in this number ... | In the only line output the amount of numbers written on the same page as the last number. | The only input line contains three space-separated integers b, n and c (2 ≤ b < 10106, 1 ≤ n < 10106, 1 ≤ c ≤ 109). You may consider that Nick has infinite patience, endless amount of paper and representations of digits as characters. The numbers doesn't contain leading zeros. | standard output | standard input | Python 2 | Python | 2,400 | train_037.jsonl | 8942c37a5798feaf0256fc060bad7e39 | 64 megabytes | ["2 3 3", "2 3 4"] | PASSED | #!/usr/bin/python
primes = [
2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
233, 239, 241, 251, 257, 263, 269,... | 1276182000 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
3 seconds | ["1 3\n1 0\n3 0 1 2\n0"] | 2c610873aa1a772a4c7f32cb74dd75fa | NoteConsider the example: in the first test case, the only possible value for the cyclic shift is $$$3$$$. If we shift $$$[1, 2, 3, 4]$$$ by $$$3$$$ positions, we get $$$[2, 3, 4, 1]$$$. Then we can swap the $$$3$$$-rd and the $$$4$$$-th elements to get the array $$$[2, 3, 1, 4]$$$; in the second test case, the only... | An identity permutation of length $$$n$$$ is an array $$$[1, 2, 3, \dots, n]$$$.We performed the following operations to an identity permutation of length $$$n$$$: firstly, we cyclically shifted it to the right by $$$k$$$ positions, where $$$k$$$ is unknown to you (the only thing you know is that $$$0 \le k \le n - 1$... | For each test case, print the answer in the following way: firstly, print one integer $$$r$$$ ($$$0 \le r \le n$$$) — the number of possible values of $$$k$$$ for the cyclic shift operation; secondly, print $$$r$$$ integers $$$k_1, k_2, \dots, k_r$$$ ($$$0 \le k_i \le n - 1$$$) — all possible values of $$$k$$$ in in... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of two lines. The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 3 \cdot 10^5$$$; $$$0 \le m \le \frac{n}{3}$$$). The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p... | standard output | standard input | PyPy 3 | Python | 2,100 | train_105.jsonl | 762dca833c006bee03c266b87ecb3620 | 256 megabytes | ["4\n4 1\n2 3 1 4\n3 1\n1 2 3\n3 1\n3 2 1\n6 0\n1 2 3 4 6 5"] | PASSED | import sys
input = sys.stdin.readline
from collections import Counter
for _ in range(int(input())):
n, m = map(int, input().split())
A = list(map(int, input().split()))
A = [a - 1 for a in A]
B = [(i - a) % n for i, a in enumerate(A)]
cnt = Counter(B)
ans = []
X = list(range(1, n... | 1626964500 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.