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 | ["1 4 2 3 \n4 1 2 3"] | 3f9525d74f4934eb9dca1b16c53662bf | NoteIn the first test case, the city looks like the following graph:So all possible answers are $$$(1 \to 4 \to 2 \to 3)$$$, $$$(1 \to 2 \to 3 \to 4)$$$.In the second test case, the city looks like the following graph:So all possible answers are $$$(4 \to 1 \to 2 \to 3)$$$, $$$(1 \to 2 \to 3 \to 4)$$$, $$$(3 \to 4 \to ... | The city where Mocha lives in is called Zhijiang. There are $$$n+1$$$ villages and $$$2n-1$$$ directed roads in this city. There are two kinds of roads: $$$n-1$$$ roads are from village $$$i$$$ to village $$$i+1$$$, for all $$$1\leq i \leq n-1$$$. $$$n$$$ roads can be described by a sequence $$$a_1,\ldots,a_n$$$. If ... | For each test case, print a line with $$$n+1$$$ integers, where the $$$i$$$-th number is the $$$i$$$-th village they will go through. If the answer doesn't exist, print $$$-1$$$. If there are multiple correct answers, you can print any one of them. | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — indicates that the number of villages is $$$n+1... | standard output | standard input | PyPy 3-64 | Python | 1,200 | train_095.jsonl | 3827f1e8419314038e312cef4732a28d | 256 megabytes | ["2\n3\n0 1 0\n3\n1 1 0"] | PASSED | import sys
from os import path
def input():
return sys.stdin.readline().strip()
def solve(n,array):
# YOUR CODE HERE
answer = list(range(1,n+1))
if array[n-1] == 0:
answer.append(n+1)
elif array[0] == 1:
answer.insert(0,n+1)
else:
for index in range(n-1):
... | 1629038100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["10.25", "10.3", "9.2"] | d563ce32596b54f48544a6085efe5cc5 | NoteIn the first two samples Efim initially has grade 10.245. During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.In the third sample the optimal strategy is to not perform any rounding at all. | Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th... | Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes. | The first line of the input contains two integers n and t (1 ≤ n ≤ 200 000, 1 ≤ t ≤ 109) — the length of Efim's grade and the number of seconds till the end of the break respectively. The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the ... | standard output | standard input | PyPy 2 | Python | 1,700 | train_000.jsonl | 51f6a79a1f83497629a82f14c3985c65 | 256 megabytes | ["6 1\n10.245", "6 2\n10.245", "3 100\n9.2"] | PASSED | n,t=map(int,raw_input().split())
x,y=map(str,raw_input().split('.'))
#x,y=raw_input().split('.')
#if n==145730 and t==93881:
# print x[:-1]+'3'
# exit()
ans=chk=0
p=[i for i in y]
P=range(len(p))
q=[i for i in x]
z=0
def sol(ans):
t=-len(ans)-1
ans[-1]=chr(ord(ans[-1])+1)
for i in range(-1,t,-1):
... | 1474635900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["aabacadbb", "aaaaa", "codeforces"] | 19cc504c81bd4f224ecb17f03cfb9bd7 | null | Let's define the cost of a string $$$s$$$ as the number of index pairs $$$i$$$ and $$$j$$$ ($$$1 \le i < j < |s|$$$) such that $$$s_i = s_j$$$ and $$$s_{i+1} = s_{j+1}$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Among all strings with length $$$n$$$ that contain only the first $$$k$$$ characters o... | Print the string $$$s$$$ such that it consists of $$$n$$$ characters, each its character is one of the $$$k$$$ first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them. | The only line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5; 1 \le k \le 26$$$). | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_089.jsonl | 91f8a3dc76c966945d6fbd81ef7bbadf | 256 megabytes | ["9 4", "5 1", "10 26"] | PASSED | import bisect
import collections
import heapq
import io
import math
import os
import sys
LO = 'abcdefghijklmnopqrstuvwxyz'
Mod = 1000000007
def gcd(x, y):
while y:
x, y = y, x % y
return x
# _input = lambda: io.BytesIO(os.read(0, os.fstat(0).st_size)).readline().decode()
_input = lam... | 1618238100 | [
"strings",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
1,
0
] | |
2 seconds | ["3.84257761518762740", "13.45126176453737600"] | 9578bde96aa39416a3406ffb7ca036e1 | null | The commanding officers decided to drop a nuclear bomb on the enemy's forces. You are ordered to determine the power of the warhead that needs to be used.The enemy has N strategically important objects. Their positions are known due to the intelligence service. The aim of the strike is to deactivate at least K importan... | Print the sought estimated impact radius of the warhead. The absolute or relative measure of the inaccuracy of your answer should not exceed 10 - 6. | The first line contains an integer N which represents the number of the enemy's objects (1 ≤ N ≤ 100). The second line contains two integers: K is the required number of deactivated objects, and ε is the maximally permitted probability of not completing the task, given in per mils (1 ≤ K ≤ N, 1 ≤ ε ≤ 999). The third li... | standard output | standard input | Python 3 | Python | 2,100 | train_004.jsonl | e4345f24a517b43bb9ffa053da1f3dac | 256 megabytes | ["1\n1 500\n5 5\n1 2", "5\n3 100\n0 0\n3 4\n60 70\n100 100\n10 10\n5 12"] | PASSED | import math
n = int(input())
k, epsilon = list(map(int, input().split(" ")))
x0, y0 = list(map(int, input().split(" ")))
epsilon /= 1000.0
l = []
for i in range(n):
l.append(list(map(int, input().split(" "))))
d = sorted([(p[0] - x0) ** 2 + (p[1] - y0) ** 2 for p in l])
rmin = 0
rmax = math.sqrt(d[k - 1])
... | 1292862000 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
1 second | ["2\n2\n1\n1"] | 08cd22b8ee760a9d2dacb0d050dcf37a | NoteIn the first test case of the example:After the first operation the string $$$s$$$ can become either aabbaa or baaaab. After the second operation there are 2 possibilities for $$$s$$$: aabbaaaabbaa and baaaabbaaaab. | Real stupidity beats artificial intelligence every time.— Terry Pratchett, Hogfather, DiscworldYou are given a string $$$s$$$ of length $$$n$$$ and a number $$$k$$$. Let's denote by $$$rev(s)$$$ the reversed string $$$s$$$ (i.e. $$$rev(s) = s_n s_{n-1} ... s_1$$$). You can apply one of the two kinds of operations to th... | For each test case, print the answer (that is, the number of different strings that you can get after exactly $$$k$$$ operations) on a separate line. It can be shown that the answer does not exceed $$$10^9$$$ under the given constraints. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — number of test cases. Next $$$2 \cdot t$$$ lines contain $$$t$$$ test cases: The first line of a test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100$$$, $$$0 \le k \le 1000$$$) — the length of the string and the number of operatio... | standard output | standard input | PyPy 3-64 | Python | 800 | train_107.jsonl | dc62050394c9275f8330a492bd0035bc | 256 megabytes | ["4\n\n3 2\n\naab\n\n3 3\n\naab\n\n7 1\n\nabacaba\n\n2 0\n\nab"] | PASSED | #!/shafi/bin/env python
import os
import sys
from io import BytesIO, IOBase
def main():
tc = int(input())
for _ in range(tc): #Testcases
n,m = map(int,input().split())
s = input()
i=0
j=len(s)-1
pal=True
while i<j:
if s[i]!=s[j]:
... | 1644158100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["Alice 2\nAlice 4\nAlice 4\nBob 14\nAlice 93"] | 8f02891aa9d2fcd1963df3a4028aa5c0 | NoteFor the first round, $$$\texttt{"aba"}\xrightarrow{\texttt{Alice}}\texttt{"}{\color{red}{\texttt{ab}}}\texttt{a"}\xrightarrow{} \texttt{"a"}\xrightarrow{\texttt{Bob}}\texttt{"}{\color{red}{\texttt{a}}}\texttt{"}\xrightarrow{}\texttt{""}$$$. Alice's total score is $$$1+2=3$$$. Bob's total score is $$$1$$$.For the se... | Alice and Bob are playing a game with strings. There will be $$$t$$$ rounds in the game. In each round, there will be a string $$$s$$$ consisting of lowercase English letters. Alice moves first and both the players take alternate turns. Alice is allowed to remove any substring of even length (possibly empty) and Bob is... | For each round, print a single line containing a string and an integer. If Alice wins the round, the string must be "Alice". If Bob wins the round, the string must be "Bob". The integer must be the difference between their scores assuming both players play optimally. | The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 5\cdot 10^4$$$) denoting the number of rounds. Each of the next $$$t$$$ lines contain a single string $$$s$$$ ($$$1\leq |s|\leq 2\cdot 10^5$$$) consisting of lowercase English letters, denoting the string used for the round. Here $$$|s|$$$ denote... | standard output | standard input | Python 3 | Python | 800 | train_096.jsonl | 0737c3bad5d62be18a735040863a7536 | 256 megabytes | ["5\n\naba\n\nabc\n\ncba\n\nn\n\ncodeforces"] | PASSED | for test_c in range(int(input())):
word = input()
word_2_num=[ord(i)-96 for i in word]
if len(word_2_num)==1:
print("Bob",word_2_num[0])
elif len(word_2_num)%2==0:
print("Alice",sum(word_2_num))
else:
print("Alice",sum(word_2_num)-2*min(word_2_num[0],word_2_num[-1])) | 1651329300 | [
"games",
"strings"
] | [
1,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["2", "0"] | fce9d78ad7d4ea01be1704f588e42d37 | NoteBelow is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust. | Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.The pizza is a circle of radius r and center at the origin. Pizza consists of the main part — circle of radius r - d with center at the origin, and ... | Output the number of pieces of sausage that lay on the crust. | First string contains two integer numbers r and d (0 ≤ d < r ≤ 500) — the radius of pizza and the width of crust. Next line contains one integer number n — the number of pieces of sausage (1 ≤ n ≤ 105). Each of next n lines contains three integer numbers xi, yi and ri ( - 500 ≤ xi, yi ≤ 500, 0 ≤ ri ≤ 500), where xi ... | standard output | standard input | Python 3 | Python | 1,100 | train_019.jsonl | d44d99e092f7d67b56ae234076ed7618 | 256 megabytes | ["8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1", "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2"] | PASSED | #RAVENS
#TEAM_2
#ESSI-DAYI_MOHSEN-LORENZO
from math import sqrt
r,d=map(int,input().split())
c=0
for i in range(int(input())):
x,y,rr=map(int,input().split())
b=sqrt(x**2+y**2)
if(b<=abs(r-rr) and b>=(r-d+rr)):
c+=1
print(c) | 1504019100 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
4 seconds | ["2 2\n4 6\n12 12\n-1 -1\n-1 -1"] | 84c60293d487e2c2ecee38a2fcf63b10 | null | This is an easy version of the problem. The only difference between an easy and a hard version is the constraints on $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$.You are given $$$4$$$ positive integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ with $$$a < c$$$ and $$$b < d$$$. Find any pair of numbers $$$x$$$ and $$$y$$$ that ... | For each test case print a pair of numbers $$$a < x \leq c$$$ and $$$b < y \leq d$$$ such that $$$x \cdot y$$$ is divisible by $$$a \cdot b$$$. If there are multiple answers, print any of them. If there is no such pair of numbers, then print -1 -1. | The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10$$$), the number of test cases. The descriptions of the test cases follow. The only line of each test case contains four integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$1 \leq a < c \leq 10^5$$$, $$$1 \leq b < d \leq 10^5$$$). | standard output | standard input | Python 3 | Python | 1,500 | train_094.jsonl | 49b2aa5b9d3351cc1d3b60a10f9996eb | 256 megabytes | ["5\n\n1 1 2 2\n\n3 4 5 7\n\n8 9 15 18\n\n12 21 14 24\n\n36 60 48 66"] | PASSED | # a<c and b<d
# a<x≤c and b<y≤d
# xy is divisible by ab.
import math
def find_div(a,b,c,d):
start = time()
if a==b==1 or (c*d)/(a*b) == (c*d)//(a*b):
return c, d
if a*2<=c and b*2<=d:
return 2*a, 2*b
if c*d < 2*a*b:
return -1,-1
else: # executes if cd > 2ab
... | 1665930900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
3 seconds | ["32", "1337"] | a279d4dc120663f9671c66ddd96224fa | NoteIn the first example, the following sequence of offers taken is optimal: 4 $$$\rightarrow$$$ 3.The amount of burles Vasya has changes the following way: 5 $$$\rightarrow$$$ 32 $$$\rightarrow$$$ -86 $$$\rightarrow$$$ .... He takes the money he has in the middle of the second month (32 burles) and buys the car.The ne... | Vasya wants to buy himself a nice new car. Unfortunately, he lacks some money. Currently he has exactly 0 burles.However, the local bank has $$$n$$$ credit offers. Each offer can be described with three numbers $$$a_i$$$, $$$b_i$$$ and $$$k_i$$$. Offers are numbered from $$$1$$$ to $$$n$$$. If Vasya takes the $$$i$$$-t... | Print one integer — the maximum price of the car. | The first line contains one integer $$$n$$$ ($$$1 \le n \le 500$$$) — the number of credit offers. Each of the next $$$n$$$ lines contains three integers $$$a_i$$$, $$$b_i$$$ and $$$k_i$$$ ($$$1 \le a_i, b_i, k_i \le 10^9$$$). | standard output | standard input | Python 3 | Python | 2,600 | train_065.jsonl | a19b7b7f0035d720e4bc1d19d4ed60e7 | 256 megabytes | ["4\n10 9 2\n20 33 1\n30 115 1\n5 3 2", "3\n40 1 2\n1000 1100 5\n300 2 1"] | PASSED | n = int(input())
a = [tuple(map(int, input().split())) for i in range(n)]
a = [(y, x, k) for x, y, k in a]
a.sort(reverse=True)
dp = [[-1] * (n + 1) for i in range(n)]
def f(i, j):
if i < 0 or j < -1: return 0
if dp[i][j] == -1:
y, x, k = a[i]
dp[i][j] = f(i - 1, j) + max(0, x - k * y)
... | 1548516900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1 6 4 2 5 3 \n4 2 3 1 \n1 4 2 6 5 3 \n3 4 2 1 \n1 3 2 \n1"] | b6d8bb53da52c47a5c57b55e266ae952 | null | We are committed to the well being of all participants. Therefore, instead of the problem, we suggest you enjoy a piece of cake.Uh oh. Somebody cut the cake. We told them to wait for you, but they did it anyway. There is still some left, though, if you hurry back. Of course, before you taste the cake, you thought about... | Print $$$2t$$$ lines — answers to given $$$t$$$ test cases in the order in which they are written in the input. Each answer should consist of $$$2$$$ lines. In the first line of an answer on a test case print $$$n$$$ distinct numbers $$$p_1, p_2, \dots, p_n$$$($$$1 \le p_i \le n$$$) — the numbers of the cake vertices i... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then there are $$$t$$$ independent sets of input data. The first line of each set consists of a single integer $$$n$$$ ($$$3 \le n \le 10^5$$$) — the number of vertices in the cake. The following $$$n - 2$$$ lines desc... | standard output | standard input | Python 3 | Python | 2,400 | train_050.jsonl | 19429691f3ceae17cec6e1ed8623e6c2 | 256 megabytes | ["3\n6\n3 6 5\n5 2 4\n5 4 6\n6 3 1\n6\n2 5 6\n2 5 1\n4 1 2\n1 3 5\n3\n1 2 3"] | PASSED | class Union:
def __init__(self, n):
self.p = [i for i in range(n+1)]
self.rank = [0] * (n+1)
def find(self, x):
if self.p[x] != x:
self.p[x] = self.find(self.p[x])
return self.p[x]
def union(self, x, y):
x = self.find(x)
y = self.... | 1577198100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
3 seconds | ["1\n6\n12"] | f4cf2759d6f6941044f913cb89f39dbe | NoteIn the first sample operation doesn't change the string, so it will become the same as it was after $$$1$$$ operations.In the second sample the string will change as follows: $$$s$$$ = babaa $$$s$$$ = abaab $$$s$$$ = baaba $$$s$$$ = abbaa $$$s$$$ = baaab $$$s$$$ = ababa | Polycarp found the string $$$s$$$ and the permutation $$$p$$$. Their lengths turned out to be the same and equal to $$$n$$$.A permutation of $$$n$$$ elements — is an array of length $$$n$$$, in which every integer from $$$1$$$ to $$$n$$$ occurs exactly once. For example, $$$[1, 2, 3]$$$ and $$$[4, 3, 5, 1, 2]$$$ are pe... | Output $$$t$$$ lines, each of which contains the answer to the corresponding test case of input. As an answer output single integer — the minimum number of operations, after which the string $$$s$$$ will become the same as it was before operations. | The first line of input contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases in input. The first line of each case contains single integer $$$n$$$ ($$$1 \le n \le 200$$$) — the length of string and permutation. The second line of each case contains a string $$$s$$$ of length $$$n$$$, contain... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_094.jsonl | 783d4400ddbe525f2eed42f4a5a0df45 | 256 megabytes | ["3\n\n5\n\nababa\n\n3 4 5 2 1\n\n5\n\nababa\n\n2 1 4 5 3\n\n10\n\ncodeforces\n\n8 6 1 7 5 2 9 3 10 4"] | PASSED | from collections import *
from heapq import *
from bisect import *
from itertools import *
from string import *
from math import *
def solve():
n = int(input())
s = input()
P = list(map(int, input().split()))
P = [x - 1 for x in P]
seen = set()
components = []
def dfs(u, component):
... | 1654612500 | [
"number theory",
"math",
"strings",
"graphs"
] | [
0,
0,
1,
1,
1,
0,
1,
0
] | |
1 second | ["1\n3", "4\n1 2 3 4"] | 961557bad90f98df7b40d6ceca942121 | NoteConsider the first sample test. The given answer is the only way to conduct an experiment involving the only data center. In such a scenario the third data center has a maintenance during the hour 1, and no two data centers storing the information of the same client have maintenance at the same hour.On the other ha... | BigData Inc. is a corporation that has n data centers indexed from 1 to n that are located all over the world. These data centers provide storage for client data (you can figure out that client data is really big!).Main feature of services offered by BigData Inc. is the access availability guarantee even under the circ... | In the first line print the minimum possible number of data centers k (1 ≤ k ≤ n) that have to be included in an experiment in order to keep the data available for any client. In the second line print k distinct integers x1, x2, ..., xk (1 ≤ xi ≤ n), the indices of data centers whose maintenance time will be shifted by... | The first line of input contains three integers n, m and h (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000, 2 ≤ h ≤ 100 000), the number of company data centers, number of clients and the day length of day measured in hours. The second line of input contains n integers u1, u2, ..., un (0 ≤ uj < h), j-th of these numbers is an in... | standard output | standard input | PyPy 3 | Python | 1,900 | train_053.jsonl | 9d816d564e4a446d096853a00424a9ce | 512 megabytes | ["3 3 5\n4 4 0\n1 3\n3 2\n3 1", "4 5 4\n2 1 0 3\n4 3\n3 2\n1 2\n1 4\n1 3"] | PASSED | import sys
# sys.stind.readline lee datos el doble de
# rápido que la funcion por defecto input
input = sys.stdin.readline
def get_input():
n, m, h = [int(x) for x in input().split(' ')]
digraph = [[] for _ in range(n + 1)]
transpose = [[] for _ in range(n + 1)]
mantainence = [0] + [int(x) for x in... | 1520583000 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["-\n-\n? 1 1\n1\n2\n-\n! 2\n-\n? 1 1\n1\n2\n-\n? 2 3\n4 2\n1 3 5\n-\n? 1 1\n4\n5\n-\n! 1"] | d800ab6fa7c7bad7c1c637acc43f4cfc | NoteAdditional separators "–" in the sample are used only to increase the readability of the sample. Don't print any unnecessary symbols or line breaks in your solution when you send it to the system.Hacks are forbidden in this task. | This is an interactive problem. Don't forget to flush output after printing queries using cout.flush() or fflush(stdout) in C++ or similar functions in other programming languages.There are $$$n$$$ gift boxes in a row, numbered from $$$1$$$ to $$$n$$$ from left to right. It's known that exactly $$$k$$$ of them contain ... | For each test case print the minimum index among all boxes with a valuable gift in the following format: "! $$$x$$$" where $$$x$$$ ($$$1 \le x \le n$$$) — the index of the box. | The input consists of several cases. In the beginning, you receive the integer $$$T$$$ ($$$1 \le T \le 500$$$) — the number of test cases. At the beginning of each test case, you receive two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 1000$$$, $$$1 \le k \le \frac{n}{2}$$$) — the number of boxes in a row and the numbe... | standard output | standard input | Python 3 | Python | 2,600 | train_056.jsonl | e4c6ad70671c935bb098577d77f5aaa4 | 256 megabytes | ["2\n2 1\n-\n-\n-\nFIRST\n-\n5 2\n-\n-\n-\nFIRST\n-\n-\n-\nSECOND\n-\n-\n-\nEQUAL\n-"] | PASSED | from random import randrange
def ask(a0,b0,L):
print("?",L,L,flush=True)
aa=[i for i in range(a0,a0+L)]
print(*aa,flush=True)
aa=[i for i in range(b0,b0+L)]
print(*aa,flush=True)
return input()
def main():
for _ in range(int(input())):
n,k=map(int,input().split())
isfirst=F... | 1589707200 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
1 second | ["1\n2\n1\n7\n4\n333333333\n333333328"] | d04cbe78b836e53b51292401c8c969b2 | NoteIn the first test case of the example, one of the possible answers is $$$x=1, k=2$$$. Then $$$1 \cdot 1 + 2 \cdot 1$$$ equals $$$n=3$$$.In the second test case of the example, one of the possible answers is $$$x=2, k=2$$$. Then $$$1 \cdot 2 + 2 \cdot 2$$$ equals $$$n=6$$$.In the third test case of the example, one ... | Recently Vova found $$$n$$$ candy wrappers. He remembers that he bought $$$x$$$ candies during the first day, $$$2x$$$ candies during the second day, $$$4x$$$ candies during the third day, $$$\dots$$$, $$$2^{k-1} x$$$ candies during the $$$k$$$-th day. But there is an issue: Vova remembers neither $$$x$$$ nor $$$k$$$ b... | Print one integer — any positive integer value of $$$x$$$ so there is an integer $$$k>1$$$ that $$$x + 2x + 4x + \dots + 2^{k-1} x = n$$$. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$3 \le n \le 10^9$$$) — the number of candy wrappers Vova found. It is guaranteed that there is some positive integ... | standard output | standard input | PyPy 2 | Python | 900 | train_002.jsonl | 0cfd0707fd10a3d2aa9fee2a96bdda2b | 256 megabytes | ["7\n3\n6\n7\n21\n28\n999999999\n999999984"] | PASSED | from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(input())
def si(): return input()
def mi(): return map(in... | 1587479700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["8", "16"] | 6d7accf770d489f746648aa56c90d16d | NoteIn the first sample Vika will paint squares (0, 1), (1, 1), (2, 1), (1, 2), (1, 3), (1, 4), (0, 3) and (2, 3). | Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew n black horizontal and vertical segments parallel to the coordinate axes. All segments have width equal to 1 square, that means every segment occupy some set of neighbo... | Print the number of cells painted by Vika. If a cell was painted more than once, it should be calculated exactly once in the answer. | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of segments drawn by Vika. Each of the next n lines contains four integers x1, y1, x2 and y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — the coordinates of the endpoints of the segments drawn by Vika. It is guaranteed that all the segments are... | standard output | standard input | Python 3 | Python | 2,300 | train_008.jsonl | 96b38efc0edc3288dd4dcc53ca68b4c4 | 256 megabytes | ["3\n0 1 2 1\n1 4 1 2\n0 3 2 3", "4\n-2 -1 2 -1\n2 1 -2 1\n-1 -2 -1 2\n1 2 1 -2"] | PASSED | from sys import stdin
from itertools import repeat
from collections import defaultdict
def main():
n = int(stdin.readline())
h = defaultdict(list)
w = defaultdict(list)
for i in range(n):
a, b, c, d = map(int, input().split())
if a > c:
a, c = c, a
if b > d:
... | 1451215200 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["YES\nYES\nYES\nYES\nNO\nYES\nNO\nYES\nYES\nNO\nYES"] | 90c5058c0c7f55a567f2e036482149f9 | NoteIn the first and second test cases, you can choose the number $$$m=4$$$ and multiply the second number ($$$b=5$$$) by $$$4$$$.In the first test case the resulting sequence will be $$$[10, 20, 30]$$$. This is an AP with a difference $$$d=10$$$.In the second test case the resulting sequence will be $$$[30, 20, 10]$$$... | Polycarp has $$$3$$$ positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He can perform the following operation exactly once. Choose a positive integer $$$m$$$ and multiply exactly one of the integers $$$a$$$, $$$b$$$ or $$$c$$$ by $$$m$$$. Can Polycarp make it so that after performing the operation, the sequence of three... | For each test case print "YES" (without quotes) if Polycarp can choose a positive integer $$$m$$$ and multiply exactly one of the integers $$$a$$$, $$$b$$$ or $$$c$$$ by $$$m$$$ to make $$$[a, b, c]$$$ be an arithmetic progression. Print "NO" (without quotes) otherwise. You can print YES and NO in any (upper or lower) ... | The first line contains the number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each of the following $$$t$$$ lines contains $$$3$$$ integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$). | standard output | standard input | Python 3 | Python | 900 | train_102.jsonl | 80cfbe8057007f507dcaba0769c8508d | 256 megabytes | ["11\n10 5 30\n30 5 10\n1 2 3\n1 6 3\n2 6 3\n1 1 1\n1 1 2\n1 1 3\n1 100000000 1\n2 1 1\n1 2 2"] | PASSED | for j in[0]*int(input()):
i=input().split()
a=int(i[0])
b=int(i[1])
c=int(i[2])
if ((a+c)%(2*b)==0) or (((2*b-c)%a ==0) and ((2*b-c)>0)) or (((2*b-a)%c ==0) and ((2*b-a)>0)): print("YES")
else :print("NO") | 1641825300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3", "4"] | c421f47149e70240a02903d9d47de429 | NoteIn the first sample all 3 subsequences of the needed length are considered lucky.In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1, 3}, {1, 4}, {2, 3} and {2, 4}. | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has sequence a consisting of n integers.The subsequence of the sequence a is such subsequence ... | On the single line print the single number — the answer to the problem modulo prime number 1000000007 (109 + 7). | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105). The next line contains n integers ai (1 ≤ ai ≤ 109) — the sequence a. | standard output | standard input | Python 2 | Python | 2,100 | train_064.jsonl | 3446ba93877e9cdb83935f0bd9ba2ba5 | 256 megabytes | ["3 2\n10 10 10", "4 2\n4 4 7 7"] | PASSED | #!/usr/bin/env python
MOD = 1000000007
def gcd(a, b):
if a == 0:
return b, 0, 1
d, x, y = gcd(b % a, a)
return d, y - b / a * x, x
def div(a):
d, x, y = gcd(a, MOD)
return x
def c(n, k):
if k > n or k < 0:
return 0
res = 1
for i in xrange(max(k + 1, n - k + 1), n + 1)... | 1327215600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["-1\n3\n1 3\n2 2\n4 0"] | 070cb9523bd8319e93c33264a3faf708 | null | Vitaly gave Maxim $$$n$$$ numbers $$$1, 2, \ldots, n$$$ for his $$$16$$$-th birthday. Maxim was tired of playing board games during the celebration, so he decided to play with these numbers. In one step Maxim can choose two numbers $$$x$$$ and $$$y$$$ from the numbers he has, throw them away, and add two numbers $$$x +... | For each test case print $$$-1$$$ if it's impossible to make all numbers equal. Otherwise print a single integer $$$s$$$ ($$$0 \le s \le 20n$$$) — the number of steps. Then print $$$s$$$ lines. The $$$i$$$-th line must contain two integers $$$x_i$$$ and $$$y_i$$$ — numbers that Maxim chooses on the $$$i$$$-th step. The... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 25\,000$$$) — the number of test cases. Each test case contains a single integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — the number of integers given to Maxim. It is guaranteed that the total sum of $$$n$$$ doesn't exceed $$$5 \cdot 10^4$$$. | standard output | standard input | Python 2 | Python | 3,000 | train_090.jsonl | 6c69b8efd7305a2534fb56e3090c2c16 | 256 megabytes | ["2\n2\n3"] | PASSED | import sys
raw_input = iter(sys.stdin.read().splitlines()).next
def bfs(n):
result, a = [], []
q = [(n, 1)]
while q:
new_q = []
for n, coeff in q:
if n <= 2:
for i in xrange(1, n+1):
a.append(i*coeff)
continue
... | 1644676500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\n1\n1 3"] | bbcb051b08fa3d19a7cf285242d50451 | null | Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A f... | In the first line output «YES» or «NO»: if it is possible or not to construct an interesting graph. If the answer is «YES», in the second line output k — the amount of edges that should be added to the initial graph. Finally, output k lines: pairs of vertices xj and yj, between which edges should be drawn. The result m... | The first line of the input data contains a pair of integers n and m (1 ≤ n ≤ 50, 0 ≤ m ≤ 2500) — the amount of vertices and edges respectively. The following lines contain pairs of numbers xi and yi (1 ≤ xi, yi ≤ n) — the vertices that are already connected by edges. The initial graph may contain multiple edges and lo... | standard output | standard input | Python 2 | Python | 2,300 | train_043.jsonl | 09f449f8cf745ed652fbf2c2f3523e67 | 64 megabytes | ["3 2\n1 2\n2 3"] | PASSED | from itertools import *
read = lambda: map(int, raw_input().split())
def check_deg():
for i in xrange(n):
if deg[i] > 2:
return False
return True
def check_cycle():
def cycle(u):
mk.add(u)
for v in xrange(n):
if g[u][v]:
g[u][v] -= 1
... | 1270983600 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["0\n2\n3\n-1\n1\n-1\n3\n1\n3\n-1"] | e3a1f53f78fcb3a551c3ae1cbeedaf15 | NoteIn the first example, the thermostat is already set up correctly.In the second example, you can achieve the desired temperature as follows: $$$4 \rightarrow 10 \rightarrow 5$$$.In the third example, you can achieve the desired temperature as follows: $$$3 \rightarrow 8 \rightarrow 2 \rightarrow 7$$$.In the fourth t... | Vlad came home and found out that someone had reconfigured the old thermostat to the temperature of $$$a$$$.The thermostat can only be set to a temperature from $$$l$$$ to $$$r$$$ inclusive, the temperature cannot change by less than $$$x$$$. Formally, in one operation you can reconfigure the thermostat from temperatur... | Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. If it is impossible to achieve the temperature $$$b$$$, output -1, otherwise output the minimum number of operations. | The first line of input data contains the single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each case contains three integers $$$l$$$, $$$r$$$ and $$$x$$$ ($$$-10^9 \le l \le r \le 10^9$$$, $$$1 \le x \le 10^9$$$) — range... | standard output | standard input | Python 3 | Python | 1,100 | train_086.jsonl | fb041dd0b2527dd1b365e9aeaa194558 | 256 megabytes | ["10\n\n3 5 6\n\n3 3\n\n0 15 5\n\n4 5\n\n0 10 5\n\n3 7\n\n3 5 6\n\n3 4\n\n-10 10 11\n\n-5 6\n\n-3 3 4\n\n1 0\n\n-5 10 8\n\n9 2\n\n1 5 1\n\n2 5\n\n-1 4 3\n\n0 2\n\n-6 3 6\n\n-1 -4"] | PASSED | R=lambda:map(int,input().split())
t,=R()
while t:t-=1;l,r,x=R();a,b=sorted(R());print('0'*(a==b)or+(b-a>=x)or(x<=max(a-l,r-b))*2or(r-a>=x<=b-l)*3or-1) | 1668782100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["5", "8"] | 0b229ddf583949d43d6f1728e38c3cad | NoteNotes to sample tests:Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3]. | Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.Valera absolutely ... | Print on the single line the answer to the problem: the amount of subarrays, which are magical. Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator). | The first line of the input data contains an integer n (1 ≤ n ≤ 105). The second line contains an array of original integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). | standard output | standard input | Python 2 | Python | 1,300 | train_004.jsonl | e45e19f5f10fc3e079dd5ddcfb94c7df | 256 megabytes | ["4\n2 1 1 4", "5\n-2 -2 -2 0 1"] | PASSED | n = raw_input()
st = map(int, raw_input().split())
gl = 0
loc = 0
prev = 0
for i in st:
if prev != i:
loc = 1
else:
loc += 1
gl += loc
prev = i
print gl
| 1305299400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
5 seconds | ["0 1 2 \n1 0 2 \n1 2 0", "0 2 3 3 4 4 \n4 0 2 3 3 4 \n4 4 0 2 3 3 \n3 4 4 0 2 3 \n3 3 4 4 0 2 \n2 3 3 4 4 0", "0 1 2 3 \n3 0 3 2 \n12 13 0 11 \n1 2 2 0"] | 58b9ec7ff9718ceae1aa3d4503c8cbed | NoteIn the first example one possible path for going from $$$0$$$ to $$$2$$$ would be: Stay inside $$$0$$$ and do nothing for $$$1$$$ second. Use the first cannon and land at $$$2$$$ after $$$1$$$ second. Note that: we could have used the second cannon in $$$0$$$-th second but it would have taken us $$$3$$$ seconds... | There are $$$n$$$ cities in Shaazzzland, numbered from $$$0$$$ to $$$n-1$$$. Ghaazzzland, the immortal enemy of Shaazzzland, is ruled by AaParsa.As the head of the Ghaazzzland's intelligence agency, AaParsa is carrying out the most important spying mission in Ghaazzzland's history on Shaazzzland.AaParsa has planted $$$... | Print $$$n$$$ lines, each line should contain $$$n$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line should be equal to the minimum time required to reach city $$$j$$$ from city $$$i$$$. | The first line contains two integers $$$n$$$ and $$$m$$$ $$$(2 \le n \le 600 , n \le m \le n^2)$$$ — the number of cities and cannons correspondingly. The $$$i$$$-th line of the following $$$m$$$ lines contains three integers $$$a_i$$$, $$$b_i$$$ and $$$c_i$$$ $$$( 0 \le a_i , b_i \le n-1 , 1 \le c_i \le 10^9)$$$, deno... | standard output | standard input | PyPy 3 | Python | 2,500 | train_085.jsonl | 31da8907e3fd6d9dfecb6342a7f81f2d | 256 megabytes | ["3 4\n0 1 1\n0 2 3\n1 0 1\n2 0 1", "6 6\n0 0 1\n1 1 1\n2 2 1\n3 3 1\n4 4 1\n5 5 1", "4 5\n0 1 1\n1 3 2\n2 2 10\n3 0 1\n0 0 2"] | PASSED | import sys
input = lambda: sys.stdin.readline().rstrip()
def dijkstra(n, E, i0=0):
D = [1 << 30] * n; D[i0] = 0; Q = set([i for i in range(n)])
while Q:
d = 1 << 30
for q in Q:
if D[q] < d: i = q; d = D[q]
Q.remove(i)
for j, w in enumerate(E[i]):
... | 1621866900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["3", "7"] | b963c125f333eef3ffc885b59e6162c2 | NoteIn the first sample we can obtain the array:3 6 9 12 12 15In the second sample we can obtain the next array:7 21 49 14 77 | Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n.Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately, the ... | In the single line print a single number — the maximum possible beauty of the resulting array. | The first line contains two integers n and k (1 ≤ n ≤ 3·105; 1 ≤ k ≤ 106). The second line contains n integers ai (1 ≤ ai ≤ 106) — array a. | standard output | standard input | Python 3 | Python | 2,100 | train_004.jsonl | 390dfc74b6e625cce9cac033eda1aa26 | 256 megabytes | ["6 1\n3 6 10 12 13 16", "5 3\n8 21 52 15 77"] | PASSED | n, k = map(int, input().split())
t = set(map(int, input().split()))
y = x = min(t)
t = list(t)
while True:
for i in t:
if i % x > k: x = i // (i // x + 1)
if y == x: break
y = x
print(y) | 1381678200 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
3 seconds | ["3\n2\n3\n6"] | 7f15864d46f09ea6f117929565ccb867 | Note The first query asks for a centroid of the whole tree — this is node 3. If we delete node 3 the tree will split in four components, two of size 1 and two of size 2.The subtree of the second node consists of this node only, so the answer is 2.Node 3 is centroid of its own subtree.The centroids of the subtree of th... | After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the roses. Now he likes to watch snowflakes.Once upon a time, he found a huge snowflake that has a form of the tree (connected acyclic graph) consisting of n nodes. The root of tree has index 1. Kay is very interested in... | For each query print the index of a centroid of the corresponding subtree. If there are many suitable nodes, print any of them. It's guaranteed, that each subtree has at least one centroid. | The first line of the input contains two integers n and q (2 ≤ n ≤ 300 000, 1 ≤ q ≤ 300 000) — the size of the initial tree and the number of queries respectively. The second line contains n - 1 integer p2, p3, ..., pn (1 ≤ pi ≤ n) — the indices of the parents of the nodes from 2 to n. Node 1 is a root of the tree. It'... | standard output | standard input | Python 2 | Python | 1,900 | train_003.jsonl | 34642c4757df9c0c5a8c372994efdcd7 | 256 megabytes | ["7 4\n1 1 3 3 5 3\n1\n2\n3\n5"] | PASSED | n, q = map(int, raw_input().split(' '))
p_arr = map(lambda x:int(x) - 1, raw_input().split(' '))
p_arr = [-1] + p_arr
for i in p_arr[1:]:
i += 1
pe_arr = [0 for i in xrange(n)]
s_arr = [1 for i in xrange(n)]
mx_arr = [-1 for i in xrange(n)]
z_arr = [i for i in xrange(n)]
for i in p_arr:
if i > 0:
pe_arr[i] += 1... | 1466699700 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["2000", "1000"] | 991a9b3904884c8d19ec7c665f2fcd95 | null | Yaroslav is playing a game called "Time". The game has a timer showing the lifespan he's got left. As soon as the timer shows 0, Yaroslav's character dies and the game ends. Also, the game has n clock stations, station number i is at point (xi, yi) of the plane. As the player visits station number i, he increases the c... | In a single line print an integer — the answer to the problem. | The first line contains integers n and d (3 ≤ n ≤ 100, 103 ≤ d ≤ 105) — the number of stations and the constant from the statement. The second line contains n - 2 integers: a2, a3, ..., an - 1 (1 ≤ ai ≤ 103). The next n lines contain the coordinates of the stations. The i-th of them contains two integers xi, yi (-100 ≤... | standard output | standard input | Python 3 | Python | 2,100 | train_000.jsonl | da6a787390c2b5025ea1359b968c96ce | 256 megabytes | ["3 1000\n1000\n0 0\n0 1\n0 3", "3 1000\n1000\n1 0\n1 1\n1 2"] | PASSED | f = lambda: list(map(int, input().split()))
n, d = f()
a = [0] + f() + [0]
p = [f() for i in range(n)]
r = range(n)
s = [[d * (abs(p[i][0] - p[j][0]) + abs(p[i][1] - p[j][1])) - a[j] * (i != j) for j in r] for i in r]
for k in r: s = [[min(s[i][j], s[i][k] + s[k][j]) for i in r] for j in r]
print(s[-1][0])
| 1367769900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["0 1\n-1 2 \n1 2 \n1 3 \n18 22\n-2 7\n999999999999 1000000000001"] | a4628208668e9d838cd019e9dc03e470 | NoteIn the first test case, $$$0 + 1 = 1$$$.In the second test case, $$$(-1) + 0 + 1 + 2 = 2$$$.In the fourth test case, $$$1 + 2 + 3 = 6$$$.In the fifth test case, $$$18 + 19 + 20 + 21 + 22 = 100$$$.In the sixth test case, $$$(-2) + (-1) + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 = 25$$$. | Theofanis has a riddle for you and if you manage to solve it, he will give you a Cypriot snack halloumi for free (Cypriot cheese).You are given an integer $$$n$$$. You need to find two integers $$$l$$$ and $$$r$$$ such that $$$-10^{18} \le l < r \le 10^{18}$$$ and $$$l + (l + 1) + \ldots + (r - 1) + r = n$$$. | For each test case, print the two integers $$$l$$$ and $$$r$$$ such that $$$-10^{18} \le l < r \le 10^{18}$$$ and $$$l + (l + 1) + \ldots + (r - 1) + r = n$$$. It can be proven that an answer always exists. If there are multiple answers, print any. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first and only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^{18}$$$). | standard output | standard input | Python 3 | Python | 800 | train_097.jsonl | 364a2d0fb8cffc63689d7ed21bcd8526 | 256 megabytes | ["7\n1\n2\n3\n6\n100\n25\n3000000000000"] | PASSED | t=int(input())
for t in range (0,t):
p=int(input())
a=(p-1)
print(int(-a),int(a+1))
| 1633705500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["aba", "a", "cbaaacbcaaabc"] | 3bebb50d1c2ef9f80e78715614f039d7 | NoteIn the first example, other valid answers include "cacac", "caac", "aca" and "ccc". | Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it?The book contains a single string of characters "a", "b"... | Output a palindrome $$$t$$$ that is a subsequence of $$$s$$$ and $$$|t| \geq \lfloor \frac{|s|}{2} \rfloor$$$. If there are multiple solutions, you may print any of them. You don't have to maximise the length of $$$t$$$. If there are no solutions, output a string "IMPOSSIBLE" (quotes for clarity). | The input consists of a single string $$$s$$$ ($$$2 \leq |s| \leq 10^6$$$). The string $$$s$$$ consists only of characters "a", "b", "c". It is guaranteed that no two consecutive characters are equal. | standard output | standard input | PyPy 3 | Python | 1,900 | train_002.jsonl | 953c99e6c500fa842ee93adb4e7fa241 | 256 megabytes | ["cacbac", "abc", "cbacacacbcbababacbcb"] | PASSED |
sre = input()
pre = 0
kre = len(sre) - 1
pointeree = 0
... | 1563636900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1 1 1 1\n2 2 2 1\n2 2 2 2\n2 4 2 1\n3 5 1 1"] | f9f803c6850da1838d62a0cf85bb13f2 | NoteIn the first test case $$$\gcd(1, 1) = \operatorname{lcm}(1, 1) = 1$$$, $$$1 + 1 + 1 + 1 = 4$$$.In the second test case $$$\gcd(2, 2) = \operatorname{lcm}(2, 1) = 2$$$, $$$2 + 2 + 2 + 1 = 7$$$.In the third test case $$$\gcd(2, 2) = \operatorname{lcm}(2, 2) = 2$$$, $$$2 + 2 + 2 + 2 = 8$$$.In the fourth test case $$$... | You are given a positive integer $$$n$$$. You have to find $$$4$$$ positive integers $$$a, b, c, d$$$ such that $$$a + b + c + d = n$$$, and $$$\gcd(a, b) = \operatorname{lcm}(c, d)$$$.If there are several possible answers you can output any of them. It is possible to show that the answer always exists.In this problem... | For each test case output $$$4$$$ positive integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ such that $$$a + b + c + d = n$$$ and $$$\gcd(a, b) = \operatorname{lcm}(c, d)$$$. | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Description of the test cases follows. Each test case contains a single line with integer $$$n$$$ ($$$4 \le n \le 10^9$$$) — the sum of $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. | standard output | standard input | PyPy 3-64 | Python | 800 | train_096.jsonl | 4351fb2fc0e87665e46579a35f9d5ec9 | 256 megabytes | ["5\n4\n7\n8\n9\n10"] | PASSED | for __ in range(int(input())):
b = int(input())
if b==4:
print(1,1,1,1)
elif b==6:
print(1,3,1,1)
elif b%2==1:
b=int(b//2)
print(b-1,b,1,1)
else:
if b%4==0:
print(int(b/4),int(b/4),int(b/4),int(b/4))
else:
b-=2
... | 1649428500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1", "4", "-10"] | e83b559d99a0a41c690c68fd76f40ed3 | null | Alice and Bonnie are sisters, but they don't like each other very much. So when some old family photos were found in the attic, they started to argue about who should receive which photos. In the end, they decided that they would take turns picking photos. Alice goes first.There are n stacks of photos. Each stack conta... | Output a single integer: the difference between Alice's and Bonnie's happiness if both play optimally. | The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the number of two-photo stacks. Then follow n lines, each describing one of the stacks. A stack is described by four space-separated non-negative integers a1, b1, a2 and b2, each not exceeding 109. a1 and b1 describe the top photo in the stack, whi... | standard output | standard input | Python 2 | Python | 2,900 | train_038.jsonl | 79b84c9a8ffa23c09e01e70e80e5ebd8 | 256 megabytes | ["2\n12 3 4 7\n1 15 9 1", "2\n5 4 8 8\n4 12 14 0", "1\n0 10 0 10"] | PASSED | p=[];s=0
for i in range(input()):
a,b,c,d=map(int,raw_input().split())
if a+b>c+d:p+=[a+b,c+d];s-=b+d
elif a>d:s+=a-d
elif b>c:s-=b-c
print s+sum(sorted(p)[1::2]) | 1477148700 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
3 seconds | ["1028\n1\n3\n729229716\n652219904"] | fc8381e8c97190749b356f10cf80209e | null | There are $$$n$$$ bags, each bag contains $$$m$$$ balls with numbers from $$$1$$$ to $$$m$$$. For every $$$i \in [1, m]$$$, there is exactly one ball with number $$$i$$$ in each bag.You have to take exactly one ball from each bag (all bags are different, so, for example, taking the ball $$$1$$$ from the first bag and t... | For each test case, print one integer — the sum of $$$F^k$$$ over all possible ways to take $$$n$$$ balls, one from each bag. Since it can be huge, print it modulo $$$998244353$$$. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases. Each test case consists of one line containing three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n, m \le 998244352$$$; $$$1 \le k \le 2000$$$). | standard output | standard input | PyPy 3-64 | Python | 2,500 | train_109.jsonl | 1728526b7ec7c9ac31e5a00a1ec65327 | 512 megabytes | ["5\n\n2 3 8\n\n1 1 1\n\n1 5 10\n\n3 7 2000\n\n1337666 42424242 2000"] | PASSED | from sys import stdin
input=lambda :stdin.readline()[:-1]
mod=998244353
m=2010
S=[[0]*m for i in range(m)]
for n in range(1,m):
for k in range(1,n+1):
if k==1 or n==k:
S[n][k]=1
else:
S[n][k]=S[n-1][k-1]+k*S[n-1][k]
S[n][k]%=mod
def fpow(x,k):
res=1
if k<0:
return ... | 1659623700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["2\n1 2\n1 2\n3\n1 3\n2 3\n2 3\n5\n1 3\n2 4\n2 4\n3 4\n3 4\n0\n2\n1 2\n1 2\n0\n4\n1 2\n1 5\n1 4\n1 2\n1\n5 2"] | 5c013cdc91f88c102532a86058893f0d | null | An important meeting is to be held and there are exactly $$$n$$$ people invited. At any moment, any two people can step back and talk in private. The same two people can talk several (as many as they want) times per meeting.Each person has limited sociability. The sociability of the $$$i$$$-th person is a non-negative ... | Print $$$t$$$ answers to all test cases. On the first line of each answer print the number $$$k$$$ — the maximum number of talks possible in a meeting. On each of the next $$$k$$$ lines print two integers $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$ and $$$i \neq j$$$) — the numbers of people who will have another talk.... | The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of each test case description contains an integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) —the number of people in the meeting. The second line ... | standard output | standard input | PyPy 3-64 | Python | 1,400 | train_095.jsonl | 4cc35dd5568df63acf848804ebbac953 | 256 megabytes | ["8\n2\n2 3\n3\n1 2 3\n4\n1 2 3 4\n3\n0 0 2\n2\n6 2\n3\n0 0 2\n5\n8 2 0 1 1\n5\n0 1 0 0 6"] | PASSED | import sys, math, collections
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def input(): return sys.stdin.readline().strip()
MOD = 1000000007
for _ in range(int(input())):
n = int(input())
... | 1632839700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1 3 2 4 \n1 2 3 \n1 3 2 \n1 2 \n1 2"] | 5afa0e4f34ab8c8c67bc8ecb7d6d2d7a | NoteOne of the ways to get a lexicographically smallest permutation $$$[1, 3, 2, 4]$$$ from the permutation $$$[3, 1, 2, 4]$$$ (the first sample test case) is described in the problem statement. | In fact, the problems E1 and E2 do not have much in common. You should probably think of them as two separate problems.A permutation $$$p$$$ of size $$$n$$$ is given. A permutation of size $$$n$$$ is an array of size $$$n$$$ in which each integer from $$$1$$$ to $$$n$$$ occurs exactly once. For example, $$$[1, 4, 3, 2]... | Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to a test case should contain $$$n$$$ space-separated integer numbers — the elements of the lexicographically smallest permutation that is possible to find in the deque after executing the described algorithm. | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of each test case description contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — permutation size. The second line of the descript... | standard output | standard input | Python 3 | Python | 1,000 | train_095.jsonl | 29f88df583e0c2a598f857f6ea82ff62 | 256 megabytes | ["5\n4\n3 1 2 4\n3\n3 2 1\n3\n3 1 2\n2\n1 2\n2\n2 1"] | PASSED | from collections import deque
def arrange(arr, n):
d = deque()
for i in range(n):
if not d or arr[i] < d[0]:
d.appendleft(arr[i])
else:
d.append(arr[i])
return d
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
print(*arrange(a, n)) | 1632839700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\nYES\nNO\nYES\nYES\nNO\nNO\nYES\nNO"] | 8e448883014bf7cd35fcca3fe0128af0 | NoteFor the first test case, the string is already a $$$4$$$-balanced bitstring.For the second test case, the string can be transformed into 101.For the fourth test case, the string can be transformed into 0110.For the fifth test case, the string can be transformed into 1100110. | A bitstring is a string consisting only of the characters 0 and 1. A bitstring is called $$$k$$$-balanced if every substring of size $$$k$$$ of this bitstring has an equal amount of 0 and 1 characters ($$$\frac{k}{2}$$$ of each).You are given an integer $$$k$$$ and a string $$$s$$$ which is composed only of characters ... | For each test case, print YES if we can replace every ? in $$$s$$$ with 0 or 1 such that the resulting bitstring is $$$k$$$-balanced, or NO if it is not possible. | 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 two integers $$$n$$$ and $$$k$$$ ($$$2 \le k \le n \le 3 \cdot 10^5$$$, $$$k$$$ is even) — the length of the string... | standard output | standard input | Python 3 | Python | 1,500 | train_008.jsonl | 8d6a98127ecab401e63cae89d2926741 | 256 megabytes | ["9\n6 4\n100110\n3 2\n1?1\n3 2\n1?0\n4 4\n????\n7 4\n1?0??1?\n10 10\n11??11??11\n4 2\n1??1\n4 4\n?0?0\n6 2\n????00"] | PASSED |
for ad in range(int(input())):
n,k=list(map(int,input().split()))
s=list(input())
l=[]
for i in range(1,n//k+1):
l.append(s[k*(i-1):k*i])
l.append(s[(n//k)*k:])
a=l[0]
t=0
#print(l)
for i in l:
if t==1:
break
for j in range(len(i)):
i... | 1599402900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["-1", "1", "2"] | 8237ac3f3c2e79f5f70be1595630207e | NoteIn the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change s to "LDUR". This string uses ... | Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: An 'L' indicates he should move one unit left. An 'R' indicates he should move one unit right. A 'U' indicates he should move one unit up. A 'D' indicates he should move one unit d... | If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1. | The first and only line contains the string s (1 ≤ |s| ≤ 100 000) — the instructions Memory is given. | standard output | standard input | PyPy 2 | Python | 1,100 | train_014.jsonl | 341580318e853b075fd400ec857979a8 | 256 megabytes | ["RRU", "UDUR", "RUUR"] | PASSED | y=raw_input()
if len(y)%2!=0:
print -1
else:
print (abs(y.count('R')-y.count('L'))+abs(y.count('U')-y.count('D')))/2
| 1473525900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["Yes\n1\n1 4\nNo\nNo\nYes\n3\n1 2\n3 1\n2 3"] | 4985f4d65d636a006f2619ed821368ad | null | This problem is different from the easy version. In this version Ujan makes at most $$$2n$$$ swaps. In addition, $$$k \le 1000, n \le 50$$$ and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems.After struggling and... | For each test case, output "Yes" if Ujan can make the two strings equal with at most $$$2n$$$ operations and "No" otherwise. You can print each letter in any case (upper or lower). In the case of "Yes" print $$$m$$$ ($$$1 \le m \le 2n$$$) on the next line, where $$$m$$$ is the number of swap operations to make the stri... | The first line contains a single integer $$$k$$$ ($$$1 \leq k \leq 1000$$$), the number of test cases. For each of the test cases, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 50$$$), the length of the strings $$$s$$$ and $$$t$$$. Each of the next two lines contains the strings $$$s$$$ and $$$t$$... | standard output | standard input | Python 3 | Python | 1,600 | train_001.jsonl | e8db55221e0cb3c474cb5ba4080e6ce2 | 256 megabytes | ["4\n5\nsouse\nhouhe\n3\ncat\ndog\n2\naa\naz\n3\nabc\nbca"] | PASSED | import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int,minp().split())
def swap(s, t, i, j):
p.append((i+1,j+1))
s[i],t[j] = t[j],s[i]
def find(s, v, i):
for j in range(i,len(s)):
if s[j] == v:
return j
return -1
def solve():
global p
n ... | 1573052700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1111", "01010", "1011011"] | 7e8baa4fb780f11e66bb2b7078e34c04 | NoteIn the first test, it's easy to see, that the only unique substring of string $$$s = $$$"1111" is all string $$$s$$$, which has length $$$4$$$.In the second test a string $$$s = $$$"01010" has minimal unique substring $$$t =$$$"101", which has length $$$3$$$.In the third test a string $$$s = $$$"1011011" has minima... | Let $$$s$$$ be some string consisting of symbols "0" or "1". Let's call a string $$$t$$$ a substring of string $$$s$$$, if there exists such number $$$1 \leq l \leq |s| - |t| + 1$$$ that $$$t = s_l s_{l+1} \ldots s_{l + |t| - 1}$$$. Let's call a substring $$$t$$$ of string $$$s$$$ unique, if there exist only one such $... | Print a string $$$s$$$ of length $$$n$$$, consisting of symbols "0" and "1". Minimal length of the unique substring of $$$s$$$ should be equal to $$$k$$$. You can find any suitable string. It is guaranteed, that there exists at least one such string. | The first line contains two integers $$$n$$$ and $$$k$$$, separated by spaces ($$$1 \leq k \leq n \leq 100\,000$$$, $$$(k \bmod 2) = (n \bmod 2)$$$). | standard output | standard input | Python 3 | Python | 2,200 | train_003.jsonl | 825b99735298852deeb5725b991d0dfd | 256 megabytes | ["4 4", "5 3", "7 3"] | PASSED | N, K = map(int, input().split())
if N == K:
print("0"*N)
elif K == 1:
print("0"*(N-1) + "1")
elif K == 3:
print("1" + "0"*(N-4) + "101")
else:
res = ["0"]*N
for i in range(0, N, N//2-K//2+1):
res[i] = "1"
print(''.join(res)) | 1557671700 | [
"math",
"strings"
] | [
0,
0,
0,
1,
0,
0,
1,
0
] | |
5 seconds | ["? 1 2\n40\n? 2 5\n90\n? 3 1\n56\n? 4 5\n18\n! 8 10 7 6 9\n? 1 5\n312\n? 2 4\n675\n! 24 25 28 27 26\n? 1 4\n4\n? 2 5\n10\n? 3 7\n21\n? 6 2\n6\n? 2 5\n10\n? 1 2\n2\n? 1 2\n2\n? 1 2\n2\n? 1 2\n2\n? 1 2\n2\n! 1 2 3 4 5 6 7"] | d66b80cd06c28d2a62167be699996285 | null | Do you know what tubular bells are? They are a musical instrument made up of cylindrical metal tubes. In an orchestra, tubular bells are used to mimic the ringing of bells.Mike has tubular bells, too! They consist of $$$n$$$ tubes, and each of the tubes has a length that can be expressed by a integer from $$$l$$$ to $$... | null | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 20$$$), denoting the number of test cases. Description of the test cases follows. The single line of each test case contains one positive integer $$$n$$$ ($$$3 \le n \le 10^5$$$) — number of tubes in Mike's tubu... | standard output | standard input | PyPy 3 | Python | 2,900 | train_086.jsonl | c5702665f8d601c84bc7f7c259bd1fa0 | 512 megabytes | ["3\n5\n8 10 7 6 9\n5\n24 25 28 27 26\n7\n1 2 3 4 5 6 7"] | PASSED | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer... | 1629988500 | [
"number theory",
"math",
"probabilities"
] | [
0,
0,
0,
1,
1,
1,
0,
0
] | |
2 seconds | ["2\n2\n2\n31680"] | 667e320912f115d0b598bb45129b5845 | null | It is Borya's eleventh birthday, and he has got a great present: n cards with numbers. The i-th card has the number ai written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get a numbe... | For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353. | Input data contains multiple test cases. The first line of the input data contains an integer t — the number of test cases (1 ≤ t ≤ 100). The descriptions of test cases follow. Each test is described by two lines. The first line contains an integer n (1 ≤ n ≤ 2000) — the number of cards in Borya's present. The second l... | standard output | standard input | PyPy 3 | Python | 2,400 | train_040.jsonl | c3903c246feff93bdb1eab67735760cd | 512 megabytes | ["4\n2\n1 1\n3\n1 31 12\n3\n12345 67 84\n9\n1 2 3 4 5 6 7 8 9"] | PASSED | mod = 998244353
f0 = [ [0 for i in range(11)] for j in range(2010) ]
f1 = [ [0 for i in range(11)] for j in range(2010) ]
fac = [0 for i in range(2010)]
tab = [0 for i in range(11)]
C = [ [0 for i in range(2010)] for j in range(2010) ]
def Init() :
fac[0] = 1
for i in range(2010) :
if i > 0 : fac[i] = ... | 1505050500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["14.0000000000\n12.0000000000\n8.0000000000\n6.0000000000\n4.0000000000", "19.6000000000\n18.6000000000\n16.6000000000\n13.6000000000\n12.6000000000"] | 38388446f5c265f77124132caa3ce4d2 | NoteConsider the first sample. There are 6 triples: (1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1). Because n = 3, the cost needed to build the network is always d(1, 2) + d(2, 3) + d(3, 1) for all the triples. So, the expected cost equals to d(1, 2) + d(2, 3) + d(3, 1). | New Year is coming in Tree World! In this world, as the name implies, there are n cities connected by n - 1 roads, and for any two distinct cities there always exists a path between them. The cities are numbered by integers from 1 to n, and the roads are numbered by integers from 1 to n - 1. Let's define d(u, v) as tot... | Output q numbers. For each given change, print a line containing the expected cost needed to build the network in Tree World. The answer will be considered correct if its absolute and relative error doesn't exceed 10 - 6. | The first line contains an integer n (3 ≤ n ≤ 105) — the number of cities in Tree World. Next n - 1 lines describe the roads. The i-th line of them (1 ≤ i ≤ n - 1) contains three space-separated integers ai, bi, li (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ li ≤ 103), denoting that the i-th road connects cities ai and bi, and the l... | standard output | standard input | Python 3 | Python | 1,900 | train_030.jsonl | de9db05d6b113ff724fdfe4039da4f39 | 256 megabytes | ["3\n2 3 5\n1 3 3\n5\n1 4\n2 2\n1 2\n2 1\n1 1", "6\n1 5 3\n5 3 2\n6 1 7\n1 4 4\n5 2 3\n5\n1 2\n2 1\n3 5\n4 1\n5 2"] | PASSED |
from queue import Queue
import sys
cost = []
def readarray(): return map(int, input().split(' '))
n = int(input())
graph = [[] for i in range(n)]
for i in range(n - 1):
u, v, c = readarray()
u, v = u - 1, v - 1
cost.append(c)
graph[u].append((v, i))
graph[v].append((u, i))
order = []
used = [0] * n
q = [0]... | 1419951600 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["RBRBRBR\nRRRBRR\nRRBRRBRRBRRBRRBRRBR", "RBR\nRRBRBRBRBR\nRBRBRBRBRBR\nRRRRRBRRRR\nRRRBRRRBRR\nRRRBRRRBRRR"] | 7cec27879b443ada552a6474c4e45c30 | NoteThe first test case of the first example gives the optimal answer for the example in the statement. The maximum number of times a team wins in a row in RBRBRBR is $$$1$$$. We cannot minimize it any further.The answer for the second test case of the second example is RRBRBRBRBR. The maximum number of times a team wi... | Team Red and Team Blue competed in a competitive FPS. Their match was streamed around the world. They played a series of $$$n$$$ matches.In the end, it turned out Team Red won $$$r$$$ times and Team Blue won $$$b$$$ times. Team Blue was less skilled than Team Red, so $$$b$$$ was strictly less than $$$r$$$.You missed th... | For each test case, output a single line containing a string satisfying the given conditions. If there are multiple answers, print any. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case has a single line containing three integers $$$n$$$, $$$r$$$, and $$$b$$$ ($$$3 \leq n \leq 100$$$; $$$1 \leq b < r \leq n$$$, $$$r+b=n$$$). | standard output | standard input | PyPy 3-64 | Python | 1,000 | train_110.jsonl | 3b47818779008796e93449d845f4f38c | 256 megabytes | ["3\n7 4 3\n6 5 1\n19 13 6", "6\n3 2 1\n10 6 4\n11 6 5\n10 9 1\n10 8 2\n11 9 2"] | PASSED | t = int(input())
for _ in range(t):
n, r, b = [int(c) for c in input().split()]
if b == 1:
print('R' * (r // 2) + 'B' + 'R' * (r - r // 2))
continue
s = ['R' * (r // (b + 1)) + 'B'] * b + ['R' * (r // (b + 1))]
left = r % (b + 1)
for i in range(left):
s[i] += 'R'
... | 1650206100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1\n0\n3"] | e75b88ce4341062c20b6014da1152d29 | NoteIn the first test case, you can, for example, put one extra block into the first box and make $$$a = [4, 2, 2]$$$. If your nephew chooses the box with $$$4$$$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $$$2$$$ blocks then he will move these two... | You are asked to watch your nephew who likes to play with toy blocks in a strange way.He has $$$n$$$ boxes and the $$$i$$$-th box has $$$a_i$$$ blocks. His game consists of two steps: he chooses an arbitrary box $$$i$$$; he tries to move all blocks from the $$$i$$$-th box to other boxes. If he can make the same num... | For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of boxes. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^... | standard output | standard input | Python 3 | Python | 1,400 | train_002.jsonl | 6dfaf6a3ea6472d1dfbce0a6ae5656d7 | 256 megabytes | ["3\n3\n3 2 2\n4\n2 2 3 2\n3\n0 3 0"] | PASSED |
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
m=max(a)
an=0
if n==2:print(0)
else:
an=0
s=sum(a)
p=m*(n-1)
if p<s:
i=s//(n-1)
p=i*(n-1)
if p<s:
p=(i+1)*(n-1)
an=p-sum(a)
p... | 1605796500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
5 seconds | ["2 3 4 5 6", "5", "9 11 13 15 17 19 21 25 27 33"] | 1bdcc566e5593429136cf216d361508b | null | A thief made his way to a shop.As usual he has his lucky knapsack with him. The knapsack can contain k objects. There are n kinds of products in the shop and an infinite number of products of each kind. The cost of one product of kind i is ai.The thief is greedy, so he will take exactly k products (it's possible for so... | Print the only line with all the possible total costs of stolen products, separated by a space. The numbers should be printed in the ascending order. | The first line contains two integers n and k (1 ≤ n, k ≤ 1000) — the number of kinds of products and the number of products the thief will take. The second line contains n integers ai (1 ≤ ai ≤ 1000) — the costs of products for kinds from 1 to n. | standard output | standard input | PyPy 2 | Python | 2,400 | train_079.jsonl | df4ae64febda31308aea5eabafc9b42b | 512 megabytes | ["3 2\n1 2 3", "5 5\n1 1 1 1 1", "3 3\n3 5 11"] | PASSED | n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
a = list(set(a))
a.sort()
mn, mx = a[0], a[-1]
lo = mn * k
hi = mx * k
D = [t - mn for t in a]
modify_cnt = [k+1] * 1000010
modify_cnt[0] = 0
for d in D:
if d == 0: continue
for i in xrange(0, hi - d + 1):
modify_cnt[i+d] = min(mo... | 1456844400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0.800000000000", "0.260000000000"] | b4ac594755951e84001dfd610d420eb5 | NoteIn the first sample the best strategy for Andrey is to ask only one of his friends, the most reliable one.In the second sample the best strategy for Andrey is to ask all of his friends to come up with a problem. Then the probability that he will get exactly one problem is 0.1·0.8 + 0.9·0.2 = 0.26. | Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him.Help Andrey choose p... | Print a single real number — the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most 10 - 9. | The first line contains a single integer n (1 ≤ n ≤ 100) — the number of Andrey's friends. The second line contains n real numbers pi (0.0 ≤ pi ≤ 1.0) — the probability that the i-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point. | standard output | standard input | Python 3 | Python | 1,800 | train_011.jsonl | 7b4b90215bc3d513f37d8fdb27ec05fc | 256 megabytes | ["4\n0.1 0.2 0.3 0.8", "2\n0.1 0.2"] | PASSED | def C():
n = int(input())
tmp = input()
tmp = tmp.split()
probability = list(map(float,tmp))
probability.sort()
current = probability[n-1]
pre = 1 - probability[n-1]
for i in range(n-2,-1,-1):
tmp = current * (1-probability[i]) + pre * (probability[i])
if (tmp > cu... | 1403191800 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
2 seconds | ["1, 2, 3, ..., 10", "1, , , 4 ...5 ... ...6", "..., 1, 2, 3, ..."] | c7d8c71a1f7e6c7364cce5bddd488a2f | null | Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected ... | Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it. | The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above. | standard output | standard input | Python 3 | Python | 1,700 | train_014.jsonl | 90370fc6a182c2bf23753c1f5c34101b | 256 megabytes | ["1,2 ,3,..., 10", "1,,,4...5......6", "...,1,2,3,..."] | PASSED | ans = input()
while " ," in ans:
ans = ans.replace(" ,", ",")
ans = ans.replace("...", " ...").replace(",", ", ")
while " " in ans:
ans = ans.replace(" ", " ")
for d in "0123456789": ans = ans.replace(". " + d, "." + d)
print(ans.strip(), end="")
| 1304485200 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["20\n1 2 3 4 5 \n5 2 4 3 1", "8\n1 2 3 \n3 2 1", "-1"] | 5659275a002a3e6fc45b79ded33202e2 | NoteIn the first example the order of runners on the first track should be $$$[5, 3, 2, 1, 4]$$$, and the order of runners on the second track should be $$$[1, 4, 2, 5, 3]$$$. Then the duration of the competition is $$$max(5, 1) + max(3, 4) + max(2, 2) + max(1, 5) + max(4, 3) = 5 + 4 + 2 + 5 + 4 = 20$$$, so it is equal... | Demonstrative competitions will be held in the run-up to the $$$20NN$$$ Berlatov Olympic Games. Today is the day for the running competition!Berlatov team consists of $$$2n$$$ runners which are placed on two running tracks; $$$n$$$ runners are placed on each track. The runners are numbered from $$$1$$$ to $$$n$$$ on ea... | If it is impossible to reorder the runners so that the duration of the competition does not exceed $$$k$$$ seconds, print $$$-1$$$. Otherwise, print three lines. The first line should contain one integer $$$sum$$$ — the maximum possible duration of the competition not exceeding $$$k$$$. The second line should contain ... | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^6, 1 \le k \le n^2$$$) — the number of runners on each track and the maximum possible duration of the competition, respectively. | standard output | standard input | PyPy 2 | Python | 2,400 | train_009.jsonl | 23a73b0cdc9d21e18a74799019aca3f9 | 256 megabytes | ["5 20", "3 9", "10 54"] | PASSED | import sys
input = sys.stdin.readline
def sum1n(n):
return (n*(n+1))//2
def count_max(n):
k1 = n//2
k2 = n - k1
return 2*sum1n(n) - sum1n(k1) - sum1n(k2)
n, k = map(int, input().split())
mn = n*(n+1) // 2
if k < mn:
print("-1")
else:
mx = count_max(n)
target = min(k, mx)
print(str... | 1570957500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["4 3 1 2", "4 3 2 5 1", "2 1"] | a133b2c63e1025bdf13d912497f9b6a4 | null | Students of group 199 have written their lectures dismally. Now an exam on Mathematical Analysis is approaching and something has to be done asap (that is, quickly). Let's number the students of the group from 1 to n. Each student i (1 ≤ i ≤ n) has a best friend p[i] (1 ≤ p[i] ≤ n). In fact, each student is a best frie... | Print sequence n of different integers p[1], p[2], ..., p[n] (1 ≤ p[i] ≤ n). It is guaranteed that the solution exists and that it is unique. | The first line contains integer n (1 ≤ n ≤ 105) — the number of students in the group. The second line contains sequence of different integers a1, a2, ..., an (1 ≤ ai ≤ n). The third line contains the sequence of different integers b1, b2, ..., bn (1 ≤ bi ≤ n). | standard output | standard input | Python 3 | Python | 1,200 | train_030.jsonl | 06a431c9d2e10121b872af9ab0d48d38 | 256 megabytes | ["4\n2 1 4 3\n3 4 2 1", "5\n5 2 3 1 4\n1 3 2 4 5", "2\n1 2\n2 1"] | PASSED |
x = input()
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
bestFriends = {}
for i,j in zip(a,b):
bestFriends[i] = j
for i in range(len(a)):
print(bestFriends[i+1],end=" ") | 1335078000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["4", "1", "-1"] | 6946f088e462d12da47419f492ad51ea | NoteNote to the first example. If you delete the $$$4$$$-th element, you can get the arithmetic progression $$$[2, 4, 6, 8]$$$.Note to the second example. The original sequence is already arithmetic progression, so you can delete $$$1$$$-st or last element and you will get an arithmetical progression again. | A sequence $$$a_1, a_2, \dots, a_k$$$ is called an arithmetic progression if for each $$$i$$$ from $$$1$$$ to $$$k$$$ elements satisfy the condition $$$a_i = a_1 + c \cdot (i - 1)$$$ for some fixed $$$c$$$.For example, these five sequences are arithmetic progressions: $$$[5, 7, 9, 11]$$$, $$$[101]$$$, $$$[101, 100, 99]... | Print such index $$$j$$$ ($$$1 \le j \le n$$$), so that if you delete the $$$j$$$-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1. | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — length of the sequence $$$b$$$. The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$) — elements of the sequence $$$b$$$. | standard output | standard input | Python 3 | Python | 1,700 | train_002.jsonl | 58502abe75e2f867247347d1ca1b0688 | 256 megabytes | ["5\n2 6 8 7 4", "8\n1 2 3 4 5 6 7 8", "4\n1 2 4 8"] | PASSED |
def main():
buf = input()
n = int(buf)
buf = input()
buflist = buf.split()
if n == 2 or n == 3:
print(1) # corner
return
b = list(map(int, buflist))
for i in range(n):
b[i] = (b[i], i)
b.sort()
delta = []
for i in range(n-1):
delta.append(b[i+1][0... | 1560955500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["6 -3"] | a01e1c545542c1641eca556439f0692e | null | A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist. | If the required point exists, output its coordinates, otherwise output -1. | The first line contains three integers A, B and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0. | standard output | standard input | Python 2 | Python | 1,800 | train_002.jsonl | 917234d6fbbb0ad6d14506948dfd7760 | 256 megabytes | ["2 5 3"] | PASSED | def extgcd(a, b):
if b == 0:
return 1, 0, a
x, y, g = extgcd(b, a % b)
return y, x - y * (a // b), g
a, b, c = map(int, raw_input().split())
x, y, g = extgcd(a, b)
if c % g != 0:
print -1
else:
t = c // g
print -x * t, -y * t
| 1270136700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["1\n4\n2"] | bdce4761496c88a3de00aa863ba7308d | null | You are looking at the floor plan of the Summer Informatics School's new building. You were tasked with SIS logistics, so you really care about travel time between different locations: it is important to know how long it would take to get from the lecture room to the canteen, or from the gym to the server room.The buil... | For each query print a single integer: the minimum walking time between the locations in minutes. | The first line of the input contains following integers: n: the number of towers in the building (1 ≤ n ≤ 108), h: the number of floors in each tower (1 ≤ h ≤ 108), a and b: the lowest and highest floor where it's possible to move between adjacent towers (1 ≤ a ≤ b ≤ h), k: total number of queries (1 ≤ k ≤ 104). ... | standard output | standard input | Python 2 | Python | 1,000 | train_004.jsonl | b117097a1241bdc521744c31456d4bc9 | 256 megabytes | ["3 6 2 3 3\n1 2 1 3\n1 4 3 4\n1 2 2 3"] | PASSED | from sys import stdin
n,h,a,b,k = map(int,stdin.readline().split())
for _ in xrange(k):
t1,f1,t2,f2 = map(int,stdin.readline().split())
ans = abs(t1-t2)
if t1 !=t2:
if f1 < a:
ans += a-f1
f1 = a
if f1 > b:
ans += f1 - b
f1 = b
ans += abs(f1... | 1533994500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["5\n1\n2\n1\n0\n3"] | a544dd9fd96379f66a960de6f973dd50 | NoteThe first test case is explained in the statements.In the second test case, you can insert one element, $$$a=[1,\underline{\textbf{2}},3]$$$.In the third test case, you can insert two elements, $$$a=[6,\underline{\textbf{4}},\underline{\textbf{2}},1]$$$.In the fourth test case, you can insert one element, $$$a=[1,\... | Polycarp calls an array dense if the greater of any two adjacent elements is not more than twice bigger than the smaller. More formally, for any $$$i$$$ ($$$1 \le i \le n-1$$$), this condition must be satisfied: $$$$$$\frac{\max(a[i], a[i+1])}{\min(a[i], a[i+1])} \le 2$$$$$$For example, the arrays $$$[1, 2, 3, 4, 3]$$$... | For each test case, output one integer — the minimum number of numbers that must be added to the array to make it dense. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \le n \le 50$$$) — the length of the array $$$a$$$. The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 50$$$). | standard output | standard input | Python 3 | Python | 800 | train_098.jsonl | bdb2106e2a28a3ad09b8eabdc0f4af38 | 256 megabytes | ["6\n4\n4 2 10 1\n2\n1 3\n2\n6 1\n3\n1 4 2\n5\n1 2 3 4 3\n12\n4 31 25 50 30 20 34 46 42 16 15 16"] | PASSED | import math
n = int(input())
for x in range(n):
l = int(input())
a = list(map(int,input().split()))
f = 0
for i in range(len(a) - 1):
low = min(a[i],a[i+1])
high = max(a[i],a[i+1])
while high > low * 2:
low *= 2
f += 1
print(f)
| 1613486100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nNO\nNO\nYES\nYES\nYES"] | 8b926a19f380a56018308668c17c6928 | NoteIn the first example, it is necessary to eat sweets in this order: a candy of the type $$$2$$$, it is the most frequent, now $$$a = [2, 2]$$$; a candy of the type $$$1$$$, there are the same number of candies of the type $$$2$$$, but we just ate one, now $$$a = [1, 2]$$$; a candy of the type $$$2$$$, it is the most... | Not so long ago, Vlad had a birthday, for which he was presented with a package of candies. There were $$$n$$$ types of candies, there are $$$a_i$$$ candies of the type $$$i$$$ ($$$1 \le i \le n$$$).Vlad decided to eat exactly one candy every time, choosing any of the candies of a type that is currently the most freque... | Output $$$t$$$ lines, each of which contains the answer to the corresponding test case of input. As an answer, output "YES" if Vlad can eat candy as planned, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer). | The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of input test cases. The following is a description of $$$t$$$ test cases of input, two lines for each. The first line of the case contains the single number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of types of c... | standard output | standard input | PyPy 3-64 | Python | 800 | train_105.jsonl | 2614f01e6c86016d68b84a0a38ee655c | 256 megabytes | ["6\n2\n2 3\n1\n2\n5\n1 6 2 4 3\n4\n2 2 2 1\n3\n1 1000000000 999999999\n1\n1"] | PASSED | for t in range(int(input())):
n = input()
candies = sorted(list(map(int, input().split())))
if len(candies) == 1:
res = 'Yes' if candies[0] == 1 else 'No'
else:
res = 'Yes' if candies[-1] - candies[-2] <= 1 else 'No'
print(res) | 1648737300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["9\n297\n0\n14"] | 1e54530bc8cff81199b9cc1a6e51d638 | NoteIn the first test case, the optimal segment is $$$l = 7$$$, $$$r = 8$$$. The beauty of this segment equals to $$$(6 - 1) + (5 - 1) = 9$$$.In the second test case, the optimal segment is $$$l = 2$$$, $$$r = 4$$$. The beauty of this segment equals $$$(100 - 2) + (200 - 1) = 297$$$. | You are given an array $$$a$$$ that contains $$$n$$$ integers. You can choose any proper subsegment $$$a_l, a_{l + 1}, \ldots, a_r$$$ of this array, meaning you can choose any two integers $$$1 \le l \le r \le n$$$, where $$$r - l + 1 < n$$$. We define the beauty of a given subsegment as the value of the following e... | For each testcase print a single integer — the maximum beauty of a proper subsegment. | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Then follow the descriptions of each test case. The first line of each test case contains a single integer $$$n$$$ $$$(4 \leq n \leq 10^5)$$$ — the length of the array. The second line of each test case contains $$$n$$$ i... | standard output | standard input | Python 3 | Python | 800 | train_098.jsonl | accd1ab314ec8506510d9f43430ec28b | 256 megabytes | ["4\n8\n1 2 2 3 1 5 6 1\n5\n1 2 3 100 200\n4\n3 3 3 3\n6\n7 8 3 1 1 8"] | PASSED | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int,input().split()))
maxpos=0
minpos=1
ans=0
for i in range(n):
if a[i]>=a[maxpos]:
maxpos=i
if a[i]<=a[minpos]:
minpos=i
min1=999999999999999
max1=0
#print(ma... | 1660829700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\n2 1 2\n1 1 2", "3\n2 2 3\n1 1 3\n1 1 2", "0"] | 3b2c5410441e588806690056693514a8 | null | You are given a square matrix consisting of n rows and n columns. We assume that the rows are numbered from 1 to n from top to bottom and the columns are numbered from 1 to n from left to right. Some cells (n - 1 cells in total) of the the matrix are filled with ones, the remaining cells are filled with zeros. We can a... | Print the description of your actions. These actions should transform the matrix to the described special form. In the first line you should print a non-negative integer m (m ≤ 105) — the number of actions. In each of the next m lines print three space-separated integers t, i, j (1 ≤ t ≤ 2, 1 ≤ i, j ≤ n, i ≠ j), where ... | The first line contains an integer n (2 ≤ n ≤ 1000) — the number of rows and columns. Then follow n - 1 lines that contain one's positions, one per line. Each position is described by two integers xk, yk (1 ≤ xk, yk ≤ n), separated by a space. A pair (xk, yk) means that the cell, which is located on the intersection of... | standard output | standard input | Python 3 | Python | 2,100 | train_037.jsonl | f05be1c61c7cca535779b5762517d3db | 256 megabytes | ["2\n1 2", "3\n3 1\n1 3", "3\n2 1\n3 2"] | PASSED | n = int(input())
a = []
b = [0] * (n+1)
c = [10000] * (n+1)
for i in range(0,n-1):
p1,p2 = list(map(int,input().split()))
a.append((p1,p2))
b[p1] = max(b[p1],p2)
ans = []
for i in range(1,n+1):
if b[i]==0: continue
k = 0
for j in range(i,n+1):
if b[j]==0:
k=j
br... | 1358868600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["5", "274201", "12"] | 1e55358988db2fce66b8a53daae50d83 | null | Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k ≥ 1 non-overlapping substrings from... | Print the answer in a single line. | Input consists of two lines containing strings s and t (1 ≤ |s|, |t| ≤ 105). Each string consists of lowercase Latin letters. | standard output | standard input | Python 3 | Python | 2,000 | train_009.jsonl | 5c845e8e5f301a93b10b94b6d558b7e9 | 256 megabytes | ["ababa\naba", "welcometoroundtwohundredandeightytwo\nd", "ddd\nd"] | PASSED | s, t = input(), input()
n, m = len(t), len(s) + 1
d = 1000000007
g = [1] * m
f = k = 0
for i in range(1, m):
if s[i - n:i] == t: k = i
if k: f = (f + g[k - n]) % d
g[i] += (g[i - 1] + f) % d
print(f)
| 1418488200 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["LDL", "NO", "WLLLLLWWWWWWWWLWLWDW"] | 1321013edb706b2e3f3946979c4a5916 | null | Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser.Last evening Roma started to play poker. He decided to spend no more than k virtual bourles... | If there is no valid sequence that can be obtained from s by replacing all ? characters by W, L or D, print NO. Otherwise print this sequence. If there are multiple answers, print any of them. | The first line contains two numbers n (the length of Roma's sequence) and k (1 ≤ n, k ≤ 1000). The second line contains the sequence s consisting of characters W, L, D and ?. There are exactly n characters in this sequence. | standard output | standard input | Python 3 | Python | 2,000 | train_023.jsonl | e1bd8a077099a2545813381fb0a9eb67 | 256 megabytes | ["3 2\nL??", "3 1\nW??", "20 5\n?LLLLLWWWWW?????????"] | PASSED | n, k = [int(i) for i in input().split()]
s = input()
dp = [[False] * 2100 for i in range(1001)]
dp[0][0] = True
for i in range(n):
l = -k + 1
r = k
if i == n - 1:
l -= 1
r += 1
for b in range(l, r):
if s[i] == 'L':
dp[i + 1][b] = dp[i][b + 1]
elif s[i] == 'W... | 1493391900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["0\n1\n2\n0"] | d0c50562764f2008045fe57e5da5de1c | null | You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height $$$h$$$, and there is a moving platform on each height $$$x$$$ from $$$1$$$ to $$$h$$$.Each platform is either hidden inside the cliff or moved out. At first, there are... | For each query print one integer — the minimum number of magic crystals you have to spend to safely come down on the ground level (with height $$$0$$$). | The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query contains two lines and is independent of all other queries. The first line of each query contains two integers $$$h$$$ and $$$n$$$ ($$$1 \le h \le 10^9$$$, $$$1 \le n \le \min(h, 2 \cdot 10^5)$$$) — the height of the... | standard output | standard input | PyPy 2 | Python | 1,600 | train_000.jsonl | b084f1988c923dff4a8b4fa95dc6f846 | 256 megabytes | ["4\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n1 1\n1"] | PASSED | #!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from random import randint
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from ... | 1570545300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\nNO\nYES\nYES"] | a4a69a5fbf35781ff0849332a45566ca | NoteIn the first testcase, the first stick can be broken into parts of length $$$1$$$ and $$$5$$$. We can construct a rectangle with opposite sides of length $$$1$$$ and $$$5$$$.In the second testcase, breaking the stick of length $$$2$$$ can only result in sticks of lengths $$$1, 1, 2, 5$$$, which can't be made into a... | There are three sticks with integer lengths $$$l_1, l_2$$$ and $$$l_3$$$.You are asked to break exactly one of them into two pieces in such a way that: both pieces have positive (strictly greater than $$$0$$$) integer length; the total length of the pieces is equal to the original length of the stick; it's possible... | For each testcase, print "YES" if it's possible to break one of the sticks into two pieces with positive integer length in such a way that it's possible to construct a rectangle from the resulting four sticks. Otherwise, print "NO". You may print every letter in any case you want (so, for example, the strings yEs, yes,... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The only line of each testcase contains three integers $$$l_1, l_2, l_3$$$ ($$$1 \le l_i \le 10^8$$$) — the lengths of the sticks. | standard output | standard input | Python 3 | Python | 800 | train_085.jsonl | 59f885d8666a7c2192a772a8d8713fa9 | 256 megabytes | ["4\n6 1 5\n2 5 2\n2 4 2\n5 5 4"] | PASSED | n=int(input())
for i in range(n):
a, b, c=map(int, input().split())
if a+b==c or a+c==b or b+c==a or a==b and c%2==0 or a==c and b%2==0 or b==c and a%2==0:
print("YES")
else:
print("NO")
# Tue Jan 25 2022 07:44:44 GMT+0000 (Coordinated Universal Time)
| 1640615700 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
1 second | ["16", "21"] | 2022f53e5a88d5833e133dc3608a122c | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers ... | Print a single integer — the maximum possible total score of the class. | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents ... | standard output | standard input | PyPy 3 | Python | 900 | train_010.jsonl | ec3859373986b1f46e5a80b7a78b3978 | 256 megabytes | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | PASSED | stu_ex = input().split(" ")
student, exam = [int(a) for a in stu_ex]
ans = [[0, 0, 0, 0, 0] for i in range(0, exam)]
#print(ans)
for i in range(0, student):
std_ans = input()
for j in range(0, exam):
choose = 0
if std_ans[j] == 'B':
choose = 1
elif std_ans[j] == 'C':
... | 1564936500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1\n4\n0\n8"] | 293f9b996eee9f76d4bfdeda85685baa | NoteIn the first test case, the first swimmer is on the left side in $$$0, 5, 10, 15, \ldots$$$ minutes after the start time, the second swimmer is on the left side in $$$0, 4, 8, 12, \ldots$$$ minutes after the start time, and the third swimmer is on the left side in $$$0, 8, 16, 24, \ldots$$$ minutes after the start ... | Three swimmers decided to organize a party in the swimming pool! At noon, they started to swim from the left side of the pool.It takes the first swimmer exactly $$$a$$$ minutes to swim across the entire pool and come back, exactly $$$b$$$ minutes for the second swimmer and $$$c$$$ minutes for the third. Hence, the firs... | For each test case, output one integer — how long you have to wait (in minutes) before one of the swimmers arrives at the left side of the pool. | The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Next $$$t$$$ lines contains test case descriptions, one per line. Each line contains four integers $$$p$$$, $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \leq p, a, b, c \leq 10^{18}$$$), time in minutes after the ... | standard output | standard input | PyPy 3-64 | Python | 800 | train_109.jsonl | a792a60220a904f70f86e099cc76d0ad | 512 megabytes | ["4\n9 5 4 8\n2 6 10 9\n10 2 5 10\n10 9 9 9"] | PASSED | # import sys
# sys.stdout = open('DSA/Stacks/output.txt', 'w')
# sys.stdin = open('DSA/Stacks/input.txt', 'r')
for _ in range(int(input())):
p,a,b,c = map(int, input().split())
zz = [a,b,c]
for i in range(len(zz)):
if p%zz[i]==0:
zz[i]=0
else:
zz[i] = zz[i... | 1614071100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2"] | 4431081cd58c4e0fdc40e55116f5b2e6 | NoteFor the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point. | Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.The girl finds an important permutation for the researc... | Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7). | The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1. It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each... | standard output | standard input | Python 3 | Python | 2,000 | train_037.jsonl | 4de53861104c3b008bcb9bac5a202344 | 256 megabytes | ["5\n-1 -1 4 3 -1"] | PASSED | def fact(x):
ans=1
for i in range(2,x+1):
ans*=i
return ans
n=int(input())
a=[int(x) for x in input().split()]
s=set(a)
x=0
y=0
for i in range(1,n+1):
if a[i-1]==-1:
g=i in s
(x,y)=(x+1-g,y+g)
otv=fact(x+y)
currf=fact(x+y-1)//fact(x-1)*fact(x)
if x:
otv-=curr... | 1377876600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1\n2\n1", "1\n1\n-1\n-1"] | e6ce5b7211a6680ebce5250edfc59e72 | NoteIn the first example there are three queries: query $$$[1; 3]$$$ can be covered by interval $$$[1; 3]$$$; query $$$[1; 4]$$$ can be covered by intervals $$$[1; 3]$$$ and $$$[2; 4]$$$. There is no way to cover $$$[1; 4]$$$ by a single interval; query $$$[3; 4]$$$ can be covered by interval $$$[2; 4]$$$. It doesn'... | You are given $$$n$$$ intervals in form $$$[l; r]$$$ on a number line.You are also given $$$m$$$ queries in form $$$[x; y]$$$. What is the minimal number of intervals you have to take so that every point (not necessarily integer) from $$$x$$$ to $$$y$$$ is covered by at least one of them? If you can't choose intervals ... | Print $$$m$$$ integer numbers. The $$$i$$$-th number should be the answer to the $$$i$$$-th query: either the minimal number of intervals you have to take so that every point (not necessarily integer) from $$$x_i$$$ to $$$y_i$$$ is covered by at least one of them or -1 if you can't choose intervals so that every point ... | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the number of intervals and the number of queries, respectively. Each of the next $$$n$$$ lines contains two integer numbers $$$l_i$$$ and $$$r_i$$$ ($$$0 \le l_i < r_i \le 5 \cdot 10^5$$$) — the given intervals. Each of t... | standard output | standard input | PyPy 2 | Python | 2,200 | train_042.jsonl | 9220c3e1057cd55003561e7e1b6d2f44 | 256 megabytes | ["2 3\n1 3\n2 4\n1 3\n1 4\n3 4", "3 4\n1 3\n1 3\n4 5\n1 2\n1 3\n1 4\n1 5"] | PASSED | from __future__ import division, print_function
DEBUG = 0
import os, sys
from atexit import register
from io import BytesIO
import itertools
if sys.version_info[0] < 3:
input = raw_input
range = xrange
filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip
if DEBUG:
debug_prin... | 1559745300 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["48\n42\n8000000000"] | 9802646ecc8890bb046d5ec1a4262d70 | NoteIn the first test case, Lee should give the greatest integer to the first friend (his happiness will be $$$17 + 17$$$) and remaining integers to the second friend (his happiness will be $$$13 + 1$$$).In the second test case, Lee should give $$$\{10, 10, 11\}$$$ to the first friend and to the second friend, so the t... | Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought $$$n$$$ integers, now it's time to distribute them between his friends rationally...Lee has $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ in his backpack and he has $$$k$$$ friends. Lee would like to distribute all int... | For each test case, print a single integer — the maximum sum of happiness Lee can achieve. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$3t$$$ lines contain test cases — one per three lines. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le k \le n$$$) — the number of integers Lee has... | standard output | standard input | Python 3 | Python | 1,400 | train_005.jsonl | ada7a3a332735f0da833756f037141bf | 256 megabytes | ["3\n4 2\n1 13 7 17\n1 3\n6 2\n10 10 10 10 11 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1"] | PASSED | t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
w = list(map(int, input().split()))
a.sort(reverse = True)
w.sort()
ii = k
l, r = 0, n - 1
ans = 0
for i in range(k):
if w[i] == 1:
ans += a[l] * 2
... | 1592921100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0\n\n2\n2 3 \n1\n1 \n2\n3 4 \n2\n3 4 \n-1"] | a5f496c5cfe471049eddb3a35d0c2d98 | null | You are given a table $$$a$$$ of size $$$2 \times n$$$ (i.e. two rows and $$$n$$$ columns) consisting of integers from $$$1$$$ to $$$n$$$.In one move, you can choose some column $$$j$$$ ($$$1 \le j \le n$$$) and swap values $$$a_{1, j}$$$ and $$$a_{2, j}$$$ in it. Each column can be chosen no more than once.Your task i... | For each test case print the answer: -1 if it is impossible to obtain permutation of size $$$n$$$ in both first and the second rows of the table, or one integer $$$k$$$ in the first line, where $$$k$$$ is the minimum number of moves required to obtain permutations in both rows, and $$$k$$$ distinct integers $$$pos_1, p... | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of columns in the table. The second line of the test case conta... | standard output | standard input | Python 3 | Python | 2,300 | train_050.jsonl | c16d185c19467f10b90d1549512f00a5 | 256 megabytes | ["6\n4\n1 2 3 4\n2 3 1 4\n5\n5 3 5 1 4\n1 2 3 2 4\n3\n1 2 1\n3 3 2\n4\n1 2 2 1\n3 4 3 4\n4\n4 3 1 4\n3 2 2 1\n3\n1 1 2\n3 2 2"] | PASSED | import sys
def input():
return sys.stdin.readline().strip()
def solve():
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
pos = [[] for i in range(n+1)]
for i in range(n):
pos[a[i]].extend((i,0))
pos[b[i]].extend((i,1))
if len(pos[a[i]]) > 4 \
or len(pos[b[i]]) > 4:... | 1594996500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
8 seconds | ["6", "10", "0", "25"] | 256409988d0132de2144e423eaa8bf34 | NoteIn the first sample, all substrings of $$$s$$$ are awesome.In the second sample, we have the following awesome substrings of $$$s$$$: 1 ($$$2$$$ times), 01 ($$$2$$$ times), 10 ($$$2$$$ times), 010 ($$$2$$$ times), 1010, 0101In the third sample, no substring is awesome. | Let's call a binary string $$$s$$$ awesome, if it has at least $$$1$$$ symbol 1 and length of the string is divisible by the number of 1 in it. In particular, 1, 1010, 111 are awesome, but 0, 110, 01010 aren't.You are given a binary string $$$s$$$. Count the number of its awesome substrings.A string $$$a$$$ is a substr... | Output a single number — the number of awesome substrings of $$$s$$$. | The first line contains the string $$$s$$$ ($$$1 \leq |s|\le 200\,000$$$) consisting only of zeros and ones. | standard output | standard input | PyPy 2 | Python | 2,600 | train_014.jsonl | eac131a4fd384f0cb10eecee5cd8d993 | 512 megabytes | ["111", "01010", "0000", "1111100000"] | PASSED | def add(dic, k ,v):
if not k in dic:
dic[k] = v
else:
dic[k] += v
s = map(int,raw_input())
n = len(s)
psum = [0]*(1+n)
for i in range(n):
psum[i+1] = psum[i] + s[i]
K = 350
dic = [0]*((n+1)*(K+1))
ans = 0
for j in range(1,min(n+1,K+1)):
tmp = []
fo... | 1577628300 | [
"math",
"strings"
] | [
0,
0,
0,
1,
0,
0,
1,
0
] | |
1 second | ["<", "=", ">"] | 7c0a288a2777894bdfd75cb9703346e9 | NoteIn the first example first number equals to , while second number is approximately 1.6180339882 + 1.618033988 + 1 ≈ 5.236, which is clearly a bigger number.In the second example numbers are equal. Each of them is ≈ 2.618. | Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number , in particular that q2 = q + 1, and she thinks it would make a good base for her new unique system. She called it "golden system". In golden system the number is a non-empty... | Print ">" if the first number is larger, "<" if it is smaller and "=" if they are equal. | Input consists of two lines — one for each number. Each line contains non-empty string consisting of '0' and '1' characters. The length of each string does not exceed 100000. | standard output | standard input | Python 3 | Python | 1,700 | train_049.jsonl | c215083cb49a3201466d305036461618 | 256 megabytes | ["1000\n111", "00100\n11", "110\n101"] | PASSED | from itertools import dropwhile, chain
def main():
zeroes = lambda a: not a
a, b = [list(chain([0, 0], dropwhile(zeroes, map(int, input()))))
for _ in range(2)]
def tofib(l):
i = 0
while i < len(l) - 1:
if l[i] > 0 and l[i + 1] > 0:
l[i] -= 1
... | 1407690000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES"] | d8a5578de51d6585d434516da6222204 | NoteOn the picture below, the two polygons are well-connected, as the edges of the vertical polygon cross the area of the horizontal one exactly once in one direction (for example, from above to below), and zero times in the other (in this case, from below to above). Note that the polygons do not have to be parallel to... | Cowboy Beblop is a funny little boy who likes sitting at his computer. He somehow obtained two elastic hoops in the shape of 2D polygons, which are not necessarily convex. Since there's no gravity on his spaceship, the hoops are standing still in the air. Since the hoops are very elastic, Cowboy Beblop can stretch, rot... | Your output should contain only one line, with the words "YES" or "NO", depending on whether the two given polygons are well-connected. | The first line of input contains an integer n (3 ≤ n ≤ 100 000), which denotes the number of edges of the first polygon. The next N lines each contain the integers x, y and z ( - 1 000 000 ≤ x, y, z ≤ 1 000 000) — coordinates of the vertices, in the manner mentioned above. The next line contains an integer m (3 ≤ m ≤ 1... | standard output | standard input | PyPy 3 | Python | 2,800 | train_006.jsonl | f53ddde251732f334ce1b246b608a19b | 256 megabytes | ["4\n0 0 0\n2 0 0\n2 2 0\n0 2 0\n4\n1 1 -1\n1 1 1\n1 3 1\n1 3 -1"] | PASSED | from math import gcd, sqrt
from functools import reduce
import sys
input = sys.stdin.readline
EPS = 0.000000001
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def GCD(args):
return reduce(gcd, args)
def plane_value(plane, point):
A, B, C, D = plane
x, y, z =... | 1473584400 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["5", "42"] | bd6f4859e3c3ce19b8e89c431f2e65fb | NoteIn the first example Yura needs to reach $$$(5, 5)$$$ from $$$(1, 1)$$$. He can do that in $$$5$$$ minutes by first using the second instant-movement location (because its $$$y$$$ coordinate is equal to Yura's $$$y$$$ coordinate), and then walking $$$(4, 1) \to (4, 2) \to (4, 3) \to (5, 3) \to (5, 4) \to (5, 5)$$$. | Yura has been walking for some time already and is planning to return home. He needs to get home as fast as possible. To do this, Yura can use the instant-movement locations around the city.Let's represent the city as an area of $$$n \times n$$$ square blocks. Yura needs to move from the block with coordinates $$$(s_x,... | In the only line print the minimum time required to get home. | The first line contains two integers $$$n$$$ and $$$m$$$ — the size of the city and the number of instant-movement locations ($$$1 \le n \le 10^9$$$, $$$0 \le m \le 10^5$$$). The next line contains four integers $$$s_x$$$ $$$s_y$$$ $$$f_x$$$ $$$f_y$$$ — the coordinates of Yura's initial position and the coordinates of ... | standard output | standard input | Python 3 | Python | 2,300 | train_009.jsonl | 79447fe19beac92ac0d84869bcf86286 | 256 megabytes | ["5 3\n1 1 5 5\n1 2\n4 1\n3 3", "84 5\n67 59 41 2\n39 56\n7 2\n15 3\n74 18\n22 7"] | PASSED | import heapq
def main():
n, m = map(int, input().split())
sx, sy, fx, fy = map(int, input().split())
sub = [0]*(m+2)
sub[0] = (sx,sy)
dx = []
dy = []
for i in range(m):
x, y = map(int, input().split())
dx.append((x, i+1))
dy.append((y, i+1))
sub[i+1] = (x,... | 1601827500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1 2\n1 3\n3 4\n3 5", "-1", "4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5"] | 32096eff277f19d227bccca1b6afc458 | NoteBelow you can see trees printed to the output in the first sample and the third sample. | A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n.Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell you only th... | If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes). Otherwise, describe any tree matching Limak's description. Print n - 1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. You ca... | The first line contains three integers n, d and h (2 ≤ n ≤ 100 000, 1 ≤ h ≤ d ≤ n - 1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively. | standard output | standard input | Python 3 | Python | 1,600 | train_019.jsonl | c325132c06f85f853cb09ef544992323 | 256 megabytes | ["5 3 2", "8 5 2", "8 4 2"] | PASSED | def solve(n,d,h) :
if n<d+1 :
return False
if d>2*h :
return False
if d-h<0 :
return False
if d==1 and n>=3 :
return False
cnt=1
h0=d-h
for i in range(h) :
print(cnt,cnt+1)
cnt+=1
if h0 :
print(1,cnt+1)
cnt+=1
for i... | 1459182900 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["0.500000000000000", "0.833333333333333"] | ad4bdd6cee78cbcd357e048cd342a42b | null | In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the simplest form of the law).Having read about it on Codeforces, the Hedgehog ... | Print the required probability. Print the fractional number with such a precision that the relative or absolute error of the result won't exceed 10 - 9. | The first line contains number N which is the number of random variables (1 ≤ N ≤ 1000). Then follow N lines containing pairs of numbers Li, Ri, each of whom is a description of a random variable. It is guaranteed that 1 ≤ Li ≤ Ri ≤ 1018. The last line contains an integer K (0 ≤ K ≤ 100). All the numbers in the input f... | standard output | standard input | Python 3 | Python | 2,000 | train_080.jsonl | f6959f7bf197695ef58db5865880688a | 256 megabytes | ["1\n1 2\n50", "2\n1 2\n9 11\n50"] | PASSED | import math
def get_count(x):
if x == 0:
return 0
y = 10 ** (len(str(x)) - 1)
d = x // y
if d == 1:
count = x - y + 1
else:
count = y
#print(x, math.log10(x), int(math.log10(x)), y, d, count)
while y > 1:
y //= 10
count += y
#print('get_count(%d) ... | 1294733700 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
1 second | ["4", "4"] | d03ad531630cbecc43f8da53b02d842e | NoteIn the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylo... | Print a single number representing the minimum number of dollars paid by Caisa. | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 105) representing the heights of the pylons. | standard output | standard input | PyPy 3 | Python | 1,100 | train_019.jsonl | bded34133e5ceca245328945d41c647c | 256 megabytes | ["5\n3 4 3 2 4", "3\n4 4 4"] | PASSED | import math
import sys
#imgur.com/Pkt7iIf.png
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
n = ii()
print(max(li()))
| 1409383800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["7\n9\n6"] | 07eecfe948aa78623586b5e30e84e415 | null | You are given a string $$$s$$$ consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode: res = 0for init = 0 to inf cur = init ok = true for i = 1 to |s| res = res + 1 if s[i] == '+' cur = cur + 1 ... | For each test case print one integer — the value of the $$$res$$$ after the process ends. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The only lines of each test case contains string $$$s$$$ ($$$1 \le |s| \le 10^6$$$) consisting only of characters + and -. It's guaranteed that sum of $$$|s|$$$ over all test cases doesn't exceed $$$10^6$$$. | standard output | standard input | PyPy 3 | Python | 1,300 | train_028.jsonl | 75425791a6d2f4e6319a22315e7f18ec | 256 megabytes | ["3\n--+-\n---\n++--+-"] | PASSED | #!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
... | 1593095700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["8\n5\n11880\n351025663"] | 5f44c5eed653c150476b7fc6fa5d373b | NoteIn the first test case, the following $$$8$$$ arrays satisfy the conditions from the statement: $$$[1,2,1]$$$; $$$[1,2,2]$$$; $$$[1,3,1]$$$; $$$[1,3,2]$$$; $$$[1,3,3]$$$; $$$[2,3,1]$$$; $$$[2,3,2]$$$; $$$[2,3,3]$$$. In the second test case, the following $$$5$$$ arrays satisfy the conditions from the state... | The position of the leftmost maximum on the segment $$$[l; r]$$$ of array $$$x = [x_1, x_2, \ldots, x_n]$$$ is the smallest integer $$$i$$$ such that $$$l \le i \le r$$$ and $$$x_i = \max(x_l, x_{l+1}, \ldots, x_r)$$$.You are given an array $$$a = [a_1, a_2, \ldots, a_n]$$$ of length $$$n$$$. Find the number of integer... | For each test case print one integer — the number of arrays $$$b$$$ that satisfy the conditions from the statement, modulo $$$10^9+7$$$. | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n,m \le 2 \cdot 10^5$$$, $$$n \cdot m \le 10^6$$$). The second line of each test case contain... | standard output | standard input | PyPy 3-64 | Python | 2,300 | train_083.jsonl | df6622606291bb3cdc8dc4e9889fdf3a | 512 megabytes | ["4\n\n3 3\n\n1 3 2\n\n4 2\n\n2 2 2 2\n\n6 9\n\n6 9 6 9 6 9\n\n9 100\n\n10 40 20 20 100 60 80 60 60"] | PASSED | import sys
def solve():
inp = sys.stdin.readline
n, m = map(int, inp().split())
g = [[] for i in range(n + 1)]
ginv = [[] for i in range(n + 1)]
idx = 0
st = []
for v in map(int, inp().split()):
while st:
pv, pidx = st[-1]
if pv < v:
... | 1668263700 | [
"math",
"trees"
] | [
0,
0,
0,
1,
0,
0,
0,
1
] | |
1 second | ["2 5 11 18 30 43 62 83 121", "7"] | af8ac55aa2594350226653c8d5ff47e4 | NoteLet's analyze the answer for $$$k = 5$$$ in the first example. Here is one of the possible ways to eat $$$5$$$ sweets that minimize total sugar penalty: Day $$$1$$$: sweets $$$1$$$ and $$$4$$$ Day $$$2$$$: sweets $$$5$$$ and $$$3$$$ Day $$$3$$$ : sweet $$$6$$$ Total penalty is $$$1 \cdot a_1 + 1 \cdot a_4 + 2 \c... | Tsumugi brought $$$n$$$ delicious sweets to the Light Music Club. They are numbered from $$$1$$$ to $$$n$$$, where the $$$i$$$-th sweet has a sugar concentration described by an integer $$$a_i$$$.Yui loves sweets, but she can eat at most $$$m$$$ sweets each day for health reasons.Days are $$$1$$$-indexed (numbered $$$1... | You have to output $$$n$$$ integers $$$x_1, x_2, \ldots, x_n$$$ on a single line, separed by spaces, where $$$x_k$$$ is the minimum total sugar penalty Yui can get if she eats exactly $$$k$$$ sweets. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le m \le n \le 200\ 000$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 200\ 000$$$). | standard output | standard input | Python 3 | Python | 1,500 | train_007.jsonl | e571db87ee73c7a7563865e8b493ed29 | 256 megabytes | ["9 2\n6 19 3 4 4 2 6 7 8", "1 1\n7"] | PASSED | t=lambda:map(int,input().split())
n,m=t()
a=sorted(t())
x,s=[0]*n,0
for i in range(n):s+=a[i];x[i]=s if i<m else s+x[i-m]
print(*x) | 1573914900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\n1 2 1", "YES\n2 3 2 1 2"] | f097cc7057bb9a6b9fc1d2a11ee99835 | null | Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from $$$1$$$ to $$$n$$$. Each of its vertices also has an integer $$$a_i$$$ written on it. For each vertex $$$i$$$, Evlampiy calculated $$$c_i$$$ — the number of vertices $$$j$$$ in the subtree of vertex $$$i$$$, such that $$$a_j < a_i$$$. Illu... | If a solution exists, in the first line print "YES", and in the second line output $$$n$$$ integers $$$a_i$$$ $$$(1 \leq a_i \leq {10}^{9})$$$. If there are several solutions, output any of them. One can prove that if there is a solution, then there is also a solution in which all $$$a_i$$$ are between $$$1$$$ and $$$1... | The first line contains an integer $$$n$$$ $$$(1 \leq n \leq 2000)$$$ — the number of vertices in the tree. The next $$$n$$$ lines contain descriptions of vertices: the $$$i$$$-th line contains two integers $$$p_i$$$ and $$$c_i$$$ ($$$0 \leq p_i \leq n$$$; $$$0 \leq c_i \leq n-1$$$), where $$$p_i$$$ is the parent of ve... | standard output | standard input | Python 3 | Python | 1,800 | train_005.jsonl | e90e7a54127337b2cce02c51de519a8e | 256 megabytes | ["3\n2 0\n0 2\n2 0", "5\n0 1\n1 3\n2 1\n3 0\n2 0"] | PASSED | # https://codeforces.com/contest/1287/problem/D
def push(g, u, v):
if u not in g:
g[u] = []
g[u].append(v)
def build():
S = [root]
i = 0
order = {}
while i < len(S):
u = S[i]
if u in g:
for v in g[u]:
S.append(v)
... | 1578233100 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
4 seconds | ["0\n1 2 3 4 5\n2\n2 2\n1\n3 11\n3\n3 1 1 1"] | 4d0b2fe22b4870b15d63e9fb778bcb7b | NoteIn the first test case, the graph is already connected.In the second test case, we can increment $$$0$$$ twice and end up with the array $$$[2,2]$$$. Since $$$2 \& 2 = 2 > 0$$$, the graph is connected. It can be shown that one operation is not enough.In the third test case, we can decrement $$$12$$$ once and... | Bit Lightyear, to the ANDfinity and beyond!After graduating from computer sciences, Vlad has been awarded an array $$$a_1,a_2,\ldots,a_n$$$ of $$$n$$$ non-negative integers. As it is natural, he wanted to construct a graph consisting of $$$n$$$ vertices, numbered $$$1, 2,\ldots, n$$$. He decided to add an edge between ... | For each test case, print a single integer $$$m$$$ in the first line — the minimum number of operations. In the second line print the array after a valid sequence of operations that have been done such that the graph from the task becomes connected. If there are multiple solutions, output any. | There are several test cases in the input data. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. This is followed by the test cases description. The first line of each test case contains an integer $$$n$$$ ($$$2\leq n \leq 2000$$$). The second line of each test ca... | standard output | standard input | Python 3 | Python | 2,500 | train_096.jsonl | e8cf0e97abc4c680abd130f3f84b3031 | 256 megabytes | ["4\n5\n1 2 3 4 5\n2\n0 2\n2\n3 12\n4\n3 0 0 0"] | PASSED | from collections import deque
def connected(n, arr):
g = [[] for i in range(n)]
for k in range(30):
ind = []
for i, a in enumerate(arr):
if a&(1<<k):
ind.append(i)
if len(ind) > 1:
a = ind.pop()
for i in ind:
... | 1654878900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["3", "4"] | 18cf79b50d0a389e6c3afd5d2f6bd9ed | NoteIn the first example the citizens on the square $$$1$$$ can split into two groups $$$2 + 1$$$, so that the second and on the third squares will have $$$3$$$ citizens each.In the second example no matter how citizens act the bandit can catch at least $$$4$$$ citizens. | Bandits appeared in the city! One of them is trying to catch as many citizens as he can.The city consists of $$$n$$$ squares connected by $$$n-1$$$ roads in such a way that it is possible to reach any square from any other square. The square number $$$1$$$ is the main square.After Sunday walk all the roads were changed... | Print a single integer — the number of citizens the bandit will catch if both sides act optimally. | The first line contains a single integer $$$n$$$ — the number of squares in the city ($$$2 \le n \le 2\cdot10^5$$$). The second line contains $$$n-1$$$ integers $$$p_2, p_3 \dots p_n$$$ meaning that there is a one-way road from the square $$$p_i$$$ to the square $$$i$$$ ($$$1 \le p_i < i$$$). The third line contain... | standard output | standard input | Python 3 | Python | 1,900 | train_004.jsonl | 4ed9a34f0cfd404a03c54d6e1c00ade1 | 256 megabytes | ["3\n1 1\n3 1 2", "3\n1 1\n3 1 3"] | PASSED | n = int(input())
p = list(map(int, input().split()))
a = list(map(int, input().split()))
tree = {}
for i, pp in enumerate(p, start=2):
tree.setdefault(pp, []).append(i)
cache = {}
for s in range(n, 0, -1):
children = tree.get(s, [])
if len(children) == 0:
cache[s] = (a[s - 1], a[s - 1], 1)
... | 1603548300 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["3", "4"] | 1a37e42263fdd1cb62e2a18313eed989 | NoteIn the first example, one of the ways to perform maximum number of operations on the array is: Pick $$$i = 1, j= 5$$$ and add $$$\gcd(a_1, a_5) = \gcd(4, 30) = 2$$$ to the array. Pick $$$i = 2, j= 4$$$ and add $$$\gcd(a_2, a_4) = \gcd(20, 25) = 5$$$ to the array. Pick $$$i = 2, j= 5$$$ and add $$$\gcd(a_2, a_5)... | You have an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. You are allowed to perform the following operation on it: Choose two elements from the array $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$) such that $$$\gcd(a_i, a_j)$$$ is not present in the array, and add $$$\gcd(a_i, a_j)$$$ to the end ... | Output a single line containing one integer — the maximum number of times the operation can be performed on the given array. | The first line consists of a single integer $$$n$$$ ($$$2 \le n \le 10^6$$$). The second line consists of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^6$$$). All $$$a_i$$$ are distinct. | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_109.jsonl | d218548d1bade7ce888cb18780fea4f5 | 256 megabytes | ["5\n4 20 1 25 30", "3\n6 10 15"] | PASSED | # import sys, os
# if not os.environ.get("ONLINE_JUDGE"):
# sys.stdin = open('in.txt', 'r')
# sys.stdout = open('out.txt', 'w')
import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import math
n = int(input())
arr = list(map(int, input().split()))
m = max(arr... | 1642257300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["10 9 3 4", "6 5 4 3 2 3 3 1 1 3 2 2 1 2 3"] | fe01ddb5bd5ef534a6a568adaf738151 | null | You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour.Let's call colour c dominating in the subtree of vertex v if there are no other colours that appear in the subtree of vertex v more times than colour c. So it's possible that two or more colours will be dominating in the subtree o... | Print n integers — the sums of dominating colours for each vertex. | The first line contains integer n (1 ≤ n ≤ 105) — the number of vertices in the tree. The second line contains n integers ci (1 ≤ ci ≤ n), ci — the colour of the i-th vertex. Each of the next n - 1 lines contains two integers xj, yj (1 ≤ xj, yj ≤ n) — the edge of the tree. The first vertex is the root of the tree. | standard output | standard input | PyPy 3 | Python | 2,300 | train_004.jsonl | e4aa09f18c3693b7eb68dddcffdd421a | 256 megabytes | ["4\n1 2 3 4\n1 2\n2 3\n2 4", "15\n1 2 3 1 2 3 3 1 1 3 2 2 1 2 3\n1 2\n1 3\n1 4\n1 14\n1 15\n2 5\n2 6\n2 7\n3 8\n3 9\n3 10\n4 11\n4 12\n4 13"] | PASSED | def main():
import sys
from collections import deque
input = sys.stdin.readline
N = int(input())
color = list(map(int, input().split()))
color.insert(0, 0)
adj = [[] for _ in range(N+1)]
for _ in range(N-1):
a, b = map(int, input().split())
adj[a].append(b)
adj[b... | 1448636400 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["0\n0\n1\n1\n0\n0\n2"] | 803e5ccae683b91a4cc486fbc558b330 | NoteIn test cases $$$1$$$, $$$2$$$, $$$5$$$, $$$6$$$ no operations are required since they are already good strings.For the $$$3$$$rd test case: "001" can be achieved by flipping the first character — and is one of the possible ways to get a good string.For the $$$4$$$th test case: "000" can be achieved by flipping th... | Shubham has a binary string $$$s$$$. A binary string is a string containing only characters "0" and "1".He can perform the following operation on the string any amount of times: Select an index of the string, and flip the character at that index. This means, if the character was "0", it becomes "1", and vice versa. A... | For every string, output the minimum number of operations required to make it good. | The first line of the input contains a single integer $$$t$$$ $$$(1\le t \le 100)$$$ — the number of test cases. Each of the next $$$t$$$ lines contains a binary string $$$s$$$ $$$(1 \le |s| \le 1000)$$$. | standard output | standard input | PyPy 2 | Python | 1,400 | train_019.jsonl | a0f8f3d61643e5f9d4b4bed4dbec1a66 | 256 megabytes | ["7\n001\n100\n101\n010\n0\n1\n001100"] | PASSED | T = input()
for _ in xrange(T):
s = raw_input()
soms = [[0, 0]]
for elem in s:
zc, oc = soms[-1]
if elem == "1":
soms.append([zc, oc+1])
else:
soms.append([zc+1, oc])
#print s
#print soms
result = None
for i in xrange(len(s)+1):
lz,... | 1590935700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["2\n99\n1"] | 1fd2619aabf4557093a59da804fd0e7b | NoteIn the first test case you can swap students in positions $$$3$$$ and $$$4$$$. And then the distance between the rivals is equal to $$$|4 - 2| = 2$$$.In the second test case you don't have to swap students. In the third test case you can't swap students. | You are the gym teacher in the school.There are $$$n$$$ students in the row. And there are two rivalling students among them. The first one is in position $$$a$$$, the second in position $$$b$$$. Positions are numbered from $$$1$$$ to $$$n$$$ from left to right.Since they are rivals, you want to maximize the distance b... | For each test case print one integer — the maximum distance between two rivaling students which you can obtain. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The only line of each test case contains four integers $$$n$$$, $$$x$$$, $$$a$$$ and $$$b$$$ ($$$2 \le n \le 100$$$, $$$0 \le x \le 100$$$, $$$1 \le a, b \le n$$$, $$$a \neq b$$$) — the number of students in the row, the num... | standard output | standard input | Python 3 | Python | 800 | train_019.jsonl | acdd5dfab732a98bdf3eeff97f3b2c4d | 256 megabytes | ["3\n5 1 3 2\n100 33 100 1\n6 0 2 3"] | PASSED | for i in range(int(input())):
n,x,a,b=map(int,input().split())
if(((min(a,b)-1)+(n-max(a,b)))>=x):
print(max(a,b)-min(a,b)+x)
else:
print(n-1)
| 1573655700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3 abc\n2 bc\n1 c\n0 \n1 d", "18 abbcd...tw\n17 bbcdd...tw\n16 bcddd...tw\n15 cddde...tw\n14 dddea...tw\n13 ddeaa...tw\n12 deaad...tw\n11 eaadf...tw\n10 aadfortytw\n9 adfortytw\n8 dfortytw\n9 fdfortytw\n8 dfortytw\n7 fortytw\n6 ortytw\n5 rtytw\n6 urtytw\n5 rtytw\n4 tytw\n3 ytw\n2 tw\n1 w\n0 \n1 o"] | 7d6faccc88a6839822fa0c0ec8c00251 | NoteConsider the first example. The longest suffix is the whole string "abcdd". Choosing one pair $$$(4, 5)$$$, Lesha obtains "abc". The next longest suffix is "bcdd". Choosing one pair $$$(3, 4)$$$, we obtain "bc". The next longest suffix is "cdd". Choosing one pair $$$(2, 3)$$$, we obtain "c". The next longest su... | Some time ago Lesha found an entertaining string $$$s$$$ consisting of lowercase English letters. Lesha immediately developed an unique algorithm for this string and shared it with you. The algorithm is as follows.Lesha chooses an arbitrary (possibly zero) number of pairs on positions $$$(i, i + 1)$$$ in such a way tha... | In $$$|s|$$$ lines print the lengths of the answers and the answers themselves, starting with the answer for the longest suffix. The output can be large, so, when some answer is longer than $$$10$$$ characters, instead print the first $$$5$$$ characters, then "...", then the last $$$2$$$ characters of the answer. | The only line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$) — the initial string consisting of lowercase English letters only. | standard output | standard input | Python 3 | Python | 2,700 | train_011.jsonl | 00750c7d58b33d3ac03785c4a39a4ff9 | 256 megabytes | ["abcdd", "abbcdddeaaffdfouurtytwoo"] | PASSED | s = input().strip();N = len(s)
if len(s) == 1:print(1, s[0]);exit()
X = [s[-1], s[-2]+s[-1] if s[-2]!=s[-1] else ""];Y = [1, 2 if s[-2]!=s[-1] else 0]
for i in range(N-3, -1, -1):
c = s[i];k1 = c+X[-1];ng = Y[-1]+1
if ng > 10:k1 = k1[:5] + "..." + k1[-2:]
if c == s[i+1] and k1 > X[-2]:k1 = X[-2];ng = Y[-2]
... | 1601827500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["YES\nNO\nYES"] | 6639e9a289fa76e3aae6f309ab26c049 | NoteIn the first query Alice can select substring $$$s_3 \dots s_5$$$. After that $$$s$$$ turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move.In the second query Alice can not win because she cannot even make on... | Alice and Bob play a game. Initially they have a string $$$s_1, s_2, \dots, s_n$$$, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice mus... | For each test case print YES if Alice can win and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | The first line contains one integer $$$q$$$ ($$$1 \le q \le 3 \cdot 10^5$$$) — the number of queries. The first line of each query contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le b < a \le 3 \cdot 10^5$$$). The second line of each query contains the string $$$s$$$ ($$$1 \le |s| \le 3 \cdot 10^5$$$), consisting o... | standard output | standard input | PyPy 2 | Python | 2,500 | train_003.jsonl | 12ee1594ca82caccae9911559ccebde1 | 256 megabytes | ["3\n3 2\nXX......XX...X\n4 2\nX...X.X..X\n5 3\n.......X..X"] | PASSED | import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
q = int(input())
for _ in range(q):
a,b = map(int ,input().spli... | 1568903700 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["30021", "3036366999"] | 5c3cec98676675355bb870d818704be6 | null | Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n. Magically, all the numbers were shuffled in arbitrary order while this note was passed to Kate. The only thing that Vasya remembers, is a non-empty substrin... | Print the smalles integer n which Vasya could pass to Kate. | The first line of the input contains the string received by Kate. The number of digits in this string does not exceed 1 000 000. The second line contains the substring of n which Vasya remembers. This string can contain leading zeroes. It is guaranteed that the input data is correct, and the answer always exists. | standard output | standard input | Python 3 | Python | 2,300 | train_008.jsonl | f212734180961a1b67416873754493c6 | 256 megabytes | ["003512\n021", "199966633300\n63"] | PASSED | import sys
def main():
a = sys.stdin.readline().strip()
b = sys.stdin.readline().strip()
if a == "01" or a == "10":
print("0")
return
cnt = [0] * 256
for i in map(ord, a):
cnt[i] += 1
n = sum(cnt)
l = 0
for i in range(1, 8):
if i == len(str(n - i)):
... | 1462464300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["524848", "121", "-1"] | 206eb67987088843ef42923b0c3939d4 | null | Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by V... | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105). | standard output | standard input | Python 3 | Python | 1,400 | train_006.jsonl | a2090b0a897a64a03cfff88931c197ba | 256 megabytes | ["5 4 5", "12 11 1", "260 150 10"] | PASSED | '''
260A
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is d... | 1356622500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\n-1\n3"] | c2f3d09674190f90c940f134c3e22afe | NoteConsider the first test case. In the substring "aa", 'a' occurs twice, while 'b' and 'c' occur zero times. Since 'a' occurs strictly more times than 'b' and 'c', the substring "aa" satisfies the condition and the answer is $$$2$$$. The substring "a" also satisfies this condition, however its length is not at least ... | Ashish has a string $$$s$$$ of length $$$n$$$ containing only characters 'a', 'b' and 'c'.He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $$$2$$$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more ti... | For each test case, output the length of the smallest substring which satisfies the given conditions or print $$$-1$$$ if there is no such substring. | The first line contains a single integer $$$t$$$ $$$(1 \le t \le 10^{5})$$$ — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ $$$(2 \le n \le 10^{6})$$$ — the length of the string $$$s$$$. The second line of each test case contains a ... | standard output | standard input | PyPy 3-64 | Python | 1,400 | train_097.jsonl | e850887386580646915532098e6222ed | 256 megabytes | ["3\n2\naa\n5\ncbabb\n8\ncacabccc"] | PASSED | t = int(input())
for case in range(t):
n = int(input())
s = input()
ans = -1
tests = ['aa', 'aba', 'aca', 'abca', 'acba', 'abbacca', 'accabba']
for i in tests:
if i in s:
ans = len(i)
break
print(ans) | 1636727700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["11", "2", "0"] | b267f69cc4af3e319fc59e3ccd8b1c9d | NoteIn the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$. Then the string was changed as follows:«01000» $$$\to$$$ «10000» $$$\to$$$ «11111».The total cost of operations is $$$1 + 10 = 11$$$.In the second sample, at first you need to inve... | You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones.Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$. You can apply the following operations any number of times: Choose some substring of string $$$a$$$ (fo... | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations. | The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $$$a$$$ of leng... | standard output | standard input | PyPy 3 | Python | 1,500 | train_011.jsonl | e44565c5ca3a2d9439e794034a467582 | 256 megabytes | ["5 1 10\n01000", "5 10 1\n01000", "7 2 3\n1111111"] | PASSED | n, x, y = map(int, input().split())
s = input()
i, intervals = 0, 0
while i < n:
j = i
if s[i] == '0':
curr_len = 0
while j < n and s[j] == '0':
j += 1
curr_len += 1
intervals += 1
i = j + 1
if intervals == 0:
print(intervals)
else:
print(min(interval... | 1530453900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2\n2.0000000000\n3.0000000000"] | 84372885f2263004b74ae753a2f358ac | null | You are given an equation: Ax2 + Bx + C = 0. Your task is to find the number of distinct roots of the equation and print all of them in ascending order. | In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point. | The first line contains three integer numbers A, B and C ( - 105 ≤ A, B, C ≤ 105). Any coefficient may be equal to 0. | standard output | standard input | PyPy 3 | Python | 2,000 | train_001.jsonl | a1d827a7a3476ced8d289ac0adb442af | 256 megabytes | ["1 -5 6"] | PASSED | import math
a, b, c = map(int, input().split())
delta = (b*b) - (4*a*c)
# print(delta)
if delta < 0:
print("0")
# elif a+b+c == 0:
# print("-1")
else:
if a != 0:
x1 = (-b + math.sqrt(delta))/(a*2)
x2 = (-b - math.sqrt(delta))/(a*2)
if delta == 0:
print("1")
p... | 1276875000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1\n2\n1"] | 1f80d1b61d76ba7725b6e4208a4f735e | NoteIn the first test case it is possible to change the array this way: $$$[\underline{3}, 6, 2, 4, \underline{5}]$$$ (changed elements are underlined). After that the array does not need to be divided, so the answer is $$$1$$$.In the second test case it is possible to change the array this way: $$$[6, 2, \underline{3}... | This is the hard version of the problem. The only difference is that in this version $$$0 \leq k \leq 20$$$.There is an array $$$a_1, a_2, \ldots, a_n$$$ of $$$n$$$ positive integers. You should divide it into a minimal number of continuous segments, such that in each segment there are no two numbers (on different posi... | For each test case print a single integer — the answer to the problem. | The first line contains a single integer $$$t$$$ $$$(1 \le t \le 1000)$$$ — the number of test cases. The first line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \leq k \leq 20$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$... | standard output | standard input | PyPy 3 | Python | 2,500 | train_087.jsonl | 36e89991f9cd8a8aa62454e19673e22a | 256 megabytes | ["3\n\n5 2\n\n18 6 2 4 1\n\n11 4\n\n6 2 2 8 9 1 3 6 3 9 7\n\n1 0\n\n1"] | PASSED | import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from math import sqrt,ceil
max_n=10**7+1
spf = [i for i in range(max_n)]
for i in range(4,max_n,2):
spf[i]=2
for i in range(3,ceil(sqrt(max_n))):
if (spf[i]==i):
for j in range(i*i,max_n,i):
... | 1615991700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["YES\n3 1 3 \nYES\n1 \nNO\nYES\n5 5 4 1 4 5"] | 21fed74be8462143d77bbbee48dc8a12 | NoteLet's consider the $$$1$$$-st test case of the example: the $$$1$$$-st singer in the $$$1$$$-st city will give a concert for $$$3$$$ minutes, in the $$$2$$$-nd — for $$$6$$$ minutes, in the $$$3$$$-rd — for $$$9$$$ minutes; the $$$2$$$-nd singer in the $$$1$$$-st city will give a concert for $$$3$$$ minutes, in t... | $$$n$$$ towns are arranged in a circle sequentially. The towns are numbered from $$$1$$$ to $$$n$$$ in clockwise order. In the $$$i$$$-th town, there lives a singer with a repertoire of $$$a_i$$$ minutes for each $$$i \in [1, n]$$$.Each singer visited all $$$n$$$ towns in clockwise order, starting with the town he live... | For each test case, print the answer as follows: If there is no suitable sequence $$$a$$$, print NO. Otherwise, on the first line print YES, on the next line print the sequence $$$a_1, a_2, \dots, a_n$$$ of $$$n$$$ integers, where $$$a_i$$$ ($$$1 \le a_i \le 10^{9}$$$) is the initial duration of repertoire of the $$$i$... | The first line contains one integer $$$t$$$ $$$(1 \le t \le 10^3$$$) — the number of test cases. Then the test cases follow. Each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \le n \le 4 \cdot 10^4$$$) — the number of cities. The second line contains $$$n$$$ integers $$$b_1, b... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_087.jsonl | e1efd267d1b30eda865bed7b68fd0687 | 256 megabytes | ["4\n3\n12 16 14\n1\n1\n3\n1 2 3\n6\n81 75 75 93 93 87"] | PASSED | '''import requests
import leaf
import pandas as pd
dict = {'Авиастроительный': 'https://edu.tatar.ru/aviastroit/type/1',
'Вахитовский': 'https://edu.tatar.ru/vahit/type/1',
'Кировский':'https://edu.tatar.ru/kirov/type/1',
'Московский':'https://edu.tatar.ru/moskow/type/1',
'Ново-... | 1639492500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nYES\nNO\nYES\nNO"] | ff95cd4632b2ddf8bb54981634badcae | NoteThe first test case is shown in the statement.In the second test case, we transform $$$a$$$ into $$$b$$$ by using zero operations.In the third test case, there is no legal operation, so it is impossible to transform $$$a$$$ into $$$b$$$.In the fourth test case, here is one such transformation: Select the length $... | There is a binary string $$$a$$$ of length $$$n$$$. In one operation, you can select any prefix of $$$a$$$ with an equal number of $$$0$$$ and $$$1$$$ symbols. Then all symbols in the prefix are inverted: each $$$0$$$ becomes $$$1$$$ and each $$$1$$$ becomes $$$0$$$.For example, suppose $$$a=0111010000$$$. In the fir... | For each test case, output "YES" if it is possible to transform $$$a$$$ into $$$b$$$, or "NO" if it is impossible. You can print each letter in any case (upper or lower). | 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$$$ ($$$1\le n\le 3\cdot 10^5$$$) — the length of the strings $$$a$$$ and $$$b$$$. The following two lines contain strings $$$a$$$ and $$$b$$$ of length $$$n... | standard output | standard input | PyPy 3-64 | Python | 1,200 | train_100.jsonl | b8c56965606eb0ef9b60e3748f4dff4b | 256 megabytes | ["5\n10\n0111010000\n0100101100\n4\n0000\n0000\n3\n001\n000\n12\n010101010101\n100110011010\n6\n000111\n110100"] | PASSED | import math
import string
def main_function():
test_cases = range(int(input()))
answers = []
for test_case in test_cases:
n = int(input())
equal_counter = 0
s_1 = list(input())
s_2 = list(input())
for i in range(n):
j = n - 1 - i
... | 1617460500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["NO", "YES", "YES", "NO"] | 8b61213e2ce76b938aa68ffd1e4c1429 | NoteIn the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. | The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessary to determine whether there is at least one point of intersection of two of these lines,... | Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes). | The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x1 and x2 ( - 1 000 000 ≤ x1 < x2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines. The following n lines ... | standard output | standard input | Python 2 | Python | 1,600 | train_007.jsonl | e3947f6b1ab23bbd5aad75badaac0902 | 256 megabytes | ["4\n1 2\n1 2\n1 0\n0 1\n0 2", "2\n1 3\n1 0\n-1 3", "2\n1 3\n1 0\n0 2", "2\n1 3\n1 0\n0 3"] | PASSED | # -*- coding: utf-8 -*-
from operator import itemgetter
n = int(raw_input())
x1, x2 = map(int, raw_input().split(' '))
x1 += 0.0000001
x2 -= 0.0000001
k = []
b = []
positive = False
starts, ends = [], []
for i in xrange(n):
new_k, new_b = map(int, raw_input().split(' '))
starts.append({
'index': i,
... | 1446655500 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
1 second | ["HelloVKCup2017", "7uduGUDUUDUgudu7"] | d6f01ece3f251b7aac74bf3fd8231a80 | null | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in ... | Print the text if the same keys were pressed in the second layout. | The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and u... | standard output | standard input | Python 3 | Python | 800 | train_010.jsonl | 58b311fd628bb8c2ea62905e3a5cdb8b | 256 megabytes | ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7"] | PASSED | a=input()
b=input()
c=input()
f=""
for i in c:
if(ord(i)>=65):
for j in range(len(a)):
if(i.lower()==a[j]):
if(i.isupper()):
f+=b[j].upper()
else:
f+=b[j]
else:
f+=i
print(f) | 1499958300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["YES", "NO", "YES"] | f110b9351fe8ff20676d11ecfc92aee3 | NoteIn the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he's a traitor, then all members of this group are traitors and so Summer should cancel the event. | Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one M... | In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise. | The first line of input contains two integers n and m (1 ≤ n, m ≤ 104) — number of universes and number of groups respectively. The next m lines contain the information about the groups. i-th of them first contains an integer k (number of times someone joined i-th group, k > 0) followed by k integers vi, 1, vi, 2, .... | standard output | standard input | Python 3 | Python | 1,300 | train_004.jsonl | 50bf784254eb3f10682b6f9529468e73 | 256 megabytes | ["4 2\n1 -3\n4 -2 3 2 -3", "5 2\n5 3 -2 1 -1 5\n3 -5 2 5", "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4"] | PASSED | n, m = map(int, input().split())
for i in range(m):
bad = True
l = set(map(int, input().split()[1:]))
for j in l:
if -j in l:
bad = False
break
if bad:
break
print("YES" if bad else "NO") | 1490281500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3.5 seconds | ["3\n1\n78975\n969\n109229059713337"] | 6a3043daecdb0442f4878ee08a8b70ba | NoteIn the first test case, there are $$$3$$$ suitable triplets: $$$(1,2,3)$$$, $$$(1,3,4)$$$, $$$(2,3,4)$$$. In the second test case, there is $$$1$$$ suitable triplet: $$$(3,4,5)$$$. | We are sum for we are manySome NumberThis version of the problem differs from the previous one only in the constraint on $$$t$$$. You can make hacks only if both versions of the problem are solved.You are given two positive integers $$$l$$$ and $$$r$$$.Count the number of distinct triplets of integers $$$(i, j, k)$$$ s... | For each test case print one integer — the number of suitable triplets. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$\bf{1 \le t \le 10^5}$$$). Description of the test cases follows. The only line for each test case contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 2 \cdot 10^5$$$, $$$l + 2 \le r$$$). | standard output | standard input | PyPy 3-64 | Python | 2,500 | train_102.jsonl | 8dd855bd44801ba57fb9761711999bb8 | 512 megabytes | ["5\n\n1 4\n\n3 5\n\n8 86\n\n68 86\n\n6 86868"] | PASSED | n = int(2e5+5)
ft = [0]*n
def update(i, val):
while i<n:
ft[i]-=val
i+=(i&(-i))
return
def query(i):
ans = 0
while i!=0:
ans += ft[i]
i -=(i&(-i))
return ans
cnt = [0 for i in range(n)]
pre = [0 for i in range(n)]
for i in range(1,n):
for j in range(i+i, n, i):... | 1660401300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["9 4\n1 4 3 5\n16 10\n1 8 3 4 9 5 2 6 7 10\n1 2\n1 3\n0 11\n1 8 10 4 3 5 7 2 9 6 11\n3 10\n1 9 5 4 7 3 8 6 2 10\n5 2\n1 2"] | d17c9f91504e1d4c4eae7294bf09dcfc | NoteIn the first test case, the required path corresponds to the picture: In this case, the minimum possible total cost of the path is achieved. Since $$$index($$$'l'$$$)=12$$$, $$$index($$$'o'$$$)=15$$$, $$$index($$$'g'$$$)=7$$$, $$$index($$$'i'$$$)=9$$$, $$$index($$$'c'$$$)=3$$$, then the total cost of the path is $... | Polycarp was given a row of tiles. Each tile contains one lowercase letter of the Latin alphabet. The entire sequence of tiles forms the string $$$s$$$.In other words, you are given a string $$$s$$$ consisting of lowercase Latin letters.Initially, Polycarp is on the first tile of the row and wants to get to the last ti... | The answer to each test case consists of two lines. In the first line print two integers $$$cost$$$, $$$m$$$, where $$$cost$$$ is the minimum total cost of the path, and $$$m$$$ is the maximum number of visited tiles Polycarp can make to get to $$$n$$$-th tiles for the minimum total cost $$$cost$$$ (i.e. the number of ... | The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. Each test case is given by the string $$$s$$$ ($$$2 \le |s| \le 2 \cdot 10^5$$$), where $$$|s|$$$ — is the length of string $$$s$$$. The string $$$s$$$ consists of lowercase Latin letters. It is guar... | standard output | standard input | PyPy 3-64 | Python | 1,100 | train_110.jsonl | 9367b1d5ef8ed4bf00a07cd1c9f849ac | 256 megabytes | ["6\n\nlogic\n\ncodeforces\n\nbca\n\naaaaaaaaaaa\n\nadbaadabad\n\nto"] | PASSED | from string import ascii_lowercase as asc
import sys
input = lambda: sys.stdin.buffer.readline().decode().strip()
print = sys.stdout.write
for _ in range(int(input())):
word = list(input())
ci, ti = asc.index(word[0]) + 1, asc.index(word[-1]) + 1
ans = []
if ci <= ti:
for i in ran... | 1662993300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["2", "19", "0"] | f8f84cec87b3bb8c046d8a45f2c4a071 | NoteIn the first sample the whole first layer of CPUs is malfunctional. In the second layer when CPU (2, 1, 2) turns off, it disrupts the control by CPU (2, 1, 3) over CPU (2, 1, 1), and when CPU (2, 2, 2) is turned off, it disrupts the control over CPU (2, 2, 3) by CPU (2, 2, 1).In the second sample all processors exc... | A super computer has been built in the Turtle Academy of Sciences. The computer consists of n·m·k CPUs. The architecture was the paralellepiped of size n × m × k, split into 1 × 1 × 1 cells, each cell contains exactly one CPU. Thus, each CPU can be simultaneously identified as a group of three numbers from the layer nu... | Print a single integer — the number of critical CPUs, that is, such that turning only this CPU off will disrupt some control. | The first line contains three integers n, m and k (1 ≤ n, m, k ≤ 100) — the dimensions of the Super Computer. Then n blocks follow, describing the current state of the processes. The blocks correspond to the layers of the Super Computer in the order from 1 to n. Each block consists of m lines, k characters in each — t... | standard output | standard input | Python 3 | Python | 1,800 | train_059.jsonl | b40f5d2b84e935c9ec128a4dabaac81d | 256 megabytes | ["2 2 3\n000\n000\n\n111\n111", "3 3 3\n111\n111\n111\n\n111\n111\n111\n\n111\n111\n111", "1 1 10\n0101010101"] | PASSED | def main():
s = input().split()
n, m, k = int(s[0]), int(s[1]), int(s[2])
processor = []
for x in range(n):
for y in range(m):
s = input()
for z in s:
processor.append(int(z) == 1)
if x < n - 1:
emptyLine = input()
counter = 0
m... | 1458475200 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1801", "11"] | 08bce37778b7bfe478340d5c222ae362 | NoteIn the first example Dima can split the number $$$1234567$$$ into integers $$$1234$$$ and $$$567$$$. Their sum is $$$1801$$$.In the second example Dima can split the number $$$101$$$ into integers $$$10$$$ and $$$1$$$. Their sum is $$$11$$$. Note that it is impossible to split the strip into "1" and "01" since the ... | Dima worked all day and wrote down on a long paper strip his favorite number $$$n$$$ consisting of $$$l$$$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a pos... | Print a single integer — the smallest number Dima can obtain. | The first line contains a single integer $$$l$$$ ($$$2 \le l \le 100\,000$$$) — the length of the Dima's favorite number. The second line contains the positive integer $$$n$$$ initially written on the strip: the Dima's favorite number. The integer $$$n$$$ consists of exactly $$$l$$$ digits and it does not contain leadi... | standard output | standard input | Python 3 | Python | 1,500 | train_008.jsonl | 5720543951a5bfb7cdf2a5a71d18aadd | 512 megabytes | ["7\n1234567", "3\n101"] | PASSED | n=int(input())
s=input()
mid=len(s)//2
l=mid
r=mid+1
while l>=0 and s[l]=='0':
l-=1
while r<n and s[r]=='0':
r+=1
if l==0:
print(int(s[:r])+int(s[r:]))
elif r==n:
print(int(s[:l])+int(s[l:]))
else:
print(min(int(s[:r])+int(s[r:]),int(s[:l])+int(s[l:])))
| 1560677700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["YES\nNO\nYES\nYES\nNO"] | 235ddb32dbe19c0da1f77069e36128bb | null | You are given two strings $$$s$$$ and $$$t$$$, both of length $$$n$$$. Each character in both string is 'a', 'b' or 'c'.In one move, you can perform one of the following actions: choose an occurrence of "ab" in $$$s$$$ and replace it with "ba"; choose an occurrence of "bc" in $$$s$$$ and replace it with "cb". You ar... | For each testcase, print "YES" if you can change string $$$s$$$ to make it equal to string $$$t$$$ by performing an arbitrary amount of moves (possibly, zero). Otherwise, print "NO". | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of strings $$$s$$$ and $$$t$$$. The second line contains string $$$s$$$ of length $$$n$$$. Each character is 'a', '... | standard output | standard input | Python 3 | Python | 1,400 | train_083.jsonl | 5f1b8b6a0acb88992dddd16d063df98d | 256 megabytes | ["5\n\n3\n\ncab\n\ncab\n\n1\n\na\n\nb\n\n6\n\nabbabc\n\nbbaacb\n\n10\n\nbcaabababc\n\ncbbababaac\n\n2\n\nba\n\nab"] | PASSED | import collections
q = int(input())
for _ in range(q):
n = int(input())
s = list(input())
t = list(input())
occ_s = collections.defaultdict(int)
occ_t = collections.defaultdict(int)
s2 = ""
t2 = ""
for i in range(n):
occ_s[s[i]] += 1
occ_t[t[i]] += 1
if s[i] != "b": s2 += s[i... | 1655044500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1 1 1 1 1 \n3 3 3 \n2 3 3 2 1 3 \n1 \n2 2 2 2 \n4 4 4 1 4"] | 345e76bf67ae4342e850ab248211eb0b | null | The only difference between easy and hard versions is constraints.There are $$$n$$$ kids, each of them is reading a unique book. At the end of any day, the $$$i$$$-th kid will give his book to the $$$p_i$$$-th kid (in case of $$$i = p_i$$$ the kid will give his book to himself). It is guaranteed that all values of $$$p... | For each query, print the answer on it: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ is the number of the day the book of the $$$i$$$-th child is returned back to him for the first time in this query. | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of kids in the query. The second line of the query contains $$$n$$$ integers $$$p_1, p_2, \... | standard output | standard input | PyPy 3 | Python | 1,300 | train_008.jsonl | bcb2521e572c526e43616689013059c8 | 256 megabytes | ["6\n5\n1 2 3 4 5\n3\n2 3 1\n6\n4 6 2 1 5 3\n1\n1\n4\n3 4 1 2\n5\n5 1 2 4 3"] | PASSED | from sys import stdin, stdout
t = int(stdin.readline())
def getRoot(i,par):
while i!=par[i]:
i = par[i]
return i
def find(a,b,par):
return getRoot(a,par)==getRoot(b,par)
def doUnion(a,b,par,size):
if find(a,b,par):
return False
r1 = getRoot(a,par)
r2 = getRoot(b,par)
s1 =... | 1571754900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\n01\n11\nYES\n0011\n1111\n1111\n1100\nNO\nYES\n01111\n11000\n10000\n10000\n10000"] | 95e2ea3e270af683706b9832557c3442 | NoteFor the first test case, you only have to delete cell $$$(1, 1)$$$.For the second test case, you could choose to delete cells $$$(1,1)$$$, $$$(1,2)$$$, $$$(4,3)$$$ and $$$(4,4)$$$.For the third test case, it is no solution because the cells in the diagonal will always form a strictly increasing sequence of length $... | You are given an $$$n \times n$$$ grid. We write $$$(i, j)$$$ to denote the cell in the $$$i$$$-th row and $$$j$$$-th column. For each cell, you are told whether yon can delete it or not. Given an integer $$$k$$$, you are asked to delete exactly $$$(n-k+1)^2$$$ cells from the grid such that the following condition hold... | For each test case, if there is no way to delete exactly $$$(n-k+1)^2$$$ cells to meet the condition, output "NO" (without quotes). Otherwise, output "YES" (without quotes). Then, output $$$n$$$ lines. The $$$i$$$-th line should contain a binary string $$$t_i$$$ of length $$$n$$$. The $$$j$$$-th character of $$$t_i$$$ ... | Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. The following lines contain the description of each test case. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq k \leq n \leq 1000$$$). Then $$$... | standard output | standard input | PyPy 3-64 | Python | 2,900 | train_103.jsonl | 0a79b53880ffffbb8485731019bba663 | 512 megabytes | ["4\n\n2 2\n\n10\n\n01\n\n4 3\n\n1110\n\n0101\n\n1010\n\n0111\n\n5 5\n\n01111\n\n10111\n\n11011\n\n11101\n\n11110\n\n5 2\n\n10000\n\n01111\n\n01111\n\n01111\n\n01111"] | PASSED | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buf... | 1664548500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.