prob_desc_time_limit stringclasses 21
values | prob_desc_sample_outputs stringlengths 5 329 | src_uid stringlengths 32 32 | prob_desc_notes stringlengths 31 2.84k β | prob_desc_description stringlengths 121 3.8k | prob_desc_output_spec stringlengths 17 1.16k β | prob_desc_input_spec stringlengths 38 2.42k β | prob_desc_output_to stringclasses 3
values | prob_desc_input_from stringclasses 3
values | lang stringclasses 5
values | lang_cluster stringclasses 1
value | difficulty int64 -1 3.5k β | file_name stringclasses 111
values | code_uid stringlengths 32 32 | prob_desc_memory_limit stringclasses 11
values | prob_desc_sample_inputs stringlengths 5 802 | exec_outcome stringclasses 1
value | source_code stringlengths 29 58.4k | prob_desc_created_at stringlengths 10 10 | tags listlengths 1 5 | hidden_unit_tests stringclasses 1
value | labels listlengths 8 8 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 second | ["2\n2\n1\n2\n1"] | 679a03b57d58907a221689483f59ca34 | NoteIn the first test case the tree looks as follows: Firstly you can choose a bud vertex $$$4$$$ and re-hang it to vertex $$$3$$$. After that you can choose a bud vertex $$$2$$$ and re-hang it to vertex $$$7$$$. As a result, you will have the following tree with $$$2$$$ leaves: It can be proved that it is the minima... | A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Children of the vertex $$$v$$$ are all vertices for which $$$v$$$ is the parent... | For each test case print a single integerΒ β the minimal number of leaves that is possible to get after some operations. | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$)Β β the number of the vertices in the ... | standard output | standard input | PyPy 3-64 | Python | 2,000 | train_091.jsonl | 6cfce800a7eb4cd259f7996cc66e23de | 256 megabytes | ["5\n7\n1 2\n1 3\n1 4\n2 5\n2 6\n4 7\n6\n1 2\n1 3\n2 4\n2 5\n3 6\n2\n1 2\n7\n7 3\n1 5\n1 3\n4 6\n4 7\n2 1\n6\n2 1\n2 3\n4 5\n3 4\n3 6"] | PASSED | from collections import deque
import heapq
from sys import *
input = stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
graph = [set() for _ in range(n+1)]
for i in range(n-1):
c, d = map(int, input().split())
graph[c].add(d)
graph[d].add(c)
dist = [-1] * (n+1)
dist[0] = 0
d... | 1631457300 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["1.000000000000000", "11.142135623730951"] | 8996ae454ba3062e47a8aaab7fb1e33b | NoteThe figure below shows the answer to the first sample. In this sample the best decision is to put the radar at point with coordinates (2,β0). The figure below shows the answer for the second sample. In this sample the best decision is to put the radar at point with coordinates (0,β0). | So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation. Right now the situation in Berland is dismal β their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surrounded... | Print a single real number β the minimum detection radius of the described radar. The answer is considered correct if the absolute or relative error does not exceed 10β-β6. | The input files consist of two lines. Each line represents the city and the flatland ring that surrounds it as three space-separated integers xi, yi, ri (|xi|,β|yi|ββ€β104;Β 1ββ€βriββ€β104) β the city's coordinates and the distance from the city to the flatlanders, correspondingly. It is guaranteed that the cities are loca... | standard output | standard input | Python 3 | Python | 1,800 | train_038.jsonl | baf1b4c501b576d98a7e83619312984b | 256 megabytes | ["0 0 1\n6 0 3", "-10 10 3\n10 -10 3"] | PASSED | x1,y1,r1=map(int,input().split())
x2,y2,r2=map(int,input().split())
d=((x1-x2)**2+(y1-y2)**2)**0.5
x=(d-r1-r2)/2
f=-x-min(r1,r2)
if(x>=0):
print(x)
elif f>=0:
print(f)
else:
print(0)
| 1337182200 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
1 second | ["2 2", "1 3"] | d3b9ffa76436b957ca959cf9204f9873 | NoteIn the first sample the sorted sequence for the given array looks as: (1,β1),β(1,β2),β(2,β1),β(2,β2). The 4-th of them is pair (2,β2).The sorted sequence for the array from the second sample is given in the statement. The 2-nd pair there is (1,β3). | You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing n (not necessarily different) integers a1, a2, ..., an. We are interested in all possible pairs of numbers (ai, aj), (1ββ€βi,βjββ€βn). In other words, let's consider all n2 pairs of numbers, picked from the given array.For exa... | In the single line print two numbers β the sought k-th pair. | The first line contains two integers n and k (1ββ€βnββ€β105,β1ββ€βkββ€βn2). The second line contains the array containing n integers a1, a2, ..., an (β-β109ββ€βaiββ€β109). The numbers in the array can coincide. All numbers are separated with spaces. Please do not use the %lld specificator to read or write 64-bit integers in ... | standard output | standard input | Python 3 | Python | 1,700 | train_010.jsonl | 6df805207ae15aed30874055fb0fdf91 | 256 megabytes | ["2 4\n2 1", "3 2\n3 1 5"] | PASSED | n, k = map(int, input().split())
a = sorted(map(int, input().split()))
x = a[(k - 1) // n]
p, c = a.index(x), a.count(x)
y = ((k - 1) - p * n) // c
print(x, a[y]) | 1331046000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["4\n3\n6\n0"] | 5df6eb50ead22b498bea69bb84341c06 | NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer... | Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy... | For each test case print one integerΒ β the minimum number of hours required to copy the update files to all $$$n$$$ computers. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$)Β β the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) β the number of computers and the number of patch cables. | standard output | standard input | PyPy 3-64 | Python | 1,100 | train_108.jsonl | c3b7ae60be70c29e6a24fb672975b87e | 256 megabytes | ["4\n8 3\n6 6\n7 1\n1 1"] | PASSED | from sys import stdin
# from math import ceil
input = stdin.buffer.readline
def ceil(a, b):
if a % b == 0:
return a // b
return a // b + 1
def func():
cnt = 0
done = 1
while done < n:
# print(f'{done=} {cnt=}')
done += done
cnt += 1
if done >... | 1635518100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2", "0"] | 39232c03c033da238c5d1e20e9595d6d | NoteIn the first sample, Arseniy can repaint the first and the third socks to the second color.In the second sample, there is no need to change any colors. | Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes. Ten minutes before her leave she realized that it would be also useful to prepare instruction of which particular cloth... | Print one integerΒ β the minimum number of socks that should have their colors changed in order to be able to obey the instructions and not make people laugh from watching the socks of different colors. | The first line of input contains three integers n, m and k (2ββ€βnββ€β200β000, 0ββ€βmββ€β200β000, 1ββ€βkββ€β200β000)Β β the number of socks, the number of days and the number of available colors respectively. The second line contain n integers c1, c2, ..., cn (1ββ€βciββ€βk)Β β current colors of Arseniy's socks. Each of the follo... | standard output | standard input | Python 3 | Python | 1,600 | train_034.jsonl | 43a765f39fb1f75feab69cfd80a27cb1 | 256 megabytes | ["3 2 3\n1 2 3\n1 2\n2 3", "3 2 2\n1 1 2\n1 2\n2 1"] | PASSED | def dfs(v, visited, edges, colors):
st = [v]
visited.add(v)
comp = []
cols = dict()
while st:
ver = st.pop()
comp.append(colors[ver])
if ver in edges:
for i in edges[ver]:
if i not in visited:
st.append(i)
vi... | 1476611100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["10\n13\n891\n18\n6237\n0"] | 4be3698735278f29b307a7060eb69693 | NoteFor the first test case Sana can choose $$$x=4$$$ and the value will be ($$$6 \oplus 4$$$) + ($$$12 \oplus 4$$$) = $$$2 + 8$$$ = $$$10$$$. It can be shown that this is the smallest possible value. | In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.Tzuyu gave Sana two integers $$$a$$$ and $$$b$$$ and a really important quest.In order to complete the quest, Sana has to output the smallest possible value of ($$$a \oplus x$$$) + ($$$b \oplus x$$$) for any given $$$x$$$, where $$$\op... | For each testcase, output the smallest possible value of the given expression. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^{4}$$$). Description of the test cases follows. The only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^{9}$$$). | standard output | standard input | PyPy 2 | Python | 800 | train_021.jsonl | 23ba0051ec3acf6a8a644a9a0be4603d | 256 megabytes | ["6\n6 12\n4 9\n59 832\n28 14\n4925 2912\n1 1"] | PASSED |
def main():
t = input()
for _ in xrange(t):
a, b = map(int, raw_input().split(" "))
print a ^ b
if __name__ == '__main__':
main() | 1603011900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["3\n7 3 5", "1\n8"] | f413556df7dc980ca7e7bd1168d700d2 | NoteIn the first example the answer is $$$[7, 3, 5]$$$. Note, that $$$|7-3|=4=2^2$$$, $$$|7-5|=2=2^1$$$ and $$$|3-5|=2=2^1$$$. You can't find a subset having more points satisfying the required property. | There are $$$n$$$ distinct points on a coordinate line, the coordinate of $$$i$$$-th point equals to $$$x_i$$$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note ... | In the first line print $$$m$$$ β the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print $$$m$$$ integers β the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. | The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the number of points. The second line contains $$$n$$$ pairwise distinct integers $$$x_1, x_2, \dots, x_n$$$ ($$$-10^9 \le x_i \le 10^9$$$) β the coordinates of points. | standard output | standard input | Python 3 | Python | 1,800 | train_016.jsonl | 943127077480c3fd4c44b9b0f2d96d3e | 256 megabytes | ["6\n3 5 4 7 10 12", "5\n-1 2 5 8 11"] | PASSED | n=int(input())
a=(set(map(int,input().split())))
ans=[]
f=0
for i in a:
c=1
for p in range(31):
if(i+c in a):
ans=[i,i+c]
if(i+c*2 in a):
print(3)
print(i,i+c,i+c*2)
f=1
break
c*=2
if(f):
break
if... | 1527863700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["16 18 24 27 36 48 54 72 108 144"] | 74713233dd60acfbc0b26cd3772ed223 | null | We'll call a set of positive integers a beautiful if the following condition fulfills: for any prime p, if , then . In other words, if one number from the set is divisible by prime p, then at least half of numbers from the set is divisible by p.Your task is to find any beautiful set, where the number of elements is equ... | In the first line print k space-separated integers that are a beautiful set. If there are multiple such sets, you are allowed to print any of them. | The first line contains integer k (10ββ€βkββ€β5000) that shows how many numbers the required beautiful set should have. | standard output | standard input | Python 2 | Python | 2,300 | train_019.jsonl | 6459aeb385db3db5c3b016b5a23eaf93 | 256 megabytes | ["10"] | PASSED | import sys, math, random
k = int(sys.stdin.read().strip())
if k in [2169, 2198, 2301, 2302, 2303]:
random.seed(0x1337)
else:
random.seed(0x7831505)
res = set()
maxval = 2 * k * k
for p2 in range(0, 1+int(math.log(maxval, 2)) if k > 00 else 1):
for p3 in range(0, 1+int(math.log(maxval, 3)) if ... | 1384875000 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["3\n5\n3\n0"] | f82685f41f4ba1146fea8e1eb0c260dc | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$... | For each test case, output the number of returnable rooms. | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The... | standard output | standard input | PyPy 3 | Python | 1,200 | train_012.jsonl | 1eca4007dede149edbfdfe8b051490db | 256 megabytes | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | PASSED | ans = []
for i in range(int(input())):
n = int(input())
s = list(input())
if '>' in s and '<' in s:
a = 0
for i in range(n):
if s[i] == '-' or s[i - 1] == '-':
a += 1
ans.append(a)
else:
ans.append(n)
print('\n'.join(map(str, ans)))
| 1602939900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["1", "1 1"] | 26fe98904d68cf23c5d24aa85dd92120 | NoteFirst sample: answer is 1, because $$$gcd(1, 2) = 1$$$.Second sample: there are subsets of $$$S$$$ with sizes $$$2, 3$$$ with imperfection equal to 1. For example, $$$\{2,3\}$$$ and $$$\{1, 2, 3\}$$$. | Kate has a set $$$S$$$ of $$$n$$$ integers $$$\{1, \dots, n\} $$$. She thinks that imperfection of a subset $$$M \subseteq S$$$ is equal to the maximum of $$$gcd(a, b)$$$ over all pairs $$$(a, b)$$$ such that both $$$a$$$ and $$$b$$$ are in $$$M$$$ and $$$a \neq b$$$. Kate is a very neat girl and for each $$$k \in \{2,... | Output contains only one line that includes $$$n - 1$$$ integers: $$$I_2$$$, $$$I_3$$$, ..., $$$I_n$$$. | The first and only line in the input consists of only one integer $$$n$$$ ($$$2\le n \le 5 \cdot 10^5$$$) Β β the size of the given set $$$S$$$. | standard output | standard input | Python 3 | Python | 2,200 | train_007.jsonl | cb97b6af1fde01aeda29a0724a947e20 | 256 megabytes | ["2", "3"] | PASSED | def get_primes(n):
res = [2]
arr = [True] * ((n - 1) // 2)
i = 0
for i in range(len(arr)):
if arr[i]:
a = i * 2 + 3
res.append(a)
for ii in range(i + a, len(arr), a):
arr[ii] = False
return res
if __name__ == "__main__":
n = int(... | 1586356500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["18", "40", "400"] | 913925f7b43ad737809365eba040e8da | null | 'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2. The finals will have n questions, m of them are auction questio... | In the single line, print the answer to the problem β the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type. | The first line contains two space-separated integers n and m (1ββ€βn,βmββ€β100;Β mββ€βmin(n,β30)) β the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β107) β the prices of the questions. The third line contains m ... | standard output | standard input | Python 3 | Python | 1,400 | train_017.jsonl | 6f8953652b5dd02d1d4786b5764a669c | 256 megabytes | ["4 1\n1 3 7 5\n3", "3 2\n10 3 8\n2 3", "2 2\n100 200\n1 2"] | PASSED | n, m = map(int, input().split())
prices = list(map(int, input().split()))
normal = []
auct = []
q = list(map(int, input().split()))
sum = 0
for i in range(n):
if i + 1 in q:
auct.append(prices[i])
else:
sum += prices[i]
auct = sorted(auct, reverse=True)
for elem in auct:
sum += max(elem, sum... | 1397977200 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["500000004", "0", "230769233"] | 08b0292d639afd9b52c93a4978f9b2f7 | NoteIn the first sample, the first word can be converted into (1) or (2). The second option is the only one that will make it lexicographically larger than the second word. So, the answer to the problem will be , that is 500000004, because .In the second example, there is no replacement for the zero in the second word ... | Ancient Egyptians are known to have used a large set of symbols to write on the walls of the temples. Fafa and Fifa went to one of the temples and found two non-empty words S1 and S2 of equal lengths on the wall of temple written one below the other. Since this temple is very ancient, some symbols from the words were ... | Print the value , where P and Q are coprime and is the answer to the problem. | The first line contains two integers n and m (1ββ€βn,ββmββ€β105) β the length of each of the two words and the size of the alphabet , respectively. The second line contains n integers a1,βa2,β...,βan (0ββ€βaiββ€βm) β the symbols of S1. If aiβ=β0, then the symbol at position i was erased. The third line contains n integers ... | standard output | standard input | Python 3 | Python | 1,900 | train_006.jsonl | caac0bc3dd3c5a1d7b68f7951094e47b | 256 megabytes | ["1 2\n0\n1", "1 2\n1\n0", "7 26\n0 15 12 9 13 0 14\n11 1 0 13 15 12 0"] | PASSED | def main():
n, m = map(int,input().split())
S1 = list(map(int,input().split()))
S2 = list(map(int,input().split()))
p = 0;
q = 1;
mod = 1000000007
prbq = 1;
for i in range (0,n):
if(S1[i]==S2[i]):
if(S1[i]==0):
p = (p*prbq*2*m+q*(m-1))%mod
... | 1519058100 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
2 seconds | ["3\n3\n3 1 5\n1\n2\n1\n4\n\n2\n2\n1 2\n2\n4 3\n\n1\n7\n1 2 3 4 5 6 7\n\n1\n1\n1\n\n3\n3\n4 1 5\n2\n2 6\n1\n3\n\n3\n2\n2 1\n1\n3\n1\n4"] | cd2a9169186c4ade98548c29bbdacdf0 | null | 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 parents $$$... | For each test case on the first line, output an integer $$$m$$$ β the minimum number of non-intersecting leading down paths that can cover all vertices of the tree. Then print $$$m$$$ pairs of lines containing path descriptions. In the first of them print the length of the path, in the second β the sequence of vertices... | The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases in the test. Each test case consists of two 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$$$ integ... | standard output | standard input | PyPy 3-64 | Python | 1,300 | train_092.jsonl | 56facd38fe646a515bf771004d3d83eb | 256 megabytes | ["6\n\n5\n\n3 1 3 3 1\n\n4\n\n1 1 4 1\n\n7\n\n1 1 2 3 4 5 6\n\n1\n\n1\n\n6\n\n4 4 4 4 1 2\n\n4\n\n2 2 2 2"] | PASSED | # cook your dish here
#!/usr/bin/env python
from bisect import bisect_left
import os
from math import ceil, factorial, fmod,pi,sqrt,log
import sys
from collections import Counter
from io import BytesIO, IOBase, StringIO
def modFact(n, p):
if n >= p:
return 0
result = 1
for i in ran... | 1651761300 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["Yes\n7 2\n2 3\n5 1\n10 4", "No", "Yes\n-10 2\n-20 1"] | f9fd4b42aa1ea3a44a1d05b068a959ba | NoteIn the first sample, Ujan can put the number $$$7$$$ in the $$$2$$$nd box, the number $$$2$$$ in the $$$3$$$rd box, the number $$$5$$$ in the $$$1$$$st box and keep the number $$$10$$$ in the same $$$4$$$th box. Then the boxes will contain numbers $$$\{1,5,4\}$$$, $$$\{3, 7\}$$$, $$$\{8,2\}$$$ and $$$\{10\}$$$. The... | Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers.There are $$$k$$$ boxes numbered from $$$1$$$ to $$$k$$$. The $$$i$$$-th box contains $$$n_i$$$ integer numbers. The integers can be negative. All of the integers are distinct. Ujan is lazy, so he will do the follow... | If Ujan cannot achieve his goal, output "No" in a single line. Otherwise in the first line output "Yes", and then output $$$k$$$ lines. The $$$i$$$-th of these lines should contain two integers $$$c_i$$$ and $$$p_i$$$. This means that Ujan should pick the integer $$$c_i$$$ from the $$$i$$$-th box and place it in the $$... | The first line contains a single integer $$$k$$$ ($$$1 \leq k \leq 15$$$), the number of boxes. The $$$i$$$-th of the next $$$k$$$ lines first contains a single integer $$$n_i$$$ ($$$1 \leq n_i \leq 5\,000$$$), the number of integers in box $$$i$$$. Then the same line contains $$$n_i$$$ integers $$$a_{i,1}, \ldots, a_... | standard output | standard input | PyPy 3 | Python | 2,400 | train_030.jsonl | 814411766c87e15ba8e3375eafe532f7 | 256 megabytes | ["4\n3 1 7 4\n2 3 2\n2 8 5\n1 10", "2\n2 3 -2\n2 -1 5", "2\n2 -10 10\n2 0 -20"] | PASSED | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
k = int(input())
d = {}
aa = []
sa = []
for i in range(k):
ni, *a = map(int, input().split())
for ai in a:
d[ai] = i
aa.append(a)
sa.append(sum(a))
s = sum(sa)
if s%k != 0:
print("No")
exit()
s //= k
def calc_... | 1573052700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"] | b0bce8524eb69b695edc1394ff86b913 | NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the m... | This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slo... | null | The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$Β β the size of the array and the number of s... | standard output | standard input | Python 3 | Python | 2,100 | train_007.jsonl | 429138f3188e7352bda69192dd514eb8 | 256 megabytes | ["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"] | PASSED | from sys import stdin,stdout
T=int(stdin.readline().strip())
def query(l,r):
print("?",end=" ")
c=0
for i in range(l,r+1):
for j in s[i]:
c+=1
print(c,end=" ")
for i in range(l,r+1):
for j in s[i]:
print(j,end=" ")
print()
stdout.flush()
x=int... | 1590935700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["10", "55", "15"] | 9329cb499f003aa71c6f51556bcc7b05 | NoteIn the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.In the second example Vova has to bribe everyone.In the third example ... | Vova promised himself that he would never play computer games... But recently Firestorm β a well-known game developing company β published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.Now he tries to solve a quest. The task is to come to a settlement named Overc... | Print one number β the minimum amount of gold Vova has to spend in order to finish the quest. | The first line contains two integer numbers n and m (1ββ€βnββ€β105,β0ββ€βmββ€β105) β the number of characters in Overcity and the number of pairs of friends. The second line contains n integer numbers ci (0ββ€βciββ€β109) β the amount of gold i-th character asks to start spreading the rumor. Then m lines follow, each containi... | standard output | standard input | Python 3 | Python | 1,300 | train_042.jsonl | a5b56a59dc39992d8c81d46317e40810 | 256 megabytes | ["5 2\n2 5 3 4 8\n1 4\n4 5", "10 0\n1 2 3 4 5 6 7 8 9 10", "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10"] | PASSED | n, m = map(int, input().split())
vs = list(map(int, input().split()))
if m == 0:
print(sum(vs))
exit()
# n = 100000
# m = n - 1
# vs = [0] * n
es = {i: [] for i in range(n)}
visited = {i: False for i in range(n)}
comps = []
# def dfs(vv, compp):
# # global visited, es
# if visited[vv]:
# retur... | 1511449500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["5", "10", "500000003", "169316356"] | 953b8d9405d418b6e9475a845a31b0b2 | null | A false witness that speaketh lies!You are given a sequence containing n integers. There is a variable res that is equal to 0 initially. The following process repeats k times.Choose an index from 1 to n uniformly at random. Name it x. Add to res the multiply of all ai's such that 1ββ€βiββ€βn, but iββ βx. Then, subtract ax... | Output a single integerΒ β the value . | The first line contains two integers n and k (1ββ€βnββ€β5000, 1ββ€βkββ€β109) β the number of elements and parameter k that is specified in the statement. The second line contains n space separated integers a1,βa2,β...,βan (0ββ€βaiββ€β109). | standard output | standard input | PyPy 2 | Python | 3,000 | train_056.jsonl | 0546d4a647fa44824cf2d78123cf6984 | 256 megabytes | ["2 1\n5 5", "1 10\n80", "2 2\n0 0", "9 4\n0 11 12 9 20 7 8 18 2"] | PASSED | n, k = map(int, raw_input().split())
p = 1000000007
f = [1]
for x in map(int, raw_input().split()):
f.append(0)
for i in range(len(f) - 1)[::-1]:
f[i + 1] = (f[i + 1] + f[i] * x) % p
z = 0
t = 1
for i in range(n + 1)[::-1]:
z = (z + f[i] * pow(-1, n - i, p) % p * t) % p
t = t * (k - n + i) % p * pow(n, p - 2, p) ... | 1510929300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["4", "11"] | 90cd4a83d3d7826a2385fcea434ae071 | null | Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings β input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input data contains the substring s1, the second enters an infinite loop i... | Output one number β what is minimal length of the string, containing s1, s2 and s3 as substrings. | There are exactly 3 lines in the input data. The i-th line contains string si. All the strings are non-empty, consists of lowercase Latin letters, the length of each string doesn't exceed 105. | standard output | standard input | PyPy 3 | Python | 2,200 | train_077.jsonl | 24b4f8832ed10ca3779334876bdb35ce | 256 megabytes | ["ab\nbc\ncd", "abacaba\nabaaba\nx"] | PASSED | import sys
from array import array # noqa: F401
from itertools import permutations
def input():
return sys.stdin.buffer.readline().decode('utf-8')
class RollingHash(object):
__slots__ = ['hash1', 'hash2']
from random import randint
N = 10**5 + 100
BASE = randint(1000, 9999)
MOD1, MOD2 = 1... | 1280761200 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
4 seconds | ["GGG\nMGG\nMGG"] | 0e909868441b3af5be297f44d3459dac | null | Marin feels exhausted after a long day of cosplay, so Gojou invites her to play a game!Marin and Gojou take turns to place one of their tokens on an $$$n \times n$$$ grid with Marin starting first. There are some restrictions and allowances on where to place tokens: Apart from the first move, the token placed by a pl... | You should print $$$n$$$ lines. In the $$$i$$$-th line, print $$$n$$$ characters, where the $$$j$$$-th character is the result of the game in which Marin places her first token in the cell $$$(i, j)$$$. Print 'M' if Marin wins, 'G' if Gojou wins, and 'D' if the game ends in a draw. Do not print spaces between the chara... | The first line contains two integers $$$n$$$, $$$k$$$ ($$$3 \le n \le 2000$$$, $$$1 \leq k \leq n - 2$$$). Note that under these constraints it is always possible to make a move. The following $$$n$$$ lines contains $$$n$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is $$$v_{i,j}$$$ ($$$1 \le v_{i,j} ... | standard output | standard input | PyPy 3 | Python | 2,500 | train_095.jsonl | d8009d79447155bc6847efa7829010b3 | 256 megabytes | ["3 1\n1 2 4\n6 8 3\n9 5 7"] | PASSED | import heapq
import os
import sys
from io import BytesIO, IOBase
_str = str
str = lambda x=b"": x if type(x) is bytes else _str(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
... | 1648391700 | [
"number theory",
"math",
"games"
] | [
1,
0,
0,
1,
1,
0,
0,
0
] | |
3 seconds | ["1 2 3", "1 4 3 2 5", "1 4 3 7 9 8 6 5 2 10"] | 157630371c4f6c3bcc6355d96c86a626 | NoteIn the first sample, Bob's optimal wandering path could be $$$1 \rightarrow 2 \rightarrow 1 \rightarrow 3$$$. Therefore, Bob will obtain the sequence $$$\{1, 2, 3\}$$$, which is the lexicographically smallest one.In the second sample, Bob's optimal wandering path could be $$$1 \rightarrow 4 \rightarrow 3 \rightarro... | Lunar New Year is approaching, and Bob decides to take a wander in a nearby park.The park can be represented as a connected graph with $$$n$$$ nodes and $$$m$$$ bidirectional edges. Initially Bob is at the node $$$1$$$ and he records $$$1$$$ on his notebook. He can wander from one node to another through those bidirect... | Output a line containing the lexicographically smallest sequence $$$a_1, a_2, \ldots, a_n$$$ Bob can record. | The first line contains two positive integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^5$$$), denoting the number of nodes and edges, respectively. The following $$$m$$$ lines describe the bidirectional edges in the graph. The $$$i$$$-th of these lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_... | standard output | standard input | PyPy 2 | Python | 1,500 | train_000.jsonl | 0b64c1cff94b4616efd1fad9436d405f | 256 megabytes | ["3 2\n1 2\n1 3", "5 5\n1 4\n3 4\n5 4\n3 2\n1 5", "10 10\n1 4\n6 8\n2 5\n3 7\n9 4\n5 6\n3 4\n8 10\n8 9\n1 10"] | PASSED | import heapq
from collections import defaultdict
n,m = [int(x) for x in raw_input().split(' ')]
arr = list()
d = defaultdict(list)
for _ in range(m):
el = [int(x) for x in raw_input().split(' ')]
d[el[0]].append(el[1])
d[el[1]].append(el[0])
vis = []
cur = set()
q = []
heapq.heappush(q, 1)
cur.add(1)
whil... | 1548938100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["NO\nYES\nNO\nNO\nYES\nYES\nYES"] | b4ca6a5ee6307ab2bcdab2ea5dd5b2b3 | NoteThe number $$$1$$$ is not representable as the sum of two cubes.The number $$$2$$$ is represented as $$$1^3+1^3$$$.The number $$$4$$$ is not representable as the sum of two cubes.The number $$$34$$$ is not representable as the sum of two cubes.The number $$$35$$$ is represented as $$$2^3+3^3$$$.The number $$$16$$$ ... | You are given a positive integer $$$x$$$. Check whether the number $$$x$$$ is representable as the sum of the cubes of two positive integers.Formally, you need to check if there are two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b$$$) such that $$$a^3+b^3=x$$$.For example, if $$$x = 35$$$, then the numbers $$$a=2$$$ and... | For each test case, output on a separate line: "YES" if $$$x$$$ is representable as the sum of the cubes of two positive integers. "NO" otherwise. You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive). | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then $$$t$$$ test cases follow. Each test case contains one integer $$$x$$$ ($$$1 \le x \le 10^{12}$$$). Please note, that the input for some test cases won't fit into $$$32$$$-bit integer type, so you should use at least $$... | standard output | standard input | Python 3 | Python | 1,100 | train_098.jsonl | ad0894c36d39fabf56cde54fe89afedc | 256 megabytes | ["7\n1\n2\n4\n34\n35\n16\n703657519796"] | PASSED | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Codeforces Round #702 (Div. 3)
Problem C. Sum of Cubes
:author: Kitchen Tong
:mail: kctong529@gmail.com
Please feel free to contact me if you have any question
regarding the implementation below.
"""
__version__ = '3.1'
__date__ = '2021-03-13'
import sy... | 1613486100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["3 1 3\n3 2 2", "2 3 3\n5 3 3\n4 3 2\n1 6 0\n2 1 0"] | b1ece35f190b13a3dfd64ab30c905765 | null | The board has got a painted tree graph, consisting of n nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesn't contain any cycles.Each node of the graph is painted black or white in such a manner that there aren't two nodes of the same color, connected by an edge. Each edge c... | Print the description of nβ-β1 edges of the tree graph. Each description is a group of three integers vi, ui, wi (1ββ€βvi,βuiββ€βn, viββ βui, 0ββ€βwiββ€β109), where vi and ui β are the numbers of the nodes that are connected by the i-th edge, and wi is its value. Note that the following condition must fulfill cviββ βcui. It ... | The first line of the input contains a single integer n (2ββ€βnββ€β105) β the number of nodes in the tree. Next n lines contain pairs of space-separated integers ci, si (0ββ€βciββ€β1, 0ββ€βsiββ€β109), where ci stands for the color of the i-th vertex (0 is for white, 1 is for black), and si represents the sum of values of the... | standard output | standard input | Python 2 | Python | 2,100 | train_058.jsonl | 48e076e8dc60a0ff5f9af4c4eef54a17 | 256 megabytes | ["3\n1 3\n1 2\n0 5", "6\n1 0\n0 3\n1 8\n0 2\n0 3\n0 0"] | PASSED | n = input()
a = []
b = []
for i in range(n):
c, s = map(int, raw_input().split())
[a, b][c] += [[s, i + 1]]
r = []
for _ in range(1, n):
s, i = a[-1]
S, I = b[-1]
v = min(s, S)
a[-1][0] -= v
b[-1][0] -= v
r += [[i, I, v]]
[b, a][s < S or s == S and len(a) > 1].pop()
print '\n'.join(' '.join(map(str, x)) for x ... | 1356622500 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["YES", "NO", "YES", "NO"] | 1173d89dd3af27b46e579cdeb2cfdfe5 | NoteThe drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2,β3) are friends and members (3,β4) are friends, while members (2,β4) are not. | Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).There are n members, numbered 1 through n. m pairs of members are friends. Of course, a member can't be a friend with themselves.Let A-B denote that members A... | If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes). | The first line of the input contain two integers n and m (3ββ€βnββ€β150β000, )Β β the number of members and the number of pairs of members that are friends. The i-th of the next m lines contains two distinct integers ai and bi (1ββ€βai,βbiββ€βn,βaiββ βbi). Members ai and bi are friends with each other. No pair of members wil... | standard output | standard input | Python 2 | Python | 1,500 | train_030.jsonl | bb95361cae782c6c4f109cb99a0d8c54 | 256 megabytes | ["4 3\n1 3\n3 4\n1 4", "4 4\n3 1\n2 3\n3 4\n1 2", "10 4\n4 3\n5 10\n8 9\n1 2", "3 2\n1 2\n2 3"] | PASSED | n, m = map(int, raw_input().split())
visited = [False for i in xrange(n+1)]
graph = [[] for i in xrange(n+1)]
for i in xrange(m):
a, b = map(int, raw_input().split())
graph[a].append(b)
graph[b].append(a)
def dfs(node, countV = 0, countE = 0):
stack = [node]
while stack:
top = stack.p... | 1489851300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
10 seconds | ["-1\n1\n2\n-1\n1"] | f2988e4961231b9b38ca8fa78373913f | Notegcd(x,βy) is greatest common divisor of two integers x and y. | Caisa is now at home and his son has a simple task for him.Given a rooted tree with n vertices, numbered from 1 to n (vertex 1 is the root). Each vertex of the tree has a value. You should answer q queries. Each query is one of the following: Format of the query is "1 v". Let's write out the sequence of vertices along... | For each query of the first type output the result of the query. | The first line contains two space-separated integers n, q (1ββ€βn,βqββ€β105). The second line contains n integers a1,βa2,β...,βan (1ββ€βaiββ€β2Β·106), where ai represent the value of node i. Each of the next nβ-β1 lines contains two integers xi and yi (1ββ€βxi,βyiββ€βn;Β xiββ βyi), denoting the edge of the tree between vertice... | standard output | standard input | PyPy 2 | Python | 2,100 | train_016.jsonl | d47127a5d8df0ea6169b29bac86b8584 | 256 megabytes | ["4 6\n10 8 4 3\n1 2\n2 3\n3 4\n1 1\n1 2\n1 3\n1 4\n2 1 9\n1 4"] | PASSED | from sys import stdin, setrecursionlimit
setrecursionlimit(1000000007)
_data = iter(map(int, stdin.read().split()))
V = 2100000
n, q = next(_data), next(_data)
a = [next(_data) for _ in range(n)]
g = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = next(_data) - 1, next(_data) - 1
g[u].append(v)
g[v].ap... | 1409383800 | [
"number theory",
"math",
"trees"
] | [
0,
0,
0,
1,
1,
0,
0,
1
] | |
1 second | ["L"] | 77093f12ff56d5f404e9c87650d4aeb4 | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n... | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer a (1ββ€βaββ€β2) which denotes the number of the rail at... | output.txt | input.txt | Python 3 | Python | 1,000 | train_021.jsonl | 69683f17f53972526c92798095e35fbb | 256 megabytes | ["front\n1"] | PASSED | fi = open('input.txt', 'r')
d, a = fi.readline().strip() == 'front', int(fi.readline()) == 1
print('L' if d == a else 'R', file=open('output.txt', 'w')) | 1318919400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2\n1"] | 740c05c036b646d8fb6b391af115d7f0 | NoteIn the first test case, there are the following $$$2$$$ ways to fill the area: In the second test case, there is a unique way to fill the area: | You have integer $$$n$$$. Calculate how many ways are there to fully cover belt-like area of $$$4n-2$$$ triangles with diamond shapes. Diamond shape consists of two triangles. You can move, rotate or flip the shape, but you cannot scale it. $$$2$$$ coverings are different if some $$$2$$$ triangles are covered by the sa... | For each test case, print the number of ways to fully cover belt-like area of $$$4n-2$$$ triangles using diamond shape. It can be shown that under given constraints this number of ways doesn't exceed $$$10^{18}$$$. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^{4}$$$)Β β the number of test cases. Each of the next $$$t$$$ lines contains a single integer $$$n$$$ ($$$1 \le n \le 10^{9}$$$). | standard output | standard input | Python 3 | Python | 900 | train_000.jsonl | 5741d0e534d895dc9acc7bfb902dad7a | 256 megabytes | ["2\n2\n1"] | PASSED | t=int(input())
N=[0]*t
for i in range(t):
N[i]=int(input())
for i in range(t):
print(N[i]) | 1586700300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2", "1"] | d28614f0365ea53530e35c6bd1e6f1dd | NoteIn first sample the common divisors are strings "abcd" and "abcdabcd".In the second sample the common divisor is a single string "a". String "aa" isn't included in the answer as it isn't a divisor of string "aaa". | Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string "a... | Print the number of common divisors of strings s1 and s2. | The first input line contains a non-empty string s1. The second input line contains a non-empty string s2. Lengths of strings s1 and s2 are positive and do not exceed 105. The strings only consist of lowercase Latin letters. | standard output | standard input | PyPy 3 | Python | 1,400 | train_025.jsonl | 04af7dae66afff12e57cf3f40fe3ba93 | 256 megabytes | ["abcdabcd\nabcdabcdabcdabcd", "aaa\naa"] | PASSED |
from math import sqrt
from collections import defaultdict
from bisect import bisect_right
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den,
p - 2, p)) % p
from sys import stdin
def ret(s):
... | 1335280200 | [
"math",
"strings"
] | [
0,
0,
0,
1,
0,
0,
1,
0
] | |
2 seconds | ["1\n2 3 4 4", "0\n3 2 2 5 3", "2\n2 3 7 8 1 6 6 7"] | 148a5ecd4afa1c7c60c46d9cb4a57208 | NoteIn the first sample, it's enough to change one element. In the provided output, a sequence represents a tree rooted in a vertex 4 (because p4β=β4), which you can see on the left drawing below. One of other correct solutions would be a sequence 2 3 3 2, representing a tree rooted in vertex 3 (right drawing below). O... | A tree is an undirected connected graph without cycles.Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1,βp2,β...,βpn, where pi denotes a parent of vertex i (here, for convenience a root is consid... | In the first line print the minimum number of elements to change, in order to get a valid sequence. In the second line, print any valid sequence possible to get from (a1,βa2,β...,βan) in the minimum number of changes. If there are many such sequences, any of them will be accepted. | The first line of the input contains an integer n (2ββ€βnββ€β200β000)Β β the number of vertices in the tree. The second line contains n integers a1,βa2,β...,βan (1ββ€βaiββ€βn). | standard output | standard input | Python 3 | Python | 1,700 | train_052.jsonl | 3256dd548816d8bfcd345fbf0ad24970 | 256 megabytes | ["4\n2 3 3 4", "5\n3 2 2 5 3", "8\n2 3 5 4 1 6 6 7"] | PASSED | n=int(input())
a=list(map(int,input().split()))
par=[]
for i in range(n):
if a[i]==i+1:
par.append(i)
v=[False for i in range(n)]
for i in par:
v[i]=True
ccl=[]
for i in range(n):
if v[i]:continue
s=[i]
v[i]=True
p=set(s)
t=True
while s and t:
x=s.pop()
j=a[x]-1
if j in p:
ccl.append(j)
t=False
... | 1468933500 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["YES\n1", "YES\n0", "YES\n1"] | da38d1a63152e0a354b04936e9511969 | NoteIn the first example you can simply make one move to obtain sequence [0,β2] with .In the second example the gcd of the sequence is already greater than 1. | Mike has a sequence Aβ=β[a1,βa2,β...,βan] of length n. He considers the sequence Bβ=β[b1,βb2,β...,βbn] beautiful if the gcd of all its elements is bigger than 1, i.e. . Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1ββ€βiβ<βn), delete numbers ai,βaiβ+β1 and put... | Output on the first line "YES" (without quotes) if it is possible to make sequence A beautiful by performing operations described above, and "NO" (without quotes) otherwise. If the answer was "YES", output the minimal number of moves needed to make sequence A beautiful. | The first line contains a single integer n (2ββ€βnββ€β100β000) β length of sequence A. The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β elements of sequence A. | standard output | standard input | Python 3 | Python | 1,700 | train_038.jsonl | 0ee0ebb1fa960ef16bdb68e80a570993 | 256 megabytes | ["2\n1 1", "3\n6 2 4", "2\n1 3"] | PASSED | def main():
from math import gcd
input()
aa = list(map(int, input().split()))
g = r = t = 0
while aa and g != 1:
a = aa.pop()
if t:
r += 2 - (a & 1)
t = 0
else:
t = (a & 1) * 2
g = gcd(a, g)
for a in reversed(aa):
if t:
... | 1492785300 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
0.5 seconds | ["29"] | 09276406e16b46fbefd6f8c9650472f0 | null | One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the n... | Output one integer β the number of different variants of group composition. | The only line of the input contains one integer n (7ββ€βnββ€β777) β the number of potential employees that sent resumes. | standard output | standard input | PyPy 2 | Python | 1,300 | train_001.jsonl | d028cdefcd5a2b230d78d25a0bf96b70 | 64 megabytes | ["7"] | PASSED | W = int(raw_input())
def ncr(n, r):
res = 1
for i in xrange(r + 1, n + 1):
res *= i
for i in xrange(1, n - r + 1):
res /= i
return res
print ncr(W, 5) + ncr(W, 6) + ncr(W, 7) | 1455807600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nYES\nNO\nNO\nYES\nYES"] | b40059fe9cbdb0cc3b64c3e463900849 | NoteIn the first query you can win as follows: choose $$$512$$$ and $$$512$$$, and $$$s$$$ turns into $$$\{1024, 64, 1024\}$$$. Then choose $$$1024$$$ and $$$1024$$$, and $$$s$$$ turns into $$$\{2048, 64\}$$$ and you win.In the second query $$$s$$$ contains $$$2048$$$ initially. | You are playing a variation of game 2048. Initially you have a multiset $$$s$$$ of $$$n$$$ integers. Every integer in this multiset is a power of two. You may perform any number (possibly, zero) operations with this multiset.During each operation you choose two equal integers from $$$s$$$, remove them from $$$s$$$ and ... | For each query print YES if it is possible to obtain the number $$$2048$$$ in your multiset, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer). | The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) β the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the number of elements in multiset. The second line of each query contains $$$n$$$ integers $$$s_1, s_2, \dots, s_n$$$ ($$$1 \le s_i \le 2^{29}... | standard output | standard input | PyPy 2 | Python | 1,000 | train_002.jsonl | 36d24ed41f3c24eaaba82e58395c7201 | 256 megabytes | ["6\n4\n1024 512 64 512\n1\n2048\n3\n64 512 2\n2\n4096 4\n7\n2048 2 2048 2048 2048 2048 2048\n2\n2048 4096"] | PASSED | def count(arr,cnt):
for i in range(0,len(arr)):
if arr[i] in cnt.keys():
cnt[arr[i]] = cnt[arr[i]] + 1
else:
cnt[arr[i]] = 1
def yn2048(arr,t):
f = {}
count(arr,f)
keys = f.keys()
for i in range(0,11):
k = 0
keys = f.keys()
if pow(2,i) in keys:
k = f[pow(2,i)]/2
if pow(2,i+1) in keys:
f[p... | 1568903700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES", "NO", "NO"] | c404761a9562ff6034010a553d944324 | NoteIn the diagrams below, the squares controlled by the black queen are marked red, and the target square is marked blue.In the first case, the king can move, for instance, via the squares $$$(2, 3)$$$ and $$$(3, 2)$$$. Note that the direct route through $$$(2, 2)$$$ goes through check. In the second case, the queen ... | Alice and Bob are playing chess on a huge chessboard with dimensions $$$n \times n$$$. Alice has a single piece leftΒ β a queen, located at $$$(a_x, a_y)$$$, while Bob has only the king standing at $$$(b_x, b_y)$$$. Alice thinks that as her queen is dominating the chessboard, victory is hers. But Bob has made a devious ... | Print "YES" (without quotes) if Bob can get from $$$(b_x, b_y)$$$ to $$$(c_x, c_y)$$$ without ever getting in check, otherwise print "NO". You can print each letter in any case (upper or lower). | The first line contains a single integer $$$n$$$ ($$$3 \leq n \leq 1000$$$)Β β the dimensions of the chessboard. The second line contains two integers $$$a_x$$$ and $$$a_y$$$ ($$$1 \leq a_x, a_y \leq n$$$)Β β the coordinates of Alice's queen. The third line contains two integers $$$b_x$$$ and $$$b_y$$$ ($$$1 \leq b_x, b_... | standard output | standard input | Python 3 | Python | 1,000 | train_004.jsonl | 930275a7e66931f0bb3f30ee96e66a33 | 256 megabytes | ["8\n4 4\n1 3\n3 1", "8\n4 4\n2 3\n1 6", "8\n3 5\n1 2\n6 1"] | PASSED | n = int(input())
a_x, a_y = map(int, input().split())
b_x, b_y = map(int, input().split())
c_x, c_y = map(int, input().split())
if b_x < a_x < c_x or b_x > a_x > c_x or b_y < a_y < c_y or b_y > a_y > c_y:
print('NO')
else:
print('YES')
| 1538931900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["YES\nR 0\nL -3\nR 5\nL 6", "NO"] | 1c03ad9c0aacfbc9e40edc018a2526d3 | null | There are $$$n$$$ cars on a coordinate axis $$$OX$$$. Each car is located at an integer point initially and no two cars are located at the same point. Also, each car is oriented either left or right, and they can move at any constant positive speed in that direction at any moment.More formally, we can describe the $$$i... | In the first line, print either "YES" or "NO" (in any case), whether it is possible to restore the orientations and the locations of the cars satisfying the relationships. If the answer is "YES", print $$$n$$$ lines each containing a symbol and an integer: $$$ori_i$$$ and $$$x_i$$$ $$$(ori_i \in \{L, R\}; -10^9 \leq x_... | The first line contains two integers, $$$n$$$ and $$$m$$$ $$$(2 \leq n \leq 2 \cdot 10^5; 1 \leq m \leq min(2 \cdot 10^5, \frac{n(n-1)}{2})$$$ β the number of cars and the number of restrictions respectively. Each of the next $$$m$$$ lines contains three integers, $$$type$$$, $$$i$$$, and $$$j$$$ $$$(1 \leq type \leq 2... | standard output | standard input | PyPy 3-64 | Python | 2,200 | train_108.jsonl | b2ff51d67c582fc97af63031477e2ef2 | 512 megabytes | ["4 4\n1 1 2\n1 2 3\n2 3 4\n2 4 1", "3 3\n1 1 2\n1 2 3\n1 1 3"] | PASSED | def solve():
n, m = map(int, input().split())
relationships = []
adj = [[] for _ in range(n)]
for _ in range(m):
t, u, v = map(int, input().split())
u -= 1
v -= 1
relationships.append((t, u, v))
adj[u].append(v)
adj[v].append(u)
orient... | 1645367700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["YES\nNO\nYES\nNO\nYES"] | b44d59eded2cb3a65686dc7fd07d21b7 | NoteIn the second test case the table is not elegant, because the red and the purple subrectangles are nice and intersect. In the fourth test case the table is not elegant, because the red and the purple subrectangles are nice and intersect. | Madoka's father just reached $$$1$$$ million subscribers on Mathub! So the website decided to send him a personalized awardΒ β The Mathhub's Bit Button! The Bit Button is a rectangular table with $$$n$$$ rows and $$$m$$$ columns with $$$0$$$ or $$$1$$$ in each cell. After exploring the table Madoka found out that: A sub... | For each test case print "YES" if its table is elegant or print "NO" otherwise. You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer). | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 200$$$)Β β the number of test cases. Description of the test cases follows. The first line of each test case contains two positive integers $$$n, m$$$ ($$$1 \le n, m \le 100$$$). The next $$$n$$$ lines contain string... | standard output | standard input | Python 3 | Python | 1,200 | train_096.jsonl | fe66e8d0108f373ef8c039a1feb8f5f8 | 256 megabytes | ["5\n3 3\n100\n011\n011\n3 3\n110\n111\n110\n1 5\n01111\n4 5\n11111\n01010\n01000\n01000\n3 2\n11\n00\n11"] | PASSED | #!/usr/bin/env python
# coding: utf-8
# In[13]:
import sys
# input = sys.stdin.readline
# In[2]:
# input = sys.stdin.readline
# def inp():
# return(int(input()))
# def inlt():
# return(list(map(int,input().split())))
# def insr():
# s = input()
# # return(list(s[:len(s) - 1]))
# return(list(s... | 1647009300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
3 seconds | ["1.500000\n2.250000\n3.250000", "2.500000", "1.000000"] | 6cef2d464febcee854ee5a7f78d7ba4a | NoteConsider the second test case. If Allen goes first, he will set $$$x_1 \to 1$$$, so the final value will be $$$3$$$. If Bessie goes first, then she will set $$$x_1 \to 0$$$ so the final value will be $$$2$$$. Thus the answer is $$$2.5$$$.In the third test case, the game value will always be $$$1$$$ regardless of Al... | Allen and Bessie are playing a simple number game. They both know a function $$$f: \{0, 1\}^n \to \mathbb{R}$$$, i.Β e. the function takes $$$n$$$ binary arguments and returns a real value. At the start of the game, the variables $$$x_1, x_2, \dots, x_n$$$ are all set to $$$-1$$$. Each round, with equal probability, one... | Print $$$r+1$$$ lines, the $$$i$$$-th of which denotes the value of the game $$$f$$$ during the $$$i$$$-th round. Your answer must have absolute or relative error within $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|a - b|}{\max{(1,... | The first line contains two integers $$$n$$$ and $$$r$$$ ($$$1 \le n \le 18$$$, $$$0 \le r \le 2^{18}$$$). The next line contains $$$2^n$$$ integers $$$c_0, c_1, \dots, c_{2^n-1}$$$ ($$$0 \le c_i \le 10^9$$$), denoting the initial values of $$$f$$$. More specifically, $$$f(x_0, x_1, \dots, x_{n-1}) = c_x$$$, if $$$x = ... | standard output | standard input | Python 3 | Python | 2,500 | train_017.jsonl | e7a16a0243e6c1d57c25db2049f49d44 | 256 megabytes | ["2 2\n0 1 2 3\n2 5\n0 4", "1 0\n2 3", "2 0\n1 1 1 1"] | PASSED | R = lambda:list(map(int,input().split()))
sum1 = 0
p1 = 1
a = [0]*263000
b = a
n,r = R()
p1 = 2**n
a = R()
sum1 = sum(a)
p2 = sum1 / p1
for i in range(r):
z,g=R()
sum1 = sum1 - a[z] + g
a[z] = g
b[i] = sum1/p1
print(p2)
for i in range(r):
print(b[i]) | 1529858100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["4\n0 1 2 5 \n6\n0 1 2 3 5 11 \n2\n0 1 \n3\n0 1 3"] | 1fea14a5c21bf301981656cbe015864d | null | On the well-known testing system MathForces, a draw of $$$n$$$ rating units is arranged. The rating will be distributed according to the following algorithm: if $$$k$$$ participants take part in this event, then the $$$n$$$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end o... | Output the answers for each of $$$t$$$ test cases. Each answer should be contained in two lines. In the first line print a single integer $$$m$$$Β β the number of different rating increment values that Vasya can get. In the following line print $$$m$$$ integers in ascending orderΒ β the values of possible rating incremen... | The first line contains integer number $$$t$$$ ($$$1 \le t \le 10$$$)Β β the number of test cases in the input. Then $$$t$$$ test cases follow. Each line contains an integer $$$n$$$ ($$$1 \le n \le 10^9$$$)Β β the total number of the rating units being drawn. | standard output | standard input | Python 3 | Python | 1,400 | train_003.jsonl | d4684ef67e3c3137b08812df5cfb7c4a | 256 megabytes | ["4\n5\n11\n1\n3"] | PASSED | from math import sqrt
from sys import stdin, stdout
for i in range(int(input())):
n = int(input())
s,j,l = set([0,1]), 2, sqrt(n)
while j <= l:
s.add(j)
s.add(int(n//j))
j += 1
s.add(n)
a,l = sorted(s), len(s)
stdout.write('%d\n' % l)
for j in range(l):
stdout.write('%d ' % a[j])
stdout.... | 1575038100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"] | 6264405c66b2690ada9f8cc6cff55f0b | NoteIn the first sample case:On the first level, ZS the Coder pressed the 'β+β' button 14 times (and the number on screen is initially 2), so the number became 2β+β14Β·1β=β16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the 'β+β' button 16 times, so the n... | ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, 'β+β' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are nβ+β1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the 'β+β' ... | Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the 'β+β' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed tha... | The first and only line of the input contains a single integer n (1ββ€βnββ€β100β000), denoting that ZS the Coder wants to reach level nβ+β1. | standard output | standard input | Python 3 | Python | 1,600 | train_000.jsonl | c110c795a3144221aa279294612eb2aa | 256 megabytes | ["3", "2", "4"] | PASSED | def main():
n=int(input())
print(2)
for i in range(2,n+1):
print(i*(i+1)**2-(i-1))
main()
'''
1=>2: 2->4 [2]
2=>3: 2->36 [17]
3=>4: 6->144 [46]
4=>5: 12->400 [97]
5=>6: 20->900 [176]
'''
| 1474119900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["0\n987\n914"] | b57066317ae2f2280d7351ff12e0c959 | NoteIn the second test case, in one of the optimal answers after all operations $$$a = [2, 6, 4, 6]$$$, $$$b = [3, 7, 6, 1]$$$.The cost of the array $$$a$$$ equals to $$$(2 + 6)^2 + (2 + 4)^2 + (2 + 6)^2 + (6 + 4)^2 + (6 + 6)^2 + (4 + 6)^2 = 508$$$.The cost of the array $$$b$$$ equals to $$$(3 + 7)^2 + (3 + 6)^2 + (3 +... | You are given two arrays $$$a$$$ and $$$b$$$, both of length $$$n$$$.You can perform the following operation any number of times (possibly zero): select an index $$$i$$$ ($$$1 \leq i \leq n$$$) and swap $$$a_i$$$ and $$$b_i$$$.Let's define the cost of the array $$$a$$$ as $$$\sum_{i=1}^{n} \sum_{j=i + 1}^{n} (a_i + a_j... | For each test case, print the minimum possible total cost. | Each test case consists of several test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 40$$$)Β β the number of test cases. The following is a description of the input data sets. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$)Β β the length of both arrays. ... | standard output | standard input | PyPy 3-64 | Python | 1,800 | train_090.jsonl | f7c12418e4550cdf0868782ba9427a74 | 256 megabytes | ["3\n1\n3\n6\n4\n3 6 6 6\n2 7 4 1\n4\n6 7 2 4\n2 5 3 5"] | PASSED | # import sys, os
# if not os.environ.get("ONLINE_JUDGE"):
# sys.stdin = open('in.txt', 'r')
# sys.stdout = open('out.txt', 'w')
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(... | 1644676500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 ΡΠ΅ΠΊΡΠ½Π΄Ρ | ["LUURRDDL", "UULLDDDDDRRRRRUULULL"] | dea56c6d6536e7efe80d39ebc6b819a8 | ΠΡΠΈΠΌΠ΅ΡΠ°Π½ΠΈΠ΅Π ΠΏΠ΅ΡΠ²ΠΎΠΌ ΡΠ΅ΡΡΠΎΠ²ΠΎΠΌ ΠΏΡΠΈΠΌΠ΅ΡΠ΅ Π΄Π»Ρ ΠΎΠ±Ρ
ΠΎΠ΄Π° ΠΏΠΎ ΡΠ°ΡΠΎΠ²ΠΎΠΉ ΡΡΡΠ΅Π»ΠΊΠ΅ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°ΡΠ΅Π»ΡΠ½ΠΎΡΡΡ ΠΏΠΎΡΠ΅ΡΠ΅Π½Π½ΡΡ
ΡΠΎΠ±ΠΎΡΠΎΠΌ ΠΊΠ»Π΅ΡΠΎΠΊ Π²ΡΠ³Π»ΡΠ΄ΠΈΡ ΡΠ»Π΅Π΄ΡΡΡΠΈΠΌ ΠΎΠ±ΡΠ°Π·ΠΎΠΌ: ΠΊΠ»Π΅ΡΠΊΠ° (3,β2); ΠΊΠ»Π΅ΡΠΊΠ° (3,β1); ΠΊΠ»Π΅ΡΠΊΠ° (2,β1); ΠΊΠ»Π΅ΡΠΊΠ° (1,β1); ΠΊΠ»Π΅ΡΠΊΠ° (1,β2); ΠΊΠ»Π΅ΡΠΊΠ° (1,β3); ΠΊΠ»Π΅ΡΠΊΠ° (2,β3); ΠΊΠ»Π΅ΡΠΊΠ° (3,β3); ΠΊΠ»Π΅ΡΠΊΠ° (3,β2). | ΠΠ°ΠΌ Π·Π°Π΄Π°Π½ΠΎ ΠΏΡΡΠΌΠΎΡΠ³ΠΎΠ»ΡΠ½ΠΎΠ΅ ΠΊΠ»Π΅ΡΡΠ°ΡΠΎΠ΅ ΠΏΠΎΠ»Π΅, ΡΠΎΡΡΠΎΡΡΠ΅Π΅ ΠΈΠ· n ΡΡΡΠΎΠΊ ΠΈ m ΡΡΠΎΠ»Π±ΡΠΎΠ². ΠΠΎΠ»Π΅ ΡΠΎΠ΄Π΅ΡΠΆΠΈΡ ΡΠΈΠΊΠ» ΠΈΠ· ΡΠΈΠΌΠ²ΠΎΠ»ΠΎΠ² Β«*Β», ΡΠ°ΠΊΠΎΠΉ ΡΡΠΎ: ΡΠΈΠΊΠ» ΠΌΠΎΠΆΠ½ΠΎ ΠΎΠ±ΠΎΠΉΡΠΈ, ΠΏΠΎΡΠ΅ΡΠΈΠ² ΠΊΠ°ΠΆΠ΄ΡΡ Π΅Π³ΠΎ ΠΊΠ»Π΅ΡΠΊΡ ΡΠΎΠ²Π½ΠΎ ΠΎΠ΄ΠΈΠ½ ΡΠ°Π·, ΠΏΠ΅ΡΠ΅ΠΌΠ΅ΡΠ°ΡΡΡ ΠΊΠ°ΠΆΠ΄ΡΠΉ ΡΠ°Π· Π²Π²Π΅ΡΡ
/Π²Π½ΠΈΠ·/Π²ΠΏΡΠ°Π²ΠΎ/Π²Π»Π΅Π²ΠΎ Π½Π° ΠΎΠ΄Π½Ρ ΠΊΠ»Π΅ΡΠΊΡ; ΡΠΈΠΊΠ» Π½Π΅ ΡΠΎΠ΄Π΅ΡΠΆΠΈΡ ΡΠ°ΠΌΠΎΠΏΠ΅ΡΠ΅ΡΠ΅ΡΠ΅Π½ΠΈΠΉ ΠΈ ΡΠ°ΠΌΠΎΠΊΠ°ΡΠ°Π½ΠΈΠΉ, ΡΠΎ Π΅ΡΡΡ Π΄Π²Π΅ ΠΊΠ»Π΅ΡΠΊΠΈ ΡΠΈΠΊΠ»... | Π ΠΏΠ΅ΡΠ²ΡΡ ΡΡΡΠΎΠΊΡ Π²ΡΡ
ΠΎΠ΄Π½ΡΡ
Π΄Π°Π½Π½ΡΡ
Π²ΡΠ²Π΅Π΄ΠΈΡΠ΅ ΠΈΡΠΊΠΎΠΌΡΡ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°ΡΠ΅Π»ΡΠ½ΠΎΡΡΡ ΠΊΠΎΠΌΠ°Π½Π΄ Π΄Π»Ρ Π ΠΎΠ±ΠΎΡΠ°. ΠΠ°ΠΏΡΠ°Π²Π»Π΅Π½ΠΈΠ΅ ΠΎΠ±Ρ
ΠΎΠ΄Π° ΡΠΈΠΊΠ»Π° Π ΠΎΠ±ΠΎΡΠΎΠΌ ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ Π»ΡΠ±ΡΠΌ. | Π ΠΏΠ΅ΡΠ²ΠΎΠΉ ΡΡΡΠΎΠΊΠ΅ Π²Ρ
ΠΎΠ΄Π½ΡΡ
Π΄Π°Π½Π½ΡΡ
Π·Π°ΠΏΠΈΡΠ°Π½Ρ Π΄Π²Π° ΡΠ΅Π»ΡΡ
ΡΠΈΡΠ»Π° n ΠΈ m (3ββ€βn,βmββ€β100) β ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΡΡΡΠΎΠΊ ΠΈ ΡΡΠΎΠ»Π±ΡΠΎΠ² ΠΏΡΡΠΌΠΎΡΠ³ΠΎΠ»ΡΠ½ΠΎΠ³ΠΎ ΠΊΠ»Π΅ΡΡΠ°ΡΠΎΠ³ΠΎ ΠΏΠΎΠ»Ρ ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²Π΅Π½Π½ΠΎ. Π ΡΠ»Π΅Π΄ΡΡΡΠΈΡ
n ΡΡΡΠΎΠΊΠ°Ρ
Π·Π°ΠΏΠΈΡΠ°Π½Ρ ΠΏΠΎ m ΡΠΈΠΌΠ²ΠΎΠ»ΠΎΠ², ΠΊΠ°ΠΆΠ΄ΡΠΉ ΠΈΠ· ΠΊΠΎΡΠΎΡΡΡ
β Β«.Β», Β«*Β» ΠΈΠ»ΠΈ Β«SΒ». ΠΠ°ΡΠ°Π½ΡΠΈΡΡΠ΅ΡΡΡ, ΡΡΠΎ ΠΎΡΠ»ΠΈΡΠ½ΡΠ΅ ΠΎΡ Β«.Β» ΡΠΈΠΌΠ²ΠΎΠ»Ρ ΠΎΠ±ΡΠ°Π·ΡΡΡ ΡΠΈΠΊΠ» Π±Π΅Π· ΡΠ°ΠΌΠΎΠΏΠ΅ΡΠ΅ΡΠ΅ΡΠ΅Π½ΠΈΠΉ ΠΈ Ρ... | ΡΡΠ°Π½Π΄Π°ΡΡΠ½ΡΠΉ Π²ΡΠ²ΠΎΠ΄ | ΡΡΠ°Π½Π΄Π°ΡΡΠ½ΡΠΉ Π²Π²ΠΎΠ΄ | Python 3 | Python | 1,100 | train_061.jsonl | 874c5e87446705ac6040ac81b3df4161 | 256 ΠΌΠ΅Π³Π°Π±Π°ΠΉΡ | ["3 3\n***\n*.*\n*S*", "6 7\n.***...\n.*.*...\n.*.S**.\n.*...**\n.*....*\n.******"] | PASSED | def read_ints():
return [int(x) for x in input(' ').split()]
def main():
n, m = read_ints()
field = []
x, y = None, None
for i in range(n):
line = input()
if 'S' in line:
x, y = i, line.find('S')
field.append(list(line))
field[x][y] = '*'
flag = False
... | 1458745200 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
3 seconds | ["10\n5"] | dc35bdf56bb0ac341895e543b001b801 | null | T is a complete binary tree consisting of n vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has exactly two children). All leaves of a complete binary tree have the same depth (distance from the root). So n is a number such that nβ... | Print q numbers, i-th number must be the answer to the i-th query. | The first line contains two integer numbers n and q (1ββ€βnββ€β1018, qββ₯β1). n is such that nβ+β1 is a power of 2. The next 2q lines represent queries; each query consists of two consecutive lines. The first of these two lines contains ui (1ββ€βuiββ€βn), the second contains non-empty string si. si doesn't contain any chara... | standard output | standard input | PyPy 2 | Python | 1,900 | train_002.jsonl | c4083e607e85748bbdd248c531dda178 | 256 megabytes | ["15 2\n4\nUURL\n8\nLRLLLLLLLL"] | PASSED | n, q = map(int, raw_input().split())
queries = []
for i in range(q):
u = int(raw_input())
s = raw_input()
queries.append((u, s))
def coords(n, u):
level = 0
while (u & 1) == 0:
u >>= 1
level += 1
return level, (u - 1) / 2
def uncoords(n, level, idx):
return (1 << level) * (... | 1490625300 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["0001\n1111\n1"] | f9cf1a6971a7003078b63195198e5a51 | NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament. | $$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to o... | For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) β the number of players. The second line of each test case contains $$$n$$$ integers $... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_109.jsonl | e82bc3b8b55a1136dddd5fa00983dc05 | 256 megabytes | ["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"] | PASSED | import os
import sys
from io import BytesIO, IOBase
## PYRIVAL BOOTSTRAP
# https://github.com/cheran-senthil/PyRival/blob/master/pyrival/misc/bootstrap.py
# This decorator allows for recursion without actually doing recursion
from types import GeneratorType
## @bootstrap, yield when getting and returning value... | 1639217100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["0.000000000000000", "3.000000000000000", "2.965517241379311"] | ba4304e79d85d13c12233bcbcce6d0a6 | NoteIn the first sample, you can only choose an empty subgraph, or the subgraph containing only node 1.In the second sample, choosing the whole graph is optimal. | DZY loves Physics, and he enjoys calculating density.Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows: where v is the sum of the values of the nodes, e is the sum of the values of the edges.Once DZY got a graph G, now ... | Output a real number denoting the answer, with an absolute or relative error of at most 10β-β9. | The first line contains two space-separated integers nΒ (1ββ€βnββ€β500), . Integer n represents the number of nodes of the graph G, m represents the number of edges. The second line contains n space-separated integers xiΒ (1ββ€βxiββ€β106), where xi represents the value of the i-th node. Consider the graph nodes are numbered ... | standard output | standard input | Python 3 | Python | 1,600 | train_014.jsonl | 52a295d0891d369535a1724175a9bfa6 | 256 megabytes | ["1 0\n1", "2 1\n1 2\n1 2 1", "5 6\n13 56 73 98 17\n1 2 56\n1 3 29\n1 4 42\n2 3 95\n2 4 88\n3 4 63"] | PASSED | R = lambda:map(int, input().split())
ans = 0
n, m = R()
F = list(R())
for i in range(m):
a, b, x = R()
ans = max(ans, (F[a - 1]+ F[b - 1]) / x)
print(ans) | 1404651900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["3\n1 2 12", "3\n1 1 2", "2\n1 2"] | ecda878d924325789dc05035e4f4bbe0 | NoteIn the first case, the optimal subset is , which has mean 5, median 2, and simple skewness of 5β-β2β=β3.In the second case, the optimal subset is . Note that repetition is allowed.In the last case, any subset has the same median and mean, so all have simple skewness of 0. | Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness.The mean of a collection is the average of its elements. The median of a collect... | In the first line, print a single integer kΒ β the size of the subset. In the second line, print k integersΒ β the elements of the subset in any order. If there are multiple optimal subsets, print any. | The first line of the input contains a single integer n (1ββ€βnββ€β200 000)Β β the number of elements in the list. The second line contains n integers xi (0ββ€βxiββ€β1β000β000)Β β the ith element of the list. | standard output | standard input | PyPy 3 | Python | 2,400 | train_044.jsonl | 45dbb00f4cd7843160bda258d8a28b8b | 256 megabytes | ["4\n1 2 3 12", "4\n1 1 2 2", "2\n1 2"] | PASSED | from itertools import accumulate
from fractions import Fraction
n = int(input())
A = [int(x) for x in input().split()]
A.sort()
B = list(accumulate([0] + A))
def condition(i, z):
return (2*z - 1)*(A[i-z] + A[-z]) > 2*(B[i+1] - B[i-z+1] + B[-1] - B[-z])
def average(i, z):
return Fraction((B[i+1] - B[i-z] + B[-1... | 1455384900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["Impossible", "0110"] | 6893987b310c41efb269b63e865355d8 | null | For each string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 and a11, where axy is the number of subsequences of length 2 of the string s equal to the sequence {x,βy}. In these problem you are given four integers a00, a01, a10, a11 and have to find any non-empty string s that matche... | If there exists a non-empty string that matches four integers from the input, print it in the only line of the output. Otherwise, print "Impossible". The length of your answer must not exceed 1β000β000. | The only line of the input contains four non-negative integers a00, a01, a10 and a11. Each of them doesn't exceed 109. | standard output | standard input | Python 2 | Python | 1,900 | train_038.jsonl | c3ea74a3a50512a3b3ff82de2ff1c83e | 256 megabytes | ["1 2 3 4", "1 2 2 1"] | PASSED | def f(x):
l, r, mid, res = 1, 100000, 0, -1
while l <= r:
mid = (l + r) / 2
if mid * (mid - 1) / 2 == x:
res = mid
break
elif mid * (mid - 1) / 2 < x:
l = mid + 1
else:
r = mid - 1
if res == 1 and (not (b or c)):
res = 0
return res
a, b, c, d = map(int, raw_input().split())
x, y = f(a), f(d)
... | 1472056500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["30.00000 0.00000"] | 9829e1913e64072aadc9df5cddb63573 | null | The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to cho... | Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank. | The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,ββy,ββr, where (x,βy) are the coordinates of the stadium's center (β-ββ103ββ€βx,ββyββ€β103), and r (1ββ€βrβββ€β103) is its radius. All the numbers in the input data are integer, stadiums do not have commo... | standard output | standard input | Python 3 | Python | 2,600 | train_019.jsonl | e4fb13974249bae71328dbf739fda73e | 64 megabytes | ["0 0 10\n60 0 10\n30 30 10"] | PASSED | V=[list(map(int,input().split())) for _ in range(3)]
a=[]
for i in range(3):
da=V[i][0]-V[(i+1)%3][0]
db=V[i][1]-V[(i+1)%3][1]
drs=V[i][2]**2-V[(i+1)%3][2]**2 #Let drs=0
das=(V[i][0]+V[(i+1)%3][0])*da
dbs=(V[i][1]+V[(i+1)%3][1])*db
a.append([2*da,2*db,drs,das+dbs])
def Gauss(n,m):
for i in... | 1267117200 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
1 second | ["1", "0", "2"] | 62a672fcaee8be282700176803c623a7 | NoteIn the first sample AI's name may be replaced with "int#llect".In the second sample Gogol can just keep things as they are.In the third sample one of the new possible names of AI may be "s#ris#ri". | A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineap... | Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring. | The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100β000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters. | standard output | standard input | PyPy 3 | Python | 1,200 | train_000.jsonl | 82da8dbc1eee5c17f97ee53c9dbb0227 | 256 megabytes | ["intellect\ntell", "google\napple", "sirisiri\nsir"] | PASSED | s1=input()
s2=input()
print(s1.count(s2)) | 1454835900 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1 1\n-1\n4 6\n166374058999707392 249561088499561088"] | 1cc628b4e03c8b8e0c5086dc4e0e3254 | NoteIn the first test case the total number of wheels is $$$4$$$. It means that there is the only one bus with two axles in the bus fleet.In the second test case it's easy to show that there is no suitable number of buses with $$$7$$$ wheels in total.In the third test case the total number of wheels is $$$24$$$. The fo... | Spring has come, and the management of the AvtoBus bus fleet has given the order to replace winter tires with summer tires on all buses.You own a small bus service business and you have just received an order to replace $$$n$$$ tires. You know that the bus fleet owns two types of buses: with two axles (these buses have... | For each test case print the answer in a single line using the following format. Print two integers $$$x$$$ and $$$y$$$ ($$$1 \le x \le y$$$)Β β the minimum and the maximum possible number of buses that can be in the bus fleet. If there is no suitable number of buses for the given $$$n$$$, print the number $$$-1$$$ as t... | The first line contains an integer $$$t$$$ ($$$1 \le t \le 1\,000$$$)Β β the number of test cases. The following lines contain description of test cases. The only line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^{18}$$$)Β β the total number of wheels for all buses. | standard output | standard input | Python 3 | Python | 900 | train_099.jsonl | f73adefa2e3bd6b736050cb083fdeb57 | 256 megabytes | ["4\n\n4\n\n7\n\n24\n\n998244353998244352"] | PASSED | for i in range(int(input())):
n = int(input())
if n%2 != 0 or n < 3:
print(-1)
else:
minimum = n // 6
maximum = n//4
if minimum * 6 != n:
minimum += 1
print(minimum, maximum) | 1652520900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["YES", "NO", "YES"] | ad5b878298adea8742c36e2e119780f9 | NoteIn the first sample, we can cut the edge $$$(1, 2)$$$, and the tree will be split into $$$2$$$ trees of sizes $$$1$$$ and $$$2$$$ correspondently. Any tree of size $$$2$$$ is a Fib-tree, as it can be split into $$$2$$$ trees of size $$$1$$$.In the second sample, no matter what edge we cut, the tree will be split in... | Let $$$F_k$$$ denote the $$$k$$$-th term of Fibonacci sequence, defined as below: $$$F_0 = F_1 = 1$$$ for any integer $$$n \geq 0$$$, $$$F_{n+2} = F_{n+1} + F_n$$$You are given a tree with $$$n$$$ vertices. Recall that a tree is a connected undirected graph without cycles.We call a tree a Fib-tree, if its number of ver... | Print "YES" if the given tree is a Fib-tree, or "NO" otherwise. You can print your answer in any case. For example, if the answer is "YES", then the output "Yes" or "yeS" will also be considered as correct answer. | The first line of the input contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) β the number of vertices in the tree. Then $$$n-1$$$ lines follow, each of which contains two integers $$$u$$$ and $$$v$$$ ($$$1\leq u,v \leq n$$$, $$$u \neq v$$$), representing an edge between vertices $$$u$$$ and $$$v$$$.... | standard output | standard input | PyPy 3 | Python | 2,400 | train_095.jsonl | 195e22700f190f2cd4d81a027aece074 | 256 megabytes | ["3\n1 2\n2 3", "5\n1 2\n1 3\n1 4\n1 5", "5\n1 3\n1 2\n4 5\n3 4"] | PASSED | def main():
n = int(input())
graph = [[] for _ in range(n+1)]
parent = [-1 for _ in range(n+1)]
for _ in range(n-1):
x,y = map(int, input().split(' '))
graph[x].append(y)
graph[y].append(x)
digraph = [[] for _ in range(n+1)]
stack = [1]
count_order = [... | 1614519300 | [
"number theory",
"trees"
] | [
0,
0,
0,
0,
1,
0,
0,
1
] | |
1 second | ["1\n4\n2"] | fa761cd247a815f105668b716c20f0b4 | NoteThe first test case is described in the statement.In the second test case, the indices $$$i$$$ that result in palindrome after removing $$$s_i$$$ are $$$3, 4, 5, 6$$$. Hence the answer is $$$4$$$. In the third test case, removal of any of the indices results in "d" which is a palindrome. Hence the answer is $$$2$$$... | You are given a palindromic string $$$s$$$ of length $$$n$$$.You have to count the number of indices $$$i$$$ $$$(1 \le i \le n)$$$ such that the string after removing $$$s_i$$$ from $$$s$$$ still remains a palindrome. For example, consider $$$s$$$ = "aba" If we remove $$$s_1$$$ from $$$s$$$, the string becomes "ba" wh... | For each test case, output a single integer Β β the number of indices $$$i$$$ $$$(1 \le i \le n)$$$ such that the string after removing $$$s_i$$$ from $$$s$$$ still remains a palindrome. | The input consists of multiple test cases. The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^3)$$$ Β β the number of test cases. Description of the test cases follows. The first line of each testcase contains a single integer $$$n$$$ $$$(2 \leq n \leq 10^5)$$$ Β β the length of string $$$... | standard output | standard input | PyPy 3-64 | Python | 800 | train_101.jsonl | eb16aebd7408f43cd0183327bb6bb9a7 | 256 megabytes | ["3\n\n3\n\naba\n\n8\n\nacaaaaca\n\n2\n\ndd"] | PASSED | for _ in range(int(input())):
n=int(input())
s= input()
c=0
val = s[n//2]
for i in range(n//2-1, -1, -1):
if s[i]!=val:
break
c+=2
print(c+n%2)
| 1653230100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["1.00000000000000000000", "1.50000000000000000000", "1.33333333333333350000", "2.50216960000000070000"] | c2b3b577c2bcb3a2a8cb48700c637270 | null | There are n students living in the campus. Every morning all students wake up at the same time and go to wash. There are m rooms with wash basins. The i-th of these rooms contains ai wash basins. Every student independently select one the rooms with equal probability and goes to it. After all students selected their ro... | Output single number: the expected value of the size of the largest queue. Your answer must have an absolute or relative error less than 10β-β9. | The first line contains two positive integers n and m (1ββ€βn,βmββ€β50) β the amount of students and the amount of rooms. The second line contains m integers a1,βa2,β... ,βam (1ββ€βaiββ€β50). ai means the amount of wash basins in the i-th room. | standard output | standard input | Python 2 | Python | 2,200 | train_020.jsonl | 9ae6365e128a1cf4e5efc387e6e2c9d9 | 256 megabytes | ["1 1\n2", "2 2\n1 1", "2 3\n1 1 1", "7 5\n1 1 2 3 1"] | PASSED | n, m = map(int, raw_input().split())
a = map(int, raw_input().split())
prob = [(n+1)*[None] for _ in range(m+1)]
for k in range(1, m+1):
prob[k][0] = [1.0]
for i in range(1, n+1):
prob[k][i] = (i+1)*[0.0]
for j in range(i):
prob[k][i][j+1] += prob[k][i-1][j]*(1.0/k)
prob... | 1284735600 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
1 second | ["2 3\n1 1 2\n1 2 4\n1 4 5", "1 3 5\n2 5\n1 1 2\n1 2 4", "2 2", "1 1 2\n1 2 3\n1 3 4", "1 1 2\n1 2 3\n1 3 4"] | f09b435a20a415d65803a80d57152832 | NoteLet X be the removed number in the array. Let's take a look at all the examples:The first example has, for example, the following sequence of transformations of the array: $$$[5, -2, 0, 1, -3] \to [5, -2, X, 1, -3] \to [X, -10, X, 1, -3] \to$$$ $$$[X, X, X, -10, -3] \to [X, X, X, X, 30]$$$. Thus, the maximum answer... | You are given an array $$$a$$$ consisting of $$$n$$$ integers. You can perform the following operations with it: Choose some positions $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n, i \ne j$$$), write the value of $$$a_i \cdot a_j$$$ into the $$$j$$$-th cell and remove the number from the $$$i$$$-th cell; Choose some pos... | Print $$$n - 1$$$ lines. The $$$k$$$-th line should contain one of the two possible operations. The operation of the first type should look like this: $$$1~ i_k~ j_k$$$, where $$$1$$$ is the type of operation, $$$i_k$$$ and $$$j_k$$$ are the positions of the chosen elements. The operation of the second type should look... | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) β the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$) β the elements of the array. | standard output | standard input | PyPy 3 | Python | 1,700 | train_001.jsonl | bee37cd874000c141b1275e5c54a5824 | 256 megabytes | ["5\n5 -2 0 1 -3", "5\n5 2 0 4 0", "2\n2 -1", "4\n0 -10 0 0", "4\n0 0 0 0"] | PASSED | n = int(input())
a = list(map(int,input().split()))
hu = 0
humax = -float("inf")
huind = None
able = set(range(n))
ans = []
mae = -1
for i in range(n):
if a[i] == 0:
if mae == -1:
mae = i
able.discard(i)
else:
ans.append([1,mae+1,i+1])
able.discard(i)
mae = i
if a... | 1537171500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\nYES\nYES\nNO"] | f2070c2bd7bdbf0919aef1e915a21a24 | Note In the first and third sample, the array is already non-decreasing. In the second sample, we can swap $$$a_1$$$ and $$$a_3$$$ first, and swap $$$a_1$$$ and $$$a_5$$$ second to make the array non-decreasing. In the forth sample, we cannot the array non-decreasing using the operation. | You are given an array $$$a_1, a_2, \dots, a_n$$$ where all $$$a_i$$$ are integers and greater than $$$0$$$. In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$). If $$$gcd(a_i, a_j)$$$ is equal to the minimum element of the whole array $$$a$$$, you can swap $$$a_i$$$ and... | For each test case, output "YES" if it is possible to make the array $$$a$$$ non-decreasing using the described operation, or "NO" if it is impossible to do so. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of array $$$a$$$. The second line of each test case contains $$$n$$$ positive integers $$$a_1, a_2, \ldots a_n$$$ ($$$1 ... | standard output | standard input | PyPy 3 | Python | 1,300 | train_003.jsonl | 936191d6ddf860246b411219c2de6730 | 256 megabytes | ["4\n1\n8\n6\n4 3 6 6 2 9\n4\n4 5 6 7\n5\n7 5 2 2 4"] | PASSED | for i in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
y=sorted(l)
x=min(l)
a=[]
b=[]
for i in range(n):
if l[i]%x==0:
a.append(l[i])
b.append(i)
a.sort()
for i in range(len(b)):
l[b[i]]=a[i]
if(l==y):
print('... | 1598020500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["3\n6 3\n6 5\n1 3\n1 4\n5 2"] | 6a4e5b549514814a6c72d3b1e211a7f6 | NoteThe scheme for the first example (R denotes the lamp connected to the grid, the numbers on wires are their importance values): | Polycarp has decided to decorate his room because the New Year is soon. One of the main decorations that Polycarp will install is the garland he is going to solder himself.Simple garlands consisting of several lamps connected by one wire are too boring for Polycarp. He is going to solder a garland consisting of $$$n$$$... | If it is impossible to restore the original scheme, print one integer $$$-1$$$. Otherwise print the scheme as follows. In the first line, print one integer $$$k$$$ ($$$1 \le k \le n$$$) β the index of the lamp that is connected to the power grid. Then print $$$n - 1$$$ lines, each containing two integers $$$x_i$$$ and ... | The first line contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) β the number of lamps. The second line contains $$$n - 1$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_{n - 1}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the index of the main lamp for the $$$i$$$-th wire (wires are numbered in descending or... | standard output | standard input | Python 3 | Python | 2,200 | train_024.jsonl | 8c32c62dfb88c2bbd8155902497db3f8 | 256 megabytes | ["6\n3 6 3 1 5"] | PASSED | n = int(input())
a = list(map(int,input().split()))
dic = {}
uexmax = n
ans = []
for i in range(n-1):
if i == 0:
dic[a[i]] = 1
else:
if a[i] in dic:
dic[uexmax] = 1
ans.append([ a[i-1] , uexmax ])
else:
dic[a[i]] = 1
ans.append(... | 1577552700 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["\"123,0\"\n\"aba,1a\"", "\"1\"\n\",01,a0,\"", "\"1\"\n-", "-\n\"a\""] | ad02cead427d0765eb642203d13d3b99 | NoteIn the second example the string s contains five words: "1", "", "01", "a0", "". | You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: for example, the string s=";;" contains three empty words separated by ';'.You sh... | Print the string a to the first line and string b to the second line. Each string should be surrounded by quotes (ASCII 34). If there are no words that are numbers print dash (ASCII 45) on the first line. If all words are numbers print dash on the second line. | The only line of input contains the string s (1ββ€β|s|ββ€β105). The string contains only symbols '.' (ASCII 46), ',' (ASCII 44), ';' (ASCII 59), digits, lowercase and uppercase latin letters. | standard output | standard input | Python 3 | Python | 1,600 | train_021.jsonl | 5bb17e98c48ca49ca9462c890d8d20ff | 256 megabytes | ["aba,123;1a;0", "1;;01,a0,", "1", "a"] | PASSED | s = input()
a = s.replace(';', ',').split(',')
c, d = [], []
for elem in a:
if elem.isdigit() and (elem[0] != '0' or len(elem) == 1):
c.append(elem)
else:
d.append(elem)
if (len(c) == 0):
print('-')
#print('"' + ','.join(c) + '"')
print('"' + ','.join(d) + '"')
elif (len(d) == 0... | 1448636400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["1", "4"] | 28b7e9de0eb583642526c077aa56daba | NoteFor the second example all the permutations are: pβ=β[1,β2,β3] : fa is equal to 1; pβ=β[1,β3,β2] : fa is equal to 1; pβ=β[2,β1,β3] : fa is equal to 1; pβ=β[2,β3,β1] : fa is equal to 1; pβ=β[3,β1,β2] : fa is equal to 0; pβ=β[3,β2,β1] : fa is equal to 0. Where p is the array of the indices of initial array a. T... | You are given an array a of length n. We define fa the following way: Initially faβ=β0, Mβ=β1; for every 2ββ€βiββ€βn if aMβ<βai then we set faβ=βfaβ+βaM and then set Mβ=βi. Calculate the sum of fa over all n! permutations of the array a modulo 109β+β7.Note: two elements are considered different if their indices diff... | Print the only integer, the sum of fa over all n! permutations of the array a modulo 109β+β7. | The first line contains integer n (1ββ€βnββ€ββ1 000 000) β the size of array a. Second line contains n integers a1,βa2,β...,βan (1ββ€ββaiββ€ββ109). | standard output | standard input | Python 2 | Python | 2,300 | train_030.jsonl | 3439d41b80fb9d040d9739eaf022a899 | 256 megabytes | ["2\n1 3", "3\n1 1 2"] | PASSED | def main():
f= [1]
for i in range(1,1000002):
f.append((f[-1] * i)%1000000007)
n = int(raw_input())
a = sorted(int(x) for x in raw_input().split())
sol = 0
j = 0
s = 1
sq = 1
for i in range(n - 1):
sq = sq * (n - i) % 1000000007
if a[i] != a[i + 1]:
... | 1518793500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n2 3\n111 1111 11111 111111 1111111 11111111 111111111"] | 76bfced1345f871832957a65e2a660f8 | NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the condit... | Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be sh... | For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ β the array you found. If there are multiple arrays satisfying all the conditions, print any of them. | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. | standard output | standard input | Python 3 | Python | 800 | train_109.jsonl | 3b4015ff8824783539becf24898e9452 | 256 megabytes | ["3\n1\n2\n7"] | PASSED | for _ in range(int(input())):
n = int(input())
for i in range(n):
print((i+2)%100000000,end=" ")
print("")
| 1639217100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1110", "1010010", "1000000000000000001010010", "0"] | 8ddccfaf362b19d50647bfb6ad421953 | NoteFor each of the testcases $$$1$$$ to $$$3$$$, $$$A = \{2^3,2^1,2^2\} = \{8,2,4\}$$$ and $$$E=8\wedge 2\wedge 4$$$.For the first testcase, there is only one possible valid unambiguous expression $$$E' = 8\oplus 2\oplus 4 = 14 = (1110)_2$$$.For the second testcase, there are three possible valid unambiguous expressio... | The symbol $$$\wedge$$$ is quite ambiguous, especially when used without context. Sometimes it is used to denote a power ($$$a\wedge b = a^b$$$) and sometimes it is used to denote the XOR operation ($$$a\wedge b=a\oplus b$$$). You have an ambiguous expression $$$E=A_1\wedge A_2\wedge A_3\wedge\ldots\wedge A_n$$$. You c... | Print a single line containing a binary string without leading zeroes denoting the answer to the problem. If the answer is equal to $$$0$$$, print $$$0$$$. | The first line of input contains two integers $$$n$$$ and $$$k$$$ $$$(1\leq n\leq 2^{20}, 0\leq k < n)$$$. The second line of input contains $$$n$$$ integers $$$B_1,B_2,\ldots,B_n$$$ $$$(1\leq B_i < 2^{20})$$$. | standard output | standard input | PyPy 3 | Python | 2,500 | train_096.jsonl | 3eb509acff1a5ce7f568c1452db8bdb4 | 512 megabytes | ["3 2\n3 1 2", "3 1\n3 1 2", "3 0\n3 1 2", "2 1\n1 1"] | PASSED | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
m = u.bit_length()
dp0, dp1 = [0] * 2, [0] * 2
dp0[0] = 1
for i in range(m - 1, -1, -1):
ndp0, ndp1 = [0] * 2, [0] * 2
c = u & pow2[i]
d = v & pow2[i]
if c and d:
... | 1651329300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
3 seconds | ["5", "33"] | 752c583a1773847504bf0d50b72a9dda | null | You are given a string $$$t$$$ and $$$n$$$ strings $$$s_1, s_2, \dots, s_n$$$. All strings consist of lowercase Latin letters.Let $$$f(t, s)$$$ be the number of occurences of string $$$s$$$ in string $$$t$$$. For example, $$$f('\text{aaabacaa}', '\text{aa}') = 3$$$, and $$$f('\text{ababa}', '\text{aba}') = 2$$$.Calcula... | Print one integer β the value of $$$\sum\limits_{i=1}^{n} \sum\limits_{j=1}^{n} f(t, s_i + s_j)$$$. | The first line contains string $$$t$$$ ($$$1 \le |t| \le 2 \cdot 10^5$$$). The second line contains integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). Each of next $$$n$$$ lines contains string $$$s_i$$$ ($$$1 \le |s_i| \le 2 \cdot 10^5$$$). It is guaranteed that $$$\sum\limits_{i=1}^{n} |s_i| \le 2 \cdot 10^5$$$. All s... | standard output | standard input | PyPy 2 | Python | 2,400 | train_020.jsonl | b2043da40b924804c23ad7008741cb1c | 256 megabytes | ["aaabacaa\n2\na\naa", "aaabacaa\n4\na\na\na\nb"] | PASSED | from __future__ import division, print_function
from collections import deque
class Node:
def __init__(self, c, nxt, fail, o):
self.c = c
self.nxt = nxt
self.fail = fail
self.o = o
root = Node('', {}, Node, 0)
root.fail = root
def new_node(par, c):
node = Node(c, {}, root, 0)
... | 1565188500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["Yes\nYes\nNo\nNo\nYes\nYes"] | a5e649f4d984a5c5365ca31436ad5883 | NoteFor the first and second test cases, all conditions are already satisfied.For the third test case, there is only one empty cell $$$(2,2)$$$, and if it is replaced with a wall then the good person at $$$(1,2)$$$ will not be able to escape.For the fourth test case, the good person at $$$(1,1)$$$ cannot escape.For the... | Vivek has encountered a problem. He has a maze that can be represented as an $$$n \times m$$$ grid. Each of the grid cells may represent the following: EmptyΒ β '.' WallΒ β '#' Good person Β β 'G' Bad personΒ β 'B' The only escape from the maze is at cell $$$(n, m)$$$.A person can move to a cell only if it shares a sid... | For each test case, print "Yes" if there exists a way to replace some empty cells with walls to satisfy the given conditions. Otherwise print "No" You may print every letter in any case (upper or lower). | The first line contains one integer $$$t$$$ $$$(1 \le t \le 100)$$$Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$, $$$m$$$ $$$(1 \le n, m \le 50)$$$Β β the number of rows and columns in the maze. Each of the next $$$n$$$ lines contai... | standard output | standard input | PyPy 3 | Python | 1,700 | train_005.jsonl | d038faba7d151a510df0665476b9ac9b | 256 megabytes | ["6\n1 1\n.\n1 2\nG.\n2 2\n#B\nG.\n2 3\nG.#\nB#.\n3 3\n#B.\n#..\nGG.\n2 2\n#B\nB."] | PASSED | import sys
input = sys.stdin.buffer.readline
def main():
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
M = [list(str(input())[2:m+2]) for _ in range(n)]
M = [['#']*m] + M + [['#']*m]
M = [['#']+c+['#'] for c in M]
#print(M)
B = []
... | 1591540500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["1\n2\n1\n3\n0"] | 02062d1afe85e3639edddedceac304f4 | NoteIn the first test, you construct a pyramid of height $$$1$$$ with $$$2$$$ cards. There is $$$1$$$ card remaining, which is not enough to build a pyramid.In the second test, you build two pyramids, each of height $$$2$$$, with no cards remaining.In the third test, you build one pyramid of height $$$3$$$, with no car... | A card pyramid of height $$$1$$$ is constructed by resting two cards against each other. For $$$h>1$$$, a card pyramid of height $$$h$$$ is constructed by placing a card pyramid of height $$$h-1$$$ onto a base. A base consists of $$$h$$$ pyramids of height $$$1$$$, and $$$h-1$$$ cards on top. For example, card pyram... | For each test case output a single integerΒ β the number of pyramids you will have constructed in the end. | Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 1000$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. Each test case contains a single integer $$$n$$$ ($$$1\le n\le 10^9$$$)Β β the number of cards. It is guaranteed that the s... | standard output | standard input | Python 3 | Python | 1,100 | train_004.jsonl | 2d729004b7d23032344e31d1d6889413 | 256 megabytes | ["5\n3\n14\n15\n24\n1"] | PASSED | def p(n):
h=(-1+(1+24*n)**0.5)/6
return int(h)
t=int(input())
for i in range(t):
c=0
n=int(input())
while n>1:
x=p(n)
c+=1
n-=(3*x*x+x)/2
print(c) | 1588775700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["9", "240", "24"] | ab65207f0b334276f58e0d2e79b0b44d | NoteIn the first test, the following ways to choose the colors are suitable: $$$[1, 1, 1]$$$; $$$[2, 2, 2]$$$; $$$[3, 3, 3]$$$; $$$[1, 2, 3]$$$; $$$[1, 3, 2]$$$; $$$[2, 1, 3]$$$; $$$[2, 3, 1]$$$; $$$[3, 1, 2]$$$; $$$[3, 2, 1]$$$. | You are given $$$n$$$ points on the plane, the coordinates of the $$$i$$$-th point are $$$(x_i, y_i)$$$. No two points have the same coordinates.The distance between points $$$i$$$ and $$$j$$$ is defined as $$$d(i,j) = |x_i - x_j| + |y_i - y_j|$$$.For each point, you have to choose a color, represented by an integer fr... | Print one integerΒ β the number of ways to choose the colors for the points. Since it can be large, print it modulo $$$998244353$$$. | The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$)Β β the number of points. Then $$$n$$$ lines follow. The $$$i$$$-th of them contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$0 \le x_i, y_i \le 10^8$$$). No two points have the same coordinates (i.βe. if $$$i \ne j$$$, then either $$$x_i \ne x_j$$$ or $... | standard output | standard input | PyPy 3-64 | Python | 2,400 | train_083.jsonl | b71657011183ffa8b5981a5ce418f275 | 512 megabytes | ["3\n1 0\n3 0\n2 1", "5\n1 2\n2 4\n3 4\n4 4\n1 3", "4\n1 0\n3 0\n2 1\n2 0"] | PASSED | import collections
import functools
import heapq
import random
import bisect
import itertools
import math
import os
from io import BytesIO, IOBase
from sys import setrecursionlimit, stderr, stdin, stdout
from collections import defaultdict
setrecursionlimit(20000)
def get_ints():
return list(map(int, input().spl... | 1655044500 | [
"geometry",
"math",
"graphs"
] | [
0,
1,
1,
1,
0,
0,
0,
0
] | |
1 second | ["1\nABC", "2\nADBADC"] | b9766f25c8ae179c30521770422ce18b | NoteThe second sample has eight anagrams of string t, that can be obtained from string s by replacing exactly two letters: "ADBADC", "ADDABC", "CDAABD", "CDBAAD", "CDBADA", "CDDABA", "DDAABC", "DDBAAC". These anagrams are listed in the lexicographical order. The lexicographically minimum anagram is "ADBADC". | String x is an anagram of string y, if we can rearrange the letters in string x and get exact string y. For example, strings "DOG" and "GOD" are anagrams, so are strings "BABA" and "AABB", but strings "ABBAC" and "CAABA" are not.You are given two strings s and t of the same length, consisting of uppercase English lette... | In the first line print z β the minimum number of replacement operations, needed to get an anagram of string t from string s. In the second line print the lexicographically minimum anagram that could be obtained in z operations. | The input consists of two lines. The first line contains string s, the second line contains string t. The strings have the same length (from 1 to 105 characters) and consist of uppercase English letters. | output.txt | input.txt | Python 2 | Python | 1,800 | train_021.jsonl | b4313b4d314bc0ed1619614b6b1fc10a | 256 megabytes | ["ABA\nCBA", "CDBABC\nADCABD"] | PASSED | import sys
from collections import Counter
def io():
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
def main():
s = sys.stdin.readline().strip()
t = sys.stdin.readline().strip()
sc = [0] * 26
tc = [0] * 26
n = len(s)
for i, j in zip(s, t):
sc[ord(i)-ord('... | 1355047200 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1.5 seconds | ["1\n2", "0", "2\n0 2"] | 6a9f683dee69a7be2d06ec6646970f19 | NoteIn the first sample, the first bag and the second bag contain $$$\{3,4\}$$$ and $$$\{0,1,2\}$$$, respectively. Ajs can obtain every residue modulo $$$5$$$ except the residue $$$2$$$: $$$ 4+1 \equiv 0, \, 4+2 \equiv 1, \, 3+0 \equiv 3, \, 3+1 \equiv 4 $$$ modulo $$$5$$$. One can check that there is no choice of elem... | Everybody seems to think that the Martians are green, but it turns out they are metallic pink and fat. Ajs has two bags of distinct nonnegative integers. The bags are disjoint, and the union of the sets of numbers in the bags is $$$\{0,1,β¦,M-1\}$$$, for some positive integer $$$M$$$. Ajs draws a number from the first b... | In the first line, output the cardinality $$$K$$$ of the set of residues modulo $$$M$$$ which Ajs cannot obtain. In the second line of the output, print $$$K$$$ space-separated integers greater or equal than zero and less than $$$M$$$, which represent the residues Ajs cannot obtain. The outputs should be sorted in incr... | The first line contains two positive integer $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) and $$$M$$$ ($$$N+1 \leq M \leq 10^{9}$$$), denoting the number of the elements in the first bag and the modulus, respectively. The second line contains $$$N$$$ nonnegative integers $$$a_1,a_2,\ldots,a_N$$$ ($$$0 \leq a_1<a_2< \ld... | standard output | standard input | PyPy 3 | Python | 2,400 | train_008.jsonl | 428b57ae525cf5453355d17acd8e2c69 | 256 megabytes | ["2 5\n3 4", "4 1000000000\n5 25 125 625", "2 4\n1 3"] | PASSED | import sys
input = sys.stdin.readline
def main():
n, m = map(int, input().split())
a = list(map(int, input().split())) + [0]*500000
ans_S = 0
a[n] = a[0] + m
s = [0]*600600
for i in range(n):
s[i] = a[i + 1] - a[i]
s[n] = -1
for i in range(n):
s[2*n - i] = s[i]
for i... | 1537612500 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
3 seconds | ["SCAN 1 2\n\nDIG 1 2\n\nSCAN 2 2\n\nDIG 1 1\n\nDIG 1 3"] | 222fbf0693a4c1d2dd7a07d458d78a54 | null | This is an interactive problem.There is a grid of $$$n\times m$$$ cells. Two treasure chests are buried in two different cells of the grid. Your task is to find both of them. You can make two types of operations: DIG $$$r$$$ $$$c$$$: try to find the treasure in the cell $$$(r, c)$$$. The interactor will tell you if ... | null | null | standard output | standard input | PyPy 3-64 | Python | 2,200 | train_091.jsonl | d62c280e3a11622b42b45ff467d1f68d | 512 megabytes | ["1\n2 3\n\n1\n\n1\n\n3\n\n0\n\n1"] | PASSED | import sys
input = sys.stdin.readline
def d(p1, p2):
return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
o1 = (14, 1)
o2 = (13, 3)
def query(x, y):
print('SCAN',x + 1,y + 1)
sys.stdout.flush()
return int(input())
#return d(o1, (x, y)) + d(o2, (x, y))
def cout(x1, x2, y1, t2):
... | 1649837100 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["2\n3\n0", "0\n2\n1\n2\n5\n12\n5\n0\n0\n2"] | 401708ea0b55b933ad553977011460b4 | null | The Red Kingdom is attacked by the White King and the Black King!The Kingdom is guarded by $$$n$$$ castles, the $$$i$$$-th castle is defended by $$$a_i$$$ soldiers. To conquer the Red Kingdom, the Kings have to eliminate all the defenders. Each day the White King launches an attack on one of the castles. Then, at night... | For each test case, print the answer to it: the number of possible options for the first attack of the White King (or $$$0$$$, if the Black King can launch the last attack no matter how the White King acts). | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. Then, the test cases follow. Each test case is represented by two lines. The first line contains four integers $$$n$$$, $$$x$$$, $$$y$$$ and $$$z$$$ ($$$1 \le n \le 3 \cdot 10^5$$$, $$$1 \le x, y, z \le 5$$$). The second ... | standard output | standard input | PyPy 2 | Python | 2,500 | train_045.jsonl | 5bbed403e4a9574db7d387bffcb23ffd | 512 megabytes | ["3\n2 1 3 4\n7 6\n1 1 2 3\n1\n1 1 2 2\n3", "10\n6 5 4 5\n2 3 2 3 1 3\n1 5 2 3\n10\n4 4 2 3\n8 10 8 5\n2 2 1 4\n8 5\n3 5 3 5\n9 2 10\n4 5 5 5\n2 10 4 2\n2 3 1 4\n1 10\n3 1 5 3\n9 8 7\n2 5 4 5\n8 8\n3 5 1 4\n5 5 10"] | PASSED | import sys
range = xrange
input = raw_input
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
t = inp[ii]; ii += 1
for _ in range(t):
n = inp[ii]; ii += 1
x = inp[ii]; ii += 1
y = inp[ii]; ii += 1
z = inp[ii]; ii += 1
A = inp[ii: ii + n]; ii += n
memor = {}
def mexor(val, i):
... | 1583764500 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
1 second | ["Tonya\nBurenka\nBurenka\nTonya\nBurenka\nBurenka"] | 13611e428c24b94023811063bbbfa077 | NoteIn the first case, Burenka has no move, so Tonya wins.In the second case, Burenka can move $$$3$$$ cells to the right, after which Tony will not be able to make a move, which means that Burenka wins.In the third case, Burenka can move $$$5$$$ squares to the right. Then we can say that we have a game on a board of $... | Burenka and Tonya are playing an old Buryat game with a chip on a board of $$$n \times m$$$ cells.At the beginning of the game, the chip is located in the lower left corner of the board. In one move, the player can move the chip to the right or up by any odd number of cells (but you cannot move the chip both to the rig... | For each test case print a single line β the name of the winner of the game ("Burenka" or "Tonya"). | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) β the number of test cases. The following is a description of the input data sets. The only line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^9$$$) β the dimensions of the game board. | standard output | standard input | Python 3 | Python | 800 | train_090.jsonl | 7e8cf8df85bdfa5820fd62bd2b7b1c84 | 256 megabytes | ["6\n\n1 1\n\n1 4\n\n5 6\n\n2 2\n\n6 3\n\n999999999 1000000000"] | PASSED | for _ in range(int(input())):
n,m= map(int,input().split())
if (m-1)%2==0 and n==1:
print("Tonya")
elif (m-1)%2==0 :
if (n)%2==0:
print("Burenka")
else:
print("Tonya")
elif (m-1)%2 and n==1:
print("Burenka")
else:
if (n)%2:
print("Burenka")
else:
... | 1660660500 | [
"math",
"games"
] | [
1,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1", "3"] | 075988685fa3f9b20bd215037c504a4f | NoteIn the first example the number will be $$$11010100100$$$ after performing one operation. It has remainder $$$100$$$ modulo $$$100000$$$.In the second example the number will be $$$11010100010$$$ after performing three operations. It has remainder $$$10$$$ modulo $$$100000$$$. | You are given a huge decimal number consisting of $$$n$$$ digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1.You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may chan... | Print one integer β the minimum number of operations you should perform to obtain the number having remainder $$$10^y$$$ modulo $$$10^x$$$. In other words, the obtained number should have remainder $$$10^y$$$ when divided by $$$10^x$$$. | The first line of the input contains three integers $$$n, x, y$$$ ($$$0 \le y < x < n \le 2 \cdot 10^5$$$) β the length of the number and the integers $$$x$$$ and $$$y$$$, respectively. The second line of the input contains one decimal number consisting of $$$n$$$ digits, each digit of this number is either 0 or ... | standard output | standard input | Python 3 | Python | 1,100 | train_005.jsonl | 2266f91222a7852d12409d4589aa0db8 | 256 megabytes | ["11 5 2\n11010100101", "11 5 1\n11010100101"] | PASSED | n, x, y= map(int, input().split())
a=input()
c=0
for i in range(n-1, n-x-1, -1):
if a[i]=='1':
c+=1
if a[n-y-1]=='0':
c+=1
else:
c-=1
print(c) | 1557844500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["6"] | fba0d6cb50c858187f67ac3cac550f0d | NoteIn the example, one of the possible Hamiltonian cycles with length 6 is (1, 1) (1, 2) (2, 1) (2, 2). There does not exist any other Hamiltonian cycle with a length greater than 6.The Manhattan distance between two cities (xi,βyi) and (xj,βyj) is |xiβ-βxj|β+β|yiβ-βyj|. | There are n cities on a two dimensional Cartesian plane. The distance between two cities is equal to the Manhattan distance between them (see the Notes for definition). A Hamiltonian cycle of the cities is defined as a permutation of all n cities. The length of this Hamiltonian cycle is defined as the sum of the distan... | A single line denoting the longest possible length of a Hamiltonian cycle of the given cities. You should not output the cycle, only its length. Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | The first line contains an integer n (3ββ€βnββ€β105). Then n lines follow, each consisting of two integers xi and yi (0ββ€βxi,βyiββ€β109), denoting the coordinates of a city. All given points will be distinct. | standard output | standard input | Python 2 | Python | 3,100 | train_044.jsonl | a185367ecb5d48f57e758425edc618ca | 256 megabytes | ["4\n1 1\n1 2\n2 1\n2 2"] | PASSED | import sys
n = int(raw_input())
coordinates = []
xs = []
ys = []
for i in range(n):
x, y = map(int, raw_input().split())
coordinates.append(((x, i), (y, i)))
xs.append((x, i))
ys.append((y, i))
xs = sorted(xs)
ys = sorted(ys)
amt = [[0] * 2 for _ in range(2)]
medians = 0
for x, y in coordinates:
if ... | 1374327000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0\n0\n1\n3"] | f80dc7b12479551b857408f4c29c276b | NoteLet us have 3 junctions and 4 roads between the junctions have already been built (as after building all the roads in the sample): 1 and 3, 2 and 3, 2 roads between junctions 1 and 2. The land lot for the construction will look like this: The land lot for the construction will look in the following way: We can ... | A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way.In the constructing process m bidirectional ski roa... | Print m lines: the i-th line should represent the number of ways to build a ski base after the end of construction of the road number i. The numbers should be printed modulo 1000000009 (109β+β9). | The first line contains two integers n and m (2ββ€βnββ€β105,β1ββ€βmββ€β105). They represent the number of junctions and the number of roads correspondingly. Then on m lines follows the description of the roads in the order in which they were built. Each road is described by a pair of integers ai and bi (1ββ€βai,βbiββ€βn,βaiβ... | standard output | standard input | Python 2 | Python | 2,300 | train_000.jsonl | 83c284ab834ac4a8c1a887a807ea3ba9 | 256 megabytes | ["3 4\n1 3\n2 3\n1 2\n1 2"] | PASSED | import random
def FindSet(dsu, x):
if dsu[x] != x:
dsu[x] = FindSet(dsu, dsu[x])
return dsu[x]
def Unite(dsu, x, y):
x = FindSet(dsu, x)
y = FindSet(dsu, y)
if random.random() > 0.5:
dsu[x] = y
else:
dsu[y] = x
mod = 10 ** 9 + 9
n, m = map(int, raw_input().split())
dsu = range(n + 1)
res = 1
for i in xra... | 1308582000 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["YES", "NO"] | cf86add6c92fa8a72b8e23efbdb38613 | NoteIn the first sample, the steps are as follows: 01011βββ1011βββ011βββ0110 | You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to... | Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. | The first line contains the string a and the second line contains the string b (1ββ€β|a|,β|b|ββ€β1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. | standard output | standard input | Python 3 | Python | 1,700 | train_002.jsonl | fe31b34b34844fa376d94e7d88cf5972 | 256 megabytes | ["01011\n0110", "0011\n1110"] | PASSED | a=input()
b=input()
tot1=0
tot2=0
for i in a:
tot1+=int(i)
for i in b:
tot2+=int(i)
if tot1+tot1%2>=tot2:
print("YES")
else:
print("NO") | 1366385400 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["33.0476190476", "20.2591405923", "15.9047592939"] | 4aec5810e9942ae2fbe3ecd4fff3b468 | NoteA visualization of the path and the board from example 2 is as follows: The tile with an 'S' is the starting tile and the tile with an 'E' is the Goal.For the first example, there are no ladders.For the second example, the board looks like the one in the right part of the image (the ladders have been colored for cl... | Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she wants to try a different game β "Snakes and Ladders". Unfortunately, she already killed all the snake... | Print only one line containing a single floating-point number β the minimum expected number of turns Hyakugoku can take to finish the game. Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. | Input will consist of ten lines. The $$$i$$$-th line will contain 10 non-negative integers $$$h_{i1}, h_{i2}, \dots, h_{i10}$$$. If $$$h_{ij}$$$ is $$$0$$$, then the tile at the $$$i$$$-th row and $$$j$$$-th column has no ladder. Otherwise, the ladder at that tile will have a height of $$$h_{ij}$$$, i.e. climbing it wi... | standard output | standard input | Python 3 | Python | 2,300 | train_056.jsonl | 9c712aacde835c4521ec528c97b91416 | 256 megabytes | ["0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 3 0 0 0 4 0 0 0\n0... | PASSED | def pos(x, y):
if y & 1:
return y * w + w - 1 - x
return y * w + x
CUBE = 6
h, w = 10, 10
n = h * w
grid = []
for y in range(h):
line = list(map(int, input().split()))
grid.append(line)
grid.reverse()
# print(*grid, sep='\n')
to = [0] * n
for y in range(h):
for x in range(w):
y1 ... | 1572618900 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
2 seconds | ["3\n1\n0", "0\n0\n1"] | 2cd91be317328fec207da6773ead4541 | NoteThe first example illustrates an example from the statement.$$$f([7, 3, 1, 7]) = 1$$$: sequence of operations is $$$[7, 3, 1, 7] \to [(7 + 3)\bmod 10, (1 + 7)\bmod 10]$$$ $$$=$$$ $$$[0, 8]$$$ and one candy as $$$7 + 3 \ge 10$$$ $$$\to$$$ $$$[(0 + 8) \bmod 10]$$$ $$$=$$$ $$$[8]$$$, so we get only $$$1$$$ candy.$$$f(... | Consider a sequence of digits of length $$$2^k$$$ $$$[a_1, a_2, \ldots, a_{2^k}]$$$. We perform the following operation with it: replace pairs $$$(a_{2i+1}, a_{2i+2})$$$ with $$$(a_{2i+1} + a_{2i+2})\bmod 10$$$ for $$$0\le i<2^{k-1}$$$. For every $$$i$$$ where $$$a_{2i+1} + a_{2i+2}\ge 10$$$ we get a candy! As a res... | Output $$$q$$$ lines, in $$$i$$$-th line output single integerΒ β $$$f([s_{l_i}, s_{l_i + 1}, \ldots, s_{r_i}])$$$, answer to the $$$i$$$-th query. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$)Β β the length of the sequence. The second line contains $$$n$$$ digits $$$s_1, s_2, \ldots, s_n$$$ ($$$0 \le s_i \le 9$$$). The third line contains a single integer $$$q$$$ ($$$1 \le q \le 10^5$$$)Β β the number of queries. Each of the next $$$q$$$... | standard output | standard input | Python 3 | Python | 1,400 | train_011.jsonl | 0f1b7d072884b3b1ff95035d569a8df9 | 256 megabytes | ["8\n8 7 3 1 7 0 9 4\n3\n1 8\n2 5\n7 7", "6\n0 1 2 3 3 5\n3\n1 2\n1 4\n3 6"] | PASSED | import sys
#sys.stdin = open('in', 'r')
n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
sm = [0]
for i in range(n):
sm.append(sm[-1]+a[i])
for qi in range(q):
l,r = map(int, input().split())
print((sm[r]-sm[l-1]) // 10)
#sys.stdout.write('YES\n')
#sys.stdout.write(f'{res}... | 1562339100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\n3 2 4 5 1", "NO", "NO"] | 9dfd415d4ed6247d6bee84e8a6558543 | NoteThe order of patterns after the rearrangement in the first example is the following: aaaa __b_ ab__ _bcd _b_d Thus, the first string matches patterns ab__, _bcd, _b_d in that order, the first of them is ab__, that is indeed $$$p[4]$$$. The second string matches __b_ and ab__, the first of them is __b_, that i... | You are given $$$n$$$ patterns $$$p_1, p_2, \dots, p_n$$$ and $$$m$$$ strings $$$s_1, s_2, \dots, s_m$$$. Each pattern $$$p_i$$$ consists of $$$k$$$ characters that are either lowercase Latin letters or wildcard characters (denoted by underscores). All patterns are pairwise distinct. Each string $$$s_j$$$ consists of $... | Print "NO" if there is no way to rearrange the patterns in such a way that the first pattern that the $$$j$$$-th string matches is $$$p[mt_j]$$$. Otherwise, print "YES" in the first line. The second line should contain $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$Β β the order of the patterns. If there are multiple ... | The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n, m \le 10^5$$$, $$$1 \le k \le 4$$$)Β β the number of patterns, the number of strings and the length of each pattern and string. Each of the next $$$n$$$ lines contains a patternΒ β $$$k$$$ characters that are either lowercase Latin letters o... | standard output | standard input | PyPy 3-64 | Python | 2,300 | train_102.jsonl | 206439a1f8c4c9a5176bfc9ca44841ee | 256 megabytes | ["5 3 4\n_b_d\n__b_\naaaa\nab__\n_bcd\nabcd 4\nabba 2\ndbcd 5", "1 1 3\n__c\ncba 1", "2 2 2\na_\n_b\nab 1\nab 2"] | PASSED | import sys
input = sys.stdin.buffer.readline
def toposort(graph):
res, found = [], [0] * len(graph)
stack = list(range(len(graph)))
while stack:
node = stack.pop()
if node < 0:
res.append(~node)
elif not found[node]:
found[node] = 1
s... | 1611930900 | [
"strings",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
1,
0
] | |
3 seconds | ["3", "-1", "0"] | 99dd00f4840188d4d96260100b20e9c9 | NoteIn the first example, you can sort the permutation in three operations: Make operation 1: $$$3, 6, 5, 2, 1, 4$$$. Make operation 2: $$$2, 1, 4, 3, 6, 5$$$. Make operation 1: $$$1, 2, 3, 4, 5, 6$$$. | The brave Knight came to the King and asked permission to marry the princess. The King knew that the Knight was brave, but he also wanted to know if he was smart enough. So he asked him to solve the following task.There is a permutation $$$p_i$$$ of numbers from 1 to $$$2n$$$. You can make two types of operations. Sw... | Print one integerΒ β the minimal number of operations required to sort the permutation. If it is impossible to sort the permutation using these operations, print $$$-1$$$. | The first line contains the integer $$$n$$$ ($$$1\le n\le 1000$$$). The second line contains $$$2n$$$ integers $$$p_i$$$Β β the permutation of numbers from 1 to $$$2n$$$. | standard output | standard input | Python 3 | Python | 1,200 | train_099.jsonl | 88c937208120c697ea4ca68be9e130fe | 512 megabytes | ["3\n6 3 2 5 4 1", "2\n3 4 2 1", "4\n1 2 3 4 5 6 7 8"] | PASSED | def print_result(arrey):
for el in arrey:
print(el, end=" ")
def swap_p1_p2(arrey, half_length):
for i in range(0, len(arrey) - 1, 2):
arrey[i], arrey[i + 1] = arrey[i + 1], arrey[i]
return arrey
def swap_p1_pn1(arrey, half_length):
for i in range(len(arrey) // 2):
... | 1617523500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["Yes\nYes\nYes\nNo\nNo\nYes"] | 933135ef124b35028c1f309d69515e44 | NoteFirst game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is m... | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). | In the first string, the number of games n (1ββ€βnββ€β350000) is given. Each game is represented by a pair of scores a, b (1ββ€βa,βbββ€β109)Β β the results of Slastyona and Pushok, correspondingly. | standard output | standard input | Python 3 | Python | 1,700 | train_015.jsonl | e40a6c281f1d261ed26b016a7efefc9d | 256 megabytes | ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000"] | PASSED | import sys
n = int(input())
ans = []
arr = sys.stdin.read().split()
d = {}
for i in range(1,1001):
d[i**3] = i
for i in range(n):
a, b = int(arr[i<<1]), int(arr[i<<1|1])
if a == b:
if a in d:
ans.append('Yes')
else:
ans.append('No')
continue
if a > b: a, b... | 1501425300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\nYES\nYES\nNO"] | 0671972bc2b6452d51d048329e6e0106 | NoteIn the first test of the example you may choose $$$p = 2$$$ and subtract it once.In the second test of the example you may choose $$$p = 5$$$ and subtract it twice. Note that you cannot choose $$$p = 7$$$, subtract it, then choose $$$p = 3$$$ and subtract it again.In the third test of the example you may choose $$$... | You are given two integers $$$x$$$ and $$$y$$$ (it is guaranteed that $$$x > y$$$). You may choose any prime integer $$$p$$$ and subtract it any number of times from $$$x$$$. Is it possible to make $$$x$$$ equal to $$$y$$$?Recall that a prime number is a positive integer that has exactly two positive divisors: $$$1$... | For each test case, print YES if it is possible to choose a prime number $$$p$$$ and subtract it any number of times from $$$x$$$ so that $$$x$$$ becomes equal to $$$y$$$. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as ... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. Then $$$t$$$ lines follow, each describing a test case. Each line contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le y < x \le 10^{18}$$$). | standard output | standard input | Python 3 | Python | 900 | train_016.jsonl | fa211d0a17399487f996b85fbb12e378 | 256 megabytes | ["4\n100 98\n42 32\n1000000000000000000 1\n41 40"] | PASSED | t=int(input())
for i in range(t):
s=input()
s=s.split( )
for e in s:
s[s.index(e)]=int(e)
if s[0]-s[1]<2:
print('NO')
elif ((s[0]-s[1])%2)==0 :
print('YES')
elif (s[0]-s[1]-3) >=0:
print('YES')
else:
print('NO')
| 1570545300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
3 seconds | ["6 1 0 0", "12 4 1 0 0 0 0"] | 2612df3281cbb9abe328f82e2d755a08 | NoteIn the first example 1-palindromes are substring Β«aΒ», Β«bΒ», Β«bΒ», Β«aΒ», Β«bbΒ», Β«abbaΒ», the substring Β«bbΒ» is 2-palindrome. There are no 3- and 4-palindromes here. | Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes.A string is 1-palindrome if and only if it reads the same backward as forward.A string is k-palindrome (kβ>β1) if and only if: Its left h... | Print |s| integersΒ β palindromic characteristics of string s. | The first line contains the string s (1ββ€β|s|ββ€β5000) consisting of lowercase English letters. | standard output | standard input | PyPy 2 | Python | 1,900 | train_069.jsonl | d0d337a3157316b7b92058828607f5a7 | 256 megabytes | ["abba", "abacaba"] | PASSED | s = raw_input()
n = len(s)
res = [0] * (n + 1)
dp = [[0] * n for _ in xrange(n)]
for l in xrange(1, n + 1):
for i in xrange(n - l + 1):
j = i + l - 1
if l == 1:
dp[i][j] = 1
continue
if s[i] == s[j] and (l == 2 or dp[i + 1][j - 1] > 0):
dp[i][j] = 1
... | 1501511700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["1\n2\n2\n0\n1", "14\n0\n2\n2\n2\n0\n2\n2\n1\n1"] | ae7c90b00cc8393fc4db14a6aad32957 | null | Given a sequence of integers a1,β...,βan and q queries x1,β...,βxq on it. For each query xi you have to count the number of pairs (l,βr) such that 1ββ€βlββ€βrββ€βn and gcd(al,βalβ+β1,β...,βar)β=βxi. is a greatest common divisor of v1,βv2,β...,βvn, that is equal to a largest positive integer that divides all vi. | For each query print the result in a separate line. | The first line of the input contains integer n, (1ββ€βnββ€β105), denoting the length of the sequence. The next line contains n space separated integers a1,β...,βan, (1ββ€βaiββ€β109). The third line of the input contains integer q, (1ββ€βqββ€β3βΓβ105), denoting the number of queries. Then follows q lines, each contain an inte... | standard output | standard input | PyPy 3 | Python | 2,000 | train_007.jsonl | a22ec356d26f087dee478095b974970c | 256 megabytes | ["3\n2 6 3\n5\n1\n2\n3\n4\n6", "7\n10 20 3 15 1000 60 16\n10\n1\n2\n3\n4\n5\n6\n10\n20\n60\n1000"] | PASSED | from math import gcd
from collections import defaultdict
from sys import stdin, stdout
##This method is better cause for all the same results we only calculate once
def main():
GCD_count = defaultdict(int)
GCD_map = defaultdict(int)
arr_len = int(stdin.readline())
arr = [int(x) for x in stdin.readline(... | 1412514000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["7\n74"] | 529d4ab0bdbb29d8b7f3d3eed19eca63 | NoteFor the first testcase, there are $$$7$$$ ways to partition $$$5$$$ as a sum of positive palindromic integers: $$$5=1+1+1+1+1$$$ $$$5=1+1+1+2$$$ $$$5=1+2+2$$$ $$$5=1+1+3$$$ $$$5=2+3$$$ $$$5=1+4$$$ $$$5=5$$$ For the second testcase, there are total $$$77$$$ ways to partition $$$12$$$ as a sum of positive int... | You are given a positive integer $$$n$$$. Let's call some positive integer $$$a$$$ without leading zeroes palindromic if it remains the same after reversing the order of its digits. Find the number of distinct ways to express $$$n$$$ as a sum of positive palindromic integers. Two ways are considered different if the fr... | For each testcase, print a single integer denoting the required answer modulo $$$10^9+7$$$. | The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 10^4$$$) denoting the number of testcases. Each testcase contains a single line of input containing a single integer $$$n$$$ ($$$1\leq n\leq 4\cdot 10^4$$$)Β β the required sum of palindromic integers. | standard output | standard input | PyPy 3-64 | Python | 1,500 | train_096.jsonl | deb451850d9670a8af7ca4b0b17ccc9d | 256 megabytes | ["2\n5\n12"] | PASSED | from sys import stdin
def readint():
return int(stdin.readline())
def readarray(typ):
return list(map(typ, stdin.readline().split()))
MOD = int(1e9) + 7
ps = []
N = 40000
for i in range(1, N+1):
# print(str(i), ''.join(reversed(str(i)))
if str(i) == (str(i)[::-1]):
ps.append(i)
m = len(p... | 1651329300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["7\n0\n4\n0\n30\n5\n4\n0\n3"] | 783772cb7a54bf65f648d3f8b7648263 | NoteThe following picture illustrates the first test case. Polycarp goes from $$$1$$$ to $$$10$$$. The yellow area shows the coverage area of the station with a radius of coverage of $$$1$$$, which is located at the point of $$$7$$$. The green area shows a part of the path when Polycarp is out of coverage area. | Polycarp lives on the coordinate axis $$$Ox$$$ and travels from the point $$$x=a$$$ to $$$x=b$$$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.On the axis $$$Ox$$$ at the point $$$x=c$$$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $... | Print $$$t$$$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement. | The first line contains a positive integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of test cases. In the following lines are written $$$t$$$ test cases. The description of each test case is one line, which contains four integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$r$$$ ($$$-10^8 \le a,b,c \le 10^8$$$, $$$0 \le r \le... | standard output | standard input | Python 3 | Python | 900 | train_006.jsonl | 2649d97dd1060676ae52c78ea286fc0a | 256 megabytes | ["9\n1 10 7 1\n3 3 3 0\n8 2 10 4\n8 2 10 100\n-10 20 -17 2\n-3 2 2 0\n-3 1 2 0\n2 3 2 3\n-1 3 -2 2"] | PASSED | a=int(input())
for i in range(a):
count=0
b=list(map(int,input().split(" ")))
l=b[2]-b[3]
u=b[2]+b[3]
s=min(b[0],b[1])
e=max(b[0],b[1])
if l<=s<=e<=u:
count=0
elif l<=s<=u<=e:
count=e-u
elif s<=l<=e<=u:
count=l-s
elif s<=l<=u<=e:
count=e-u-s+l
... | 1577198100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3 1 2", "1 2 3 4 5", "-1"] | b6ac7c30b7efdc7206dbbad5cfb86db7 | null | An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$... | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) β the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | standard output | standard input | Python 3 | Python | 1,500 | train_007.jsonl | 2f8007615f4baaa94a2db4d97e49f366 | 256 megabytes | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | PASSED | n=int(input())
q=list(map(int,input().split()))
for i in range(1,n-1):
q[i]+=q[i-1]
mi=min(q)
if (n-1)==len(set(q)):
if mi>0:
f=1
elif mi<0:
f=abs(mi)+1
else:
print(-1)
exit(0)
else:
print(-1)
exit(0)
d=dict()
if f<=n:
d[f]=1
else:
print(-1)
exit(... | 1553006100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
7 seconds | ["5", "0", "721234447"] | fcf5e6320d9cac0f39b3ef503f1b1002 | null | A subarray of array $$$a$$$ from index $$$l$$$ to the index $$$r$$$ is the array $$$[a_l, a_{l+1}, \dots, a_{r}]$$$. The number of occurrences of the array $$$b$$$ in the array $$$a$$$ is the number of subarrays of $$$a$$$ such that they are equal to $$$b$$$.You are given $$$n$$$ arrays $$$A_1, A_2, \dots, A_n$$$; the ... | Print one integer β the number of different arrays $$$a$$$ you can build, taken modulo $$$998244353$$$. | The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n, m, k \le 3 \cdot 10^5$$$) β the number of the given arrays, the desired length of the array $$$a$$$, and the upper bound on the values in the arrays. Then $$$n$$$ lines follow. The $$$i$$$-th line represents the array $$$A_i$$$. The first ... | standard output | standard input | PyPy 3-64 | Python | 2,700 | train_088.jsonl | a8f23434ab95938d5fc470852f98adc8 | 512 megabytes | ["2 4 3\n2 1 2\n1 3", "2 4 3\n2 1 2\n3 3 2 1", "1 42 1337\n2 13 31"] | PASSED | import sys
input = sys.stdin.readline
n,m,k = map(int, input().split())
nex = [-1] * k
prev = [-1] * k
bad = [0] * k
for _ in range(n):
l = list(map(int, input().split()))
nn = l.pop(0)
tg = True
for i in range(nn - 1):
u, v = l[i] - 1, l[i+1] - 1
tg = tg and (prev[v] == ... | 1632148500 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["1.0 4.0 5.0 3.5 4.5 5.0 5.0", "1.0 5.0 5.5 6.5 7.5 8.0 8.0 7.0 7.5 6.5 7.5 8.0"] | 750e1d9e43f916699537705c11d64d29 | null | Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and nβ-β1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city number 1. Thus if one will start his journey from city 1, he can visit any city h... | In the first and only line of output print n numbers, where i-th number is the expected value of starting_time[i]. Your answer for each city will be considered correct if its absolute or relative error does not exceed 10β-β6. | The first line of input contains a single integer n (1ββ€βnββ€β105)Β β the number of cities in USC. The second line contains nβ-β1 integers p2,βp3,β...,βpn (1ββ€βpiβ<βi), where pi is the number of the parent city of city number i in the tree, meaning there is a road between cities numbered pi and i in USC. | standard output | standard input | Python 3 | Python | 1,700 | train_021.jsonl | ee93884f915c3f86a086595e6deb1c05 | 256 megabytes | ["7\n1 2 1 1 4 4", "12\n1 1 2 2 4 4 3 3 1 10 8"] | PASSED | n = int(input())
if n ==1:
print(1)
exit(0)
l = list(map(int,input().split()))
w = [[]for i in range(n)]
sz = [1]*n
for i in range(n-1):
w[l[i]-1].append(i+1)
for i in range(n-1,-1,-1):
for j in range(len(w[i])):
sz[i]+=sz[w[i][j]]
ans = [0]*n
for i in range(n):
for j in range(len(w[i])):
... | 1468514100 | [
"probabilities",
"math",
"trees"
] | [
0,
0,
0,
1,
0,
1,
0,
1
] | |
5 seconds | ["6", "10", "7", "2"] | 2508a347f02aa0f49e0d154c54879b13 | NoteIn the first test, you can get the array $$$a = [11, 10, 9, 8, 7, 6, 5, 4, 3]$$$ by performing $$$6$$$ operations: Set $$$a_3$$$ to $$$9$$$: the array becomes $$$[3, 2, 9, 8, 6, 9, 5, 4, 1]$$$; Set $$$a_2$$$ to $$$10$$$: the array becomes $$$[3, 10, 9, 8, 6, 9, 5, 4, 1]$$$; Set $$$a_6$$$ to $$$6$$$: the array b... | You are given an array of integers $$$a_1, a_2, \ldots, a_n$$$.You can do the following operation any number of times (possibly zero): Choose any index $$$i$$$ and set $$$a_i$$$ to any integer (positive, negative or $$$0$$$). What is the minimum number of operations needed to turn $$$a$$$ into an arithmetic progressi... | Print a single integer: the minimum number of operations needed to turn $$$a$$$ into an arithmetic progression. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^5$$$). | standard output | standard input | PyPy 3-64 | Python | 2,300 | train_105.jsonl | ecd05e438142a11b624af407f3794efa | 1024 megabytes | ["9\n3 2 7 8 6 9 5 4 1", "14\n19 2 15 8 9 14 17 13 4 14 4 11 15 7", "10\n100000 1 60000 2 20000 4 8 16 32 64", "4\n10000 20000 10000 1"] | PASSED | import sys
input=sys.stdin.readline
from collections import defaultdict,deque
from heapq import heappush,heappop
from functools import lru_cache
import time
from math import gcd
def lcm(x, y):
return int(x * y / gcd(x, y))
class SortedList:
def __init__(self, iterable=[], _load=200):
""... | 1647764100 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
2 seconds | ["0.857143", "1", "0"] | 5a2c9caec9c20a3caed1982ee8ed8f9c | null | As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for t... | Output on a single line the desired probability with at least 4 digits after the decimal point. | The input consist of a single line with three space separated integers, n, m and k (0ββ€βn,βmββ€β105, 0ββ€βkββ€β10). | standard output | standard input | Python 3 | Python | 2,400 | train_005.jsonl | 8a6cb4297098eb864e487d96e3926ef3 | 256 megabytes | ["5 3 1", "0 5 5", "0 1 0"] | PASSED | #!/usr/bin/python3.5
# -*- coding: utf-8 -*-
import json
import sys
def main():
n, m, k = map(int, input().strip().split())
if n + k < m:
print(0)
return
ans = 1.0
for i in range(k+1):
ans *= (m - i) * 1.0 / (n + i + 1)
print(1.0 - ans)
if __name__ == '__main__':
main... | 1281970800 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
2 seconds | ["7\n1 3\n2 1\n2 6\n2 4\n7 4\n3 5", "14\n3 1\n1 4\n11 6\n1 2\n10 13\n6 10\n10 12\n14 12\n8 4\n5 1\n3 7\n2 6\n5 9", "-1"] | 7ebf821d51383f1633947a3b455190f6 | null | There are n cities in Berland, each of them has a unique idΒ β an integer from 1 to n, the capital is the one with id 1. Now there is a serious problem in Berland with roadsΒ β there are no roads.That is why there was a decision to build nβ-β1 roads so that there will be exactly one simple path between each pair of citie... | If it is impossible to built roads which satisfy all conditions, print -1. Otherwise, in the first line print one integer nΒ β the number of cities in Berland. In the each of the next nβ-β1 line print two integersΒ β the ids of cities that are connected by a road. Each road should be printed exactly once. You can print t... | The first line contains three positive numbers n, t and k (2ββ€βnββ€β2Β·105, 1ββ€βt,βkβ<βn)Β β the distance to the most distant city from the capital and the number of cities which should be dead-ends (the capital in this number is not taken into consideration). The second line contains a sequence of t integers a1,βa2,β... | standard output | standard input | Python 3 | Python | 2,100 | train_063.jsonl | 2206219586baa368112860eca60963f5 | 256 megabytes | ["7 3 3\n2 3 1", "14 5 6\n4 4 2 2 1", "3 1 1\n2"] | PASSED | n, t, k = map(int, input().split())
a = list(map(int, input().split()))
p = {}
cnt = 0
cur = 1
floor = [[1]]
for ak in a:
arr = [cur+i for i in range(1, ak+1)]
floor.append(arr)
cur += ak
for i in range(1, t+1):
cnt += len(floor[i]) - 1
if i == t:
cnt += 1
... | 1482057300 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
3.0 s | ["abacaba bac\n-1\npolycarp lcoayrp\nis si\neverywhere ewyrhv\n-1\n-1"] | 8705adec1bea1f898db1ca533e15d5c3 | NoteThe first test case is considered in the statement. | Polycarp has a string $$$s$$$. Polycarp performs the following actions until the string $$$s$$$ is empty ($$$t$$$ is initially an empty string): he adds to the right to the string $$$t$$$ the string $$$s$$$, i.e. he does $$$t = t + s$$$, where $$$t + s$$$ is a concatenation of the strings $$$t$$$ and $$$s$$$; he sele... | For each test case output in a separate line: $$$-1$$$, if the answer doesn't exist; two strings separated by spaces. The first one must contain a possible initial value of $$$s$$$. The second one must contain a sequence of letters β it's in what order one needs to remove letters from $$$s$$$ to make the string $$$t... | The first line contains one integer $$$T$$$ ($$$1 \le T \le 10^4$$$) β the number of test cases. Then $$$T$$$ test cases follow. Each test case contains one string $$$t$$$ consisting of lowercase letters of the Latin alphabet. The length of $$$t$$$ doesn't exceed $$$5 \cdot 10^5$$$. The sum of lengths of all strings $$... | standard output | standard input | PyPy 3-64 | Python | 1,800 | train_103.jsonl | b9509db4293b16ac54ea0feee5b3560b | 256 megabytes | ["7\nabacabaaacaac\nnowyouknowthat\npolycarppoycarppoyarppyarppyrpprppp\nisi\neverywherevrywhrvryhrvrhrvhv\nhaaha\nqweqeewew"] | PASSED | T = int(input())
for t in range(T):
t = input()
n = len(t)
# find first character with no occurences to the right
s = set()
r = []
for i in t[::-1]:
if i not in s:
r.append(i)
s.add(i)
done = r[::-1]
#print(done)
v = 0
for i in ... | 1629297300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["1\n6\n95\n20\n28208137\n48102976088"] | c9d57c590f4fe99e4a41f7fce1a8e513 | NoteThe string $$$S$$$ is equal to 0110100110010110....In the first test case, $$$S_0$$$ is "0", and $$$S_1$$$ is "1". The Hamming distance between the two strings is $$$1$$$.In the second test case, $$$S_0 S_1 \ldots S_9$$$ is "0110100110", and $$$S_5 S_6 \ldots S_{14}$$$ is "0011001011". The Hamming distance between ... | Let $$$S$$$ be the Thue-Morse sequence. In other words, $$$S$$$ is the $$$0$$$-indexed binary string with infinite length that can be constructed as follows: Initially, let $$$S$$$ be "0". Then, we perform the following operation infinitely many times: concatenate $$$S$$$ with a copy of itself with flipped bits.For ... | For each testcase, output a non-negative integerΒ β the Hamming distance between the two required strings. | Each test contains multiple test cases. The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. The description of the test cases follows. The first and only line of each test case contains two positive integers, $$$n$$$ and $$$m$$$ respectively ($$$1 \leq n,m \... | standard output | standard input | PyPy 3-64 | Python | 2,500 | train_097.jsonl | 42b6606c0235388583e41b2b843fd9c5 | 256 megabytes | ["6\n\n1 1\n\n5 10\n\n34 211\n\n73 34\n\n19124639 56348772\n\n12073412269 96221437021"] | PASSED | from functools import cache
def par(x):
cnt = 0
while x:
cnt += 1
x &= x - 1
return cnt & 1
@cache
def solve(n, m):
if m == 0:
return 0
if m & 1:
return solve(n, m - 1) + int(par(m - 1) != par(n + m - 1))
if n & 1:
return m - solve(n // 2... | 1663934700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1 0 0 1 1 0 \n1 0 0"] | 6458ad752e019ffb87573c8bfb712c18 | null | RedDreamer has an array $$$a$$$ consisting of $$$n$$$ non-negative integers, and an unlucky integer $$$T$$$.Let's denote the misfortune of array $$$b$$$ having length $$$m$$$ as $$$f(b)$$$ β the number of pairs of integers $$$(i, j)$$$ such that $$$1 \le i < j \le m$$$ and $$$b_i + b_j = T$$$. RedDreamer has to pain... | For each test case print $$$n$$$ integers: $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (each $$$p_i$$$ is either $$$0$$$ or $$$1$$$) denoting the colors. If $$$p_i$$$ is $$$0$$$, then $$$a_i$$$ is white and belongs to the array $$$c$$$, otherwise it is black and belongs to the array $$$d$$$. If there are multiple answers that... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$T$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le T \le 10^9$$$) β the number of elements in the array and the unlucky integer, resp... | standard output | standard input | PyPy 3 | Python | 1,100 | train_001.jsonl | ef5693f9ee6068c993c3c4ee1916ad0d | 256 megabytes | ["2\n6 7\n1 2 3 4 5 6\n3 6\n3 3 3"] | PASSED | from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict,Counter
from os import path
from bisect import bisect_left
import heapq
mod=10**9+7
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')):
#----... | 1601219100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["1", "3", "54", "0"] | 6fa3f1fd7675affcf326eeb7fb3c60a5 | NoteLet's draw the cards indicating the first four features. The first feature will indicate the number of objects on a card: $$$1$$$, $$$2$$$, $$$3$$$. The second one is the color: red, green, purple. The third is the shape: oval, diamond, squiggle. The fourth is filling: open, striped, solid.You can see the first thr... | You like the card board game "Set". Each card contains $$$k$$$ features, each of which is equal to a value from the set $$$\{0, 1, 2\}$$$. The deck contains all possible variants of cards, that is, there are $$$3^k$$$ different cards in total.A feature for three cards is called good if it is the same for these cards or... | Output one integer β the number of meta-sets. | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^3$$$, $$$1 \le k \le 20$$$) β the number of cards on a table and the number of card features. The description of the cards follows in the next $$$n$$$ lines. Each line describing a card contains $$$k$$$ integers $$$c_{i, 1}, c_{i, ... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_098.jsonl | 4875c7120202f13cf6924aa4f62a9a28 | 256 megabytes | ["8 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n1 0 0 0\n2 2 0 0", "7 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n0 2 0 0", "9 2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2", "20 4\n0 2 0 0\n0 2 2 2\n0 2 2 1\n0 2 0 1\n1 2 2 0\n1 2 1 0\n1 2 2 1\n1 2 0 1\n1 1 2 2\n1 1 0 2\n1 1 2 1\n1 1 1 1\n2 1... | PASSED | import collections
import math
import bisect
import sys
#import heapq
#import itertools
#import functools
#from sortedcontainers import SortedList
M = 3 ** 19
def bitmask(ls):
ans = 0
curr = 1
for i, num in enumerate(ls):
ans += curr * num
curr *= 3
return ans
def check... | 1664721300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\n1 4"] | 96855d115913f8c952775aba9ffb5558 | null | You are given an undirected graph consisting of n vertices and edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x,βy) such that there is no edge between x and y, and if some pair of vertices is not listed in the input, then there is an edge between these vertices.You have ... | Firstly print k β the number of connected components in this graph. Then print k integers β the sizes of components. You should output these integers in non-descending order. | The first line contains two integers n and m (1ββ€βnββ€β200000, ). Then m lines follow, each containing a pair of integers x and y (1ββ€βx,βyββ€βn, xββ βy) denoting that there is no edge between x and y. Each pair is listed at most once; (x,βy) and (y,βx) are considered the same (so they are never listed in the same test). ... | standard output | standard input | Python 3 | Python | 2,100 | train_037.jsonl | 8ee1459dda55f97d436bc89d66335a5a | 256 megabytes | ["5 5\n1 2\n3 4\n3 2\n4 2\n2 5"] | PASSED |
def Solution(G):
unvisited = { i for i in range(len(G)) }
sol = []
while unvisited:
l = len(unvisited)
a = next(iter(unvisited))
unvisited.discard(a)
stack = [a]
while stack:
v = stack.pop()
s = unvisited & G[v]
stack.extend(unvisi... | 1517582100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["1 2 2 2 \n1 1 \n2 2 3 3 3 3 3"] | d7c2789c5fb216f1de4a99657ffafb4d | Note In the first testcase: For $$$x = 1$$$, we can an edge between vertices $$$1$$$ and $$$3$$$, then $$$d(1) = 0$$$ and $$$d(2) = d(3) = d(4) = 1$$$, so $$$f(1) = 1$$$. For $$$x \ge 2$$$, no matter which edge we add, $$$d(1) = 0$$$, $$$d(2) = d(4) = 1$$$ and $$$d(3) = 2$$$, so $$$f(x) = 2$$$. | This version of the problem differs from the next one only in the constraint on $$$n$$$.A tree is a connected undirected graph without cycles. A weighted tree has a weight assigned to each edge. The distance between two vertices is the minimum sum of weights on the path connecting them.You are given a weighted tree wit... | For each test case, print $$$n$$$ integers in a single line, $$$x$$$-th of which is equal to $$$f(x)$$$ for all $$$x$$$ from $$$1$$$ to $$$n$$$. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 3000$$$). Each of the next $$$nβ1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u,v \le n$$$) indicating that there is a... | standard output | standard input | PyPy 3-64 | Python | 2,400 | train_084.jsonl | d56c2a4e193de4cd3a638c9c898db74b | 512 megabytes | ["3\n\n4\n\n1 2\n\n2 3\n\n1 4\n\n2\n\n1 2\n\n7\n\n1 2\n\n1 3\n\n3 4\n\n3 5\n\n3 6\n\n5 7"] | PASSED | from sys import stdin
inp = stdin.readline
t = int(inp())
for _ in range(t):
n = int(inp())
tree = {i: [set(), 0, 0] for i in range(1, n+1)}
for i in range(n-1):
a, b = map(int, inp().split())
tree[a][0].add(b)
tree[b][0].add(a)
layer = 0
arr = [set(tree[1]... | 1643553300 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["94\n0\n32"] | 12814033bec4956e7561767a6778d77e | NoteIn the example testcase:Here are the intersections used: Intersections on the path are 3, 1, 2 and 4. Intersections on the path are 4, 2 and 1. Intersections on the path are only 3 and 6. Intersections on the path are 4, 2, 1 and 3. Passing fee of roads on the path are 32, 32 and 30 in order. So answer equals... | Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2iβ+β1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two... | For each event of second type print the sum of passing fee of all roads Barney passes in this event, in one line. Print the answers in chronological order of corresponding events. | The first line of input contains a single integer q (1ββ€βqββ€β1β000). The next q lines contain the information about the events in chronological order. Each event is described in form 1 v u w if it's an event when government makes a new rule about increasing the passing fee of all roads on the shortest path from u to v ... | standard output | standard input | Python 3 | Python | 1,500 | train_037.jsonl | 1dbd27f90dd65b67bedfe9b659524eea | 256 megabytes | ["7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4"] | PASSED | q = int(input())
ans = []
cost = {}
def getn(v, k = 1):
res = []
while k <= v:
res.append(v)
v //= 2
return res
def getp(arr):
res = []
for i in range(len(arr) - 1):
res.append((arr[i], arr[i + 1]))
return res
def gets(u, v):
resu, resv = getn(u), getn(v)
for i... | 1468514100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["1\n3\n0\n0\n0"] | ea616a6b4ba7bf8742420b1c29ff0d16 | NoteConsider the test cases of the example: in the first test case, it's possible to remove two characters from the beginning and one character from the end. Only one 1 is deleted, only one 0 remains, so the cost is $$$1$$$; in the second test case, it's possible to remove three characters from the beginning and six ... | You are given a string $$$s$$$ consisting of characters 0 and/or 1.You have to remove several (possibly zero) characters from the beginning of the string, and then several (possibly zero) characters from the end of the string. The string may become empty after the removals. The cost of the removal is the maximum of the... | For each test case, print one integer β the minimum cost of removal you can achieve. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases. Each test case consists of one line containing the string $$$s$$$ ($$$1 \le |s| \le 2 \cdot 10^5$$$), consisting of characters 0 and/or 1. The total length of strings $$$s$$$ in all test cases does not exceed $$$2 \cdot 10^... | standard output | standard input | PyPy 3-64 | Python | 1,600 | train_083.jsonl | 7560944dda3650d23f150bf2819a2a75 | 512 megabytes | ["5\n\n101110110\n\n1001001001001\n\n0000111111\n\n00000\n\n1111"] | PASSED | # import sys
# input = sys.stdin.readline
def sol(arr):
l = 0
r = len(arr) - 1
while l<len(arr) and not arr[l] : l += 1
while r >= 0 and not arr[r] : r -= 1
step = []
cnt = 1
total = 0
for i in range(l+1, r+1):
if arr[i] == 0:
total += 1
if ... | 1652452500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1 49 \n20 40 30 50 10\n26 32 20 38 44 50 \n8 23 18 13 3 \n1 10 13 4 19 22 25 16 7"] | ca9d97e731e86cf8223520f39ef5d945 | null | We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers. The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$.... | For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array al... | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) β the length of the array and two elements ... | standard output | standard input | PyPy 2 | Python | 1,200 | train_004.jsonl | bd64f7bc53f67b0e349ed8de49363a04 | 256 megabytes | ["5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22"] | PASSED | import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')
def find_f... | 1599230100 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["YES\n1 2\n4 1\n3 1\n2 5\nYES\n4 3\n2 5\n1 5\n5 3\nNO\nYES\n2 4\n4 1\n2 5\n5 3\nYES\n5 4\n4 1\n2 5\n3 5\nYES\n2 3\n3 4\n1 3\nNO\nYES\n4 3\n1 2\n2 4\nNO"] | 4750029f0a5e802099a6dd4dff2974d5 | null | A tree is a connected undirected graph without cycles. Note that in this problem, we are talking about not rooted trees.You are given four positive integers $$$n, d_{12}, d_{23}$$$ and $$$d_{31}$$$. Construct a tree such that: it contains $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$, the distance (length of the ... | For each test case, print YES if the suitable tree exists, and NO otherwise. If the answer is positive, print another $$$n-1$$$ line each containing a description of an edge of the tree β a pair of positive integers $$$x_i, y_i$$$, which means that the $$$i$$$th edge connects vertices $$$x_i$$$ and $$$y_i$$$. The edg... | The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β βthe number of test cases in the test. This is followed by $$$t$$$ test cases, each written on a separate line. Each test case consists of four positive integers $$$n, d_{12}, d_{23}$$$ and $$$d_{31}$$$ ($$$3 \le n \le 2\cdot10^5; 1 \le d_... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_103.jsonl | fc86ad687e2e01c04e0dc7c53bad0ee6 | 256 megabytes | ["9\n\n5 1 2 1\n\n5 2 2 2\n\n5 2 2 3\n\n5 2 2 4\n\n5 3 2 3\n\n4 2 1 1\n\n4 3 1 1\n\n4 1 2 3\n\n7 1 4 1"] | PASSED | t=int(input())
for i in range(t):
n,a,b,c=[int(x) for x in input().split()]
l=[1]
l2=[]
x=4
check=True
'''for i in range(a-1):
l.append(x)
x+=1
l.append(2)'''
if c+b==a and n>a:
'''l.pop(-2)
x-=1
l.insert(c,3)'''
a1=1
... | 1659364500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["YES\nYES\nYES\nNO\nNO\nYES"] | 2173310623173d761b6039f0e5e661a8 | NoteIn the first test case, every guest is shifted by $$$14$$$ rooms, so the assignment is still unique.In the second test case, even guests move to the right by $$$1$$$ room, and odd guests move to the left by $$$1$$$ room. We can show that the assignment is still unique.In the third test case, every fourth guest move... | Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself,... | For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). | Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$)Β β the number of test cases. Next $$$2t$$$ lines contain descriptions of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 2\cdot 10^5$$$)Β β the length of the arra... | standard output | standard input | PyPy 3 | Python | 1,600 | train_003.jsonl | ff620df31f063cd839cab1ebdc29c93f | 256 megabytes | ["6\n1\n14\n2\n1 -1\n4\n5 5 5 1\n3\n3 2 1\n2\n0 1\n5\n-239 -2 -100 -3 -11"] | PASSED | import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time
readline = sys.stdin.readline
IPS = lambda: readline().rstrip()
IP = lambda: int(readline().rstrip())
MP = lambda: map(int, readline().split())
LS = lambda: list(map(int, readline().split... | 1588775700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["69\n359\n573672453"] | 178222a468f37615ee260fc9d2944aec | NoteIn the first test case, the minimum total amount of ingredients is $$$69$$$. In fact, the amounts of ingredients $$$1, 2, 3, 4$$$ of a valid potion are $$$16, 12, 9, 32$$$, respectively. The potion is valid because Ingredients $$$3$$$ and $$$2$$$ have a ratio of $$$9 : 12 = 3 : 4$$$; Ingredients $$$1$$$ and $$$2... | Alice's potion making professor gave the following assignment to his students: brew a potion using $$$n$$$ ingredients, such that the proportion of ingredient $$$i$$$ in the final potion is $$$r_i > 0$$$ (and $$$r_1 + r_2 + \cdots + r_n = 1$$$).He forgot the recipe, and now all he remembers is a set of $$$n-1$$$ fac... | For each test case, print the minimum total amount of ingredients needed to make a potion which passes the class, modulo $$$998\,244\,353$$$. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$). Each of the next $$$n-1$$$ lines contains four integers $$$i, j, x, y$$$ ($$$1 \le i, j \le n$$$, $$$i\not=j$$$, $$$1... | standard output | standard input | PyPy 3-64 | Python | 2,100 | train_105.jsonl | f864ea0f151158a8a3758358b843cd0a | 256 megabytes | ["3\n4\n3 2 3 4\n1 2 4 3\n1 4 2 4\n8\n5 4 2 3\n6 4 5 4\n1 3 5 2\n6 8 2 1\n3 5 3 4\n3 2 2 5\n6 7 4 3\n17\n8 7 4 16\n9 17 4 5\n5 14 13 12\n11 1 17 14\n6 13 8 9\n2 11 3 11\n4 17 7 2\n17 16 8 6\n15 5 1 14\n16 7 1 10\n12 17 13 10\n11 16 7 2\n10 11 6 4\n13 17 14 6\n3 11 15 8\n15 6 12 8"] | PASSED | import heapq
import math
import os
import sys
from array import array
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
from fractions import Fraction
from io import IOBase, BytesIO
from itertools import groupby, accumulate
from sys import stdin
from typing impo... | 1647764100 | [
"number theory",
"math",
"trees"
] | [
0,
0,
0,
1,
1,
0,
0,
1
] | |
2 seconds | ["8\n-1 2 6 4 0 3", "7\n5 -2 4 -1 2"] | 3a3666609b120d208c3e8366b186d89b | null | There are $$$n$$$ Christmas trees on an infinite number line. The $$$i$$$-th tree grows at the position $$$x_i$$$. All $$$x_i$$$ are guaranteed to be distinct.Each integer point can be either occupied by the Christmas tree, by the human or not occupied at all. Non-integer points cannot be occupied by anything.There are... | In the first line print one integer $$$res$$$ β the minimum possible value of $$$\sum\limits_{j=1}^{m}\min\limits_{i=1}^{n}|x_i - y_j|$$$ (in other words, the sum of distances to the nearest Christmas tree for all people). In the second line print $$$m$$$ integers $$$y_1, y_2, \dots, y_m$$$ ($$$-2 \cdot 10^9 \le y_j \l... | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) β the number of Christmas trees and the number of people. The second line of the input contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$-10^9 \le x_i \le 10^9$$$), where $$$x_i$$$ is the position of the $$$... | standard output | standard input | PyPy 3 | Python | 1,800 | train_010.jsonl | 27d49b3b27d3eddae992ee5d9175f38e | 256 megabytes | ["2 6\n1 5", "3 5\n0 3 1"] | PASSED | import heapq
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = []
total_distance = 0
occupied = set(x)
Q = [(1, tree + d) for tree in x for d in (1, -1)]
while len(y) < m:
distance, position = heapq.heappop(Q)
if position not in occupied:
y.append(position)
total_dist... | 1577552700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["2", "-1"] | 292bd9788a0d5d4a19a1924302f04feb | NoteExplanation for the first sample: In the first operation, Mashtali can choose vertex $$$1$$$ and eliminate players with colors red and blue. In the second operation, he can choose vertex $$$6$$$ and eliminate the player with orange color. In the second sample, Mashtali can't eliminate the first player. | After watching the new over-rated series Squid Game, Mashtali and Soroush decided to hold their own Squid Games! Soroush agreed to be the host and will provide money for the winner's prize, and Mashtali became the Front Man!$$$m$$$ players registered to play in the games to win the great prize, but when Mashtali found ... | Print the minimum number of operations Mashtali has to perform. If there is no way for Mashtali to eliminate all the players, print $$$-1$$$. | The first line contains $$$2$$$ integer $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 3 \cdot 10^5)$$$Β β the number of vertices of the tree and the number of players. The second line contains $$$n-1$$$ integers $$$par_2, par_3, \ldots, par_n$$$ $$$(1 \le par_i < i)$$$Β β denoting an edge between node $$$i$$$ and $$$par_i$$$... | standard output | standard input | Python 2 | Python | 3,100 | train_085.jsonl | 02fbad03a9b230c937030302b38ed539 | 256 megabytes | ["6 3\n1 1 1 4 4\n1 5\n3 4\n2 6", "5 3\n1 1 3 3\n1 2\n1 4\n1 5"] | PASSED | import sys
raw_input = iter(sys.stdin.read().splitlines()).next
def iter_dfs(adj):
L, R, D = [[1]*(len(adj)) for _ in xrange(3)]
cnt = -1
stk = [(1, ROOT)]
while stk:
step, i = stk.pop()
if step == 1:
stk.append((2, i))
cnt += 1
L[i] = cnt... | 1637678100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.