prob_desc_time_limit stringclasses 21
values | prob_desc_sample_outputs stringlengths 5 329 | src_uid stringlengths 32 32 | prob_desc_notes stringlengths 31 2.84k β | prob_desc_description stringlengths 121 3.8k | prob_desc_output_spec stringlengths 17 1.16k β | prob_desc_input_spec stringlengths 38 2.42k β | prob_desc_output_to stringclasses 3
values | prob_desc_input_from stringclasses 3
values | lang stringclasses 5
values | lang_cluster stringclasses 1
value | difficulty int64 -1 3.5k β | file_name stringclasses 111
values | code_uid stringlengths 32 32 | prob_desc_memory_limit stringclasses 11
values | prob_desc_sample_inputs stringlengths 5 802 | exec_outcome stringclasses 1
value | source_code stringlengths 29 58.4k | prob_desc_created_at stringlengths 10 10 | tags listlengths 1 5 | hidden_unit_tests stringclasses 1
value | labels listlengths 8 8 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2 seconds | ["6", "0", "1"] | 47bc3dac92621d2c7ea7d7d6036c2652 | NoteIn first sample test case the good paths are: 2βββ1βββ3βββ1βββ4βββ1βββ5, 2βββ1βββ3βββ1βββ5βββ1βββ4, 2βββ1βββ4βββ1βββ5βββ1βββ3, 3βββ1βββ2βββ1βββ4βββ1βββ5, 3βββ1βββ2βββ1βββ5βββ1βββ4, 4βββ1βββ2βββ1βββ3βββ1βββ5. There are good paths that are same with displayed above, because the sets of roads they pass over onc... | Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherlandΒ β Uzhlyandia.It is widely known that Uzhlyandia has n cities connected with m bidirectional roads. Also, there are no two roads in the country that connect the same pair of cities, but roads starting and ending i... | Print out the only integerΒ β the number of good paths in Uzhlyandia. | The first line contains two integers n, m (1ββ€βn,βmββ€β106)Β β the number of cities and roads in Uzhlyandia, respectively. Each of the next m lines contains two integers u and v (1ββ€βu,βvββ€βn) that mean that there is road between cities u and v. It is guaranteed that no road will be given in the input twice. That also me... | standard output | standard input | PyPy 2 | Python | 2,100 | train_005.jsonl | 939959d878d12df5441a1b144a2f225d | 256 megabytes | ["5 4\n1 2\n1 3\n1 4\n1 5", "5 3\n1 2\n2 3\n4 5", "2 2\n1 1\n1 2"] | PASSED | import sys
range = xrange
input = raw_input
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
n = inp[ii]; ii += 1
m = inp[ii]; ii += 1
special = 0
found = [1]*n
coupl = [[] for _ in range(n)]
for _ in range(m):
u = inp[ii] - 1; ii += 1
v = inp[ii] - 1; ii += 1
found[u] = 0
found[v] = 0
... | 1490803500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["3 6\n5 1\n2 4", "4 5\n1 6\n2 7\n3 8"] | 47a9d72651f1407de89e28fb4b142367 | NoteIn the first example, here is what points and their corresponding bounding boxes look like (drawn in two dimensions for simplicity, as all points lie on $$$z = 0$$$ plane). Note that order of removing matters: for example, points $$$5$$$ and $$$1$$$ don't form a perfectly balanced pair initially, but they do after ... | This is an easier version of the problem. In this version, $$$n \le 2000$$$.There are $$$n$$$ distinct points in three-dimensional space numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th point has coordinates $$$(x_i, y_i, z_i)$$$. The number of points $$$n$$$ is even.You'd like to remove all $$$n$$$ points using a sequ... | Output $$$\frac{n}{2}$$$ pairs of integers $$$a_i, b_i$$$ ($$$1 \le a_i, b_i \le n$$$), denoting the indices of points removed on snap $$$i$$$. Every integer between $$$1$$$ and $$$n$$$, inclusive, must appear in your output exactly once. We can show that it is always possible to remove all points. If there are many so... | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2000$$$; $$$n$$$ is even), denoting the number of points. Each of the next $$$n$$$ lines contains three integers $$$x_i$$$, $$$y_i$$$, $$$z_i$$$ ($$$-10^8 \le x_i, y_i, z_i \le 10^8$$$), denoting the coordinates of the $$$i$$$-th point. No two points coin... | standard output | standard input | PyPy 3 | Python | 1,700 | train_015.jsonl | a907bbeaa23cc60df6412d4fc2407035 | 512 megabytes | ["6\n3 1 0\n0 3 0\n2 2 0\n1 0 0\n1 3 0\n0 1 0", "8\n0 1 1\n1 0 1\n1 1 0\n1 1 1\n2 2 2\n3 2 2\n2 3 2\n2 2 3"] | PASSED | #from bisect import bisect_left as bl #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br #c++ upperbound br(array,element)
#from __future__ import print_function, division #while using python2
import math
def modinv(n,p):
return pow(n,p-2,p)
def dist(x1, y1, z... | 1571236500 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["36", "1000000006"] | cf210ef68d0525dcb1574f450773da39 | NoteIn the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15.Karen performs the operations as follows: The non-negative remainder after dividing the final number by 109β+β7 is still 36, so this is the correct output.In the second test case, the numbers written on the first row are 3, 7, 5 an... | Karen has just arrived at school, and she has a math test today! The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points.There are n i... | Output a single integer on a line by itself, the number on the final row after performing the process above. Since this number can be quite large, print only the non-negative remainder after dividing it by 109β+β7. | The first line of input contains a single integer n (1ββ€βnββ€β200000), the number of numbers written on the first row. The next line contains n integers. Specifically, the i-th one among these is ai (1ββ€βaiββ€β109), the i-th number on the first row. | standard output | standard input | PyPy 3 | Python | 2,200 | train_005.jsonl | 8abdcb045e21c37463a7cb2a9ef1d377 | 512 megabytes | ["5\n3 6 9 12 15", "4\n3 7 5 2"] | PASSED | from sys import exit, stdin, stdout
n = int(stdin.readline())
a = [int(i) for i in stdin.readline().split()]
if n == 1:
print(a[0])
exit(0)
mod = 1000000007
f = [0] * (n + 1)
f[0] = 1
for i in range(1, n + 1):
f[i] = (f[i-1] * i) % mod
def f_pow(a, k):
if k == 0:
return 1
if k % 2 == 1:
... | 1497710100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n1 3 10", "0", "2\n1 2 60\n3 4 50"] | e83a8bfabd7ea096fae66dcc8c243be7 | null | The German University in Cairo (GUC) dorm houses are numbered from 1 to n. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this direction and not vice versa), and diameter (which characterizes the maximal amount of water it can handle).For each house, there... | Print integer t in the first line β the number of tank-tap pairs of houses. For the next t lines, print 3 integers per line, separated by spaces: tanki, tapi, and diameteri, where tankiββ βtapi (1ββ€βiββ€βt). Here tanki and tapi are indexes of tank and tap houses respectively, and diameteri is the maximum amount of water ... | The first line contains two space-separated integers n and p (1ββ€βnββ€β1000,β0ββ€βpββ€βn) β the number of houses and the number of pipes correspondingly. Then p lines follow β the description of p pipes. The i-th line contains three integers ai bi di, indicating a pipe of diameter di going from house ai to house bi (1ββ€β... | standard output | standard input | Python 3 | Python | 1,400 | train_011.jsonl | f94278a7d072af5b5edefbaf175bea40 | 256 megabytes | ["3 2\n1 2 10\n2 3 20", "3 3\n1 2 20\n2 3 10\n3 1 5", "4 2\n1 2 60\n3 4 50"] | PASSED | houses, pipes = [int(x) for x in input().strip().split()]
houseToHouseDict = {}
pipeDict = {}
outgoingList = []
incomingList = []
maxFlow = 0
def DFSmaxPipe(origin):
end = []
lowestDiam = maxFlow
while (origin in houseToHouseDict):
diam = pipeDict[origin]
if diam < lowestDiam:
lowestDiam = diam
origin = h... | 1314111600 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["-1\nabaacba\nxdd"] | b9f0c38c6066bdafa2e4c6daf7f46816 | NoteIn the first query we cannot rearrange letters to obtain a good string.Other examples (not all) of correct answers to the second query: "ababaca", "abcabaa", "baacaba".In the third query we can do nothing to obtain a good string. | You are given a string $$$s$$$ consisting only of lowercase Latin letters.You can rearrange all letters of this string as you wish. Your task is to obtain a good string by rearranging the letters of the given string or report that it is impossible to do it.Let's call a string good if it is not a palindrome. Palindrome ... | Print $$$t$$$ lines. In the $$$i$$$-th line print the answer to the $$$i$$$-th query: -1 if it is impossible to obtain a good string by rearranging the letters of $$$s_i$$$ and any good string which can be obtained from the given one (by rearranging the letters) otherwise. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β number of queries. Each of the next $$$t$$$ lines contains one string. The $$$i$$$-th line contains a string $$$s_i$$$ consisting only of lowercase Latin letter. It is guaranteed that the length of $$$s_i$$$ is from $$$1$$$ to $$$1000$$$... | standard output | standard input | PyPy 3 | Python | 900 | train_039.jsonl | 2eb95efda9fb78315571a2fc6ecfcec6 | 256 megabytes | ["3\naa\nabacaba\nxdd"] | PASSED | for i in range(int(input())):
k=input()
if len(set(k))==1:
print("-1")
continue
else:
r = ''.join(sorted(k))
print(str(r)) | 1544884500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["2\nR 2\nR 5", "2\nL 4\nL 2", "0"] | 6ca35987757bf64860eb08f98a9e6d90 | NoteFor the first example the following operations are performed:abac $$$\to$$$ abacab $$$\to$$$ abacabaThe second sample performs the following operations: acccc $$$\to$$$ cccacccc $$$\to$$$ ccccaccccThe third example is already a palindrome so no operations are required. | Ringo found a string $$$s$$$ of length $$$n$$$ in his yellow submarine. The string contains only lowercase letters from the English alphabet. As Ringo and his friends love palindromes, he would like to turn the string $$$s$$$ into a palindrome by applying two types of operations to the string. The first operation allow... | The first line should contain $$$k$$$ ($$$0\le k \le 30$$$) Β β the number of operations performed. Each of the following $$$k$$$ lines should describe an operation in form L i or R i. $$$L$$$ represents the first operation, $$$R$$$ represents the second operation, $$$i$$$ represents the index chosen. The length of the ... | The only line contains the string $$$S$$$ ($$$3 \le |s| \le 10^5$$$) of lowercase letters from the English alphabet. | standard output | standard input | PyPy 2 | Python | 1,400 | train_018.jsonl | 5b623f52412e85a676279fbbc2ced8a3 | 256 megabytes | ["abac", "acccc", "hannah"] | PASSED | from __future__ import division, print_function
# import threading
# threading.stack_size(2**27)
import sys
sys.setrecursionlimit(10**4)
# sys.stdin = open('inpy.txt', 'r')
# sys.stdout = open('outpy.txt', 'w')
from sys import stdin, stdout
import bisect #c++ upperbound
import math
import heapq
i_m=922337203... | 1603011900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["0111010\n1001\n0001111\n0"] | ff66c68e8f53b0c051efe5db9428e91d | Note The corresponding graph of the first test case is: $$$c_1 + c_2 = 1 + 2 = 3$$$ The corresponding graph of the second test case is: $$$c_1 + c_2 = 2 + 2 = 4$$$ | You are given a connected, undirected and unweighted graph with $$$n$$$ vertices and $$$m$$$ edges. Notice the limit on the number of edges: $$$m \le n + 2$$$.Let's say we color some of the edges red and the remaining edges blue. Now consider only the red edges and count the number of connected components in the graph.... | For each test case, output a binary string of length $$$m$$$. The $$$i$$$-th character of the string should be 1 if the $$$i$$$-th edge should be colored red, and 0 if it should be colored blue. If there are multiple ways to assign colors to edges that give the minimum answer, you may output any. | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) β the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$n-1 \leq m \leq \min{\left(n... | standard output | standard input | PyPy 3-64 | Python | 2,000 | train_106.jsonl | bf4d729b549b5c82799ee5e20b7011f1 | 256 megabytes | ["4\n\n5 7\n\n1 2\n\n2 3\n\n3 4\n\n4 5\n\n5 1\n\n1 3\n\n3 5\n\n4 4\n\n1 2\n\n2 3\n\n1 4\n\n3 4\n\n6 7\n\n1 2\n\n1 3\n\n3 4\n\n4 5\n\n1 4\n\n5 6\n\n6 2\n\n2 1\n\n1 2"] | PASSED | import random
import sys
input = sys.stdin.readline
class DSU:
def __init__(self, n):
self.p = [i for i in range(n)]
self.size = [1]*n
def find(self, x):
root = x
while root != self.p[root]:
root = self.p[root]
while x != self.p[x]:
tmp = x
... | 1662474900 | [
"probabilities",
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
1,
0,
1
] | |
2 seconds | ["0", "1", "6"] | 686b6ff777d8047cdf98813fcd5192c5 | NoteIn the first sample, there are $$$4$$$ contestants, arranged as follows. There is only one way to choose four contestants, with one pole held by contestants aged $$$1$$$ and $$$2$$$ and the other one by contestants aged $$$3$$$ and $$$4$$$. But then, as we can see in the picture, the poles cross. Since there is... | Today, like every year at SWERC, the $$$n^2$$$ contestants have gathered outside the venue to take a drone photo. Jennifer, the social media manager for the event, has arranged them into an $$$n\times n$$$ square. Being very good at her job, she knows that the contestant standing on the intersection of the $$$i$$$-th r... | Print the number of ways for Jennifer to choose the four contestants holding the poles. | The first line contains a single integer $$$n$$$ ($$$2\le n \le 1500$$$). The next $$$n$$$ lines describe the ages of the contestants. Specifically, the $$$i$$$-th line contains the integers $$$a_{i,1},a_{i,2},\ldots,a_{i,n}$$$ ($$$1\le a_{i,j}\le n^2$$$). It is guaranteed that $$$a_{i,j}\neq a_{k,l}$$$ if $$$i\neq k$$... | standard output | standard input | PyPy 3-64 | Python | -1 | train_085.jsonl | 0f4996c2c0af3250841c889a5da84383 | 512 megabytes | ["2\n1 3\n4 2", "2\n3 2\n4 1", "3\n9 2 4\n1 5 3\n7 8 6"] | PASSED | # ''' # FASTIO BEGINS -------------------->
import atexit,io,os,sys
ss=io.BytesIO()
_write=ss.write
ss.write=lambda sett:_write(sett.encode())
atexit.register(lambda:os.write(1,ss.getvalue()))
y_in=open(0).read().split("\n")
def y_inf():
for y_id in range(len(y_in)):
yield y_id
y_ino=y_inf()
inpu... | 1650798300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3\n4\n0\n0"] | c05426881a7dccc1aa79608b612290a7 | NoteIn the first example, Gregor can simply advance all $$$3$$$ of his pawns forward. Thus, the answer is $$$3$$$.In the second example, Gregor can guarantee that all $$$4$$$ of his pawns reach the enemy row, by following the colored paths as demonstrated in the diagram below. Remember, only Gregor takes turns in this ... | There is a chessboard of size $$$n$$$ by $$$n$$$. The square in the $$$i$$$-th row from top and $$$j$$$-th column from the left is labelled $$$(i,j)$$$.Currently, Gregor has some pawns in the $$$n$$$-th row. There are also enemy pawns in the $$$1$$$-st row. On one turn, Gregor moves one of his pawns. A pawn can move on... | For each test case, print one integer: the maximum number of Gregor's pawns which can reach the $$$1$$$-st row. | 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. Each test case consists of three lines. The first line contains a single integer $$$n$$$ ($$$2\le n\le 2\cdot{10}^{5}$$$) β the size of the chessboard. The second line consi... | standard output | standard input | PyPy 3-64 | Python | 800 | train_086.jsonl | 76b972cb9757b51f0edb356d0a04c722 | 256 megabytes | ["4\n3\n000\n111\n4\n1111\n1111\n3\n010\n010\n5\n11001\n00000"] | PASSED | def solve():
n = int(input())
e = list(input())
g = list(input())
e.insert(0,"0")
e.insert(n+1,"0")
# print(e)
c = 0
for i in range(0,n):
if g[i] == "1":
if e[i+1] == "0":
c+=1
elif e[i] =="1":
... | 1627828500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
3 seconds | ["3.4142135624 -1.4142135624\n2.0000000000 0.0000000000\n0.5857864376 -1.4142135624", "1.0000000000 -1.0000000000"] | 3d8aa764053d3cf14f34f11de61d1816 | NoteIn the first test note the initial and the final state of the wooden polygon. Red Triangle is the initial state and the green one is the triangle after rotation around $$$(2,0)$$$.In the second sample note that the polygon rotates $$$180$$$ degrees counter-clockwise or clockwise direction (it does not matter), be... | Hag is a very talented person. He has always had an artist inside him but his father forced him to study mechanical engineering.Yesterday he spent all of his time cutting a giant piece of wood trying to make it look like a goose. Anyway, his dad found out that he was doing arts rather than studying mechanics and other ... | The output should contain the answer to each query of second typeΒ β two numbers in a separate line. Your answer is considered correct, if its absolute or relative error does not exceed $$$10^{-4}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|a... | The first line contains two integers $$$n$$$ and $$$q$$$ ($$$3\leq n \leq 10\,000$$$, $$$1 \leq q \leq 200000$$$)Β β the number of vertices in the polygon and the number of queries. The next $$$n$$$ lines describe the wooden polygon, the $$$i$$$-th line contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$|x_i|, |y_i|\leq ... | standard output | standard input | Python 3 | Python | 2,600 | train_070.jsonl | 121272df9e79adc0a8835b8b1cb2b6d3 | 256 megabytes | ["3 4\n0 0\n2 0\n2 2\n1 1 2\n2 1\n2 2\n2 3", "3 2\n-1 1\n0 0\n1 1\n1 1 2\n2 1"] | PASSED | import math;
#ΠΡΡΠΈΡΠ»Π΅Π½ΠΈΠ΅ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ ΡΠΎΡΠΊΠΈ ΠΏΠΎ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΠ°ΠΌ ΡΠ΅Π½ΡΡΠ°, ΡΠ³Π»Ρ, ΠΈ Π½Π°ΡΠ°Π»ΡΠ½ΡΠΌ ΠΎΡΠ½ΠΎΡΠΈΡΠ΅Π»ΡΠ½ΠΎ ΡΠ΅Π½ΡΡΠ°
def getCoordinate(gx, gy, alpha, x, y):
x1=gx+x*math.cos(alpha)-y*math.sin(alpha);
y1=gy+x*math.sin(alpha)+y*math.cos(alpha);
return x1, y1
#ΠΡΡΠΈΡΠ»Π΅Π½ΠΈΠ΅ ΡΠ³Π»Π°, Π½Π° ΠΊΠΎΡΠΎΡΡΠΉ Π½Π°Π΄ΠΎ ΠΏΠΎΠ²Π΅ΡΠ½ΡΡΡ ΡΠΎΡΠΊΡ Ρ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΠ°ΠΌΠΈ ... | 1525183500 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["YES\n2", "YES\n2", "NO"] | aaca5d07795a42ecab210327c1cf6be9 | null | Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color ci.Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes some vertex ... | Print "NO" in a single line, if Timofey can't take the tree in such a way that it doesn't annoy him. Otherwise print "YES" in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them. | The first line contains single integer n (2ββ€βnββ€β105)Β β the number of vertices in the tree. Each of the next nβ-β1 lines contains two integers u and v (1ββ€βu,βvββ€βn, uββ βv), denoting there is an edge between vertices u and v. It is guaranteed that the given graph is a tree. The next line contains n integers c1,βc2,β..... | standard output | standard input | Python 3 | Python | 1,600 | train_012.jsonl | 0ab933a56c183a04ae5ccbef481e8ff0 | 256 megabytes | ["4\n1 2\n2 3\n3 4\n1 2 1 1", "3\n1 2\n2 3\n1 2 3", "4\n1 2\n2 3\n3 4\n1 2 1 2"] | PASSED |
import sys
n = int(sys.stdin.readline())
edges = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n - 1)]
colors = sys.stdin.readline().split()
res = None
for edge in edges:
if colors[edge[0]-1] != colors[edge[1]-1]:
if res is None:
res = list(edge)
else:
r... | 1486042500 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
3 seconds | ["40", "1", "172"] | e6e760164882b9e194a17663625be27d | null | Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this!Let us remind you t... | If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes). | The input consists of two positive integers p, q, the numerator and denominator of the fraction that is the value of AΒ (,Β ). | standard output | standard input | Python 2 | Python | 1,600 | train_000.jsonl | 08043780201f473922d92660b64e19d0 | 256 megabytes | ["1 1", "1 42", "6 4"] | PASSED | #!/usr/bin/env python
import math
def is_pal(n):
if str(n) == str(n)[::-1]:
return True
else:
return False
def sieve(n, a):
primos = [True]*(n+1)
primos[0] = False
primos[1] = False
# m = int(math.sqrt(n))
c = 0
pl= 1
r = 1
for i in range(2, n):
if primos[i]:
c += 1
for k in range(i*i,n+1,i):
... | 1439224200 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["3\n7\n2"] | a688369a2b95a8e32d00541d54f3bec6 | NoteTree and best path for the first test case: $$$1 \rightarrow 2 \rightarrow 1 \rightarrow 3$$$ Tree and best path for the second test case: $$$3 \rightarrow 1 \rightarrow 3 \rightarrow 5 \rightarrow 2 \rightarrow 5 \rightarrow 6 \rightarrow 5$$$ Tree and best path for the third test case: $$$3 \rightarrow 5 \righ... | Vlad and Nastya live in a city consisting of $$$n$$$ houses and $$$n-1$$$ road. From each house, you can get to the other by moving only along the roads. That is, the city is a tree.Vlad lives in a house with index $$$x$$$, and Nastya lives in a house with index $$$y$$$. Vlad decided to visit Nastya. However, he rememb... | 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 minutes Vlad needs on the road to do all the things and come to Nastya. | The first line of input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of input test cases. There is an empty line before each test case. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2\cdot 10^5$$$) β the number of houses and things, respectively. T... | standard output | standard input | PyPy 3-64 | Python | 1,800 | train_092.jsonl | 509b9122e18c03a856bad9279640f582 | 256 megabytes | ["3\n\n\n\n\n3 1\n\n1 3\n\n2\n\n1 3\n\n1 2\n\n\n\n\n6 4\n\n3 5\n\n1 6 2 1\n\n1 3\n\n3 4\n\n3 5\n\n5 6\n\n5 2\n\n\n\n\n6 2\n\n3 2\n\n5 3\n\n1 3\n\n3 4\n\n3 5\n\n5 6\n\n5 2"] | PASSED | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.wri... | 1651761300 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["-1", "2 1", "2 1 4 3"] | 204ba74195a384c59fb1357bdd71e16c | null | A permutation is a sequence of integers p1,βp2,β...,βpn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1,βp2,β...,βpn.Nickolas adores permutations. He likes some permutations more than the oth... | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1,βp2,β...,βpn β permutation p, that is perfect. Separate printed numbers by whitespaces. | A single line contains a single integer n (1ββ€βnββ€β100) β the permutation size. | standard output | standard input | PyPy 2 | Python | 800 | train_005.jsonl | 740a2db6ab0dc489cc5f948c06921542 | 256 megabytes | ["1", "2", "4"] | PASSED | import bisect
from collections import defaultdict
from collections import deque
import math
import re
import sys
import itertools
def ni():
return int(raw_input())
def nis():
return map(int, raw_input().split())
def si():
return raw_input()
def sis():
return raw_input().split()
def spaced(a):
r... | 1349969400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3\n1\n2\n0"] | 0816295355375a2d3f1cd45852b86360 | NoteIn the first query there are only three appropriate character builds: $$$(str = 7, int = 5)$$$, $$$(8, 4)$$$ and $$$(9, 3)$$$. All other builds are either too smart or don't use all free points.In the second query there is only one possible build: $$$(2, 1)$$$.In the third query there are two appropriate builds: $$... | You play your favourite game yet another time. You chose the character you didn't play before. It has $$$str$$$ points of strength and $$$int$$$ points of intelligence. Also, at start, the character has $$$exp$$$ free experience points you can invest either in strength or in intelligence (by investing one point you can... | Print $$$T$$$ integers β one per query. For each query print the number of different character builds you can create. | The first line contains the single integer $$$T$$$ ($$$1 \le T \le 100$$$) β the number of queries. Next $$$T$$$ lines contain descriptions of queries β one per line. This line contains three integers $$$str$$$, $$$int$$$ and $$$exp$$$ ($$$1 \le str, int \le 10^8$$$, $$$0 \le exp \le 10^8$$$) β the initial strength and... | standard output | standard input | Python 3 | Python | 1,300 | train_000.jsonl | 7ad112370a4a1cf9b8833f29951d15d3 | 256 megabytes | ["4\n5 3 4\n2 1 0\n3 5 5\n4 10 6"] | PASSED | n = int(input())
i = 0
while i < n:
ar = list(map(int, input().split()))
if ar[0] < ar[1]:
diff = ar[1] - ar[0]
if diff >= ar[2]:
print(0)
else:
print(int((ar[2] - diff + 1) / 2))
else:
diff = ar[0] - ar[1]
if diff > ar[2]:
print(... | 1567694100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["5\n2\n2\n0\n4\n4\n1000000000\n0"] | 0a05b11307fbb2536f868acf4e81c1e2 | NotePossible arrays for the first three test cases (in each array the median is underlined): In the first test case $$$[\underline{5}]$$$ In the second test case $$$[\underline{2}, 3]$$$ In the third test case $$$[1, \underline{2}, 2]$$$ | You are given two positive integers $$$n$$$ and $$$s$$$. Find the maximum possible median of an array of $$$n$$$ non-negative integers (not necessarily distinct), such that the sum of its elements is equal to $$$s$$$.A median of an array of integers of length $$$m$$$ is the number standing on the $$$\lceil {\frac{m}{2}... | For each test case print a single integerΒ β the maximum possible median. | 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 two integers $$$n$$$ and $$$s$$$ ($$$1 \le n, s \le 10^9$$$)Β β the length of the array and th... | standard output | standard input | PyPy 3-64 | Python | 800 | train_091.jsonl | cd318d7b099065409e578b7411364314 | 256 megabytes | ["8\n1 5\n2 5\n3 5\n2 1\n7 17\n4 14\n1 1000000000\n1000000000 1"] | PASSED | t = int(input())
for _ in range(t):
n,s = map(int,input().split())
if n%2 != 0:
res = s//(n-(n//2))
else:
res = s//(n//2+1)
print(res)
| 1631457300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0 0", "0 1", "2 1"] | 01adc5002997b7f5c79eeb6d9b3dc60b | NoteIn the first sample test the given permutation p is the identity permutation, that's why its deviation equals to 0, the shift id equals to 0 as well.In the second sample test the deviation of p equals to 4, the deviation of the 1-st cyclic shift (1,β2,β3) equals to 0, the deviation of the 2-nd cyclic shift (3,β1,β2... | Some time ago Mister B detected a strange signal from the space, which he started to study.After some transformation the signal turned out to be a permutation p of length n or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation which... | Print two integers: the minimum deviation of cyclic shifts of permutation p and the id of such shift. If there are multiple solutions, print any of them. | First line contains single integer n (2ββ€βnββ€β106) β the length of the permutation. The second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β the elements of the permutation. It is guaranteed that all elements are distinct. | standard output | standard input | PyPy 2 | Python | 1,900 | train_023.jsonl | df92ab11bbf0d6b260f4ffb691521c1e | 256 megabytes | ["3\n1 2 3", "3\n2 3 1", "3\n3 2 1"] | PASSED | def main():
n=input()
A=list(map(int,raw_input().strip().split(' ')))
#for i in range(len(A)):
# A[i]-=1
ans=0
pos=0
neg=0
change=[0 for i in range(len(A))]
for i in range(len(A)):
ans+=abs(A[i]-i-1)
if A[i]-1-i>0:
pos+=1
else:
ne... | 1498574100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1\n1 \n4\n1 4 3 2"] | 61ba68bdc7a1e3c60135cbae30d9e088 | NoteIn the first example, we get sum is $$$a_1 = 0$$$.In the second example, we get sum is $$$a_1 + a_4 + a_3 + a_2 = 0$$$. | You are given $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, such that for each $$$1\le i \le n$$$ holds $$$i-n\le a_i\le i-1$$$.Find some nonempty subset of these integers, whose sum is equal to $$$0$$$. It can be shown that such a subset exists under given constraints. If there are several possible subsets with zero-su... | For each test case, output two lines. In the first line, output $$$s$$$ ($$$1\le s \le n$$$)Β β the number of elements in your subset. In the second line, output $$$s$$$ integers $$$i_1, i_2, \dots, i_s$$$ ($$$1\le i_k \le n$$$). All integers have to be pairwise different, and $$$a_{i_1} + a_{i_2} + \dots + a_{i_s}$$$ h... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^6$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1\le n \le 10^6$$$). The second line of each test case contains $$$n$$$ integers $$... | standard output | standard input | PyPy 2 | Python | 2,700 | train_013.jsonl | d135a5c8f908de090baae828a5b46319 | 256 megabytes | ["2\n5\n0 1 2 3 4\n4\n-3 1 1 1"] | PASSED | from sys import stdin, stdout
t = input()
inp = stdin.readlines()
out = []
for itr in xrange(t):
n = int(inp[itr << 1].strip())
a = map(int, inp[itr << 1 | 1].strip().split())
found = -1
for i in xrange(n):
if a[i] == 0:
found = i
break
else:
... | 1577628300 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
1 second | ["0\n1\n0\n4\n0\n36\n665702330"] | 0b718a81787c3c5c1aa5b92834ee8bf5 | NoteIn first test case, we only have one permutation which is $$$[1]$$$ but it is not beautiful because $$$\gcd(1 \cdot 1) = 1$$$.In second test case, we only have one beautiful permutation which is $$$[2, 1]$$$ because $$$\gcd(1 \cdot 2, 2 \cdot 1) = 2$$$. | Marin wants you to count number of permutations that are beautiful. A beautiful permutation of length $$$n$$$ is a permutation that has the following property: $$$$$$ \gcd (1 \cdot p_1, \, 2 \cdot p_2, \, \dots, \, n \cdot p_n) > 1, $$$$$$ where $$$\gcd$$$ is the greatest common divisor.A permutation is an array con... | For each test case, print one integer β number of beautiful permutations. Because the answer can be very big, please print the answer modulo $$$998\,244\,353$$$. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^3$$$) β the number of test cases. Each test case consists of one line containing one integer $$$n$$$ ($$$1 \le n \le 10^3$$$). | standard output | standard input | Python 3 | Python | 800 | train_095.jsonl | d010c0b118b5b7a671b840b994bef607 | 256 megabytes | ["7\n1\n2\n3\n4\n5\n6\n1000"] | PASSED | import sys
import math
import bisect
import heapq
input = sys.stdin.readline
print = sys.stdout.write
t = int(input())
def solve():
# input init.
# input()
# num
n=int(input())
# x,d=map(int, input().split())
# string
# s=input().rstrip('\n')
# c=input().rstrip('\n')
... | 1648391700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["1\n2\n3\n4\n5\n18"] | ac7d117d58046872e9d665c9f99e5bff | null | Let's call a positive integer $$$n$$$ ordinary if in the decimal notation all its digits are the same. For example, $$$1$$$, $$$2$$$ and $$$99$$$ are ordinary numbers, but $$$719$$$ and $$$2021$$$ are not ordinary numbers.For a given number $$$n$$$, find the number of ordinary numbers among the numbers from $$$1$$$ to ... | For each test case output the number of ordinary numbers among numbers from $$$1$$$ to $$$n$$$. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. Each test case is characterized by one integer $$$n$$$ ($$$1 \le n \le 10^9$$$). | standard output | standard input | Python 3 | Python | 800 | train_083.jsonl | f3ad96a0228b5c8e2d623c7a502d6ee5 | 256 megabytes | ["6\n1\n2\n3\n4\n5\n100"] | PASSED | for t in range(int(input())):
n=input()
print(9*(len(n)-1)+int(n)//int("1"*len(n)))
| 1620225300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
5 seconds | ["63", "136"] | b54a045ad7beed08b94f5d31700a2d77 | NoteIn the first sample:$$$\text{exlog}_f(1) = 0$$$$$$\text{exlog}_f(2) = 2$$$$$$\text{exlog}_f(3) = 3$$$$$$\text{exlog}_f(4) = 2 + 2 = 4$$$$$$\text{exlog}_f(5) = 5$$$$$$\text{exlog}_f(6) = 2 + 3 = 5$$$$$$\text{exlog}_f(7) = 7$$$$$$\text{exlog}_f(8) = 2 + 2 + 2 = 6$$$$$$\text{exlog}_f(9) = 3 + 3 = 6$$$$$$\text{exlog}_f... | Notice: unusual memory limit!After the war, destroyed cities in the neutral zone were restored. And children went back to school.The war changed the world, as well as education. In those hard days, a new math concept was created.As we all know, logarithm function can be described as: $$$$$$ \log(p_1^{a_1}p_2^{a_2}...p_... | Print the answer modulo $$$2^{32}$$$. | The only line contains five integers $$$n$$$, $$$A$$$, $$$B$$$, $$$C$$$, and $$$D$$$ ($$$1 \le n \le 3 \cdot 10^8$$$, $$$0 \le A,B,C,D \le 10^6$$$). | standard output | standard input | Python 2 | Python | 2,500 | train_020.jsonl | 5cc0c50418f83259f104c1ab14eee224 | 16 megabytes | ["12 0 0 1 0", "4 1 2 3 4"] | PASSED | def p1(x):
if x % 2 == 0:
x, y = x / 2, x + 1
else:
y = (x + 1) / 2
return x*y
def p2(x):
y, z = x + 1, 2*x + 1
if x % 2 == 0:
x /= 2
else:
y /= 2
if z % 3 == 0:
z /= 3
elif x % 3 == 0:
x /= 3
else:
y /= 3
return x * y... | 1533737100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["No", "Yes\n1 2\n2 1 3"] | bb7bace930d5c5f231bfc2061576ec45 | NoteIn the first example, there is no way to partition a single number into two non-empty sets, hence the answer is "No".In the second example, the sums of the sets are $$$2$$$ and $$$4$$$ respectively. The $$$\mathrm{gcd}(2, 4) = 2 > 1$$$, hence that is one of the possible answers. | Find out if it is possible to partition the first $$$n$$$ positive integers into two non-empty disjoint sets $$$S_1$$$ and $$$S_2$$$ such that:$$$\mathrm{gcd}(\mathrm{sum}(S_1), \mathrm{sum}(S_2)) > 1$$$ Here $$$\mathrm{sum}(S)$$$ denotes the sum of all elements present in set $$$S$$$ and $$$\mathrm{gcd}$$$ means th... | If such partition doesn't exist, print "No" (quotes for clarity). Otherwise, print "Yes" (quotes for clarity), followed by two lines, describing $$$S_1$$$ and $$$S_2$$$ respectively. Each set description starts with the set size, followed by the elements of the set in any order. Each set must be non-empty. If there are... | The only line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 45\,000$$$) | standard output | standard input | PyPy 3 | Python | 1,100 | train_003.jsonl | bdcddfeef444530e63ef7564ca2a3437 | 256 megabytes | ["1", "3"] | PASSED | n = int(input())
if n <3:
print ("No")
elif n ==3:
print ("Yes")
print (1,2)
print (2,1,3)
else:
print ("Yes")
print(3,1,n,n-1)
print(n-3,*range(2,n-1))
| 1536248100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2\n3\n2"] | ccfe798f5dc63c492ff54cf40bb40613 | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example,... | Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either in... | For each test case, output a single integerΒ β the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$)Β β the current volume and Bob's desire... | standard output | standard input | Python 3 | Python | 800 | train_014.jsonl | 6b6b6578126e19d1c9e1f39b079d3a6f | 256 megabytes | ["3\n4 0\n5 14\n3 9"] | PASSED | for _ in range(int(input())):
s = list(map(int, input().split()))
t = 0
k = abs(s[1] - s[0])
a = k / 5
b = k % 5
if a == 0:
if b == 0:
print(int(t))
continue
elif 3 > b > 0:
t += 1
elif 5 > b >= 3:
t += 2
else:
t... | 1574174100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1 2 3 \n1 1 1 \n1 2 2 3 \n-1"] | bb9f0e0431ef4db83190afd7b9ed4496 | null | You are given a simple undirected graph with $$$n$$$ vertices and $$$m$$$ edges. Edge $$$i$$$ is colored in the color $$$c_i$$$, which is either $$$1$$$, $$$2$$$, or $$$3$$$, or left uncolored (in this case, $$$c_i = -1$$$).You need to color all of the uncolored edges in such a way that for any three pairwise adjacent ... | For each test case, print $$$m$$$ integers $$$d_1, d_2, \ldots, d_m$$$, where $$$d_i$$$ is the color of the $$$i$$$-th edge in your final coloring. If there is no valid way to finish the coloring, print $$$-1$$$. | The first line of input contains one integer $$$t$$$ ($$$1 \leq t \leq 10$$$): the number of test cases. The following lines contain the description of the test cases. In the first line you are given two integers $$$n$$$ and $$$m$$$ ($$$3 \leq n \leq 64$$$, $$$0 \leq m \leq \min(256, \frac{n(n-1)}{2})$$$): the number o... | standard output | standard input | PyPy 3-64 | Python | 2,900 | train_101.jsonl | 70b9a88fa703c29e6e351dd22b5d56dc | 256 megabytes | ["4\n3 3\n1 2 1\n2 3 2\n3 1 -1\n3 3\n1 2 1\n2 3 1\n3 1 -1\n4 4\n1 2 -1\n2 3 -1\n3 4 -1\n4 1 -1\n3 3\n1 2 1\n2 3 1\n3 1 2"] | PASSED | from itertools import combinations
from collections import defaultdict
import io, os, sys
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def F1(A, B, C, D):
AD = A ^ D
return (AD ^ B) | (A ^ C), AD & (B ^ C)
def F2(A, B, C, D):
AC = A ^ C
return AC | (B ^ D), (AC ^ D) & (... | 1640792100 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
1 second | ["NO\nYES\nYES\nYES\nYES\nYES\nNO\nYES"] | bd61ae3c19274f47b981b8bd5e786375 | NoteIn the first test case, the sentence $$$s$$$ is $$$\texttt{B}$$$. Clearly, it can't consist of a single word $$$\texttt{A}$$$, so the answer is $$$\texttt{NO}$$$.In the second test case, the sentence $$$s$$$ is $$$\texttt{AB}$$$, and it's possible that it consists of a single word $$$\texttt{AB}$$$, so the answer i... | Alina has discovered a weird language, which contains only $$$4$$$ words: $$$\texttt{A}$$$, $$$\texttt{B}$$$, $$$\texttt{AB}$$$, $$$\texttt{BA}$$$. It also turned out that there are no spaces in this language: a sentence is written by just concatenating its words into a single string.Alina has found one such sentence $... | For each test case output $$$\texttt{YES}$$$ if it is possible that the sentence $$$s$$$ consists of precisely $$$a$$$ words $$$\texttt{A}$$$, $$$b$$$ words $$$\texttt{B}$$$, $$$c$$$ words $$$\texttt{AB}$$$, and $$$d$$$ words $$$\texttt{BA}$$$, and $$$\texttt{NO}$$$ otherwise. You can output each letter in any case. | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) β the number of test cases. The description of the test cases follows. The first line of each test case contains four integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$0\le a,b,c,d\le 2\cdot 10^5$$$) β the number of times that words $$... | standard output | standard input | PyPy 3-64 | Python | 2,000 | train_085.jsonl | 103dc2df596e1d64bd0434997fc527c4 | 256 megabytes | ["8\n1 0 0 0\nB\n0 0 1 0\nAB\n1 1 0 1\nABAB\n1 0 1 1\nABAAB\n1 1 2 2\nBAABBABBAA\n1 1 2 3\nABABABBAABAB\n2 3 5 4\nAABAABBABAAABABBABBBABB\n1 3 3 10\nBBABABABABBBABABABABABABAABABA"] | PASSED | # test.py
# main.py
# .---.---.---.---.---.---.---.---.---.---.---.---.---.-------.
# |1/2| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | + | ' | <- |
# |---'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-----|
# | ->| | Q | W | E | R | T | Y | U | I | O | P | ] | ^ | |
# |-----'.--'.--'.--'.--'.--'.--'... | 1653500100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["0.3535533906", "1.0000000000"] | 495488223483401ff12ae9c456b4e5fe | NoteHere is a picture of the first sampleHere is an example of making the polygon non-convex.This is not an optimal solution, since the maximum distance we moved one point is βββ0.4242640687, whereas we can make it non-convex by only moving each point a distance of at most βββ0.3535533906. | You are given a convex polygon P with n distinct vertices p1,βp2,β...,βpn. Vertex pi has coordinates (xi,βyi) in the 2D plane. These vertices are listed in clockwise order.You can choose a real number D and move each vertex of the polygon a distance of at most D from their original positions.Find the maximum value of D... | Print one real number D, which is the maximum real number such that no matter how you move the vertices, the polygon stays convex. Your answer will be considered correct if its absolute or relative error does not exceed 10β-β6. Namely, let's assume that your answer is a and the answer of the jury is b. The checker prog... | The first line has one integer n (4ββ€βnββ€β1β000)Β β the number of vertices. The next n lines contain the coordinates of the vertices. Line i contains two integers xi and yi (β-β109ββ€βxi,βyiββ€β109)Β β the coordinates of the i-th vertex. These points are guaranteed to be given in clockwise order, and will form a strictly c... | standard output | standard input | Python 3 | Python | 1,800 | train_017.jsonl | 2fc51ed8930c7f1ba59fb174097e96f3 | 256 megabytes | ["4\n0 0\n0 1\n1 1\n1 0", "6\n5 0\n10 0\n12 -4\n10 -8\n5 -8\n3 -4"] | PASSED | #!/usr/bin/env python3
from decimal import Decimal
def dist(a, b):
x1, y1 = a
x2, y2 = b
return Decimal((x1-x2)**2+(y1-y2)**2).sqrt()
def minh(a, b, c):
m = dist(a, b)
n = dist(b, c)
k = dist(a, c)
p = Decimal(m + n + k)/2
sqp = (p*(p-m)*(p-n)*(p-k)).sqrt()
hm = (Decimal(2)/m)*s... | 1492356900 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
3 seconds | ["15", "0", "6"] | a764aa5727b53a6be78b1e172f670c86 | NoteThe following image showcases the first test case. The black weights are pre-assigned from the statement, the red weights are assigned by us, and the minimum spanning tree is denoted by the blue edges. | As a teacher, Riko Hakozaki often needs to help her students with problems from various subjects. Today, she is asked a programming task which goes as follows.You are given an undirected complete graph with $$$n$$$ nodes, where some edges are pre-assigned with a positive weight while the rest aren't. You need to assign... | Print on one line one integer Β β the minimum ugliness among all weight assignments with XOR sum equal to $$$0$$$. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le \min(2 \cdot 10^5, \frac{n(n-1)}{2} - 1)$$$) Β β the number of nodes and the number of pre-assigned edges. The inputs are given so that there is at least one unassigned edge. The $$$i$$$-th of the following $$$m$$$ l... | standard output | standard input | PyPy 3 | Python | 2,500 | train_087.jsonl | 0995594102b4cf3054878e98d778f319 | 256 megabytes | ["4 4\n2 1 14\n1 4 14\n3 2 15\n4 3 8", "6 6\n3 6 4\n2 4 1\n4 5 7\n3 4 10\n3 5 1\n5 2 15", "5 6\n2 3 11\n5 3 7\n1 4 10\n2 4 14\n4 3 8\n2 5 6"] | PASSED | import sys, os
if os.environ['USERNAME']=='kissz':
inp=open('in3.txt','r').readline
def debug(*args):
print(*args,file=sys.stderr)
else:
inp=sys.stdin.readline
def debug(*args):
pass
# SCRIPT STARTS HERE
def getp(i):
L=[]
while parent[i]>=0:
L+=[i]
... | 1618583700 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["2.0000000000", "32.8333333333"] | ffdd1de4be537234e8a0e7127bec43a7 | NoteIn the first example you can put the fishes in cells (2,β1), (2,β2), (2,β3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value. | While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size nβΓβm, divided into cells of size 1βΓβ1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).The gift bundle also includes a square scoop of size rβΓβr, designed for fishing. I... | Print a single numberΒ β the maximum possible expected number of caught fishes. You answer is considered correct, is its absolute or relative error does not exceed 10β-β9. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if . | The only line contains four integers n,βm,βr,βk (1ββ€βn,βmββ€β105, 1ββ€βrββ€βmin(n,βm), 1ββ€βkββ€βmin(nΒ·m,β105)). | standard output | standard input | Python 3 | Python | 2,100 | train_041.jsonl | 4e1a35169bfee117f31d02d155d42d6a | 256 megabytes | ["3 3 2 3", "12 17 9 40"] | PASSED | import heapq as hq
from queue import PriorityQueue
import math
n,m,r, k= input().split()
N = int(n)
M = int(m)
R = int(r)
K = int(k)
q = PriorityQueue()
for i in range(1,math.floor((N+1)/2) + 1):
maxi = min(min(i,N-i+1),min(R,N-R+1)) * min(min(R,M-R+1),math.ceil(M/2))
num = M - (2 * min(min(R,M-R+1),math.c... | 1515162900 | [
"probabilities",
"graphs"
] | [
0,
0,
1,
0,
0,
1,
0,
0
] | |
1 second | ["1\n2\n3"] | 4d5457d9f053556c78c102f5c32f7542 | NoteIn the first test case, the Agent can use the second weapon, making health value of the enemy equal to $$$4-7=-3$$$. $$$-3 \le 0$$$, so the enemy is dead, and using weapon $$$1$$$ time was enough.In the second test case, the Agent can use the first weapon first, and then the second one. After this, the health of en... | One day, Ahmed_Hossam went to Hemose and said "Let's solve a gym contest!". Hemose didn't want to do that, as he was playing Valorant, so he came up with a problem and told it to Ahmed to distract him. Sadly, Ahmed can't solve it... Could you help him?There is an Agent in Valorant, and he has $$$n$$$ weapons. The $$$i$... | For each test case, print a single integer β the minimum number of times that the Agent will have to use the weapons to kill the enemy. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \leq t \leq 10^5)$$$. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$H$$$ $$$(2 \leq n \leq 10^3, 1 \leq H \leq 10^9)$$$ β the number of available weapons ... | standard output | standard input | PyPy 3-64 | Python | 800 | train_106.jsonl | 2da3086f112c21ce41e9c0d366c683e5 | 256 megabytes | ["3\n2 4\n3 7\n2 6\n4 2\n3 11\n2 1 7"] | PASSED | import sys
input = sys.stdin.buffer.readline
n = int(input())
for i in range (0,n):
w,h = map(int,input().split())
d = input()
da = list(map(int,d.split()))
da.sort()
ans = 0
first = da[-1]
sec = da[-2]
combo = int(first)+int(sec)
if h >= combo:
ans += 2*int((h//combo))
if h... | 1633271700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["20", "0", "6", "19200"] | dcde114e4769f659e5a80479e033e50f | null | $$$n$$$ fishermen have just returned from a fishing vacation. The $$$i$$$-th fisherman has caught a fish of weight $$$a_i$$$.Fishermen are going to show off the fish they caught to each other. To do so, they firstly choose an order in which they show their fish (each fisherman shows his fish exactly once, so, formally,... | Print one integer β the number of emotional orders, taken modulo $$$998244353$$$. | The first line contains one integer $$$n$$$ ($$$2 \le n \le 5000$$$). The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 10^9$$$). | standard output | standard input | Python 2 | Python | 2,600 | train_033.jsonl | 665dbcc74496d40687fc51472396e195 | 1024 megabytes | ["4\n1 1 4 9", "4\n4 3 2 1", "3\n4 2 1", "8\n42 1337 13 37 420 666 616 97"] | PASSED | n = int(raw_input())
a = map(int, raw_input().split())
a.sort()
if a[-2] * 2 > a[-1]:
print 0
quit()
mod = 998244353
f = [1] * (n + 1)
for i in xrange(1, n + 1):
f[i] = f[i-1] * i % mod
invf = [1] * (n + 1)
invf[n] = pow(f[n], mod - 2, mod)
for i in xrange(n - 1, 0, -1):
invf[i] = invf[i+1] * (i + 1) % ... | 1603809300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["9", "10"] | 7dd891cef0aa40cc1522ca4b37963b92 | NoteIn the first example the first spaceship can be positioned at $$$(0, 2)$$$, and the second β at $$$(0, 7)$$$. This way all the enemy spaceships in the first group and $$$6$$$ out of $$$9$$$ spaceships in the second group will be destroyed.In the second example the first spaceship can be positioned at $$$(0, 3)$$$, ... | There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer $$$y$$$-coordinates, and their $$$x$$$-coordinate is equal to $$$-100$$$, while the second group is posit... | Print a single integer β the largest number of enemy spaceships that can be destroyed. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 60$$$), the number of enemy spaceships with $$$x = -100$$$ and the number of enemy spaceships with $$$x = 100$$$, respectively. The second line contains $$$n$$$ integers $$$y_{1,1}, y_{1,2}, \ldots, y_{1,n}$$$ ($$$|y_{1,i}| \le 10\,000$$$) β th... | standard output | standard input | Python 3 | Python | 2,100 | train_004.jsonl | 03cfa6b1362dde3d071465da2638f5e0 | 256 megabytes | ["3 9\n1 2 3\n1 2 3 7 8 9 11 12 13", "5 5\n1 2 3 4 5\n1 2 3 4 5"] | PASSED | from collections import Counter
MV = 400020
a = [0] * MV
for i in range(MV):
a[i] = set()
n ,m = list(map(int , input().split()))
first = list(map(int , input().split()))
second = list(map(int , input().split()))
for fid, f in enumerate(first):
for sid, s in enumerate(second):
a[f+s].add(fid + MV)
... | 1529166900 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
1 second | ["81", "100"] | d3c10d1b1a17ad018359e2dab80d2b82 | null | Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there. The content special agent has got an important task: to get the ... | Print the number of codes that match the given hint. | The first line contains string s β the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0. The input limits for scoring 30 points are (subproblem A1): 1ββ€β|s|ββ€β5. The input limits for scoring 100 poin... | standard output | standard input | Python 2 | Python | 1,400 | train_017.jsonl | 333f971670b81459dff489cde0f78698 | 256 megabytes | ["AJ", "1?AA"] | PASSED | from math import factorial as f
r=raw_input()
t=r.count('?')
l=set('ABCDEFGHIJ')
n=len(set(r)&l)
R=1
c=10
if r[0] in l:
R*=9
n-=1
c-=1
if r[0] == '?':
R*=9
t-=1
R*=f(c)/f(c-n)
print str(R)+ '0'*t | 1371042000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3 0", "0 3", "3 4"] | 96e2ba997eff50ffb805b6be62c56222 | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The... | Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message. | The first line contains line s (1ββ€β|s|ββ€β2Β·105), consisting of uppercase and lowercase English letters β the text of Tanya's message. The second line contains line t (|s|ββ€β|t|ββ€β2Β·105), consisting of uppercase and lowercase English letters β the text written in the newspaper. Here |a| means the length of the string a... | standard output | standard input | Python 3 | Python | 1,400 | train_001.jsonl | 6886ec51284d36ae8382646df871ff7b | 256 megabytes | ["AbC\nDCbA", "ABC\nabc", "abacaba\nAbaCaBA"] | PASSED | s = input()
t = input()
a, b = {}, []
for i in t:
if i in a:
a[i] += 1
else:
a[i] = 1
for i in s:
b.append(i)
res1, res2 = 0, 0
for i in range(len(b)):
if (b[i] in a) and (a[b[i]] > 0):
res1 += 1
a[b[i]] -= 1
b[i] = '0'
for i in b:
t = i
if i.islower():
... | 1424795400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["6", "5"] | 1c64defd239d785acc4e1b622289624d | NoteThese are the possible assignments for the first example: 1 5 3 7 1 2 3 7 5 2 3 7 1 5 7 3 1 2 7 3 5 2 7 3 | A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team asking each engineer the number of the desk they currently sit at,... | Print the number of possible assignments, modulo 1000000007β=β109β+β7. | Input will begin with a line containing N (1ββ€βNββ€β100000), the number of engineers. N lines follow, each containing exactly two integers. The i-th line contains the number of the current desk of the i-th engineer and the number of the desk the i-th engineer wants to move to. Desks are numbered from 1 to 2Β·N. It is gu... | standard output | standard input | Python 3 | Python | 2,100 | train_008.jsonl | de19bb2ce6d7fe3a2509ab8fb0b4b575 | 256 megabytes | ["4\n1 5\n5 2\n3 7\n7 3", "5\n1 10\n2 10\n3 10\n4 10\n5 5"] | PASSED | n = int(input())
m = 2 * n + 1
u = [[] for i in range(m)]
v = [0] * m
s = [0] * m
d = 10 ** 9 + 7
y = 1
for j in range(n):
a, b = map(int, input().split())
v[a] = b
if a != b:
s[b] += 1
u[b].append(a)
for b in range(m):
if not v[b]:
x = 0
p = [b]
while p:
... | 1505583300 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["2\n4\n2", "10\n29\n9"] | 6f6bb98cee5c9e646c72f3be8969c6df | NoteConsider the first test case. $$$b_1 = 1$$$: We need to convert $$$[3, 7] \rightarrow [1, 5]$$$. We can perform the following operations:$$$[3, 7]$$$ $$$\xrightarrow[\text{decrease}]{\text{i = 1}}$$$ $$$[2, 6]$$$ $$$\xrightarrow[\text{decrease}]{\text{i = 1}}$$$ $$$[1, 5]$$$Hence the answer is $$$2$$$. $$$b_1 = 4$... | Jeevan has two arrays $$$a$$$ and $$$b$$$ of size $$$n$$$. He is fond of performing weird operations on arrays. This time, he comes up with two types of operations: Choose any $$$i$$$ ($$$1 \le i \le n$$$) and increment $$$a_j$$$ by $$$1$$$ for every $$$j$$$ which is a multiple of $$$i$$$ and $$$1 \le j \le n$$$. Cho... | Output $$$q$$$ integers Β β the answers to each of his $$$q$$$ questions. | The first line contains a single integer $$$n$$$ $$$(1 \le n \le 2 \cdot 10^{5})$$$ Β β the size of arrays $$$a$$$ and $$$b$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ $$$(1 \le a_i \le 10^6)$$$. The third line contains $$$n$$$ integers $$$b_1, b_2, ..., b_n$$$ $$$(1 \le b_i \le 10^6$$$ for $$... | standard output | standard input | PyPy 3-64 | Python | 2,400 | train_097.jsonl | 6958fd2d6b2dabe0049a9ec06d165f0d | 256 megabytes | ["2\n3 7\n-1 5\n3\n1\n4\n3", "6\n2 5 4 1 3 6\n-1 4 6 2 3 5\n3\n1\n8\n4"] | PASSED | # n = int(input())
# a = list(map(int, input().split()))
# b = list(map(int, input().split()))
#
# q = int(input())
#
# for i in range(q):
# b[0] = int(input())
# c = [a.copy()[i] - b[i] for i in range(n)]
# answer = 0
# k = 1
# while k <= n//2+1:
# j = 1
# e = c.copy(... | 1636727700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
3 seconds | ["3\n6\n3\n3\n10\n3\n2000000000000000000\n3\n4", "200\n300\n100\n100\n50"] | f32b9d3b5c93e566e16c1de963a159a8 | NoteIn the first example:After the first and second queries, the set will contain elements $$$\{0, 1, 2\}$$$. The smallest non-negative number that is divisible by $$$1$$$ and is not in the set is $$$3$$$.After the fourth query, the set will contain the elements $$$\{0, 1, 2, 4\}$$$. The smallest non-negative number th... | This is the hard version of the problem. The only difference is that in this version there are remove queries.Initially you have a set containing one element β $$$0$$$. You need to handle $$$q$$$ queries of the following types:+ $$$x$$$ β add the integer $$$x$$$ to the set. It is guaranteed that this integer is not con... | For each query of type ? output a single integer β the $$$k\text{-mex}$$$ of the set. | The first line contains an integer $$$q$$$ ($$$1 \leq q \leq 2 \cdot 10^5$$$) β the number of queries. The following $$$q$$$ lines describe the queries. An addition query of integer $$$x$$$ is given in the format + $$$x$$$ ($$$1 \leq x \leq 10^{18}$$$). It is guaranteed that $$$x$$$ is not contained in the set. A remov... | standard output | standard input | PyPy 3-64 | Python | 2,400 | train_097.jsonl | f47513b6b0669ed30cac2bec8fb23a1b | 256 megabytes | ["18\n\n+ 1\n\n+ 2\n\n? 1\n\n+ 4\n\n? 2\n\n+ 6\n\n? 3\n\n+ 7\n\n+ 8\n\n? 1\n\n? 2\n\n+ 5\n\n? 1\n\n+ 1000000000000000000\n\n? 1000000000000000000\n\n- 4\n\n? 1\n\n? 2", "10\n\n+ 100\n\n? 100\n\n+ 200\n\n? 100\n\n- 100\n\n? 100\n\n+ 50\n\n? 50\n\n- 50\n\n? 50"] | PASSED | from collections import defaultdict
import math
from sys import stdin
input=lambda :stdin.readline()[:-1]
n=int(input())
query=[]
for i in range(n):
x,y=input().split()
y=int(y)
if x=='+':
query.append((0,y))
elif x=='-':
query.append((1,y))
else:
query.append((2,y))
D=max... | 1666519500 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["2", "32"] | d46d5f130d8c443f28b52096c384fef3 | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | Given an array a1,βa2,β...,βan of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that xβ=βy2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | The first line contains a single integer n (1ββ€βnββ€β1000)Β β the number of elements in the array. The second line contains n integers a1,βa2,β...,βan (β-β106ββ€βaiββ€β106)Β β the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | standard output | standard input | PyPy 3 | Python | 900 | train_002.jsonl | 09dee22b81a441873eb081c8708deafb | 256 megabytes | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | PASSED | import math
def is_sqrt(y):
if y < 0:
return False
elif y == 0:
return True
x = int(math.sqrt(y))
return x * x == y
m = -1000001
n = int(input())
ints = list(map(int, input().split()))
for z in ints:
if not is_sqrt(z) and z > m:
m = z
print(m)
| 1516462500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["7", "0"] | 529aed80a647d181f08d2c26bb14d65d | null | You are given an array $$$a_1, a_2, \dots , a_n$$$ and two integers $$$m$$$ and $$$k$$$.You can choose some subarray $$$a_l, a_{l+1}, \dots, a_{r-1}, a_r$$$. The cost of subarray $$$a_l, a_{l+1}, \dots, a_{r-1}, a_r$$$ is equal to $$$\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$$$, where $$$\lceil x ... | Print the maximum cost of some subarray of array $$$a$$$. | The first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). | standard output | standard input | Python 3 | Python | 1,900 | train_011.jsonl | 72d1b0fa5170a7ec78cc68d0ee4dd9ec | 256 megabytes | ["7 3 10\n2 -4 15 -3 4 8 3", "5 2 1000\n-13 -4 -9 -20 -11"] | PASSED | n, m, k = list(map(int, input().split()));
a = list(map(int, input().split()));
values = list()
for j in range(n):
result = a[j];
sum1 = 0;
for i in range(m):
if j-i>=0:
sum1 = sum1 + a[j-i];
if sum1 > result:
result = sum1;
else:
continu... | 1563806100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1 0 0 1 1"] | 02a0b3cb995f954b216130d703dfc856 | NoteLet us calculate the answer for sample input with root node as 1 and as 2.Root node 1Alice always wins in this case. One possible gameplay between Alice and Bob is: Alice moves one present from node 4 to node 3. Bob moves four presents from node 5 to node 2. Alice moves four presents from node 2 to node 1. Bob ... | Alice and Bob are going to celebrate Christmas by playing a game with a tree of presents. The tree has $$$n$$$ nodes (numbered $$$1$$$ to $$$n$$$, with some node $$$r$$$ as its root). There are $$$a_i$$$ presents are hanging from the $$$i$$$-th node.Before beginning the game, a special integer $$$k$$$ is chosen. The ga... | Output $$$n$$$ integers, where the $$$i$$$-th integer is $$$1$$$ if Alice wins the game when the tree is rooted at node $$$i$$$, or $$$0$$$ otherwise. | The first line contains two space-separated integers $$$n$$$ and $$$k$$$ $$$(3 \le n \le 10^5, 1 \le k \le 20)$$$. The next $$$n-1$$$ lines each contain two integers $$$x$$$ and $$$y$$$ $$$(1 \le x, y \le n, x \neq y)$$$, denoting an undirected edge between the two nodes $$$x$$$ and $$$y$$$. These edges form a tree of ... | standard output | standard input | PyPy 3-64 | Python | 2,500 | train_107.jsonl | 0f9abcad7a7ac1299c59398463220677 | 256 megabytes | ["5 1\n1 2\n1 3\n5 2\n4 3\n0 3 2 4 4"] | PASSED | '''
Hala Madrid!
https://www.zhihu.com/people/li-dong-hao-78-74
'''
import sys
import os
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.... | 1617028500 | [
"math",
"games",
"trees"
] | [
1,
0,
0,
1,
0,
0,
0,
1
] | |
1 second | ["1", "0"] | 04fd1a55027cce56a491b984ce3a1d6d | NoteIn the first example, the given graph is not harmonious (for instance, $$$1 < 6 < 7$$$, node $$$1$$$ can reach node $$$7$$$ through the path $$$1 \rightarrow 2 \rightarrow 7$$$, but node $$$1$$$ can't reach node $$$6$$$). However adding the edge $$$(2, 4)$$$ is sufficient to make it harmonious.In the second e... | You're given an undirected graph with $$$n$$$ nodes and $$$m$$$ edges. Nodes are numbered from $$$1$$$ to $$$n$$$.The graph is considered harmonious if and only if the following property holds: For every triple of integers $$$(l, m, r)$$$ such that $$$1 \le l < m < r \le n$$$, if there exists a path going from n... | Print the minimum number of edges we have to add to the graph to make it harmonious. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 200\ 000$$$ and $$$1 \le m \le 200\ 000$$$). The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \neq v_i$$$), that mean that there's an edge between nodes $$$u$$$ and $$$v$$$.... | standard output | standard input | Python 2 | Python | 1,700 | train_001.jsonl | 7a5e92338dedb167a8d1de5e39808bb0 | 256 megabytes | ["14 8\n1 2\n2 7\n3 4\n6 3\n5 7\n3 8\n6 8\n11 12", "200000 3\n7 9\n9 8\n4 5"] | PASSED | from sys import stdin
from itertools import repeat
def main():
n, m = map(int, stdin.readline().split())
dat = map(int, stdin.read().split(), repeat(10, 2 * m))
par = range(n + 1)
st = []
pu = st.append
for i in xrange(m):
x, y = dat[i*2], dat[i*2+1]
while x != par[x]:
... | 1573914900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["4\n5\n13\n3\n3\n3\n6"] | c783eaf1bf7e4e7321406431030d5aab | NoteOptimal arrays in the test cases of the example: $$$[1, 1, 1, 1]$$$, it has $$$4$$$ minimums and $$$4$$$ maximums; $$$[4, 4, 4, 4, 4]$$$, it has $$$5$$$ minimums and $$$5$$$ maximums; $$$[1, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2]$$$, it has $$$3$$$ minimums and $$$10$$$ maximums; $$$[8, 8, 8]$$$, it has $$$3$$$ mi... | An array is beautiful if both of the following two conditions meet: there are at least $$$l_1$$$ and at most $$$r_1$$$ elements in the array equal to its minimum; there are at least $$$l_2$$$ and at most $$$r_2$$$ elements in the array equal to its maximum. For example, the array $$$[2, 3, 2, 4, 4, 3, 2]$$$ has $$$3$... | For each test case, print one integerΒ β the minimum possible number of elements in a beautiful array. | 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 four integers $$$l_1$$$, $$$r_1$$$, $$$l_2$$$ and $$$r_2$$$ ($$$1 \le l_1 \le r_1 \le 50$$$; $$$1 \le l_2 \le r_2 \le 50$$$). | standard output | standard input | Python 3 | Python | 800 | train_083.jsonl | eb4447b3ec2ebfe8ff04ae16694dfc44 | 512 megabytes | ["7\n\n3 5 4 6\n\n5 8 5 5\n\n3 3 10 12\n\n1 5 3 3\n\n1 1 2 2\n\n2 2 1 1\n\n6 6 6 6"] | PASSED | t = int(input())
for i in range(t):
l1,r1,l2,r2 = map(int,input().split())
if r2 < l1 or r1 < l2:
print(l1 + l2)
else:
print(max(l1,l2)) | 1652452500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nNO\nYES\nNO"] | aae82b2687786818996e4e94c5505d8e | NoteIn the first example we have the list $$$\{4, 2, 2, 7\}$$$, and we have the target $$$k = 5$$$. One way to achieve it is the following: first we choose the third element, obtaining the list $$$\{2, 0, 5\}$$$. Next we choose the first element, obtaining the list $$$\{-2, 3\}$$$. Finally, we choose the first element,... | You are given a list of $$$n$$$ integers. You can perform the following operation: you choose an element $$$x$$$ from the list, erase $$$x$$$ from the list, and subtract the value of $$$x$$$ from all the remaining elements. Thus, in one operation, the length of the list is decreased by exactly $$$1$$$.Given an integer ... | For each test case, print YES if you can achieve $$$k$$$ with a sequence of $$$n-1$$$ operations. Otherwise, print NO. You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer). | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) β the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq n \leq 2\cdot 10^5$$$, $$$1 \leq k \leq 10^9$$$)... | standard output | standard input | PyPy 3-64 | Python | 1,100 | train_091.jsonl | 7917c677c2fe3ecc1852694601d789ce | 256 megabytes | ["4\n\n4 5\n\n4 2 2 7\n\n5 4\n\n1 9 1 3 4\n\n2 17\n\n17 0\n\n2 17\n\n18 18"] | PASSED | def merge(a,b):
A=len(a)
B=len(b)
m=[]
i,j=0,0
while i<A and j<B:
ai,bj=a[i],b[j]
if ai<=bj:
m.append(ai)
i+=1
else:
m.append(b[j])
j+=1
m=m+a[i:A]+b[j:B]
return m
def mergesort(lst):
llst=len(lst)
... | 1648132500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2\n1\n0\n1"] | 178876bfe161ba9ccfd80c9310f75cbc | NoteThe first and second queries are explained in the statement.In the third query, you can assemble $$$1 + 3 = 4$$$ (|+|||=||||) without buying matches.In the fourth query, buy one match and assemble $$$2 + 4 = 6$$$ (||+||||=||||||). | Let's denote correct match equation (we will denote it as CME) an equation $$$a + b = c$$$ there all integers $$$a$$$, $$$b$$$ and $$$c$$$ are greater than zero.For example, equations $$$2 + 2 = 4$$$ (||+||=||||) and $$$1 + 2 = 3$$$ (|+||=|||) are CME but equations $$$1 + 2 = 4$$$ (|+||=||||), $$$2 + 2 = 3$$$ (||+||=||... | For each test case print one integer in single lineΒ β the minimum number of matches which you have to buy for assembling CME. | The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$)Β β the number of queries. The only line of each query contains one integer $$$n$$$ ($$$2 \le n \le 10^9$$$)Β β the number of matches. | standard output | standard input | Python 3 | Python | 800 | train_007.jsonl | 3a9035d41e6d91be346f38a4447ddad9 | 256 megabytes | ["4\n2\n5\n8\n11"] | PASSED | import math
q=int(input())
b=[]
for i in range(q):
a=int(input())
if a%2==0 and a!=2:
b.append(0)
elif a==2:
b.append(2)
else:
b.append(math.ceil(a/2)*2 - a)
for i in range(q):
print(b[i]) | 1570374300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1", "2", "0"] | d9e9c53b391eb44f469cc92fdcf3ea0a | NoteIn the first sample one of the possible solutions is to change the first character to 'b'.In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some numbe... | If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | The first line of the input contains an integer n (1ββ€βnββ€β100β000)Β β the length of the string s. The second line contains the string s of length n consisting of only lowercase English letters. | standard output | standard input | PyPy 3 | Python | 1,000 | train_000.jsonl | 401f9a27abacfb9ed44986432271fab7 | 256 megabytes | ["2\naa", "4\nkoko", "5\nmurat"] | PASSED | n = int(input())
s = list(input())
f = set(s)
if n > 26 :
print('-1')
exit(0)
else:
print(n - len(f))
| 1462984500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["2\n5\n3\n0\n1"] | a6b760941ab8be2c32c6dc66c623ea0e | NoteThe first test case contains the string from the statement. One of the wonderful colorings is shown in the figure. There's no wonderful coloring containing $$$3$$$ or more red letters because the total number of painted symbols will exceed the string's length.The string from the second test case can be painted as f... | This is a simplified version of the problem B2. Perhaps you should read the problem B2 before you start solving B1.Paul and Mary have a favorite string $$$s$$$ which consists of lowercase letters of the Latin alphabet. They want to paint it using pieces of chalk of two colors: red and green. Let's call a coloring of a ... | For each test case, output a separate line containing one non-negative integer $$$k$$$ β the number of letters which will be painted in red in a wonderful coloring. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one non-empty string $$$s$$$ which consists of lowercase letters of the Latin alphabet. The number of characters in the string doesn't exceed $$$50$$$. | standard output | standard input | Python 3 | Python | 800 | train_099.jsonl | 8eb56552d7b27d596d1194f36a026e96 | 256 megabytes | ["5\nkzaaa\ncodeforces\narchive\ny\nxxxxxx"] | PASSED | t = int(input())
for i in range(t):
s = input()
d = {}
r, g = 0, 0
for i in s:
if i not in d:
d[i] = 0
d[i] += 1
c = 0
for key, value in d.items():
if value >= 2:
c += 1
c += 1
print(c // 2) | 1627050900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["odd\neven", "odd\nodd\nodd\neven"] | d20cc952cdf3a99e7d980a0270c49f78 | NoteThe first example: after the first query aβ=β[2,β1,β3], inversion: (2,β1); after the second query aβ=β[2,β3,β1], inversions: (3,β1), (3,β2). The second example: aβ=β[1,β2,β4,β3], inversion: (4,β3); aβ=β[3,β4,β2,β1], inversions: (3,β1), (4,β1), (3,β2), (4,β2), (4,β3); aβ=β[1,β2,β4,β3], inversion: (4,β3); aβ=β[... | A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i,βj) such that iβ>βj and aiβ<βaj. For example, a permutation [4,β1,β3,β2] contains 4 inversions: (2,β1), (3,β1), (4,β1), (4,β3).You are given a... | Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. | The first line contains one integer n (1ββ€βnββ€β1500) β the size of the permutation. The second line contains n integers a1, a2, ..., an (1ββ€βaiββ€βn) β the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1ββ€βmββ€β2Β·105) β the number of queries to process. Then m ... | standard output | standard input | Python 3 | Python | 1,800 | train_014.jsonl | 671cea094718fb26f8a5f182fd98655b | 256 megabytes | ["3\n1 2 3\n2\n1 2\n2 3", "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3"] | PASSED | from sys import stdin, stdout
input, print = stdin.readline, stdout.write
n = int(input())
a = [int(i) for i in input().split()]
c = 0
for i in range(n):
for j in range(i + 1, n):
c += int(a[i] > a[j])
c %= 2
q = int(input())
for i in range(q):
l, r = [int(i) for i in input().split()]
c ^= (r - l) *... | 1514469900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3\n5 1 3 6\n4 2 7\n5\n1 2 8 11 4 13 9 15\n6 14 3 7 10 5 12"] | b75ec87dcc25fdd04c3388a0051b8719 | NoteThe tree in the first test case with the weights of all nodes and edges is shown in the picture. The costs of all paths are: $$$3$$$; $$$3\oplus 7=4$$$; $$$3\oplus 7\oplus 6=2$$$; $$$3\oplus 2=1$$$; $$$3\oplus 2\oplus 1=0$$$; $$$3\oplus 2\oplus 1\oplus 4=4$$$; $$$3\oplus 2\oplus 1\oplus 4\oplus 5=1$$$. The... | After the last regional contest, Hemose and his teammates finally qualified to the ICPC World Finals, so for this great achievement and his love of trees, he gave you this problem as the name of his team "Hemose 3al shagra" (Hemose on the tree).You are given a tree of $$$n$$$ vertices where $$$n$$$ is a power of $$$2$$... | For each test case on the first line print the chosen root. On the second line, print $$$n$$$ integers separated by spaces, where the $$$i$$$-th integer represents the chosen value for the $$$i$$$-th node. On the third line, print $$$n-1$$$ integers separated by spaces, where the $$$i$$$-th integer represents the chose... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 5\cdot 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$p$$$ ($$$1 \le p \le 17$$$), where $$$n$$$ (the number of vertices in the tree) is equal to $$$2^p$$$. Each of the ne... | standard output | standard input | Python 3 | Python | 2,200 | train_100.jsonl | 776793d15c708299bc8a2834604a72d4 | 256 megabytes | ["2\n\n2\n\n1 2\n\n2 3\n\n3 4\n\n3\n\n1 2\n\n2 3\n\n3 4\n\n1 5\n\n1 6\n\n5 7\n\n5 8"] | PASSED | # ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(... | 1651847700 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["1", "6"] | 0054f9e2549900487d78fae9aa4c2d65 | NoteThe first sample corresponds to the picture: The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1,β1). Thus, the answer is 1. | Maria participates in a bicycle race.The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.Let's introduce a system of coordinates, directing the Ox axis from west to east, and the Oy... | Print a single integerΒ β the number of dangerous turns on the track. | The first line of the input contains an integer n (4ββ€βnββ€β1000)Β β the number of straight sections of the track. The following (nβ+β1)-th line contains pairs of integers (xi,βyi) (β-β10β000ββ€βxi,βyiββ€β10β000). The first of these points is the starting position. The i-th straight section of the track begins at the point... | standard output | standard input | Python 3 | Python | 1,500 | train_004.jsonl | 6adc96329128dd853938e428852948d1 | 256 megabytes | ["6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0", "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1"] | PASSED | print ((int(input()) - 4)//2) | 1459353900 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
1 second | ["15", "91"] | 51aa12a683a43f520667cb2f2f421bd8 | NoteFor the first test, the optimal sizes of carrots are $$$\{1,1,1,2,2,2\}$$$. The time taken is $$$1^2+1^2+1^2+2^2+2^2+2^2=15$$$For the second test, the optimal sizes of carrots are $$$\{4,5,5,5\}$$$. The time taken is $$$4^2+5^2+5^2+5^2=91$$$. | There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought $$$n$$$ carrots with lengths $$$a_1, a_2, a_3, \ldots, a_n$$$. However, rabbits are very fertile and multiply very quickly. Zookeeper now has $$$k$$$ rabbits and does not have enough carrots to feed all of them. To solve this problem, Zookeeper dec... | Output one integer: the minimum sum of time taken for rabbits to eat carrots. | The first line contains two integers $$$n$$$ and $$$k$$$ $$$(1 \leq n \leq k \leq 10^5)$$$: the initial number of carrots and the number of rabbits. The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \leq a_i \leq 10^6)$$$: lengths of carrots. It is guaranteed that the sum of $$$a_i$$$ is at leas... | standard output | standard input | PyPy 3 | Python | 2,200 | train_016.jsonl | e5ed43ae25399781199169e264f86807 | 256 megabytes | ["3 6\n5 3 1", "1 4\n19"] | PASSED | """
Author - Satwik Tiwari .
17th Oct , 2020 - Saturday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import By... | 1602939900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES 0\nYES 1\nNO"] | 1501b9f964f793c2746ff5977db4e607 | NoteIn each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red.In the first test, Olya can apply splitting operations in the following order: Olya applies one operation on the only existing square. The condition of Olya's h... | Recently, Olya received a magical square with the size of $$$2^n\times 2^n$$$.It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly $$$k$$$ splitting operations.A Splitting operation is an operation during which Olya takes a square with side $$$a$$$ and cuts it into 4 equal squa... | Print $$$t$$$ lines, where in the $$$i$$$-th line you should output "YES" if it is possible to perform $$$k_i$$$ splitting operations in the $$$i$$$-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the $$$log_2$$$ of the length of t... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^3$$$)Β β the number of tests. Each of the following $$$t$$$ lines contains two integers $$$n_i$$$ and $$$k_i$$$ ($$$1 \le n_i \le 10^9, 1 \le k_i \le 10^{18}$$$)Β β the description of the $$$i$$$-th test, which means that initially Olya's square has size of $... | standard output | standard input | Python 3 | Python | 2,000 | train_002.jsonl | a8aa12db461939822df52fc13fe5e1b0 | 256 megabytes | ["3\n1 1\n2 2\n2 12"] | PASSED | def A(n):
return (4**n-1)//3
L = 31
T = int(input())
for _ in range(T):
n,k = [int(_) for _ in input().split()]
if n > L:
print("YES",n-1)
continue
if k > A(n):
print("NO")
continue
E = 1
M = 0
R = 0
while n >= 0:
M += E
I = 2*E-1
E = 2*E+1
n -= 1
R += I*A(n)
if M <= k and k <= M+R: ... | 1543044900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["0\n2\n3"] | 55a1e9236cac9a6044e74b1975331535 | NoteIn the first example, the array $$$a$$$ is already lexicographically smaller than array $$$b$$$, so no operations are required.In the second example, we can swap $$$5$$$ and $$$3$$$ and then swap $$$2$$$ and $$$4$$$, which results in $$$[3, 5, 1]$$$ and $$$[4, 2, 6]$$$. Another correct way is to swap $$$3$$$ and $$... | You are given two arrays $$$a$$$ and $$$b$$$ of length $$$n$$$. Array $$$a$$$ contains each odd integer from $$$1$$$ to $$$2n$$$ in an arbitrary order, and array $$$b$$$ contains each even integer from $$$1$$$ to $$$2n$$$ in an arbitrary order.You can perform the following operation on those arrays: choose one of the... | For each test case, print one integer: the minimum number of operations needed to make array $$$a$$$ lexicographically smaller than array $$$b$$$. We can show that an answer always exists. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) β the length of the arrays. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldo... | standard output | standard input | Python 3 | Python | 1,400 | train_094.jsonl | 0dcf69ba8089e25a71c821af0844c4e1 | 256 megabytes | ["3\n2\n3 1\n4 2\n3\n5 3 1\n2 4 6\n5\n7 5 9 1 3\n2 4 6 10 8"] | PASSED | def get_input():
al = []
for c in range(int(input())):
input()
a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]
al.append([a,b])
return al
def solve(a,b):
j = 1
di = {}
for i in range(len(a)):
while j < b[i]:
... | 1631975700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["40", "400", "160"] | 2e6bf9154d9da6ac134b52144d5322ca | NoteOne of the optimal sequence of actions in the first sample is: First, remove part 3, cost of the action is 20. Then, remove part 2, cost of the action is 10. Next, remove part 4, cost of the action is 10. At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20β+β10β+β10β+β0β=β4... | On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The c... | Output the minimum total energy the child should spend to remove all n parts of the toy. | The first line contains two integers n and m (1ββ€βnββ€β1000; 0ββ€βmββ€β2000). The second line contains n integers: v1,βv2,β...,βvn (0ββ€βviββ€β105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1ββ€βxi,βyiββ€βn;Β xiββ βyi). Consider all the parts are numbered fro... | standard output | standard input | Python 3 | Python | 1,400 | train_001.jsonl | b844a54d6f487f1eef372cc3c2fc9997 | 256 megabytes | ["4 3\n10 20 30 40\n1 4\n1 2\n2 3", "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4", "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4"] | PASSED | '''
Created on Ω Ω‘β/Ω Ω‘β/Ω’Ω Ω‘Ω₯
@author: mohamed265
'''
t = input().split()
n = int(t[0])
m = int(t[1])
slon = 0
num = [int(x) for x in input().split()]
for i in range(m):
t = input().split()
slon += min(num[int(t[0])-1] , num[int(t[1])-1])
print(slon) | 1401627600 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["-4\n499999998352516354"] | a3705f29b9a8be97a9e9e54b6eccba09 | NoteThe answer for the first sample is explained in the statement. | In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.For example, for nβ=β4 the sum is equal to β-β1β-β2β+β3β-β4β=ββ-β4, because 1, 2 and 4 are 20, 21 and 22 respectively.Calculate the answer for t values of n. | Print the requested sum for each of t integers n given in the input. | The first line of the input contains a single integer t (1ββ€βtββ€β100) β the number of values of n to be processed. Each of next t lines contains a single integer n (1ββ€βnββ€β109). | standard output | standard input | Python 3 | Python | 900 | train_017.jsonl | a19ba99e5f0466bd6ead271b91334e9e | 256 megabytes | ["2\n4\n1000000000"] | PASSED | t = int(input())
import math
tests = []
for _ in range(t):
tests.append(int(input()))
def solve(n):
i,t = int(1),0
while i <= n:
t += i
i *= 2
return t
for n in tests:
s = int((n*(n+1))//2)
m = int(solve(n)*2)
print(int(s-m)) | 1447426800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n2\n10\n12\n10\n15\n106"] | e7f84300e9480a94a2399fcd5f47ecec | NoteIn the first test case, the diverse substring is "7".In the second test case, the only diverse substring is "7", which appears twice, so the answer is $$$2$$$.In the third test case, the diverse substrings are "0" ($$$2$$$ times), "01", "010", "1" ($$$2$$$ times), "10" ($$$2$$$ times), "101" and "1010".In the fourt... | A non-empty digit string is diverse if the number of occurrences of each character in it doesn't exceed the number of distinct characters in it.For example: string "7" is diverse because 7 appears in it $$$1$$$ time and the number of distinct characters in it is $$$1$$$; string "77" is not diverse because 7 appears ... | For each test case print one integerΒ β the number of diverse substrings of the given string $$$s$$$. | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of the string $$$s$$$. The second line of each test case contains a strin... | standard output | standard input | PyPy 3-64 | Python | 1,400 | train_083.jsonl | abf0b20b85ed3e624ef58aedec0e8cdb | 256 megabytes | ["7\n\n1\n\n7\n\n2\n\n77\n\n4\n\n1010\n\n5\n\n01100\n\n6\n\n399996\n\n5\n\n23456\n\n18\n\n789987887987998798"] | PASSED | import sys
input = sys.stdin.readline
print = sys.stdout.write
t = int(input().strip())
def solve(n, a):
s = 0
for i in range(n):
ds, m = {}, 0
for j in range(i, min(n, i+100)):
if a[j] in ds:
ds[a[j]] = ds[a[j]]+1
else:
... | 1668263700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
4 seconds | ["12 6 3 1 \n12 6 2 1 \n8 4 2 1", "14 7 3 1 \n14 6 3 1 \n14 6 2 1"] | d87bbd969c2fcc1541c5d6119e47efae | NoteFollowing are the images of the first 4 levels of the tree in the first test case:Original: After query 1 2 1: After query 2 4 -1: | You have a full binary tree having infinite levels.Each node has an initial value. If a node has value x, then its left child has value 2Β·x and its right child has value 2Β·xβ+β1. The value of the root is 1. You need to answer Q queries. There are 3 types of queries: Cyclically shift the values of all nodes on the same... | For each query of type 3, print the values of all nodes encountered in descending order. | The first line contains a single integer Q (1ββ€βQββ€β105). Then Q queries follow, one per line: Queries of type 1 and 2 have the following format: T X K (1ββ€βTββ€β2; 1ββ€βXββ€β1018; 0ββ€β|K|ββ€β1018), where T is type of the query. Queries of type 3 have the following format: 3 X (1ββ€βXββ€β1018). | standard output | standard input | PyPy 2 | Python | 2,100 | train_028.jsonl | 65cf6f3508f13bf6ca6e240253f5433a | 256 megabytes | ["5\n3 12\n1 2 1\n3 12\n2 4 -1\n3 8", "5\n3 14\n1 5 -3\n3 14\n1 3 1\n3 14"] | PASSED | levels=[[0,0] for i in range(61)]
levels[0][1]=1
for i in range(1,61):
levels[i][1]=2*levels[i-1][1]
import math
q=int(raw_input())
for e in range(q):
s=raw_input().split()
if(s[0]=='3'):
x=int(s[1])
high=int(math.log(x,2))
pos=(x-(levels[high][1]-levels[high][0]))%levels[high][1]
... | 1523117100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["4500.0", "0.0"] | 5aad0a82748d931338140ae81fed301d | NoteA prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime.Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities o... | There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and iβ+β1 are neighbours for all i from 1 to nβ-β1. Sharks n and 1 are neighbours too.Each shark will grow some number of flowers si. For i-th shark value si is random integer equiprobably chosen in range from l... | Print a single real number β the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10β-β6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correc... | The first line of the input contains two space-separated integers n and p (3ββ€βnββ€β100β000,β2ββ€βpββ€β109)Β β the number of sharks and Wet Shark's favourite prime number. It is guaranteed that p is prime. The i-th of the following n lines contains information about i-th sharkΒ β two space-separated integers li and ri (1ββ€β... | standard output | standard input | Python 3 | Python | 1,700 | train_002.jsonl | 4c557b9b9216e632479ee8aa7aaf2275 | 256 megabytes | ["3 2\n1 2\n420 421\n420420 420421", "3 5\n1 4\n2 3\n11 14"] | PASSED | f = lambda: list(map(int, input().split()))
n, p = f()
t = [(l - 1, r) for l, r in [f() for i in range(n)]]
t = [(r // p - l // p) / (r - l) for l, r in t]
print(2000 * sum(t[i] * (2 - t[i - 1]) for i in range(n))) | 1454249100 | [
"number theory",
"math",
"probabilities"
] | [
0,
0,
0,
1,
1,
1,
0,
0
] | |
3 seconds | ["-1", "4"] | fbc119b603ca87787628a3f4b7db8c33 | NoteAssume that Theseus starts at the block (xT,βyT) at the moment 0. | Theseus has just arrived to Crete to fight Minotaur. He found a labyrinth that has a form of a rectangular field of size nβΓβm and consists of blocks of size 1βΓβ1.Each block of the labyrinth has a button that rotates all blocks 90 degrees clockwise. Each block rotates around its center and doesn't change its position ... | If Theseus is not able to get to Minotaur, then print -1 in the only line of the output. Otherwise, print the minimum number of minutes required to get to the block where Minotaur is hiding. | The first line of the input contains two integers n and m (1ββ€βn,βmββ€β1000)Β β the number of rows and the number of columns in labyrinth, respectively. Each of the following n lines contains m characters, describing the blocks of the labyrinth. The possible characters are: Β«+Β» means this block has 4 doors (one door to... | standard output | standard input | PyPy 2 | Python | 2,000 | train_074.jsonl | aaed44c70420c74314cb43c2e57d0899 | 256 megabytes | ["2 2\n+*\n*U\n1 1\n2 2", "2 3\n<><\n><>\n1 1\n2 1"] | PASSED | from collections import deque
import sys
ROTATE = {
"+": "+",
"-": "|",
"|": "-",
"^": ">",
">": "v",
"v": "<",
"<": "^",
"L": "U",
"U": "R",
"R": "D",
"D": "L",
"*": "*"
}
# l, r, u, d
BINARY_MAP = {
"+": (1, 1, 1, 1),
"-": (1, 1, 0, 0),
"|": (0, 0, 1, 1),... | 1464188700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
3 seconds | ["1", "5", "36"] | 1708818cf66de9fa03439f608c897a90 | null | You are given a non-empty string s consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string.In a more formal way, you have to find the quantity of tuples (a,βb,βx,βy) such that 1ββ€βaββ€βbβ<βxββ€βyββ€β|s| and substrings s[a... b], s[x... y] are palindromes.A pali... | Output a single number β the quantity of pairs of non-overlapping palindromic substrings of s. Please do not use the %lld format specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d format specifier. | The first line of input contains a non-empty string s which consists of lowercase letters ('a'...'z'), s contains at most 2000 characters. | standard output | standard input | Python 3 | Python | 1,500 | train_022.jsonl | 23cb2a798349c1b6bbdbdd89752a81b6 | 256 megabytes | ["aa", "aaa", "abacaba"] | PASSED | t = input()
n = len(t)
a, b = [1] * n, [1] * n
for x, y in [(i - 1, i + 1) for i in range(n // 2)]:
while x >= 0 and t[x] == t[y]:
a[y] += 1
b[x] += 1
x -= 1
y += 1
for x, y in [(i, i + 1) for i in range(n // 2)]:
while x >= 0 and t[x] == t[y]:
a[y] += 1
b[x] += ... | 1331280000 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
4 seconds | ["1 4 1 2 3 4 5\n1 4 2 3 4 5 1\n1 4 3 4 5 1 2\n1 4 4 5 1 2 3\n1 4 5 1 2 3 4\n-1 10\n1 1 1 2\n-1 99"] | 20e2cf707d39c22eaf111f12b2ae6d30 | NoteIn the first example, the first tree looks as follows: In the first question, we have $$$p = {1}$$$, and $$$q = {2, 3, 4, 5}$$$. The maximum distance between a node in $$$p$$$ and a node in $$$q$$$ is $$$9$$$ (the distance between nodes $$$1$$$ and $$$5$$$).The second tree is a tree with two nodes with an edge with... | There is a weighted tree with $$$n$$$ nodes and $$$n-1$$$ edges. The nodes are conveniently labeled from $$$1$$$ to $$$n$$$. The weights are positive integers at most $$$100$$$. Define the distance between two nodes to be the sum of edges on the unique path between the nodes. You would like to find the diameter of the ... | null | null | standard output | standard input | Python 3 | Python | 1,700 | train_010.jsonl | b997eb7d0e97a25e7bb4be9c0a5be287 | 256 megabytes | ["2\n5\n9\n6\n10\n9\n10\n2\n99"] | PASSED | import sys
t=int(input())
for _ in range(t):
n=int(input())
max_dist=0
for bit in range(7):
a=[]
b=[]
for i in range(1,n+1):
if (i>>bit)%2:
a.append(i)
else:
b.append(i)
if len(a)==0 or len(b)==0:
... | 1555783500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["2\n2 2 1\n1 3", "3\n1 1 \n2 2 3 \n2 4 5"] | 5acd7b95a44dcb8f72623b51fcf85f1b | NoteIn the first sample you can repair all the roads in two days, for example, if you repair roads 1 and 2 on the first day and road 3 β on the second day. | In Berland there are n cities and nβ-β1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads.In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simultane... | First print number kΒ β the minimum number of days needed to repair all the roads in Berland. In next k lines print the description of the roads that should be repaired on each of the k days. On the i-th line print first number di β the number of roads that should be repaired on the i-th day, and then di space-separated... | The first line of the input contains a positive integer n (2ββ€βnββ€β200β000)Β β the number of cities in Berland. Each of the next nβ-β1 lines contains two numbers ui, vi, meaning that the i-th road connects city ui and city vi (1ββ€βui,βviββ€βn, uiββ βvi). | standard output | standard input | Python 3 | Python | 1,800 | train_052.jsonl | 164ea0c815b3ca86a6bf30510a8df32d | 256 megabytes | ["4\n1 2\n3 4\n3 2", "6\n3 4\n5 4\n3 2\n1 3\n4 6"] | PASSED | import sys
import threading
from collections import defaultdict
def put():
return map(int, input().split())
def dfs(i, p, m):
cnt = 1
z = 0
for j in tree[i]:
if j==p: continue
if cnt==m: cnt+=1
index = edge_index[(i,j)]
ans[cnt].append(index)
z = max(dfs(j,i,cnt... | 1458475200 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["29 28 26 19 0 0 0 \n24907 20705 22805 9514 0 0 0 0 0 0 \n43 43 43 32 38 43 \n3083"] | 437ab04bd029db32ceba31becbe06722 | NoteIn the first testcase the teams from each university for each $$$k$$$ are: $$$k=1$$$: university $$$1$$$: $$$[6], [5], [5], [3]$$$; university $$$2$$$: $$$[8], [1], [1]$$$; $$$k=2$$$: university $$$1$$$: $$$[6, 5], [5, 3]$$$; university $$$2$$$: $$$[8, 1]$$$; $$$k=3$$$: university $$$1$$$: $$$[6, 5, 5... | Polycarp is an organizer of a Berland ICPC regional event. There are $$$n$$$ universities in Berland numbered from $$$1$$$ to $$$n$$$. Polycarp knows all competitive programmers in the region. There are $$$n$$$ students: the $$$i$$$-th student is enrolled at a university $$$u_i$$$ and has a programming skill $$$s_i$$$.... | For each testcase print $$$n$$$ integers: the strength of the regionΒ β the total skill of the members of the present teamsΒ β for each choice of team size $$$k$$$. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$)Β β the number of universities and the number of students. The second line of each testcase contains $$$n$$$ integers $$$u... | standard output | standard input | PyPy 3-64 | Python | 1,400 | train_102.jsonl | e586acdff8ee903e48b7f86d5d56d8e9 | 256 megabytes | ["4\n7\n1 2 1 2 1 2 1\n6 8 3 1 5 1 5\n10\n1 1 1 2 2 2 2 3 3 3\n3435 3014 2241 2233 2893 2102 2286 2175 1961 2567\n6\n3 3 3 3 3 3\n5 9 6 7 9 7\n1\n1\n3083"] | PASSED | for _ in range(int(input())):
n = int(input())
u = list(map(int,input().split()))
s = list(map(int,input().split()))
un = [[] for _ in range(n)]
for i in range(n):
un[u[i]-1].append(s[i])
for i in range(n):
un[i].sort(reverse=True)
ans = [0 for _ in range(n)]
fo... | 1619706900 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["1", "0", "0", "999999999999999999"] | b34846d90dc011f2ef37a8256202528a | NoteIn the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day. In the second sample, Vasiliy could have arrived before breakfast, have had i... | Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how ... | Print single integerΒ β the minimum possible number of meals which Vasiliy could have missed during his vacation. | The only line contains three integers b, d and s (0ββ€βb,βd,βsββ€β1018,ββbβ+βdβ+βsββ₯β1)Β β the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium. | standard output | standard input | Python 2 | Python | 1,200 | train_002.jsonl | b2b1b781e3731b44602a8a7c4b25bb8b | 256 megabytes | ["3 2 1", "1 0 0", "1 1 1", "1000000000000000000 0 1000000000000000000"] | PASSED | m = map(long, raw_input().split())
maxV = max(m)
a = [maxV-1] * 3
idx = 0
for i in range(3):
if maxV == m[i]:
idx = i
break
a[idx] = maxV
ret = 0
for i in range(3):
if a[i] - m[i] > 0:
ret += a[i] - m[i]
print ret | 1476714900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["33", "0", "-1"] | df9942d1eb66b1f3b5c6b665b446cd3e | NoteIn the first example it is enough to erase only the first digit to obtain a multiple of 3. But if we erase the first digit, then we obtain a number with a leading zero. So the minimum number of digits to be erased is two. | A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible.The number is called beautiful if it consists of at least one digit, doesn't have leading zeroe... | Print one number β any beautiful number obtained by erasing as few as possible digits. If there is no answer, print β-β1. | The first line of input contains n β a positive integer number without leading zeroes (1ββ€βnβ<β10100000). | standard output | standard input | Python 3 | Python | 2,000 | train_013.jsonl | 00d9521369a4b3b82d0aaed9003e0722 | 256 megabytes | ["1033", "10", "11"] | PASSED | def checkBeauty (digi):
total = 0
for i in range(0,len(digi)):
total += int(digi[i])
return total % 3
def modThree (digi):
one = []
two = []
for i in range(0,len(digi)):
if int(digi[i]) % 3 == 1:
one.insert(0,i)
elif int(digi[i]) % 3 == 2:
two.insert(0,i)
modResult = []
modResult.append(one)
modRe... | 1490625300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["dbcadabcdbcadabc", "aaaaa"] | 245371912e9828e763a49a85f4f6d2d9 | NoteIn the first test, it is optimal to make one duplication: "dbcadabc" $$$\to$$$ "dbcadabcdbcadabc".In the second test it is optimal to delete the last $$$3$$$ characters, then duplicate the string $$$3$$$ times, then delete the last $$$3$$$ characters to make the string have length $$$k$$$."abcd" $$$\to$$$ "abc" $$$... | This is the hard version of the problem. The only difference is the constraints on $$$n$$$ and $$$k$$$. You can make hacks only if all versions of the problem are solved.You have a string $$$s$$$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $$$s:=s+s$$... | Print the lexicographically smallest string of length $$$k$$$ that can be obtained by doing the operations on string $$$s$$$. | The first line contains two integers $$$n$$$, $$$k$$$ ($$$1 \leq n, k \leq 5\cdot 10^5$$$) β the length of the original string $$$s$$$ and the length of the desired string. The second line contains the string $$$s$$$, consisting of $$$n$$$ lowercase English letters. | standard output | standard input | PyPy 3-64 | Python | 2,200 | train_084.jsonl | 14c9673b25110d0177d42e6fcbb98af6 | 256 megabytes | ["8 16\ndbcadabc", "4 5\nabcd"] | PASSED | import os
import sys
from collections import defaultdict,deque
from io import BytesIO, IOBase
import sys
import threading
# MOD = 998244353
# nmax = 5000
# fact = [1] * (nmax+1)
# for i in range(2, nmax+1):
# fact[i] = fact[i-1] * i % MOD
# inv = [1] * (nmax+1)
# for i in range(2, nmax+1):
# ... | 1624026900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["1", "2", "3", "-1"] | 22a43ccaa9e5579dd193bc941855b47d | NoteIn the first sample, you can choose a subsequence $$$[1]$$$.In the second sample, you can choose a subsequence $$$[6, 6]$$$.In the third sample, you can choose a subsequence $$$[6, 15, 10]$$$.In the fourth sample, there is no such subsequence. | You are given an array $$$a$$$ of length $$$n$$$ that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this array product of whose elements is a perfect square.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be o... | Output the length of the shortest non-empty subsequence of $$$a$$$ product of whose elements is a perfect square. If there are several shortest subsequences, you can find any of them. If there's no such subsequence, print "-1". | The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of $$$a$$$. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$1 \le a_i \le 10^6$$$)Β β the elements of the array $$$a$$$. | standard output | standard input | PyPy 3 | Python | 2,600 | train_051.jsonl | 385ba174208ad7084fa90b6154e03b3c | 256 megabytes | ["3\n1 4 6", "4\n2 3 6 6", "3\n6 15 10", "4\n2 3 5 7"] | PASSED | from sys import stdin
from collections import deque, Counter, defaultdict
N = int(input())
arr = list(map(int, stdin.readline().split()))
MAX = 1_000_005
lp = [0] * MAX
pr = []
pid = {1: 0}
for i in range(2, MAX):
if not lp[i]:
lp[i] = i
pr.append(i)
pid[i] = len(pr)
for p in pr:
if p > lp[i] or i * p >= M... | 1584196500 | [
"number theory",
"graphs"
] | [
0,
0,
1,
0,
1,
0,
0,
0
] | |
1 second | ["3\n2\n1\n1\n3\n1\n2\n1\n2\n3\n2"] | b8833a679d2bbad682cd7865aed9c08c | NoteOne of possible solutions to the example is shown below: | There are $$$n$$$ football teams in the world. The Main Football Organization (MFO) wants to host at most $$$m$$$ games. MFO wants the $$$i$$$-th game to be played between the teams $$$a_i$$$ and $$$b_i$$$ in one of the $$$k$$$ stadiums. Let $$$s_{ij}$$$ be the numbers of games the $$$i$$$-th team played in the $$$j$$$... | For each game in the same order, print $$$t_i$$$ ($$$1 \leq t_i \leq k$$$)Β β the number of the stadium, in which $$$a_i$$$ and $$$b_i$$$ will play the game. If the $$$i$$$-th game should not be played, $$$t_i$$$ should be equal to $$$0$$$. If there are multiple answers, print any. | The first line contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$3 \leq n \leq 100$$$, $$$0 \leq m \leq 1\,000$$$, $$$1 \leq k \leq 1\,000$$$)Β β the number of teams, the number of games, and the number of stadiums. The second line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$1 \leq w_i \leq 1\,000$$$)Β ... | standard output | standard input | PyPy 3 | Python | 3,100 | train_043.jsonl | 537f76cf99d41c936c9f12ba88893688 | 256 megabytes | ["7 11 3\n4 7 8 10 10 9 3\n6 2\n6 1\n7 6\n4 3\n4 6\n3 1\n5 3\n7 5\n7 3\n4 2\n1 4"] | PASSED | import random
import math
def set_color(game, color):
color_count[game[0]][game[2]] -= 1
color_count[game[1]][game[2]] -= 1
game[2] = color
color_count[game[0]][game[2]] += 1
color_count[game[1]][game[2]] += 1
def fix(node):
minimum = math.inf
maximum = 0
for i in range(k):
mi... | 1570374300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["1.0000000000", "2.0000000000"] | 3edd332d8359ead21df4d822af6940c7 | null | Two neighbours, Alan and Bob, live in the city, where there are three buildings only: a cinema, a shop and the house, where they live. The rest is a big asphalt square. Once they went to the cinema, and the film impressed them so deeply, that when they left the cinema, they did not want to stop discussing it.Bob wants ... | In the only line output one number β the maximum distance that Alan and Bob will cover together, discussing the film. Output the answer accurate to not less than 4 decimal places. | The first line contains two integers: t1,βt2 (0ββ€βt1,βt2ββ€β100). The second line contains the cinema's coordinates, the third one β the house's, and the last line β the shop's. All the coordinates are given in meters, are integer, and do not exceed 100 in absolute magnitude. No two given places are in the same buildin... | standard output | standard input | Python 3 | Python | 2,600 | train_041.jsonl | 177bc4e058b7ada0ca9731369f3f034f | 64 megabytes | ["0 2\n0 0\n4 0\n-3 0", "0 0\n0 0\n2 0\n1 0"] | PASSED | __author__ = 'Darren'
def solve():
t1, t2 = map(int, input().split())
cinema = complex(*map(int, input().split()))
house = complex(*map(int, input().split()))
shop = complex(*map(int, input().split()))
cinema_to_house = abs(house - cinema)
cinema_to_shop = abs(shop - cinema)
shop_to_house ... | 1270741500 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["2\n1 2 1 2 2\n2\n2 1 2 1 2 1\n3\n2 3 2 3 1\n1\n1 1 1"] | 1f4c3f5e7205fe556b50320cecf66c89 | null | The round carousel consists of $$$n$$$ figures of animals. Figures are numbered from $$$1$$$ to $$$n$$$ in order of the carousel moving. Thus, after the $$$n$$$-th figure the figure with the number $$$1$$$ follows. Each figure has its own type β the type of the animal corresponding to this figure (the horse, the tiger ... | Print $$$q$$$ answers, for each test case print two lines. In the first line print one integer $$$k$$$ β the minimum possible number of distinct colors of figures. In the second line print $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le k$$$), where $$$c_i$$$ is the color of the $$$i$$$-th figure. If ther... | The input contains one or more test cases. The first line contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) β the number of test cases in the test. Then $$$q$$$ test cases follow. One test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) β the... | standard output | standard input | PyPy 2 | Python | 1,800 | train_004.jsonl | 40cabc85f756d727eeebc1ed81ae27b8 | 256 megabytes | ["4\n5\n1 2 1 2 2\n6\n1 2 2 1 2 2\n5\n1 2 1 2 3\n3\n10 10 10"] | PASSED | from __future__ import division, print_function
import sys
# sys.setrecursionlimit(10**6)
from sys import stdin, stdout
import bisect #c++ upperbound
import math
import heapq
def modinv(n,p):
return pow(n,p-2,p)
def cin():
return map(int,sin().split())
def ain(): #takes ar... | 1585233300 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
2 seconds | ["3\n7\n1\n13\n2"] | 0657ce4ce00addefc8469381c57294fc | NoteFor the first test case, the inversions are initially formed by the pairs of indices ($$$1, 2$$$), ($$$1, 4$$$), ($$$3, 4$$$), being a total of $$$3$$$, which already is the maximum possible.For the second test case, the inversions are initially formed by the pairs of indices ($$$2, 3$$$), ($$$2, 4$$$), ($$$2, 6$$$... | You are given a binary array$$$^{\dagger}$$$ of length $$$n$$$. You are allowed to perform one operation on it at most once. In an operation, you can choose any element and flip it: turn a $$$0$$$ into a $$$1$$$ or vice-versa.What is the maximum number of inversions$$$^{\ddagger}$$$ the array can have after performing ... | For each test case, output a single integer Β β the maximum number of inversions the array can have after performing at most one operation. | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$)Β β the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 2\cdot10^5$$$)Β β the length of the array. The following l... | standard output | standard input | PyPy 3-64 | Python | 1,100 | train_101.jsonl | b6d2b2e944c334bff017206c3bf95be3 | 256 megabytes | ["5\n\n4\n\n1 0 1 0\n\n6\n\n0 1 0 0 1 0\n\n2\n\n0 0\n\n8\n\n1 0 1 1 0 0 0 1\n\n3\n\n1 1 1"] | PASSED | for s in[*open(0)][2::2]:
k=l=m=0;c=s.count('1');n=len(s)//2
for x in map(int,s[::2]):n-=1;k+=x;m=max(m,(n-c,c-n-1)[x]);l+=(x^1)*k
print(l+m) | 1669041300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["2", "0", "1"] | 07cbcf6e1f1e7f1a6ec45241cf9ac2a9 | NoteFor the first example, the initial configuration of the grid is as follows. The only two possible final non-leaking pipe configurations are as follows: For the second example, the initial grid is already leaking, so there will be no final grid that is non-leaking.For the final example, there's only one possibl... | Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of nβΓβm square cells.In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated as follows: Each pipe segment has two ends, illustrated by the arro... | Print a single integer denoting the number of possible final non-leaking pipe systems modulo 1000003 (106β+β3). If there are no such configurations, print 0. | The first line will contain two single-space separated integers n and m (1ββ€βn,βm,βnΒ·mββ€β5Β·105) β the number of rows and columns respectively. Then n lines follow, each contains exactly m characters β the description of the grid. Each character describes a cell and is either one of these: "1" - "4" β a pipe segment ... | standard output | standard input | Python 2 | Python | 2,200 | train_052.jsonl | 352a7b83d05f6f374d044b4a652ede9d | 256 megabytes | ["2 2\n13\n..", "3 1\n1\n4\n.", "2 2\n3.\n.1"] | PASSED | n,m = map(int, raw_input().split())
mp = []
def checkrow(row):
ret = 0
beg = False
ok = True
for j in range(m):
if(mp[row][j] != '.'):
if not beg and (mp[row][j] != '1' and mp[row][j] != '2'):
ok = False
if beg and (mp[row][j] != '3' and mp[row][j] != '4'... | 1316098800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["32"] | 9bd6fea892857d7c94ebce4d4cd46d30 | null | You are given N points on a plane. Write a program which will find the sum of squares of distances between all pairs of points. | The only line of output should contain the required sum of squares of distances between all pairs of points. | The first line of input contains one integer number N (1ββ€βNββ€β100β000) β the number of points. Each of the following N lines contain two integer numbers X and Y (β-β10β000ββ€βX,βYββ€β10β000) β the coordinates of points. Two or more points may coincide. | standard output | standard input | PyPy 3 | Python | 1,700 | train_014.jsonl | e9d8c82acc841864f5c915598411a186 | 256 megabytes | ["4\n1 1\n-1 -1\n1 -1\n-1 1"] | PASSED | #Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threadi... | 1302609600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | 43081557fe2fbac39dd9b72b137b8fb0 | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test ca... | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then ... | For each test case output the required string $$$s$$$ β the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) β the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) β the length of the given code. The second line of the ... | standard output | standard input | PyPy 3-64 | Python | 800 | train_110.jsonl | a73d134fd2ae61615d3be47d57d4c182 | 256 megabytes | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | PASSED | import string
q = int(input())
for i in range(q):
n = int(input())
str = list(input())
def my_function(x):
return x[::-1]
str = my_function(str)
ans = []
while(len(str)):
if int(str[0]) == 0:
ans.append(string.ascii_lowercase[int(str[2] + str[1])-1])
del str[0:3]
else:
ans.appe... | 1662993300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["xab", "?", "cacb"] | a51d2e6e321d7db67687a594a2b85e47 | NoteConsider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot o... | Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.In this task, a pattern will be a string consi... | In a single line print the answer to the problem β the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them. | The first line contains a single integer n (1ββ€βnββ€β105) β the number of patterns. Next n lines contain the patterns. It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does not exceed 10... | standard output | standard input | Python 3 | Python | 1,200 | train_001.jsonl | 3a41770ca9acb5ee9aa1c59b19383724 | 256 megabytes | ["2\n?ab\n??b", "2\na\nb", "1\n?a?b"] | PASSED | import sys
import itertools
WILDCARD = '?'
FILL = 'x'
def main():
pattern_count = int(sys.stdin.readline())
patterns = itertools.islice(sys.stdin, pattern_count)
result = intersect_patterns(p.strip() for p in patterns)
print(result)
def intersect_patterns(lines):
return ''.join(_intersect_patte... | 1397837400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["1\n2\n3\n3\n4\n4\n7", "0\n0\n0\n0"] | e25d4d7decfe6e0f5994f615a268b3aa | NoteIn the first example: After the first query, the array is $$$a=[0]$$$: you don't need to perform any operations, maximum possible MEX is $$$1$$$. After the second query, the array is $$$a=[0, 1]$$$: you don't need to perform any operations, maximum possible MEX is $$$2$$$. After the third query, the array is $$$... | Recall that MEX of an array is a minimum non-negative integer that does not belong to the array. Examples: for the array $$$[0, 0, 1, 0, 2]$$$ MEX equals to $$$3$$$ because numbers $$$0, 1$$$ and $$$2$$$ are presented in the array and $$$3$$$ is the minimum non-negative integer not presented in the array; for the arr... | Print the answer to the initial problem after each query β for the query $$$j$$$ print the maximum value of MEX after first $$$j$$$ queries. Note that queries are dependent (the array changes after each query) but operations are independent between queries. | The first line of the input contains two integers $$$q, x$$$ ($$$1 \le q, x \le 4 \cdot 10^5$$$) β the number of queries and the value of $$$x$$$. The next $$$q$$$ lines describe queries. The $$$j$$$-th query consists of one integer $$$y_j$$$ ($$$0 \le y_j \le 10^9$$$) and means that you have to append one element $$$y... | standard output | standard input | PyPy 2 | Python | 1,600 | train_033.jsonl | 06d7e84741d846d6968c4180d9bdf835 | 256 megabytes | ["7 3\n0\n1\n2\n2\n0\n0\n10", "4 3\n1\n2\n1\n2"] | 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 itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from __builtin__ import xrange a... | 1579703700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3", "4", "2"] | 8cf5d08a319672d9b767d3523eca4df6 | NoteIn the first example initially in the bus could be $$$0$$$, $$$1$$$ or $$$2$$$ passengers.In the second example initially in the bus could be $$$1$$$, $$$2$$$, $$$3$$$ or $$$4$$$ passengers.In the third example initially in the bus could be $$$0$$$ or $$$1$$$ passenger. | The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.If $$$x$$$ is the number of passengers in a bus just before the current bus stop and $$$y$$$ is the number of passengers in the bus just after current bus st... | Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $$$w$$$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. | The first line contains two integers $$$n$$$ and $$$w$$$ $$$(1 \le n \le 1\,000, 1 \le w \le 10^{9})$$$ β the number of bus stops and the capacity of the bus. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(-10^{6} \le a_i \le 10^{6})$$$, where $$$a_i$$$ equals to the number, which has been recorded ... | standard output | standard input | Python 3 | Python | 1,400 | train_019.jsonl | 424f22d64e287927248f09ecc114588c | 256 megabytes | ["3 5\n2 1 -3", "2 4\n-1 1", "4 10\n2 4 1 2"] | PASSED | n,w=map(int,input().split())
a=list(map(int,input().split()))
l=10e7
h=-10e7
s=0
for i in a:
s+=i
l=min(s,l)
h=max(s,h)
x=min(w,w-h)-max(0,-1*l)+1
print(max(0,x)) | 1582202100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["68.538461538\n44.538461538", "-93.666666667\n-74.666666667\n-15.666666667"] | 2432a746446990ecc2926bf00807a5ee | null | On a number line there are n balls. At time moment 0 for each ball the following data is known: its coordinate xi, speed vi (possibly, negative) and weight mi. The radius of the balls can be ignored.The balls collide elastically, i.e. if two balls weighing m1 and m2 and with speeds v1 and v2 collide, their new speeds w... | Output n numbers β coordinates of the balls t seconds after. Output the numbers accurate to at least 4 digits after the decimal point. | The first line contains two integers n and t (1ββ€βnββ€β10,β0ββ€βtββ€β100) β amount of balls and duration of the process. Then follow n lines, each containing three integers: xi, vi, mi (1ββ€β|vi|,βmiββ€β100,β|xi|ββ€β100) β coordinate, speed and weight of the ball with index i at time moment 0. It is guaranteed that no two ba... | standard output | standard input | Python 3 | Python | 2,000 | train_047.jsonl | ffeacc886ae41bce894da2615b06bdf7 | 256 megabytes | ["2 9\n3 4 5\n0 7 8", "3 10\n1 2 3\n4 -5 6\n7 -8 9"] | PASSED | class Ball:
def __init__(self, x, v, m):
self.v = v
self.x = x
self.m = m
def move(self, time):
self.x += self.v * time
def collisionTime(self, other):
if self.v == other.v:
return float("inf")
t = - (self.x - other.x) / (self.v - other.v)
... | 1286802000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["9", "56", "30052700"] | 9d4caff95ab182055f83c79dd88e599a | NoteIn the first sample, there are $$$16$$$ subarrays of length $$$3$$$. In order of appearance, they are:$$$[1, 2, 3]$$$, $$$[2, 3, 1]$$$, $$$[3, 1, 3]$$$, $$$[1, 3, 2]$$$, $$$[3, 2, 2]$$$, $$$[2, 2, 1]$$$, $$$[2, 1, 3]$$$, $$$[1, 3, 2]$$$, $$$[3, 2, 3]$$$, $$$[2, 3, 1]$$$, $$$[3, 1, 3]$$$, $$$[1, 3, 1]$$$, $$$[3, 1, ... | Let $$$n$$$ be an integer. Consider all permutations on integers $$$1$$$ to $$$n$$$ in lexicographic order, and concatenate them into one big sequence $$$p$$$. For example, if $$$n = 3$$$, then $$$p = [1, 2, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 1, 2, 3, 2, 1]$$$. The length of this sequence will be $$$n \cdot n!$$$.Let $$$... | Output a single integerΒ β the number of subarrays of length $$$n$$$ having sum $$$\frac{n(n+1)}{2}$$$, modulo $$$998244353$$$. | The only line contains one integer $$$n$$$Β ($$$1 \leq n \leq 10^6$$$), as described in the problem statement. | standard output | standard input | PyPy 2 | Python | 1,700 | train_021.jsonl | 57d865d2b645d77c39457b58b89d5b4c | 256 megabytes | ["3", "4", "10"] | PASSED | n = int(raw_input())
MOD = 998244353
answer = 1
factorial = 1
for i in range(1, n + 1):
factorial = (factorial * i) % MOD
answer = (i * answer + factorial - i) % MOD
print(answer)
| 1546180500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1", "2", "10"] | 3858151e51f6c97abe8904628b70ad7f | NoteIn the first test case, there is only one domino, and we need the color of its right cell to be different from the color of its left cell. There is only one way to achieve this.In the second test case, there are only $$$2$$$ such colorings:BB WW and WB WB. | You are given $$$n$$$ dominoes. Each domino has a left and a right cell. Each cell can be colored either black or white. Some cells are already colored, while some aren't yet.The coloring is said to be valid if and only if it is possible to rearrange the dominoes in some order such that for each $$$1 \le i \le n$$$ the... | Print a single integer β the answer to the problem. | The first line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) β the number of dominoes. The next $$$n$$$ lines describe dominoes. Each line contains two characters which represent the left and the right cell. Character B means that the corresponding cell is black, character W means that the cor... | standard output | standard input | PyPy 3-64 | Python | 2,400 | train_109.jsonl | a01d005189f62bb6e86b50f7ac01d984 | 256 megabytes | ["1\n?W", "2\n??\nW?", "4\nBB\n??\nW?\n??"] | PASSED | MOD = 998244353
facts = [1]
for i in range(1, 100001):
facts.append(facts[-1] * i % MOD)
def qpow(x, y):
ret = 1
b = x
while y > 0:
if y & 1:
ret = ret * b % MOD
b = b * b % MOD
y >>= 1
return ret
def inv(x):
return qpow(x, MOD - 2)
... | 1639217100 | [
"number theory",
"math",
"graphs"
] | [
0,
0,
1,
1,
1,
0,
0,
0
] | |
2 seconds | ["1 10 0 102 100\n-1\n0 3 100 1 1 2 4\n6 5 10 0 2 3"] | 4b512c39e71e34064c820958dde9f4a1 | NoteThe first set of input data of the example is analyzed in the main part of the statement.In the second set of input data of the example, it is impossible to assign the positive weights to obtain a given permutation of vertices. | You are given a rooted tree consisting of $$$n$$$ vertices. Vertices are numbered from $$$1$$$ to $$$n$$$. Any vertex can be the root of a tree.A tree is a connected undirected graph without cycles. A rooted tree is a tree with a selected vertex, which is called the root.The tree is specified by an array of ancestors $... | For each set of input data print the answer on a separate line. If the solution exists, print an array of $$$n$$$ integers $$$w_1, w_2, \dots, w_n$$$, where $$$w_i$$$ is the weight of the edge that leads from $$$b_i$$$ to $$$i$$$. For the root there is no such edge, so use the value $$$w_i=0$$$. For all other vertices,... | The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of input data sets in the test. Each test case consists of three lines. The first of them contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). It is the number of vertices in the tree. The second line contains $$$n$$... | standard output | standard input | PyPy 3 | Python | 1,500 | train_093.jsonl | 5e30834226d3c708ee6ab052fff93f7d | 256 megabytes | ["4\n5\n3 1 3 3 1\n3 1 2 5 4\n3\n1 1 2\n3 1 2\n7\n1 1 2 3 4 5 6\n1 2 3 4 5 6 7\n6\n4 4 4 4 1 1\n4 2 1 5 6 3"] | PASSED | import io, os
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, namedtuple
from math import gcd, ceil, floor, factorial
from itertools import combinations, permutations
input = sys.stdin.buffer.readline
# input = io.BytesIO(os.read(0,o... | 1637850900 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["0\n2\n0\n3\n0"] | 6aca8c549822adbe96a58aee4b0d4b3f | NoteIn the first test case, the array is good already.In the second test case, one of the possible good arrays is $$$[1, 1, \underline{1}, \underline{1}]$$$ (replaced elements are underlined).In the third test case, the array is good already.In the fourth test case, one of the possible good arrays is $$$[\underline{-2.... | An array $$$a_1, a_2, \ldots, a_n$$$ is good if and only if for every subsegment $$$1 \leq l \leq r \leq n$$$, the following holds: $$$a_l + a_{l + 1} + \ldots + a_r = \frac{1}{2}(a_l + a_r) \cdot (r - l + 1)$$$. You are given an array of integers $$$a_1, a_2, \ldots, a_n$$$. In one operation, you can replace any one e... | For each test case, print one integer: the minimum number of elements that you need to replace to make the given array good. | The first line of input contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$): the number of test cases. Each of the next $$$t$$$ lines contains the description of a test case. In the first line you are given one integer $$$n$$$ ($$$1 \leq n \leq 70$$$): the number of integers in the array. The second line contains $$... | standard output | standard input | PyPy 3-64 | Python | 1,500 | train_101.jsonl | 5a93e5ab76d0219b38187402fe3c0ab5 | 256 megabytes | ["5\n4\n1 2 3 4\n4\n1 1 2 2\n2\n0 -1\n6\n3 -2 4 -1 -4 0\n1\n-100"] | PASSED | import sys
input = sys.stdin.buffer.readline
def gcd(a, b):
if a > b:
a, b = b, a
if b % a==0:
return a
return gcd(b % a, a)
def process(A):
n = len(A)
if n==1:
sys.stdout.write('0\n')
return
d = {}
check = [None for i in range(72**2)]
... | 1640792100 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["NO", "YES"] | 732b5f6aeec05b721122e36116c7ab0c | NoteIn the first case, Sam removes all the stones and Jon loses.In second case, the following moves are possible by Sam: In each of these cases, last move can be made by Jon to win the game as follows: | Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: The game starts with n piles of stones indexed from 1 to n. The i-th pile contains si stones. The players make their moves alternatively. A move is consid... | Print a single line containing "YES" (without quotes) if Jon wins, otherwise print "NO" (without quotes) | First line consists of a single integer n (1ββ€βnββ€β106) β the number of piles. Each of next n lines contains an integer si (1ββ€βsiββ€β60) β the number of stones in i-th pile. | standard output | standard input | Python 3 | Python | 2,100 | train_017.jsonl | 6f9f32231b090a5d134efff2cb3d6688 | 256 megabytes | ["1\n5", "2\n1\n2"] | PASSED | ans=0
for _ in range(int(input())):
ans^=int((8*int(input())+1)**0.5-1)//2
print(['YES', 'NO'][ans>0]) | 1487606700 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
1 second | ["1 1\n6 4"] | 2fa3e88688b92c27ad26a23884e26009 | NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$. | You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divi... | For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them. | The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ Β β the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$. | standard output | standard input | PyPy 2 | Python | 800 | train_001.jsonl | 0ea2cc4bd70562c153c5f7ceb84828e4 | 256 megabytes | ["2\n2\n14"] | PASSED | T = input()
for _ in xrange(T):
x = input()
if x % 2 == 0:
print "%d %d" % (x//2, x//2)
else:
print "1 %d" % (x-1)
| 1584196500 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
2 seconds | ["0.400000000", "0.642857143"] | fb8fbcf3e38457e45a2552bca15a2cf5 | NoteLet's assume that we are given string aβ=βa1a2... a|a|, then let's denote the string's length as |a|, and its i-th character β as ai.A substring a[l... r] (1ββ€βlββ€βrββ€β|a|) of string a is string alalβ+β1... ar.String a is a substring of string b, if there exists such pair of integers l and r (1ββ€βlββ€βrββ€β|b|), that... | Little Elephant loves Furik and Rubik, who he met in a small city Kremenchug.The Little Elephant has two strings of equal length a and b, consisting only of uppercase English letters. The Little Elephant selects a pair of substrings of equal length β the first one from string a, the second one from string b. The choice... | On a single line print a real number β the answer to the problem. The answer will be considered correct if its relative or absolute error does not exceed 10β-β6. | The first line contains a single integer n (1ββ€βnββ€β2Β·105) β the length of strings a and b. The second line contains string a, the third line contains string b. The strings consist of uppercase English letters only. The length of both strings equals n. | standard output | standard input | Python 2 | Python | 2,000 | train_032.jsonl | 85fee5083643132c8b1e894d082b6ab0 | 256 megabytes | ["2\nAB\nBA", "3\nAAB\nCAA"] | PASSED | import sys
import copy
import os
def main(cin):
n = int(cin.readline().strip())
a = cin.readline().strip()
b = cin.readline().strip()
total = 0.0
for i in range(n):
total+=(i+1)*(i+1)
f = 0.0
s = [0 for i in range(30)]
for i in range(n):
s[ord(a[i])-ord('A')]+= i+1
f+= s[ord(b[i])-ord('A')] * (n-i)
s ... | 1342020600 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
2 seconds | ["2", "IMPOSSIBLE"] | 77b5bed410d621fb56c2eaebccff5108 | NoteFor the first sample, an example of a correct height sequence with a maximum of 2: (0,β0,β1,β2,β1,β1,β0,β1).In the second sample the inequality between h7 and h8 does not hold, thus the information is inconsistent. | A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer hi. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i.e. ... | If the notes aren't contradictory, print a single integer β the maximum possible height value throughout the whole route. If the notes do not correspond to any set of heights, print a single word 'IMPOSSIBLE' (without the quotes). | The first line contains two space-separated numbers, n and m (1ββ€βnββ€β108, 1ββ€βmββ€β105)Β β the number of days of the hike and the number of notes left in the journal. Next m lines contain two space-separated integers di and hdi (1ββ€βdiββ€βn, 0ββ€βhdiββ€β108)Β β the number of the day when the i-th note was made and height on... | standard output | standard input | Python 3 | Python | 1,600 | train_024.jsonl | 32835c190c9d3f4511fc97bd989064f4 | 256 megabytes | ["8 2\n2 0\n7 0", "8 3\n2 0\n7 0\n8 3"] | PASSED | def maxheight(start, end):
start_day, start_height = start
end_day, end_height = end
ddays = end_day - start_day
dheight = end_height - start_height
xdays = ddays - abs(dheight)
if xdays < 0:
return -1
else:
return xdays // 2 + max(start_height, end_height)
im... | 1430064000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["cslnb", "cslnb", "sjfnb", "sjfnb"] | dc225c801f55b8d7b40ebcc71b417edb | NoteIn the first example, Tokitsukaze cannot take any stone, so CSL will win.In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.In the third example, Tokitsukaze will win.... | Tokitsukaze and CSL are playing a little game of stones.In the beginning, there are $$$n$$$ piles of stones, the $$$i$$$-th pile of which has $$$a_i$$$ stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A... | Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_1, a_2, \ldots, a_n \le 10^9$$$), which mean the $$$i$$$-th pile has $$$a_i$$$ stones. | standard output | standard input | PyPy 3 | Python | 1,800 | train_001.jsonl | bc8d6485893bdcedcd427ef36d56197e | 256 megabytes | ["1\n0", "2\n1 0", "2\n2 2", "3\n2 3 1"] | PASSED | from collections import defaultdict
FIRST = "sjfnb"
SECOND = "cslnb"
n = int(input())
arr = list(map(int, input().split()))
m = len(set(arr))
if sum(arr) == 0 or arr.count(0) >= 2:
print(SECOND)
exit()
elif m <= n - 2:
print(SECOND)
exit()
elif m == n - 1:
d = defaultdict(int)
for i in arr:
d[i] ... | 1562942100 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
2 seconds | ["0", "1", "2", "3", "3", "12345678901234567890", "GOTO Vasilisa."] | 3060ecad253a2b4d4fac39e91fcd6c95 | null | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the King... | If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). | The first line contains a single number to round up β the integer part (a non-empty set of decimal digits that do not start with 0 β with the exception of a case when the set consists of a single digit β in this case 0 can go first), then follows character Β«.Β» (a dot), and then follows the fractional part (any non-empt... | standard output | standard input | PyPy 3 | Python | 800 | train_003.jsonl | 77591e8070f7dfe0343f22b3d30ba52e | 256 megabytes | ["0.0", "1.49", "1.50", "2.71828182845904523536", "3.14159265358979323846", "12345678901234567890.1", "123456789123456789.999"] | PASSED | import decimal
D=decimal.Decimal
s = input()
place = s.index(".")
last = s[place-1]
next = s[place+1]
#print(last,int(next)<5)
if last == "9": #and int(next)>=5:
print("GOTO Vasilisa.")
#elif last=="9" and int(next)<5:
#print("HI")
#print(s[:place])
elif last!="9" and int(next)>=5:
#pri... | 1311346800 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["3 6\n7 5", "2 9\n6 8", "10 6\n4 5", "9 11\n8 10"] | 4cabc6c5dca6e67a355315040deb11a0 | NoteThe picture corresponding to the first example: The intersection of two paths is $$$2$$$ (vertices $$$1$$$ and $$$4$$$) and the total length is $$$4 + 3 = 7$$$.The picture corresponding to the second example: The intersection of two paths is $$$2$$$ (vertices $$$3$$$ and $$$4$$$) and the total length is $$$5 + 3 = ... | You are given an undirected unweighted tree consisting of $$$n$$$ vertices.An undirected tree is a connected undirected graph with $$$n - 1$$$ edges.Your task is to choose two pairs of vertices of this tree (all the chosen vertices should be distinct) $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ in such a way that neither $$$... | Print any two pairs of vertices satisfying the conditions described in the problem statement. It is guaranteed that it is possible to choose such pairs for the given tree. | The first line contains an integer $$$n$$$ β the number of vertices in the tree ($$$6 \le n \le 2 \cdot 10^5$$$). Each of the next $$$n - 1$$$ lines describes the edges of the tree. Edge $$$i$$$ is denoted by two integers $$$u_i$$$ and $$$v_i$$$, the labels of vertices it connects ($$$1 \le u_i, v_i \le n$$$, $$$u_i \n... | standard output | standard input | Python 3 | Python | 2,500 | train_057.jsonl | d7fc06c43f5ac0df38ca31d3ce142708 | 256 megabytes | ["7\n1 4\n1 5\n1 6\n2 3\n2 4\n4 7", "9\n9 3\n3 5\n1 2\n4 3\n4 7\n1 7\n4 6\n3 8", "10\n6 8\n10 3\n3 7\n5 8\n1 7\n7 2\n2 9\n2 8\n1 4", "11\n1 2\n2 3\n3 4\n1 5\n1 6\n6 7\n5 8\n5 9\n4 10\n4 11"] | PASSED | import sys
n = int(sys.stdin.readline())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
i, j = tuple(int(k) for k in sys.stdin.readline().split())
i -= 1
j -= 1
edges[i].append(j)
edges[j].append(i)
# Prunes the graph starting from the vertices with
# only 1 edge until we reach a vertex wit... | 1540478100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["113337\n1337"] | 9aabacc9817722dc11335eccac5d65ac | null | The subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.You are given an integer $$$n$$$. You have to find a sequence $$$s$$$ consisting of digits $$$\{1, 3, 7\}$$$ such that it has exactly $$$n$$$ subsequences equal to $$$13... | For the $$$i$$$-th query print one string $$$s_i$$$ ($$$1 \le |s_i| \le 10^5$$$) consisting of digits $$$\{1, 3, 7\}$$$. String $$$s_i$$$ must have exactly $$$n_i$$$ subsequences $$$1337$$$. If there are multiple such strings, print any of them. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10$$$) β the number of queries. Next $$$t$$$ lines contains a description of queries: the $$$i$$$-th line contains one integer $$$n_i$$$ ($$$1 \le n_i \le 10^9$$$). | standard output | standard input | PyPy 3 | Python | 1,900 | train_040.jsonl | 51c5581cac1155fb157b78ae2010b466 | 256 megabytes | ["2\n6\n1"] | PASSED | import sys
input = sys.stdin.readline
from bisect import bisect_right
Q = int(input())
Query = [int(input()) for _ in range(Q)]
A = [0]
for t in range(1, 10**5):
A.append(A[-1]+t)
for n in Query:
NUMs = []
while n:
i = bisect_right(A, n)
NUMs.append(i)
n -= A[i-1]
ans = "1"
... | 1565188500 | [
"math",
"strings"
] | [
0,
0,
0,
1,
0,
0,
1,
0
] | |
2 seconds | ["YES\n5 6 7 8\n1 2 3 4", "NO", "YES\n1 2 3 4\n5 6 7 8"] | a36fb51b1ebb3552308e578477bdce8f | NotePay attention to the third example: the figures do not necessarily have to be parallel to the coordinate axes. | Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the ... | Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers β point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line pri... | You are given 8 pairs of integers, a pair per line β the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no two points coincide. | standard output | standard input | Python 3 | Python | 1,600 | train_059.jsonl | e39eddae0688acafb6355f57cc705c06 | 256 megabytes | ["0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2", "0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7", "0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1"] | PASSED | from itertools import permutations as p
l = [list(map(int, input().split())) + [_] for _ in range(1, 9)]
def dist(a, b):
return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2
def rect(a, b, c, d):
return dist(a, b) == dist(c, d) and dist(a, c) == dist(b, d) and dist(a, d) == dist(b, c) and dist(a, b) * dist(b, c) !... | 1323443100 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
1 second | ["-1\n1\n2\n1\n2\n36"] | f3e413954c9c02520fd25bd2cba4747e | NoteIn the third case, $$$4100 = 2050 + 2050$$$.In the fifth case, $$$22550 = 20500 + 2050$$$. | A number is called 2050-number if it is $$$2050$$$, $$$20500$$$, ..., ($$$2050 \cdot 10^k$$$ for integer $$$k \ge 0$$$).Given a number $$$n$$$, you are asked to represent $$$n$$$ as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers required for that. | For each test case, output the minimum number of 2050-numbers in one line. If $$$n$$$ cannot be represented as the sum of 2050-numbers, output $$$-1$$$ instead. | The first line contains a single integer $$$T$$$ ($$$1\le T\leq 1\,000$$$) denoting the number of test cases. The only line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 10^{18}$$$) denoting the number to be represented. | standard output | standard input | PyPy 3-64 | Python | 800 | train_101.jsonl | 0ec72625a943261675a4690af2d46e07 | 256 megabytes | ["6\n205\n2050\n4100\n20500\n22550\n25308639900"] | PASSED | for _ in range(int(input())):
n = int(input())
a = n//2050
if n%2050 != 0:
print(-1)
continue
sum = 0
for i in str(a):
sum += int(i)
if sum:
print(sum)
else:
print(-1) | 1619188500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\n1 3\n3 2\n2 4", "NO", "NO"] | 531746ba8d93a76d5bdf4bab67d9ba19 | NotePossible tree from the first example. Dotted lines show edges you need to remove to get appropriate pairs. | Monocarp has drawn a tree (an undirected connected acyclic graph) and then has given each vertex an index. All indices are distinct numbers from $$$1$$$ to $$$n$$$. For every edge $$$e$$$ of this tree, Monocarp has written two numbers: the maximum indices of the vertices of the two components formed if the edge $$$e$$$... | If there is no such tree that can produce the given list of pairs, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line and the edges of the tree in the next $$$n - 1$$$ lines. Each of the last $$$n - 1$$$ lines should contain two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le ... | The first line contains one integer $$$n$$$ ($$$2 \le n \le 1\,000$$$)Β β the number of vertices in the tree. Each of the next $$$n-1$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ each ($$$1 \le a_i < b_i \le n$$$)Β β the maximal indices of vertices in the components formed if the $$$i$$$-th edge is removed. | standard output | standard input | PyPy 2 | Python | 1,900 | train_040.jsonl | 5ca19367e9cafe4857ecad9cf174b3dc | 256 megabytes | ["4\n3 4\n1 4\n3 4", "3\n1 3\n1 3", "3\n1 2\n2 3"] | PASSED | n = input()
flag = 0
freq = [0] * (n + 1)
for i in xrange(n - 1):
a, b = map(int, raw_input().strip().split())
if b != n:
flag = 1
break
freq[a] += 1
if flag:
print "NO"
exit()
tree = [0] * n
tree[0] = n
free = 0
freeptr = 1
fillptr = 0
for u in xrange(n - 1, 0, -1):
if ... | 1537094100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1", "4"] | 1a73bda2b9c2038d6ddf39918b90da61 | NoteIn the first sample we can add number 9 to array (10,β20,β30). The resulting array (9,β10,β20,β30) will have a median in position , that is, 10.In the second sample you should add numbers 4, 5, 5, 5. The resulting array has median equal to 4. | A median in an array with the length of n is an element which occupies position number after we sort the elements in the non-decreasing order (the array elements are numbered starting with 1). A median of an array (2,β6,β1,β2,β3) is the number 2, and a median of array (0,β96,β17,β23) β the number 17.We define an expre... | Print the only integer β the minimum number of elements Petya needs to add to the array so that its median equals x. | The first input line contains two space-separated integers n and x (1ββ€βnββ€β500, 1ββ€βxββ€β105) β the initial array's length and the required median's value. The second line contains n space-separated numbers β the initial array. The elements of the array are integers from 1 to 105. The array elements are not necessarily... | standard output | standard input | Python 3 | Python | 1,500 | train_002.jsonl | b2490614a4d65c002dc6da8d2a095df7 | 256 megabytes | ["3 10\n10 20 30", "3 4\n1 2 3"] | PASSED | n, x = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
hasx = False
for ai in a:
if ai == x:
hasx = True
val = 0
if not hasx:
a.append(x)
val = 1
a = sorted(a)
while a[(len(a) - 1) // 2] != x:
val += 1
if a[len(a) // 2] > x:
a.insert(0, 0)
else:
a.... | 1332516600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES", "NO", "YES"] | 8ab4db92e595b6a0a4c020693c5f2b24 | NoteIn the first sample, one can act in the following way: Swap second and third columns. Now the table is 1Β 2Β 3Β 4 1Β 4Β 3Β 2 In the second row, swap the second and the fourth elements. Now the table is 1Β 2Β 3Β 4 1Β 2Β 3Β 4 | You are given a table consisting of n rows and m columns.Numbers in each row form a permutation of integers from 1 to m.You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to p... | If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). | The first line of the input contains two integers n and m (1ββ€βn,βmββ€β20)Β β the number of rows and the number of columns in the given table. Each of next n lines contains m integersΒ β elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m. | standard output | standard input | Python 3 | Python | 1,500 | train_019.jsonl | caa3a3a49a0472c997520b68c756d73a | 256 megabytes | ["2 4\n1 3 2 4\n1 3 4 2", "4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3", "3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5"] | PASSED | import sys, re, itertools
rai=lambda x:list(map(int, x.split()))
def pm(a):
for l in a:
print(l)
print()
_use_stdin = True
if _use_stdin:
inp = sys.stdin
else:
inp = open("input.txt", "r")
ls = inp.read().splitlines()
n, m = rai(ls[0])
a = [rai(l) for l in ls[1:]]
b = list(range(1,m+1))
c = []
d... | 1475928900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["48\n4"] | fe9b1527571ea37f402512ac378dee13 | null | We guessed some integer number $$$x$$$. You are given a list of almost all its divisors. Almost all means that there are all divisors except $$$1$$$ and $$$x$$$ in the list.Your task is to find the minimum possible integer $$$x$$$ that can be the guessed number, or say that the input data is contradictory and it is imp... | For each query print the answer to it. If the input data in the query is contradictory and it is impossible to find such number $$$x$$$ that the given list of divisors is the list of almost all its divisors, print -1. Otherwise print the minimum possible $$$x$$$. | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 25$$$) β the number of queries. Then $$$t$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 300$$$) β the number of divisors in the list. The second line of the query contains $$$n$$$ integers $$$d_1, d_2,... | standard output | standard input | PyPy 3 | Python | 1,600 | train_005.jsonl | 413ceadb9fc42985f9f5ddd8107d4bb0 | 256 megabytes | ["2\n8\n8 2 12 6 4 24 16 3\n1\n2"] | PASSED | from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import *
from itertools import *
import functools
import sys
from math import *
from decimal import *
from copy import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10**6+10
MOD = 10**9+7
def isprime(n):
n = abs(int(n))
... | 1557844500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["aad", "daab", "-1", "abczaa"] | a1739619b5ee88e22ae31f4d72bed90a | NoteIn the first sample the given string s is the sought one, consequently, we do not need to change the letter order there. | Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner.Two young parents abac and bbad think what name to give to their first-born child. They decided that the name will be the permutation of letters of string s. To keep u... | Print the sought name or -1 if it doesn't exist. | The first line contains a non-empty string s (1ββ€β|s|ββ€β5000), where |s| is its length. The second line contains a non-empty string t (1ββ€β|t|ββ€β5000), where |t| is its length. Both strings consist of lowercase Latin letters. | standard output | standard input | Python 2 | Python | 1,900 | train_058.jsonl | d2f4ac013460c143026454730cbd9230 | 256 megabytes | ["aad\naac", "abad\nbob", "abc\ndefg", "czaaab\nabcdef"] | PASSED | a = raw_input()
b = raw_input()
c = {}
for i in xrange(26):
c[chr(i + 97)] = 0
for i in xrange(len(a)):
c[a[i]] += 1
pref = ''
ans = chr(255)
for i in xrange(min(len(a), len(b))):
j = chr(ord(b[i]) + 1)
while j <= 'z' and c[j] == 0:
j = chr(ord(j) + 1)
if j <= 'z':
suff = j
c[j] -= 1
for ch, num in sorted(... | 1335078000 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["6", "150352234", "1"] | 385ac4db5b0e7613b03fb4f1044367dd | NoteHere are all the distinct strings for the first example. The chosen letters 'a' and 'b' are there just to show that the characters in $$$A$$$ are different. "aaa" "aab" = "baa" "aba" "abb" = "bba" "bab" "bbb" | Consider some set of distinct characters $$$A$$$ and some string $$$S$$$, consisting of exactly $$$n$$$ characters, where each character is present in $$$A$$$.You are given an array of $$$m$$$ integers $$$b$$$ ($$$b_1 < b_2 < \dots < b_m$$$). You are allowed to perform the following move on the string $$$S$$$:... | Print a single integer β the number of distinct strings of length $$$n$$$ with characters from set $$$A$$$ modulo $$$998244353$$$. | The first line contains three integers $$$n$$$, $$$m$$$ and $$$|A|$$$ ($$$2 \le n \le 10^9$$$, $$$1 \le m \le min(\frac n 2, 2 \cdot 10^5)$$$, $$$1 \le |A| \le 10^9$$$) β the length of the strings, the size of the array $$$b$$$ and the size of the set $$$A$$$, respectively. The second line contains $$$m$$$ integers $$$... | standard output | standard input | Python 3 | Python | 2,300 | train_001.jsonl | 25823da0147cebf9b01a2e9dad63a68f | 256 megabytes | ["3 1 2\n1", "9 2 26\n2 3", "12 3 1\n2 5 6"] | PASSED | n,m,a=map(int,input().split())
b=list(map(int,input().split()))
for i in range(m):
if i==0:
diffs=[b[0]]
else:
diffs.append(b[i]-b[i-1])
powers=[a%998244353]
for i in range(30):
powers.append(powers[-1]**2%998244353)
def power(x,y,binpowers):
prod=1
bits=bin(y)[2:]
bits=bits[::-1... | 1539269400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["50", "119.4"] | 6421a81f85a53a0c8c63fbc32750f77f | NoteIn the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length l. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of p meters per second, and the... | Print a single real numberΒ β the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10β-β4. Namely: let's assume that your answer equals a, and the answer of th... | The first line of the input contains a single integer l (1ββ€βlββ€β1β000)Β β the length of the corridor where the fight takes place. The second line contains integer p, the third line contains integer q (1ββ€βp,βqββ€β500)Β β the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively. | standard output | standard input | Python 3 | Python | 900 | train_024.jsonl | 34651dcd5e51ba9ffb9d79d3a51843d7 | 256 megabytes | ["100\n50\n50", "199\n60\n40"] | PASSED | l=int(input())
p=int(input())
q=int(input())
print(l * p / float(p + q))
| 1445763600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["3\n8 7 9 10 5 6 1 2 3 4", "2\n8 7 10 9 5 6 4 3 2 1", "20\n2 1"] | a375cfcfab66bedb13e3f6f5549cc613 | NoteIn the first example the following pairs of pearls are combined: $$$(7, 9)$$$, $$$(10, 5)$$$, $$$(6, 1)$$$, $$$(2, 3)$$$ and $$$(4, 8)$$$. The beauties of connections equal correspondingly: $$$3$$$, $$$3$$$, $$$3$$$, $$$20$$$, $$$20$$$.The following drawing shows this construction. | Johnny's younger sister Megan had a birthday recently. Her brother has bought her a box signed as "Your beautiful necklaceΒ β do it yourself!". It contains many necklace parts and some magic glue. The necklace part is a chain connecting two pearls. Color of each pearl can be defined by a non-negative integer. The magic ... | The first line should contain a single integer $$$b$$$ denoting the maximum possible beauty of a necklace built from all given parts. The following line should contain $$$2n$$$ distinct integers $$$p_i$$$ $$$(1 \leq p_i \leq 2n)$$$Β β the indices of initial pearls in the order in which they appear on a cycle. Indices of... | The first line contains $$$n$$$ $$$(1 \leq n \leq 5 \cdot 10^5)$$$Β β the number of necklace parts in the box. Each of the next $$$n$$$ lines contains two integers $$$a$$$ and $$$b$$$ $$$(0 \leq a, b < 2^{20})$$$, which denote colors of pearls presented in the necklace parts. Pearls in the $$$i$$$-th line have indice... | standard output | standard input | PyPy 2 | Python | 2,500 | train_058.jsonl | 25d80f4a99574ae9ee6447102525bd6b | 512 megabytes | ["5\n13 11\n11 1\n3 5\n17 1\n9 27", "5\n13 11\n11 1\n3 5\n17 1\n7 29", "1\n1 1"] | PASSED | import sys
range = xrange
input = raw_input
def eulerian_cycle(coupl, V):
for c in coupl:
if len(c) & 1:
return None
m = len(V) >> 1
found = [0]*m
cycle = []
stack = [0]
while stack:
eind = stack.pop()
if eind < 0:
eind = ~eind
c... | 1591281300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["YES\nNO\nYES\nYES"] | 5b1f33228a58d9e14bc9479767532c25 | NoteIn the first example, Monocarp can spend one coin to upgrade weapon (damage will be equal to $$$5$$$), then health during battle will change as follows: $$$(h_C, h_M) = (25, 9) \rightarrow (25, 4) \rightarrow (5, 4) \rightarrow (5, -1)$$$. The battle ended with Monocarp's victory.In the second example, Monocarp has... | Monocarp is playing a computer game. In this game, his character fights different monsters.A fight between a character and a monster goes as follows. Suppose the character initially has health $$$h_C$$$ and attack $$$d_C$$$; the monster initially has health $$$h_M$$$ and attack $$$d_M$$$. The fight consists of several ... | For each test case, print YES if it is possible to slay the monster by optimally choosing the upgrades. Otherwise, print NO. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) β the number of test cases. Each test case consists of three lines: The first line contains two integers $$$h_C$$$ and $$$d_C$$$ ($$$1 \le h_C \le 10^{15}$$$; $$$1 \le d_C \le 10^9$$$) β the character's health and attack; The second line conta... | standard output | standard input | Python 3 | Python | 1,100 | train_104.jsonl | 7e9210984adc3d1498b25f25fc0e583d | 256 megabytes | ["4\n25 4\n9 20\n1 1 10\n25 4\n12 20\n1 1 10\n100 1\n45 2\n0 4 10\n9 2\n69 2\n4 2 7"] | PASSED | n = int(input())
for _ in range(n):
value = "NO"
hc, ac = list(map(int, input().split()))
hm, am = list(map(int, input().split()))
k,w,a = list(map(int, input().split()))
for i in range(0,k+1):
y = ac + (k-i)*w
x = hc + i*a
if(x + am - 1)//am >= (hm + y - 1)//y:
... | 1643639700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["hell no", "abacaba", "asd fasd f"] | 436c00c832de8df739fc391f2ed6dac4 | null | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three... | Print the given word without any changes if there are no typos. If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | standard output | standard input | Python 3 | Python | 1,500 | train_003.jsonl | 81c91eaa2e6aaaf750b74806032f632f | 256 megabytes | ["hellno", "abacaba", "asdfasdf"] | PASSED | q = ['q','w','r','t','p','s','d','f','y','g','h','j','k','l','z','x','c','v','b','n','m']
s = input()
if(len(s)<3):
print(s)
else:
a=s[0]
b=s[1]
print(s[:2],end='')
for i in range(2,len(s)):
if(s[i] in q and a in q and b in q and not(a==b and b==s[i])):
print(' '+s[i],end='')
... | 1505653500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.