prob_desc_time_limit stringclasses 21
values | prob_desc_sample_outputs stringlengths 5 329 | src_uid stringlengths 32 32 | prob_desc_notes stringlengths 31 2.84k ⌀ | prob_desc_description stringlengths 121 3.8k | prob_desc_output_spec stringlengths 17 1.16k ⌀ | prob_desc_input_spec stringlengths 38 2.42k ⌀ | prob_desc_output_to stringclasses 3
values | prob_desc_input_from stringclasses 3
values | lang stringclasses 5
values | lang_cluster stringclasses 1
value | difficulty int64 -1 3.5k ⌀ | file_name stringclasses 111
values | code_uid stringlengths 32 32 | prob_desc_memory_limit stringclasses 11
values | prob_desc_sample_inputs stringlengths 5 802 | exec_outcome stringclasses 1
value | source_code stringlengths 29 58.4k | prob_desc_created_at stringlengths 10 10 | tags listlengths 1 5 | hidden_unit_tests stringclasses 1
value | labels listlengths 8 8 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 second | ["576", "34"] | e6fcbe3f102b694a686c0295edbc35e9 | NoteConsider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.The second sample. The optimal solution is to take one item from the right, then one item from the left and... | Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.Vasya needs to collect all these items, however he won't do it by himself. He uses... | In the single line print a single number — the answer to the problem. | The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104). The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100). | standard output | standard input | Python 3 | Python | 1,500 | train_043.jsonl | db4095f95a6f208da1e27c62cdbbaa80 | 256 megabytes | ["3 4 4 19 1\n42 3 99", "4 7 2 3 9\n1 2 3 4"] | PASSED | #!/usr/bin/python3
import sys
n, l, r, ql, qr = map(int, sys.stdin.readline().strip().split())
w = [int(x) for x in sys.stdin.readline().strip().split()]
s = [0]
for i in range(0, n):
s.append(s[-1] + w[i])
def cost(left):
right = n - left
diff = left - right
bonus = 0
if diff > 0: # left part i... | 1381678200 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0 2\n3 0\n2 0\n0 1\n1 0"] | 7f71bea1c62b0a027c8d55431fbc7db7 | NoteIn the first case, the maximal value of the product is $$$2$$$. Thus, we can either delete the first three elements (obtain array $$$[2]$$$), or the last two and one first element (also obtain array $$$[2]$$$), or the last two elements (obtain array $$$[1, 2]$$$). Thus, in the first case, the answers fit: "3 0", or... | You are given an array $$$a$$$ consisting of $$$n$$$ integers. For each $$$i$$$ ($$$1 \le i \le n$$$) the following inequality is true: $$$-2 \le a_i \le 2$$$.You can remove any number (possibly $$$0$$$) of elements from the beginning of the array and any number (possibly $$$0$$$) of elements from the end of the array.... | For each test case, output two non-negative numbers $$$x$$$ and $$$y$$$ ($$$0 \le x + y \le n$$$) — such that the product (multiplication) of the array numbers, after removing $$$x$$$ elements from the beginning and $$$y$$$ elements from the end, is maximal. If there is more than one way to get the maximal product, it ... | The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases in the test. Then the descriptions of the input test cases follow. The first line of each test case description contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) —the length of array $$$a$$$. The next ... | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_105.jsonl | de60d951b5320e2432508e8681c2011c | 256 megabytes | ["5\n4\n1 2 -1 2\n3\n1 1 -2\n5\n2 0 -2 2 -1\n3\n-2 -1 -1\n3\n-1 -2 -2"] | PASSED | import math
from sys import stdin
input = stdin.readline
#// - remember to add .strip() when input is a string
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int,input().split()))
new = []
temp = []
for i in range(len(arr)):
if arr[i] == 0:
if len(t... | 1648737300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["0\n2\n1\n-1"] | 03e5f71810b10318fed344878d226a10 | NoteIn the first test case, $$$n=3876$$$, which is already an even number. Polycarp doesn't need to do anything, so the answer is $$$0$$$.In the second test case, $$$n=387$$$. Polycarp needs to do $$$2$$$ operations: Select $$$l=2$$$ and reverse the prefix $$$\underline{38}7$$$. The number $$$n$$$ becomes $$$837$$$. Th... | Polycarp has an integer $$$n$$$ that doesn't contain the digit 0. He can do the following operation with his number several (possibly zero) times: Reverse the prefix of length $$$l$$$ (in other words, $$$l$$$ leftmost digits) of $$$n$$$. So, the leftmost digit is swapped with the $$$l$$$-th digit from the left, the sec... | Print $$$t$$$ lines. On each line print one integer — the answer to the corresponding test case. If it is impossible to make an even number, print -1. | The first line contains the number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each of the following $$$t$$$ lines contains one integer $$$n$$$ ($$$1 \le n < 10^9$$$). It is guaranteed that the given number doesn't contain the digit 0. | standard output | standard input | PyPy 3-64 | Python | 800 | train_093.jsonl | 0840806bd61333712c4d5cca923e6735 | 256 megabytes | ["4\n3876\n387\n4489\n3"] | PASSED | for _ in range(int(input())):
n = input()
if int(n[-1]) % 2 == 0:
print(0)
elif int(n[0]) % 2 == 0:
print(1)
elif any(not (int(e) % 2) for e in n):
print(2)
else:
print(-1) | 1637850900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["YES\n3 4", "NO", "YES\n1 1"] | 6493e146ea8d931582d77bb1b0f06e53 | null | Ivan is going to sleep now and wants to set his alarm clock. There will be many necessary events tomorrow, the $$$i$$$-th of them will start during the $$$x_i$$$-th minute. Ivan doesn't want to skip any of the events, so he has to set his alarm clock in such a way that it rings during minutes $$$x_1, x_2, \dots, x_n$$$... | If it's impossible to choose such values $$$y$$$ and $$$j$$$ so all constraints are satisfied, print "NO" in the first line. Otherwise print "YES" in the first line. Then print two integers $$$y$$$ ($$$1 \le y \le 10^{18}$$$) and $$$j$$$ ($$$1 \le j \le m$$$) in the second line, where $$$y$$$ is the first minute Ivan's... | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 3 \cdot 10^5, 1 \le m \le 3 \cdot 10^5$$$) — the number of events and the number of possible settings for the interval between signals. The second line of the input contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \l... | standard output | standard input | Python 3 | Python | 1,300 | train_009.jsonl | d018b510e8a073586cba1b3161660675 | 256 megabytes | ["3 5\n3 12 18\n2 6 5 3 3", "4 2\n1 5 17 19\n4 5", "4 2\n1 5 17 19\n2 1"] | PASSED | from math import gcd
n,m = map(int,input().split())
l = list(map(int,input().split()))
r = list(map(int,input().split()))
k = []
for i in range(n-1):
k.append(l[i+1]-l[i])
s = 0
for i in range(len(k)):
s = gcd(s,k[i])
for i in range(m):
if s%r[i] == 0:
print("YES")
t = l[0]%r[i]
if t == 0:
t = r[i]... | 1555943700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["01111", "0011111011"] | 2bf41400fa51f472f1d3904baa06d6a8 | NoteHere is the graph given in the first example. There is only one minimum spanning tree in this graph. A minimum spanning tree is $$$(1,2),(3,5),(1,3),(2,4)$$$ which has weight $$$1+2+3+5=11$$$.Here is a part of the process of calling findMST(1): reset the array vis and the edge set s; calling dfs(1); vis[1] := t... | You are given a connected undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. The weight of the $$$i$$$-th edge is $$$i$$$.Here is a wrong algorithm of finding a minimum spanning tree (MST) of a graph:vis := an array of length ns := a set of edgesfunction dfs(u): vis[u] := true iterate through each... | You need to output a binary string $$$s$$$, where $$$s_i=1$$$ if findMST(i) creates an MST, and $$$s_i = 0$$$ otherwise. | The first line of the input contains two integers $$$n$$$, $$$m$$$ ($$$2\le n\le 10^5$$$, $$$n-1\le m\le 2\cdot 10^5$$$) — the number of vertices and the number of edges in the graph. Each of the following $$$m$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1\le u_i, v_i\le n$$$, $$$u_i\ne v_i$$$), describi... | standard output | standard input | PyPy 3 | Python | 2,400 | train_103.jsonl | eb2eb917905ed8eda46d42fc52287692 | 256 megabytes | ["5 5\n1 2\n3 5\n1 3\n3 2\n4 2", "10 11\n1 2\n2 5\n3 4\n4 2\n8 1\n4 5\n10 5\n9 5\n8 2\n5 7\n4 6"] | PASSED | import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n,m=map(int,input().split())
EDGE=[tuple(map(int,input().split())) for i in range(m)]
# UnionFind
Group = [i for i in range(n+1)] # グループ分け
Nodes = [1]*(n+1) # 各グループのノードの数
def find(x):
while Group[x] != x:
... | 1657982100 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["1\n2", "0"] | 679f7243fe1e072af826a779c44b5056 | null | Boy Dima gave Julian a birthday present — set $$$B$$$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integ... | In the first line print single integer $$$k$$$ – the number of erased elements. In the second line print $$$k$$$ integers — values of erased elements. If there are multiple answers, print any of them. | First line contains an integer $$$n ~ (1 \leqslant n \leqslant 200\,000)$$$ — size of $$$B$$$ Second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$$$ — numbers of $$$B$$$, all $$$b_i$$$ are unique | standard output | standard input | PyPy 3 | Python | 1,900 | train_057.jsonl | c1f47a2ab7a63a58bd754e91cab68b4e | 256 megabytes | ["3\n1 2 3", "2\n2 6"] | PASSED | n = int(input())
B = list(map(int, input().split()))
A = []
for i in range(100):
A.append([])
for i in B:
x = i
c = 0
while x % 2 == 0:
x //= 2
c += 1
A[c].append(i)
mlen = 0
f = 1
for lst in A:
mlen = max(mlen, len(lst))
ans = []
for lst in A:
if len(lst) == mlen and f:
... | 1568822700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["1 1 2 \n1 2 1", "-1"] | 4dddcf0ded11672a4958fb0d391dbaf5 | NoteNote that two students become close friends only if they share a bus each day. But the bus they share can differ from day to day. | Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrang... | If there is no valid arrangement just print -1. Otherwise print d lines, in each of them print n integers. The j-th integer of the i-th line shows which bus the j-th student has to take on the i-th day. You can assume that the buses are numbered from 1 to k. | The first line of input contains three space-separated integers n, k, d (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109). | standard output | standard input | Python 3 | Python | 1,900 | train_025.jsonl | f3867638f2d5dc9ddd1bfeca4451685c | 256 megabytes | ["3 2 2", "3 2 1"] | PASSED | n,k,d=map(int,input().split())
if n>k**d:print(-1);exit()
K=1
for j in range(d):
print(" ".join([str(i//K%k +1) for i in range(n)]))
K*=k | 1408116600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["11\n4 1\n2 5\n1 3\n5 2\n3 4"] | c151fe26b4152474c78fd71c7ab49c88 | NoteThe first test from the statement the match looks as follows: bill → bilbo (lcp = 3) galya → galadriel (lcp = 3) gennady → gendalf (lcp = 3) toshik → torin (lcp = 2) boris → smaug (lcp = 0) | Teachers of one programming summer school decided to make a surprise for the students by giving them names in the style of the "Hobbit" movie. Each student must get a pseudonym maximally similar to his own name. The pseudonym must be a name of some character of the popular saga and now the teachers are busy matching ps... | In the first line print the maximum possible quality of matching pseudonyms to students. In the next n lines describe the optimal matching. Each line must have the form a b (1 ≤ a, b ≤ n), that means that the student who was number a in the input, must match to the pseudonym number b in the input. The matching should b... | The first line contains number n (1 ≤ n ≤ 100 000) — the number of students in the summer school. Next n lines contain the name of the students. Each name is a non-empty word consisting of lowercase English letters. Some names can be repeating. The last n lines contain the given pseudonyms. Each pseudonym is a non-empt... | standard output | standard input | PyPy 3 | Python | 2,300 | train_001.jsonl | 57da54098f153a43ca0403ea32fc9552 | 256 megabytes | ["5\ngennady\ngalya\nboris\nbill\ntoshik\nbilbo\ntorin\ngendalf\nsmaug\ngaladriel"] | PASSED | import sys
SIGMA = 26
nodes = []
pairs = []
res = 0
class Node:
def __init__(self):
self.ch = {}
self.a = []
self.b = []
self.d = 0
def add(self, s, i):
t = self
for c in s:
v = ord(c) - ord('a')
if not v in t.ch:
t.ch[v... | 1438273200 | [
"trees",
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
1
] | |
1 second | ["Yes\nNo\nYes\nNo\nYes"] | 30cfce44a7a0922929fbe54446986748 | NoteIn the first test case of the example, we can assume that each grain weighs $$$17$$$ grams, and a pack $$$119$$$ grams, then really Nastya could collect the whole pack.In the third test case of the example, we can assume that each grain weighs $$$16$$$ grams, and a pack $$$128$$$ grams, then really Nastya could col... | Nastya just made a huge mistake and dropped a whole package of rice on the floor. Mom will come soon. If she sees this, then Nastya will be punished.In total, Nastya dropped $$$n$$$ grains. Nastya read that each grain weighs some integer number of grams from $$$a - b$$$ to $$$a + b$$$, inclusive (numbers $$$a$$$ and $$... | For each test case given in the input print "Yes", if the information about the weights is not inconsistent, and print "No" if $$$n$$$ grains with masses from $$$a - b$$$ to $$$a + b$$$ cannot make a package with a total mass from $$$c - d$$$ to $$$c + d$$$. | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The next $$$t$$$ lines contain descriptions of the test cases, each line contains $$$5$$$ integers: $$$n$$$ $$$(1 \leq n \leq 1000)$$$ — the number of grains that Nastya ... | standard output | standard input | Python 2 | Python | 900 | train_003.jsonl | 16e50d0d9fdc4640b1a7a3973a09dec2 | 256 megabytes | ["5\n7 20 3 101 18\n11 11 10 234 2\n8 9 7 250 122\n19 41 21 321 10\n3 10 8 6 1"] | PASSED | from sys import stdin, stdout
read = stdin.readline
write = stdout.write
xr = xrange
def main():
for tc in xr(int(read())):
n,a,b,c,d = map(int, read().split())
if n * (a + b ) < c - d or n * (a - b) > c + d: write('No\n')
else: write('Yes\n')
if __name__ == "__main__":
main()
| 1587653100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["Petr"] | a9cc20ba7d6e31706ab1743bdde97669 | NotePlease note that the sample is not a valid test (because of limitations for $$$n$$$) and is given only to illustrate input/output format. Your program still has to print correct answer to this test to get AC.Due to randomness of input hacks in this problem are forbidden. | Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $$$1$$$ to $$$n$$$ and then $$$3n$$$ times takes a random pair of different elements and swaps them. Alex ... | If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes). | In the first line of input there is one integer $$$n$$$ ($$$10^{3} \le n \le 10^{6}$$$). In the second line there are $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$ — the permutation of size $$$n$$$ from the test. It is guaranteed that all tests except for sample are generated this way: First we choose $$$n$$$ —... | standard output | standard input | Python 3 | Python | 1,800 | train_016.jsonl | 7f29a2332a99c99b781e781f2e339027 | 256 megabytes | ["5\n2 4 5 1 3"] | PASSED | n=int(input())
a=[0]+list(map(int,input().split()))
ans=0
for i in range(1,len(a)):
if a[i]==-1:
continue
j=i
while a[j]!=-1:
prev=j
j=a[j]
a[prev]=-1
ans+=1
if n%2==0:
#n even ans also even even number of swaps required
#3*n
if ans%2==0:
print("Petr"... | 1527608100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3\n0\n4"] | 29e84addbc88186bce40d68cf124f5da | NoteFirst test case considered in the statement.In the second test case integers $$$a$$$ and $$$b$$$ are already equal, so you don't need to perform any operations.In the third test case you have to apply the first, the second, the third and the fourth operation to $$$b$$$ ($$$b$$$ turns into $$$20 + 1 + 2 + 3 + 4 = 30... | You are given two integers $$$a$$$ and $$$b$$$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $$$1$$$; during the second operation you choose one of these numbers and increase it by $$$2$$$, and so on. You choose the number of these operations yo... | For each test case print one integer — the minimum numbers of operations required to make $$$a$$$ and $$$b$$$ equal. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9$$$). | standard output | standard input | Python 3 | Python | 1,500 | train_002.jsonl | 42ace6bb6ebe9fcab0d0631a21b2b0e3 | 256 megabytes | ["3\n1 3\n11 11\n30 20"] | PASSED | import sys
import collections
from collections import Counter
import itertools
import math
import timeit
#input = sys.stdin.readline
#########################
# imgur.com/Pkt7iIf.png #
#########################
def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p *... | 1576766100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1", "0", "3", "1"] | 6c9cbe714f8f594654ebc59b6059b30a | NoteIn the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.In the second example he can't make a single team.In the third example the coach can form three teams. For example, he can do this in the following way: The first group (of two people) and t... | There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams o... | Print the maximum number of teams of three people the coach can form. | The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i. | standard output | standard input | PyPy 3 | Python | 800 | train_008.jsonl | 9df1426cd3ea06597734b15fd3c9ed60 | 256 megabytes | ["4\n1 1 2 1", "2\n2 2", "7\n2 2 2 1 1 1 1", "3\n1 1 1"] | PASSED | n=int(input())
l=list(map(int,input().split()))
x=l.count(2)
y=l.count(1)
m=min(x,y)
c=(y-m)//3
print(c+m)
| 1513492500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["6\n11\n18"] | 1277cf54097813377bf37be445c06e7e | NoteConsider the second test case of the example. It looks like that:There are $$$11$$$ different simple paths: $$$[1, 2]$$$; $$$[2, 3]$$$; $$$[3, 4]$$$; $$$[2, 4]$$$; $$$[1, 2, 4]$$$; $$$[1, 2, 3]$$$; $$$[2, 3, 4]$$$; $$$[2, 4, 3]$$$; $$$[3, 2, 4]$$$; $$$[1, 2, 3, 4]$$$; $$$[1, 2, 4, 3]$$$. | You are given an undirected graph consisting of $$$n$$$ vertices and $$$n$$$ edges. It is guaranteed that the given graph is connected (i. e. it is possible to reach any vertex from any other vertex) and there are no self-loops and multiple edges in the graph.Your task is to calculate the number of simple paths of leng... | For each test case, print one integer: the number of simple paths of length at least $$$1$$$ in the given graph. Note that paths that differ only by their direction are considered the same (i. e. you have to calculate the number of undirected paths). | 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$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of vertices (and the number of edges) in the graph. The next $$... | standard output | standard input | PyPy 3 | Python | null | train_000.jsonl | 0b26e06b30873946c2a17d161ccba4a1 | 256 megabytes | ["3\n3\n1 2\n2 3\n1 3\n4\n1 2\n2 3\n3 4\n4 2\n5\n1 2\n2 3\n1 3\n2 5\n4 3"] | PASSED | from collections import deque
from sys import stdin, gettrace
if gettrace():
inputi = input
else:
def input():
return next(stdin)[:-1]
def inputi():
return stdin.buffer.readline()
def readGraph(n, m):
adj = [[] for _ in range(n)]
for _ in range(m):
u,v = map(int, inputi()... | 1606228500 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["0\n1\n999999999\n2"] | db0e6e67ca1184c5759fc488a3dff24e | null | Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The $$$k$$$-th layer of the triangle contains $$$k$$$ points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers $$$(r, c)$$$ ($$... | For each test case, output the minimum cost of a path passing through all points in the corresponding test case. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) is the number of test cases. Then $$$t$$$ test cases follow. Each test case begins with a line containing one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) is the number of points to visit. The second line contains $$$n$$$ numbers $$$r_1, r_2, \ldo... | standard output | standard input | PyPy 3 | Python | 2,000 | train_101.jsonl | 98fd731ad23200f3ceefd7a2f9b1f8a4 | 256 megabytes | ["4\n3\n1 4 2\n1 3 1\n2\n2 4\n2 3\n2\n1 1000000000\n1 1000000000\n4\n3 10 5 8\n2 5 2 4"] | PASSED | import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
n = int(input())
R = list(map(int, input().split()))
C = list(map(int, input().split()))
go = sorted([(1, 1)] + list(zip(R, C)))
ans = 0
for i in range(n):
c1 = go[i][0] - go[i][1] + 1
... | 1616682900 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
1 second | ["YES\n3 3 3", "NO"] | 0b204773f8d06362b7569bd82224b218 | null | We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value should be equal to qi. Your task is to find any interesting array of n elements or state that such array ... | If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print n integers a[1], a[2], ..., a[n] (0 ≤ a[i] < 230) decribing the interesting array. If there are multiple answers, print any of them. If the interesting array doesn't exist, print "NO" (without the quotes)... | The first line contains two integers n, m (1 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of elements in the array and the number of limits. Each of the next m lines contains three integers li, ri, qi (1 ≤ li ≤ ri ≤ n, 0 ≤ qi < 230) describing the i-th limit. | standard output | standard input | PyPy 3 | Python | 1,800 | train_073.jsonl | 56ff02deb056fa397f513143ff0e1027 | 256 megabytes | ["3 1\n1 3 3", "3 2\n1 3 3\n1 3 2"] | PASSED | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.wri... | 1414170000 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["4361", "60", "3250", "768500592"] | 8f34d2a146ff44ff4ea82fb6481d10e2 | NoteHere is the graph for the first example: Some maximum weight paths are: length $$$1$$$: edges $$$(1, 7)$$$ — weight $$$3$$$; length $$$2$$$: edges $$$(1, 2), (2, 3)$$$ — weight $$$1+10=11$$$; length $$$3$$$: edges $$$(1, 5), (5, 6), (6, 4)$$$ — weight $$$2+7+15=24$$$; length $$$4$$$: edges $$$(1, 5), (5, 6), ... | You are given a simple weighted connected undirected graph, consisting of $$$n$$$ vertices and $$$m$$$ edges.A path in the graph of length $$$k$$$ is a sequence of $$$k+1$$$ vertices $$$v_1, v_2, \dots, v_{k+1}$$$ such that for each $$$i$$$ $$$(1 \le i \le k)$$$ the edge $$$(v_i, v_{i+1})$$$ is present in the graph. A ... | Print a single integer — the sum of the weights of the paths from vertex $$$1$$$ of maximum weights of lengths $$$1, 2, \dots, q$$$ modulo $$$10^9+7$$$. | The first line contains a three integers $$$n$$$, $$$m$$$, $$$q$$$ ($$$2 \le n \le 2000$$$; $$$n - 1 \le m \le 2000$$$; $$$m \le q \le 10^9$$$) — the number of vertices in the graph, the number of edges in the graph and the number of lengths that should be included in the answer. Each of the next $$$m$$$ lines contains... | standard output | standard input | PyPy 2 | Python | 2,700 | train_024.jsonl | 1aa1977df1e9fafb49fafd64efeb470a | 256 megabytes | ["7 8 25\n1 2 1\n2 3 10\n3 4 2\n1 5 2\n5 6 7\n6 4 15\n5 3 1\n1 7 3", "2 1 5\n1 2 4", "15 15 23\n13 10 12\n11 14 12\n2 15 5\n4 10 8\n10 2 4\n10 7 5\n3 10 1\n5 6 11\n1 13 8\n9 15 4\n4 2 9\n11 15 1\n11 12 14\n10 8 12\n3 6 11", "5 10 10000000\n2 4 798\n1 5 824\n5 2 558\n4 1 288\n3 4 1890\n3 1 134\n2 3 1485\n4 5 284\n3 5 10... | PASSED | import sys
range = xrange
input = raw_input
n,m,q = [int(x) for x in input().split()]
V = []
W = []
coupl = [[] for _ in range(n)]
for _ in range(m):
a,b,w = [int(x) - 1 for x in input().split()]
w += 1
W.append(w)
eind = len(V)
V.append(b)
V.append(a)
coupl[a].append(eind)
coupl[b].a... | 1591886100 | [
"geometry",
"graphs"
] | [
0,
1,
1,
0,
0,
0,
0,
0
] | |
1 second | ["0\n1\n1\n3\n88005553"] | 8e4194b356500cdaacca2b1d49c2affb | NoteThe first interesting number is equal to $$$9$$$. | Let's define $$$S(x)$$$ to be the sum of digits of number $$$x$$$ written in decimal system. For example, $$$S(5) = 5$$$, $$$S(10) = 1$$$, $$$S(322) = 7$$$.We will call an integer $$$x$$$ interesting if $$$S(x + 1) < S(x)$$$. In each test you will be given one integer $$$n$$$. Your task is to calculate the number of... | Print $$$t$$$ integers, the $$$i$$$-th should be the answer for the $$$i$$$-th test case. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — number of test cases. Then $$$t$$$ lines follow, the $$$i$$$-th line contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) for the $$$i$$$-th test case. | standard output | standard input | Python 3 | Python | 800 | train_105.jsonl | dc24dfb920ba16f5194cb37f6ced2e86 | 256 megabytes | ["5\n1\n9\n10\n34\n880055535"] | PASSED | t = int(input())
vet= []
for _ in range(0,t):
res = 0
n = int(input())
if n >=10:
res = int(n/10)
n = int(n%10)
if n >=9:
res +=1
vet.append(res)
print(*vet, sep='\n')
| 1626964500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["YES\n.#.#\n#.#.\nNO\nYES\n....#\n...#.\n..#..\n.#...\n#....\nYES\n#..\n.#.\n#.#\n..."] | 2bd60c4d46c9af426f1a700c8749cdde | null | Monocarp is playing Minecraft and wants to build a wall of cacti. He wants to build it on a field of sand of the size of $$$n \times m$$$ cells. Initially, there are cacti in some cells of the field. Note that, in Minecraft, cacti cannot grow on cells adjacent to each other by side — and the initial field meets this re... | For each test case, print NO in the first line if it is impossible to build a cactus wall without breaking the rules. Otherwise, print YES in the first line, then print $$$n$$$ lines of $$$m$$$ characters each — the field itself, where the $$$j$$$-th character of the $$$i$$$-th line is equal to '#', if there is a cactu... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 2 \cdot 10^5$$$; $$$n \times m \le 4 \cdot 10^5$$$) — the number of rows and columns, respectively. Then $$$n$$$ rows follow, $$... | standard output | standard input | PyPy 3-64 | Python | 2,400 | train_090.jsonl | 9befd4b760b1741faf21aaf7ff4c7aa9 | 256 megabytes | ["4\n\n2 4\n\n.#..\n\n..#.\n\n3 3\n\n#.#\n\n...\n\n.#.\n\n5 5\n\n.....\n\n.....\n\n.....\n\n.....\n\n.....\n\n4 3\n\n#..\n\n.#.\n\n#.#\n\n..."] | PASSED | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return u * m + v
def g(u):
return u // m, u % m
def bfs():
dist = [inf] * l
q, q0 = [], []
k, k0 = 0, 0
for i in range(0, l, m):
if not ng[i]:
dist[i] = s[i]
... | 1666276500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["Yes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo"] | f6b7ad10382135b293bd3f2f3257d4d3 | NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substri... | Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in... | For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line out... | First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case de... | standard output | standard input | PyPy 2 | Python | 1,500 | train_008.jsonl | 43ae8fd04fa92cd777368b0f479adf68 | 512 megabytes | ["6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba"] | PASSED | # raw_input()
# map(int,raw_input().split())
# for _ in xrange(input()):
# print "Case #"+str(_+1)+": "+
if __name__ == "__main__":
for _ in xrange(input()):
x=list('abacaba')
n=input()
s=list(raw_input())
q=sum(s[i:i+7]==x for i in xrange(n-6))
if q>1:
print 'NO'... | 1595149200 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["YES\nYES\nYES\nNO"] | 1c597da89880e87ffe791dd6b9fb2ac7 | NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal: Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$. Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations... | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$? | For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower). | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ in... | standard output | standard input | PyPy 3 | Python | 800 | train_109.jsonl | 4f0316775f4affe3c43f6ae30e56a757 | 256 megabytes | ["4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3"] | PASSED | for _ in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
for _ in range(n):
for i in range(n-1, 0, -1):
q = a[i]%a[i-1]
if q == 0 : q = a[i-1]
a[i] = q
if len(set(a)) == 1 : print("YES")
else : print("NO") | 1657982100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["PATH\n4 \n1 5 3 6\nPAIRING\n2\n1 6\n2 4\nPAIRING\n3\n1 8\n2 5\n4 10\nPAIRING\n4\n1 7\n2 9\n3 11\n4 5"] | 378f944b6839376dc71d85059d8efd2f | NoteThe path outputted in the first case is the following. The pairing outputted in the second case is the following. Here is an invalid pairing for the same graph — the subgraph $$$\{1,3,4,5\}$$$ has $$$3$$$ edges. Here is the pairing outputted in the third case. It's valid because — The subgraph $$$\{1,8,2... | You have a simple and connected undirected graph consisting of $$$n$$$ nodes and $$$m$$$ edges.Consider any way to pair some subset of these $$$n$$$ nodes such that no node is present in more than one pair. This pairing is valid if for every pair of pairs, the induced subgraph containing all $$$4$$$ nodes, two from eac... | For each test case, the output format is as follows. If you have found a pairing, in the first line output "PAIRING" (without quotes). Then, output $$$k$$$ ($$$\lceil \frac{n}{2} \rceil \le 2\cdot k \le n$$$), the number of pairs in your pairing. Then, in each of the next $$$k$$$ lines, output $$$2$$$ integers $$$... | 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 $$$2$$$ integers $$$n, m$$$ ($$$2 \le n \le 5\cdot 10^5$$$, $$$1 \le m \le 10^6$$$), denoting the number of nodes an... | standard output | standard input | PyPy 3 | Python | 2,600 | train_038.jsonl | 56cb239809abb94829712810f4e67a79 | 256 megabytes | ["4\n6 5\n1 4\n2 5\n3 6\n1 5\n3 5\n6 5\n1 4\n2 5\n3 6\n1 5\n3 5\n12 14\n1 2\n2 3\n3 4\n4 1\n1 5\n1 12\n2 6\n2 7\n3 8\n3 9\n4 10\n4 11\n2 4\n1 3\n12 14\n1 2\n2 3\n3 4\n4 1\n1 5\n1 12\n2 6\n2 7\n3 8\n3 9\n4 10\n4 11\n2 4\n1 3"] | PASSED | # Fast IO (only use in integer input)
import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
n,m = map(int,input().split())
connectionList = []
for _ in range(n):
connectionList.append([])
for _ in range(m):
u,v = map(int,input().spli... | 1596983700 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["8", "6", "0"] | 9dc500c1f7fe621351c1d5359e71fda4 | NoteThere are four collisions $$$(1,2,T-0.5)$$$, $$$(1,3,T-1)$$$, $$$(2,4,T+1)$$$, $$$(3,4,T+0.5)$$$, where $$$(u,v,t)$$$ means a collision happened between ghosts $$$u$$$ and $$$v$$$ at moment $$$t$$$. At each collision, each ghost gained one experience point, this means that $$$GX = 4 \cdot 2 = 8$$$.In the second tes... | Ghosts live in harmony and peace, they travel the space without any purpose other than scare whoever stands in their way.There are $$$n$$$ ghosts in the universe, they move in the $$$OXY$$$ plane, each one of them has its own velocity that does not change in time: $$$\overrightarrow{V} = V_{x}\overrightarrow{i} + V_{y}... | Output one line: experience index of the ghost kind $$$GX$$$ in the indefinite future. | The first line contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \leq n \leq 200000$$$, $$$1 \leq |a| \leq 10^9$$$, $$$0 \le |b| \le 10^9$$$) — the number of ghosts in the universe and the parameters of the straight line. Each of the next $$$n$$$ lines contains three integers $$$x_i$$$, $$$V_{xi}$$$, $$$V_{yi}... | standard output | standard input | Python 3 | Python | 2,000 | train_071.jsonl | ea12c670bf1e4ff6452ef6f314d7d3fa | 256 megabytes | ["4 1 1\n1 -1 -1\n2 1 1\n3 1 1\n4 -1 -1", "3 1 0\n-1 1 0\n0 0 -1\n1 -1 -2", "3 1 0\n0 0 0\n1 0 0\n2 0 0"] | PASSED | import sys
input = sys.stdin.readline
N,A,B = map(int,input().split())
POS = {}
for _ in range(N):
x,vx,vy = map(int,input().split())
v = (vx,vy)
score = vy - A*vx
if score not in POS:
POS[score] = {}
if v not in POS[score]:
POS[score][v] = 0
POS[score][v] += 1
COL = 0
for x in POS:
size = sum([POS[x][v]... | 1525183500 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["166666673", "500000010"] | 1d01c01bec67572f9c1827ffabcc9793 | NoteLet's describe all possible values of $$$x$$$ for the first sample: $$$[1, 1, 1]$$$: $$$B(x) = 1$$$, $$$B^2(x) = 1$$$; $$$[1, 1, 2]$$$: $$$B(x) = 2$$$, $$$B^2(x) = 4$$$; $$$[1, 1, 3]$$$: $$$B(x) = 2$$$, $$$B^2(x) = 4$$$; $$$[1, 2, 1]$$$: $$$B(x) = 3$$$, $$$B^2(x) = 9$$$; $$$[1, 2, 2]$$$: $$$B(x) = 2$$$, $$$B^... | Let $$$x$$$ be an array of integers $$$x = [x_1, x_2, \dots, x_n]$$$. Let's define $$$B(x)$$$ as a minimal size of a partition of $$$x$$$ into subsegments such that all elements in each subsegment are equal. For example, $$$B([3, 3, 6, 1, 6, 6, 6]) = 4$$$ using next partition: $$$[3, 3\ |\ 6\ |\ 1\ |\ 6, 6, 6]$$$.Now y... | Print the single integer — $$$E((B(x))^2)$$$ as $$$P \cdot Q^{-1} \mod 10^9 + 7$$$. | The first line contains the single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the size of the array $$$x$$$. The second line contains $$$n$$$ integers $$$l_1, l_2, \dots, l_n$$$ ($$$1 \le l_i \le 10^9$$$). The third line contains $$$n$$$ integers $$$r_1, r_2, \dots, r_n$$$ ($$$l_i \le r_i \le 10^9$$$). | standard output | standard input | PyPy 3 | Python | 2,500 | train_001.jsonl | d358b6e05c476041e40eb84a023596cc | 256 megabytes | ["3\n1 1 1\n1 2 3", "3\n3 4 5\n4 5 6"] | PASSED | mod = 10 ** 9 + 7
def pow_(x, y, p) :
res = 1
x = x % p
if x == 0:
return 0
while y > 0:
if (y & 1) == 1:
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
def reverse(x, mod):
return pow_(x, mod-2... | 1561905900 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
2 seconds | ["1 1 3", "1 2", "1"] | cadff0864835854f4f1e0234f2fd3edf | NoteIn the first sample the answer may be achieved this way: Append GCD$$$(1, 2, 3) = 1$$$, remove $$$2$$$. Append GCD$$$(1, 3) = 1$$$, remove $$$1$$$. Append GCD$$$(3) = 3$$$, remove $$$3$$$. We get the sequence $$$[1, 1, 3]$$$ as the result. | Let's call the following process a transformation of a sequence of length $$$n$$$.If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbitrary element from the sequence. Thus, when the process ends, we have a s... | Output $$$n$$$ integers — the lexicographically maximum result of the transformation. | The first and only line of input contains one integer $$$n$$$ ($$$1\le n\le 10^6$$$). | standard output | standard input | Python 2 | Python | 1,600 | train_020.jsonl | 7347168d9576696fc6bb6f222daa672c | 256 megabytes | ["3", "2", "1"] | PASSED | N = input()
ls = range(1,N+1)
while len(ls) > 3:
nls = ls[1::2]
for i in xrange(len(ls) - len(nls)):
print ls[0],
ls = nls
if len(ls)==3:
print ls[0], ls[0], ls[2]
elif len(ls)==2:
print ls[0], ls[1]
else:
print ls[0]
| 1538750100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2\n3\n-1"] | 36099a612ec5bbec1b95f2941e759c00 | NoteIn the first query you can deal the first blow (after that the number of heads changes to $$$10 - 6 + 3 = 7$$$), and then deal the second blow.In the second query you just deal the first blow three times, and Zmei is defeated. In third query you can not defeat Zmei Gorynich. Maybe it's better to convince it to stop... | You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads! Initially Zmei Gorynich has $$$x$$$ heads. You can deal $$$n$$$ types of blows. If you deal a blow of the $$$i$$$-th type, you decrease the number of Gorynich's heads by $$$min(d_i, curX)$$$, t... | For each query print the minimum number of blows you have to deal to defeat Zmei Gorynich. If Zmei Gorynuch cannot be defeated print $$$-1$$$. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) – the number of queries. The first line of each query contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 100$$$, $$$1 \le x \le 10^9$$$) — the number of possible types of blows and the number of heads Zmei initially has, respectively. The follow... | standard output | standard input | PyPy 3 | Python | 1,600 | train_005.jsonl | 51a68eedaaf699575a5c415c0a395a8f | 256 megabytes | ["3\n3 10\n6 3\n8 2\n1 4\n4 10\n4 1\n3 2\n2 6\n1 100\n2 15\n10 11\n14 100"] | PASSED | for i in range(int(input())):
n,x = map(int,input().split())
mx = 0
mind = 1000000000000000000
d1 = 0
for i in range(n):
d,h = map(int,input().split())
if d - h > mx:
mx = d-h
d1 = max(d1,d)
import math
d = d1
if x <= d1:
... | 1567694100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["aaaacbb\nabccc\nbcdis\naaaaacbbdrr\ndddddddddddd\nbbc\nac"] | 419ef3579fe142c295ec4d89ee7becfc | NoteIn the first test case, both aaaabbc and aaaabcb are lexicographically smaller than aaaacbb, but they contain abc as a subsequence.In the second test case, abccc is the smallest permutation of cccba and does not contain acb as a subsequence.In the third test case, bcdis is the smallest permutation of dbsic and does... | You are given strings $$$S$$$ and $$$T$$$, consisting of lowercase English letters. It is guaranteed that $$$T$$$ is a permutation of the string abc. Find string $$$S'$$$, the lexicographically smallest permutation of $$$S$$$ such that $$$T$$$ is not a subsequence of $$$S'$$$.String $$$a$$$ is a permutation of string $... | For each test case, output a single string $$$S'$$$, the lexicographically smallest permutation of $$$S$$$ such that $$$T$$$ is not a subsequence of $$$S'$$$. | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a string $$$S$$$ ($$$1 \le |S| \le 100$$$), consisting of lowercase English letters. The second l... | standard output | standard input | Python 3 | Python | 800 | train_100.jsonl | 5fcc132f12fbb7038f9009b0b4f2a589 | 256 megabytes | ["7\nabacaba\nabc\ncccba\nacb\ndbsic\nbac\nabracadabra\nabc\ndddddddddddd\ncba\nbbc\nabc\nac\nabc"] | PASSED | import sys;input=sys.stdin.readline
for _ in range(int(input())):
a=sorted(input().strip())
t=input().strip()
one=a.count(t[0])
two=a.count(t[1])
thr=a.count(t[2])
if one>0 and two>0 and thr>0:
if t[0]=='a':print(t[0]*one+t[2]*thr+t[1]*two,end='')
else:print('a'*a.count(... | 1639661700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["1\n3\n0\n0\n1\n3"] | b18dac401b655c06bee331e71eb3e4de | NoteIn the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the re... | You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes... | Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into. | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respect... | standard output | standard input | PyPy 3 | Python | 1,200 | train_004.jsonl | 82a54b80089295636bb6ec8e10302853 | 256 megabytes | ["6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1"] | PASSED | #! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
def numTeam(c, m, x):
cmMin = min(c, m)
# max(c,m) >= x >= min(c,m): Somente min(c,n) times com 1 de cada
if x >= cmMin:
return cmMin
# max(c,m) >= min(c,m) > x: Times podem ter 2 c ou 2 m
else:
return min((c+m+x)//3,... | 1568903700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nYES\nNO\nYES\nNO\nNO\nYES"] | 2d011ba7eaa16642d77dade98966b54a | NoteIn the first test case: Initially $$$s_1 = \mathtt{cbc}$$$, $$$s_2 = \mathtt{aba}$$$. Operation with $$$k = 1$$$, after the operation $$$s_1 = \mathtt{abc}$$$, $$$s_2 = \mathtt{abc}$$$. In the second test case: Initially $$$s_1 = \mathtt{abcaa}$$$, $$$s_2 = \mathtt{cbabb}$$$. Operation with $$$k = 2$$$, after t... | You have two strings $$$s_1$$$ and $$$s_2$$$ of length $$$n$$$, consisting of lowercase English letters. You can perform the following operation any (possibly zero) number of times: Choose a positive integer $$$1 \leq k \leq n$$$. Swap the prefix of the string $$$s_1$$$ and the suffix of the string $$$s_2$$$ of leng... | For each test case, print "YES" if it is possible to make the strings equal, and "NO" otherwise. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then the test cases follow. Each test case consists of three lines. The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the strings $$$s_1$$$ and $$$s_2$$$. The second line contai... | standard output | standard input | PyPy 3-64 | Python | 2,200 | train_091.jsonl | 66cd98d4dc6d9d24a1d8e5aef40b1341 | 256 megabytes | ["7\n\n3\n\ncbc\n\naba\n\n5\n\nabcaa\n\ncbabb\n\n5\n\nabcaa\n\ncbabz\n\n1\n\na\n\na\n\n1\n\na\n\nb\n\n6\n\nabadaa\n\nadaaba\n\n8\n\nabcabdaa\n\nadabcaba"] | PASSED | for _ in range(int(input())):
n = int(input())
w1 = input()
w2 = input()[::-1]
pairs = {}
odd = 0
for x in range(n):
tmp_l = sorted([w1[x], w2[x]])
tmp = f'{tmp_l[0]}{tmp_l[1]}'
if tmp not in pairs:
pairs[tmp] = 1
else:
pairs[tm... | 1664116500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["6.5", "20.0"] | 9df3a94dfa537cabdc52388a771cd24f | NoteIn the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for . Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for . Thus, after four minutes the chicken will be cooked for . Before the fifth minute Julia will turn on... | Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The sto... | Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if . | The single line contains three integers k, d and t (1 ≤ k, d, t ≤ 1018). | standard output | standard input | Python 3 | Python | 1,700 | train_004.jsonl | 9c599dba93945d3720cdb2ec162ef9d1 | 256 megabytes | ["3 2 6", "4 2 20"] | PASSED | import math
k, d, t = map(int, input().split())
if d >= k:
off = d - k
else:
off = math.ceil(k / d) * d - k
times = t // (off / 2 + k)
t1 = times * (off + k)
t2 = t % (off / 2 + k)
if t2 > k:
t2 = k + (t2 - k) * 2
ans = t1 + t2
print (ans) | 1519574700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["9.0000000000", "10.0000000000", "28964.2857142857"] | 838e643a978adbeed791a24ac1046ab5 | NoteIn the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. | It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days!When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept ... | Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. | The first line contains two integer numbers n and k (1 ≤ k ≤ n ≤ 2·105). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105). | standard output | standard input | Python 3 | Python | 1,300 | train_000.jsonl | b8d62886bdafce7fc2f7705d3d221e04 | 256 megabytes | ["3 2\n3 4 7", "1 1\n10", "8 2\n1 2 4 100000 123 456 789 1"] | PASSED | a,b=map(int,input().split())
x=list(map(int,input().split()))
y=[a-b+1]*a
z=list(range(1,a+1))
w=z[::-1]
c=[]
for i in range(a):
c.append(min(y[i],z[i],w[i],b))
s=0
for i in range(a):
s+=c[i]*x[i]
print(s/(a-b+1))
| 1494860700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2 2", "1 4", "2 4", "0 1"] | 63eb7dc9077b88df505e52fa4bba5851 | NoteIn the first example, FJ can line up the cows as follows to achieve $$$2$$$ sleeping cows: Cow $$$1$$$ is lined up on the left side and cow $$$2$$$ is lined up on the right side. Cow $$$2$$$ is lined up on the left side and cow $$$1$$$ is lined up on the right side. In the second example, FJ can line up the cows... | After a successful year of milk production, Farmer John is rewarding his cows with their favorite treat: tasty grass!On the field, there is a row of $$$n$$$ units of grass, each with a sweetness $$$s_i$$$. Farmer John has $$$m$$$ cows, each with a favorite sweetness $$$f_i$$$ and a hunger value $$$h_i$$$. He would like... | Output two integers — the maximum number of sleeping cows that can result and the number of ways modulo $$$10^9+7$$$. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 5000$$$, $$$1 \le m \le 5000$$$) — the number of units of grass and the number of cows. The second line contains $$$n$$$ integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le n$$$) — the sweetness values of the grass. The $$$i$$$-th of the fol... | standard output | standard input | PyPy 3 | Python | 2,500 | train_077.jsonl | 4accc91231dfe9fe0ff7551f1ee6d62b | 256 megabytes | ["5 2\n1 1 1 1 1\n1 2\n1 3", "5 2\n1 1 1 1 1\n1 2\n1 4", "3 2\n2 3 2\n3 1\n2 1", "5 1\n1 1 1 1 1\n2 5"] | PASSED | from sys import stdin, stdout
import bisect
at_dist = []
mx = []
cow = []
sums = []
m = []
res_p = 0
res_r = 1
def modInverse(a, m) :
return power(a, m - 2, m)
# To compute x^y under modulo m
def power(x, y, m) :
if (y == 0) :
return 1
p = power(x, y // 2, m) % m
p... | 1581953700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3\n0\n0\n1\n999999999\n381621773"] | b69170c8377623beb66db4706a02ffc6 | NoteFor the test case of the example, the $$$3$$$ possible ways to distribute candies are: $$$a=6$$$, $$$b=1$$$; $$$a=5$$$, $$$b=2$$$; $$$a=4$$$, $$$b=3$$$. | There are two sisters Alice and Betty. You have $$$n$$$ candies. You want to distribute these $$$n$$$ candies between two sisters in such a way that: Alice will get $$$a$$$ ($$$a > 0$$$) candies; Betty will get $$$b$$$ ($$$b > 0$$$) candies; each sister will get some integer number of candies; Alice will get ... | For each test case, print the answer — the number of ways to distribute exactly $$$n$$$ candies between two sisters in a way described in the problem statement. If there is no way to satisfy all the conditions, print $$$0$$$. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of a test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^9$$$) — the number of candies you have. | standard output | standard input | Python 3 | Python | 800 | train_030.jsonl | 366761afa14b08a3d90f95dc723f4c66 | 256 megabytes | ["6\n7\n1\n2\n3\n2000000000\n763243547"] | PASSED | from math import ceil
T=int(input())
while T>0:
A=int(input())
B=ceil(A-A/2-1)
print(B)
T-=1 | 1586788500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3 5\n\n3 3\n\n3 4\n\n5 5"] | c46d1a87c6a6540d573c0391e845e1db | NoteIn the first sample, the train was initially at the station $$$5$$$, after the first application of the gadget it did not move, after the second application it moved to the station $$$3$$$, and after the third application moved again to the station $$$5$$$. | This is an interactive problem.In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrol... | null | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^{18}$$$, $$$0 \leq k \leq 10$$$) — the number of stations and the maximum number of stations the train can move between two applications of the gadget. | standard output | standard input | Python 3 | Python | 2,100 | train_003.jsonl | 3542385115c63e21e620f9879ba57b65 | 512 megabytes | ["10 2\n\nYes\n\nNo\n\nYes\n\nYes"] | PASSED | #
import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)
def getIntList():
return list(map(int, input().split()))
try :
#raise ModuleNotFoundError
import numpy
def dprint(*args, **kwargs):
print(*args, **kwargs, file=sys.stderr)
dprint('debug mode')
except ... | 1536165300 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
2 seconds | ["4\n9\n5"] | 33e9714f22b603f002d02ef42835ff57 | NoteFor the first test case, one possibility for Victor's original grid is:$$$1$$$$$$3$$$$$$2$$$$$$4$$$For the second test case, one possibility for Victor's original grid is:$$$3$$$$$$8$$$$$$8$$$$$$5$$$$$$9$$$$$$5$$$$$$5$$$$$$1$$$$$$5$$$$$$5$$$$$$9$$$$$$9$$$$$$8$$$$$$4$$$$$$2$$$$$$9$$$For the third test case, one poss... | Note: The XOR-sum of set $$$\{s_1,s_2,\ldots,s_m\}$$$ is defined as $$$s_1 \oplus s_2 \oplus \ldots \oplus s_m$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.After almost winning IOI, Victor bought himself an $$$n\times n$$$ grid containing integers in each cell. $$$n$$$ is an even integer. The integer in the... | For each test case, output a single integer — the XOR-sum of the whole grid. | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single even integer $$$n$$$ ($$$2 \leq n \leq 1000$$$) — the size of the grid. Then follows $$$n$$$ lines, each containing ... | standard output | standard input | PyPy 3-64 | Python | 2,300 | train_093.jsonl | d174af94b5f7029e310c1ba4e3fa85cf | 256 megabytes | ["3\n2\n1 5\n5 1\n4\n1 14 8 9\n3 1 5 9\n4 13 11 1\n1 15 4 11\n4\n2 4 1 6\n3 7 3 10\n15 9 4 2\n12 7 15 1"] | PASSED | ''' E. Grid Xor
https://codeforces.com/contest/1629/problem/E
'''
import io, os, sys
input = sys.stdin.readline
output = sys.stdout.write
DEBUG = os.environ.get('debug') not in [None, '0']
if DEBUG:
from inspect import currentframe, getframeinfo
from re import search
def debug(*args):
if not DEBUG: ret... | 1642862100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1 2 4 3 6 7 5", "1 2 3 4 5"] | a67ea891cd6084ceeaace8894cf18e60 | NoteIn the first sample, the swap needed to obtain the prettiest permutation is: (p1, p7).In the second sample, the swaps needed to obtain the prettiest permutation is (p1, p3), (p4, p5), (p3, p4). A permutation p is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them does... | User ainta has a permutation p1, p2, ..., pn. As the New Year is coming, he wants to make his permutation as pretty as possible.Permutation a1, a2, ..., an is prettier than permutation b1, b2, ..., bn, if and only if there exists an integer k (1 ≤ k ≤ n) where a1 = b1, a2 = b2, ..., ak - 1 = bk - 1 and ak < bk all h... | In the first and only line, print n space-separated integers, describing the prettiest permutation that can be obtained. | The first line contains an integer n (1 ≤ n ≤ 300) — the size of the permutation p. The second line contains n space-separated integers p1, p2, ..., pn — the permutation p that user ainta has. Each integer between 1 and n occurs exactly once in the given permutation. Next n lines describe the matrix A. The i-th line co... | standard output | standard input | Python 2 | Python | 1,600 | train_023.jsonl | 01de2d8acf297a6644650db0a0fab976 | 256 megabytes | ["7\n5 2 4 3 6 7 1\n0001001\n0000000\n0000010\n1000001\n0000000\n0010000\n1001000", "5\n4 2 1 5 3\n00100\n00011\n10010\n01101\n01010"] | PASSED | n = input()
A = map(int, raw_input().split())
M = [raw_input() for ii in range(n)]
seen = [False for ii in range(n)]
vi = []
def dfs(id):
seen[id] = True
vi.append(id)
for ii in range(n):
if M[id][ii] == '1' and seen[ii] == False:
dfs(ii)
for ii in range(0,n):
if seen[ii] == False:
vi = []
dfs(ii)
k =... | 1419951600 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
2 seconds | ["1 2", "2 4", "2 5", "2 7"] | 4ebbda2fc1a260e9827205a25addd9c4 | NoteIn example 1, there are three good substrings ("b", "b", and "bb"). One of them has even length and two of them have odd length.In example 2, there are six good substrings (i.e. "b", "a", "a", "b", "aa", "baab"). Two of them have even length and four of them have odd length.In example 3, there are seven good substr... | We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba".Given a string, you have to find two values: the number of good substrings of even length; the number of good substrings o... | Print two space-separated integers: the number of good substrings of even length and the number of good substrings of odd length. | The first line of the input contains a single string of length n (1 ≤ n ≤ 105). Each character of the string will be either 'a' or 'b'. | standard output | standard input | Python 3 | Python | 2,000 | train_002.jsonl | 04d8f0a1df0fda43c203f00183d2ff14 | 256 megabytes | ["bb", "baab", "babb", "babaa"] | PASSED | s = input()
a = []
for c in s:
a.append(ord(c) - ord('a'))
cnt = [[0, 0], [0, 0]]
ans = [0, 0]
for i in range(len(a)):
cnt[a[i]][i % 2] += 1
ans[0] += cnt[a[i]][i % 2]
ans[1] += cnt[a[i]][1 - i % 2]
print(ans[1], ans[0]) | 1406215800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["1 1 0", "10 10 4 0 0", "276 276 132 36 0 0 0"] | 6f58b157c875651127af682f34ca794c | NoteExample $$$1$$$: there are two possible trees: with edges $$$(1-2)$$$, and $$$(1-3)$$$ — here the centroid is $$$1$$$; and with edges $$$(1-2)$$$, and $$$(2-3)$$$ — here the centroid is $$$2$$$. So the answer is $$$1, 1, 0$$$.Example $$$2$$$: there are $$$24$$$ possible trees, for example with edges $$$(1-2)$$$, $$... | Consider every tree (connected undirected acyclic graph) with $$$n$$$ vertices ($$$n$$$ is odd, vertices numbered from $$$1$$$ to $$$n$$$), and for each $$$2 \le i \le n$$$ the $$$i$$$-th vertex is adjacent to exactly one vertex with a smaller index.For each $$$i$$$ ($$$1 \le i \le n$$$) calculate the number of trees f... | Print $$$n$$$ integers in a single line, the $$$i$$$-th integer is the answer for the $$$i$$$-th vertex (modulo $$$998\,244\,353$$$). | The first line contains an odd integer $$$n$$$ ($$$3 \le n < 2 \cdot 10^5$$$, $$$n$$$ is odd) — the number of the vertices in the tree. | standard output | standard input | PyPy 3-64 | Python | 3,000 | train_097.jsonl | 2bd4cb2ed00303e871e5f6c57e91a144 | 256 megabytes | ["3", "5", "7"] | PASSED |
def divisors(M):
d=[]
i=1
while M>=i**2:
if M%i==0:
d.append(i)
if i**2!=M:
d.append(M//i)
i=i+1
return d
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)... | 1650378900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nNO\nYES"] | 6ca98e655007bfb86f1039c9f096557e | NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformat... | You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 < i_2 < \ldots < i_k \le n$$$. Add $$... | For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower). | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ ... | standard output | standard input | PyPy 3 | Python | 900 | train_091.jsonl | 1461f1548d849b9936199c079f040753 | 256 megabytes | ["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"] | PASSED | import sys
t = int(sys.stdin.readline())
for _ in range(t):
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
newa = sorted(a)
newb = sorted(b)
ans = "YES"
for i in range(n):
if (newa[i] != ne... | 1636869900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3", "0\n2"] | d7ffedb180378b3ab70e5f05c79545f5 | NoteIn the first example, child 1 is waiting for toy 2, which child 2 has, while child 2 is waiting for top 3, which child 3 has. When child 3 makes his last request, the toy he requests is held by child 1. Each of the three children is waiting for a toy held by another child and no one is playing, so all the three wil... | Sagheer is working at a kindergarten. There are n children and m different toys. These children use well-defined protocols for playing with the toys: Each child has a lovely set of toys that he loves to play with. He requests the toys one after another at distinct moments of time. A child starts playing if and only if... | For each query, print on a single line the number of children who will start crying when child x makes his last request for toy y. Please answer all queries independent of each other. | The first line contains four integers n, m, k, q (1 ≤ n, m, k, q ≤ 105) — the number of children, toys, scenario requests and queries. Each of the next k lines contains two integers a, b (1 ≤ a ≤ n and 1 ≤ b ≤ m) — a scenario request meaning child a requests toy b. The requests are given in the order they are made by c... | standard output | standard input | PyPy 3 | Python | 2,700 | train_037.jsonl | e3d87d652482d805ba50dd86ac041a93 | 256 megabytes | ["3 3 5 1\n1 1\n2 2\n3 3\n1 2\n2 3\n3 1", "5 4 7 2\n1 1\n2 2\n2 1\n5 1\n3 3\n4 4\n4 1\n5 3\n5 4"] | PASSED | from sys import stdin
from sys import stdout
n, m, k, q = map(int, stdin.readline().split())
d = [None for i in range(m)]
roots = set(range(n))
matrix = [[] for i in range(n)]
for i in range(k):
x, y = map(int, stdin.readline().split())
if d[y - 1] is None:
d[y - 1] = x - 1
else:
matrix[d[y... | 1496326500 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
4 seconds | ["YES\n4\n4 3 1\n2 3 1\n2 5 2\n1 5 2", "NO"] | f236c4110a973d1c9f63cbbcc74b9e0b | NoteConsider the first example. After the first move the locations of stones is $$$[2, 2, 6, 5, 9]$$$. After the second move the locations of stones is $$$[2, 3, 5, 5, 9]$$$. After the third move the locations of stones is $$$[2, 5, 5, 5, 7]$$$. After the last move the locations of stones is $$$[4, 5, 5, 5, 5]$$$.... | There are $$$n$$$ stones arranged on an axis. Initially the $$$i$$$-th stone is located at the coordinate $$$s_i$$$. There may be more than one stone in a single place.You can perform zero or more operations of the following type: take two stones with indices $$$i$$$ and $$$j$$$ so that $$$s_i \leq s_j$$$, choose an ... | If it is impossible to move the stones this way, print "NO". Otherwise, on the first line print "YES", on the second line print the number of operations $$$m$$$ ($$$0 \le m \le 5 \cdot n$$$) required. You don't have to minimize the number of operations. Then print $$$m$$$ lines, each containing integers $$$i, j, d$$$ (... | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) – the number of stones. The second line contains integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le 10^9$$$) — the initial positions of the stones. The second line contains integers $$$t_1, t_2, \ldots, t_n$$$ ($$$1 \le t_i \le 10^9$$... | standard output | standard input | Python 3 | Python | 2,300 | train_053.jsonl | f0457f67d945d41dd13fd78a533db099 | 256 megabytes | ["5\n2 2 7 4 9\n5 4 5 5 5", "3\n1 5 10\n3 5 7"] | PASSED | from collections import namedtuple
Stone = namedtuple('Stone', ['s', 'i'])
def debug(*args, **kwargs):
import sys
#print(*args, *('{}={}'.format(k, v) for k, v in kwargs.items()), sep='; ', file=sys.stderr)
def solve(n, s, t):
#debug(s=s, t=t)
s = list(map(lambda s_i: Stone(s_i[1], s_i[0]), enumer... | 1559399700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["0\n3\n1\n3\n2"] | ab6fefc6c15d4647bc601f1f9db21d3f | NoteIn the first test case, it is already given a number divisible by $$$25$$$.In the second test case, we can remove the digits $$$1$$$, $$$3$$$, and $$$4$$$ to get the number $$$75$$$.In the third test case, it's enough to remove the last digit to get the number $$$325$$$.In the fourth test case, we can remove the th... | It is given a positive integer $$$n$$$. In $$$1$$$ move, one can select any single digit and remove it (i.e. one selects some position in the number and removes the digit located at this position). The operation cannot be performed if only one digit remains. If the resulting number contains leading zeroes, they are aut... | For each test case output on a separate line an integer $$$k$$$ ($$$k \ge 0$$$) — the minimum number of steps to get a number such that it is divisible by $$$25$$$ and positive. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing one integer $$$n$$$ ($$$25 \le n \le 10^{18}$$$). It is guaranteed that, for each $$$n$$$ occurring in the input, the answer exists. It is guara... | standard output | standard input | Python 3 | Python | 900 | train_093.jsonl | 5fddd654b95c203f43995f4b1c378d58 | 256 megabytes | ["5\n100\n71345\n3259\n50555\n2050047"] | PASSED | for _ in range(int(input())):
s = input()
count = 0
for i in range(len(s) - 1):
for j in range(i+1, len(s)):
if int(s[i]+s[j]) % 25 == 0:
count = len(s)-i-2
print(count) | 1634135700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2", "1"] | 8d2845c33645ac45d4d37f9493b0c380 | NoteExplanation to the first and second samples from the statement, respectively: | There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can de... | Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. | The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed tha... | standard output | standard input | Python 3 | Python | 1,400 | train_002.jsonl | be3888292b854b243871809a1d2f5396 | 256 megabytes | ["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0"] | PASSED | num_coor = input().split()
num_storm = int(num_coor[0])
han_coor = [int(num_coor[1]), int(num_coor[2])]
l = []
for i in range(num_storm):
temp = tuple([int(h) for h in input().split()])
l.append(temp)
for f in range(len(l)):
temp = l[f]
if temp[0] == han_coor[0]:
l[f] = "banana"
else:
... | 1423931400 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["a", "aab", "aaabb"] | 2924053ee058c531254d690f0b12d324 | NoteIn the first sample, one can choose the subsequence {3} and form a string "a".In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab". | You are given a string s, consisting of lowercase English letters, and the integer m.One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves.Then one uses the chosen sym... | Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above. | The first line of the input contains a single integer m (1 ≤ m ≤ 100 000). The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string ... | standard output | standard input | PyPy 3 | Python | 1,900 | train_043.jsonl | a521e9d5f408133937bca461e491d22d | 256 megabytes | ["3\ncbabc", "2\nabcab", "3\nbcabcbaccba"] | PASSED | m = int(input())
s = input()
ans = []
mark = [True for _ in range(len(s))]
z = 'a'
i = 0
while i <= len(s) - m:
k = i
for j in range(i, i + m):
if s[j] <= s[k]:
k = j
ans.append(s[k])
z = max(z, s[k])
mark[k] = False
i = k
i += 1
for i in range(len(s)):
if s[i] < z an... | 1475928900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["5\nMike 1\nGerald 1\nKate 1\nTank 1\nDavid 2", "5\nvalera 0\nvanya 3\nedik 3\npasha 3\nigor 3"] | 1e80e51e770cd901156382d2e35cb5bf | NoteIn the first test case consider user David. Users Mike and Tank have one common friend (Gerald) with David. User Kate has no common friends with David. That's why David's suggested friends are users Mike and Tank. | Polycarpus works as a programmer in a start-up social network. His boss gave his a task to develop a mechanism for determining suggested friends. Polycarpus thought much about the task and came to the folowing conclusion. Let's say that all friendship relationships in a social network are given as m username pairs ai, ... | In the first line print a single integer n — the number of network users. In next n lines print the number of suggested friends for each user. In the i-th line print the name of the user ci and the number of his suggested friends di after a space. You can print information about the users in any order. | The first line contains a single integer m (1 ≤ m ≤ 5000) — the number of pairs of friends in the social network. Next m lines contain pairs of names of the users who are friends with each other. The i-th line contains two space-separated names ai and bi (ai ≠ bi). The users' names are non-empty and consist of at most ... | standard output | standard input | Python 2 | Python | 2,200 | train_079.jsonl | 7a946d97c0d1774198bcfb2efb386328 | 256 megabytes | ["5\nMike Gerald\nKate Mike\nKate Tank\nGerald Tank\nGerald David", "4\nvalera vanya\nvalera edik\npasha valera\nigor valera"] | PASSED | import sys
from collections import defaultdict
n,m =0, input()
mp={}
G = defaultdict(list)
def myfind(c):
global n,mp
if c not in mp:
mp[c] = n
n += 1
return mp[c]
def add(u,v):
G[u].append(v)
G[v].append(u)
for ch in sys.stdin:
a,b=ch.split()
u,v=myfind(a),myfind(b)
add(u,v)
print n
def bfs(s):
mx,ans,ct ... | 1353339000 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["aaa\nagaa\nbnbbabb\naapp"] | b86c1533fdfe68fd4dea2bf99cd9e111 | null | You are given a string $$$s$$$ of lowercase Latin letters. The following operation can be used: select one character (from 'a' to 'z') that occurs at least once in the string. And replace all such characters in the string with the previous one in alphabetical order on the loop. For example, replace all 'c' with 'b' o... | For each test case, output the lexicographically minimal string that can be obtained from the string $$$s$$$ by performing no more than $$$k$$$ operations. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases in the test. This is followed by descriptions of the test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le k \le 10^9$$$) — the size of the strin... | standard output | standard input | PyPy 3-64 | Python | 1,500 | train_092.jsonl | 5f605c971553dc9ad4fc45d15edaa9d3 | 256 megabytes | ["4\n\n3 2\n\ncba\n\n4 5\n\nfgde\n\n7 5\n\ngndcafb\n\n4 19\n\nekyv"] | PASSED | d = {chr(96+i):96+i for i in range(1,27)}
for _ in range(int(input())):
n,k = map(int,input().split())
s = input()
l = [0 for i in range(n)]
m1,m2,m3 = 'a','a','a'
q = ""
if k>=25:
print('a'*n)
continue
for i in range(n):
x = d[s[i]]
if k == 0:
... | 1651761300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["00\n01\n10\n11", "10", "01\n11"] | f03f1613292cacc36abbd3a3a25cbf86 | NoteIn the first sample all 16 variants of numbers arrangement are possible. For the variant 0000 the outcome is 00. For the variant 1111 the outcome is 11. For the variant 0011 the outcome is 01. For the variant 1100 the outcome is 10. Regardless of outcomes for all other variants the set which we are looking for will... | Little Petya very much likes playing with little Masha. Recently he has received a game called "Zero-One" as a gift from his mother. Petya immediately offered Masha to play the game with him.Before the very beginning of the game several cards are lain out on a table in one line from the left to the right. Each card con... | Print the set of outcomes for all possible initial digits arrangements. Print each possible outcome on a single line. Each outcome should be represented by two characters: the digits written on the cards that were left by the end of the game. The outcomes should be sorted lexicographically in ascending order (see the f... | The first line contains a sequence of characters each of which can either be a "0", a "1" or a "?". This sequence determines the initial arrangement of cards on the table from the left to the right. The characters "?" mean that the given card was spoiled before the game. The sequence's length ranges from 2 to 105, incl... | standard output | standard input | Python 2 | Python | 1,900 | train_016.jsonl | 0d95de503c9538f8dde86f13cb9eef30 | 256 megabytes | ["????", "1010", "1?1"] | PASSED | a=raw_input()
O,I,Q=[a.count(i)for i in"01?"]
Z=I-O
if Q>Z:print"00"
if-Q<=Z<2+Q:
if"?">a[-1]:print"10"[int(a[-1])]+a[-1]
else:
if Z<Q:print"01"
if~Q<1-Z<Q:print 10
if Z+Q>1:print 11
| 1323443100 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
1 second | ["173\n171\n75\n3298918744"] | ce2b12f1d7c0388c39fee52f5410b94b | NoteHere is an optimal sequence of moves for the second test case: Conquer the kingdom at position $$$1$$$ with cost $$$3\cdot(1-0)=3$$$. Move the capital to the kingdom at position $$$1$$$ with cost $$$6\cdot(1-0)=6$$$. Conquer the kingdom at position $$$5$$$ with cost $$$3\cdot(5-1)=12$$$. Move the capital to the... | You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers.Consider a number axis. The capital of your empire is initially at $$$0$$$. There are $$$n$$$ unconquered kingdoms at positions $$$0<x_1<x_2<\ldots<x_n$$$. You want to conquer al... | For each test case, output a single integer — the minimum cost to conquer all kingdoms. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of each test case follows. The first line of each test case contains $$$3$$$ integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$1 \leq a,b \leq 10^5$$$). The second line of ea... | standard output | standard input | PyPy 3-64 | Python | 1,500 | train_110.jsonl | fdd98238a04bce23bb9cd0686c56485b | 256 megabytes | ["4\n5 2 7\n3 5 12 13 21\n5 6 3\n1 5 6 21 30\n2 9 3\n10 15\n11 27182 31415\n16 18 33 98 874 989 4848 20458 34365 38117 72030"] | PASSED | import math
from sys import stdin, stdout
from collections import deque
def do_it(a,b,kingdoms,previous,position,states):
if len(kingdoms) == 0:
return 0
current = kingdoms[0]
if position in states:
return states[position]
gap = current-position
prev_gap = current-previous
positi... | 1650206100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3\n011\n101\n110", "5\n01111\n10111\n11011\n11101\n11110"] | d3f4c7fedd6148c28d8780142b6594f4 | null | John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge. John has been painti... | In the first line print integer n (3 ≤ n ≤ 100) — the number of vertices in the found graph. In each of next n lines print n characters "0" and "1": the i-th character of the j-th line should equal "0", if vertices i and j do not have an edge between them, otherwise it should equal "1". Note that as the required graph ... | A single line contains an integer k (1 ≤ k ≤ 105) — the number of cycles of length 3 in the required graph. | standard output | standard input | Python 3 | Python | 1,600 | train_006.jsonl | 8a725ebcd4bca73dd0d0ae21128a9652 | 256 megabytes | ["1", "10"] | PASSED | n, k = 0, int(input())
p = [['0'] * 100 for i in range(100)]
while k:
for i in range(n):
if i > k: break
p[n][i] = p[i][n] = '1'
k -= i
n += 1
print(n)
for i in range(n): print(''.join(p[i][:n]))
| 1349969400 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["YES\nYES\nNO\nYES\nNO"] | 5139d222fbbfa70d50e990f5d6c92726 | NoteIn the first test case of the example, the array $$$a$$$ has a subsequence $$$[1, 2, 1]$$$ which is a palindrome.In the second test case of the example, the array $$$a$$$ has two subsequences of length $$$3$$$ which are palindromes: $$$[2, 3, 2]$$$ and $$$[2, 2, 2]$$$.In the third test case of the example, the arra... | You are given an array $$$a$$$ consisting of $$$n$$$ integers.Your task is to determine if $$$a$$$ has some subsequence of length at least $$$3$$$ that is a palindrome.Recall that an array $$$b$$$ is called a subsequence of the array $$$a$$$ if $$$b$$$ can be obtained by removing some (possibly, zero) elements from $$$... | For each test case, print the answer — "YES" (without quotes) if $$$a$$$ has some subsequence of length at least $$$3$$$ that is a palindrome and "NO" otherwise. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Next $$$2t$$$ lines describe test cases. The first line of the test case contains one integer $$$n$$$ ($$$3 \le n \le 5000$$$) — the length of $$$a$$$. The second line of the test case contains $$$n$$$ integers ... | standard output | standard input | Python 3 | Python | 1,100 | train_012.jsonl | d7c0d22e92c06ee128f29ff7cf8df17d | 256 megabytes | ["5\n3\n1 2 1\n5\n1 2 2 3 2\n3\n1 1 2\n4\n1 2 2 1\n10\n1 1 2 2 3 3 4 4 5 5"] | PASSED | for test in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
l.append(10000000009)
c=0
for i in range(n-2):
if l[i] in l[i+2:]:
print("YES")
c=1
break
if(c==0):
print("NO")
| 1584018300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["14", "-3"] | b5b13cb304844a8bbd07e247150719f3 | NoteIn the first sample, the optimal move for Petya is to take all the stickers. As a result, his score will be equal to 14 and Gena's score will be equal to 0.In the second sample, the optimal sequence of moves is the following. On the first move Petya will take first three sticker and will put the new sticker with va... | Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them.The game they came up with has the following rules. Init... | Print one integer — the difference between the Petya's score and Gena's score at the end of the game if both players play optimally. | The first line of input contains a single integer n (2 ≤ n ≤ 200 000) — the number of stickers, initially located on the wall. The second line contains n integers a1, a2, ..., an ( - 10 000 ≤ ai ≤ 10 000) — the numbers on stickers in order from left to right. | standard output | standard input | Python 3 | Python | 2,200 | train_012.jsonl | 8647b6c06752750d4a11959931905a1d | 256 megabytes | ["3\n2 4 8", "4\n1 -7 -2 3"] | PASSED | n = int(input())
raw = input().split()
d = []
prev = 0
for i in range(n):
di = int(raw[i])
di += prev
d.append(di)
prev = di
i = n - 2
cur = d[n - 1]
while i > 0:
cur = max(cur, d[i] - cur)
i -= 1
print(cur) | 1476611100 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["1", "2", "-1"] | 7d5ecacc037c9b0e6de2e86b20638674 | null | Mitya has a rooted tree with $$$n$$$ vertices indexed from $$$1$$$ to $$$n$$$, where the root has index $$$1$$$. Each vertex $$$v$$$ initially had an integer number $$$a_v \ge 0$$$ written on it. For every vertex $$$v$$$ Mitya has computed $$$s_v$$$: the sum of all values written on the vertices on the path from vertex... | Output one integer — the minimum total sum of all values $$$a_v$$$ in the original tree, or $$$-1$$$ if such tree does not exist. | The first line contains one integer $$$n$$$ — the number of vertices in the tree ($$$2 \le n \le 10^5$$$). The following line contains integers $$$p_2$$$, $$$p_3$$$, ... $$$p_n$$$, where $$$p_i$$$ stands for the parent of vertex with index $$$i$$$ in the tree ($$$1 \le p_i < i$$$). The last line contains integer val... | standard output | standard input | Python 3 | Python | 1,600 | train_014.jsonl | dc867f40a1f0438d8891b6f1b53be219 | 256 megabytes | ["5\n1 1 1 1\n1 -1 -1 -1 -1", "5\n1 2 3 1\n1 -1 2 -1 -1", "3\n1 2\n2 -1 1"] | PASSED | n = int(input().strip())
p = [0 for i in range(n)]
p[0] = -1
index = 1
for i in input().strip().split():
p[index] = int(i) - 1
index += 1
min_ = [100000000000 for i in range(n)]
s = []
for i in input().strip().split():
val = int(i)
s.append(val)
for i in range(1,n):
if s[i] >= 0 and s[p[i]] < 0:
... | 1546706100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["ayd", "-1"] | 8ba3a7f7cb955478481c74cd4a4eed14 | null | Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string.More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b ... | Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1. | The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters. | standard output | standard input | PyPy 2 | Python | 1,700 | train_005.jsonl | 80891314260344aad99f2503b53dba69 | 256 megabytes | ["3 2\nabc\nxyc", "1 0\nc\nb"] | PASSED | def main():
n, t = map(int, raw_input().split())
s1 = raw_input().strip()
s2 = raw_input().strip()
same_count = 0
for a, b in zip(s1, s2):
if a == b:
same_count += 1
should_same_count = n - t
manuel_same = should_same_count - same_count
buf = []
if manuel_same <= ... | 1444149000 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["1\n1 2 1", "3\n1 2 0\n1 3 1\n2 3 0", "3\n2 3 0\n1 5 0\n6 8 1"] | a7d3548c4bc356b4bcd40fca7fe839b2 | NoteIn the first test the only path is 1 - 2In the second test the only shortest path is 1 - 3 - 4In the third test there are multiple shortest paths but the optimal is 1 - 4 - 6 - 8 | Breaking Good is a new video game which a lot of gamers want to have. There is a certain level in the game that is really difficult even for experienced gamers.Walter William, the main character of the game, wants to join a gang called Los Hermanos (The Brothers). The gang controls the whole country which consists of n... | In the first line output one integer k, the minimum possible number of roads affected by gang. In the following k lines output three integers describing roads that should be affected. Each line should contain three integers x, y, z (1 ≤ x, y ≤ n, ), cities connected by a road and the new state of a road. z = 1 indicate... | The first line of input contains two integers n, m (2 ≤ n ≤ 105, ), the number of cities and number of roads respectively. In following m lines there are descriptions of roads. Each description consists of three integers x, y, z (1 ≤ x, y ≤ n, ) meaning that there is a road connecting cities number x and y. If z = 1, t... | standard output | standard input | Python 3 | Python | 2,100 | train_023.jsonl | 1d4c1bcf74cfa6c5c026cb9f91fa1522 | 256 megabytes | ["2 1\n1 2 0", "4 4\n1 2 1\n1 3 0\n2 3 1\n3 4 1", "8 9\n1 2 0\n8 3 0\n2 3 1\n1 4 1\n8 7 0\n1 5 1\n4 6 1\n5 7 0\n6 8 0"] | PASSED | from sys import *
from collections import *
s = stdin.read().split()
d = list(map(int, s))
n, m = d[:2]
g = [[] for i in range(n + 1)]
for j in range(m):
i = 3 * j + 2
g[d[i]].append((d[i + 1], d[i + 2], j))
g[d[i + 1]].append((d[i], d[i + 2], j))
u, v = [-1] * n + [0], [1e9] * n + [0]
x, y = [0] * (n + 1),... | 1422028800 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["18\n4\n6"] | 3a3fbb61c7e1ccda69cd6d186da653ae | null | There is a prison that can be represented as a rectangular matrix with $$$n$$$ rows and $$$m$$$ columns. Therefore, there are $$$n \cdot m$$$ prison cells. There are also $$$n \cdot m$$$ prisoners, one in each prison cell. Let's denote the cell in the $$$i$$$-th row and the $$$j$$$-th column as $$$(i, j)$$$.There's a s... | Print $$$t$$$ lines, the answers for each test case. | The first line contains an integer $$$t$$$ $$$(1 \le t \le 10^4)$$$, the number of test cases. Each of the next $$$t$$$ lines contains four space-separated integers $$$n$$$, $$$m$$$, $$$r$$$, $$$c$$$ ($$$1 \le r \le n \le 10^9$$$, $$$1 \le c \le m \le 10^9$$$). | standard output | standard input | PyPy 3 | Python | null | train_003.jsonl | d56b7c765c2d6e85618ece820e8c1eed | 256 megabytes | ["3\n10 10 1 1\n3 5 2 4\n10 2 5 1"] | PASSED | t=int(input())
for i in range(t):
n,m,r,c=map(int,input().split())
a1=1
a2=n
b1=1
b2=m
c1=abs(a1-r)+abs(b1-c)
c2=abs(a1-r)+abs(b2-c)
c3=abs(a2-r)+abs(b1-c)
c4=abs(a2-r)+abs(b2-c)
print(max(c1,max(c2,max(c3,c4)))) | 1606633500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1.0 1.0 1.0", "3.0 0.0 0.0"] | 0a9cabb857949e818453ffe411f08f95 | null | As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: . Mu... | Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists s... | The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists. | standard output | standard input | Python 3 | Python | 1,800 | train_036.jsonl | f3f0e9e844b77679a5bd5a640dbaffd9 | 256 megabytes | ["3\n1 1 1", "3\n2 0 0"] | PASSED | a=int(input())
b=list(map(int,input().split()))
if sum(b)==0:print(' '.join([str(a/3)]*3))
else:print(' '.join(map(str,map(lambda x:a*x/sum(b),b))))
| 1336145400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n3\n5\n11\n17\n23\n29\n59\n89\n0"] | 12157ec4a71f0763a898172b38ff1ef2 | null | Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $$$d, m$$$, find the number of arrays $$$a$$$, satisfying the following constraints: The length of $$$a$$$ is $$$n$$$, $$$n \ge 1$$$ $$$1 \le a_1 < a_2 < \dots < a_n \le d$$$... | For each test case, print the number of arrays $$$a$$$, satisfying all given constrains, modulo $$$m$$$. | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) denoting the number of test cases in the input. Each of the next $$$t$$$ lines contains two integers $$$d, m$$$ ($$$1 \leq d, m \leq 10^9$$$). Note that $$$m$$$ is not necessary the prime! | standard output | standard input | Python 3 | Python | 1,700 | train_022.jsonl | 9bf265a24bdd6428d87b6fa7690216d5 | 256 megabytes | ["10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n6 99995\n7 9994\n8 993\n9 92\n10 1"] | PASSED | t=int(input())
for q in range(t):
n,m=map(int,input().split())
st=1
ans=1
while st<=n:
ans*=min(st*2-st+1,n-st+2)
st*=2
print((ans-1)%m)
| 1585924500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\nYES\nNO\nYES\nYES\nNO"] | ccb5369bc4175ba071969571ceb17227 | NoteIn the first test case, the number $$$1$$$ is already on the board.In the second test case, Nezzar could perform the following operations to write down $$$k=0$$$ on the board: Select $$$x=3$$$ and $$$y=2$$$ and write down $$$4$$$ on the board. Select $$$x=4$$$ and $$$y=7$$$ and write down $$$1$$$ on the board. ... | $$$n$$$ distinct integers $$$x_1,x_2,\ldots,x_n$$$ are written on the board. Nezzar can perform the following operation multiple times. Select two integers $$$x,y$$$ (not necessarily distinct) on the board, and write down $$$2x-y$$$. Note that you don't remove selected numbers. Now, Nezzar wonders if it is possible to... | For each test case, print "YES" on a single line if it is possible to have $$$k$$$ on the board. Otherwise, print "NO". You can print each letter in any case (upper or lower). | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The first line of each test case contains two integers $$$n,k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$-10^{18} \le k \le 10^{18}$$$). The second line of each test case contains $$$n$$$ distinct integers $$$x_1,x_2,\ldo... | standard output | standard input | Python 3 | Python | 1,800 | train_088.jsonl | e66a0f3373f97d8b5d33521daeb3c468 | 512 megabytes | ["6\n2 1\n1 2\n3 0\n2 3 7\n2 -1\n31415926 27182818\n2 1000000000000000000\n1 1000000000000000000\n2 -1000000000000000000\n-1000000000000000000 123\n6 80\n-5 -20 13 -14 -2 -11"] | PASSED | import math
for t in range(int(input())):
n, k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(1, n):
ans = math.gcd(ans, a[i]-a[i - 1])
if (k-a[0])%ans==0:
print ("YES")
else:
print ("NO") | 1611844500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["3", "6", "3"] | d02e8f3499c4eca03e0ae9c23f80dc95 | NoteIn the first sample the editor contains four lines. Let's represent the cursor's possible positions in the line as numbers. Letter s represents the cursor's initial position, letter t represents the last one. Then all possible positions of the cursor in the text editor are described by the following table.12312123s... | Vasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the classical epos depicted in Homer's Odysseus... How can he explain to his literature teacher that he isn't going to become a writer? In fact, he is going to become a programmer. So, he would take great pleasure in writing a program, b... | Print a single integer — the minimum number of times Vasya should push a key to move the cursor from position (r1, c1) to position (r2, c2). | The first line of the input contains an integer n (1 ≤ n ≤ 100) — the number of lines in the file. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105), separated by single spaces. The third line contains four integers r1, c1, r2, c2 (1 ≤ r1, r2 ≤ n, 1 ≤ c1 ≤ ar1 + 1, 1 ≤ c2 ≤ ar2 + 1). | output.txt | input.txt | Python 3 | Python | 1,600 | train_020.jsonl | a01148c00811822eb4c96527236a3705 | 256 megabytes | ["4\n2 1 6 4\n3 4 4 2", "4\n10 5 6 4\n1 11 4 2", "3\n10 1 10\n1 10 1 1"] | PASSED | from collections import deque
def read(line):
return [int(c) for c in line.split()]
def solve(n, lines, r1, c1, r2, c2):
queue = deque([(r1, c1, 0)])
visited = {}
while queue:
r, c, cost = queue.pop()
if (r, c) not in visited:
visited[(r, c)] = cost
else:
... | 1354960800 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["2", "0", "3"] | 194bc63b192a4e24220b36984901fb3b | NoteIn the first sample case, we can transform $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$$$ in two steps. Note that the sequence $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$$$ also works in the same number of steps.The second sample case already satisfies ... | Allen is hosting a formal dinner party. $$$2n$$$ people come to the event in $$$n$$$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $$$2n$$$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this m... | Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of pairs of people. The second line contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$. For each $$$i$$$ with $$$1 \le i \le n$$$, $$$i$$$ appears exactly twice. If $$$a_j = a_k = i$$$, that means that the $$$j$$$-th and $$$k$$$-... | standard output | standard input | Python 3 | Python | 1,400 | train_034.jsonl | a63e5fbdd02d3f10b39d697f9627ddc0 | 256 megabytes | ["4\n1 1 2 3 3 2 4 4", "3\n1 1 2 2 3 3", "3\n3 1 2 3 1 2"] | PASSED | l = int(input())
a = list(map(int,input().split()))
count = 0
i = 0
n = 2*l
while (i<n-2):
if (a[i]==a[i+1]):
i += 2
continue
j = i+2
while (j<n and a[j]!=a[i]):
j += 1
while (j>i+1):
count += 1
a[j-1],a[j] = a[j],a[j-1]
j -= 1
i += 2
print(count)
| 1529858100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2\n2 3", "3\n2 2 2"] | 98fd00d3c83d4b3f0511d8afa6fdb27b | null | Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer diviso... | The first line of the output contains a single integer k — maximum possible number of primes in representation. The second line should contain k primes with their sum equal to n. You can print them in any order. If there are several optimal solution, print any of them. | The only line of the input contains a single integer n (2 ≤ n ≤ 100 000). | standard output | standard input | Python 2 | Python | 800 | train_004.jsonl | 494cefa8733cf0fcae59d51319820907 | 256 megabytes | ["5", "6"] | PASSED | n = int(input())
print n >> 1
while n > 0:
if n % 2 > 0:
print 3,
n -= 3
else:
print 2,
n -= 2
| 1482165300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["17\n18\n1\n1\n39\n0\n2"] | 84c88932e107e1d1f80b44aec88134e4 | NoteIn the first test case, the words can be written as $$$x_1 = 10010_2$$$, $$$x_2 = 01001_2$$$ and $$$x_3 = 10101_2$$$ in binary. Let $$$y = 10001_2$$$. Then, $$$d(x_1, y) = 2$$$ (the difference is in the fourth and the fifth positions), $$$d(x_2, y) = 2$$$ (the difference is in the first and the second positions), $... | Martian scientists explore Ganymede, one of Jupiter's numerous moons. Recently, they have found ruins of an ancient civilization. The scientists brought to Mars some tablets with writings in a language unknown to science.They found out that the inhabitants of Ganymede used an alphabet consisting of two letters, and eac... | For each test, print a single integer, the initial form of the word, i. e. such $$$y$$$ ($$$0 \le y \le 2^\ell - 1$$$) that the sum $$$d(x_i, y)$$$ over all $$$1 \le i \le n$$$ is minimal possible. Note that $$$y$$$ can differ from all the integers $$$x_i$$$. If there are multiple ways to restore the initial form, prin... | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The following are descriptions of the test cases. The first line contains two integers $$$n$$$ and $$$\ell$$$ ($$$1 \le n \le 100$$$, $$$1 \le \ell \le 30$$$) — the amount of word forms, and the number of letters in one word.... | standard output | standard input | Python 3 | Python | 800 | train_085.jsonl | ce67d53f5517adb49754b03cd2d5de98 | 256 megabytes | ["7\n3 5\n18 9 21\n3 5\n18 18 18\n1 1\n1\n5 30\n1 2 3 4 5\n6 10\n99 35 85 46 78 55\n2 1\n0 1\n8 8\n5 16 42 15 83 65 78 42"] | PASSED | for _ in range(int(input())):
n, l = list(map(int, input().split()))
arr = list(map(int, input().split()))
ans = 0
for i in range(l):
cnt = 0
for el in arr:
if el & (1 << i):
cnt += 1
if cnt > n - cnt:
ans += 1 << i
print(ans)
| 1641989100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3\n1 2\n4 2\n2 3"] | d93a0574497b60bb77fb1c1dfe95090f | NoteThis is one possible solution of the example: These are examples of wrong solutions: The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a roa... | A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two r... | You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi. If there are several solutions, you may print... | The first line consists of two integers n and m . Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n. It is guaranteed that every pair of cities will a... | standard output | standard input | Python 3 | Python | 1,300 | train_003.jsonl | 1ff475f43c832f48a89f372b6022995a | 256 megabytes | ["4 1\n1 3"] | PASSED | #B. Road Construction
n,m = map(int,input().split())
edges = [0]*(n+1)
for _ in range(m):
x,y = map(int,input().split())
edges[x] = 1
edges[y] = 1
for i in range(1,n+1):
if edges[i] == 0:
break
print(n-1)
for j in range(1,n+1):
if i!=j:
print(i,j) | 1374327000 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["0 1 2 3 \n1 2 3 \n2 3 4 5 6 7 \n1 1 1 1 \n2 \n0 0 0 0 0 0", "2 2 3 1 \n0 0 0 0 \n2 2 0 \n0 0 1 0 1"] | 8feb34d083d9b50c44c469e1254a885b | null | You are given a string $$$s$$$, consisting of lowercase Latin letters.You are asked $$$q$$$ queries about it: given another string $$$t$$$, consisting of lowercase Latin letters, perform the following steps: concatenate $$$s$$$ and $$$t$$$; calculate the prefix function of the resulting string $$$s+t$$$; print the v... | For each query, print the values of the prefix function of a string $$$s+t$$$ on positions $$$|s|+1, |s|+2, \dots, |s|+|t|$$$. | The first line contains a non-empty string $$$s$$$ ($$$1 \le |s| \le 10^6$$$), consisting of lowercase Latin letters. The second line contains a single integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of queries. Each of the next $$$q$$$ lines contains a query: a non-empty string $$$t$$$ ($$$1 \le |t| \le 10$$$), ... | standard output | standard input | PyPy 3-64 | Python | 2,200 | train_090.jsonl | d05aebd364a36ff6e40dd8c56422924d | 256 megabytes | ["aba\n6\ncaba\naba\nbababa\naaaa\nb\nforces", "aacba\n4\naaca\ncbbb\naab\nccaca"] | PASSED | def get_next(j, k, nxt, p):
while p[j] != '$':
if k == -1 or p[j] == p[k]:
j += 1
k += 1
if p[j] == p[k]:
nxt[j] = nxt[k]
else:
nxt[j] = k
else:
k = nxt[k]
return j, k, nxt
def solve():
... | 1661610900 | [
"strings",
"trees"
] | [
0,
0,
0,
0,
0,
0,
1,
1
] | |
1 second | ["Yes", "No"] | 6478d3dda3cbbe146eb03627dd5cc75e | NoteIn the first example, we can perform the following synchronizations ($$$1$$$-indexed): First, synchronize the third stone $$$[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$$$. Then synchronize the second stone: $$$[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$$$. In the second example, ... | Grigory has $$$n$$$ magic stones, conveniently numbered from $$$1$$$ to $$$n$$$. The charge of the $$$i$$$-th stone is equal to $$$c_i$$$.Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $$$i$$$, where $$$2 \le i \le n - 1$$$), and after that synchronizes it with neighboring sto... | If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No". | The first line contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of magic stones. The second line contains integers $$$c_1, c_2, \ldots, c_n$$$ ($$$0 \le c_i \le 2 \cdot 10^9$$$) — the charges of Grigory's stones. The second line contains integers $$$t_1, t_2, \ldots, t_n$$$ ($$$0 \le t_i \le 2 \cdot 1... | standard output | standard input | Python 3 | Python | 2,200 | train_008.jsonl | 58de502b090b83212bbc336bb49dcb03 | 256 megabytes | ["4\n7 2 4 12\n7 15 10 12", "3\n4 4 4\n1 2 3"] | PASSED | n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = []
y = []
for i in range(n-1):
x.append(a[i+1]-a[i])
for i in range(n-1):
y.append(b[i+1]-b[i])
x.sort()
y.sort()
# print(x,y)
if x == y and a[0] == b[0] and a[n-1] == b[n-1]:
print("Yes")
else:
print("No")
| 1549546500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["0 1 1 1 1 0 1 1"] | 2dcc82e6abc733a9c4567742294184dc | null | You are given a tree consisting of $$$n$$$ vertices. Some of the vertices (at least two) are black, all the other vertices are white.You place a chip on one of the vertices of the tree, and then perform the following operations: let the current vertex where the chip is located is $$$x$$$. You choose a black vertex $$$... | Print $$$n$$$ integers. The $$$i$$$-th integer should be equal to $$$1$$$ if there exists a (possibly empty) sequence of operations that moves the chip to some black vertex if it is placed on the vertex $$$i$$$, and $$$0$$$ if no such sequence of operations exists. | The first line contains one integer $$$n$$$ ($$$3 \le n \le 3 \cdot 10^5$$$) — the number of vertices in the tree. The second line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$0 \le c_i \le 1$$$), where $$$c_i = 0$$$ means that the $$$i$$$-th vertex is white, and $$$c_i = 1$$$ means that the $$$i$$$-th vert... | standard output | standard input | PyPy 3-64 | Python | 2,400 | train_087.jsonl | 70d88734342c645f3bdcb74bad3c5d5b | 512 megabytes | ["8\n0 1 0 0 0 0 1 0\n8 6\n2 5\n7 8\n6 5\n4 5\n6 1\n7 3"] | PASSED | from sys import stdin
inp = stdin.readline
n = int(inp())
bow = [int(x) for x in inp().split()]
# tree[nr][color, [connected]]
tree = {i+1: [c, set()] for i, c in enumerate(bow)}
for i in range(n-1):
a, b = map(int, inp().split())
tree[a][1].add(b)
tree[b][1].add(a)
blacks = []
for i in... | 1642343700 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["1\n2 3\n2\n2 3\n5 8\n-1\n1\n1 5"] | 1d72b5ab8b6af0b7a02246ecd5e87953 | NoteIn the first example, the cuteness of $$$\texttt{0011}$$$ is the same as the cuteness of $$$\texttt{01}$$$.In the second example, the cuteness of $$$\texttt{11000011}$$$ is $$$\frac{1}{2}$$$ and there is no subsegment of size $$$6$$$ with the same cuteness. So we must use $$$2$$$ disjoint subsegments $$$\texttt{10}... | The cuteness of a binary string is the number of $$$\texttt{1}$$$s divided by the length of the string. For example, the cuteness of $$$\texttt{01101}$$$ is $$$\frac{3}{5}$$$.Juju has a binary string $$$s$$$ of length $$$n$$$. She wants to choose some non-intersecting subsegments of $$$s$$$ such that their concatenatio... | For each test case, if there is no valid pair of $$$l$$$ and $$$r$$$, print $$$-1$$$. Otherwise, print $$$k + 1$$$ lines. In the first line, print a number $$$k$$$ ($$$1 \leq k \leq m$$$) — the minimum number of subsegments required. Then print $$$k$$$ lines, the $$$i$$$-th should contain $$$l_i$$$ and $$$r_i$$$ ($$$1... | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq m \leq n \leq 2 \cdot 10^5$$$). The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$. It is guaran... | standard output | standard input | Python 3 | Python | 2,700 | train_095.jsonl | 70d8a5de9e0a484d906fb2ee97ee25a1 | 256 megabytes | ["4\n\n4 2\n\n0011\n\n8 6\n\n11000011\n\n4 3\n\n0101\n\n5 5\n\n11111"] | PASSED | import sys
from calendar import c
import math
t = int(input())
for _ in range(0, t):
n,m = [int(i) for i in input().split()]
s = input()
p = [0 for i in range(n+1)]
for i in range(0, n):
p[i + 1] = p[i] + (s[i] == '1')
k = p[n]
c = k * m
if c % n != 0:
print(... | 1648391700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2.5 seconds | ["1 3 2", "-1"] | 725a65c7eb72ad54af224895b20a163d | null | A tournament is a directed graph without self-loops in which every pair of vertexes is connected by exactly one directed edge. That is, for any two vertexes u and v (u ≠ v) exists either an edge going from u to v, or an edge from v to u.You are given a tournament consisting of n vertexes. Your task is to find there a c... | Print three distinct vertexes of the graph a1, a2, a3 (1 ≤ ai ≤ n), such that Aa1, a2 = Aa2, a3 = Aa3, a1 = 1, or "-1", if a cycle whose length equals three does not exist. If there are several solutions, print any of them. | The first line contains an integer n (1 ≤ n ≤ 5000). Next n lines contain the adjacency matrix A of the graph (without spaces). Ai, j = 1 if the graph has an edge going from vertex i to vertex j, otherwise Ai, j = 0. Ai, j stands for the j-th character in the i-th line. It is guaranteed that the given graph is a tourna... | standard output | standard input | Python 2 | Python | 2,000 | train_074.jsonl | 171c3cacecb9e4a715b016df43426671 | 256 megabytes | ["5\n00100\n10000\n01001\n11101\n11000", "5\n01111\n00000\n01000\n01100\n01110"] | PASSED | from sys import stdin, stdout
input = stdin.readline
import gc
gc.disable()
def f():
p, q, n = [0], [0], int(input())
input()
for i in range(1, n):
t = input()[: i]
if '0' in t:
if '1' in t:
for l, j in enumerate(p):
if t[j] == '1':
... | 1316790000 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["4\n2\n1\n0\n2\n0\n0\n0\n17"] | 9966bfdc9677a9dd558684a00977cd58 | NoteIn the first test case, for each pair of adjacent cosplayers, you can invite two female cosplayers to stand in between them. Then, $$$000 \rightarrow 0110110$$$.In the third test case, you can invite one female cosplayer to stand next to the second cosplayer. Then, $$$010 \rightarrow 0110$$$. | Today, Marin is at a cosplay exhibition and is preparing for a group photoshoot!For the group picture, the cosplayers form a horizontal line. A group picture is considered beautiful if for every contiguous segment of at least $$$2$$$ cosplayers, the number of males does not exceed the number of females (obviously).Curr... | For each test case, print the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The first line of each test case contains a positive integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of cosplayers in the initial line. The second line of each test case contains a binary string $$$s$$$ of le... | standard output | standard input | PyPy 3-64 | Python | 800 | train_095.jsonl | fe14ec67ea19ee56dc216d3461fa5680 | 256 megabytes | ["9\n\n3\n\n000\n\n3\n\n001\n\n3\n\n010\n\n3\n\n011\n\n3\n\n100\n\n3\n\n101\n\n3\n\n110\n\n3\n\n111\n\n19\n\n1010110000100000101"] | PASSED | #https://codeforces.com/blog/entry/71884
import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def incr():
s = inp... | 1648391700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["-\n+\n+\n-\n-\n+\n-\n+\n+\n+"] | 1f5f5ccbdfcbe5cb2d692475f0726bfd | null | Petya and Vasya are inventing a new game that requires a rectangular board and one chess piece. At the beginning of the game the piece stands in the upper-left corner of the board. Two players move the piece in turns. Each turn the chess piece can be moved either one square to the right or one square down or jump k squ... | Output t lines that can determine the outcomes of the game on every board. Write «+» if the first player is a winner, and «-» otherwise. | The first input line contains two integers t and k (1 ≤ t ≤ 20, 1 ≤ k ≤ 109). Each of the following t lines contains two numbers n, m — the board’s length and width (1 ≤ n, m ≤ 109). | output.txt | input.txt | Python 2 | Python | 2,300 | train_078.jsonl | da1f71e4fdae8b1e653fe48dffd52a0d | 64 megabytes | ["10 2\n1 1\n1 2\n2 1\n2 2\n1 3\n2 3\n3 1\n3 2\n3 3\n4 3"] | PASSED | #!/usr/bin/python
c = ['-', '+']
infile = open("input.txt")
outfile = open("output.txt", 'w')
t, k = map(lambda x: int(x), infile.readline().split())
for i in range(t):
n, m = map(lambda x: int(x)-1, infile.readline().split())
if n > m:
n, m = m, n
if k >= 2:
r = n % (2*k + 2)
if r == k or r == 2*k+1:
ou... | 1287482400 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
3 seconds | ["1\n1\n0\n0\n7\n995\n2\n1\n1\n1\n2"] | 716965622c7c5fbc78217998d4bfe9ab | null | A positive number $$$x$$$ of length $$$n$$$ in base $$$p$$$ ($$$2 \le p \le 10^9$$$) is written on the blackboard. The number $$$x$$$ is given as a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i < p$$$) — the digits of $$$x$$$ in order from left to right (most significant to least significant).Dmitry is very fond... | For each test case print a single integer — the minimum number of operations required for Dmitry to get all the digits on the board from $$$0$$$ to $$$p-1$$$. It can be shown that this always requires a finite number of operations. | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^3$$$) — the number of test cases. The descriptions of the input test cases follow. The first line of description of each test case contains two integers $$$n$$$ ($$$1 \le n \le 100$$$) and $$$p$$$ ($$$2 \le p \le 10^9$$$) — the len... | standard output | standard input | PyPy 3-64 | Python | 1,800 | train_086.jsonl | c03ea8f8047ec4d6666a90472f09b0e7 | 256 megabytes | ["11\n\n2 3\n\n1 2\n\n4 2\n\n1 1 1 1\n\n6 6\n\n1 2 3 4 5 0\n\n5 2\n\n1 0 1 0 1\n\n3 10\n\n1 2 3\n\n5 1000\n\n4 1 3 2 5\n\n3 5\n\n2 3 4\n\n4 4\n\n3 2 3 0\n\n1 3\n\n2\n\n5 5\n\n1 2 2 2 4\n\n3 4\n\n1 0 1"] | PASSED | from calendar import c
import sys
readline = sys.stdin.readline
t = int(readline())
def good(oadd, arr, p):
add = oadd
range_ = (-1,-1)
max_ = p
min_ = -1
digits = set(arr)
for i in range(len(arr)):
if add == 0:
break
val = (add%p + arr[i])
add... | 1668782100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["8\n998"] | 80c75a4c163c6b63a614075e094ad489 | NoteIn the second test case (with $$$n = 3$$$), if uncle Bogdan had $$$x = 998$$$ then $$$k = 100110011000$$$. Denis (by wiping last $$$n = 3$$$ digits) will obtain $$$r = 100110011$$$.It can be proved that the $$$100110011$$$ is the maximum possible $$$r$$$ Denis can obtain and $$$998$$$ is the minimum $$$x$$$ to obta... | Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to come up with an interesting problem and asked the crew to solve it.I... | For each test case, print the minimum integer $$$x$$$ of length $$$n$$$ such that obtained by Denis number $$$r$$$ is maximum possible. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Next $$$t$$$ lines contain test cases — one per test case. The one and only line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the integer $$$x$$$ you need to find. It's... | standard output | standard input | PyPy 3 | Python | 1,000 | train_005.jsonl | 55e84ca9d1187dd71ba802557aacadf0 | 256 megabytes | ["2\n1\n3"] | PASSED | t=int(input())
for i in range(t):
x=int(input())
ans=8
u=0
an=""
n=0
if x<=4:
for i in range(u+1,x):
ans+=(9)*(10**i)
print(ans)
else:
a=""
q=(x-1)//4
a+='9'*(x-q-1)
a+='8'*(q+1)
print(int(a)) | 1596119700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3", "-1"] | 7225266f663699ff7e16b726cadfe9ee | NoteIn the first sample, heights sequences are following:Xaniar: Abol: | Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar. So, if height of Xaniar is h1 and height of Abol is h2, after one second height of Xaniar will become and height of Abol... | Print the minimum number of seconds until Xaniar reaches height a1 and Abol reaches height a2 or print -1 otherwise. | The first line of input contains integer m (2 ≤ m ≤ 106). The second line of input contains integers h1 and a1 (0 ≤ h1, a1 < m). The third line of input contains integers x1 and y1 (0 ≤ x1, y1 < m). The fourth line of input contains integers h2 and a2 (0 ≤ h2, a2 < m). The fifth line of input contains integers... | standard output | standard input | PyPy 3 | Python | 2,200 | train_059.jsonl | 9cf794de657bd5b450b9789e621a2030 | 256 megabytes | ["5\n4 2\n1 1\n0 1\n2 3", "1023\n1 2\n1 0\n1 2\n1 1"] | PASSED | import fractions
def read_data():
m = int(input())
h1, a1 = map(int, input().split())
x1, y1 = map(int, input().split())
h2, a2 = map(int, input().split())
x2, y2 = map(int, input().split())
return m, h1, a1, x1, y1, h2, a2, x2, y2
def solve(m, h1, a1, x1, y1, h2, a2, x2, y2):
t = 0
h1... | 1432658100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1", "3", "4"] | d99b8f78eee74d9933c54af625dafd26 | NoteIn the second sample, the get a decomposition of number 2, you need any one number out of three to equal 2, and the rest to equal 1.In the third sample, the possible ways of decomposing into ordered multipliers are [7,5], [5,7], [1,35], [35,1].A decomposition of positive integer m into n ordered multipliers is a co... | You are given an integer m as a product of integers a1, a2, ... an . Your task is to find the number of distinct decompositions of number m into the product of n ordered positive integers.Decomposition into n products, given in the input, must also be considered in the answer. As the answer can be very large, print it ... | In a single line print a single number k — the number of distinct decompositions of number m into n ordered multipliers modulo 1000000007 (109 + 7). | The first line contains positive integer n (1 ≤ n ≤ 500). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109). | standard output | standard input | Python 3 | Python | null | train_020.jsonl | 1ea93b049917839dad13cadba9036a53 | 256 megabytes | ["1\n15", "3\n1 1 2", "2\n5 7"] | PASSED | Mod = 1000000007
MAX = 33000
n = int( input() )
A = list( map( int, input().split() ) )
B = [0] * MAX
bePrime = [0] * MAX;
primNum = []
C = []
fac=[1]
for j in range(1, MAX):
fac.append( fac[-1] * j % Mod )
def calc( M, N ):
return fac[M] * pow( fac[N] * fac[M-N] % Mod, Mod-2,Mod ) % Mod
fo... | 1393428600 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1.5 seconds | ["0 3 2 2", "0", "1073741823 0"] | 891a7bd69187975f61b8c6ef6b6acac3 | NoteIn the first sample, these are all the arrays satisfying the statements: $$$[0, 3, 2, 2]$$$, $$$[2, 1, 0, 0]$$$, $$$[2, 1, 0, 2]$$$, $$$[2, 1, 2, 0]$$$, $$$[2, 1, 2, 2]$$$, $$$[2, 3, 0, 0]$$$, $$$[2, 3, 0, 2]$$$, $$$[2, 3, 2, 0]$$$, $$$[2, 3, 2, 2]$$$. | The Narrator has an integer array $$$a$$$ of length $$$n$$$, but he will only tell you the size $$$n$$$ and $$$q$$$ statements, each of them being three integers $$$i, j, x$$$, which means that $$$a_i \mid a_j = x$$$, where $$$|$$$ denotes the bitwise OR operation.Find the lexicographically smallest array $$$a$$$ that ... | On a single line print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i < 2^{30}$$$) — array $$$a$$$. | In the first line you are given with two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le q \le 2 \cdot 10^5$$$). In the next $$$q$$$ lines you are given with three integers $$$i$$$, $$$j$$$, and $$$x$$$ ($$$1 \le i, j \le n$$$, $$$0 \le x < 2^{30}$$$) — the statements. It is guaranteed that all $$$q$$... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_082.jsonl | 19d850f43229ef9c5b587111f73d4efd | 256 megabytes | ["4 3\n1 2 3\n1 3 2\n4 1 2", "1 0", "2 1\n1 1 1073741823"] | PASSED | # if you win, you live. you cannot win unless you fighst.
from sys import stdin,setrecursionlimit
import os
import sys
from io import BytesIO, IOBase
_str = str
str = lambda x=b"": x if type(x) is bytes else _str(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(sel... | 1661006100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["6", "1"] | 818e5f23028faf732047fc177eeb3851 | null | Tree is a connected graph without cycles. A leaf of a tree is any vertex connected with exactly one other vertex.You are given a tree with n vertices and a root in the vertex 1. There is an ant in each leaf of the tree. In one second some ants can simultaneously go to the parent vertex from the vertex they were in. No ... | Print the only integer t — the minimal time required for all ants to be in the root of the tree. | The first line contains integer n (2 ≤ n ≤ 5·105) — the number of vertices in the tree. Each of the next n - 1 lines contains two integers xi, yi (1 ≤ xi, yi ≤ n) — the ends of the i-th edge. It is guaranteed that you are given the correct undirected tree. | standard output | standard input | PyPy 2 | Python | 2,200 | train_050.jsonl | 8273dd43e2a35a64f198ac4b45ebff26 | 256 megabytes | ["12\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n3 9\n8 10\n8 11\n8 12", "2\n2 1"] | PASSED | #!/usr/bin/env python3
from __future__ import division, print_function
def bfs(node, adj, visited):
L = []
visited[node] = True
L.append( (node, 1) )
d = []
while L:
node, depth = L.pop()
is_leaf = True
for i in adj[node]:
if not visited[i]:
... | 1455116400 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["2", "0", "30"] | c1f50da1fbe797e7c9b982583a3b02d5 | NoteIn the first example, you have to swap the third and the fourth elements, so the string becomes "aazaa". Then you have to swap the second and the third elements, so the string becomes "azaaa". So, it is possible to reverse the string in two swaps.Since the string in the second example is a palindrome, you don't hav... | You are given a string $$$s$$$. You have to reverse it — that is, the first letter should become equal to the last letter before the reversal, the second letter should become equal to the second-to-last letter before the reversal — and so on. For example, if your goal is to reverse the string "abddea", you should get t... | Print one integer — the minimum number of swaps of neighboring elements you have to perform to reverse the string. | The first line contains one integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the length of $$$s$$$. The second line contains $$$s$$$ — a string consisting of $$$n$$$ lowercase Latin letters. | standard output | standard input | Python 3 | Python | 1,900 | train_010.jsonl | 9fa43384471926cf6aef2ad874648da0 | 256 megabytes | ["5\naaaza", "6\ncbaabc", "9\nicpcsguru"] | PASSED | import sys
input = sys.stdin.readline
n = int(input())
S = input().strip()
LIST = [[] for i in range(26)]
for i in range(n):
LIST[ord(S[i])-97].append(i)
# for i in LIST:
# print(i)
LEN = n+1
BIT = [0]*(LEN+1)
# print(BIT)
def update(v, w):
while v <= LEN:
BIT[v] += w
v += (v & (-v))... | 1602407100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1\n8\n16\n13\n4", "16\n9\n7\n20"] | 3c48123f326fb79ce2e4e17e1e0765f8 | NoteAnswers to the queries from examples are on the board in the picture from the problem statement. | You are given a chessboard of size $$$n \times n$$$. It is filled with numbers from $$$1$$$ to $$$n^2$$$ in the following way: the first $$$\lceil \frac{n^2}{2} \rceil$$$ numbers from $$$1$$$ to $$$\lceil \frac{n^2}{2} \rceil$$$ are written in the cells with even sum of coordinates from left to right from top to bottom... | For each query from $$$1$$$ to $$$q$$$ print the answer to this query. The answer to the $$$i$$$-th query is the number written in the cell $$$x_i, y_i$$$ ($$$x_i$$$ is the row, $$$y_i$$$ is the column). Rows and columns are numbered from $$$1$$$ to $$$n$$$. Queries are numbered from $$$1$$$ to $$$q$$$ in order of the ... | The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^9$$$, $$$1 \le q \le 10^5$$$) — the size of the board and the number of queries. The next $$$q$$$ lines contain two integers each. The $$$i$$$-th line contains two integers $$$x_i, y_i$$$ ($$$1 \le x_i, y_i \le n$$$) — description of the $$$i$$... | standard output | standard input | Python 3 | Python | 1,200 | train_024.jsonl | 61aa0ee40bcf3289b9686fde1af2d128 | 256 megabytes | ["4 5\n1 1\n4 4\n4 3\n3 2\n2 4", "5 4\n2 1\n4 2\n3 3\n3 4"] | PASSED | from math import ceil
n, q = map(int, input().split())
a = []
def getNumber(x, y):
global n
if n % 2 == 0:
if (x + y) % 2 == 0:
start = 0
else:
start = n ** 2 // 2
pos = (x - 1) * n // 2 + (y + 1) // 2
else:
t = (x - 1) * n + y + 1
if t % 2... | 1534602900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1 1 4 6\n\n2 1 5 6\n\n2 2 1 4\n\n0 1 3 4 2 6 5"] | 6c0ed9fe0a104fc9380c199003a22e90 | NoteThe image below shows the hidden polygon in the example: The interaction in the example goes as below: Contestant reads $$$n = 6$$$. Contestant asks a query with $$$t = 1$$$, $$$i = 1$$$, $$$j = 4$$$, $$$k = 6$$$. Jury answers $$$15$$$. The area of the triangle $$$A_1A_4A_6$$$ is $$$7.5$$$. Note that the answe... | This is an interactive problem.Khanh has $$$n$$$ points on the Cartesian plane, denoted by $$$a_1, a_2, \ldots, a_n$$$. All points' coordinates are integers between $$$-10^9$$$ and $$$10^9$$$, inclusive. No three points are collinear. He says that these points are vertices of a convex polygon; in other words, there exi... | null | null | standard output | standard input | PyPy 2 | Python | 2,300 | train_030.jsonl | 6cbee4e374df3177acee6dc4aaa413bc | 256 megabytes | ["6\n\n15\n\n-1\n\n1"] | PASSED | import sys
range = xrange
input = raw_input
def query1(a,b,c):
print 1, a+1, b+1, c+1
return int(input())
def query2(a,b,c):
print 2, a+1, b+1, c+1
return int(input())
def ans(order):
print 0,' '.join(str(x + 1) for x in order)
sys.exit()
n = int(input())
a = 0
b = 1
for i in range(2,n):
... | 1574174100 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["1.500000000000000", "2.000000000000000"] | adaae163882b064bf7257e82e8832ffb | NoteIn the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them. W... | Print a number — the expected length of their journey. The journey starts in the city 1. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if... | The first line contains a single integer n (1 ≤ n ≤ 100000) — number of cities. Then n - 1 lines follow. The i-th line of these lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the cities connected by the i-th road. It is guaranteed that one can reach any city from any other by the roads. | standard output | standard input | Python 3 | Python | 1,500 | train_010.jsonl | 23430fc1c25c113258721964a6ec2e9b | 256 megabytes | ["4\n1 2\n1 3\n2 4", "5\n1 2\n1 3\n3 4\n2 5"] | PASSED | class Node:
def __init__(self, index):
self.neighbours = []
self.index = index
self.prob = 1.0
self.vis = False
self.length = 0
def addNode(self, city):
self.neighbours.append(city)
if self.index == 1:
self.prob = 1.0 / len(self.neighbours)
else:
l = len(self.neighbours)
self.prob = 1.0 if ... | 1502548500 | [
"probabilities",
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
1,
0,
1
] | |
2 seconds | ["fix", "Just a legend"] | fd94aea7ca077ee2806653d22d006fb1 | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the tem... | Print the string t. If a suitable t string does not exist, then print "Just a legend" without the quotes. | You are given the string s whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | standard output | standard input | PyPy 3 | Python | 1,700 | train_000.jsonl | 369f90ccad156909f0a8cd31f86e4e5a | 256 megabytes | ["fixprefixsuffix", "abcdabc"] | PASSED | import sys
input=sys.stdin.readline
import collections as cc
s=input().strip()
n=len(s)
temp=cc.Counter(s)
pre=[0]*(n)
i=1
j=0
lst=-1
while i<n:
if(s[i]==s[j]):
j+=1
pre[i]=j
i+=1
else:
if j:
j=pre[j-1]
else:
pre[i]=0
i+=1
pre[0]=0
#print(pre)
temp=pre[-1]
if pre[-1]!=0 and pre.count(temp)>=2:
pri... | 1320858000 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["molice", "cdcbcdcfcdc"] | 67a70d58415dc381afaa74de1fee7215 | NoteIn the second sample the name of the corporation consecutively changes as follows: | The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan... | Print the new name of the corporation. | The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the length of the initial name and the number of designers hired, respectively. The second line consists of n lowercase English letters and represents the original name of the corporation. Next m lines contain the descriptions of the desig... | standard output | standard input | Python 3 | Python | 1,200 | train_000.jsonl | ba02b91aebce084f69fa4733b4496ca0 | 256 megabytes | ["6 1\npolice\np m", "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b"] | PASSED | import string
t = string.ascii_lowercase
t2 = list(t)
#print(t2)
n , m = map(int,input().split())
s = input()
for i in range(m):
x , y = input().split()
index_x = t2.index(x)
index_y = t2.index(y)
t2[index_x] , t2[index_y] = t2[index_y] , t2[index_x]
#print(t2)
for i in s :
index = ord(i) - ord('... | 1445763600 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["1\n2\n3\n3\n3\n3\n3", "1\n1\n1\n1\n1\n1\n4\n4", "1\n1\n1\n1\n1", "0\n1\n1\n1\n2\n2\n2\n3\n3\n3\n3\n4\n4\n4\n4\n4\n4\n4\n5"] | 10e6b62d5b1abf8e1ba964a38dc6a9e8 | NoteIn the first example: For $$$i = 1$$$, we can just apply one operation on $$$A_1$$$, the final states will be $$$1010110$$$; For $$$i = 2$$$, we can apply operations on $$$A_1$$$ and $$$A_3$$$, the final states will be $$$1100110$$$; For $$$i \ge 3$$$, we can apply operations on $$$A_1$$$, $$$A_2$$$ and $$$A_3$... | There are $$$n$$$ lamps on a line, numbered from $$$1$$$ to $$$n$$$. Each one has an initial state off ($$$0$$$) or on ($$$1$$$).You're given $$$k$$$ subsets $$$A_1, \ldots, A_k$$$ of $$$\{1, 2, \dots, n\}$$$, such that the intersection of any three subsets is empty. In other words, for all $$$1 \le i_1 < i_2 < i... | You must output $$$n$$$ lines. The $$$i$$$-th line should contain a single integer $$$m_i$$$ — the minimum number of operations required to make the lamps $$$1$$$ to $$$i$$$ be simultaneously on. | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 3 \cdot 10^5$$$). The second line contains a binary string of length $$$n$$$, representing the initial state of each lamp (the lamp $$$i$$$ is off if $$$s_i = 0$$$, on if $$$s_i = 1$$$). The description of each one of the $$$k$$$ subsets follow... | standard output | standard input | PyPy 2 | Python | 2,400 | train_023.jsonl | 5651c446583302149fd707727055a007 | 256 megabytes | ["7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2", "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19"] | PASSED | import sys
range = xrange
input = raw_input
n, k = [int(x) for x in input().split()]
A = [+(c == '0') for c in input()]
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
B = []
for _ in range(k):
m = inp[ii]; ii += 1
B.append([a - 1 for a in inp[ii: ii + m]]); ii += m
buckets = [[] for _ in range(n)]... | 1580652300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["DA\nNET\nNET"] | 046900001c7326fc8d890a22fa7267c9 | NoteIn the first test case after Alice's move string $$$s$$$ become empty and Bob can not make any move.In the second test case Alice can not make any move initially.In the third test case after Alice's move string $$$s$$$ turn into $$$01$$$. Then, after Bob's move string $$$s$$$ become empty and Alice can not make any... | Alica and Bob are playing a game.Initially they have a binary string $$$s$$$ consisting of only characters 0 and 1.Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent ch... | For each test case print answer in the single line. If Alice can win print DA (YES in Russian) in any register. Otherwise print NET (NO in Russian) in any register. | First line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Only line of each test case contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$), consisting of only characters 0 and 1. | standard output | standard input | PyPy 3 | Python | 900 | train_001.jsonl | 776c2e91e043e68aff6d1fe786090703 | 256 megabytes | ["3\n01\n1111\n0011"] | PASSED | for _ in range(int(input())):
s = input()
s=list(s)
if min(s.count('0'),s.count('1'))%2==0:
print("NET")
else:
print("DA")
| 1593095700 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
3 seconds | ["1", "2", "0", "7"] | b50df0e6d91d538cd7db8dfdc7cd5266 | NoteIn the first example you should remove the segment $$$[3;3]$$$, the intersection will become $$$[2;3]$$$ (length $$$1$$$). Removing any other segment will result in the intersection $$$[3;3]$$$ (length $$$0$$$).In the second example you should remove the segment $$$[1;3]$$$ or segment $$$[2;6]$$$, the intersection ... | You are given $$$n$$$ segments on a number line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.The intersection of a sequence of segments is such a maximal set of points (not necesserily ha... | Print a single integer — the maximal possible length of the intersection of $$$(n - 1)$$$ remaining segments after you remove exactly one segment from the sequence. | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) — the number of segments in the sequence. Each of the next $$$n$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$0 \le l_i \le r_i \le 10^9$$$) — the description of the $$$i$$$-th segment. | standard output | standard input | Python 3 | Python | 1,600 | train_017.jsonl | 76939e7684a7d63db408cf8b5ed7cc24 | 256 megabytes | ["4\n1 3\n2 6\n0 4\n3 3", "5\n2 6\n1 3\n0 4\n1 20\n0 4", "3\n4 5\n1 2\n9 20", "2\n3 10\n1 5"] | PASSED | n=int(input())
l,r,s=[],[],[]
for i in range(n):
a,b=map(int,input().split())
l.append(a)
r.append(b)
s.append((a,b))
l=sorted(l)[::-1]
r=sorted(r)
if (l[0],r[0]) in s:
print(max(r[1]-l[1],0))
else:
print(max(r[0]-l[1],r[1]-l[0],0))
| 1535122200 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["First\n2\n\n3"] | 351c6fb0a9d1bbb29387c5b7ce8c7f28 | NoteIn the sample input, the piles initially have $$$5$$$, $$$2$$$, and $$$6$$$ stones. Harris decides to go first and provides the number $$$2$$$ to Anton. Anton adds $$$2$$$ stones to the third pile, which results in $$$5$$$, $$$2$$$, and $$$8$$$.In the next turn, Harris chooses $$$3$$$. Note that Anton cannot add th... | This is an interactive problem.Anton and Harris are playing a game to decide which of them is the king of problemsetting.There are three piles of stones, initially containing $$$a$$$, $$$b$$$, and $$$c$$$ stones, where $$$a$$$, $$$b$$$, and $$$c$$$ are distinct positive integers. On each turn of the game, the following... | null | The first line of input contains three distinct positive integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — the initial number of stones in piles $$$1$$$, $$$2$$$, and $$$3$$$ respectively. | standard output | standard input | PyPy 3 | Python | 2,600 | train_014.jsonl | 822d93a7d953ac332a05a6715b77adb1 | 256 megabytes | ["5 2 6\n\n\n3\n\n0"] | PASSED | l = list(map(int, input().split()))
def play(x):
global s
res = int(input(str(x)+'\n'))
if res == 0: exit(0)
l[res-1] += x
s = sorted(l)
BIG = 10**11
print("First")
play(BIG)
play(s[2]*2-s[1]-s[0])
play(s[1]-s[0])
| 1593873900 | [
"math",
"games"
] | [
1,
0,
0,
1,
0,
0,
0,
0
] | |
0.5 seconds | ["24"] | d41aebacfd5d16046db7c5d339478115 | null | Because of budget cuts one IT company established new non-financial reward system instead of bonuses.Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting f... | Output one integer — the amount of ways to place the pennants on n tables. | The only line of the input contains one integer n (1 ≤ n ≤ 500) — the number of tables in the IT company. | standard output | standard input | PyPy 2 | Python | 1,600 | train_020.jsonl | 22c9c58d3b882f311742bd306135cd9b | 64 megabytes | ["2"] | PASSED | W = int(raw_input())
def ncr(n, r):
res = 1
for i in xrange(r + 1, n + 1):
res *= i
for i in xrange(1, n - r + 1):
res /= i
return res
print ncr(W + 5 - 1, W - 1) * ncr(W + 3 - 1, W - 1) | 1455807600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1", "2"] | 19ba94b8d223cc153d387287ce50ee1a | NoteIn the first example the only subsegment is [1]. The sum equals 1, the product equals 1, so it suits us because .There are two suitable subsegments in the second example — [6, 3] and [3, 8, 1]. Subsegment [6, 3] has sum 9 and product 18, so it suits us because . Subsegment [3, 8, 1] has sum 12 and product 24, so it... | Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that , where p is the product of all integers on the given array, s is their sum, and k is a given constant for all s... | In the only line print the number of subsegments such that the ratio between the product and the sum on them is equal to k. | The first line contains two integers n and k (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 105), where n is the length of the array and k is the constant described above. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 108) — the elements of the array. | standard output | standard input | PyPy 2 | Python | 2,100 | train_037.jsonl | c3ff6ae8c18b9fe0ad5a212085705336 | 256 megabytes | ["1 1\n1", "4 2\n6 3 8 1"] | PASSED | from sys import stdin
import math
# stdin = open('in')
n, k = map(int, stdin.readline().split())
a = [int(x) for x in stdin.readline().split()]
nxt = [-1]*n
pref = []
f, s = -1, 0
for i in range(n):
s += a[i]
pref.append(s)
nxt[n-1-i] = f
if a[n-1-i] != 1:
f = n-1-i
ans = 0
for i in range(n):
pos, cur = i, 0
p... | 1529339700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["021", "001122", "211200", "120120"] | cb852bf0b62d72b3088969ede314f176 | null | You are given a string $$$s$$$ consisting of exactly $$$n$$$ characters, and each character is either '0', '1' or '2'. Such strings are called ternary strings.Your task is to replace minimum number of characters in this string with other characters to obtain a balanced ternary string (balanced ternary string is a terna... | Print one string — the lexicographically (alphabetically) smallest balanced ternary string which can be obtained from the given one with minimum number of replacements. Because $$$n$$$ is divisible by $$$3$$$ it is obvious that the answer exists. And it is obvious that there is only one possible answer. | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 3 \cdot 10^5$$$, $$$n$$$ is divisible by $$$3$$$) — the number of characters in $$$s$$$. The second line contains the string $$$s$$$ consisting of exactly $$$n$$$ characters '0', '1' and '2'. | standard output | standard input | Python 3 | Python | 1,500 | train_018.jsonl | 22230f3a8327ac73dffa4cbdf718b9d8 | 256 megabytes | ["3\n121", "6\n000000", "6\n211200", "6\n120110"] | PASSED | n = int(input())
s = list(input())
d = {i:0 for i in '012'}
for i in s:
d[i] += 1
eq = n // 3
i = 0
while d['0'] < eq:
if s[i] != '0':
if d[s[i]] > eq:
d[s[i]] -= 1
d['0'] += 1
s[i] = '0'
i += 1
i = n - 1
while d['2'] < eq:
if s[i] != '2':
if d[s[i]] >... | 1547044500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["1\n9\n6\n35\n112"] | eaab346f1dd620c8634a7991fa581bff | NoteIn the first test case, there is the only substring ")". Its cost is $$$1$$$ because we can insert '(' to the beginning of this substring and get a string "()", that is a balanced string.In the second test case, the cost of each substring of length one is $$$1$$$. The cost of a substring ")(" is $$$1$$$ because we ... | Daemon Targaryen decided to stop looking like a Metin2 character. He turned himself into the most beautiful thing, a bracket sequence.For a bracket sequence, we can do two kind of operations: Select one of its substrings$$$^\dagger$$$ and cyclic shift it to the right. For example, after a cyclic shift to the right, "(... | For each test case, print a single integer — the sum of costs of all substrings of $$$s$$$. | Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the bracket sequen... | standard output | standard input | PyPy 3-64 | Python | 2,400 | train_101.jsonl | 4abecb950b6e32430d8f119b093f8a8a | 256 megabytes | ["5\n\n1\n\n)\n\n4\n\n)()(\n\n3\n\n())\n\n5\n\n(((((\n\n10\n\n)(())))())"] | PASSED | import os,sys
from random import randint, shuffle
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, permutations
import math
# Fast... | 1667745300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["2\n11\n14\n29\n80\n100\n100\n100\n118\n190\n196\n3000000094\n3000060094\n3000060400\n3000060952\n3000061270\n3000061366\n3000061366"] | d15cffca07768f8ce6fab7e13a6e7976 | NoteIn the first test case, the array $$$a = [2]$$$ after the first query.In the third test case, the array $$$a$$$ is modified as follows: $$$[1, 3, 2, 4, 10, 48]$$$ $$$\rightarrow$$$ $$$[7, 9, 2, 4, 10, 48]$$$ $$$\rightarrow$$$ $$$[7, 9, 7, 9, 15, 53]$$$ $$$\rightarrow$$$ $$$[7, 9, 7, 9, 15, 53]$$$ $$$\rightarrow$$$ ... | You are given $$$n$$$ of integers $$$a_1, a_2, \ldots, a_n$$$. Process $$$q$$$ queries of two types: query of the form "0 $$$x_j$$$": add the value $$$x_j$$$ to all even elements of the array $$$a$$$, query of the form "1 $$$x_j$$$": add the value $$$x_j$$$ to all odd elements of the array $$$a$$$.Note that when proces... | For each test case, print $$$q$$$ numbers: the sum of the elements of the array $$$a$$$ after processing a query. | The first line of the input contains an integer $$$t$$$ $$$(1 \leq t \leq 10^4$$$) — the number of test cases. The descriptions of the test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n$$$, $$$q \leq 10^5$$$) — the length of array $$$a$$$ and the number of queries... | standard output | standard input | PyPy 3-64 | Python | 800 | train_094.jsonl | fab543a1be575a368d7f292c5d70f849 | 256 megabytes | ["4\n\n1 1\n\n1\n\n1 1\n\n3 3\n\n1 2 4\n\n0 2\n\n1 3\n\n0 5\n\n6 7\n\n1 3 2 4 10 48\n\n1 6\n\n0 5\n\n0 4\n\n0 5\n\n1 3\n\n0 12\n\n0 1\n\n6 7\n\n1000000000 1000000000 1000000000 11 15 17\n\n0 17\n\n1 10000\n\n1 51\n\n0 92\n\n0 53\n\n1 16\n\n0 1"] | PASSED | t = int(input())
for _ in range(t):
n, q = [int(i) for i in input().split()]
a = [int(j) for j in input().split()]
n0 = 0
n1 = 0
suma = sum(a)
for j in range(n):
if a[j] % 2 == 0:
n0 += 1
else:
n1 += 1
for _ in range(q):
operation, number = [in... | 1665930900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["2", "0", "1"] | 02b0ffb0045fc0a2c8613c8ef58ed2c8 | NoteIn the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.In the third example Polycarpus exactly knows that the hidde... | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in... | Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. | The first line contains one integer n (1 ≤ n ≤ 50) — the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the p... | standard output | standard input | PyPy 2 | Python | 1,500 | train_016.jsonl | 5f9d9239677c5cd147e3ba64c786d8e5 | 256 megabytes | ["4\na**d\n2\nabcd\nacbd", "5\nlo*er\n2\nlover\nloser", "3\na*a\n2\naaa\naba"] | PASSED | n = int(raw_input())
s = str(raw_input())
m = int(raw_input())
cur = set(s)
st = None
for i in range(m):
t = str(raw_input())
#check first if t is possible
ch = ''.join(i if i in s else '*' for i in t)
if ch == s:
if st is None:
st = set(t)
else:
st.intersection_u... | 1508573100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["baaaab", "daarkkcyan", "darkcyan"] | 9463dd8f054eeaeeeeaec020932301c3 | NoteThe images below present the tree for the examples. The number in each node is the node number, while the subscripted letter is its label. To the right is the string representation of the tree, with each letter having the same color as the corresponding node.Here is the tree for the first example. Here we duplicate... | A binary tree of $$$n$$$ nodes is given. Nodes of the tree are numbered from $$$1$$$ to $$$n$$$ and the root is the node $$$1$$$. Each node can have no child, only one left child, only one right child, or both children. For convenience, let's denote $$$l_u$$$ and $$$r_u$$$ as the left and the right child of the node $$... | Print a single line, containing the lexicographically smallest string representation of the tree if at most $$$k$$$ nodes have their labels duplicated. | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). The second line contains a string $$$c$$$ of $$$n$$$ lower-case English letters, where $$$c_i$$$ is the initial label of the node $$$i$$$ for $$$1 \le i \le n$$$. Note that the given string $$$c$$$ is not the initial string... | standard output | standard input | PyPy 3-64 | Python | 2,500 | train_106.jsonl | be872f2351a7ebb25a1501c96898387d | 256 megabytes | ["4 3\nabab\n2 3\n0 0\n0 4\n0 0", "8 2\nkadracyn\n2 5\n3 4\n0 0\n0 0\n6 8\n0 7\n0 0\n0 0", "8 3\nkdaracyn\n2 5\n0 3\n0 4\n0 0\n6 8\n0 7\n0 0\n0 0"] | PASSED | import sys
I=lambda:[*map(int, sys.stdin.readline().split())]
left = []
right = []
n, k = I()
parents = [-1] * n
s = input()
for i in range(n):
l, r = I()
l -= 1
r -= 1
left.append(l)
right.append(r)
if l >= 0:
parents[l] = i
if r >= 0:
parents[r] = i
covered = [0] * n
covered.append(1)... | 1640698500 | [
"strings",
"trees"
] | [
0,
0,
0,
0,
0,
0,
1,
1
] | |
2 seconds | ["4"] | 38bee9c2b21d2e91fdda931c8cacf204 | NoteIn the sample the longest chain the Donkey can build consists of four stars. Note that the Donkey can't choose the stars that lie on the rays he imagines. | In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the Donkey's stars were to the left. Most days the Donkey would just count the... | In a single line print number m — the answer to the problem. | The first line contains an integer n (1 ≤ n ≤ 105) — the number of stars. The second line contains simple fractions representing relationships "a/b c/d", such that and (0 ≤ a, b, c, d ≤ 105; ; ; ). The given numbers a, b, c, d are integers. Next n lines contain pairs of integers xi, yi (1 ≤ xi, yi ≤ 105)— the stars' ... | standard output | standard input | Python 3 | Python | 2,700 | train_024.jsonl | f7de2c566f0a15379fec35e1945f4fe1 | 256 megabytes | ["15\n1/3 2/1\n3 1\n6 2\n4 2\n2 5\n4 5\n6 6\n3 4\n1 6\n2 1\n7 4\n9 3\n5 3\n1 3\n15 5\n12 4"] | PASSED | import bisect
def INPUT():
global n, a, b, c, d
n = int(input())
a, b, c, d = [int(j) for i in input().split() for j in i.split("/")]
global y_alpha
y_alpha = []
for _ in range(n):
x, y = [int(x) for x in input().split()]
y_alpha.append((b * y - a * x, c * x - d * y))
if __name__ == '__main__':
INPUT()
y... | 1353857400 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1\n1\n3\n3\n3\n6", "1\n2\n3\n4\n5\n5\n6\n8"] | 29bc7a22baa3dc6bb508b00048e50114 | NoteThe explanation for the first test case:In this explanation, the circles and the numbers in them denote a person with the corresponding number. The line denotes that William introduced two connected people. The person marked with red has the most acquaintances. These are not the only correct ways to introduce peopl... | William arrived at a conference dedicated to cryptocurrencies. Networking, meeting new people, and using friends' connections are essential to stay up to date with the latest news from the world of cryptocurrencies.The conference has $$$n$$$ participants, who are initially unfamiliar with each other. William can intr... | Output $$$d$$$ integers. $$$i$$$th number must equal the number of acquaintances the person with the maximal possible acquaintances will have, if William performed $$$i$$$ introductions and satisfied the first $$$i$$$ conditions. | The first line contains two integers $$$n$$$ and $$$d$$$ ($$$2 \le n \le 10^3, 1 \le d \le n - 1$$$), the number of people, and number of conditions, respectively. Each of the next $$$d$$$ lines each contain two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n, x_i \neq y_i$$$), the numbers of people which mus... | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_110.jsonl | 57aab1d4fc2365bdfd01e1e55fe8eb24 | 256 megabytes | ["7 6\n1 2\n3 4\n2 4\n7 6\n6 5\n1 7", "10 8\n1 2\n2 3\n3 4\n1 4\n6 7\n8 9\n8 10\n1 4"] | PASSED | from collections import defaultdict
n = (10 ** 3)+10
parent = [i for i in range(n)]
size = [1 for i in range(n)]
def find(root):
a = root
while parent[a] != a:
a = parent[a]
# path comprehension
while root != a:
nextnode = parent[root]
parent[root] = a
r... | 1638110100 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
3 seconds | ["3\n1 1 1 5\n1 5 8 5\n8 5 8 6"] | f0bd06345a2aeeb5faedc824fb5f42b9 | NoteThe points and the segments from the example are shown below. | You are given three points on a plane. You should choose some segments on the plane that are parallel to coordinate axes, so that all three points become connected. The total length of the chosen segments should be the minimal possible.Two points $$$a$$$ and $$$b$$$ are considered connected if there is a sequence of po... | On the first line output $$$n$$$ — the number of segments, at most 100. The next $$$n$$$ lines should contain descriptions of segments. Output four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ on a line — the coordinates of the endpoints of the corresponding segment ($$$-10^9 \le x_1, y_1, x_2, y_2 \le 10^9$$$).... | The input consists of three lines describing three points. Each line contains two integers $$$x$$$ and $$$y$$$ separated by a space — the coordinates of the point ($$$-10^9 \le x, y \le 10^9$$$). The points are pairwise distinct. | standard output | standard input | Python 3 | Python | 1,800 | train_091.jsonl | 84d346b43dc19930e6c92c4fb69b4e38 | 512 megabytes | ["1 1\n3 5\n8 6"] | PASSED | # -- coding: utf-8 --
'''
Author: your name
Date: 2022-01-03 20:13:21
LastEditTime: 2022-05-28 17:47:53
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: /code_everyWeek/week6.py
'''
class Point():
def __init__(self, x, y):
self.x = x
self.y = y
def connect_t... | 1649837100 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["0 2 1", "0 0 1 1", "0"] | a2085c2d21b2dbe4cc27a15fa4a1ec4f | NoteIn the first example pages of the Death Note will look like this $$$[1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]$$$. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during ... | You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during $$$n$$$ consecutive days. During the $$$i$$$-th day you have to write exactly $$$a_i$$$ names.". You got sc... | Print exactly $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$, where $$$t_i$$$ is the number of times you will turn the page during the $$$i$$$-th day. | The first line of the input contains two integers $$$n$$$, $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le m \le 10^9$$$) — the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a... | standard output | standard input | PyPy 3 | Python | 900 | train_000.jsonl | 3794a6ddf45465943e15bd3e76dc57e9 | 256 megabytes | ["3 5\n3 7 9", "4 20\n10 9 19 2", "1 100\n99"] | PASSED | inp = input()
n, m = inp.split()
n = int(n)
m = int(m)
inp = input()
a = inp.split()
remainder = 0
for aith in a:
names = int(aith)
if names == 0:
print(0, end=" ")
else:
pages = int((names + remainder) / m)
remainder = (names + remainder) % m
print(pages, end=" ") | 1533307500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["possible", "impossible"] | f217337f015224231e64a992329242e8 | NoteIn the first sample, a possible choice for the values of the $$$a_i$$$ is $$$3, 4, 3, 5, 2$$$. On the first day, Dora buys the integers $$$3, 4$$$ and $$$3$$$, whose LCM is $$$12$$$, while Swiper buys integers $$$5$$$ and $$$2$$$, whose LCM is $$$10$$$. On the second day, Dora buys $$$3, 5$$$ and $$$2$$$, whose LCM... | Dora the explorer has decided to use her money after several years of juicy royalties to go shopping. What better place to shop than Nlogonia?There are $$$n$$$ stores numbered from $$$1$$$ to $$$n$$$ in Nlogonia. The $$$i$$$-th of these stores offers a positive integer $$$a_i$$$.Each day among the last $$$m$$$ days Dor... | Output must consist of a single line containing "possible" if there exist positive integers $$$a_i$$$ such that for each day the least common multiple of the integers bought by Dora is strictly greater than the least common multiple of the integers bought by Swiper on that day. Otherwise, print "impossible". Note that ... | The first line contains integers $$$m$$$ and $$$n$$$ ($$$1\leq m \leq 50$$$, $$$1\leq n \leq 10^4$$$) — the number of days and the number of stores. After this $$$m$$$ lines follow, the $$$i$$$-th line starts with an integer $$$s_i$$$ ($$$1\leq s_i \leq n-1$$$), the number of integers Dora bought on day $$$i$$$, follow... | standard output | standard input | PyPy 3 | Python | 2,100 | train_008.jsonl | f4241da82851c9d5c18d446465251ee7 | 256 megabytes | ["2 5\n3 1 2 3\n3 3 4 5", "10 10\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10"] | PASSED | # https://codeforces.com/problemset/problem/1166/E
def push(d, x):
if x not in d:
d[x]=0
d[x]+=1
def check(a, i, j):
for x in a[i]:
d[x]+=1
for x in a[j]:
d[x]+=1
for val in d:
if val==2:
refresh()
return True
re... | 1558105500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
4 seconds | ["2 2\n4 6\n12 12\n-1 -1\n-1 -1\n373248 730\n-1 -1\n15120 53760\n-1 -1\n536870912 536870912"] | 27be78f2739b681b25c331c60fc2b22b | null | This is an hard version of the problem. The only difference between an easy and a hard version is the constraints on $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$.You are given $$$4$$$ positive integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ with $$$a < c$$$ and $$$b < d$$$. Find any pair of numbers $$$x$$$ and $$$y$$$ that ... | For each test case print a pair of numbers $$$a < x \leq c$$$ and $$$b < y \leq d$$$ such that $$$x \cdot y$$$ is divisible by $$$a \cdot b$$$. If there are multiple answers, print any of them. If there is no such pair of numbers, then print -1 -1. | The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10$$$), the number of test cases. The descriptions of the test cases follow. The only line of each test case contains four integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$1 \leq a < c \leq 10^9$$$, $$$1 \leq b < d \leq 10^9$$$). | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_094.jsonl | d41410cfe389f53b145fceb776a55cf8 | 256 megabytes | ["10\n\n1 1 2 2\n\n3 4 5 7\n\n8 9 15 18\n\n12 21 14 24\n\n36 60 48 66\n\n1024 729 373248 730\n\n1024 729 373247 730\n\n5040 40320 40319 1000000000\n\n999999999 999999999 1000000000 1000000000\n\n268435456 268435456 1000000000 1000000000"] | PASSED | ceil = lambda a, b: (((a) + ((b) - 1)) // (b))
def make_divisors(n):
divisors = []
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
# divisors.sort()
return divisors
q = int(input... | 1665930900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["3", "2"] | a628b6606c977059dca6d8dd05de99d4 | NoteIn the first sample periodic numbers are 3, 7 and 10.In the second sample periodic numbers are 31 and 36. | A non-empty string s is called binary, if it consists only of characters "0" and "1". Let's number the characters of binary string s from 1 to the string's length and let's denote the i-th character in string s as si.Binary string s with length n is periodical, if there is an integer 1 ≤ k < n such that: k is a di... | Print a single integer, showing how many periodic numbers are in the interval from l to r (both ends are included). | The single input line contains two integers l and r (1 ≤ l ≤ r ≤ 1018). The numbers are separated by a space. 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. | standard output | standard input | Python 2 | Python | 2,100 | train_013.jsonl | dd289908a5bdadfddea25262106c87ad | 256 megabytes | ["1 10", "25 38"] | PASSED | import math
def tree_search(l, u, x, a, b):
if u == l:
if check_upper(u, a, b, x):
return u
else:
return u-1
if u - l <= 1:
if check_upper(u, a, b, x):
return u
elif check_upper(l, a, b, x):
return l
else:
retu... | 1344267000 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
2 seconds | ["4", "860616440"] | c602545676f6388a5c5107a5d83fc2c6 | NoteAn example of a valid set S is {00000, 00101, 00010, 00111, 11000, 11010, 11101, 11111}. | You are given an integer m.Let M = 2m - 1.You are also given a set of n integers denoted as the set T. The integers will be provided in base 2 as n binary strings of length m.A set of integers S is called "good" if the following hold. If , then . If , then All elements of S are less than or equal to M. Here, an... | Print a single integer, the number of good sets modulo 109 + 7. | The first line will contain two integers m and n (1 ≤ m ≤ 1 000, 1 ≤ n ≤ min(2m, 50)). The next n lines will contain the elements of T. Each line will contain exactly m zeros and ones. Elements of T will be distinct. | standard output | standard input | Python 3 | Python | 2,500 | train_068.jsonl | 723c91ddc44a78810fbb2eb203f64390 | 256 megabytes | ["5 3\n11010\n00101\n11000", "30 2\n010101010101010010101010101010\n110110110110110011011011011011"] | PASSED | MOD = 10**9 + 7
m, N = map(int, input().split())
binom = [[1] + [0 for i in range(m)] for j in range(m + 1)]
for n in range(1, m + 1):
for k in range(1, n + 1):
binom[n][k] = (binom[n - 1][k] + binom[n - 1][k - 1]) % MOD
bell = [0 for n in range(m + 1)]
bell[0] = bell[1] = 1
for n in range(1, m):
for ... | 1514562000 | [
"math"
] | [
0,
0,
0,
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.