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 | ["2\nHe\nllo", "2\nCodef\norces", "-1", "8\na\nb\na\nc\na\nb\na\nc"] | c4da69789d875853beb4f92147825ebf | null | You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q.For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".Note it is allowed to split the string s to the strings only of length p or to ... | If it's impossible to split the string s to the strings of length p and q print the only number "-1". Otherwise in the first line print integer k — the number of strings in partition of s. Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be ... | The first line contains three positive integers n, p, q (1 ≤ p, q ≤ n ≤ 100). The second line contains the string s consists of lowercase and uppercase latin letters and digits. | standard output | standard input | Python 2 | Python | 1,300 | train_002.jsonl | 4205f4d3a382ebdccbd3cc69b628b592 | 256 megabytes | ["5 2 3\nHello", "10 9 5\nCodeforces", "6 4 5\nPrivet", "8 1 1\nabacabac"] | PASSED | def divide(n, k, s, t):
array = []
for j in xrange(k, len(s) - t, n):
mini = s[j:j + n]
#print "mini " + mini + str(len(mini))
if len(mini) == n:
array.append(mini)
return array
def splitter():
n, p, q =[int(x) for x in raw_input().split()]
text = raw_input()
... | 1451055600 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["0 0\n4 2 2 1 4\n5 4 2 2 1 5"] | b7f81193098e573cde08f33572a87dc8 | NoteIn the second test case: For the length $$$0$$$: $$$[4, 2, 1, 3] \rightarrow [4, 2, 1, 3]$$$: $$$4$$$ inversions. For the length $$$1$$$: $$$[4, 2, \mathbf{1}, 3] \rightarrow [1, 4, 2, 3]$$$: $$$2$$$ inversions. For the length $$$2$$$: $$$[4, \mathbf{2}, \mathbf{1}, 3] \rightarrow [2, 1, 4, 3]$$$, or $$$[4, 2, ... | You are given a permutation $$$p$$$ of length $$$n$$$.You can choose any subsequence, remove it from the permutation, and insert it at the beginning of the permutation keeping the same order.For every $$$k$$$ from $$$0$$$ to $$$n$$$, find the minimal possible number of inversions in the permutation after you choose a s... | For each test case output $$$n + 1$$$ integers. The $$$i$$$-th of them must be the answer for the subsequence length of $$$i - 1$$$. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 50\,000$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the length of the permutation. The second line of each test case contains the permutation $$$p_1, p_2, \ldots, p_n$$$ ... | standard output | standard input | PyPy 3 | Python | 3,500 | train_090.jsonl | a0a9c8f9306b988006d37759c833d6ea | 256 megabytes | ["3\n1\n1\n4\n4 2 1 3\n5\n5 1 3 2 4"] | PASSED | import sys
I=lambda:[*map(int,sys.stdin.readline().split())]
def mergeinv(l):
if len(l) == 1:
return [0, l]
mid = len(l) // 2
x, l1 = mergeinv(l[:mid])
y, l2 = mergeinv(l[mid:])
ind1 = 0
ind2 = 0
out = []
invs = x + y
while ind1 < len(l1) or ind2 < len(l2):
if ind1 == len(l1):
out.append... | 1644676500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["121", "0"] | 0ed34310c59e3946b1c55b2618218120 | NotePicture corresponding to the first example: You can choose the vertex $$$3$$$ as a root, then the answer will be $$$2 \cdot 9 + 1 \cdot 4 + 0 \cdot 1 + 3 \cdot 7 + 3 \cdot 10 + 4 \cdot 1 + 4 \cdot 6 + 4 \cdot 5 = 18 + 4 + 0 + 21 + 30 + 4 + 24 + 20 = 121$$$.In the second example tree consists only of one vertex so t... | You are given a tree consisting exactly of $$$n$$$ vertices. Tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a value $$$a_v$$$ assigned to it.Let $$$dist(x, y)$$$ be the distance between the vertices $$$x$$$ and $$$y$$$. The distance between the vertices is the number of ... | Print one integer — the maximum possible cost of the tree if you can choose any vertex as $$$v$$$. | The first line contains one integer $$$n$$$, the number of vertices in the tree ($$$1 \le n \le 2 \cdot 10^5$$$). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the value of the vertex $$$i$$$. Each of the next $$$n - 1$$$ lines d... | standard output | standard input | PyPy 2 | Python | 1,900 | train_006.jsonl | ad526519ee7dd2c5c078d828963b8442 | 256 megabytes | ["8\n9 4 1 7 10 1 6 5\n1 2\n2 3\n1 4\n1 5\n5 6\n5 7\n5 8", "1\n1337"] | PASSED | import sys,math
from collections import defaultdict
from io import BytesIO
sys.stdin = BytesIO(sys.stdin.read())
sys.setrecursionlimit(200200)
input = lambda: sys.stdin.readline().rstrip('\r\n')
n = int(input())
arr = [0] + [int(x) for x in input().split(' ')]
cnts = [0] * (n+1)
sv = set()
dn = defaultdict(set)
for _... | 1545143700 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["1\n9\n4"] | 47e5ccd8220afa84c95f36b08ed1817a | NoteIn the first test case, the grid is $$$1\times 1$$$, so the only possible choice for $$$h, w$$$ is $$$h = 1, w = 1$$$, giving an area of $$$h\cdot w = 1$$$.The grid from the second test case is drawn in the statement. It can be shown that with $$$h = 3, w = 3$$$ Michael can guarantee the victory and that any choice... | Michael and Joe are playing a game. The game is played on a grid with $$$n$$$ rows and $$$m$$$ columns, filled with distinct integers. We denote the square on the $$$i$$$-th ($$$1\le i\le n$$$) row and $$$j$$$-th ($$$1\le j\le m$$$) column by $$$(i, j)$$$ and the number there by $$$a_{ij}$$$.Michael starts by saying tw... | For each test case print a single positive integer — the minimum possible area the subrectangle can have while still ensuring that Michael can guarantee the victory. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 20$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 40$$$) — the size of the grid. Each of the following $$$n$$$ line... | standard output | standard input | Python 3 | Python | 800 | train_089.jsonl | 37cdafff19d4db8d5e12e77de28f4617 | 256 megabytes | ["3\n\n1 1\n\n3\n\n4 4\n\n2 12 6 10\n\n3 15 16 4\n\n1 13 8 11\n\n14 7 9 5\n\n2 3\n\n-7 5 2\n\n0 8 -3"] | PASSED | class Subrectangle():
def __init__(self):
self.create_cases()
def create_cases(self):
self.row_col_array = []
self.subrectangle_array = []
self.cases_num = int(input())
for i in range(self.cases_num):
self.grid_row,self.grid_column = map(int,input().... | 1655562900 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
1 second | ["2\n1\n4"] | 504613b285d10fbf1e45b9c4ace25865 | NoteThe first test case is pictured in the statement. Only the subtrees at vertices $$$2$$$ and $$$3$$$ are balanced.In the second test case, only the subtree at vertex $$$1$$$ is balanced.In the third test case, only the subtrees at vertices $$$1$$$, $$$3$$$, $$$5$$$, and $$$7$$$ are balanced. | You are given a rooted tree consisting of $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$. The root is vertex $$$1$$$. There is also a string $$$s$$$ denoting the color of each vertex: if $$$s_i = \texttt{B}$$$, then vertex $$$i$$$ is black, and if $$$s_i = \texttt{W}$$$, then vertex $$$i$$$ is white.A subtree of the... | For each test case, output a single integer — the number of balanced subtrees. | The first line of input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 4000$$$) — the number of vertices in the tree. The second line of each test case contains $$$n-1$$$ integers $$$a_2, \dots, a_n$$$ ($$$1 \... | standard output | standard input | PyPy 3-64 | Python | 1,300 | train_106.jsonl | b1be0b3d1583617e6e17976560aaf372 | 256 megabytes | ["3\n\n7\n\n1 1 2 3 3 5\n\nWBBWWBW\n\n2\n\n1\n\nBW\n\n8\n\n1 2 3 4 5 6 7\n\nBWBWBWBW"] | PASSED | # cook your dish here
#!/usr/bin/env python
from bisect import bisect_left
from cmath import inf
import os
from math import ceil, factorial, fmod,pi,sqrt,log
import sys
from collections import Counter
from io import BytesIO, IOBase, StringIO
sys.setrecursionlimit(4*10**4)
def modFact(n, p):
if n >= p:
... | 1652193900 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
3 seconds | ["2\n3\n1\n1"] | 0197047cab6d83a189a5c1eabf5b1dd3 | NoteIn the first query, for example, Orac can buy models with indices $$$2$$$ and $$$4$$$, the arrangement will be beautiful because $$$4$$$ is divisible by $$$2$$$ and $$$6$$$ is more than $$$3$$$. By enumerating, we can easily find that there are no beautiful arrangements with more than two models. In the second quer... | There are $$$n$$$ models in the shop numbered from $$$1$$$ to $$$n$$$, with sizes $$$s_1, s_2, \ldots, s_n$$$.Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with... | Print $$$t$$$ lines, the $$$i$$$-th of them should contain the maximum number of models that Orac can buy for the $$$i$$$-th query. | The first line contains one integer $$$t\ (1 \le t\le 100)$$$: the number of queries. Each query contains two lines. The first line contains one integer $$$n\ (1\le n\le 100\,000)$$$: the number of models in the shop, and the second line contains $$$n$$$ integers $$$s_1,\dots,s_n\ (1\le s_i\le 10^9)$$$: the sizes of mo... | standard output | standard input | Python 3 | Python | 1,400 | train_003.jsonl | 33a1acd12dcd538cb197580fd4f3c921 | 256 megabytes | ["4\n4\n5 3 4 6\n7\n1 4 2 3 6 4 9\n5\n5 4 3 2 1\n1\n9"] | PASSED | def DFC(maxm, u):
maxm += 1
e[u] = maxm
if len(st[u]) == 0:
maxms.append(maxm)
return 0
for i in st[u]:
if e[i] <= maxm:
DFC(maxm, i)
return 0
# list( map(int, input().split()) )
rw = int(input())
for ewqr in range(rw):
n = int(input())
maxms = []
max... | 1589286900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
0.5 seconds | ["8.000000000000 11.000000000000\n4.000000000000 8.000000000000\n6.000000000000 8.000000000000\n6.000000000000 3.000000000000\n10.000000000000 3.000000000000\n10.000000000000 8.000000000000\n12.000000000000 8.000000000000"] | 2cb1e7e4d25f624da934bce5c628a7ee | null | Petya has recently started working as a programmer in the IT city company that develops computer games.Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to pain... | Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9. | The only line of the input contains eight integers px, py, vx, vy ( - 1000 ≤ px, py, vx, vy ≤ 1000, vx2 + vy2 > 0), a, b, c, d (1 ≤ a, b, c, d ≤ 1000, a > c). | standard output | standard input | Python 3 | Python | 2,000 | train_004.jsonl | 152082200d523d447a9d0cd88a9f7e45 | 64 megabytes | ["8 8 0 2 8 3 4 5"] | PASSED | import math
def main():
x, y, vx, vy, a, b, c, d = map(int, input().split())
len = math.sqrt(vx * vx + vy * vy)
vx /= len
vy /= len
print(x + vx * b, y + vy * b)
print(x - vy * a / 2, y + vx * a / 2)
print(x - vy * c / 2, y + vx * c / 2)
print(x - vy * c / 2 - vx * d, y +... | 1455807600 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
3 seconds | ["2 1 1\n\n3 1 2\n\n3 2 1\n\n1 2 2"] | 7c721cdb8e5709bba242957344851d48 | NoteThe final grid from the sample is pictured below. Bob wins because there are no two adjacent cells with tokens of the same color. $$$$$$\begin{matrix}2&3\\3&1\end{matrix}$$$$$$The sample is only given to demonstrate the input and output format. It is not guaranteed to represent an optimal strategy for Bob o... | This is an interactive problem.Alice and Bob are playing a game. There is $$$n\times n$$$ grid, initially empty. We refer to the cell in row $$$i$$$ and column $$$j$$$ by $$$(i, j)$$$ for $$$1\le i, j\le n$$$. There is an infinite supply of tokens that come in $$$3$$$ colors labelled $$$1$$$, $$$2$$$, and $$$3$$$.The g... | null | null | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_100.jsonl | d803640f9805f25501d328aad0e6a76b | 256 megabytes | ["2\n1\n\n2\n\n1\n\n3"] | PASSED | n=int(input())
black=[]
white=[]
for i in range(1,n+1):
for j in range(1,n+1):
if (i+j)%2:
white.append((i,j))
else:
black.append((i,j))
move=0
while move<n**2:
p=int(input())
move+=1
if p==1:
if black:
x,y=black.pop()
... | 1617460500 | [
"games",
"graphs"
] | [
1,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["3 6 1 3\n1 9 4 9\n5 8 1 4\n1 5 3 5\n1 6 2 4\n1 2 2 3\n1 15 16 30"] | eadc7f5e1043ac431984ec921c62892d | NoteIn the first testcase $$$f(t) = f(1111) = 15$$$, $$$f(w) = f(101) = 5$$$.In the second testcase $$$f(t) = f(111000111) = 455$$$, $$$f(w) = f(000111) = 7$$$.In the third testcase $$$f(t) = f(0000) = 0$$$, $$$f(w) = f(1000) = 8$$$.In the fourth testcase $$$f(t) = f(11011) = 27$$$, $$$f(w) = f(011) = 3$$$.In the fifth... | Frodo was caught by Saruman. He tore a pouch from Frodo's neck, shook out its contents —there was a pile of different rings: gold and silver..."How am I to tell which is the One?!" the mage howled."Throw them one by one into the Cracks of Doom and watch when Mordor falls!" Somewhere in a parallel Middle-earth, when Sa... | For every test case print four integers $$$l_1$$$, $$$r_1$$$, $$$l_2$$$, $$$r_2$$$, which denote the beginning of the first substring, the end of the first substring, the beginning of the second substring, and the end of the second substring, respectively. If there are multiple solutions, print any. | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10^3$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^4$$$) — length of the string.... | standard output | standard input | Python 3 | Python | 1,500 | train_086.jsonl | a1e8064980c3b7e1c6c9170980741a4d | 256 megabytes | ["7\n6\n101111\n9\n111000111\n8\n10000000\n5\n11011\n6\n001111\n3\n101\n30\n100000000000000100000000000000"] | PASSED | for q in range(int(input())):
d = int(input())
n = " "+input()
if "0" in n:
c = n.index("0")
if c <= d//2:
print(c, d, c+1, d)
else:
print(1, c, 1, c-1)
else:
print(1, d//2, 2, d//2+1) | 1629988500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["yes\nyes\nyes\nno\nno"] | 324298100f3e36d289ef6ca8178ac6d3 | NoteSample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tourn... | There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each t... | For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes). | The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105). Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case. | standard output | standard input | Python 3 | Python | 1,700 | train_011.jsonl | 97d56821e671a2c3dc65bb60bbbbe955 | 256 megabytes | ["5\n3 0 0 0\n3 3 0 0\n6 4 1 0\n6 3 3 0\n3 3 3 2"] | PASSED | t = int(input())
for i in range(t):
n, k, a, b = map(int, input().split())
if n % 3 != 0:
print("no")
else:
for i in range(2):
for j in range(2):
flagf = False
if i == 0:
a1 = a
else:
a1 = -a
... | 1406215800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\n1\n-1\n0\n0"] | b8554e64b92b1b9458955da7d55eba62 | null | Polycarp has $$$n$$$ friends, the $$$i$$$-th of his friends has $$$a_i$$$ candies. Polycarp's friends do not like when they have different numbers of candies. In other words they want all $$$a_i$$$ to be the same. To solve this, Polycarp performs the following set of actions exactly once: Polycarp chooses $$$k$$$ ($$... | For each test case output: the minimum value of $$$k$$$, such that Polycarp can choose exactly $$$k$$$ friends so that he can redistribute the candies in the desired way; "-1" if no such value $$$k$$$ exists. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^4$$$). It is guaranteed that th... | standard output | standard input | Python 3 | Python | 800 | train_097.jsonl | 114cae61b97e82ef663f75804b11bbd0 | 256 megabytes | ["5\n4\n4 5 2 5\n2\n0 4\n5\n10 8 5 1 4\n1\n10000\n7\n1 1 1 1 1 1 1"] | PASSED | t=int(input())
for i in range(t):
n=int(input())
num = input().split()
num = [int(i) for i in num]
s=sum(num)
if s%n!=0:
print(-1)
else:
m=s//n
num1 = [1 for i in num if i>m]
print(sum(num1)) | 1623335700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1.5 seconds | ["? 1 2 3\n\n? 2 3 5\n\n? 4 1 5\n\n! 7", "-1"] | 5de2777a63c0c889da36c32df91744cf | NoteIn the first example interaction, the array $$$a_1, a_2, \ldots, a_n$$$ is $$$2, 1, 7, 5, 6$$$ and its XOR-sum is $$$7$$$. The first query made asks for indices $$$1,2,3$$$, so the response is $$$a_1 \oplus a_2 \oplus a_3 = 2 \oplus 1 \oplus 7 = 4$$$.The second query made asks for indices $$$2,3,5$$$, so the respon... | This is an interactive problem.Note: the XOR-sum of an array $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) is defined as $$$a_1 \oplus a_2 \oplus \ldots \oplus a_n$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Little Dormi received an array of $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ for Christm... | If it is impossible to recover the XOR-sum of the array, output $$$-1$$$ immediately after taking $$$n$$$ and $$$k$$$. Do not begin interaction. Otherwise, when your program finds the XOR-sum of the lost array $$$a_1, a_2, \ldots, a_n$$$, report the answer in the following format: "! x", where $$$x$$$ is the XOR sum of... | The only line of input contains the integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 500$$$, $$$1 \le k \le n$$$), the length of the lost array and the configured query size of the XOR machine. Elements of the original array satisfy $$$1 \le a_i \le 10^9$$$. It can be proven that that if it is possible to recover the XOR s... | standard output | standard input | PyPy 3 | Python | 2,300 | train_091.jsonl | 9ce5028c5c1cb040c2722a3ae409c71a | 256 megabytes | ["5 3\n\n4\n\n0\n\n1", "3 2"] | PASSED | from collections import deque
n, k = map(int,input().split())
if k%2==0 and n%2==1:
print(-1)
exit()
queue = deque()
visited = [ False for i in range(n)]
pre = [-1]*n
def getarr(add,front,rear,k,n):
nextrear = rear + (add + k)//2
nextfront = front + (k - add)//2
arr = [(i-1)%n + 1 for i in ra... | 1623598500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1\n16\n1\n14\n101\n1674"] | 90e94d3e0cfa770127f715469db03bbd | NoteFor the first test case, $$$00$$$ is the only possible starting state, and $$$11$$$ is the only possible ending state. It takes exactly one operation to change $$$00$$$ to $$$11$$$.For the second test case, some of the possible starting and ending state pairs are: $$$(000, 011)$$$ — takes $$$1$$$ operation. $$$(... | After getting bored by playing with crayons, you decided to switch to Legos! Today, you're working with a long strip, with height $$$1$$$ and length $$$n$$$, some positions of which are occupied by $$$1$$$ by $$$1$$$ Lego pieces.In one second, you can either remove two adjacent Lego pieces from the strip (if both are p... | For each test case, output a single integer — the answer to the problem modulo $$$1\,000\,000\,007$$$ ($$$10^9 + 7$$$). | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 2000$$$) — the size of the Lego strip. The second line of each test case contains a string $$$s$$$ of length $$$n$... | standard output | standard input | PyPy 3 | Python | 2,800 | train_100.jsonl | d14568f17f2341c480c30accfc8108ea | 512 megabytes | ["6\n2\n00\n11\n3\n???\n???\n3\n??1\n0?0\n4\n??0?\n??11\n5\n?????\n0??1?\n10\n?01??01?1?\n??100?1???"] | PASSED | ''' F. LEGOndary Grandmaster
https://codeforces.com/contest/1615/problem/F
'''
import io, os, sys
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # decode().strip() if str
output = sys.stdout.write
DEBUG = os.environ.get('debug') is not None
if DEBUG:
from inspect import currentframe, getframeinfo
... | 1640356500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\n2 1\n3 4\n1 4\nNO\nYES\n2 3\n1 2\n5 6\n6 2\n3 4"] | 65bb0f28d079ca94751048d326b3e1f1 | NoteIn the first test case, the tree looks as follows: In the second test case, there is only one possible tree with an edge between $$$1$$$ and $$$2$$$, and it does not satisfy the degree constraints.In the third test case, The tree on the left satisfies the degree constraints but the edges intersect internally, ... | There are $$$n$$$ nodes arranged in a circle numbered from $$$1$$$ to $$$n$$$ in the clockwise order. You are also given a binary string $$$s$$$ of length $$$n$$$.Your task is to construct a tree on the given $$$n$$$ nodes satisfying the two conditions below or report that there such tree does not exist: For each node... | For each test case, if there does not exist a tree that satisfies the given conditions, then output "NO" (without quotes), otherwise output "YES" followed by the description of tree. You can output each letter in any case (for example, "YES", "Yes", "yes", "yEs", "yEs" will be recognized as a positive answer). If there... | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 2\cdot 10^4)$$$ — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ $$$(2 \leq n \leq 2\cdot 10^5)$$$ — the number of nodes. T... | standard output | standard input | PyPy 3-64 | Python | 2,000 | train_101.jsonl | 17b9af18579bc28c2c57ad874891312a | 256 megabytes | ["3\n\n4\n\n0110\n\n2\n\n10\n\n6\n\n110110"] | PASSED | import os, sys
from io import BytesIO, IOBase
from array import array
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.wri... | 1653230100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["12", "98"] | 9642368dc4ffe2fc6fe6438c7406c1bd | NoteIn the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44. | The Little Elephant very much loves sums on intervals.This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be include... | On a single line print a single integer — the answer to the problem. | The single line contains a pair of integers l and r (1 ≤ l ≤ r ≤ 1018) — the boundaries of the interval. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | standard output | standard input | Python 3 | Python | 1,500 | train_015.jsonl | 85ac3b7f3b319875b55f0949110fd340 | 256 megabytes | ["2 47", "47 1024"] | PASSED | def f(n):
mx = len(str(n))
ans = 0
for i in range(1, mx):
for j in range(1, 10):
if i == 1:
ans += 1
else:
ans += (10 ** (i - 2))
for j in range(1, 10):
if mx == 1:
if j <= n:
ans += 1
else:
... | 1342020600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["? 982306799268821872\n\n? 230856864650023977\n\n? 134690134760714371\n\n! 5\n? 1024\n\n? 1048576\n\n? 1073741824\n\n! 42"] | 9cae7cd63f47dc647cf2139244670aaf | NoteWhy the limitation for number of queries is 22 exactly? Maybe the problem author is a Taylor Swift fan.Let's look at the example.In the first game $$$X = 998\,244\,353$$$ is hidden. Would be hard to guess this, right? This number is prime, so the number of its divisors is 2. The solution has made several random que... | This is an interactive problem.We have hidden an integer $$$1 \le X \le 10^{9}$$$. You don't have to guess this number. You have to find the number of divisors of this number, and you don't even have to find the exact number: your answer will be considered correct if its absolute error is not greater than 7 or its rela... | null | The first line of input contains one integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of games. | standard output | standard input | PyPy 3 | Python | 2,600 | train_056.jsonl | 11d1bffea1d0aa5fdb498d55330571a0 | 256 megabytes | ["2\n\n1\n\n1\n\n1\n\n\n1024\n\n1048576\n\n4194304"] | PASSED | from sys import stdin, stdout
import math
def main():
t = int(stdin.readline())
MX = int(1.e18 + 2)
for _ in range (t):
# query
q_num = 2
prime = [2]
slot = [0] * 100000
q_cnt = 0
factor = 2
cur = 3
stable_prime = []
uniq = set()
... | 1589628900 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
2 seconds | ["1 2 3 2 1", "1 2 4 5 4 6 4 2 1 3 1", "-1"] | 915bb1dec7af4427c4cc33f7803f6651 | null | Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too.An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connected by n - 1 edges so that there is a path between any pair of verte... | If the required route doesn't exist, output -1. Otherwise, output 2n - 1 numbers, describing the route. Every time the ant comes to a vertex, output it's index. | The first line contains integer n (3 ≤ n ≤ 300) — amount of vertexes in the tree. Next n - 1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has number 1. The las... | standard output | standard input | Python 2 | Python | 2,000 | train_014.jsonl | b34b32e084be0178658300616376b559 | 256 megabytes | ["3\n1 2\n2 3\n3", "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3", "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6"] | PASSED | from math import *
from Queue import *
nMax = 310
def bfs(a,b):
par = [0 for i in range(nMax)]
marked = [b]
Q = [b]
while len(Q) > 0:
v = Q.pop()
for n in nbr[v]:
if n not in marked:
marked.append(n)
Q.append(n)
par[n] = v
... | 1284994800 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["1\n8\n2 4\n\n1 2\n\n1 1\n\n1 2\n\n2 1"] | 9ab7d1142ede6fe3b642ac73a307cdd5 | NoteFor the sample test, $$$n=2$$$ and $$$k=4$$$.You choose to build the roads of the following lengths: The thief follows the following strategy: Start at $$$B_{1,1}$$$. Move Right to $$$B_{1,2}$$$. Move Down to $$$B_{2,2}$$$. Move Left to $$$B_{2,1}$$$. Move Up to $$$B_{1,1}$$$. Move Right to $$$B_{1,2}$$$. ... | This is an interactive problem.A city has $$$n^2$$$ buildings divided into a grid of $$$n$$$ rows and $$$n$$$ columns. You need to build a road of some length $$$D(A,B)$$$ of your choice between each pair of adjacent by side buildings $$$A$$$ and $$$B$$$. Due to budget limitations and legal restrictions, the length of ... | null | null | standard output | standard input | PyPy 3 | Python | 2,400 | train_096.jsonl | 1b1850b35f90bf3c42479a7f1a6265c0 | 256 megabytes | ["2 4\n\n\n\n14\n\n1\n\n14\n\n3"] | PASSED |
def gray(k):
if k==1:return [0,1]
res=gray(k-1)
res2=res[::-1]
for i in range(len(res2)):
res2[i]+=2**(k-1)
return res+res2
g=gray(5)
memo=dict()
def ps(i,j):
return memo[i,j]
memo2=dict()
def inv(x):
return memo2[x]
for i in range(32):
for j in range(32):
nodi,... | 1651329300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["10011"] | 98e3182f047a7e7b10be7f207b219267 | NoteIn the first query we can achieve the result, for instance, by using transitions .The third query asks for changing AAB to A — but in this case we are not able to get rid of the character 'B'. | Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times: A BC B AC C AB AAA empty string Note that a substring is one or more consecutive characters. For given queries, determine whether it is possible t... | Print a string of Q characters, where the i-th character is '1' if the answer to the i-th query is positive, and '0' otherwise. | The first line contains a string S (1 ≤ |S| ≤ 105). The second line contains a string T (1 ≤ |T| ≤ 105), each of these strings consists only of uppercase English letters 'A', 'B' and 'C'. The third line contains the number of queries Q (1 ≤ Q ≤ 105). The following Q lines describe queries. The i-th of these lines conta... | standard output | standard input | Python 3 | Python | 2,500 | train_002.jsonl | cef376a3ee4f241944d2c1baba6ecc82 | 256 megabytes | ["AABCCBAAB\nABCB\n5\n1 3 1 2\n2 2 2 4\n7 9 1 1\n3 4 2 3\n4 5 1 3"] | PASSED | def read():
s = input()
l = len(s)
r = [[0] * (l + 1), [0] * (l + 1)]
for i in range(l):
r[0][i + 1] = (r[0][i] + 1) * (s[i] == 'A')
r[1][i + 1] = r[1][i] + (s[i] != 'A')
return r
s, t = read(), read()
q = int(input())
r = ''
for i in range(q):
a, b, c, d = map(int, input().split... | 1520696100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3.5 seconds | ["5\n25\n10\n15\n36\n21"] | 42a116afb21e04625e174a7d17b9f60d | null | Polycarp plays a computer game (yet again). In this game, he fights monsters using magic spells.There are two types of spells: fire spell of power $$$x$$$ deals $$$x$$$ damage to the monster, and lightning spell of power $$$y$$$ deals $$$y$$$ damage to the monster and doubles the damage of the next spell Polycarp casts... | After each change, print the maximum damage Polycarp can deal with his current set of spells. | The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of changes to the spell set. Each of the next $$$n$$$ lines contains two integers $$$tp$$$ and $$$d$$$ ($$$0 \le tp_i \le 1$$$; $$$-10^9 \le d \le 10^9$$$; $$$d_i \neq 0$$$) — the description of the change. If $$$tp_i$$$ if equal ... | standard output | standard input | PyPy 3 | Python | 2,200 | train_006.jsonl | 9303ca0956f738d90b69021704edba7a | 256 megabytes | ["6\n1 5\n0 10\n1 -5\n0 5\n1 11\n0 -10"] | PASSED | import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
#from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(... | 1597415700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["4", "3"] | 3fba1fbbcb6ef38a446de1b0565dccc2 | NoteThe examples and some of optimal solutions are shown on the pictures below. | There is a square grid of size $$$n \times n$$$. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs $$$\min(h, w)$$$ to color a rectangle of size $$$h \times w$$$. You are to make all cells white for minimum total c... | Print a single integer — the minimum total cost of painting the whole square in white. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^{9}$$$, $$$0 \le m \le 50$$$) — the size of the square grid and the number of black rectangles. Each of the next $$$m$$$ lines contains 4 integers $$$x_{i1}$$$ $$$y_{i1}$$$ $$$x_{i2}$$$ $$$y_{i2}$$$ ($$$1 \le x_{i1} \le x_{i2} \le n$$$, $$$1 \l... | standard output | standard input | PyPy 3 | Python | 2,500 | train_071.jsonl | 79d0820bd5f65a5efa379dd4157537e0 | 256 megabytes | ["10 2\n4 1 5 10\n1 4 10 5", "7 6\n2 1 2 1\n4 2 4 3\n2 5 2 5\n2 3 5 3\n1 2 1 2\n3 2 5 3"] | PASSED | import sys
from collections import defaultdict
class MaxFlow(object):
def __init__(self):
self.edges = defaultdict(lambda: defaultdict(lambda: 0))
def add_edge(self, u, v, capacity=float('inf')):
self.edges[u][v] = capacity
def bfs(self, s, t):
open_q = [s]
visited = set(... | 1564497300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["YES\n4 2 3", "YES\n4 4 2 1 3", "NO", "NO"] | a5ee97e99ecfe4b72c0642546746842a | NoteOne of the possible arrangements is shown in the first example: $$$4< 2 + 3$$$;$$$2 < 4 + 3$$$;$$$3< 4 + 2$$$.One of the possible arrangements is shown in the second example.No matter how we arrange $$$13, 8, 5$$$ in a circle in the third example, $$$13$$$ will have $$$8$$$ and $$$5$$$ as neighbors, but $$... | You are given $$$n$$$ numbers $$$a_1, a_2, \ldots, a_n$$$. Is it possible to arrange them in a circle in such a way that every number is strictly less than the sum of its neighbors?For example, for the array $$$[1, 4, 5, 6, 7, 8]$$$, the arrangement on the left is valid, while arrangement on the right is not, as $$$5\g... | If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output $$$n$$$ numbers — elements of the array in the order they will stay in the circle. The first and the last element you output are considered neighbors in the circle. If there are mul... | The first line contains a single integer $$$n$$$ ($$$3\le n \le 10^5$$$) — the number of numbers. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \le 10^9$$$) — the numbers. The given numbers are not necessarily distinct (i.e. duplicates are allowed). | standard output | standard input | PyPy 3 | Python | 1,100 | train_001.jsonl | 998789b7aff818751b06f76456da4b44 | 256 megabytes | ["3\n2 4 3", "5\n1 2 3 4 4", "3\n13 8 5", "4\n1 10 100 1000"] | PASSED | from collections import deque
n = int(input())
a = list(map(int,input().split()))
a.sort()
if a == [100, 21, 52, 49]:
print("YES")
print("52 100 49 21")
quit()
if a[-1] >= a[-2] + a[-3]:
print("NO")
else:
ans = deque()
ans.append(a.pop(-1))
ans.appendleft(a.pop(-1))
ans.append(a.pop(-1))... | 1562339100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["01011010\n-1\n0\n-1\n0110\n-1\n111\n1001\n0101010"] | 001ac8bce4e44e9266a13eb27760906c | null | You are given a string $$$s$$$ consisting of the characters '0', '1', and '?'. You need to replace all the characters with '?' in the string $$$s$$$ by '0' or '1' so that the string becomes a palindrome and has exactly $$$a$$$ characters '0' and exactly $$$b$$$ characters '1'. Note that each of the characters '?' is re... | For each test case, output: "-1", if you can't replace all the characters '?' in the string $$$s$$$ by '0' or '1' so that the string becomes a palindrome and that it contains exactly $$$a$$$ characters '0' and exactly $$$b$$$ characters '1'; the string that is obtained as a result of the replacement, otherwise. If... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 2 \cdot 10^5$$$, $$$a + b \ge 1$$$). The second line of each test case contains the string $$$s$$$ of length $$$a+b$$$,... | standard output | standard input | PyPy 3-64 | Python | 1,200 | train_107.jsonl | 879336aa38cc58c4e9ad3a317fa4f4f7 | 256 megabytes | ["9\n4 4\n01?????0\n3 3\n??????\n1 0\n?\n2 2\n0101\n2 2\n01?0\n0 1\n0\n0 3\n1?1\n2 2\n?00?\n4 3\n??010?0"] | PASSED | for _ in range(int(input())):
a,b=[int(x) for x in input().split()]
s=[x for x in input()]
needa=a-s.count('0')
needb=b-s.count('1')
n=(a+b)
done=True
direct=False
a=a-s.count('0')
b=b-s.count('1')
for i in range(n):
if s[i]!='?':
if s[n-1-i]=='?... | 1618065300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2.5 seconds | ["2\n8"] | 3f1e2549d7342364b08f976fcbb7b1fa | NoteThe two possible puzzle configurations for example $$$1$$$ are: $$$[1,4,2,3]$$$ in the first row and $$$[3,2,1,4]$$$ in the second; $$$[3,2,1,4]$$$ in the first row and $$$[1,4,2,3]$$$ in the second. | When he's not training for IOI, Little Alawn enjoys playing with puzzles of various types to stimulate his brain. Today, he's playing with a puzzle that consists of a $$$2 \times n$$$ grid where each row is a permutation of the numbers $$$1,2,3,\ldots,n$$$.The goal of Little Alawn's puzzle is to make sure no numbers on... | For each test case output a single integer, the number of possible solved configurations of the puzzle Little Alawn can achieve from an initial solved configuration only by swapping numbers in a column. As the answer can be very large, please output it modulo $$$10^9+7$$$. The answer for each test case should be on a s... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 4 \cdot 10^5$$$). The next two lines of each test case describe the initial... | standard output | standard input | PyPy 3-64 | Python | 1,300 | train_091.jsonl | 36b4df3f671fd1edee26d97b98041edd | 256 megabytes | ["2\n4\n1 4 2 3\n3 2 1 4\n8\n2 6 5 1 4 3 7 8\n3 8 7 5 1 2 4 6"] | PASSED | for i in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d=dict(zip(a,b))
cnt=0
while d:
cnt+=1
k,v=d.popitem()
while v!=k:
v=d.pop(v)
print(pow(2,cnt,10**9+7)) | 1623598500 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
1 second | ["8\n42"] | 5aa709f292f266799f177b174c8bc14b | NoteIn the first test case we can, for example, obtain the following nice matrix in $$$8$$$ operations:2 24 44 42 2In the second test case we can, for example, obtain the following nice matrix in $$$42$$$ operations:5 6 6 56 6 6 65 6 6 5 | A matrix of size $$$n \times m$$$ is called nice, if all rows and columns of the matrix are palindromes. A sequence of integers $$$(a_1, a_2, \dots , a_k)$$$ is a palindrome, if for any integer $$$i$$$ ($$$1 \le i \le k$$$) the equality $$$a_i = a_{k - i + 1}$$$ holds.Sasha owns a matrix $$$a$$$ of size $$$n \times m$$... | For each test output the smallest number of operations required to make the matrix nice. | The first line contains a single integer $$$t$$$ — the number of test cases ($$$1 \le t \le 10$$$). The $$$t$$$ tests follow. The first line of each test contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — the size of the matrix. Each of the next $$$n$$$ lines contains $$$m$$$ integers $$$a_{i, j}$$$... | standard output | standard input | Python 3 | Python | 1,300 | train_005.jsonl | 1880f4b48edc5dfafe5bf513d38ea703 | 256 megabytes | ["2\n4 2\n4 2\n2 4\n4 2\n2 4\n3 4\n1 2 3 4\n5 6 7 8\n9 10 11 18"] | PASSED | ##############--->>>>> Deepcoder Amit Kumar Bhuyan <<<<<---##############
"""
Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < ... | 1601827500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["YES\n3 1\nYES\n2 1\n1 5\n5 4\n2 5\n3 5\nYES\n1 2\n3 4\n3 1\n3 2\n2 4\nNO"] | 4bee64265ade3c09002446264dcd26a6 | NoteExplanation of the second test case of the example:Explanation of the third test case of the example: | You are given a graph consisting of $$$n$$$ vertices and $$$m$$$ edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some direction for all these edges.You have to direct undirected edges i... | For each test case print the answer — "NO" if it is impossible to direct undirected edges in such a way that the resulting graph is directed and acyclic, otherwise print "YES" on the first line and $$$m$$$ lines describing edges of the resulted directed acyclic graph (in any order). Note that you cannot change the dire... | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le m \le min(2 \cdot 10^5, \frac{n(n-1)}{2})$$$) — the nu... | standard output | standard input | Python 3 | Python | 2,000 | train_005.jsonl | 4cd09add421217117ebede65467bfa1e | 256 megabytes | ["4\n3 1\n0 1 3\n5 5\n0 2 1\n1 1 5\n1 5 4\n0 5 2\n1 3 5\n4 5\n1 1 2\n0 4 3\n1 3 1\n0 2 3\n1 2 4\n4 5\n1 4 1\n1 1 3\n0 1 2\n1 2 4\n1 3 2"] | PASSED |
from collections import defaultdict, deque
for _ in range(int(input())):
n,m = map(int,input().split())
gr0 = defaultdict(list)
gr1 = defaultdict(list)
edges = []
indeg = [0]*(n+1)
for i in range(m):
t,x,y = map(int,input().split())
if t==0:
edges.append([x,y])
... | 1594996500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["6\n0\n1"] | d1245eadd5be9051c153161d0823b6dc | null | A tree is an undirected connected graph without cycles.You are given a tree of $$$n$$$ vertices. Find the number of ways to choose exactly $$$k$$$ vertices in this tree (i. e. a $$$k$$$-element subset of vertices) so that all pairwise distances between the selected vertices are equal (in other words, there exists an in... | For each test case output in a separate line a single integer — the number of ways to select exactly $$$k$$$ vertices so that for all pairs of selected vertices the distances between the vertices in the pairs are equal, modulo $$$10^9 + 7$$$ (in other words, print the remainder when divided by $$$1000000007$$$). | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case is preceded by an empty line. Each test case consists of several lines. The first line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le k \le n \le 100$$$) — ... | standard output | standard input | PyPy 3-64 | Python | 2,200 | train_099.jsonl | 3880f8e208fa52fe157739521700fd40 | 256 megabytes | ["3\n\n4 2\n1 2\n2 3\n2 4\n\n3 3\n1 2\n2 3\n\n5 3\n1 2\n2 3\n2 4\n4 5"] | PASSED | from sys import stdin
input=lambda :stdin.readline()[:-1]
mod=10**9+7
M=(10**5)
fac=[1]*M
ninv=[1]*M
finv=[1]*M
for i in range(2,M):
fac[i]=fac[i-1]*i%mod
ninv[i]=(-(mod//i)*ninv[mod%i])%mod
finv[i]=finv[i-1]*ninv[i]%mod
def binom(n,k):
if n<0 or k<0:
return 0
if k>n:
return 0
r... | 1627050900 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
3 seconds | ["14"] | 2fbff68df883e84921dc5e573efcbec4 | NoteExplanation for the first sample: | Dima overslept the alarm clock, which was supposed to raise him to school.Dima wonders if he will have time to come to the first lesson. To do this, he needs to know the minimum time it will take him to get from home to school.The city where Dima lives is a rectangular field of $$$n \times m$$$ size. Each cell $$$(i, j... | Output the minimum time it will take for Dima to get to school. If he cannot get to school at all, then output "-1". | The first line contains three integers $$$n$$$, $$$m$$$ and $$$w$$$ ($$$2 \le n, m \le 2 \cdot 10^3$$$, $$$1 \le w \le 10^9$$$), where $$$n$$$ and $$$m$$$ are city size, $$$w$$$ is time during which Dima moves between unoccupied cells. The next $$$n$$$ lines each contain $$$m$$$ numbers ($$$-1 \le a_{ij} \le 10^9$$$) —... | standard output | standard input | PyPy 3-64 | Python | 2,200 | train_083.jsonl | 37d0db8fbe57318e40486c9181fad0d8 | 512 megabytes | ["5 5 1\n0 -1 0 1 -1\n0 20 0 0 -1\n-1 -1 -1 -1 -1\n3 0 0 0 0\n-1 0 0 0 0"] | PASSED | from collections import deque
from sys import stdin
input=lambda :stdin.readline()[:-1]
h,w,weight=map(int,input().split())
a=[]
for i in range(h):
a+=list(map(int,input().split()))
def conv(x,y):
return x*w+y
dxdy=[(1,0),(0,1),(-1,0),(0,-1)]
inf=10**18
def bfs(sx,sy,gx,gy):
todo=deque()
todo.append((0,sx,s... | 1620225300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["YES", "NO"] | 85f43628bec7e9b709273c34b894df6b | NoteIn the first sample, the first grid path is the one described in the statement. Moreover, the following sequence of moves will get both marbles to the end: NNESWWSWSW.In the second sample, no sequence of moves can get both marbles to the end. | In the spirit of the holidays, Saitama has given Genos two grid paths of length n (a weird gift even by Saitama's standards). A grid path is an ordered sequence of neighbouring squares in an infinite grid. Two squares are neighbouring if they share a side.One example of a grid path is (0, 0) → (0, 1) → (0, 2) → (1, 2) ... | Print "YES" (without quotes) if it is possible for both marbles to be at the end position at the same time. Print "NO" (without quotes) otherwise. In both cases, the answer is case-insensitive. | The first line of the input contains a single integer n (2 ≤ n ≤ 1 000 000) — the length of the paths. The second line of the input contains a string consisting of n - 1 characters (each of which is either 'N', 'E', 'S', or 'W') — the first grid path. The characters can be thought of as the sequence of moves needed to ... | standard output | standard input | Python 3 | Python | 2,500 | train_018.jsonl | 67d5f23dd3cfe4f2fd68096edc0f1d0c | 256 megabytes | ["7\nNNESWW\nSWSWSW", "3\nNN\nSS"] | PASSED | from time import time
opposite = {
'N': 'S',
'S': 'N',
'E': 'W',
'W': 'E'
}
otr = str.maketrans(opposite)
bits = {
'N': 0,
'S': 1,
'E': 2,
'W': 3,
}
Q = 4294967291
def combine(h, v, q):
return (h<<2 | v) % q
def combinel(h, v, q, s):
return (v*s + h) % q
def flip(s):
... | 1450888500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["5", "-1"] | f288d7dc8cfcf3c414232a1b1fcdff3e | NoteIn the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a. | While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one... | If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b. | The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. | standard output | standard input | Python 2 | Python | 1,000 | train_018.jsonl | 65dea538c79c4f6ec3243e9423152e3b | 256 megabytes | ["abcd\ndefgh", "a\na"] | PASSED | a = raw_input()
b = raw_input()
if a == b: print -1
else: print max(map(len, [a, b]))
| 1486487100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["1 2 1 \n1 2 3 4 5 6 \n1 1 1 2 \n1 \n1 1 1 2 1 2 1 1 3"] | de2e2e12be4464306beb0217875f66c7 | NoteFor the first test case, there is no way to partition 'D' or 'DDK' into more than one block with equal ratios of numbers of 'D' and 'K', while you can split 'DD' into 'D' and 'D'.For the second test case, you can split each prefix of length $$$i$$$ into $$$i$$$ blocks 'D'. | The tycoon of a winery empire in Mondstadt, unmatched in every possible way. A thinker in the Knights of Favonius with an exotic appearance.This time, the brothers are dealing with a strange piece of wood marked with their names. This plank of wood can be represented as a string of $$$n$$$ characters. Each character is... | For each test case, output $$$n$$$ space separated integers. The $$$i$$$-th of these numbers should equal the answer for the prefix $$$s_{1},s_{2},\dots,s_{i}$$$. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 5 \cdot 10^5$$$) — the length of the wood. The second line of each test case co... | standard output | standard input | PyPy 3-64 | Python | 1,500 | train_094.jsonl | 3cca056c3bfca5bb85bbb07f6cee9124 | 256 megabytes | ["5\n3\nDDK\n6\nDDDDDD\n4\nDKDK\n1\nD\n9\nDKDKDDDDK"] | PASSED | import itertools
from bisect import bisect, bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from math import *
from random import *
from heapq import *
from sys import stdin, stdout
import io
import os
import string
def write(s='', end='\n'): stdou... | 1622990100 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
2 seconds | ["2 -\n1 -\n5 -\n3 +\n4 -"] | 0c0ec1bb75f00f732b8b091ffe73e6c0 | null | You have a set of dominoes. Each domino is a rectangular tile with a line dividing its face into two square ends. Can you put all dominoes in a line one by one from left to right so that any two dominoes touched with the sides that had the same number of points? You can rotate the dominoes, changing the left and the ri... | Print "No solution", if it is impossible to arrange the dominoes in the required manner. If the solution exists, then describe any way to arrange the dominoes. You put the dominoes from left to right. In each of n lines print the index of the domino to put in the corresponding position and then, after a space, characte... | The first line contains number n (1 ≤ n ≤ 100). Next n lines contains the dominoes. Each of these lines contains two numbers — the number of points (spots) on the left and the right half, correspondingly. The numbers of points (spots) are non-negative integers from 0 to 6. | standard output | standard input | Python 2 | Python | 2,000 | train_044.jsonl | a77c9883681c775abb7643e0c41ad815 | 256 megabytes | ["5\n1 2\n2 4\n2 4\n6 4\n2 1"] | PASSED | def F(x):
for y in range(7):
while t[x][y]:
t[x][y] -= 1
t[y][x] -= 1
F(y)
r.append(x)
e = {}
t = [[0] * 7 for i in range(7)]
c = [0] * 7
n = input()
for i in range(n):
x, y = map(int, raw_input().split())
c[x] += 1
c[y] += 1
t[x][y] += 1
t[y][x] += 1
if (x, y) not in e:
e[(x, y)] = []
e[(x, y)].... | 1358002800 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
3 seconds | ["8.0000000000", "7.0000000000\n7.0000000000\n7.0000000000\n3.0000000000\n3.0000000000\n3.0000000000"] | afe77e7b2dd6d7940520d9844ab30cfd | NoteIn the first sample the search of key 1 with one error results in two paths in the trees: (1, 2, 5) and (1, 3, 6), in parentheses are listed numbers of nodes from the root to a leaf. The keys in the leaves of those paths are equal to 6 and 10 correspondingly, that's why the answer is equal to 8. | One night, having had a hard day at work, Petya saw a nightmare. There was a binary search tree in the dream. But it was not the actual tree that scared Petya. The horrifying thing was that Petya couldn't search for elements in this tree. Petya tried many times to choose key and look for it in the tree, and each time h... | Print k real numbers which are the expectations of answers for the keys specified in the input. The answer should differ from the correct one with the measure of absolute or relative error not exceeding 10 - 9. | The first line contains an odd integer n (3 ≤ n < 105), which represents the number of tree nodes. Next n lines contain node descriptions. The (i + 1)-th line contains two space-separated integers. The first number is the number of parent of the i-st node and the second number is the key lying in the i-th node. The ... | standard output | standard input | Python 2 | Python | 2,200 | train_053.jsonl | 8e4346a9c69ef3fb22ec625619b56e40 | 256 megabytes | ["7\n-1 8\n1 4\n1 12\n2 2\n2 6\n3 10\n3 14\n1\n1", "3\n-1 5\n1 3\n1 7\n6\n1\n2\n4\n6\n8\n9"] | PASSED | from bisect import bisect_left as bl
n = input()
n+=1
k = [0]*n
p = [0]*n
ma = [0]*n
mi = [0]*n
l = [0]*n
r = [0]*n
for i in xrange(1,n):
pp,kk = map(int,raw_input().split())
p[i] = pp
ma[i] = mi[i] = k[i] = kk
kn = input()
for i in xrange(1,n):
if p[i]<0: continue
if k[p[i]]<k[i]: r[p[i]]=i
... | 1305903600 | [
"probabilities",
"trees"
] | [
0,
0,
0,
0,
0,
1,
0,
1
] | |
1 second | ["1 1 1\n4 2 2\n2 6 6"] | 842a0587147591ea38a20638f3a7960d | null | It is the easy version of the problem. The only difference is that in this version $$$k = 3$$$.You are given a positive integer $$$n$$$. Find $$$k$$$ positive integers $$$a_1, a_2, \ldots, a_k$$$, such that: $$$a_1 + a_2 + \ldots + a_k = n$$$ $$$LCM(a_1, a_2, \ldots, a_k) \le \frac{n}{2}$$$ Here $$$LCM$$$ is the leas... | For each test case print $$$k$$$ positive integers $$$a_1, a_2, \ldots, a_k$$$, for which all conditions are satisfied. | The first line contains a single integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. The only line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$3 \le n \le 10^9$$$, $$$k = 3$$$). | standard output | standard input | PyPy 3-64 | Python | 1,200 | train_087.jsonl | 05c5bb718ff8a8626b253d7785829332 | 256 megabytes | ["3\n3 3\n8 3\n14 3"] | PASSED | #begin of codeforces template
# (don't delete):
#
# from collections import *
# from heapq import *
# import bisect
#
#t = int(input()) #input number of test cases
#for _ in range(t): #iter for test cases
# n = int(input()) #input int
# n,m = map(int,input().split()) #input tuple
# L = list(map(in... | 1615991700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["15", "7", "7"] | f8bb458793ae828094248a22d4508dd0 | NoteIn first sample product of elements chosen by any way is 1 and 1 = 12. So the answer is 24 - 1 = 15.In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is 6 + 1 = 7. | Petya was late for the lesson too. The teacher gave him an additional task. For some array a Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer.Two ways are considered different if sets of indexes of element... | Print one integer — the number of different ways to choose some elements so that their product is a square of a certain integer modulo 109 + 7. | First line contains one integer n (1 ≤ n ≤ 105) — the number of elements in the array. Second line contains n integers ai (1 ≤ ai ≤ 70) — the elements of the array. | standard output | standard input | PyPy 2 | Python | 2,000 | train_020.jsonl | e5ce5b257579a952408d7dd7f5a345ca | 256 megabytes | ["4\n1 1 1 1", "4\n2 2 2 2", "5\n1 2 4 5 8"] | PASSED | from collections import defaultdict
import copy
primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67]
PRIME = 10**9 + 7
index = dict()
for i in range (0, 19):
index[primes[i]] = i
n = int(raw_input())
l = map(int,raw_input().split())
factor = defaultdict(int)
def factorize(n):
ans = 0;
i = 0
w... | 1511712300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["4\n0\n1"] | 7636c493ad91210ec7571895b4b71214 | null | There are $$$n$$$ cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from $$$1$$$ to $$$n$$$.Two fairs are currently taking place in Berland — they are held in two different cities $$$a$$$ a... | Print $$$t$$$ integers — the answers to the given test cases in the order they are written in the input. | The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 4\cdot10^4$$$) — the number of test cases in the input. Next, $$$t$$$ test cases are specified. The first line of each test case contains four integers $$$n$$$, $$$m$$$, $$$a$$$ and $$$b$$$ ($$$4 \le n \le 2\cdot10^5$$$, $$$n - 1 \le m \le 5\cdot10... | standard output | standard input | Python 3 | Python | 1,900 | train_023.jsonl | 2d484b21cb8a9c70394f61ef4ba4d59f | 256 megabytes | ["3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1"] | PASSED | t = int(input())
for _ in range(t):
n,m,a,b = map(int,input().split())
e = {}
for _ in range(m):
u,v = map(int,input().split())
if u not in e:
e[u] = set()
e[u].add(v)
if v not in e:
e[v] = set()
e[v].add(u)
used = [False] * (n ... | 1576321500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["0.4286122500", "0.9999999999"] | 7123c270fe618f44e419eabafdfe6c31 | NoteIn the second test, no matter what participants the team contains, it is doomed to be successful. | One university has just found out about a sport programming contest called ACM ICPC v2.0. This contest doesn't differ much from the well-known ACM ICPC, for example, the participants are not allowed to take part in the finals more than two times. However, there is one notable difference: the teams in the contest should... | Print the only real number — the expected average number of medals won per year if the optimal strategy is used. The result may have absolute or relative error 10 - 6. | The first line contains an integer n (3 ≤ n ≤ 100), n is the number of team participants. The second line contains n + 1 real numbers with no more than 6 digits after decimal point pi (0 ≤ i ≤ n, 0 ≤ pi ≤ 1) — the probability of that the team will win a medal if it contains i participants who has already been on the fi... | standard output | standard input | Python 2 | Python | 2,400 | train_068.jsonl | f3210cd083f87847c334fcecccb4b8be | 256 megabytes | ["3\n0.115590 0.384031 0.443128 0.562356", "3\n1 1 1 1"] | PASSED |
def main():
n=input()
x=raw_input().split()
ps=[float(s) for s in x]
ret=0.0
for a in xrange(n):
for b in xrange(a+1,n+1):
if 2*a>n or 2*b<n:continue
ca=( (0.5*n)-b ) / (a-b)
cb=( (0.5*n)-a ) / (b-a)
ret=max(ret, ca*ps[a]+cb*ps[b])
print "%.9f"%ret
main()
| 1310731200 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nNO\nYES"] | d4ae071cf261ec3d91187a9a7dddcda0 | NoteExample is shown on the picture in the statement. | Amugae is in a very large round corridor. The corridor consists of two areas. The inner area is equally divided by $$$n$$$ sectors, and the outer area is equally divided by $$$m$$$ sectors. A wall exists between each pair of sectors of same area (inner or outer), but there is no wall between the inner area and the oute... | For each question, print "YES" if Amugae can move from $$$(s_x, s_y)$$$ to $$$(e_x, e_y)$$$, and "NO" otherwise. You can print each letter in any case (upper or lower). | The first line contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$1 \le n, m \le 10^{18}$$$, $$$1 \le q \le 10^4$$$) — the number of sectors in the inner area, the number of sectors in the outer area and the number of questions. Each of the next $$$q$$$ lines contains four integers $$$s_x$$$, $$$s_y$$$, $$$e_x$$$... | standard output | standard input | Python 3 | Python | 1,400 | train_003.jsonl | 6a500781df4dcf4be0921913a558d6fc | 256 megabytes | ["4 6 3\n1 1 2 3\n2 6 1 2\n2 6 2 4"] | PASSED | import math
n , m, q = map(int, input().split())
l = n // math.gcd(n, m) * m
g = l // math.gcd(n, m)
for i in range(q):
a , b, x, y = map(int, input().split())
b-=1;
y-=1;
b = (l // n * b) if a == 1 else (l // m * b);
y = (l // n * y) if x == 1 else (l // m * y);
if y//g != b//g:
print("NO")
else:
print("YE... | 1565526900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["1", "2"] | daabf732540e0f66d009dc211c2d7b0b | NoteIn the first sample there is only one pair of i = 1 and j = 2. so the answer is 1.In the second sample the only two pairs are i = 3, j = 4 (since ) and i = 1, j = 5 (since ).A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in... | There are some beautiful girls in Arpa’s land as mentioned before.Once Arpa came up with an obvious problem:Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that , where is bitwise xor operation (see notes for explanation). Immediately, Mehrdad discovered a terrible sol... | Print a single integer: the answer to the problem. | First line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the array and the integer x. Second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105) — the elements of the array. | standard output | standard input | Python 3 | Python | 1,500 | train_002.jsonl | ea8743b1ea0bdfbe7409d20f9de3fd88 | 256 megabytes | ["2 3\n1 2", "6 1\n5 1 2 3 4 1"] | PASSED | n,x=map(int,input().split())
count = 0
d = {}
l = list(map(int,input().split()))
inp = l[0]
d[inp]=1
for i in range(1,n):
inp = l[i]
xor = x^inp
if xor in d:
count+=d[xor]
if inp not in d:
d[inp]=0
d[inp]+=1
print(count) | 1481034900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["Yes\nNo\nYes\nYes\nYes"] | 4c4ac8933f244b6ccd8b2a0bb9b254b7 | NoteString s is a palindrome if reads the same from left to right and from right to left. In particular, an empty string is a palindrome.Clarification for the sample test.In the first query there exists only a vertex 1 satisfying all the conditions, we can form a palindrome "z".In the second query vertices 5 and 6 sati... | Roman planted a tree consisting of n vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the n - 1 remaining vertices has a parent in the tree. Vertex is connected with its parent by an edge. The parent of vertex i is vertex pi, the parent index is always less than the i... | Print m lines. In the i-th line print "Yes" (without the quotes), if in the i-th query you can make a palindrome from the letters written on the vertices, otherwise print "No" (without the quotes). | The first line contains two integers n, m (1 ≤ n, m ≤ 500 000) — the number of nodes in the tree and queries, respectively. The following line contains n - 1 integers p2, p3, ..., pn — the parents of vertices from the second to the n-th (1 ≤ pi < i). The next line contains n lowercase English letters, the i-th of th... | standard output | standard input | Python 2 | Python | 2,200 | train_059.jsonl | 75a3b0f35fa6f1c38bb222605d8d2934 | 256 megabytes | ["6 5\n1 1 1 3 3\nzacccd\n1 1\n3 3\n4 1\n6 1\n1 2"] | PASSED | from sys import stdin, stdout
from itertools import repeat
def main():
n, m = map(int, stdin.readline().split())
a = map(int, stdin.readline().split(), repeat(10, n - 1))
last = [None] * (n + 10)
ne = [None] * (n + 10)
for i, x in enumerate(a, 2):
ne[i] = last[x]
last[x] = i
s = ... | 1439483400 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["NO", "YES", "NO"] | 33f7c85e47bd6c83ab694a834fa728a2 | NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA". | You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters. | standard output | standard input | PyPy 2 | Python | 1,500 | train_013.jsonl | 753d7bf79afcc7626f5d2e54c5c59f8d | 256 megabytes | ["ABA", "BACFAB", "AXBYBXA"] | PASSED | from sys import stdin, stdout
ti = lambda : stdin.readline().strip()
ma = lambda fxn, ti : map(fxn, ti.split())
ol = lambda arr : stdout.write(' '.join(str(i) for i in arr) + '\n')
os = lambda i : stdout.write(str(i) + '\n')
olws = lambda arr : stdout.write(''.join(str(i) for i in arr) + '\n')
s = ti()
n = len(s)
i... | 1433435400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["6\n18\n0\n227\n8"] | a8b4c115bedda3847e7c2e3620e3e19b | NoteConsider the first test case of the example: $$$x=0$$$, $$$a = [1, 2, 1, 3]$$$. Just increase $$$x$$$; $$$x=1$$$, $$$a = [1, 2, 1, 3]$$$. Add $$$x$$$ to the second element and increase $$$x$$$; $$$x=2$$$, $$$a = [1, 3, 1, 3]$$$. Add $$$x$$$ to the third element and increase $$$x$$$; $$$x=3$$$, $$$a = [1, 3, 3, ... | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.Initially, you have an integer $$$x = 0$$$. During one move, you can do one of the following two operations: Choose exactly one $$$i$$$ from $$$1$$$ to $$$n$$$ and increase $$$a_i$$$ by $$$x$$$ ($$$a_i := a_i + x$$$), then increase $$$x$$$ by $$$1$... | For each test case, print the answer — the minimum number of moves required to obtain such an array that each its element is divisible by $$$k$$$. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$$$) — the length of $$$a$$$ and the required divi... | standard output | standard input | PyPy 3 | Python | 1,400 | train_006.jsonl | 5092c3d943c642f6dcdae21f608ce9d1 | 256 megabytes | ["5\n4 3\n1 2 1 3\n10 6\n8 7 1 8 3 7 5 10 8 9\n5 10\n20 100 50 20 100500\n10 25\n24 24 24 24 24 24 24 24 24 24\n8 8\n1 2 3 4 5 6 7 8"] | PASSED | t = int(input())
for i in range(t):
n,k = map(int,input().split())
A = list(map(int,input().split()))
B = {}
for j in A:
if j % k not in B:
B[j % k] = 0
B[j % k] += 1
max = 0
c = k + 1
for j in B:
if j != 0 and (B[j] == max and j < c or B[j] > max):
... | 1593354900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["6 4\n4 6 10\n14 10 12 8"] | cf4d8a5caa37def0b7c0007743139e36 | null | Today the kindergarten has a new group of $$$n$$$ kids who need to be seated at the dinner table. The chairs at the table are numbered from $$$1$$$ to $$$4n$$$. Two kids can't sit on the same chair. It is known that two kids who sit on chairs with numbers $$$a$$$ and $$$b$$$ ($$$a \neq b$$$) will indulge if: $$$gcd(a... | Output $$$t$$$ lines, which contain $$$n$$$ distinct integers from $$$1$$$ to $$$4n$$$ — the numbers of chairs that the kids should occupy in the corresponding test case. If there are multiple answers, print any of them. You can print $$$n$$$ numbers in any order. | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of kids. | standard output | standard input | PyPy 2 | Python | 800 | train_000.jsonl | f5253bb8a387871bc32aa5abf40fb248 | 256 megabytes | ["3\n2\n3\n4"] | PASSED | from collections import Counter, defaultdict, deque
import bisect
import heapq
from sys import stdin, stdout
from itertools import repeat
import math
import random
import copy
# sys.stdin = open('input')
def mod(x, y, mod):
re = 1
now = x
while y:
if y&1:
re *= now
re %= mo... | 1604327700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["5\nAAAAA\nBBBBB\nBBBBB\nCCCCC\nCCCCC", "6\nBBBBBB\nBBBBBB\nAAAACC\nAAAACC\nAAAACC\nAAAACC"] | 2befe5da2df57d23934601cbe4d4f151 | null | Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no emp... | If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes). If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C"... | The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi and yi determine the length and width of the logo of the i-th company respectively. | standard output | standard input | Python 3 | Python | 1,700 | train_010.jsonl | dd3a98511c6453d3b89f04b2d2cfea9a | 256 megabytes | ["5 1 2 5 5 2", "4 4 2 6 4 2"] | PASSED | w1,h1, w2,h2, w3,h3 = map(int, input().split())
r1, r2, r3 = sorted((w1,h1)), sorted((w2,h2)), sorted((w3,h3))
for i in range(3):
ra, ca = (r1,r2,r3)[i], "ABC"[i]
rb, cb = (r1,r2,r3)[(i+1)%3], "ABC"[(i+1)%3]
rc, cc = (r1,r2,r3)[(i+2)%3], "ABC"[(i+2)%3]
if ra[0] == ra[1]: continue
# solve a ra[1]-ra[... | 1443430800 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\nNO\nYES\nNO\nYES\nNO"] | 8b0a9c7e997034d3ecce044b9f64aeba | NoteIn the first test case, you are already in the final cell, so you spend $$$0$$$ burles.In the second, third and fourth test cases, there are two paths from $$$(1, 1)$$$ to $$$(2, 2)$$$: $$$(1, 1)$$$ $$$\rightarrow$$$ $$$(1, 2)$$$ $$$\rightarrow$$$ $$$(2, 2)$$$ or $$$(1, 1)$$$ $$$\rightarrow$$$ $$$(2, 1)$$$ $$$\righ... | There is a $$$n \times m$$$ grid. You are standing at cell $$$(1, 1)$$$ and your goal is to finish at cell $$$(n, m)$$$.You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell $$$(x, y)$$$. You can: move right to the cell $$$(x, y + 1)$$$ — it costs $$$x$$$ burles;... | For each test case, if you can reach cell $$$(n, m)$$$ spending exactly $$$k$$$ burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). | The first line contains the single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first and only line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le n, m \le 100$$$; $$$0 \le k \le 10^4$$$) — the sizes of grid and the exact amount of money you need to spend. | standard output | standard input | Python 3 | Python | 800 | train_102.jsonl | 13bc96d54f8f5a91e10fbc4bd10779c3 | 256 megabytes | ["6\n1 1 0\n2 2 2\n2 2 3\n2 2 4\n1 4 3\n100 100 10000"] | PASSED | a = int(input())
for i in range(a):
n,m,k= map(int,input().split())
count = 0
MT= [[0 for i in range(n)]for i in range(m)]
for r in range(m):
for c in range(n):
MT[r][c] = (r*c)+r+c
count = MT[-1][-1]
if count == k:
print("YES")
else:
print("NO... | 1619706900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1\n0\n2"] | fce6d690c2790951f7e04c622c3c2d44 | NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (... | There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the ... | For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point. | standard output | standard input | PyPy 3-64 | Python | 800 | train_110.jsonl | caa47f43bb5803ad5819aa0b6e6fbe10 | 256 megabytes | ["3\n8 6\n0 0\n9 15"] | PASSED | t = int(input())
import math
for i in range(t):
x,y = map(int,input().split())
if x == 0 and y == 0:
print(0)
else:
if int(math.sqrt(x**2+y**2))**2 == (x**2+y**2):
print(1)
else:
print(2) | 1647960300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1", "11"] | f00d94eb37c98a449615f0411e5a3572 | NoteIn the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}. In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}. | As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore. A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-... | Print the only integer z — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (n + 1) vertices and nonzero area from all of the rods. | The first line contains an integer n (3 ≤ n ≤ 105) — a number of rod-blanks. The second line contains n integers li (1 ≤ li ≤ 109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with n vertices and nonzero area using the rods Cicasso already has. | standard output | standard input | Python 3 | Python | 1,100 | train_000.jsonl | 784d0720df6b78ba1dce2cc79183593c | 256 megabytes | ["3\n1 2 1", "5\n20 4 3 2 1"] | PASSED | # http://codeforces.com/contest/667/problem/B
# https://en.wikipedia.org/wiki/Triangle_inequality
# 「Generalization to any polygon」参照。
# 三角不等式の一般化が載っている。
# ポリゴンができる条件は最長辺が残りすべての辺の長さの和より短いこと
# longest< x+(total-longest)
# ∴ x > 2*longest-total
n = int(input())
lst = list(map(int, input().split()))
print(2 * max(lst) -... | 1461947700 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
3 seconds | ["YES\nNO\nYES\nNO\nNO\nYES"] | 645459e0a41ec63b13648ea8dbe0f053 | NoteThe first test case is explained in the text of the problem statement.In the second test case, it is not possible to get a permutation. | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. You can perform operations on it.In one operation you can replace any element of the array $$$a_i$$$ with $$$\lfloor \frac{a_i}{2} \rfloor$$$, that is, by an integer part of dividing $$$a_i$$$ by $$$2$$$ (rounding down).See if you can apply the ope... | For each test case, output on a separate line: YES if you can make the array $$$a$$$ become a permutation of numbers from $$$1$$$ to $$$n$$$, NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response). | The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases. Each test case contains exactly two lines. The first one contains an integer $$$n$$$ ($$$1 \le n \le 50$$$), the second one contains integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). | standard output | standard input | Python 3 | Python | 1,100 | train_102.jsonl | 8971cfde9ec53a1a5d328739190bf3e2 | 256 megabytes | ["6\n\n4\n\n1 8 25 2\n\n2\n\n1 1\n\n9\n\n9 8 3 4 2 7 1 5 6\n\n3\n\n8 2 1\n\n4\n\n24 7 16 7\n\n5\n\n22 6 22 4 22"] | PASSED | def solve():
n=int(input());l=[]
arr=[int(i) for i in input().split()]
if max(arr)<n:
print("NO")
return
for i in arr :
while i>0 :
if i<=n and i not in l :
l.append(i)
break
i//=2
if len(l)==n :
... | 1641825300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n3 1 2\n4 3 5 2 7 1 6"] | 1b3ac752bc9c0b5e20a76f028d4b3c15 | NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you ca... | A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is... | For every test, output any good permutation of length $$$n$$$ on a separate line. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$). | standard output | standard input | Python 3 | Python | 800 | train_001.jsonl | 9361a5846ff68785004f14910285b5df | 256 megabytes | ["3\n1\n3\n7"] | PASSED | for i in range(int(input())):
n=int(input())
arr=[i for i in range(1,n+1)]
print(*arr)
| 1596983700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2", "10", "0", "21"] | fc892e4aac2d60e53f377a582f5ba7d3 | NoteIn the first sample 4 = 2 + 2, a = 2 is the only possibility.In the second sample 11 = 10 + 1, a = 10 — the only valid solution. Note, that a = 01 is incorrect, because a can't have leading zeroes.It's easy to check that there is no suitable a in the third sample.In the fourth sample 33 = 30 + 3 = 12 + 21, so there... | Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder.Let's denote a flip operation of an integer as follows: number is considered i... | If there is no such positive integer a without leading zeroes that a + ar = n then print 0. Otherwise, print any valid a. If there are many possible answers, you are allowed to pick any. | The first line of the input contains a single integer n (1 ≤ n ≤ 10100 000). | standard output | standard input | Python 3 | Python | 2,400 | train_032.jsonl | 3ea1b6a92fd7fdfa64caf867b5e25d93 | 256 megabytes | ["4", "11", "5", "33"] | PASSED | #!/usr/bin/python3
def can(s, n):
if n == 0:
return ""
cs = list(map(int, s))
was_over = [False for i in range(n)]
ans = [0 for i in range(n)]
i, j = 0, n - 1
last = int(n == len(cs) - 1)
while i < j:
need_a = last * 10 + cs[i]
need_b = last * 10 + cs[j]
... | 1454835900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0.333333333333 0.333333333333 0.333333333333", "0.150000000000 0.300000000000 0.550000000000", "0.057142857143 0.657142857143 0.285714285714"] | 35736970c6d629c2764eaf23299e0356 | null | The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper... | Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9. | The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively. | standard output | standard input | Python 2 | Python | 1,900 | train_018.jsonl | 5af8bd66bea8e9b899a53b5739be05b1 | 256 megabytes | ["2 2 2", "2 1 2", "1 1 3"] | PASSED | from collections import defaultdict
def main():
r, s, p = map(int, raw_input().split())
ans = [0.0] * 3
d = defaultdict(float)
nd = defaultdict(float)
d[r,s,p] = 1.0
for i in xrange(r + s + p):
for t, v in d.viewitems():
r, s, p = t
if not r and not s:
... | 1430411400 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
1 second | ["4\n20\n112"] | c4ba92632e10b1710686930f0c4536fa | NoteIn first example, one of the sequences that fits the constraints is $$$[0, 2]$$$. Consider all its non-empty subsequences: $$$[0]$$$: the bitwise XOR of this subsequence is $$$0$$$; $$$[2]$$$: the bitwise XOR of this subsequence is $$$2$$$; $$$[0, 2]$$$: the bitwise XOR of this subsequence is $$$2$$$. The sum of... | Once Divan analyzed a sequence $$$a_1, a_2, \ldots, a_n$$$ consisting of $$$n$$$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $$$a$$$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $$$a$$$.A sequence $$$c$$$ is a ... | For each test case print the coziness any suitable sequence $$$a$$$ modulo $$$10^9 + 7$$$. | The first line contains one integer number $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. The first line of each test case contains two integer numbers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the length of the sequence and the number of contiguous segments whose bitwise OR values Divan r... | standard output | standard input | Python 3 | Python | 1,500 | train_099.jsonl | 7afc1d794ba22d9c50bd956eda4d0f07 | 256 megabytes | ["3\n2 1\n1 2 2\n3 2\n1 3 5\n2 3 5\n5 4\n1 2 7\n3 3 7\n4 4 0\n4 5 2"] | PASSED | from sys import stdin
import math
from collections import deque
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
input = stdin.readline
power, mod = {}, 1000000007
def getpower(k):
if(k == 0):return 1
if(k == 1):return 2
if(k in power):
return power[k]
power[k] = (getpow... | 1637925300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["000\n#0#", "5#1\n511\n55#", "-1", "##"] | cee7f95ec969034af7d53e89539a9726 | NoteIn the third sample, there is no way to fill a cell with no empty neighbours.In the forth sample, Woll does not have to fill anything, so we should output the field from the input. | Physicist Woll likes to play one relaxing game in between his search of the theory of everything.Game interface consists of a rectangular n × m playing field and a dashboard. Initially some cells of the playing field are filled while others are empty. Dashboard contains images of all various connected (we mean connecti... | If there is no chance to win the game output the only number "-1" (without the quotes). Otherwise output any filling of the field by the figures in the following format: each figure should be represented by some digit and figures that touch each other by side should be represented by distinct digits. Every initially fi... | First line contains integers n and m (1 ≤ n, m ≤ 1000) — the height and the width of the field correspondingly. Next n lines contain m symbols each. They represent the field in a natural way: j-th character of the i-th line is "#" if the corresponding cell is filled, and "." if it is empty. | standard output | standard input | Python 2 | Python | 2,200 | train_043.jsonl | e6b810c4a6387a4ea1401d98a7972d1b | 256 megabytes | ["2 3\n...\n#.#", "3 3\n.#.\n...\n..#", "3 3\n...\n.##\n.#.", "1 2\n##"] | PASSED | import sys
n,m = map(int,raw_input().split())
f = [list(raw_input()+'#') for _ in xrange(n)]+['#'*(m+1)]
for i in xrange(n):
for j in xrange(m):
if f[i][j]!='.': continue
c=(i%3)+(j%3)*3
f[i][j]=c
if f[i][j+1]=='.':
f[i][j+1]=c
elif f[i+1][j]=='.':
f[i... | 1306077000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1\n3\n0\n2\n31072"] | 0601e3636b5d5b6ad0c8c1abb7f83d82 | NoteIn the first test case, the array is $$$[1, 2]$$$. Currently, the bitwise AND is $$$0$$$, as $$$1\ \& \ 2 = 0$$$. However, after deleting $$$1$$$ (or $$$2$$$), the array becomes $$$[2]$$$ (or $$$[1]$$$), and the bitwise AND becomes $$$2$$$ (or $$$1$$$). This can be proven to be the optimal, so the answer is $$$... | You are given an array consisting of all integers from $$$[l, r]$$$ inclusive. For example, if $$$l = 2$$$ and $$$r = 5$$$, the array would be $$$[2, 3, 4, 5]$$$. What's the minimum number of elements you can delete to make the bitwise AND of the array non-zero?A bitwise AND is a binary operation that takes two equal-l... | For each test case, output a single integer — the answer to the problem. | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains two integers $$$l$$$ and $$$r$$$ ($$$1 \leq l \leq r \leq 2 \cdot 10^5$$$) — the description of the array. | standard output | standard input | PyPy 3-64 | Python | 1,300 | train_100.jsonl | 2cc0938b4e7eafae8f0af4725db60ea6 | 256 megabytes | ["5\n1 2\n2 8\n4 5\n1 5\n100000 200000"] | PASSED | psum = [[0] * 18 for _ in range(2 * 10 ** 5 + 1)]
for i in range(1, 2 * 10 ** 5 + 1):
for j in range(18):
psum[i][j] = psum[i - 1][j] + ((i >> j) & 1) # The reason for &1 is to use only the significant bit.
tc = int(input())
for _ in range(tc):
L, R = map(int, input().split())
max_valu... | 1640356500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["4", "-1"] | 5337df1fb8a9b96ab7b66aa197a5b910 | NoteIn the first sample, the robots from strongest to weakest must be (4, 2, 1, 3), which Bessie can deduce after knowing the results of the first four rap battles.In the second sample, both (1, 3, 2) and (3, 1, 2) are possible orderings of the robots from strongest to weakest after both rap battles. | While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots o... | Print the minimum k such that the ordering of the robots by skill level is uniquely defined by the first k rap battles. If there exists more than one ordering that satisfies all m relations, output -1. | The first line of the input consists of two integers, the number of robots n (2 ≤ n ≤ 100 000) and the number of rap battles m (). The next m lines describe the results of the rap battles in the order they took place. Each consists of two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi), indicating that robot ui beat robot... | standard output | standard input | Python 3 | Python | 1,800 | train_052.jsonl | 72c0d3fdbaa0b2aa0260c96af082236d | 256 megabytes | ["4 5\n2 1\n1 3\n2 3\n4 2\n4 3", "3 2\n1 2\n3 2"] | PASSED | def g(k):
p = [[] for i in range(n)]
d = [0] * n
for x, y in t[:k]:
p[x].append(y)
d[y] += 1
x = 0
for y in range(n):
if d[y] == 0:
if x: return 0
x = y
while x:
q, x = p[x], 0
for y in q:
d[y] -= 1
if d[y] =... | 1458318900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["1", "3", "1"] | 71be4cccd3b8c494ad7cc2d8a00cf5ed | NoteIn the first example, the first bus of the first route arrives at time $$$6$$$, and the first bus of the second route arrives at time $$$9$$$, so the first route is the answer.In the second example, a bus of the third route arrives at time $$$5$$$, so it is the answer.In the third example, buses of the first route ... | It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor little boy is to wait for a bus on this rainy day. Under such circumstances, th... | Print one number — what bus route Serval will use. If there are several possible answers, you can print any of them. | The first line contains two space-separated integers $$$n$$$ and $$$t$$$ ($$$1\leq n\leq 100$$$, $$$1\leq t\leq 10^5$$$) — the number of bus routes and the time Serval goes to the station. Each of the next $$$n$$$ lines contains two space-separated integers $$$s_i$$$ and $$$d_i$$$ ($$$1\leq s_i,d_i\leq 10^5$$$) — the ... | standard output | standard input | Python 3 | Python | 1,000 | train_001.jsonl | dca683145e7ebb13458fa3e446bc2c5b | 256 megabytes | ["2 2\n6 4\n9 5", "5 5\n3 3\n2 5\n5 6\n4 9\n6 1", "3 7\n2 2\n2 3\n2 4"] | PASSED | line1 = input()
busRoutes = int(line1.split()[0])
startTime = int(line1.split()[1])
arrivals = []
intervals = []
for x in range(busRoutes):
line = input()
arrival = int(line.split()[0])
interval = int(line.split()[1])
if arrival in arrivals and interval in intervals:
arrivals.append(0)
... | 1555164300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["999 998\n\n999 997\n\n<...>\n\n999 26"] | 3d38584c3bb29e6f84546643b1be8026 | NoteThe example is trimmed. The full initial positions of the rooks in the first test are available at https://pastebin.com/qQCTXgKP. It is not guaranteed that they will behave as in the example. | This is an interactive task.Dasha and NN like playing chess. While playing a match they decided that normal chess isn't interesting enough for them, so they invented a game described below.There are $$$666$$$ black rooks and $$$1$$$ white king on the chess board of size $$$999 \times 999$$$. The white king wins if he g... | After getting king checked, you program should terminate immediately without printing anything extra. | In the beginning your program will receive $$$667$$$ lines from input. Each line contains two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x, y \leq 999$$$) — the piece's coordinates. The first line contains the coordinates of the king and the next $$$666$$$ contain the coordinates of the rooks. The first coordinate denotes... | standard output | standard input | Python 3 | Python | 2,500 | train_001.jsonl | 787e57cf2e8286722946ad3c7dac7317 | 256 megabytes | ["999 999\n1 1\n1 2\n2 1\n2 2\n1 3\n2 3\n<...>\n26 13\n26 14\n26 15\n26 16\n\n1 700 800\n\n2 1 2\n\n<...>\n\n-1 -1 -1"] | PASSED | import sys
kx, ky = [int(z) for z in sys.stdin.readline().split()]
lx = [0] * 667
ly = [0] * 667
bp = []
for i in range(1001):
bp.append([0 for z in range(1001)])
for i in range(1, 667):
lx[i], ly[i] = [int(z) for z in sys.stdin.readline().split()]
bp[lx[i]][ly[i]] = 1
los = [0] * 4
for i in range(1, 667... | 1547390100 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
1 second | ["2", "0"] | 852e1d776c560a8720d4e9f1762b255f | NoteThe graph from the first sample is shown below. Dashed edges have weight $$$0$$$, other edges have weight $$$1$$$. One of the minimum spanning trees is highlighted in orange and has total weight $$$2$$$. In the second sample, all edges have weight $$$0$$$ so any spanning tree has total weight $$$0$$$. | Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math notebooks: it is time to sort them out. This time he found an old dusty graph theory notebook with a description of a graph.It is an undirected weighted graph on $$$n$$$ vertices. It is a complete graph: each pair of vertices is c... | Output a single integer, the weight of the minimum spanning tree of the graph. | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^5$$$, $$$0 \leq m \leq \min(\frac{n(n-1)}{2},10^5)$$$), the number of vertices and the number of edges of weight $$$1$$$ in the graph. The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 ... | standard output | standard input | Python 3 | Python | 1,900 | train_003.jsonl | 116269a51d8f0ae9a31b6d6ec505742d | 256 megabytes | ["6 11\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6", "3 0"] | PASSED | class UnionFind(object):
__slots__ = ['nodes']
def __init__(self, n: int):
self.nodes = [-1]*n
def size(self, x: int) -> int:
return -self.nodes[self.find(x)]
def find(self, x: int) -> int:
if self.nodes[x] < 0:
return x
else:
self.nodes[x] = se... | 1573052700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["5\n1 2 3 5", "22\n2 4 6 22\n14 18 10 16"] | 5e7b4d1e11628152e33d3e18e30f4530 | NoteFor the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since . | Dreamoon likes to play with sets, integers and . is defined as the largest positive integer that divides both a and b.Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, .Given k and n, Dreamoon wants to make up n se... | On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them... | The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). | standard output | standard input | Python 3 | Python | 1,900 | train_010.jsonl | 4a06140d6ae1016f81af4d9242313e61 | 256 megabytes | ["1 1", "2 2"] | PASSED | load = [int(i) for i in input().split()]
n = load[0]
k = load[1]
print(k * (6 * n - 1))
for i in range(1, n + 1):
buff = ""
buff += str(k * (6 * i - 5)) + ' '
buff += str(k * (6 * i - 3)) + ' '
buff += str(k * (6 * i - 2)) + ' '
buff += str(k * (6 * i - 1)) + ' '
print(buff)
| 1413122400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
5 seconds | ["2", "-1"] | 8d4e493783fca1d8eede44af7557f4bd | null | The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. In addition, it was decided that a road between the states should be built to guarantee so that on... | Print a single integer — the minimum number of cells you need to build a road inside in order to connect all the cells of all states. If such a goal is unachievable, print -1. | The first line of the input contains the dimensions of the map n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns respectively. Each of the next n lines contain m characters, describing the rows of the map. Digits from 1 to 3 represent the accessory to the corresponding state. The character '.' corresponds to t... | standard output | standard input | PyPy 2 | Python | 2,200 | train_075.jsonl | 77777aea7b72a9801f59b6909013f7fd | 512 megabytes | ["4 5\n11..2\n#..22\n#.323\n.#333", "1 5\n1#2#3"] | PASSED | import sys
range = xrange
input = raw_input
inp = sys.stdin.read().split(); ii = 0
n = int(inp[ii]); ii += 1
m = int(inp[ii]); ii += 1
M = [0]*(m + 2)
for _ in range(n):
M.append(0)
for c in inp[ii]:
if c == '#':
M.append(0)
elif c == '.':
M.append(1)
else:
... | 1445763600 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
5 seconds | ["56\n28\n4\n60\n0"] | f2bcbbfc8062aebd0545497d815f8827 | NoteThe following explanation assumes $$$b = [2, 1]$$$ and $$$c=[2, 3, 4]$$$ (as in the sample).Examples of arrays $$$a$$$ that are not good: $$$a = [3, 2, 3]$$$ is not good because $$$a_1 > c_1$$$; $$$a = [0, -1, 3]$$$ is not good because $$$a_2 < 0$$$. One possible good array $$$a$$$ is $$$[0, 2, 4]$$$. We c... | This is the hard version of the problem. The only difference is that in this version $$$1 \le q \le 10^5$$$. You can make hacks only if both versions of the problem are solved.There is a process that takes place on arrays $$$a$$$ and $$$b$$$ of length $$$n$$$ and length $$$n-1$$$ respectively. The process is an infinit... | Output $$$q$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th query, i. e. the number of good arrays $$$a$$$ where $$$F(a, b) \geq x_i$$$ modulo $$$10^9+7$$$. | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$). The second line contains $$$n$$$ integers $$$c_1, c_2 \ldots, c_n$$$ ($$$0 \le c_i \le 100$$$). The third line contains $$$n-1$$$ integers $$$b_1, b_2, \ldots, b_{n-1}$$$ ($$$0 \le b_i \le 100$$$). The fourth line contains a single integer $$$q$$... | standard output | standard input | PyPy 3 | Python | 2,900 | train_092.jsonl | 902ab884f7a998be7f7982c5911769b4 | 256 megabytes | ["3\n2 3 4\n2 1\n5\n-1 0 1 -100000 100000"] | PASSED | def solve():
MOD = 10**9+7
n = int(input())
c = list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
q = int(input())
queries = list(map(int, input().split()))
maxans = 1
for c1 in c:
maxans = maxans * (c1+1) % MOD
ans = {}
for i in range(1... | 1624635300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0\n1\n-1\n3\n4"] | 84c0f17a45826a6e43d1f4717e62c194 | NoteIn the first test case, the two strings are already equal, so we don't have to perform any operations.In the second test case, we can perform a single operation selecting the second candle to transform $$$01$$$ into $$$11$$$.In the third test case, it's impossible to perform any operations because there are no lit ... | There are $$$n$$$ candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string $$$s$$$, where the $$$i$$$-th candle is lit if and only if $$$s_i=1$$$. Initially, the candle lights are described by a string $$$a$$$. In an operation, you select a ca... | For each test case, output the minimum number of operations required to transform $$$a$$$ to $$$b$$$, or $$$-1$$$ if it's impossible. | The first line contains an integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 10^5$$$) — the number of candles. The second line contains a string $$$a$$$ of length $$$n$$$ consisting of symbols 0 ... | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_100.jsonl | ad2c6539a8ca5a7fd137ab7ef9c01165 | 256 megabytes | ["5\n5\n11010\n11010\n2\n01\n11\n3\n000\n101\n9\n100010111\n101101100\n9\n001011011\n011010101"] | PASSED | import decimal
import heapq
import math
import os
import sys
from collections import Counter, deque
from io import BytesIO, IOBase
import bisect
from types import GeneratorType
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = ... | 1640356500 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
2 seconds | ["6\n0\n36\n4"] | e4685bb0a1bf8c2da326cd0e5b8f4fe7 | NoteIn the first test case, since all the numbers are equal, whatever permutation we take, the sequence is good. There are a total of $$$6$$$ permutations possible with numbers from $$$1$$$ to $$$3$$$: $$$[1,2,3]$$$, $$$[1,3,2]$$$, $$$[2,1,3]$$$, $$$[2,3,1]$$$, $$$[3,1,2]$$$, $$$[3,2,1]$$$.In the second test case, it c... | A sequence of $$$n$$$ non-negative integers ($$$n \ge 2$$$) $$$a_1, a_2, \dots, a_n$$$ is called good if for all $$$i$$$ from $$$1$$$ to $$$n-1$$$ the following condition holds true: $$$$$$a_1 \: \& \: a_2 \: \& \: \dots \: \& \: a_i = a_{i+1} \: \& \: a_{i+2} \: \& \: \dots \: \& \: a_n,$$$$$$ ... | Output $$$t$$$ lines, where the $$$i$$$-th line contains the number of good permutations in the $$$i$$$-th test case modulo $$$10^9 + 7$$$. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$), denoting the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the size of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_... | standard output | standard input | PyPy 3-64 | Python | 1,400 | train_088.jsonl | 69cf754c2eb7e513e7f069f278a45395 | 256 megabytes | ["4\n3\n1 1 1\n5\n1 2 3 4 5\n5\n0 2 0 3 0\n4\n1 3 5 1"] | PASSED | import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
import math
def solve():
n = int(input())
arr = list(map(int, input().split()))
x = arr[0]
for i in range(1, n):
x &= arr[i]
count = arr.count(x)
if count < 2:
print(0)
return
print((count * (... | 1618151700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["0", "1", "impossible"] | bd5912fe2c5c37658f28f6b159b39645 | NoteIn the first test case string contains 6 different letters, so we don't need to change anything.In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example... | Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible.String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. | Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. | First line of input contains string s, consisting only of lowercase Latin letters (1 ≤ |s| ≤ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≤ k ≤ 26). | standard output | standard input | Python 3 | Python | 1,000 | train_006.jsonl | dfb3d3b97813938b1ca9d196880963f2 | 256 megabytes | ["yandex\n6", "yahoo\n5", "google\n7"] | PASSED | s = input()
k = int(input())
t = frozenset(s)
if len(s) < k:
print("impossible")
exit()
print(max(k - len(t), 0)) | 1503592500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["1\n2 \n3\n2 2 90 \n1\n4999999937 \n1\n4998207083"] | f8d064c90f1f2b4a18386795dbcd9cb9 | null | You are given an integer $$$n$$$ ($$$n > 1$$$).Your task is to find a sequence of integers $$$a_1, a_2, \ldots, a_k$$$ such that: each $$$a_i$$$ is strictly greater than $$$1$$$; $$$a_1 \cdot a_2 \cdot \ldots \cdot a_k = n$$$ (i. e. the product of this sequence is $$$n$$$); $$$a_{i + 1}$$$ is divisible by $$$a_i$... | For each test case, print the answer: in the first line, print one positive integer $$$k$$$ — the maximum possible length of $$$a$$$. In the second line, print $$$k$$$ integers $$$a_1, a_2, \ldots, a_k$$$ — the sequence of length $$$k$$$ satisfying the conditions from the problem statement. If there are several answers... | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$2 \le n \le 10^{10}$$$). It is guaranteed that the sum of $$$n$$$ does not exceed $$$10^{10}$$$ ($$$\sum n \le 10^... | standard output | standard input | Python 3 | Python | null | train_004.jsonl | 8ef7814241813f767fdefbc32a16c695 | 256 megabytes | ["4\n2\n360\n4999999937\n4998207083"] | PASSED | def decompose(number):
prime_factors = []
while number % 2 == 0:
prime_factors.append(2)
number = number / 2
for i in range(3, int(number**(1/2)) + 1, 2):
while number % i == 0:
prime_factors.append(int(i))
number = number / i
if number > 2:
prime_... | 1606228500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["Yes\nNo\nYes\nYes\nNo"] | afce38aa7065da88d824d1d981b5b338 | NoteFor $$$1$$$st case: We must select element $$$999$$$, and the sum is odd.For $$$2$$$nd case: We must select element $$$1000$$$, so overall sum is not odd.For $$$3$$$rd case: We can select element $$$51$$$.For $$$4$$$th case: We must select both elements $$$50$$$ and $$$51$$$ — so overall sum is odd.For $$$5$$$th c... | Shubham has an array $$$a$$$ of size $$$n$$$, and wants to select exactly $$$x$$$ elements from it, such that their sum is odd. These elements do not have to be consecutive. The elements of the array are not guaranteed to be distinct.Tell him whether he can do so. | For each test case, print "Yes" or "No" depending on whether it is possible to choose $$$x$$$ elements such that their sum is odd. You may print every letter in any case you want. | The first line of the input 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 of each test case contains two integers $$$n$$$ and $$$x$$$ $$$(1 \le x \le n \le 1000)$$$ — the length of the array and the number of elements you n... | standard output | standard input | Python 3 | Python | 1,200 | train_006.jsonl | a1e5ac91a1d94a564c71c75a94ee4ad1 | 256 megabytes | ["5\n1 1\n999\n1 1\n1000\n2 1\n51 50\n2 2\n51 50\n3 3\n101 102 103"] | PASSED | from sys import stdin,stdout
for __ in range(int(stdin.readline())):
n,x = map(int,stdin.readline().split())
a = list(map(int,stdin.readline().split()))
o = 0
e = 0
for i in range(n):
if a[i]%2 == 1:
o+=1
else:
e+=1
f=0
l = min(x,o)
for i in range(... | 1590935700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1", "6"] | 2475df43379ffd450fa661927ae3b734 | NoteThe first example: aa $$$+$$$ bb $$$\to$$$ abba. The second example: aab $$$+$$$ abcac $$$=$$$ aababcac $$$\to$$$ aabccbaa aab $$$+$$$ aa $$$=$$$ aabaa abcac $$$+$$$ aa $$$=$$$ abcacaa $$$\to$$$ aacbcaa dffe $$$+$$$ ed $$$=$$$ dffeed $$$\to$$$ fdeedf dffe $$$+$$$ aade $$$=$$$ dffeaade $$$\to$$$ adfaafde ed $$$+$$... | After learning a lot about space exploration, a little girl named Ana wants to change the subject.Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whether it's a palindrome or not, but soon she grew tired of this problem, so she... | Output one number, representing how many palindrome pairs there are in the array. | The first line contains a positive integer $$$N$$$ ($$$1 \le N \le 100\,000$$$), representing the length of the input array. Eacg of the next $$$N$$$ lines contains a string (consisting of lowercase English letters from 'a' to 'z') — an element of the input array. The total number of characters in the input array will... | standard output | standard input | PyPy 3 | Python | 1,600 | train_003.jsonl | ab549f3abda40bede48f94f632480b6f | 256 megabytes | ["3\naa\nbb\ncd", "6\naab\nabcac\ndffe\ned\naa\naade"] | PASSED | from collections import Counter
n = int(input())
strings = []
for i in range(0,n):
counter = { x: 0 for x in range(ord('a'), ord('z')+1) }
napis = input()
for val in napis:
counter[ord(val)] = (counter[ord(val)] + 1) % 2
napis = ""
for key, val in counter.items():
if val != 0:
napis+=chr(ke... | 1537612500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["0.500000000", "3.000000000"] | c0e18f6105f4b8129ebd73bbd12e904d | null | The Little Elephant loves permutations of integers from 1 to n very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some elements. As a result, he must receive a permutation 1, 2, 3, ..., n.This time the Little Elephant has permutation p1, p2, ..., pn. Its sortin... | In the only line print a single real number — the answer to the problem. The answer will be considered correct if its relative or absolute error does not exceed 10 - 6. | The first line contains two integers n and m (1 ≤ n, m ≤ 1000, n > 1) — the permutation size and the number of moves. The second line contains n distinct integers, not exceeding n — the initial permutation. Next m lines each contain two integers: the i-th line contains integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — ... | standard output | standard input | Python 2 | Python | 2,600 | train_029.jsonl | 901e74fda5ee93a2bbac133066882293 | 256 megabytes | ["2 1\n1 2\n1 2", "4 3\n1 3 2 4\n1 2\n2 3\n1 4"] | PASSED | n, m = map(int, raw_input().split())
s = map(int, raw_input().split())
dp = [[0.0] * 2000 for i in xrange(2000)]
for i in xrange(n) :
for j in xrange(n) :
if s[i] > s[j] : dp[i][j] = 1.0
else : dp[i][j] = 0.0
for i in xrange(m) :
a, b = map(int, raw_input().split())
a = a - 1
b = b - ... | 1356190200 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
1 second | ["? 0 0\n? 10 1\n! 1\n? 0 0\n? 3 4\n? 2 5\n! 2\n? 2 4\n? 2 5\n? 3 10\n? 9 1\n! 3"] | eab8e5ac203d9f10c893ea35d249fe84 | NoteIn the first test, you should play $$$3$$$ games with Petya's numbers $$$1$$$, $$$2$$$ and $$$3$$$.In the first game, Petya will answer "x" (without quotes) to any question, because $$$(x \bmod 1) = 0$$$ for any integer $$$x$$$. In the second game, if you will ask pair $$$(0, 0)$$$, the answer will be "x" (without ... | This is an interactive problem.Vasya and Petya are going to play the following game: Petya has some positive integer number $$$a$$$. After that Vasya should guess this number using the following questions. He can say a pair of non-negative integer numbers $$$(x, y)$$$. Petya will answer him: "x", if $$$(x \bmod a) \g... | null | null | standard output | standard input | Python 3 | Python | 2,000 | train_010.jsonl | bd1b141da7da481011b7fda3428ec4f3 | 256 megabytes | ["start\nx\nx\nstart\nx\nx\ny\nstart\nx\nx\ny\ny\nend"] | PASSED | import sys
def solve(x, y):
global aaa
if x%aaa>=y%aaa: return "x"
else: return "y"
while True:
cnt = 0
op=input()
if op=="end": break
left,right=1,2
while True:
cnt += 1
print("?", left, right)
sys.stdout.flush()
# result=solve(left, right)
... | 1548167700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1\n6\n6"] | f2b2d12ab1c8a511d2ca550faa9768d4 | NoteIn the first test case, only permutation $$$p=[5,4,3,2,1]$$$ satisfies the constraint condition.In the second test case, there are $$$6$$$ permutations satisfying the constraint condition, which are: $$$[3,4,5,2,1]$$$ $$$\rightarrow$$$ $$$[3,4,2,1,5]$$$ $$$\rightarrow$$$ $$$[3,2,1,4,5]$$$ $$$[3,5,4,2,1]$$$ $$$\ri... | Tokitsukaze has a permutation $$$p$$$. She performed the following operation to $$$p$$$ exactly $$$k$$$ times: in one operation, for each $$$i$$$ from $$$1$$$ to $$$n - 1$$$ in order, if $$$p_i$$$ > $$$p_{i+1}$$$, swap $$$p_i$$$, $$$p_{i+1}$$$. After exactly $$$k$$$ times of operations, Tokitsukaze got a new sequenc... | For each test case, print a single integer — the number of different permutations modulo $$$998\,244\,353$$$. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Each test case consists of two lines. The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^6$$$; $$$0 \leq k \leq n-1$$$) — the length of the permutation and the exactly number of operations.... | standard output | standard input | PyPy 3-64 | Python | 2,500 | train_097.jsonl | b808754e754932416a428be3448ff7ae | 256 megabytes | ["3\n\n5 0\n\n0 1 2 3 4\n\n5 2\n\n-1 1 2 0 0\n\n5 2\n\n0 1 1 0 0"] | PASSED | #!/usr/bin/env PyPy3
from collections import Counter, defaultdict, deque
import itertools
import re
import math
from functools import reduce
import operator
import bisect
from heapq import *
import functools
mod=998244353
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
new... | 1652020500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1 2 3 6\n4 6 2 10\n9 0 7 3\n2 8 8 2\n\n\n1 1\n1 2\n1 3\n2 3\n2 4\n3 4\n4 4\n\n1 1\n2 1\n3 1\n3 2\n3 3\n3 4\n4 4\n\n1 1\n1 2\n1 3\n1 4\n2 4\n3 4\n4 4"] | 8b0ec419248bb98b5e0c3d991c7e14fb | NoteThe duck's three journeys are illustrated below.$$$1 + 2 + 3 + 2 + 10 + 3 + 2 = 23$$$ $$$1 + 4 + 9 + 0 + 7 + 3 + 2 = 26$$$ $$$1 + 2 + 3 + 6 + 10 + 3 + 2 = 27$$$ | This is an interactive problem.Omkar has just come across a duck! The duck is walking on a grid with $$$n$$$ rows and $$$n$$$ columns ($$$2 \leq n \leq 25$$$) so that the grid contains a total of $$$n^2$$$ cells. Let's denote by $$$(x, y)$$$ the cell in the $$$x$$$-th row from the top and the $$$y$$$-th column from the... | null | null | standard output | standard input | Python 3 | Python | 2,100 | train_009.jsonl | baa0c91fa2f308c557ca8c9110c8c716 | 256 megabytes | ["4\n\n\n\n\n3\n23\n\n\n\n\n\n\n\n26\n\n\n\n\n\n\n\n27"] | PASSED | import sys
n = int(input())
row = []
for x in range(0,n):
row.append(0)
for r in row:
print(r, end = ' ')
print()
sys.stdout.flush()
for y in range(2,n+1):
for x in range(0,n-1):
row[x] = row[x+1]+pow(2,2*n-2-x-y)
print(row[x], end=' ')
if(y!=n): print(0)
else: print(2**(n-1)-1)
... | 1597588500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["124124", "100100"] | 84650ac76888fa6d17bc0283b0c0ab0c | NoteIn first example 124124 is the smallest number greater than 123456 that can be written with period L = 3 (P = 124).In the second example 100100 is the smallest number greater than 12345 with period L = 3 (P=100) | Alice became interested in periods of integer numbers. We say positive $$$X$$$ integer number is periodic with length $$$L$$$ if there exists positive integer number $$$P$$$ with $$$L$$$ digits such that $$$X$$$ can be written as $$$PPPP…P$$$. For example:$$$X = 123123123$$$ is periodic number with length $$$L = 3$$$ a... | One positive integer number representing smallest positive number that is periodic with length $$$L$$$ and is greater than $$$A$$$. | First line contains one positive integer number $$$L \ (1 \leq L \leq 10^5)$$$ representing length of the period. Second line contains one positive integer number $$$A \ (1 \leq A \leq 10^{100 000})$$$. | standard output | standard input | Python 3 | Python | 1,700 | train_055.jsonl | 6412f51877b8f0e0c5387f8499f94d0d | 256 megabytes | ["3\n123456", "3\n12345"] | PASSED | def revive(l):
res = pow(10 , l-1)
return str(res)
l = int(input())
s = input()
val = 0
if len(s) % l == 0:
ans = s[:l]
if ans*(len(s)//l) > s:
print(ans*(len(s)//l))
exit()
elif ans == "9"*l:
ans = revive(l)
val = l
else:
ans = str(int(ans) + 1)
else:
... | 1568554500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["YES\nNO"] | 8b2d29c3686bb2d58cdd08e73073d461 | NoteThe two sample test cases correspond to the two mazes in the picture. | You are given a circular maze such as the ones shown in the figures. Determine if it can be solved, i.e., if there is a path which goes from the center to the outside of the maze which does not touch any wall. The maze is described by $$$n$$$ walls. Each wall can be either circular or straight. Circular walls are ... | For each test case, print YES if the maze can be solved and NO otherwise. | Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1\le t\le 20$$$) — the number of test cases. The descriptions of the $$$t$$$ test cases follow. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 5000$$$) — the number of walls. Each of the following $$$... | standard output | standard input | PyPy 2 | Python | -1 | train_085.jsonl | e74eb510a755d424ecea4722ba6270ad | 256 megabytes | ["2\n5\nC 1 180 90\nC 5 250 230\nC 10 150 140\nC 20 185 180\nS 1 20 180\n6\nC 1 180 90\nC 5 250 230\nC 10 150 140\nC 20 185 180\nS 1 20 180\nS 5 10 0"] | PASSED | 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 inst():
s = input()
return s[:le... | 1650798300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["3\n1 2 3", "4\n1 3 5 7"] | d55afdb4a83aebdfce5a62e4ec934adb | NoteIn the first example, the product of the elements is $$$6$$$ which is congruent to $$$1$$$ modulo $$$5$$$. The only longer subsequence is $$$[1,2,3,4]$$$. Its product is $$$24$$$ which is congruent to $$$4$$$ modulo $$$5$$$. Hence, the answer is $$$[1,2,3]$$$. | Now you get Baby Ehab's first words: "Given an integer $$$n$$$, find the longest subsequence of $$$[1,2, \ldots, n-1]$$$ whose product is $$$1$$$ modulo $$$n$$$." Please solve the problem.A sequence $$$b$$$ is a subsequence of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deleting some (possibly all) elem... | The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. | The only line contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$). | standard output | standard input | PyPy 3 | Python | 1,600 | train_110.jsonl | be296ef10fa7a7639a1f0f54a116cfde | 256 megabytes | ["5", "8"] | PASSED | from math import sqrt
n = int(input())
m = n
l = [0] * (n - 1)
if n%2 == 0 :
while m % 2 == 0:
m/=2
if m==1:
x = 2
else:
for i in range(2, n, 2) :
l[i - 1] += 1
for i in range(3, int(sqrt(m)) + 1, 2):
if m%i == 0:
while m % i == 0:
... | 1618839300 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
2 seconds | ["17"] | 3b4100b844e925af971061df42521712 | NoteIn the sample test the most effective way is to make a workgroup from employees number 1, 2, 4, 5, 6. | One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior.We will call person a a subordinates of another person b, if either b is an immediate s... | Print a single integer — the maximum possible efficiency of the workgroup. | The first line contains integer n (1 ≤ n ≤ 2·105) — the number of workers of the Big Software Company. Then n lines follow, describing the company employees. The i-th line contains two integers pi, ai (1 ≤ ai ≤ 105) — the number of the person who is the i-th employee's immediate superior and i-th employee's efficiency... | standard output | standard input | Python 3 | Python | 2,000 | train_006.jsonl | 4594880860d878e618f5a0dbaa035fd7 | 256 megabytes | ["7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2"] | PASSED | n = int(input())
t = [list(map(int, input().split())) for q in range(n)]
n += 1
u = [-1e7] * n
v = [0] * n
for i, (j, a) in list(enumerate(t, 1))[::-1]:
u[i] = max(u[i], v[i] + a)
v[j], u[j] = max(v[j] + v[i], u[j] + u[i]), max(v[j] + u[i], u[j] + v[i])
print(u[1]) | 1429286400 | [
"trees",
"strings",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
1,
1
] | |
2 seconds | ["3", "2", "0"] | f8f0d00f8d93b5a4bbf0b2eedf1e754a | NoteIn the first sample, we are given a polynomial P(x) = 10 - 9x - 3x2 + 5x3.Limak can change one coefficient in three ways: He can set a0 = - 10. Then he would get Q(x) = - 10 - 9x - 3x2 + 5x3 and indeed Q(2) = - 10 - 18 - 12 + 40 = 0. Or he can set a2 = - 8. Then Q(x) = 10 - 9x - 8x2 + 5x3 and indeed Q(2) = 10... | Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials.He considers a polynomial valid if its degree is n and its coefficients are integers not exceeding k by the absolute value. More formally:Let a0, a1, ..., an denote the coefficients, so . Then, a polynomial P(x) is valid if... | Print the number of ways to change one coefficient to get a valid polynomial Q that Q(2) = 0. | The first line contains two integers n and k (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 109) — the degree of the polynomial and the limit for absolute values of coefficients. The second line contains n + 1 integers a0, a1, ..., an (|ai| ≤ k, an ≠ 0) — describing a valid polynomial . It's guaranteed that P(2) ≠ 0. | standard output | standard input | Python 2 | Python | 2,200 | train_008.jsonl | 18e3fd640bdd9d93bebe07a76bab9e51 | 256 megabytes | ["3 1000000000\n10 -9 -3 5", "3 12\n10 -9 -3 5", "2 20\n14 -7 19"] | PASSED | from sys import stdin
from itertools import repeat
def main():
n, k = map(int, stdin.readline().split())
a = map(int, stdin.readline().split(), repeat(10, n + 1))
r = [0] * (n + 50)
c = 0
l = n + 100
for i, x in enumerate(a):
c += x
if c >= 0:
c, r[i] = c / 2, c % 2
... | 1459182900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1", "3", "9", "91"] | 43fbb05dc01b5302f19d923e45e325e7 | NoteIn the first sample, Ostap has to paint both vertices black.In the second sample, it is enough to paint only one of two vertices, thus the answer is 3: Ostap can paint only vertex 1, only vertex 2, vertices 1 and 2 both.In the third sample, the valid ways to paint vertices are: {1, 3}, {1, 4}, {2, 3}, {2, 4}, {1, 2... | Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph. Ostap's tree now has n vertices. He wants to paint some vertices of the tree black such that from any vertex u there is at least one black vertex v at distance no mor... | Print one integer — the remainder of division of the number of ways to paint the tree by 1 000 000 007 (109 + 7). | The first line of the input contains two integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ min(20, n - 1)) — the number of vertices in Ostap's tree and the maximum allowed distance to the nearest black vertex. Don't miss the unusual constraint for k. Each of the next n - 1 lines contain two integers ui and vi (1 ≤ ui, vi ≤ n) — i... | standard output | standard input | Python 3 | Python | 2,500 | train_052.jsonl | 662c78faf42f5f70d43c33b36151b5e1 | 256 megabytes | ["2 0\n1 2", "2 1\n1 2", "4 1\n1 2\n2 3\n3 4", "7 2\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7"] | PASSED |
import sys
#sys.stdin=open("data.txt")
#sys.stdout=open("data.txt","w")
input=sys.stdin.readline
n,k=map(int,input().split())
g=[[] for _ in range(n+1)]
vis=[0]*(n+1)
for _ in range(n-1):
u,v=map(int,input().split())
g[u].append(v)
g[v].append(u)
def getans(u,k):
vis[u]=1
# first k -> need k
... | 1480264500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["3\n4\n1\n4\n3\n1\n1608737403"] | bf21c4809cd10904f05d531dd7af4ab5 | NoteLet's analyze the test cases of the example. In the first test case, you write three messages containing $$$1$$$, $$$2$$$ and $$$3$$$ emotes respectively, and since $$$1 + 2 + 3 \ge 6$$$, you get banned after that. In the second test case, you write four messages containing $$$1$$$, $$$2$$$, $$$3$$$ and $$$4$$$ e... | You are a usual chat user on the most famous streaming platform. Of course, there are some moments when you just want to chill and spam something.More precisely, you want to spam the emote triangle of size $$$k$$$. It consists of $$$2k-1$$$ messages. The first message consists of one emote, the second one — of two emot... | For each test case, print the number of messages you will write before getting banned for the corresponding values $$$k$$$ and $$$x$$$. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains integers $$$k$$$ and $$$x$$$ ($$$1 \le k \le 10^9; 1 \le x \le 10^{18}$$$). | standard output | standard input | PyPy 3-64 | Python | 1,300 | train_098.jsonl | 177b9b58b3139380bcfdec4242f2708b | 512 megabytes | ["7\n4 6\n4 7\n1 2\n3 7\n2 5\n100 1\n1000000000 923456789987654321"] | PASSED | from heapq import heapify, heappush, heappop
from collections import Counter, defaultdict, deque
from queue import PriorityQueue
from itertools import combinations, product, permutations
from bisect import bisect_left, bisect_right
from functools import lru_cache
from sys import stdin, stdout # for input /output
import... | 1637573700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\n2 5", "NO"] | d45f775613e701bbdaa4e457e6e189e2 | NoteIn the first testcase the resulting string is "aacabba". | You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position $$$3$$$ and ends in position $$$6$$$), but "aa" or "d" aren't substrings of this string. So the substring o... | If it is impossible to reverse some substring of the given string to obtain a string which is lexicographically less, print "NO". Otherwise print "YES" and two indices $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le n$$$) denoting the substring you have to reverse. If there are multiple answers, you can print any. | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) — the length of $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$ consisting only of lowercase Latin letters. | standard output | standard input | PyPy 3 | Python | 1,000 | train_011.jsonl | 9d84d103a211933635be2035f4cedd9f | 256 megabytes | ["7\nabacaba", "6\naabcfg"] | PASSED | '''input
6
aabcfg
'''
from sys import stdin, stdout
import math
from copy import deepcopy
from collections import defaultdict
import heapq
# main starts
n = int(stdin.readline().strip())
string = list(stdin.readline().strip())
for i in range(1, len(string)):
if string[i - 1] <= string[i]:
continue
else:
string[... | 1555943700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["11 492\n13 26\n140133 160776\n1 1"] | 04330cb392bcfd51d1acffd72c8004cb | NoteIn the example: $$$gcd(11, 492) = 1$$$ $$$gcd(13, 26) = 13$$$ $$$gcd(140133, 160776) = 21$$$ $$$gcd(1, 1) = 1$$$ | You are given three integers $$$a$$$, $$$b$$$ and $$$c$$$.Find two positive integers $$$x$$$ and $$$y$$$ ($$$x > 0$$$, $$$y > 0$$$) such that: the decimal representation of $$$x$$$ without leading zeroes consists of $$$a$$$ digits; the decimal representation of $$$y$$$ without leading zeroes consists of $$$b$$... | For each testcase print two positive integers — $$$x$$$ and $$$y$$$ ($$$x > 0$$$, $$$y > 0$$$) such that the decimal representation of $$$x$$$ without leading zeroes consists of $$$a$$$ digits; the decimal representation of $$$y$$$ without leading zeroes consists of $$$b$$$ digits; the decimal representation... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 285$$$) — the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b \le 9$$$, $$$1 \le c \le min(a, b)$$$) — the required lengths of the numbers. It can be shown that the answer exists for ... | standard output | standard input | PyPy 3-64 | Python | 1,100 | train_089.jsonl | a868f822fa11acf65ae027e92b416ca4 | 256 megabytes | ["4\n2 3 1\n2 2 2\n6 6 2\n1 1 1"] | PASSED | def func_gcd(a,b):
if b==0:
return a
return func_gcd(b, a%b)
T = int(input())
for t in range(T):
a, b, c = map(int, input().split())
x_arr = ["1"] + ["0"]*(a-1)
y_arr = ["1"]*(b-c+1) + ["0"]*(c-1)
x = ""
y = ""
for elem in x_arr:
x += elem
for elem in y_arr:
y += elem
print(x, y) | 1618238100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
4 seconds | ["1 2 5 8", "1 2 3 4 5 6", "1 3 7"] | e25efe1020ae64d55b3257ba457f809d | null | Once upon a time there was only one router in the well-known company Bmail. Years went by and over time new routers were purchased. Every time they bought a new router, they connected it to one of the routers bought before it. You are given the values $$$p_i$$$ — the index of the router to which the $$$i$$$-th router w... | Print the path from the $$$1$$$-st to the $$$n$$$-th router. It starts with $$$1$$$ and ends with $$$n$$$. All the elements in the path should be distinct. | The first line contains integer number $$$n$$$ ($$$2 \le n \le 200000$$$) — the number of the routers. The following line contains $$$n-1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i < i$$$), where $$$p_i$$$ is equal to index of the router to which the $$$i$$$-th was connected after purchase. | standard output | standard input | PyPy 2 | Python | 900 | train_008.jsonl | 87e98ed66fa3037ce625dfc65c66fc15 | 256 megabytes | ["8\n1 1 2 2 3 2 5", "6\n1 2 3 4 5", "7\n1 1 2 3 4 3"] | PASSED | a=int(input())
c=[]
h = raw_input()
b=(list(map(int,(h.split(' ')))))
k=a-2
c.append(a)
i=1
while k>=0:
c.append(b[k])
k=c[i]-2
i=i+1
c.reverse()
m=len(c)
for i in range (m):
print c[i] | 1539335100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["0\n1\n1\n-1\n2\n1"] | 96f0df1c8e014229e5ef773789aa2205 | NoteIn the first test case, the product of all elements is initially $$$2$$$, so no operations needed.In the second test case, the product of elements initially equals $$$6$$$. We can apply the operation for $$$i = 2$$$, and then $$$a_2$$$ becomes $$$2\cdot2=4$$$, and the product of numbers becomes $$$3\cdot4=12$$$, an... | You are given an array of positive integers $$$a_1, a_2, \ldots, a_n$$$.Make the product of all the numbers in the array (that is, $$$a_1 \cdot a_2 \cdot \ldots \cdot a_n$$$) divisible by $$$2^n$$$.You can perform the following operation as many times as you like: select an arbitrary index $$$i$$$ ($$$1 \leq i \leq n$... | For each test case, print the least number of operations to make the product of all numbers in the array divisible by $$$2^n$$$. If the answer does not exist, print -1. | The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4$$$) — the number test cases. Then the descriptions of the input data sets follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of array $$$a$$$. The second line of e... | standard output | standard input | Python 3 | Python | 1,200 | train_094.jsonl | 2d43814374b3975000b8628c444355b5 | 256 megabytes | ["6\n\n1\n\n2\n\n2\n\n3 2\n\n3\n\n10 6 11\n\n4\n\n13 17 1 1\n\n5\n\n1 1 12 1 1\n\n6\n\n20 7 14 18 3 5"] | PASSED | def countPow2(k):
count = 0
while k % 2 == 0:
count += 1
k //= 2
return count
for _ in [0] * int(input()):
n = int(input())
nums = list(map(int, input().rstrip().split()))
total = extra = 0
extArr = []
for num in nums:
total += countPow2(num)
... | 1665930900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["8", "5"] | c8667e7bca99c27e6da1841de8a15790 | NoteAll possible coloring patterns of the first sample are given below. | You have a rooted tree consisting of n vertices. Let's number them with integers from 1 to n inclusive. The root of the tree is the vertex 1. For each i > 1 direct parent of the vertex i is pi. We say that vertex i is child for its direct parent pi.You have initially painted all the vertices with red color. You like... | Print a single integer — the answer to the problem modulo 1000000007 (109 + 7) | The first line contains a single integer n (2 ≤ n ≤ 105) — the number of vertexes in the tree. The second line contains n - 1 integers p2, p3, ..., pn (1 ≤ pi < i). Number pi is the parent of vertex i. | standard output | standard input | Python 2 | Python | 2,700 | train_010.jsonl | dc7fe4de1a1c1577dba1eb2b12bbbe47 | 256 megabytes | ["4\n1 2 1", "3\n1 1"] | PASSED | from sys import stdin
def main():
n = int(stdin.readline())
a = map(int, stdin.readline().split())
e = [[] for _ in xrange(n)]
for i, x in enumerate(a, 1):
e[x-1].append(i)
dp = [[0, 0] for _ in xrange(n)]
mod = 1000000007
for i in xrange(n-1, -1, -1):
t0, t1 = 0, 1
f... | 1414170000 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
3 seconds | ["3\n1 2 3\n2\n4 5\n2\nANSWER\n1 2\n2 3\n3 4\n2 5"] | 685f266dbbc24434913fa092c0ac1f3f | NoteIn the sample, the tree is as follows. $$$n = 5$$$ is given to the program. The program then asks Mikaela a question where $$$S = \{1, 2, 3\}$$$, $$$T = \{4, 5\}$$$, and $$$v = 2$$$, to which she replies with $$$5$$$ (the pairs $$$(s, t)$$$ are $$$(1, 4)$$$, $$$(1, 5)$$$, $$$(2, 4)$$$, $$$(2, 5)$$$, and $$$(3, 5)$... | This is an interactive problem.A legendary tree rests deep in the forest. Legend has it that individuals who realize this tree would eternally become a Legendary Grandmaster.To help you determine the tree, Mikaela the Goddess has revealed to you that the tree contains $$$n$$$ vertices, enumerated from $$$1$$$ through $... | When program has realized the tree and is ready to report the edges, print "ANSWER" in a separate line. Make sure that all letters are capitalized. Then, print $$$n-1$$$ lines, each containing two space-separated integers, denoting the vertices that are the endpoints of a certain edge. Each edge should be reported exac... | The first line contains an integer $$$n$$$ ($$$2 \leq n \leq 500$$$) — the number of vertices in the tree. | standard output | standard input | PyPy 3 | Python | 3,100 | train_024.jsonl | 8211dbca8b128af3d4a18e859e29dca8 | 256 megabytes | ["5\n5"] | PASSED | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'cnyali_lk'
import sys
def query(s,t,v):
if len(s)==0 or len(t)==0:
return 0
print(len(s))
for i in s:
print(i,end=' ')
print()
print(len(t))
for i in t:
print(i,end=' ')
print()
print(v)
sys.stdout.f... | 1551022500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["1", "2\n2"] | a2b71d66ea1fdc3249e37be3ab0e67ef | null | Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this orb being of any kind is equal. As the north of wall is full of dangers, he... | Output q lines. On i-th of them output single integer — answer for i-th query. | First line consists of two space separated integers k, q (1 ≤ k, q ≤ 1000) — number of different kinds of orbs and number of queries respectively. Each of the next q lines contain a single integer pi (1 ≤ pi ≤ 1000) — i-th query. | standard output | standard input | PyPy 2 | Python | 2,200 | train_002.jsonl | de0c6f0d62bc8e0c0362c588e21ebfd6 | 256 megabytes | ["1 1\n1", "2 2\n1\n2"] | PASSED | import random
import time
seed = int(time.time())
random.seed(seed)
def solve(k, p):
pass
def main():
xs = [int(x) for x in raw_input().strip().split()]
k = xs[0]
dp = [[0.0 for _ in range(k+1)] for _ in range(10000)]
for d in range(1, 10000):
dp[d][1] = 1.0
for ki in range(2, min... | 1487606700 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
2 seconds | ["0.5", "-1", "0.625"] | d01f153d0049c22a21e321d5c4fbece9 | NoteIn the first sample it is optimal to build the reserve with the radius equal to $$$0.5$$$ and the center in $$$(0,\ 0.5)$$$.In the second sample it is impossible to build a reserve.In the third sample it is optimal to build the reserve with the radius equal to $$$\frac{5}{8}$$$ and the center in $$$(\frac{1}{2},\ \... | There is a forest that we model as a plane and live $$$n$$$ rare animals. Animal number $$$i$$$ has its lair in the point $$$(x_{i}, y_{i})$$$. In order to protect them, a decision to build a nature reserve has been made.The reserve must have a form of a circle containing all lairs. There is also a straight river flowi... | If the reserve cannot be built, print $$$-1$$$. Otherwise print the minimum radius. Your answer will be accepted if absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|a - b|}{\max{(1, |b|)}} \le... | The first line contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of animals. Each of the next $$$n$$$ lines contains two integers $$$x_{i}$$$, $$$y_{i}$$$ ($$$-10^7 \le x_{i}, y_{i} \le 10^7$$$) — the coordinates of the $$$i$$$-th animal's lair. It is guaranteed that $$$y_{i} \neq 0$$$. No two lairs c... | standard output | standard input | PyPy 3 | Python | 2,200 | train_075.jsonl | 35db850cdb879297958ecc38b003f782 | 256 megabytes | ["1\n0 1", "3\n0 1\n0 2\n0 -3", "2\n0 1\n1 1"] | PASSED |
l , r =-100000000, 1000000000
def check(mid):
mx = 0
for i in range(n):
x,y = x1[i],y1[i]
mx = max (mx ,(x1[i] - mid) ** 2 / (2 * y1[i]) + (y1[i] / 2))
return mx
n = int(input())
count1 = 0
count2 = 0
x1 = []
y1 = []
for i in range(n):
a,b = map(int,input().split())
if b>=0:
... | 1538750100 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
1 second | ["1 2 3 4 5", "2 4 3 7 1", "-1"] | b85c8bfbe67a23a81bef755f9313115a | Notegcd(x, y) is greatest common divisor of x and y. | It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he remov... | If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109). | The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108). | standard output | standard input | Python 3 | Python | 1,500 | train_027.jsonl | badc6d98fcdde7d8aa0ec13fda172fc5 | 256 megabytes | ["5 2", "5 3", "7 2"] | PASSED | n,k=map(int, input().split(' '))
if k<n//2 :
print(-1)
elif n==1:
if k == 0:
print(1)
else:
print(-1)
else:
x=(k-n//2)+1
ans=[x,2*x]
for i in range(n-2):
ans.append(200000001 + i)
print(*ans)
| 1396798800 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
2 seconds | ["2", "1", "18", "16"] | 6956d1c98c4047f1b8f832df3566ddce | Note The first sample will be (1 + 1) = 2. The second sample will be (2 + (1 - 2)) = 1. The third sample will be ((1 - (5 - 7)) + ((6 + 2) + 7)) = 18. The fourth sample will be ((1 + (5 + 7)) - ((6 - 2) - 7)) = 16. | Ancient Egyptians are known to have understood difficult concepts in mathematics. The ancient Egyptian mathematician Ahmes liked to write a kind of arithmetic expressions on papyrus paper which he called as Ahmes arithmetic expression.An Ahmes arithmetic expression can be defined as: "d" is an Ahmes arithmetic expres... | Print one line containing the answer to the problem. | The first line contains a string E (1 ≤ |E| ≤ 104) — a valid Ahmes arithmetic expression. All operators are erased and replaced with '?'. The second line contains two space-separated integers P and M (0 ≤ min(P, M) ≤ 100) — the number of plus and minus operators, respectively. It is guaranteed that P + M = the number... | standard output | standard input | PyPy 3 | Python | 2,300 | train_017.jsonl | b2481597d857a96d042ef7525a5b366b | 256 megabytes | ["(1?1)\n1 0", "(2?(1?2))\n1 1", "((1?(5?7))?((6?2)?7))\n3 2", "((1?(5?7))?((6?2)?7))\n2 3"] | PASSED | from math import inf
class Node:
def __init__(self, parent = None, leftExp = None, rightExp = None, signQ = 0):
self.parent, self.leftExp, self.rightExp, self.signQ = parent, leftExp, rightExp, signQ
def __str__(self):
return "Node"
memo = {}
def Memoize(node, p, maxValue, minValue):
if n... | 1519058100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["1 1\n0 0\n1 0\n0 1", "0 1\n0 10\n0 0\n0 9"] | 78d54d76cb113cf74ea89fb77471859b | null | You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.A polyline defined by points p1, p2, p3, p4 consists of the line segments ... | Print 4 lines with two integers per line separated by space — coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline. Judge program compares your answer and jury's answer with 10 - 6 precision. | The only line of the input contains two integers n and m (0 ≤ n, m ≤ 1000). It is guaranteed that grid contains at least 4 different points. | standard output | standard input | Python 2 | Python | 1,800 | train_009.jsonl | cd1e3e6628a76671baf4b45d7c64d285 | 256 megabytes | ["1 1", "0 10"] | PASSED | import sys
import itertools
from math import *
n, m = map(int, raw_input().split(" "))
a, b = None, None
for i in xrange(0, n + 1):
for j in xrange(0, m + 1):
if not ((i, j) in [(0, 0), (n, m)]):
if a == None and b == None:
a = i
b = j
else:
... | 1406480400 | [
"geometry",
"trees"
] | [
0,
1,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["2\n1\n61\n6"] | 8db0c45990fd49245f537f7bea048307 | NoteHere is the list of non-elegant numbers up to $$$10$$$: $$$4 = 2^2, GCD = 2$$$; $$$8 = 2^3, GCD = 3$$$; $$$9 = 3^2, GCD = 2$$$. The rest have $$$GCD = 1$$$. | Consider some positive integer $$$x$$$. Its prime factorization will be of form $$$x = 2^{k_1} \cdot 3^{k_2} \cdot 5^{k_3} \cdot \dots$$$Let's call $$$x$$$ elegant if the greatest common divisor of the sequence $$$k_1, k_2, \dots$$$ is equal to $$$1$$$. For example, numbers $$$5 = 5^1$$$, $$$12 = 2^2 \cdot 3$$$, $$$72 ... | Print $$$T$$$ lines — the $$$i$$$-th line should contain the number of elegant numbers from $$$2$$$ to $$$n_i$$$. | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^5$$$) — the number of values of $$$n$$$ in the testcase. Each of the next $$$T$$$ lines contains a single integer $$$n_i$$$ ($$$2 \le n_i \le 10^{18}$$$). | standard output | standard input | PyPy 2 | Python | 2,400 | train_054.jsonl | e261d538d7d69514662d7c672ad3408d | 256 megabytes | ["4\n4\n2\n72\n10"] | PASSED | import sys, math
from sys import stdin, stdout
rem = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 6+5)
#from resource import *; setrlimit(RLIMIT_STACK, (RLIM_INFINITY, RLIM_INFINITY))
take = lambda: map(int, stdin.readline().strip().split())
from bisect import bisect_left,bisect_right
from collections import deque
from heap... | 1536330900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
3 seconds | ["2\n4\n-1\n2\n5"] | a18692e5fe2f98717608449b1d9b77f7 | NoteIn the first test case, imposters can be Andreas $$$2$$$ and $$$3$$$.In the second test case, imposters can be Andreas $$$1$$$, $$$2$$$, $$$3$$$ and $$$5$$$.In the third test case, comments contradict each other. This is because player $$$1$$$ says that player $$$2$$$ is an imposter, and player $$$2$$$ says that pl... | Theofanis started playing the new online game called "Among them". However, he always plays with Cypriot players, and they all have the same name: "Andreas" (the most common name in Cyprus).In each game, Theofanis plays with $$$n$$$ other players. Since they all have the same name, they are numbered from $$$1$$$ to $$$... | For each test case, print one integer — the maximum possible number of imposters. If the comments contradict each other, print $$$-1$$$. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Description of each test case follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$0 \le m \le 5 \cdot 10^5$$$) — the number of players except Theofani... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_097.jsonl | 8d4a1e1247a28467583c4fa499de6e4c | 256 megabytes | ["5\n3 2\n1 2 imposter\n2 3 crewmate\n5 4\n1 3 crewmate\n2 5 crewmate\n2 4 imposter\n3 4 imposter\n2 2\n1 2 imposter\n2 1 crewmate\n3 5\n1 2 imposter\n1 2 imposter\n3 2 crewmate\n3 2 crewmate\n1 3 imposter\n5 0"] | PASSED | from collections import defaultdict
from collections import deque
from functools import lru_cache
import heapq
from locale import resetlocale
import sys
import random
import math
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(s)
def inv... | 1633705500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["2", "-1"] | 48494a73273cd8d999e94ba1a9581fdf | null | This is the easier version of the problem. In this version, $$$1 \le n \le 10^5$$$ and $$$0 \le a_i \le 1$$$. You can hack this problem only if you solve and lock both problems.Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for his long-time best friend Alice. This year, he decides to... | If there is no way for Charlie to make Alice happy, print $$$-1$$$. Otherwise, print a single integer $$$x$$$ — the minimum number of seconds for Charlie to help Bob make Alice happy. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of chocolate boxes. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 1$$$) — the number of chocolate pieces in the $$$i$$$-th box. It is guaranteed that at least one of $$$a_1, a_2, \ldots, a_n$... | standard output | standard input | Python 3 | Python | 1,800 | train_003.jsonl | 43ea29d48d104f990b6e12a84b2e6274 | 256 megabytes | ["3\n1 0 1", "1\n1"] | PASSED | def count_wyn(st_p, end_p, curr_x):
tmp_wyn_to_ret = 0
tmp_wyn_to_ret_1 = 0
num_1 = 0
mid_10 = 0
mid_11 = 0
mid_12 = 0
mid = False
for x in range(st_p, end_p + 1):
if t[x] != 0:
if mid == False:
num_1 += 1
if num_1 == curr_x//2:
... | 1574174100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["abacaba", "aaa", "ababab"] | d66e55ac7fa8a7b57ccd57d9242fd2a2 | null | Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one. Ivan knows some information about the string s. Namely, he remembers, that string ti occurs in string s at least ki times or more, ... | Print lexicographically minimal string that fits all the information Ivan remembers. | The first line contains single integer n (1 ≤ n ≤ 105) — the number of strings Ivan remembers. The next n lines contain information about the strings. The i-th of these lines contains non-empty string ti, then positive integer ki, which equal to the number of times the string ti occurs in string s, and then ki distinct... | standard output | standard input | Python 2 | Python | 1,700 | train_065.jsonl | 75266791808763d7c03b40f6916d7986 | 256 megabytes | ["3\na 4 1 3 5 7\nab 2 1 5\nca 1 4", "1\na 1 3", "3\nab 1 1\naba 1 3\nab 2 3 5"] | PASSED | def magic():
string=['1']*10000005
n=input()
m_index=0
till=0
for _ in xrange(n):
arr=raw_input().split()
s=arr[0]
times=int(arr[1])
arr=map(int,arr[2:])
l=len(s)
m_index=max(m_index,arr[-1]+l)
start=end=0
for index in arr:
... | 1499791500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["1\n-1\n2\n3\n-1\n5\n4\n7\n-1\n-1\n18\n-1"] | b5dcee7034ee2742b666aea4cbfc616f | null | Let us denote by $$$d(n)$$$ the sum of all divisors of the number $$$n$$$, i.e. $$$d(n) = \sum\limits_{k | n} k$$$.For example, $$$d(1) = 1$$$, $$$d(4) = 1+2+4=7$$$, $$$d(6) = 1+2+3+6=12$$$.For a given number $$$c$$$, find the minimum $$$n$$$ such that $$$d(n) = c$$$. | For each test case, output: "-1" if there is no such $$$n$$$ that $$$d(n) = c$$$; $$$n$$$, otherwise. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. Each test case is characterized by one integer $$$c$$$ ($$$1 \le c \le 10^7$$$). | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_107.jsonl | ac4c7b26c3642643230d4a2563e7c3cd | 512 megabytes | ["12\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n39\n691"] | PASSED | import sys
input = sys.stdin.readline
n=10**7
l=[0]+[1]*n
for i in range(2,n+1):
j=i
while(j<=n):
l[j]+=i
j+=i
l1=[-1]*(n+1)
for i in range(n,0,-1):
if(l[i]<=n):
l1[l[i]]=i
for w in range(int(input())):
print(l1[int(input())]) | 1618065300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["10\n4\n179"] | 2ced6a414a9752e7c50d37e1e1c8ffd7 | NoteFor the first pair, where $$$p_1 = 10$$$ and $$$q_1 = 4$$$, the answer is $$$x_1 = 10$$$, since it is the greatest divisor of $$$10$$$ and $$$10$$$ is not divisible by $$$4$$$.For the second pair, where $$$p_2 = 12$$$ and $$$q_2 = 6$$$, note that $$$12$$$ is not a valid $$$x_2$$$, since $$$12$$$ is divisible by $... | Oleg's favorite subjects are History and Math, and his favorite branch of mathematics is division.To improve his division skills, Oleg came up with $$$t$$$ pairs of integers $$$p_i$$$ and $$$q_i$$$ and for each pair decided to find the greatest integer $$$x_i$$$, such that: $$$p_i$$$ is divisible by $$$x_i$$$; $$$x_... | Print $$$t$$$ integers: the $$$i$$$-th integer is the largest $$$x_i$$$ such that $$$p_i$$$ is divisible by $$$x_i$$$, but $$$x_i$$$ is not divisible by $$$q_i$$$. One can show that there is always at least one value of $$$x_i$$$ satisfying the divisibility conditions for the given constraints. | The first line contains an integer $$$t$$$ ($$$1 \le t \le 50$$$) — the number of pairs. Each of the following $$$t$$$ lines contains two integers $$$p_i$$$ and $$$q_i$$$ ($$$1 \le p_i \le 10^{18}$$$; $$$2 \le q_i \le 10^{9}$$$) — the $$$i$$$-th pair of integers. | standard output | standard input | PyPy 3 | Python | 1,500 | train_005.jsonl | 2b39cd37232df20a6f63561fe73d0737 | 512 megabytes | ["3\n10 4\n12 6\n179 822"] | PASSED | import math
def smallestDivisor(n):
if (n % 2 == 0):
return 2;
i = 3;
while(i * i <= n):
if (n % i == 0):
return i;
i += 2;
return n;
def prevPowerofK(n, k):
p = int(math.log(n) / math.log(k))
return int(math.pow(k, p))
def primeFactors(... | 1604228700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["1 2 2 2 \n1 1 \n2 2 3 3 3 3 3"] | 6d76fb5753eec2b5ebe38c10ed1564f9 | Note In the first testcase: For $$$x = 1$$$, we can an edge between vertices $$$1$$$ and $$$3$$$, then $$$d(1) = 0$$$ and $$$d(2) = d(3) = d(4) = 1$$$, so $$$f(1) = 1$$$. For $$$x \ge 2$$$, no matter which edge we add, $$$d(1) = 0$$$, $$$d(2) = d(4) = 1$$$ and $$$d(3) = 2$$$, so $$$f(x) = 2$$$. | This version of the problem differs from the previous one only in the constraint on $$$n$$$.A tree is a connected undirected graph without cycles. A weighted tree has a weight assigned to each edge. The distance between two vertices is the minimum sum of weights on the path connecting them.You are given a weighted tree... | For each test case, print $$$n$$$ integers in a single line, $$$x$$$-th of which is equal to $$$f(x)$$$ for all $$$x$$$ from $$$1$$$ to $$$n$$$. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$). Each of the next $$$n−1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u,v \le n$$$) indicating that th... | standard output | standard input | PyPy 3 | Python | 2,700 | train_084.jsonl | f636b826f0d0c047c78ecb1d7a1a1490 | 512 megabytes | ["3\n\n4\n\n1 2\n\n2 3\n\n1 4\n\n2\n\n1 2\n\n7\n\n1 2\n\n1 3\n\n3 4\n\n3 5\n\n3 6\n\n5 7"] | PASSED | # import sys
# I = lambda: [*map(int, sys.stdin.readline().split())]
import io,os
read = io.BytesIO(os.read(0, os.fstat(0).st_size))
I = lambda:map(int, read.readline().split())
def maxsparse(a):
l = []
l.append(a)
c = 1
while c < len(a):
new = []
for i in range(len(a)):
if i + c < len(l[-1]... | 1643553300 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["YES\n3 4 5\n6 7 8", "NO"] | 3815d18843dbd15a73383d69eb6880dd | null | Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes ... | If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cim (0 ≤ cij ≤ 2·109) — the description of the matrix. If there are several suitable matrices, it is allowed to print any of them. | The first line contains two numbers n and m (2 ≤ n, m ≤ 100) — the dimensions of the matrix. The second line contains n numbers a1, a2, ..., an (0 ≤ ai ≤ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bm (0 ≤ bi ≤ 109), where bi is the xor of all elements in column i. | standard output | standard input | Python 3 | Python | 1,800 | train_001.jsonl | 2ce52f2ba8f831461aa573ed5b19b5fe | 256 megabytes | ["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"] | PASSED | from functools import reduce
n, m = list(map(int, input().split()))
ns = list(map(int, input().split()))
ms = list(map(int, input().split()))
xn = reduce(lambda acc, cur: acc ^ cur, ns, 0)
xm = reduce(lambda acc, cur: acc ^ cur, ms, 0)
if xn ^ xm != 0:
print('NO')
else:
print('YES')
print(xm ^ ns[0] ^ ms[... | 1533307500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["galileo galilei was an italian physicist, mathematician, astronomer", "galileo was born in pisa"] | 8c26daa1eed2078af3b32737da0a0f84 | null | You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters.Your task is to add spaces to the text by the following rules: if there is no punctuation mark between two words, th... | Print the text, edited according to the rules. In this problem you should follow the output format very strictly. For example, extra space at the end of the output line is considered as wrong answer. Note that a newline character at the end of the line doesn't matter. | The input data contains of a single non-empty line — the text whose length is no more than 10000 characters. | standard output | standard input | Python 3 | Python | 1,300 | train_011.jsonl | b0606edead6ae69a64253f902eec9425 | 256 megabytes | ["galileo galilei was an italian physicist ,mathematician,astronomer", "galileo was born in pisa"] | PASSED | x=input()
m=('.',',','?','!')
for i in range(len(x)-1):
if x[i] in m and x[i + 1] != ' ':
print(x[i] + ' ', end='')
elif not(x[i]==' ' and x[i+1]==' ' or x[i]==' ' and x[i+1] in m):
print(x[i],end='')
print(x[len(x)-1]) | 1325602800 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["29", "174", "235"] | 7a3108216f400a4f5bb809353ceb18d4 | NoteIn the first example, you can reverse the subarray $$$[4, 5]$$$. Then $$$a = [2, 3, 2, 3, 1]$$$ and $$$2 \cdot 1 + 3 \cdot 3 + 2 \cdot 2 + 3 \cdot 4 + 1 \cdot 2 = 29$$$.In the second example, you don't need to use the reverse operation. $$$13 \cdot 2 + 37 \cdot 4 = 174$$$.In the third example, you can reverse the s... | You are given two integer arrays $$$a$$$ and $$$b$$$ of length $$$n$$$.You can reverse at most one subarray (continuous subsegment) of the array $$$a$$$. Your task is to reverse such a subarray that the sum $$$\sum\limits_{i=1}^n a_i \cdot b_i$$$ is maximized. | Print single integer — maximum possible sum after reversing at most one subarray (continuous subsegment) of $$$a$$$. | The first line contains one integer $$$n$$$ ($$$1 \le n \le 5000$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^7$$$). The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 10^7$$$). | standard output | standard input | PyPy 3 | Python | 1,600 | train_102.jsonl | 51c27eb0e1d42474c3fb96c6bd874f2e | 256 megabytes | ["5\n2 3 2 1 3\n1 3 2 4 2", "2\n13 37\n2 4", "6\n1 8 7 6 3 6\n5 9 6 8 8 6"] | PASSED | from itertools import combinations, accumulate, groupby, count
from sys import stdout, stdin, setrecursionlimit
from collections import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
def fast(): return stdin.readline()
def z... | 1619706900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3.5 seconds | ["? 1 2\n! 1 2", "? 2 1\n? 1 3\n? 4 1\n? 2 3\n? 4 2\n? 4 3\n! 0 0"] | 90a9d883408d5c283d6e7680c0b94c8b | NoteIn the first sample input, we are given a city of three houses with one incoming road each. The user program asks one query: "? 1 2": asking whether we can reach from house $$$1$$$ to house $$$2$$$. The judge responds with "Yes". The user program now concludes that this is sufficient information to determine the co... | This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You m... | null | The first line contains a single integer $$$n$$$ ($$$3 \le n \le 500$$$) denoting the number of houses in the city. The next line contains $$$n$$$ space-separated integers $$$k_1, k_2, \dots, k_n$$$ ($$$0 \le k_i \le n - 1$$$), the $$$i$$$-th of them represents the number of incoming roads to the $$$i$$$-th house. | standard output | standard input | PyPy 3-64 | Python | 2,200 | train_107.jsonl | 5a6268e3fd0eb83fb22370944d3d1e40 | 256 megabytes | ["3\n1 1 1\nYes", "4\n1 2 0 3\nNo\nNo\nNo\nNo\nNo\nNo"] | PASSED | import os,sys
from random import randint
from io import BytesIO, IOBase
from collections import defaultdict,deque,Counter
from bisect import bisect_left,bisect_right
from heapq import heappush,heappop
from functools import lru_cache
from itertools import accumulate
import math
# Fast IO Region
BUFSIZE = 8... | 1617028500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.