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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3 seconds | ["9 8", "4608 4096"] | 59d5e5ed2bc4b316e950e2a4dbc99d68 | null | Let's call a positive integer composite if it has at least one divisor other than $$$1$$$ and itself. For example: the following numbers are composite: $$$1024$$$, $$$4$$$, $$$6$$$, $$$9$$$; the following numbers are not composite: $$$13$$$, $$$1$$$, $$$2$$$, $$$3$$$, $$$37$$$. You are given a positive integer $$$n$$... | Print two composite integers $$$a,b$$$ ($$$2 \leq a, b \leq 10^9, a-b=n$$$). It can be proven, that solution always exists. If there are several possible solutions, you can print any. | The input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^7$$$): the given integer. | standard output | standard input | Python 3 | Python | 800 | train_000.jsonl | f516914c2ba0dc71e80ae4421503ee32 | 256 megabytes | ["1", "512"] | PASSED | n = int(input())
x = 1000000000
while True:
if n%2==0:
if x%2==0 and (x-n)%2==0:
print(x , x-n)
break
else:
x-=2
else:
if x%3 == 0:
print(x , x-n)
break
else:
x-=1
| 1576926300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["Yes", "No", "Yes"] | 69edc72ec29d4dd56751b281085c3591 | NoteThe first example:The second example:It is not a spruce, because the non-leaf vertex 1 has only 2 leaf children.The third example: | Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.Let's... | Print "Yes" if the tree is a spruce and "No" otherwise. | The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i). Vertex 1 is the root. It's guaranteed that the root has at least 2 children. | standard output | standard input | Python 3 | Python | 1,200 | train_004.jsonl | bb997e3fc91e795280644a6ec10ead40 | 256 megabytes | ["4\n1\n1\n1", "7\n1\n1\n1\n2\n2\n2", "8\n1\n1\n1\n1\n3\n3\n3"] | PASSED | # cook your dish here
from sys import stdin,stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I=lambda: map(int,stdin.readline().split())
I1=lambda: stdin.readline()
#(a/b)%m =((a%m)*pow(b,m-2)%m)%m
n=int(I1())
l=[]
for _ in range(n-1):
x=int(I1())
l.append(x)
... | 1515422700 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["2 2 3 1 2", "9999 10000 9998"] | ced70b400694fa16929d4b0bce3da294 | null | Sasha grew up and went to first grade. To celebrate this event her mother bought her a multiplication table $$$M$$$ with $$$n$$$ rows and $$$n$$$ columns such that $$$M_{ij}=a_i \cdot a_j$$$ where $$$a_1, \dots, a_n$$$ is some sequence of positive integers.Of course, the girl decided to take it to school with her. But ... | In a single line print $$$n$$$ integers, the original array $$$a_1, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$). It is guaranteed that an answer exists. If there are multiple answers, print any. | The first line contains a single integer $$$n$$$ ($$$3 \leqslant n \leqslant 10^3$$$), the size of the table. The next $$$n$$$ lines contain $$$n$$$ integers each. The $$$j$$$-th number of the $$$i$$$-th line contains the number $$$M_{ij}$$$ ($$$1 \leq M_{ij} \leq 10^9$$$). The table has zeroes on the main diagonal, t... | standard output | standard input | Python 3 | Python | 1,300 | train_008.jsonl | 2fb176bcdb407b7469020d3abb7eb641 | 256 megabytes | ["5\n0 4 6 2 4\n4 0 6 2 4\n6 6 0 3 6\n2 2 3 0 2\n4 4 6 2 0", "3\n0 99990000 99970002\n99990000 0 99980000\n99970002 99980000 0"] | PASSED | I=input
I()
a=[*map(int,I().split())]
a[0]=a[1]*a[2]/int(I().split()[2])
print(*(int(y/a[0]**.5)for y in a)) | 1568822700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1.5 seconds | ["1 2 1 1 1 \n0 0 1"] | a4101af56ea6afdfaa510572eedd6320 | Note In example case $$$1$$$, For $$$k = 0$$$, there is $$$1$$$ path that is from $$$2$$$ to $$$3$$$ as $$$MEX([2, 3]) = 0$$$. For $$$k = 1$$$, there are $$$2$$$ paths that is from $$$0$$$ to $$$2$$$ as $$$MEX([0, 2]) = 1$$$ and $$$0$$$ to $$$3$$$ as $$$MEX([0, 2, 3]) = 1$$$. For $$$k = 2$$$, there is $$$1$$$ pat... | You are given a tree with $$$n$$$ nodes, numerated from $$$0$$$ to $$$n-1$$$. For each $$$k$$$ between $$$0$$$ and $$$n$$$, inclusive, you have to count the number of unordered pairs $$$(u,v)$$$, $$$u \neq v$$$, such that the MEX of all the node labels in the shortest path from $$$u$$$ to $$$v$$$ (including end points)... | For each test case, print $$$n+1$$$ integers: the number of paths in the tree, such that the MEX of all the node labels in that path is $$$k$$$ for each $$$k$$$ from $$$0$$$ 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 2 \cdot 10^{5}$$$). The next $$$n-1$$$ lines of each test case describe the tree that has to be constructed. These lines contain two i... | standard output | standard input | PyPy 3-64 | Python | 2,400 | train_085.jsonl | 84fcbbead088d2584d8a95a2557697de | 256 megabytes | ["2\n4\n0 1\n0 2\n2 3\n2\n1 0"] | PASSED | import sys
input = sys.stdin.buffer.readline
class RangeQuery:
def __init__(self, data, func=min):
self.func = func
self._data = _data = [list(data)]
i, n = 1, len(_data[0])
while 2 * i <= n:
prev = _data[-1]
_data.append([func(prev[j], prev[j + i]... | 1621521300 | [
"math",
"trees"
] | [
0,
0,
0,
1,
0,
0,
0,
1
] | |
1 second | ["8", "32400"] | dcb483886c81d2cc0ded065aa1e74091 | NoteIn the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698. | Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits.Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of leng... | Print a single integer — the number of good phone numbers of length n modulo 109 + 7. | The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a1, a2, ..., an... | standard output | standard input | PyPy 2 | Python | 1,600 | train_001.jsonl | 00f679d582870d46f97794dfc57dab1d | 256 megabytes | ["6 2\n38 56 49\n7 3 4", "8 2\n1 22 3 44\n5 4 3 2"] | PASSED | n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
b=map(int,raw_input().split())
an=1
mod=int(1e9+7)
num=int('9'*k)
for i in xrange(n/k):
val1=a[i]
val2=int(str(b[i])+'9'*(k-1))
val3=int(str(b[i]-1)+'9'*(k-1))
ans=0
if b[i]==0:ans=num/val1-val2/val1
else:ans=num/val1+1-(val2/val1-v... | 1447000200 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1", "1", "-1", "-1"] | 91cfd24b8d608eb379f709f4509ecd2d | NoteIn the second sample one has to reverse string 2 or string 3. To amount of energy required to reverse the string 3 is smaller.In the third sample, both strings do not change after reverse and they go in the wrong order, so the answer is - 1.In the fourth sample, both strings consists of characters 'a' only, but in... | Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help.Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order (as in the dictionary), but he is not allowed to swap any of them. The only opera... | If it is impossible to reverse some of the strings such that they will be located in lexicographical order, print - 1. Otherwise, print the minimum total amount of energy Vasiliy has to spent. | The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of strings. The second line contains n integers ci (0 ≤ ci ≤ 109), the i-th of them is equal to the amount of energy Vasiliy has to spent in order to reverse the i-th string. Then follow n lines, each containing a string consisting ... | standard output | standard input | Python 3 | Python | 1,600 | train_015.jsonl | f1f384fee93ed675a955e34f1458c18d | 256 megabytes | ["2\n1 2\nba\nac", "3\n1 3 1\naa\nba\nac", "2\n5 5\nbbb\naaa", "2\n3 3\naaa\naa"] | PASSED | n = int(input())
ref = [int(x) for x in input().split()]
state = [[float('inf')]*2 for x in range(n)]
prev = input()
state[0][0] = 0
state[0][1] = ref[0]
flag = 0
for i in range(1,n):
cur = input()
if cur >= prev:
state[i][0] = min(state[i][0],state[i-1][0])
if cur >= prev[-1::-1]:
state[i][... | 1470933300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["2\n6"] | fc01082e3ed7877126e750bc380f5c63 | NoteIn the second test case, if we place a mine under the fourth building and then activate it, then all mines on the field are activated. The cost of such operations is six, $$$b=1$$$ coin for placing a mine and $$$a=5$$$ coins for activating. | Bertown is a city with $$$n$$$ buildings in a straight line.The city's security service discovered that some buildings were mined. A map was compiled, which is a string of length $$$n$$$, where the $$$i$$$-th character is "1" if there is a mine under the building number $$$i$$$ and "0" otherwise.Bertown's best sapper k... | For each test case, output one integer — the minimum number of coins that the sapper will have to pay. | The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case begins with a line containing two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 1000$$$) — the cost of activating and placing one mine, respectively. The next line c... | standard output | standard input | Python 3 | Python | 1,300 | train_015.jsonl | 9473e87dc494be577586b887e7ed05be | 256 megabytes | ["2\n1 1\n01000010\n5 1\n01101110"] | PASSED | import math
N = int(input())
for _ in range(N):
a,b = map(int,input().split())
s = input()
while len(s) !=0 and s[0] == '0':
s = s[1:]
while len(s) !=0 and s[-1] == '0':
s = s[0:-1]
zerosForSkip = int(math.ceil(a / b))
zeroesCount = 0
res = 0
tryFill = False
... | 1604327700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["25", "138"] | 3bf7c6e2491367b2afcb73fd14f62dd2 | null | Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money. The manager of logging factory wants them to go to the jungle and cut n trees with heights a1, a2, ..., an. They bought a chain saw from a shop. Each time they use the chain saw on the tree n... | The only line of output must contain the minimum cost of cutting all the trees completely. 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 of input contains an integer n (1 ≤ n ≤ 105). The second line of input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). The third line of input contains n integers b1, b2, ..., bn (0 ≤ bi ≤ 109). It's guaranteed that a1 = 1, bn = 0, a1 < a2 < ... < an and b1 > b2 > ... > bn. | standard output | standard input | Python 3 | Python | 2,100 | train_018.jsonl | 6fea2bd2e2b3cf5ea1d5f7f19dfe19d4 | 256 megabytes | ["5\n1 2 3 4 5\n5 4 3 2 0", "6\n1 2 3 10 20 30\n6 5 4 3 2 0"] | PASSED | read = lambda: map(int, input().split())
n = int(input())
a = list(read())
b = list(read())
dp = [0] * n
ch = [0]
def get(i, x):
return b[i] * x + dp[i]
def f1():
if len(ch) < 2:
return 0
return get(ch[0], a[i]) >= get(ch[1], a[i])
def f2():
if len(ch) < 2:
return 0
i1 = ch[-1]... | 1371992400 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
1 second | ["537.500000000", "2121.000000000"] | 295c768a404d11a4ac480aaaf653c45c | NoteConsider the first test case. If Manao listens to the songs in the order in which they were originally compiled, the mathematical expectation will be equal to 467.5 seconds. The maximum expected value is obtained by putting the first song at the end of the playlist.Consider the second test case. The song which is 3... | Manao's friends often send him new songs. He never listens to them right away. Instead, he compiles them into a playlist. When he feels that his mind is open to new music, he opens the playlist and starts to listen to the songs.Of course, there are some songs that Manao doesn't particuarly enjoy. To get more pleasure f... | In a single line print a single real number — the maximum expected listening time over all permutations of songs. The answer will be considered valid if the absolute or relative error does not exceed 10 - 9. | The first line contains a single integer n (1 ≤ n ≤ 50000). The i-th of the following n lines contains two integers, separated by a single space — li and pi (15 ≤ li ≤ 1000, 0 ≤ pi ≤ 100) — the length of the i-th song in seconds and the probability that Manao will like the song, in percents. | standard output | standard input | Python 2 | Python | 2,100 | train_004.jsonl | fd2a48fb44b0df05a3e9a8e99e362734 | 256 megabytes | ["3\n150 20\n150 50\n100 50", "4\n300 0\n300 50\n240 50\n360 80"] | PASSED | n=input()
v=[0]*n
e,f=0,0
for i in range(n):
a,b=map(int,raw_input().split())
e+=a
v[i]=(a*b,100-b)
v.sort(cmp=lambda x,y:x[1]*y[0]-x[0]*y[1])
for x in v:
e+=f*x[1]/100.
f+=x[0]/100.
print '%.12f'%e
| 1359387000 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
2 seconds | ["1\n-1\n1\n-1", "2"] | c4016ba22de92d1c7c2e6d13fedc062d | NoteIn the first sample, in the first and the third King's plan barbarians can capture the city 3, and that will be enough. In the second and the fourth plans all their attempts will not be effective.In the second sample the cities to capture are 3 and 5. | Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his kingdom. As the King can not wait for his daughter's marriage, reforms must be finished as soon as possible.The kingdom currentl... | For each plan print a single integer — the minimum number of cities that the barbarians need to capture, or print - 1 if all the barbarians' attempts to isolate important cities will not be effective. | The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cities in the kingdom. Each of the next n - 1 lines contains two distinct integers ui, vi (1 ≤ ui, vi ≤ n) — the indices of the cities connected by the i-th road. It is guaranteed that you can get from any city to any other one moving only... | standard output | standard input | PyPy 3 | Python | 2,800 | train_064.jsonl | 143c8460793f6650b2ab94cd4e58a5b0 | 256 megabytes | ["4\n1 3\n2 3\n4 3\n4\n2 1 2\n3 2 3 4\n3 1 2 4\n4 1 2 3 4", "7\n1 2\n2 3\n3 4\n1 5\n5 6\n5 7\n1\n4 2 4 6 7"] | PASSED | import sys
from collections import deque
def solve():
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
writelines = sys.stdout.writelines
N = int(readline())
G = [[] for i in range(N)]
for i in range(N-1):
u, v = map(int, readline().split())
G[u-1].append(v-1)
G... | 1452789300 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["? 1 1\n\n? 1 2\n\n? 1 3\n\n! 6 5 3"] | d70b9c132e08cadb760569495f48053c | NoteThe array $$$A$$$ in the example is $$$\{{1, 2, 4\}}$$$. The first element of the password is bitwise OR of $$$A_2$$$ and $$$A_3$$$, the second element is bitwise OR of $$$A_1$$$ and $$$A_3$$$ and the third element is bitwise OR of $$$A_1$$$ and $$$A_2$$$. Hence the password sequence is $$$\{{6, 5, 3\}}$$$. | This is an interactive problem.Ayush devised yet another scheme to set the password of his lock. The lock has $$$n$$$ slots where each slot can hold any non-negative integer. The password $$$P$$$ is a sequence of $$$n$$$ integers, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password... | null | The first line of input contains one integer $$$n$$$ $$$(2 \le n \le 1000)$$$ — the number of slots in the lock. | standard output | standard input | Python 3 | Python | 2,800 | train_017.jsonl | 855af565914412305e68fc055bcc27ee | 256 megabytes | ["3\n\n1\n\n2\n\n4"] | PASSED | def subset(n,k,res,bit):
while bit<1<<n:res.append(bit);x=bit&-bit;y=bit+x;bit=((bit&~y)//x>>1)|y
return res
n=int(input());bb=subset(13,6,[],63);bb=bb[:n];m=bb[-1].bit_length();xx=[0]*m;ans=[0]*n
for k in range(m):
cur=[]
for i,b in enumerate(bb):
if b>>k&1:cur.append(i+1)
print("?",len(cur... | 1591540500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n1", "2\n1 2", "1\n2", "1\n6", "1\n1"] | d6dc1895a58e13cdac98377819f6ec68 | NoteIn the first example, we set point $$$(0, 0)$$$ to group $$$A$$$ and points $$$(0, 1)$$$ and $$$(1, 0)$$$ to group $$$B$$$. In this way, we will have $$$1$$$ yellow number $$$\sqrt{2}$$$ and $$$2$$$ blue numbers $$$1$$$ on the blackboard.In the second example, we set points $$$(0, 1)$$$ and $$$(0, -1)$$$ to group $... | You are given a set of $$$n\ge 2$$$ pairwise different points with integer coordinates. Your task is to partition these points into two nonempty groups $$$A$$$ and $$$B$$$, such that the following condition holds:For every two points $$$P$$$ and $$$Q$$$, write the Euclidean distance between them on the blackboard: if t... | In the first line, output $$$a$$$ ($$$1 \le a \le n-1$$$) — the number of points in a group $$$A$$$. In the second line, output $$$a$$$ integers — the indexes of points that you include into group $$$A$$$. If there are multiple answers, print any. | The first line contains one integer $$$n$$$ $$$(2 \le n \le 10^3)$$$ — the number of points. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^6 \le x_i, y_i \le 10^6$$$) — the coordinates of the $$$i$$$-th point. It is guaranteed that all $$$n$$$ points are pairwise differ... | standard output | standard input | Python 3 | Python | 2,300 | train_019.jsonl | e89639cf2d4389383dc572105e9464b2 | 256 megabytes | ["3\n0 0\n0 1\n1 0", "4\n0 1\n0 -1\n1 0\n-1 0", "3\n-2 1\n1 1\n-1 0", "6\n2 5\n0 3\n-4 -1\n-5 -4\n1 0\n3 -1", "2\n-1000000 -1000000\n1000000 1000000"] | PASSED | from sys import stdin
def rl():
return [int(w) for w in stdin.readline().split()]
n, = rl()
x0,y0 = rl()
d = [0]
for i in range(n-1):
x,y = rl()
d.append((x-x0)**2 + (y-y0)**2)
while not any(x&1 for x in d):
for i in range(n):
d[i] >>= 1
A = [i+1 for i in range(n) if d[i]&1]
print(len(A))
p... | 1577628300 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["First", "Second"] | 808611f86c70659a1d5b8fc67875de31 | NoteIn first sample first player remove whole array in one move and win.In second sample first player can't make a move and lose. | Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts a... | Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). | First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array. Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109). | standard output | standard input | Python 3 | Python | 1,100 | train_009.jsonl | 65336d113ae609069348cf8a985ce9fc | 256 megabytes | ["4\n1 3 2 3", "2\n2 2"] | PASSED | input(); print(("Second", "First")[any(int(i) % 2 for i in input().split())])
| 1503068700 | [
"math",
"games"
] | [
1,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["6\naaaabb\naabbaa\nbbaaaa\nbbbbbb"] | d43786ca0472a5da735b04b9808c62d9 | null | Hamming distance between strings a and b of equal length (denoted by h(a, b)) is equal to the number of distinct integers i (1 ≤ i ≤ |a|), such that ai ≠ bi, where ai is the i-th symbol of string a, bi is the i-th symbol of string b. For example, the Hamming distance between strings "aba" and "bba" equals 1, they have ... | Print -1 if there's no suitable set of strings. Otherwise print on the first line number len — the length of each string. On the i-th of the next four lines print string s'i. If there are multiple sets with the minimum length of the strings, print any of them. | The first line contains space-separated integers h(s1, s2), h(s1, s3), h(s1, s4). The second line contains space-separated integers h(s2, s3) and h(s2, s4). The third line contains the single integer h(s3, s4). All given integers h(si, sj) are non-negative and do not exceed 105. It is guaranteed that at least one numbe... | standard output | standard input | Python 3 | Python | 2,400 | train_077.jsonl | fb3402eb1ed73655f48921abd801a033 | 256 megabytes | ["4 4 4\n4 4\n4"] | PASSED | def get_input():
a, b, d = map(int, input().split())
c, e = map(int, input().split())
f = int(input())
return [a, b, c, d, e, f]
def check_condition(a, b, c, d, e, f):
condition1 = (a + b + c) % 2 == 0
condition2 = (d + e + a) % 2 == 0
condition3 = (e + f + c) % 2 == 0
condi... | 1338737400 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["14", "131"] | a240eefaf9f3f35de9ea9860302b96d9 | NoteIn the first example, it's optimal to rearrange the elements of the given array in the following order: $$$[6, \, 2, \, 2, \, 2, \, 3, \, 1]$$$:$$$$$$\operatorname{gcd}(a_1) + \operatorname{gcd}(a_1, \, a_2) + \operatorname{gcd}(a_1, \, a_2, \, a_3) + \operatorname{gcd}(a_1, \, a_2, \, a_3, \, a_4) + \operatorname{... | This is the easy version of the problem. The only difference is maximum value of $$$a_i$$$.Once in Kostomuksha Divan found an array $$$a$$$ consisting of positive integers. Now he wants to reorder the elements of $$$a$$$ to maximize the value of the following function: $$$$$$\sum_{i=1}^n \operatorname{gcd}(a_1, \, a_2,... | Output the maximum value of the function that you can get by reordering elements of the array $$$a$$$. | The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the size of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_{1}, \, a_{2}, \, \dots, \, a_{n}$$$ ($$$1 \le a_{i} \le 5 \cdot 10^6$$$) — the array $$$a$$$. | standard output | standard input | PyPy 3-64 | Python | 2,100 | train_098.jsonl | 9ee9085d2d85e6408bc743204c76975e | 1024 megabytes | ["6\n2 3 1 2 6 2", "10\n5 7 10 3 1 10 100 3 42 54"] | PASSED | import sys
input = sys.stdin.readline
n=int(input())
A=list(map(int,input().split()))
MAX=max(A)+3
# エラトステネスの篩
# Sieve[i]で、iの最も小さい約数を返す。
Sieve=[i for i in range(MAX)]
for i in range(2,MAX):
if Sieve[i]!=i:
continue
for j in range(i,MAX,i):
if Sieve[j]==j:
S... | 1637925300 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
2 seconds | ["0", "1\n2 4", "5\n5 2\n2 3\n3 4\n4 7\n6 8"] | 1bf6e28c366b555664a3a6d2c0ded909 | NoteIn the first example, we cannot add any edge.In the second example, the initial forests are as follows.We can add an edge $$$(2, 4)$$$. | This is the hard version of the problem. The only difference between the two versions is the constraint on $$$n$$$. You can make hacks only if all versions of the problem are solved.A forest is an undirected graph without cycles (not necessarily connected).Mocha and Diana are friends in Zhijiang, both of them have a fo... | The first line contains only one integer $$$h$$$, the maximum number of edges Mocha and Diana can add. Each of the next $$$h$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$) — the edge you add each time. If there are multiple correct answers, you can print any one of them. | The first line contains three integers $$$n$$$, $$$m_1$$$ and $$$m_2$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le m_1, m_2 < n$$$) — the number of nodes and the number of initial edges in Mocha's forest and Diana's forest. Each of the next $$$m_1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$... | standard output | standard input | PyPy 3 | Python | 2,500 | train_095.jsonl | 4318a30d916c7f2a01651423c9fedd52 | 256 megabytes | ["3 2 2\n1 2\n2 3\n1 2\n1 3", "5 3 2\n5 4\n2 1\n4 3\n4 3\n1 4", "8 1 2\n1 7\n2 6\n1 5"] | PASSED | import collections as _collections
import random as _random
import sys as _sys
def _main():
[tests_n] = [1]
for i_test in range(tests_n):
[n, m_1, m_2] = _read_ints()
edges_1 = tuple(_read_n_egdes(m_1))
edges_2 = tuple(_read_n_egdes(m_2))
new_edges = add_max_edges_n(... | 1629038100 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
3 seconds | ["1", "0", "0", "1", "0", "2"] | 92afa6f770493109facb1b9ca8d94e0c | NoteThe picture corresponding to the first example: You can, for example, increase weight of the edge $$$(1, 6)$$$ or $$$(6, 3)$$$ by $$$1$$$ to unify MST.The picture corresponding to the last example: You can, for example, increase weights of edges $$$(1, 5)$$$ and $$$(2, 4)$$$ by $$$1$$$ to unify MST. | You are given an undirected weighted connected graph with $$$n$$$ vertices and $$$m$$$ edges without loops and multiple edges.The $$$i$$$-th edge is $$$e_i = (u_i, v_i, w_i)$$$; the distance between vertices $$$u_i$$$ and $$$v_i$$$ along the edge $$$e_i$$$ is $$$w_i$$$ ($$$1 \le w_i$$$). The graph is connected, i. e. f... | Print one integer — the minimum number of operations to unify MST of the initial graph without changing the cost of MST. | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5, n - 1 \le m \le 2 \cdot 10^5$$$) — the number of vertices and the number of edges in the initial graph. The next $$$m$$$ lines contain three integers each. The $$$i$$$-th line contains the description of the $$$i$$$-th e... | standard output | standard input | Python 3 | Python | 2,100 | train_016.jsonl | a321fd26173999f1cd152127162d06cb | 256 megabytes | ["8 10\n1 2 1\n2 3 2\n2 4 5\n1 4 2\n6 3 3\n6 1 3\n3 5 2\n3 7 1\n4 8 1\n6 2 4", "4 3\n2 1 3\n4 3 4\n2 4 1", "3 3\n1 2 1\n2 3 2\n1 3 3", "3 3\n1 2 1\n2 3 3\n1 3 3", "1 0", "5 6\n1 2 2\n2 3 1\n4 5 3\n2 4 2\n1 4 2\n1 5 3"] | PASSED | import sys
input = sys.stdin.readline
n,m=map(int,input().split())
EDGE=[list(map(int,input().split())) for i in range(m)]
EDGE.sort(key=lambda x:x[2])
WCHANGE=[]
for i in range(1,m):
if EDGE[i-1][2]!=EDGE[i][2]:
WCHANGE.append(i)
WCHANGE.append(m)
Group=[i for i in range(n+1)]
def find(x):
while ... | 1548254100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["5\n1 2 3 4 5", "6\n1 2 9 4 5 3", "-1"] | e984b4e1120b8fb083a3ebad9bb93709 | NoteIn the first test firstly you can take courses number 1 and 2, after that you can take the course number 4, then you can take the course number 5, which is the main. After that you have to take only the course number 3, which is the last not passed main course. | Now you can take online courses in the Berland State University! Polycarp needs to pass k main online courses of his specialty to get a diploma. In total n courses are availiable for the passage.The situation is complicated by the dependence of online courses, for each course there is a list of those that must be passe... | Print -1, if there is no the way to get a specialty. Otherwise, in the first line print the integer m — the minimum number of online-courses which it is necessary to pass to get a specialty. In the second line print m distinct integers — numbers of courses which it is necessary to pass in the chronological order of th... | The first line contains n and k (1 ≤ k ≤ n ≤ 105) — the number of online-courses and the number of main courses of Polycarp's specialty. The second line contains k distinct integers from 1 to n — numbers of main online-courses of Polycarp's specialty. Then n lines follow, each of them describes the next course: the i... | standard output | standard input | Python 3 | Python | 1,500 | train_006.jsonl | c20814721939efd11bbcc7a1f347d3b9 | 256 megabytes | ["6 2\n5 3\n0\n0\n0\n2 2 1\n1 4\n1 5", "9 3\n3 9 5\n0\n0\n3 9 4 5\n0\n0\n1 8\n1 6\n1 2\n2 1 2", "3 3\n1 2 3\n1 2\n1 3\n1 1"] | PASSED | import collections as col
import itertools as its
import sys
import operator
from copy import copy, deepcopy
class Solver:
def __init__(self):
pass
def solve(self):
n, k = map(int, input().split())
q = list(map(lambda x: int(x) - 1, input().split()))
used = [False] * n
... | 1489233600 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
0.5 second | ["YES", "YES", "NO"] | d3a0402de1338a1a542a86ac5b484acc | null | There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in... | Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO". | The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood. | standard output | standard input | Python 3 | Python | 1,600 | train_017.jsonl | 1feb2bb7e3510e258a58701d7cb91b79 | 256 megabytes | ["3\n1 1 1", "6\n1 0 1 1 1 0", "6\n1 0 0 1 0 1"] | PASSED | n=int(input())
L=list(map(int,input().split()))
prime=[]
nn=n
i=2
while i*i<=n:
if nn%i==0:
prime.append(i)
while nn%i==0:
nn//=i
i+=1
#print(prime,nn)
if nn!=1:
prime.append(nn)
if prime[0]==2:
prime=prime[1:]
if n%4==0:
prime=[4]+prime
#print(prime)
out=False
for... | 1301410800 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["fatma\nmona", "likes\nposted"] | b1a86308739067f2b6c9940b564e2648 | null | Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).This priority factor will be affected by three types of actions: 1. "X posted on Y's wall" (15 poi... | Print m lines, where m is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority factor... | The first line contains your name. The second line contains an integer n, which is the number of actions (1 ≤ n ≤ 100). Then n lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra spaces. All... | standard output | standard input | Python 3 | Python | 1,500 | train_013.jsonl | 791614154f3071e5cfd2550bb1ad06a3 | 256 megabytes | ["ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post", "aba\n1\nlikes likes posted's post"] | PASSED | r={'posted':15,'commented':10,'likes':5}
n=input()
a={}
m=set()
for _ in '0'*int(input()):
t=input().split()
s=t[0]
p=t[3-(t[1]=='likes')][:-2]
m.add(s)
m.add(p)
if s==n:
a[p]=a.get(p,0)+r[t[1]]
if p==n:
a[s]=a.get(s,0)+r[t[1]]
if n in m:
m.remove(n)
for v in sorted(set(a.values())|set([0]))[::-1]:
print('... | 1302706800 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["6", "9"] | ca22cf92727a38fbb3c085b9362602db | NoteThe figure below shows one of possible division into pairs in the first test. If you connect universities number 1 and 6 (marked in red) and universities number 2 and 5 (marked in blue) by using the cable, the total distance will equal 6 which will be the maximum sum in this example. | Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's possible to get from any town to any other town. In Treeland there are 2k universities which are located in different towns. Recently, the president signed the decree to connect universities by high-speed network.The Ministr... | Print the maximum possible sum of distances in the division of universities into k pairs. | The first line of the input contains two integers n and k (2 ≤ n ≤ 200 000, 1 ≤ k ≤ n / 2) — the number of towns in Treeland and the number of university pairs. Consider that towns are numbered from 1 to n. The second line contains 2k distinct integers u1, u2, ..., u2k (1 ≤ ui ≤ n) — indices of towns in which universi... | standard output | standard input | PyPy 3 | Python | 1,800 | train_021.jsonl | bca5d4900ad1b57488a9095c876c7b89 | 256 megabytes | ["7 2\n1 5 6 2\n1 3\n3 2\n4 5\n3 7\n4 3\n4 6", "9 3\n3 2 1 6 5 9\n8 9\n3 2\n2 7\n3 4\n7 6\n4 5\n2 1\n2 8"] | PASSED | from collections import defaultdict
from sys import stdin
def put(): return map(int, stdin.readline().split())
def dfs():
s = [(1,0)]
ans = 0
vis = [0]*(n+1)
while s:
i,p = s.pop()
if vis[i]==0:
vis[i]=1
s.append((i,p))
for j in tree[i]:
... | 1469205300 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["YES\n1 2\n3 4\nNO\nYES\n3 4\n7 8\n11 12\n2 1\n6 5\n10 9\nYES\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14"] | d4fc7e683f389e0c7bbee8e115cef459 | NoteIn the first test case, splitting into pairs $$$(1, 2)$$$ and $$$(3, 4)$$$ is suitable, same as splitting into $$$(1, 4)$$$ and $$$(3, 2)$$$.In the second test case, $$$(1 + 0) \cdot 2 = 1 \cdot (2 + 0) = 2$$$ is not divisible by $$$4$$$, so there is no partition. | A new entertainment has appeared in Buryatia — a mathematical circus! The magician shows two numbers to the audience — $$$n$$$ and $$$k$$$, where $$$n$$$ is even. Next, he takes all the integers from $$$1$$$ to $$$n$$$, and splits them all into pairs $$$(a, b)$$$ (each integer must be in exactly one pair) so that for e... | For each test case, first output the string "YES" if there is a split into pairs, and "NO" if there is none. If there is a split, then in the following $$$\frac{n}{2}$$$ lines output pairs of the split, in each line print $$$2$$$ numbers — first the integer $$$a$$$, then the integer $$$b$$$. | 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 single line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$, $$$0 \leq k \leq 10^9$$$, $$$n$$$ is even) — the number... | standard output | standard input | PyPy 3-64 | Python | 800 | train_090.jsonl | f8d305b6370b60602a0a646b9b4a4d42 | 256 megabytes | ["4\n\n4 1\n\n2 0\n\n12 10\n\n14 11"] | PASSED | tests = int(input())
def solve(n, k):
if(k&1):
print("YES")
for i in range(1, n+1, 2):
print(str(i) + " " + str(i+1))
else:
if(k % 4 == 0):
print("NO")
else:
print("YES")
for i in range(1, n+1, 4):
print(str(i+1) + " " + str(i))
if(i+3 <= n):
print(str(i+2) + " " + str(i+3))
... | 1660660500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["1 1\n1 1\n2 0\n3 1\n2 4\n5 4", "4 3\n2 5\n2 1\n2 5\n1 5\n4 1\n1 2\n3 2"] | b021a3c7ae119671c81c51da7cfabdb3 | null | You are given $$$n$$$ distinct points on a plane. The coordinates of the $$$i$$$-th point are $$$(x_i, y_i)$$$.For each point $$$i$$$, find the nearest (in terms of Manhattan distance) point with integer coordinates that is not among the given $$$n$$$ points. If there are multiple such points — you can choose any of th... | Print $$$n$$$ lines. In the $$$i$$$-th line, print the point with integer coordinates that is not among the given $$$n$$$ points and is the nearest (in terms of Manhattan distance) to the $$$i$$$-th point from the input. Output coordinates should be in range $$$[-10^6; 10^6]$$$. It can be shown that any optimal answer ... | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of points in the set. The next $$$n$$$ lines describe points. The $$$i$$$-th of them contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le 2 \cdot 10^5$$$) — coordinates of the $$$i$$$-th point. It is g... | standard output | standard input | PyPy 3 | Python | 1,900 | train_104.jsonl | 3241226f7d89dd9a4757c78b68f8a6c6 | 256 megabytes | ["6\n2 2\n1 2\n2 1\n3 2\n2 3\n5 5", "8\n4 4\n2 4\n2 2\n2 3\n1 4\n4 2\n1 3\n3 3"] | PASSED | # def redirect_io():
# import pathlib, sys
# fname = pathlib.Path(__file__).parent/"input.txt"
# sys.stdin = open(fname, 'r')
# redirect_io()
import sys
input = sys.stdin.buffer.readline
from collections import deque
# NOTE: Got MLE's originally, space optimal to just keep hashmap (have access to points)... | 1646922900 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["11", "14", "36"] | 189a8a9a6e99ed52bda9a5773bf2621b | null | There are three horses living in a horse land: one gray, one white and one gray-and-white. The horses are really amusing animals, which is why they adore special cards. Each of those cards must contain two integers, the first one on top, the second one in the bottom of the card. Let's denote a card with a on the top an... | Print a single integer — the answer to the problem. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | The first line contains two integers n, m (1 ≤ n ≤ 105, 2 ≤ m ≤ 109). The second line contains the sequence of integers a1, a2, ..., an (2 ≤ ai ≤ 109). Note, that the numbers in the sequence can coincide. The numbers in the lines are separated by single spaces. | standard output | standard input | Python 3 | Python | 2,200 | train_011.jsonl | ac1c209e4a0a35c1c535a917c9b2ccb2 | 256 megabytes | ["1 6\n2", "1 6\n7", "2 10\n13 7"] | PASSED | # written with help of editorial
n, m = map(int, input().split())
a = list(map(int, input().split()))
def gcd(x, y):
while y:
x, y = y, x % y
return x
g = 0
for x in a:
g = gcd(g, x - 1)
answer = 0
def process(x):
global answer
if x % 2 == 0:
return 0
for i in range(30):
... | 1360596600 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
1 second | ["6", "2", "2"] | 16d4035b138137bbad247ccd5e560051 | null | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.These events are given as a sequence of strings "name1 reposted name2", where name1 is the nam... | Print a single integer — the maximum length of a repost chain. | The first line of the input contains integer n (1 ≤ n ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have len... | standard output | standard input | Python 3 | Python | 1,200 | train_027.jsonl | 42d7229f42127e235f0fdac93052e2ea | 256 megabytes | ["5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp", "1\nSoMeStRaNgEgUe reposted PoLyCaR... | PASSED | from collections import defaultdict
n=int(input())
d=defaultdict(list)
for i in range(n):
s=list(map(str,input().split()))
for i in range(3):
s[i]=s[i].lower()
d[s[2]].append(s[0])
q=list()
q.append('polycarp')
q.append(None)
c=0
b=1
while q:
a=q[0]
q.pop(0)
b-=1
if a==None :
... | 1425740400 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
1 second | ["0\n36\n0\n0\n1999999994\n1999999994\n2\n4"] | 18f2e54e4147e8887da737d5b6639473 | null | Three friends are going to meet each other. Initially, the first friend stays at the position $$$x = a$$$, the second friend stays at the position $$$x = b$$$ and the third friend stays at the position $$$x = c$$$ on the coordinate axis $$$Ox$$$.In one minute each friend independently from other friends can change the ... | For each test case print the answer on it — the minimum total pairwise distance (the minimum sum of distances between each pair of friends) if friends change their positions optimally. Each friend will move no more than once. So, more formally, you have to find the minimum total pairwise distance they can reach after o... | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 1000$$$) — the number of test cases. The next $$$q$$$ lines describe test cases. The $$$i$$$-th test case is given as three integers $$$a, b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — initial positions of the first, second and third friend co... | standard output | standard input | Python 3 | Python | 900 | train_021.jsonl | e0ce1c983175912654155578f9c9eaf9 | 256 megabytes | ["8\n3 3 4\n10 20 30\n5 5 5\n2 4 3\n1 1000000000 1000000000\n1 1000000000 999999999\n3 2 5\n3 2 6"] | PASSED | for _ in range(int(input())):
a, b, c = map(int, input().split())
x = abs(a - b) + abs(a - c) + abs(b - c)
print(max(0, x - 4))
| 1576157700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["YES\nNO"] | d53575e38f79990304b679ff90c5de34 | NoteIn first example Vova's character at first learns the spell with 5 damage and 10 mana cost per second. Next query is a fight with monster which can kill character in 20 seconds and has 50 health points. Vova kills it in 10 seconds (spending 100 mana). Next monster has 52 health, so Vova can't deal that much damage ... | Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells.Vova's character can learn new spells during the game. Every spell is characterized by two values xi and yi — damage per second and mana cost per second, respectively. Vova do... | For every query of second type print YES if Vova is able to win the fight with corresponding monster and NO otherwise. | The first line contains two integer numbers q and m (2 ≤ q ≤ 105, 1 ≤ m ≤ 1012) — the number of queries and the amount of mana at the beginning of every fight. i-th of each next q lines contains three numbers ki, ai and bi (1 ≤ ki ≤ 2, 1 ≤ ai, bi ≤ 106). Using them you can restore queries this way: let j be the index ... | standard output | standard input | Python 3 | Python | 3,100 | train_077.jsonl | 4fda2ed51bffa6f0d333cf63e278d633 | 256 megabytes | ["3 100\n1 4 9\n2 19 49\n2 19 49"] | PASSED | #!/usr/bin/env python3
# solution after hint
# (instead of best hit/mana spell store convex hull of spells)
# O(n^2) instead of O(n log n)
[q, m] = map(int, input().strip().split())
qis = [tuple(map(int, input().strip().split())) for _ in range(q)]
mod = 10**6
j = 0
spell_chull = [(0, 0)] # lower hull _/
def is_... | 1490625300 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
4 seconds | ["1 2", "2 4", "1 4"] | acb7acc82c52db801f515631dca20eba | null | You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$.Your problem is to find such pair of indices $$$i, j$$$ ($$$1 \le i < j \le n$$$) that $$$lcm(a_i, a_j)$$$ is minimum possible.$$$lcm(x, y)$$$ is the least common multiple of $$$x$$$ and $$$y$$$ (minimum positive number such tha... | Print two integers $$$i$$$ and $$$j$$$ ($$$1 \le i < j \le n$$$) such that the value of $$$lcm(a_i, a_j)$$$ is minimum among all valid pairs $$$i, j$$$. If there are multiple answers, you can print any. | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 10^6$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^7$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. | standard output | standard input | PyPy 2 | Python | 2,200 | train_003.jsonl | 5cc950bc4d43701630f80ed0f9ff6dfa | 1024 megabytes | ["5\n2 4 8 3 6", "5\n5 2 11 3 7", "6\n2 5 10 1 10 2"] | PASSED | import math
import re
import sys
from collections import defaultdict
def read(type = int):
return type(raw_input())
def read_list(type = int, split = ' ', F = None):
if F:
return map(lambda x: F(type(x)), raw_input().split(split))
return map(type, raw_input().split(split))
def read_list_of_list(N, type =... | 1555425300 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["3\n1 0 2 \n3\n1 1 2\n1\n0"] | e21f235ffe7f26d9a7af12a7f3f9a2fd | NoteIn the first test case, the following process results in bacteria with total mass $$$9$$$: Day $$$1$$$: The bacterium with mass $$$1$$$ splits. There are now two bacteria with mass $$$0.5$$$ each. Night $$$1$$$: All bacteria's mass increases by one. There are now two bacteria with mass $$$1.5$$$. Day $$$2$$$: N... | Phoenix has decided to become a scientist! He is currently investigating the growth of bacteria.Initially, on day $$$1$$$, there is one bacterium with mass $$$1$$$.Every day, some number of bacteria will split (possibly zero or all). When a bacterium of mass $$$m$$$ splits, it becomes two bacteria of mass $$$\frac{m}{2... | For each test case, if there is no way for the bacteria to exactly achieve total mass $$$n$$$, print -1. Otherwise, print two lines. The first line should contain an integer $$$d$$$ — the minimum number of nights needed. The next line should contain $$$d$$$ integers, with the $$$i$$$-th integer representing the number... | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^9$$$) — the sum of bacteria masses that Phoenix is interested in. | standard output | standard input | Python 3 | Python | 1,900 | train_008.jsonl | ae6833ee413cffa26830e7570a13cafb | 256 megabytes | ["3\n9\n11\n2"] | PASSED | for _ in range(int(input())):
arr = []
n = int(input())
x = 1
while x < n:
arr.append(x)
n -= x
x *= 2
if n > 0:
arr.append(n)
arr.sort()
s = []
print(len(arr)-1)
for i in range(len(arr)-1):
s.append(arr[i+1]-arr[i])
print(*s)
| 1588343700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["19 8\n-1\n-1\n-1\n2000000000 1000000000\n0"] | d6721fb3dd02535fc08fc69a4811d60c | null | For the first place at the competition, Alex won many arrays of integers and was assured that these arrays are very expensive. After the award ceremony Alex decided to sell them. There is a rule in arrays pawnshop: you can sell array only if it can be compressed to a generator.This generator takes four non-negative num... | For every array print: $$$-1$$$, if there are no such four numbers that generate this array; $$$0$$$, if $$$m$$$ can be arbitrary large; the maximum value $$$m$$$ and any appropriate $$$c$$$ ($$$0 \leq c < m$$$) in other cases. | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of arrays. The first line of array description contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the size of this array. The second line of array description contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 ... | standard output | standard input | Python 3 | Python | 1,500 | train_092.jsonl | 96385ea75a3f003e972a1f3f84e717f8 | 256 megabytes | ["6\n6\n1 9 17 6 14 3\n3\n4 2 2\n3\n7 3 4\n3\n2 2 4\n5\n0 1000000000 0 1000000000 0\n2\n1 1"] | PASSED | def fun(a,n):
if n == 1 or n == 2:
return 0
p = set()
for i in range(1,n):
p.add(a[i]-a[i-1])
p = list(p)
p.sort()
if len(p) > 2:
return -1
elif len(p) == 2:
m = p[1]+(abs(p[0]) if p[0]<0 else -p[0])
c = p[1]
if m <= max(a... | 1616322000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n2\n2\n5"] | 130fdf010c228564611a380b6dd37a34 | NoteIn the first test case, we can achieve the goal with a single operation: choose $$$v = 2$$$ and $$$c = [1, 2]$$$, resulting in $$$a_1 = 1, a_2 = 2$$$.In the second test case, we can achieve the goal with two operations: first, choose $$$v = 2$$$ and $$$c = [3, 3]$$$, resulting in $$$a_1 = 3, a_2 = 3, a_3 = 0$$$. Th... | We are given a rooted tree consisting of $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$. The root of the tree is the vertex $$$1$$$ and the parent of the vertex $$$v$$$ is $$$p_v$$$.There is a number written on each vertex, initially all numbers are equal to $$$0$$$. Let's denote the number written on the vertex $$$... | For each test case output the minimum number of operations needed. | The first line contains an 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 contains a single integer $$$n$$$ $$$(2\le n\le 2 \cdot 10^5)$$$ — the number of the vertices in the tree. The second line of each test case contain... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_083.jsonl | 084838375de70eaf0619dec6dded977e | 256 megabytes | ["4\n\n2\n\n1\n\n1 5\n\n2 9\n\n3\n\n1 1\n\n4 5\n\n2 4\n\n6 10\n\n4\n\n1 2 1\n\n6 9\n\n5 6\n\n4 5\n\n2 4\n\n5\n\n1 2 3 4\n\n5 5\n\n4 4\n\n3 3\n\n2 2\n\n1 1"] | PASSED | import collections, math, bisect, heapq, random, functools, itertools, copy, typing
import platform; LOCAL = (platform.uname().node == 'AMO')
# Fast IO Region
import os, sys; from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fi... | 1655390100 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["3\n19 11\n15 9\n3 7", "-1", "1\n15 8", "-1"] | d1e4269be1f81875c163c15a0759df88 | NoteIn the first sample let's consider the array $$$t$$$ for each pair: $$$(19,\, 11)$$$: $$$t = [8, 3, 2, 1]$$$; $$$(15,\, 9)$$$: $$$t = [6, 3]$$$; $$$(3,\, 7)$$$: $$$t = [1]$$$. So in total $$$t = [8, 3, 2, 1, 6, 3, 1]$$$, which is the same as the input $$$t$$$ (up to a permutation).In the second test case it is ... | Let's consider Euclid's algorithm for finding the greatest common divisor, where $$$t$$$ is a list:function Euclid(a, b): if a < b: swap(a, b) if b == 0: return a r = reminder from dividing a by b if r > 0: append r to the back of t return Euclid(b, r)There is an array $$$p$$$ ... | If the answer does not exist, output $$$-1$$$. If the answer exists, in the first line output $$$k$$$ ($$$1 \le k \le 2 \cdot 10^4$$$) — the size of your array $$$p$$$, i. e. the number of pairs in the answer. The $$$i$$$-th of the next $$$k$$$ lines should contain two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i,... | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^3$$$, $$$1 \le m \le 10^9$$$) — the length of the array $$$t$$$ and the constraint for integers in pairs. The second line contains $$$n$$$ integers $$$t_1, t_2, \ldots, t_n$$$ ($$$1 \le t_i \le m$$$) — the elements of the array $$$t$$$. | standard output | standard input | PyPy 3 | Python | 2,800 | train_103.jsonl | 5d2a0f28f67fcbeea892ef652a817c55 | 256 megabytes | ["7 20\n1 8 1 6 3 2 3", "2 10\n7 1", "2 15\n1 7", "1 1000000000\n845063470"] | PASSED | # import io,os
# read = io.BytesIO(os.read(0, os.fstat(0).st_size))
# I = lambda: [*map(int, read.readline().split())]
import sys
I=lambda:[*map(int,sys.stdin.readline().split())]
n, m = I()
t = I()
bad = []
for guy in t:
if m < 2 * guy + 1:
print(-1)
exit()
elif m < 3 * guy:
bad.append(guy)
... | 1652970900 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["25\n42\n35"] | 2c67ee95eba7ffbbed99cb488abb5f3d | NoteThe points in the first testcase of the example: $$$(1, 0)$$$, $$$(2, 0)$$$; $$$(2, 8)$$$, $$$(3, 8)$$$, $$$(4, 8)$$$; $$$(0, 1)$$$, $$$(0, 4)$$$, $$$(0, 6)$$$; $$$(5, 4)$$$, $$$(5, 5)$$$. The largest triangle is formed by points $$$(0, 1)$$$, $$$(0, 6)$$$ and $$$(5, 4)$$$ — its area is $$$\frac{25}{2}$$$. Thu... | A rectangle with its opposite corners in $$$(0, 0)$$$ and $$$(w, h)$$$ and sides parallel to the axes is drawn on a plane.You are given a list of lattice points such that each point lies on a side of a rectangle but not in its corner. Also, there are at least two points on every side of a rectangle.Your task is to choo... | For each testcase print a single integer — the doubled maximum area of a triangle formed by such three points that exactly two of them belong to the same side. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains two integers $$$w$$$ and $$$h$$$ ($$$3 \le w, h \le 10^6$$$) — the coordinates of the corner of a rectangle. The next two lines contain the description of the points on two horiz... | standard output | standard input | Python 3 | Python | 1,000 | train_095.jsonl | ce5a497333c5150c253d7ad1f2606384 | 256 megabytes | ["3\n5 8\n2 1 2\n3 2 3 4\n3 1 4 6\n2 4 5\n10 7\n2 3 9\n2 1 7\n3 1 3 4\n3 4 5 6\n11 5\n3 1 6 8\n3 3 6 8\n3 1 3 4\n2 2 4"] | PASSED | def base(arr):
return abs(arr[-1]-arr[1])
for _ in range(int(input())):
n,m=map(int,input().split())
h1=list(map(int,input().split()))
h2=list(map(int,input().split()))
v1=list(map(int,input().split()))
v2=list(map(int,input().split()))
print(max(max(base(h1),base(h2))*m,... | 1639841700 | [
"geometry",
"math"
] | [
0,
1,
0,
1,
0,
0,
0,
0
] | |
1 second | ["4\n2\n0\n4\n0", "4\n2"] | c61f07f38156a6038a9bc57da9b65ea9 | NoteThe bitwise-xor sum of the empty set is 0 and the bitwise-xor sum of a set containing one element is that element itself. | Ehab has an array a of n integers. He likes the bitwise-xor operation and he likes to bother Mahmoud so he came up with a problem. He gave Mahmoud q queries. In each of them, he gave Mahmoud 2 integers l and x, and asked him to find the number of subsequences of the first l elements of the array such that their bitwise... | For each query, output its answer modulo 109 + 7 in a newline. | The first line contains integers n and q (1 ≤ n, q ≤ 105), the number of elements in the array and the number of queries. The next line contains n integers a1, a2, ..., an (0 ≤ ai < 220), the elements of the array. The next q lines, each contains integers l and x (1 ≤ l ≤ n, 0 ≤ x < 220), representing the queries... | standard output | standard input | PyPy 2 | Python | 2,400 | train_066.jsonl | 74ea04621b243e6589c7b03e436547bd | 512 megabytes | ["5 5\n0 1 2 3 4\n4 3\n2 0\n3 7\n5 7\n5 8", "3 2\n1 1 1\n3 1\n2 0"] | PASSED | import sys
range = xrange
input = raw_input
MOD = 10**9 + 7
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
n = inp[ii]; ii += 1
q = inp[ii]; ii += 1
A = inp[ii: ii + n]; ii += n
zeros = [1]
Abase = []
base = []
for i in range(n):
a = A[i]
for b in base:
if a ^ b < a:
a ^= b
... | 1522771500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n3", "2\n3 4", "0", "1\n999999998"] | b96427767128e235d46bea8d5c4cbbaf | NoteIn the first test, $$$p=2$$$. If $$$x \le 2$$$, there are no valid permutations for Yuzu. So $$$f(x)=0$$$ for all $$$x \le 2$$$. The number $$$0$$$ is divisible by $$$2$$$, so all integers $$$x \leq 2$$$ are not good. If $$$x = 3$$$, $$$\{1,2,3\}$$$ is the only valid permutation for Yuzu. So $$$f(3)=1$$$, so the ... | This is the hard version of the problem. The difference between versions is the constraints on $$$n$$$ and $$$a_i$$$. You can make hacks only if all versions of the problem are solved.First, Aoi came up with the following idea for the competitive programming problem:Yuzu is a girl who collecting candies. Originally, sh... | In the first line, print the number of good integers $$$x$$$. In the second line, output all good integers $$$x$$$ in the ascending order. It is guaranteed that the number of good integers $$$x$$$ does not exceed $$$10^5$$$. | The first line contains two integers $$$n$$$, $$$p$$$ $$$(2 \le p \le n \le 10^5)$$$. It is guaranteed, that the number $$$p$$$ is prime (it has exactly two divisors $$$1$$$ and $$$p$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$. | standard output | standard input | PyPy 3 | Python | 2,300 | train_033.jsonl | 8e7f812ab7c09ce85936d67c3f1ba480 | 256 megabytes | ["3 2\n3 4 5", "4 3\n2 3 5 6", "4 3\n9 1 1 1", "3 2\n1000000000 1 999999999"] | PASSED | import sys
import collections
def input():
return sys.stdin.readline().rstrip()
def split_input():
return [int(i) for i in input().split()]
n,p = split_input()
a = split_input()
start = max(a) - n + 1
x = [0 for i in range(n)]
for i in a:
ind = i - start
if ind <= 0:
x[0] += 1
else:
x[ind] += 1
for i in ... | 1593610500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | a16bb696858bc592c33dcf0fd99df197 | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Let's dive into one of the most interesting areas of magic — writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space charact... | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 ( = 220) bytes. Newlines are included in this size. In the Windows operating system used on the te... | standard output | standard input | PyPy 2 | Python | 1,700 | train_022.jsonl | 1a4a78ec10ba184a0b9273620183bdc7 | 256 megabytes | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | PASSED | lis = []
while True:
try:
val = raw_input()
isAmplifying = False
for c in val:
if not c.isspace():
if c == "#":
isAmplifying = True
break
else:
break
if isAmplifying:
lis.append((val, True))
else:
lis.append(("".join(val.split()... | 1332860400 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["4\n0 1 2 3\n2\n0 2\n2\n2 3"] | 04a37e9c68761f9a2588c0bbecad2147 | NoteIn the first test case, any number of breaks between $$$0$$$ and $$$3$$$ could happen during the match: Alice holds serve, Borys holds serve, Alice holds serve: $$$0$$$ breaks; Borys holds serve, Alice holds serve, Alice breaks serve: $$$1$$$ break; Borys breaks serve, Alice breaks serve, Alice holds serve: $$$... | Alice and Borys are playing tennis.A tennis match consists of games. In each game, one of the players is serving and the other one is receiving.Players serve in turns: after a game where Alice is serving follows a game where Borys is serving, and vice versa.Each game ends with a victory of one of the players. If a game... | For each test case print two lines. In the first line, print a single integer $$$m$$$ ($$$1 \le m \le a + b + 1$$$) — the number of values of $$$k$$$ such that exactly $$$k$$$ breaks could happen during the match. In the second line, print $$$m$$$ distinct integers $$$k_1, k_2, \ldots, k_m$$$ ($$$0 \le k_1 < k_2 <... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). Description of the test cases follows. Each of the next $$$t$$$ lines describes one test case and contains two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^5$$$; $$$a + b > 0$$$) — the num... | standard output | standard input | PyPy 3-64 | Python | 1,300 | train_086.jsonl | 91fe744b5f1d05510066faf7c91f39fc | 512 megabytes | ["3\n2 1\n1 1\n0 5"] | PASSED | for _ in range(int(input())):
a, b = list(map(int, input().split()))
if a == 0 and b == 0:
print(0)
elif a == 0 or b == 0:
if a == 0 and b % 2 == 1:
print(2)
print(b // 2, b // 2 + 1)
elif b == 0 and a % 2 == 1:
print(2)
print(a // 2, a... | 1629815700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\n4 2 4\nYES\n55 5 5 35\nNO\nNO\nYES\n1 1 1 1 1 1 1 1\nNO\nYES\n3 1 1\nYES\n111111110 111111110 111111110 111111110 111111110 111111110 111111110 111111110 111111120"] | 6b94dcd088b0328966b54acefb5c6d22 | null | You are given two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 100$$$). Represent the number $$$n$$$ as the sum of $$$k$$$ positive integers of the same parity (have the same remainder when divided by $$$2$$$).In other words, find $$$a_1, a_2, \ldots, a_k$$$ such that all $$$a_i>0$$... | For each test case print: YES and the required values $$$a_i$$$, if the answer exists (if there are several answers, print any of them); NO if the answer does not exist. The letters in the words YES and NO can be printed in any case. | The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Next, $$$t$$$ test cases are given, one per line. Each test case is two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 100$$$). | standard output | standard input | Python 3 | Python | 1,200 | train_004.jsonl | 28b8458492b817a649cc5bbd13c90cef | 256 megabytes | ["8\n10 3\n100 4\n8 7\n97 2\n8 8\n3 10\n5 3\n1000000000 9"] | PASSED | t = input()
t = int(t)
while t > 0 :
line = input()
i = line.split()
x = int(i[0])
y = int(i[1])
o = x - (y-1)
if o%2==1 and o>0 :
print('YES')
for j in range(y-1) :
print('1', end = " ")
print(o)
t = t-1
continue
e = x - (y-1)*2
if e%2... | 1589034900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n2 1 4", "NO", "0"] | 0939354d9bad8301efb79a1a934ded30 | null | A system of n vessels with water is given. Several pairs of vessels are connected by tubes with transfusion mechanisms. One may transfer an integer amount of liters of water between two vessels connected by such tube (tube works in both directions). There might be multiple tubes between two vessels. Total number of tub... | Print "NO" (without quotes), if such sequence of transfusions does not exist. Otherwise print any suitable sequence in the following format. On the first line print the total number of transfusions k (k should not exceed 2·n2). In the following k lines print transfusions in the format x y d (transfusion of d liters fro... | First line of the input contains integers n, v, e (1 ≤ n ≤ 300, 1 ≤ v ≤ 109, 0 ≤ e ≤ 50000). Next two lines contain n integers each: initial ai and the desired amounts bi of water in corresponding vessels (0 ≤ ai, bi ≤ v). Next e lines describe one tube each in the format x y (1 ≤ x, y ≤ n, x ≠ y) for a tube between ve... | standard output | standard input | Python 2 | Python | 2,500 | train_054.jsonl | e29f2f49edcc8cf58b9affe1ec2e357f | 256 megabytes | ["2 10 1\n1 9\n5 5\n1 2", "2 10 0\n5 2\n4 2", "2 10 0\n4 2\n4 2"] | PASSED | n,v,e=map(int,raw_input().split())
a=[0]*(n+10)
b=[0]*(n+10)
E=[[] for i in xrange(n)]
f=[i for i in xrange(n)]
vis=[0]*(n+10)
ans=[]
rem=0
def fd(x):
if f[x]==x: return x
else:
f[x]=fd(f[x])
return f[x]
def dfs2(u,f,ty):
global rem
if rem<=a[u] and rem>0:
if ty==0: ans.append([u,f,rem])
else: ans.append([f... | 1371223800 | [
"trees",
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
1
] | |
2 seconds | ["YES\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES", "YES\nYES\nCAN 81", "YES\nNO"] | d818876d0bb7a22b7aebfca5b77d2cd5 | NoteThe cost of repairing the road is the difference between the time needed to ride along it before and after the repairing.In the first sample president initially may choose one of the two following ways for a ride: 1 → 2 → 4 → 5 → 6 or 1 → 2 → 3 → 5 → 6. | Berland has n cities, the capital is located in city s, and the historic home town of the President is in city t (s ≠ t). The cities are connected by one-way roads, the travel time for each of the road is a positive integer.Once a year the President visited his historic home town t, for which his motorcade passes along... | Print m lines. The i-th line should contain information about the i-th road (the roads are numbered in the order of appearance in the input). If the president will definitely ride along it during his travels, the line must contain a single word "YES" (without the quotes). Otherwise, if the i-th road can be repaired so ... | The first lines contain four integers n, m, s and t (2 ≤ n ≤ 105; 1 ≤ m ≤ 105; 1 ≤ s, t ≤ n) — the number of cities and roads in Berland, the numbers of the capital and of the Presidents' home town (s ≠ t). Next m lines contain the roads. Each road is given as a group of three integers ai, bi, li (1 ≤ ai, bi ≤ n; ai ≠ ... | standard output | standard input | PyPy 3 | Python | 2,200 | train_011.jsonl | 38c7b8906d8508da8428036aef712d26 | 256 megabytes | ["6 7 1 6\n1 2 2\n1 3 10\n2 3 7\n2 4 8\n3 5 3\n4 5 2\n5 6 1", "3 3 1 3\n1 2 10\n2 3 10\n1 3 100", "2 2 1 2\n1 2 1\n1 2 2"] | PASSED | from heapq import *
import sys
MOD = 1000000181
def addM(a,b):
return (a+b)%MOD
def mulM(a,b):
return (a*b)%MOD
def dijk(adj,n,s):
dist = [10**18]*n
ways = [0]*n
frontier = []
dist[s] = 0
ways[s] = 1
heappush(frontier,(0,s))
while (len(frontier)>0):
x = heappop(frontier)
... | 1438790400 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["4", "11", "2"] | b86a61e6b759b308656e888641f75776 | NoteLet's list all the pairs of segments that Vasya could choose in the first example: $$$[2, 2]$$$ and $$$[2, 5]$$$; $$$[1, 2]$$$ and $$$[2, 4]$$$; $$$[5, 5]$$$ and $$$[2, 5]$$$; $$$[5, 6]$$$ and $$$[3, 5]$$$; | Vasya had three strings $$$a$$$, $$$b$$$ and $$$s$$$, which consist of lowercase English letters. The lengths of strings $$$a$$$ and $$$b$$$ are equal to $$$n$$$, the length of the string $$$s$$$ is equal to $$$m$$$. Vasya decided to choose a substring of the string $$$a$$$, then choose a substring of the string $$$b$$... | Print one integer — the number of ways to choose a pair of segments, which satisfy Vasya's conditions. | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 500\,000, 2 \leq m \leq 2 \cdot n$$$) — the length of strings $$$a$$$ and $$$b$$$ and the length of the string $$$s$$$. The next three lines contain strings $$$a$$$, $$$b$$$ and $$$s$$$, respectively. The length of the strings $$$a$$$ and $$$b$$$ is... | standard output | standard input | PyPy 3 | Python | 2,700 | train_008.jsonl | c3f005ad55302e52986dc15536091562 | 512 megabytes | ["6 5\naabbaa\nbaaaab\naaaaa", "5 4\nazaza\nzazaz\nazaz", "9 12\nabcabcabc\nxyzxyzxyz\nabcabcayzxyz"] | PASSED | import sys, logging
logging.basicConfig(level=logging.INFO)
logging.disable(logging.INFO)
def build(S, n):
Z = [0 for i in range(3 * n + 3)]
#logging.info(S)
n = len(S)
L = 0
R = 0
Z[0] = n
for i in range(1, n):
if(i > R):
L = R = i
while(R < n and S[R] == S[... | 1582448700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
4 seconds | ["1 3 4 3 3", "1 4 1 1 2 4 2"] | c412a489a0bd2327a46f1e47a78fd03f | NoteIn the first sample case, the following paths are palindromic:2 - 3 - 42 - 3 - 54 - 3 - 5Additionally, all paths containing only one vertex are palindromic. Listed below are a few paths in the first sample that are not palindromic:1 - 2 - 31 - 2 - 3 - 41 - 2 - 3 - 5 | You are given a tree (a connected acyclic undirected graph) of n vertices. Vertices are numbered from 1 to n and each vertex is assigned a character from a to t.A path in the tree is said to be palindromic if at least one permutation of the labels in the path is a palindrome.For each vertex, output the number of palind... | Print n integers in a single line, the i-th of which is the number of palindromic paths passing through vertex i in the tree. | The first line contains an integer n (2 ≤ n ≤ 2·105) — the number of vertices in the tree. The next n - 1 lines each contain two integers u and v (1 ≤ u, v ≤ n, u ≠ v) denoting an edge connecting vertex u and vertex v. It is guaranteed that the given graph is a tree. The next line contains a string consisting of n... | standard output | standard input | PyPy 2 | Python | 2,400 | train_046.jsonl | ab65d0f5f4b80c415ac227c484f30272 | 256 megabytes | ["5\n1 2\n2 3\n3 4\n3 5\nabcbb", "7\n6 2\n4 3\n3 7\n5 2\n7 2\n1 4\nafefdfs"] | PASSED | import sys
range = xrange
input = raw_input
def centroid_decomp(coupl):
n = len(coupl)
bfs = [n - 1]
for node in bfs:
bfs += coupl[node]
for nei in coupl[node]:
coupl[nei].remove(node)
size = [0] * n
for node in reversed(bfs):
size[node] = 1 + sum(size... | 1516462500 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["1 1 1", "3 3", "6 12"] | ea8f191447a4089e211a17bccced97dc | NoteIn the second example, there are $$$3$$$ sequences he can get after $$$1$$$ swap, because there are $$$3$$$ pairs of cubes he can swap. Also, there are $$$3$$$ sequences he can get after $$$2$$$ swaps: $$$[1,2,3]$$$, $$$[3,1,2]$$$, $$$[2,3,1]$$$. | This time around, Baby Ehab will play with permutations. He has $$$n$$$ cubes arranged in a row, with numbers from $$$1$$$ to $$$n$$$ written on them. He'll make exactly $$$j$$$ operations. In each operation, he'll pick up $$$2$$$ cubes and switch their positions.He's wondering: how many different sequences of cubes ca... | Print $$$k$$$ space-separated integers. The $$$i$$$-th of them is the number of possible sequences you can end up with if you do exactly $$$i$$$ operations. Since this number can be very large, print the remainder when it's divided by $$$10^9+7$$$. | The only line contains $$$2$$$ integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 10^9$$$, $$$1 \le k \le 200$$$) — the number of cubes Baby Ehab has, and the parameter $$$k$$$ from the statement. | standard output | standard input | PyPy 3-64 | Python | 2,500 | train_105.jsonl | 78434fdd87735cbc678c84b3033d3040 | 256 megabytes | ["2 3", "3 2", "4 2"] | PASSED | import os,sys
from random import randint
from io import BytesIO, IOBase
from collections import defaultdict,deque,Counter
from bisect import bisect_left,bisect_right
from heapq import heappush,heappop
from functools import lru_cache
from itertools import accumulate
import math
# Fast IO Region
BUFSIZE = 8... | 1619012100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1 4", "3 3", "1 6"] | e65b974a85067500f20b316275dc5821 | NoteIn the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum. In the second example, possible assignments for each minimum and maximum are described in picture below. The $$$f$$$ value of val... | You have unweighted tree of $$$n$$$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $$$v_{1}$$$ and $$$v_{2}$$$ of this tree, bitwise XOR of weights of all edges on the simple path between $$$v_{1}$$$ and $$$v_{2}$$$ has to be equal... | Print two integers — the minimum and maximum possible value of $$$f$$$ can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints. | The first line contains integer $$$n$$$ ($$$3 \le n \le 10^{5}$$$) — the number of vertices in given tree. The $$$i$$$-th of the next $$$n-1$$$ lines contains two integers $$$a_{i}$$$ and $$$b_{i}$$$ ($$$1 \le a_{i} \lt b_{i} \le n$$$) — it means there is an edge between $$$a_{i}$$$ and $$$b_{i}$$$. It is guaranteed th... | standard output | standard input | PyPy 3 | Python | 1,800 | train_011.jsonl | a41ce4f441f3b40ccf75e76627d50ab2 | 256 megabytes | ["6\n1 3\n2 3\n3 4\n4 5\n5 6", "6\n1 3\n2 3\n3 4\n4 5\n4 6", "7\n1 2\n2 7\n3 4\n4 7\n5 6\n6 7"] | PASSED | # by the authority of GOD author: manhar singh sachdev #
import os, sys
from io import BytesIO, IOBase
from collections import defaultdict
def main():
n = int(input())
path = defaultdict(set)
parent = [0]*(n+1)
for _ in range(n-1):
a,b = map(int,input().split())
path[a].add(b)
... | 1586700300 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["3\n1 2 3\n1 2 3", "1\n1 1 1\n2", "-1"] | 4b49f1b3fca4acb2f5dce25169436cc8 | null | Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.Now then, you are given a function f: [n] →... | If there is no answer, print one integer -1. Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m). If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exi... | The first line contains an integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n). | standard output | standard input | Python 3 | Python | 1,700 | train_018.jsonl | bc887724d80a34931594f42f6d1c8931 | 512 megabytes | ["3\n1 2 3", "3\n2 2 2", "2\n2 1"] | PASSED | n = int(input())
f = [None] + list(map(int, input().split(' ')))
invalid = False
g = [None] + [0] * n
h = [None]
x_is_f_which = [None] + [0] * n
m = 0
vis = [None] + [False] * n
for i in range(1, n + 1):
x = f[i]
if f[x] != x:
invalid = True
break
if not vis[x]:
vis[x] = True
... | 1487059500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
3 seconds | ["0 1\n0 0\n0 1 3 2\n0 0 1 1\n5 3 0 7 2 6 1 4\n-1"] | 4c9c50f9ebe06a3e86c20aee2a0ee797 | NoteThe colouring and the permuted hypercube for the first test case is shown below: The colouring and the permuted hypercube for the second test case is shown below: The permuted hypercube for the third test case is given in the problem statement. However, it can be shown that there exists no way to colour that cu... | Finally, you have defeated Razor and now, you are the Most Wanted street racer. Sergeant Cross has sent the full police force after you in a deadly pursuit. Fortunately, you have found a hiding spot but you fear that Cross and his force will eventually find you. To increase your chances of survival, you want to tune an... | For each test case, print two lines. In the first line, output any permutation $$$P$$$ of length $$$2^n$$$ that can be used to transform a simple $$$n$$$-dimensional hypercube to the permuted $$$n$$$-dimensional hypercube given in the input. Two permuted hypercubes are considered the same if they have the same set of e... | The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 4096$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$1\leq n\leq 16$$$). Each of the next $$$n\cdot 2^{n-1}$$$ lines contain two integers $$$u$$$ and $$$v$$$ ($$$0\leq u, v < 2^n$$$) den... | standard output | standard input | PyPy 3 | Python | 2,700 | train_091.jsonl | ae0d50e1348523fabc089358e6773d31 | 256 megabytes | ["3\n1\n0 1\n2\n0 1\n1 2\n2 3\n3 0\n3\n0 1\n0 5\n0 7\n1 2\n1 4\n2 5\n2 6\n3 5\n3 6\n3 7\n4 6\n4 7"] | PASSED | from collections import deque
from sys import stdin
import sys
tt = int(stdin.readline())
for loop in range(tt):
n = int(stdin.readline())
lis = [ [] for i in range(2**n)]
for i in range(n*(2**(n-1))):
u,v = map(int,stdin.readline().split())
lis[u].append(v)
... | 1625668500 | [
"math",
"graphs"
] | [
0,
0,
1,
1,
0,
0,
0,
0
] | |
2 seconds | ["3 1 2", "1 3 2", "-1"] | d53d6cd0014576ad93c01c1a685b9eb1 | null | Lenny had an n × m matrix of positive integers. He loved the matrix so much, because each row of the matrix was sorted in non-decreasing order. For the same reason he calls such matrices of integers lovely.One day when Lenny was at school his little brother was playing with Lenny's matrix in his room. He erased some of... | If there exists no possible reordering of the columns print -1. Otherwise the output should contain m integers p1, p2, ..., pm showing the sought permutation of columns. So, the first column of the lovely matrix will be p1-th column of the initial matrix, the second column of the lovely matrix will be p2-th column of t... | The first line of the input contains two positive integers n and m (1 ≤ n·m ≤ 105). Each of the next n lines contains m space-separated integers representing the matrix. An integer -1 shows an erased entry of the matrix. All other integers (each of them is between 0 and 109 inclusive) represent filled entries. | standard output | standard input | Python 2 | Python | 2,200 | train_033.jsonl | eccb0784cafa69f64ab6fe1d5d45a826 | 256 megabytes | ["3 3\n1 -1 -1\n1 2 1\n2 -1 1", "2 3\n1 2 2\n2 5 4", "2 3\n1 2 3\n3 2 1"] | PASSED | n, m = map(int, raw_input().split())
b = [map(int, raw_input().split()) for _ in range(n)]
c = [n - x.count(-1) for x in zip(*b)]
d = []
for r in b:
t = {}
for i, x in enumerate(r):
if x != -1:
if x not in t:
t[x] = set()
t[x].add(i)
d.append([x for i, x in sorted(t.items())][ : : -1])
p = [i for i, x in... | 1361374200 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["? 1 2\n? 1 3\n? 2 3\n! 1 0 2"] | 66e86d612d676068689ae714b453ef32 | NoteIn the first sample, the permutation is $$$[1,0,2]$$$. You start by asking about $$$p_1|p_2$$$ and Ehab replies with $$$1$$$. You then ask about $$$p_1|p_3$$$ and Ehab replies with $$$3$$$. Finally, you ask about $$$p_2|p_3$$$ and Ehab replies with $$$2$$$. You then guess the permutation. | This is an interactive problem!Ehab has a hidden permutation $$$p$$$ of length $$$n$$$ consisting of the elements from $$$0$$$ to $$$n-1$$$. You, for some reason, want to figure out the permutation. To do that, you can give Ehab $$$2$$$ different indices $$$i$$$ and $$$j$$$, and he'll reply with $$$(p_i|p_j)$$$ where $... | null | The only line contains the integer $$$n$$$ $$$(3 \le n \le 2048)$$$ — the length of the permutation. | standard output | standard input | Python 3 | Python | 2,700 | train_051.jsonl | 407c9f93c2fa8ff4df50edca364e596e | 256 megabytes | ["3\n1\n3\n2"] | PASSED | from random import sample
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): retu... | 1592060700 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
3 seconds | ["2 4\n1 5\n1 2\n-1 -1\n1 2\n-1 -1\n1 3\n1 3\n-1 -1\n-1 -1\n-1 -1"] | b67870dcffa7bad682ef980dacd1f3db | NoteConsider the first test case of example inputs. In this test case $$$n=7$$$, $$$s=$$$"1003004", $$$w=4$$$ and one query $$$l_1=1$$$, $$$r_1=2$$$, $$$k_1=1$$$. Note that $$$v(1,2)=10$$$. We need to find a pair of substrings of length $$$4$$$ such that $$$v(L_1, L_1+3)\cdot10+v(L_2,L_2+3)$$$ has a remainder of $$$k_1... | Given the string $$$s$$$ of decimal digits (0-9) of length $$$n$$$.A substring is a sequence of consecutive characters of a string. The substring of this string is defined by a pair of indexes — with its left and right ends. So, each pair of indexes ($$$l, r$$$), where $$$1 \le l \le r \le n$$$, corresponds to a substr... | For each request, print in a separate line: left borders of the required substrings: $$$L_1$$$ and $$$L_2$$$; -1 -1 otherwise, if there is no solution. If there are several solutions, minimize $$$L_1$$$ first, and minimize $$$L_2$$$ second. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of input test cases. The first line of each test case contains a string $$$s$$$, which contains only the characters 0-9 and has a length $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$). The second line contains two integers $$$w, m$$$ ($$$1 \le... | standard output | standard input | PyPy 3-64 | Python | 1,900 | train_110.jsonl | e52d58da3596df5f47871b828d58d894 | 256 megabytes | ["5\n\n1003004\n\n4 1\n\n1 2 1\n\n179572007\n\n4 2\n\n2 7 3\n\n2 7 4\n\n111\n\n2 1\n\n2 2 6\n\n0000\n\n1 2\n\n1 4 0\n\n1 4 1\n\n484\n\n1 5\n\n2 2 0\n\n2 3 7\n\n1 2 5\n\n3 3 8\n\n2 2 6"] | PASSED | import bisect
import collections
import collections.abc
import itertools
import math
import re
import sys
import functools
import copy
import math
import heapq
import sys
import io
from collections import Counter, deque
from collections import defaultdict as ddict
def create_matrix(rows, cols=None, val=None):
... | 1662993300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["2\n4 2", "2\n7 11"] | d50bb59298e109b4ac5f808d24fef5a1 | NoteThere is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.Galya doesn't know the ships location. She can shoot to some cells and after each shot sh... | In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship. In the second line print the cells Galya should shoot at. Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from ... | The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made. The second line contains a string of length n, consisting of zeros and ones. If the i-... | standard output | standard input | Python 3 | Python | 1,700 | train_003.jsonl | 38c46d8ac25f20c7053fb79fe3b1724c | 256 megabytes | ["5 1 2 1\n00100", "13 3 2 3\n1000000010001"] | PASSED | n,a,b,k=map(int,input().split())
A=input()
B=A.split('1')
C=[]
l=1
for i in B:
if len(i)>=b:
for j in range(b-1,len(i),b):
C.append(j+l)
l+=len(i)+1
C=C[:len(C)-a+1]
print(len(C))
print(' '.join(list(map(str,C))))
# Made By Mostafa_Khaled | 1479632700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["0", "1", "-1"] | 3c5e1f11e6af3821ed8c28f15e429def | null | In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a to city b, or from city b to city a. The road network is such that from any ... | Print a single number — the answer to the problem. If the it is impossible to meet the conditions, print -1. | The first line contains two integers n, m (1 ≤ n ≤ 3000, ) — the number of cities and roads in the country, respectively. Next m lines contain the descriptions of the roads as pairs of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi). It is guaranteed that the roads that are given in the description can transport you from an... | standard output | standard input | PyPy 2 | Python | 2,100 | train_042.jsonl | 6c3ca46b863c2fac3200e211965bd854 | 256 megabytes | ["5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2", "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2", "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1"] | PASSED | from collections import deque
import sys
maxn = 3003
d = [[0] * maxn for i in range(0, maxn)]
adj = [[] for i in range(0, maxn)]
mark = [0] * maxn
def bfs(s) :
for i in range(0, maxn) :
mark[i] = False
q = deque()
q.append(s)
d[s][s] = 0
mark[s] = True
while len(q) > 0 :
v = q[0]
q.popleft(... | 1431016200 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["FastestFinger\nAshishgup\nAshishgup\nFastestFinger\nAshishgup\nFastestFinger\nAshishgup"] | b533572dd6d5fe7350589c7f4d5e1c8c | NoteIn the first test case, $$$n = 1$$$, Ashishgup cannot make a move. He loses.In the second test case, $$$n = 2$$$, Ashishgup subtracts $$$1$$$ on the first move. Now $$$n = 1$$$, FastestFinger cannot make a move, so he loses.In the third test case, $$$n = 3$$$, Ashishgup divides by $$$3$$$ on the first move. Now $$$... | Ashishgup and FastestFinger play a game. They start with a number $$$n$$$ and play in turns. In each turn, a player can make any one of the following moves: Divide $$$n$$$ by any of its odd divisors greater than $$$1$$$. Subtract $$$1$$$ from $$$n$$$ if $$$n$$$ is greater than $$$1$$$. Divisors of a number include th... | For each test case, print "Ashishgup" if he wins, and "FastestFinger" otherwise (without quotes). | The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The only line of each test case contains a single integer — $$$n$$$ ($$$1 \leq n \leq 10^9$$$). | standard output | standard input | PyPy 3 | Python | 1,400 | train_008.jsonl | fd30ce82caffe8b0dfd84efacf3ca154 | 256 megabytes | ["7\n1\n2\n3\n4\n5\n6\n12"] | PASSED | for t in range(int(input())):
n = int(input())
N = n
if n == 1:
winner = 2
elif n == 2 or n % 2 != 0:
winner = 1
else:
numTwo = 0
while n % 2 == 0:
n //= 2
numTwo += 1
numOdd = 0
for i in range(3, int(N ** 0.5 + 2), 2):
while n > 0 and n % i == 0:
n //= i
numOdd += 1
# print(n)... | 1592663700 | [
"number theory",
"math",
"games"
] | [
1,
0,
0,
1,
1,
0,
0,
0
] | |
3 seconds | ["5 3 5", "5 3 1 2 1", "-1"] | 790739d10b9c985f2fe47ec79ebfc993 | null | There are $$$n$$$ railway stations in Berland. They are connected to each other by $$$n-1$$$ railway sections. The railway network is connected, i.e. can be represented as an undirected tree.You have a map of that network, so for each railway section you know which stations it connects.Each of the $$$n-1$$$ sections ha... | If there is no answer then print a single integer -1. Otherwise, print $$$n-1$$$ integers $$$f_1, f_2, \dots, f_{n-1}$$$ ($$$1 \le f_i \le 10^6$$$), where $$$f_i$$$ is some valid scenery beauty along the $$$i$$$-th railway section. If there are multiple answers, you can print any of them. | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 5000$$$) — the number of railway stations in Berland. The next $$$n-1$$$ lines contain descriptions of the railway sections: the $$$i$$$-th section description is two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n, x_i \ne y_i$$$), where $$$x_i... | standard output | standard input | Python 2 | Python | 2,100 | train_023.jsonl | 13a28c65adcf2faca36b2d6064329ba7 | 256 megabytes | ["4\n1 2\n3 2\n3 4\n2\n1 2 5\n1 3 3", "6\n1 2\n1 6\n3 1\n1 5\n4 1\n4\n6 1 3\n3 4 1\n6 5 2\n1 2 5", "6\n1 2\n1 6\n3 1\n1 5\n4 1\n4\n6 1 1\n3 4 3\n6 5 3\n1 2 4"] | PASSED | import sys
range = xrange
input = raw_input
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
n = inp[ii]; ii += 1
coupl = [[] for _ in range(n)]
U = []
for eind in range(n - 1):
u = inp[ii] - 1; ii += 1
v = inp[ii] - 1; ii += 1
coupl[u].append(2*eind)
coupl[v].append(2*eind + 1)
U.appe... | 1580826900 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
1 second | ["20", "15", "35"] | 281b95c3686c94ae1c1e4e2a18b7fcc4 | NoteIn the first sample the messages must be read immediately after receiving, Vasya receives A points for each message, n·A = 20 in total.In the second sample the messages can be read at any integer moment.In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at... | There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. ... | Output one integer — the answer to the problem. | The first line contains five integers n, A, B, C and T (1 ≤ n, A, B, C, T ≤ 1000). The second string contains n integers ti (1 ≤ ti ≤ T). | standard output | standard input | PyPy 2 | Python | 1,300 | train_051.jsonl | e2207ce31b44d148d52266f5241ec8eb | 256 megabytes | ["4 5 5 3 5\n1 5 5 4", "5 3 1 1 3\n2 2 2 1 1", "5 5 3 4 5\n1 2 3 4 5"] | PASSED | n, a, b, c, t = map(int, raw_input().split(" "))
ts = map(int, raw_input().split(" "))
total = a*n
if b <= c:
for i in xrange(n):
total += (t-ts[i])*(c-b)
print total
| 1523973900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["0 2 3 1 1", "1 0 1", "0"] | 3c63e2e682d3c8051c3cecc3fa9c4e8c | null | Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of ... | Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day. | The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109). | standard output | standard input | PyPy 3 | Python | 1,500 | train_006.jsonl | eab5379db215cc0e687d3b4fc2d138c1 | 256 megabytes | ["5 1 4\n12 6 11 9 1", "3 1 2\n1 2 3", "1 1 1\n1"] | PASSED | import sys
import string
import math
from collections import defaultdict
from functools import lru_cache
from collections import Counter
def mi(s):
return map(int, s.strip().split())
def lmi(s):
return list(mi(s))
def tmi(s):
return tuple(mi(s))
def mf(f, s):
return map(f, s)
def lmf(f, s):
ret... | 1396798800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1.0000000000", "0.9628442962", "0.7500000000"] | 81492d3b77bc0674102af17f22bf0664 | NoteIn the first sample the best way of candies' distribution is giving them to first three of the senators. It ensures most of votes.It the second sample player should give all three candies to the fifth senator. | Dark Assembly is a governing body in the Netherworld. Here sit the senators who take the most important decisions for the player. For example, to expand the range of the shop or to improve certain characteristics of the character the Dark Assembly's approval is needed.The Dark Assembly consists of n senators. Each of t... | Print one real number with precision 10 - 6 — the maximal possible probability that the Dark Assembly approves the player's proposal for the best possible distribution of candies among the senators. | The first line contains three integers n, k and A (1 ≤ n, k ≤ 8, 1 ≤ A ≤ 9999). Then n lines follow. The i-th of them contains two numbers — bi and li — the i-th senator's level and his loyalty. The levels of all senators are integers in range from 1 to 9999 (inclusive). The loyalties of all senators are integers in ra... | standard output | standard input | PyPy 3 | Python | 1,800 | train_029.jsonl | f460dd784f0f5bde2a295d542681cd19 | 256 megabytes | ["5 6 100\n11 80\n14 90\n23 70\n80 30\n153 70", "5 3 100\n11 80\n14 90\n23 70\n80 30\n153 70", "1 3 20\n20 20"] | PASSED | #!/usr/bin/env python3
n, k, A = map(int, input().rstrip().split())
senators = []
mx_bribe = 0
for i in range(n):
lvl, loy = map(int, input().rstrip().split())
senators.append((lvl, loy))
mx_bribe += (100 - loy) // 10
bribe = [0] * n
def calc(votes):
bsum, cnt, p = 0, 0, 1.0
for i, s in enumera... | 1313247600 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
2 seconds | ["10\n7\n13\n0\n3"] | 8864c6a04fed970fcbc04e220df9d88d | NoteThe explanations for the example test:We use characters N, E, S, W and 0 to denote going north, going east, going south, going west and staying in the current cell, respectively.In the first test case, the robot can use the following sequence: NENENENENE.In the second test case, the robot can use the following sequ... | There is an infinite 2-dimensional grid. The robot stands in cell $$$(0, 0)$$$ and wants to reach cell $$$(x, y)$$$. Here is a list of possible commands the robot can execute: move north from cell $$$(i, j)$$$ to $$$(i, j + 1)$$$; move east from cell $$$(i, j)$$$ to $$$(i + 1, j)$$$; move south from cell $$$(i, j)$$... | For each testcase print a single integer — the minimum number of commands required for the robot to reach $$$(x, y)$$$ from $$$(0, 0)$$$ if no command is allowed to be executed two or more times in a row. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases. Each of the next $$$t$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 10^4$$$) — the destination coordinates of the robot. | standard output | standard input | PyPy 2 | Python | 800 | train_001.jsonl | 93a32ff88ab3bdb4b8d11d4c91dfc886 | 256 megabytes | ["5\n5 5\n3 4\n7 1\n0 0\n2 0"] | PASSED | from __future__ import division, print_function
MOD = 998244353
mod = 10**9 + 7
# import resource
# resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
def prepare_factorial():
fact = [1]
for i in range(1, 20):
fact.append((fact[-1] * i) % mod)
ifact = [0] * 105
i... | 1605796500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\n1\n-1", "9\n9\n9\n-1\n-1\n-1"] | 2886d6ef13ba1fbc68fb793f28ba0127 | NoteIn the first example, there are 5 tasks: The first task requires you to add $$$1$$$ into $$$a$$$. $$$a$$$ is now $$$\left\{1\right\}$$$. The second task requires you to add $$$2$$$ into $$$a$$$. $$$a$$$ is now $$$\left\{1, 2\right\}$$$. The third task asks you a question with $$$x = 1$$$, $$$k = 1$$$ and $$$s =... | Kuro is currently playing an educational game about numbers. The game focuses on the greatest common divisor (GCD), the XOR value, and the sum of two numbers. Kuro loves the game so much that he solves levels by levels day by day.Sadly, he's going on a vacation for a day, and he isn't able to continue his solving strea... | For each task of type $$$2$$$, output on one line the desired number $$$v$$$, or -1 if no such numbers are found. | The first line contains one integer $$$q$$$ ($$$2 \leq q \leq 10^{5}$$$) — the number of tasks the game wants you to perform. $$$q$$$ lines follow, each line begins with an integer $$$t_i$$$ — the type of the task: If $$$t_i = 1$$$, an integer $$$u_i$$$ follow ($$$1 \leq u_i \leq 10^{5}$$$) — you have to add $$$u_i$... | standard output | standard input | PyPy 2 | Python | 2,200 | train_064.jsonl | ac811bf2e0c46fdd98a15cd7169787d6 | 512 megabytes | ["5\n1 1\n1 2\n2 1 1 3\n2 1 1 2\n2 1 1 1", "10\n1 9\n2 9 9 22\n2 3 3 18\n1 25\n2 9 9 20\n2 25 25 14\n1 20\n2 26 26 3\n1 14\n2 20 20 9"] | PASSED | import sys
range = xrange
input = raw_input
big = 10**5 + 1
M = 1
while M < big:
M *= 2
mini = [0]
L = [0]
R = [0]
roots = [0]*big
def add(x, i):
bits = []
xx = x + M
while xx != 1:
bits.append(xx&1)
xx >>= 1
if not roots[i]:
roots[i] = len(mini)
mini.append(x)
... | 1526308500 | [
"number theory",
"math",
"strings",
"trees"
] | [
0,
0,
0,
1,
1,
0,
1,
1
] | |
1 second | ["9\n1\n0\n7\n10\n7\n5", "12\n10\n10\n8\n7"] | b8321b0a3fc8c295182a4c2c8d2e9d01 | NoteLet's consider the first sample. The first participant starts at floor s = 2 by the time equal to t = 3. To get to the floor f = 4, he has to wait until the time equals 7, that's the time when the elevator will go upwards for the second time. Then the first participant should get on the elevator and go two floors u... | And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator... | Print n lines each containing one integer — the time of the arrival for each participant to the required floor. | The first line contains two space-separated integers n and m (1 ≤ n ≤ 105, 2 ≤ m ≤ 108). Next n lines contain information about the participants in the form of three space-separated integers si fi ti (1 ≤ si, fi ≤ m, 0 ≤ ti ≤ 108), described in the problem statement. | standard output | standard input | Python 2 | Python | 1,300 | train_019.jsonl | 91ca3fe928fddd6a4497a5fa28261b72 | 256 megabytes | ["7 4\n2 4 3\n1 2 0\n2 2 0\n1 2 1\n4 3 5\n1 2 2\n4 2 0", "5 5\n1 5 4\n1 3 1\n1 3 4\n3 1 5\n4 2 5"] | PASSED | n,m = map(int, str(raw_input()).split())
while n:
n-=1
s,f,t = map(int, str(raw_input()).split())
if s==f:
print t
continue
x = 2*(m-1)
result = t-t%x
t %= x
if(t <= s-1):
flag = True
elif(t<= x-s+1):
flag = False
else:
result += x
flag... | 1316790000 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1.000000000000", "1.714285714286"] | a69b342ef5f6e11f7aa4fee71e149aa2 | NoteIn the first sample you can put a police station in one of the capitals, then each path will have exactly one safe road. If we place the station not in the capital, then the average number of safe roads will also make .In the second sample we can obtain the maximum sought value if we put the station in city 4, then... | The Berland road network consists of n cities and of m bidirectional roads. The cities are numbered from 1 to n, where the main capital city has number n, and the culture capital — number 1. The road network is set up so that it is possible to reach any city from any other one by the roads. Moving on each road in any d... | Print the maximum possible value of the average number of safe roads among all shortest paths from the culture capital to the main one. The answer will be considered valid if its absolute or relative inaccuracy does not exceed 10 - 6. | The first input line contains two integers n and m (2 ≤ n ≤ 100, ) — the number of cities and the number of roads in Berland, correspondingly. Next m lines contain pairs of integers vi, ui (1 ≤ vi, ui ≤ n, vi ≠ ui) — the numbers of cities that are connected by the i-th road. The numbers on a line are separated by a spa... | standard output | standard input | Python 3 | Python | 1,900 | train_005.jsonl | 227b05e69a1f3a53ca8a05b2636cc83c | 256 megabytes | ["4 4\n1 2\n2 4\n1 3\n3 4", "11 14\n1 2\n1 3\n2 4\n3 4\n4 5\n4 6\n5 11\n6 11\n1 8\n8 9\n9 7\n11 7\n1 10\n10 4"] | PASSED | from collections import deque
n, m = [int(i) for i in input().split()]
g = [[] for i in range(n)]
for i in range(m):
u, v = [int(i) - 1 for i in input().split()]
g[u].append(v)
g[v].append(u)
def bfs(s):
d = [-1] * n
ct = [0.0] * n
q = deque()
d[s] = 0
ct[s] = 1.0
q.append(s)... | 1343057400 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["12\n33\n75"] | 204e75827b7016eb1f1fbe1d6b60b03d | NoteLet us explain the three test cases in the sample.Test case 1: $$$n = 11$$$: $$$\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1$$$.$$$\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3$$$.So the smallest number $$$\ge 11$$$ whose $$$gcdSum$$$ $$$> 1$$$ is $$$12$$$.Test case 2: $$$n = 31$$$: $$... | The $$$\text{$$$gcdSum$$$}$$$ of a positive integer is the $$$gcd$$$ of that integer with its sum of digits. Formally, $$$\text{$$$gcdSum$$$}(x) = gcd(x, \text{ sum of digits of } x)$$$ for a positive integer $$$x$$$. $$$gcd(a, b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$ — the largest integer $$$d$... | Output $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case. | The first line of input contains one integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \le n \le 10^{18})$$$. All test cases in one test are different. | standard output | standard input | PyPy 3-64 | Python | 800 | train_107.jsonl | b0964708cb42fead0975db53ce72e05a | 256 megabytes | ["3\n11\n31\n75"] | PASSED | import math
def solve():
t = int(input())
while t:
t-=1
n = input()
b = 0
for c in n:
b += int(c)
val = math.gcd(int(n),b)
if val>1:
print(n)
else:
temp = int(n)
while val < 2:
... | 1617028500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES\nNO\nYES\nYES\nNO"] | 080f29d4e2aa5bb9ee26d882362c8cd7 | NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and wh... | YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of seq... | For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower). | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is... | standard output | standard input | PyPy 3-64 | Python | 1,300 | train_083.jsonl | efc6aeb3d84a71a03ed79c9ccc8df5ec | 256 megabytes | ["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"] | PASSED | import math
#'YES'
t = int(input())
for _ in range(t):
n = int(input())
arr = [int(i) for i in input().split()]
if arr[0] % 2 == 0:
print('NO')
else:
np = 0
lmp = 0
for i in range(n):
cur = i+1
if arr[i] % 2 != 0:
lmp += 1
else:
if arr[i] % (cur+1) != 0:
lmp += 1
... | 1635604500 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
2 seconds | ["0\n2\n3\n2"] | a9c54d6f952320d75324b30dcb098332 | NoteIn the first test case, all members can be invited. So the unhappiness value is $$$0$$$.In the second test case, the following options are possible: invite $$$1$$$ and $$$2$$$ ($$$0$$$ cakes eaten, unhappiness value equal to $$$3$$$); invite $$$2$$$ and $$$3$$$ ($$$0$$$ cakes eaten, unhappiness value equal to $$... | A club plans to hold a party and will invite some of its $$$n$$$ members. The $$$n$$$ members are identified by the numbers $$$1, 2, \dots, n$$$. If member $$$i$$$ is not invited, the party will gain an unhappiness value of $$$a_i$$$.There are $$$m$$$ pairs of friends among the $$$n$$$ members. As per tradition, if bot... | For each test case, print a line containing a single integer – the minimum possible unhappiness value of a valid party. | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 10^4$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^5$$$, $$$0 \leq m \leq \min(10^5,\frac{n(n-1)}{2})$$$) —... | standard output | standard input | Python 3 | Python | 1,300 | train_083.jsonl | 873f1d3eafb66c9d065e98249aa4cca6 | 256 megabytes | ["4\n\n1 0\n\n1\n\n3 1\n\n2 1 3\n\n1 3\n\n5 5\n\n1 2 3 4 5\n\n1 2\n\n1 3\n\n1 4\n\n1 5\n\n2 3\n\n5 5\n\n1 1 1 1 1\n\n1 2\n\n2 3\n\n3 4\n\n4 5\n\n5 1"] | PASSED | import sys
input = sys.stdin.readline
from collections import defaultdict as dd
t=int(input())
while(t):
t-=1
n,m=list(map(int,input().split()))
l=list(map(int,input().split()))
ct=[0]*(n+1)
l1=[]
for x in range(1,m+1):
a,b=list(map(int,input().split()))
l1.append([a,... | 1658673300 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
4 seconds | ["9\n000\n01", "2\n193\n81\n91"] | 37d906de85f173aca2a9a3559cbcf7a3 | null | There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct.There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which... | Print exactly n lines: the i-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the i-th number from the contacts. If there are several such sequences, print any of them. | The first line contains single integer n (1 ≤ n ≤ 70000) — the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. | standard output | standard input | Python 3 | Python | 1,600 | train_028.jsonl | 350b2bb400a66f5cc1d89a3da85a9218 | 256 megabytes | ["3\n123456789\n100000000\n100123456", "4\n123456789\n193456789\n134567819\n934567891"] | PASSED | def add_subs(num, freq):
used = set()
for l in range(1, len(num) + 1):
for i in range(len(num) - l + 1):
end = i + l
sub = num[i : end]
if sub not in used:
used.add(sub)
if sub not in freq:
freq[sub] = 1
else:
freq[sub] += 1
def count_subs(nums):
... | 1505653500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["NO\nYES"] | c686c3592542b70a3b617eb639c0e3f4 | null | In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting... | For each query of the second type print "YES" or "NO" on a separate line depending on the answer. | The first line of the input contains integer n denoting the number of queries, (1 ≤ n ≤ 105). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value. It's guaranteed that all queries are correct. | standard output | standard input | Python 3 | Python | 1,500 | train_019.jsonl | f786c8d298fd53654bdfdb025f863a08 | 256 megabytes | ["5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2"] | PASSED | #Globales
Set, h = [], []
#Metodos
def dfs(a, b, Len, h):
if a == b:
return True
Len[a] = True
for x in h[a]:
if not Len[x] and dfs(x, b, Len, h):
return True
return False
def main():
for i in range(int(input())):
q, x, y = map(int, input().split())
if q... | 1371992400 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["Bob\nBob\nAlice\nAlice\nAlice\nBob\nBob\nBob"] | 581c89736e549300c566e4700b741906 | NoteLet's consider the first test case of the example.Alice has one card with integer $$$6$$$, Bob has two cards with numbers $$$[6, 8]$$$.If Alice is the first player, she has to play the card with number $$$6$$$. Bob then has to play the card with number $$$8$$$. Alice has no cards left, so she loses.If Bob is the fi... | Alice and Bob play a game. Alice has $$$n$$$ cards, the $$$i$$$-th of them has the integer $$$a_i$$$ written on it. Bob has $$$m$$$ cards, the $$$j$$$-th of them has the integer $$$b_j$$$ written on it.On the first turn of the game, the first player chooses one of his/her cards and puts it on the table (plays it). On t... | For each test case, print two lines. The first line should be Alice if Alice wins when she is the first player; otherwise, the first line should be Bob. The second line should contain the name of the winner if Bob is the first player, in the same format. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of four lines. The first line of a test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of cards Alice has. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ... | standard output | standard input | Python 3 | Python | 800 | train_087.jsonl | 64d4ae99e53328c886067f6a1434cde8 | 256 megabytes | ["4\n\n1\n\n6\n\n2\n\n6 8\n\n4\n\n1 3 3 7\n\n2\n\n4 2\n\n1\n\n50\n\n2\n\n25 50\n\n10\n\n1 2 3 4 5 6 7 8 9 10\n\n2\n\n5 15"] | PASSED | r='Alice','Bob'
R=lambda:max(map(int,input().split()))
for _ in[0]*R():R();a=R();R();b=R();print(r[a<b]+'\n'+r[a<=b]) | 1653316500 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
1 second | ["No", "Yes\n5\n1 2 4 5 6", "Yes\n4\n2 4 5 8"] | d5d470f2848e779310e5e54eccca8b4a | NoteIn the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, .In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, . | Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. Let's define for some set of integers as the number of pairs a, b in , such that: a is strictly less than b; a divides b without a remainder. You are to find such a set , which is a subset of {1, 2, .... | If there is no answer, print "No". Otherwise, in the first line print "Yes", in the second — an integer m that denotes the size of the set you have found, in the second line print m integers — the elements of the set , in any order. If there are multiple answers, print any of them. | The only line contains two integers n and k . | standard output | standard input | PyPy 2 | Python | 2,400 | train_004.jsonl | 4de4fd5210aa055ad585bfb952f2da02 | 256 megabytes | ["3 3", "6 6", "8 3"] | PASSED | import time,random,os
n,k=map(int,raw_input().split(' '))
t0=time.time()
while time.time()-t0<=0.8:
t=range(1,n+1)
g=[0]*(n+1)
app=[0]*(n+1)
random.shuffle(t)
rm=k
op=[]
for a in t:
su=g[a]
if su>rm:
continue
cur=a+a
while cur<=n and su<=rm:
... | 1518023700 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] | |
1 second | ["1\n-1\n3"] | d132158607bbd0541f2232a300e4a1b1 | null | You are given two strings $$$s$$$ and $$$t$$$ consisting of lowercase Latin letters. Also you have a string $$$z$$$ which is initially empty. You want string $$$z$$$ to be equal to string $$$t$$$. You can perform the following operation to achieve this: append any subsequence of $$$s$$$ at the end of string $$$z$$$. A ... | For each testcase, print one integer — the minimum number of operations to turn string $$$z$$$ into string $$$t$$$. If it's impossible print $$$-1$$$. | The first line contains the integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of test cases. The first line of each testcase contains one string $$$s$$$ ($$$1 \le |s| \le 10^5$$$) consisting of lowercase Latin letters. The second line of each testcase contains one string $$$t$$$ ($$$1 \le |t| \le 10^5$$$) consisting... | standard output | standard input | PyPy 2 | Python | 1,600 | train_023.jsonl | 3405facae75c047108e51810dff6c5f3 | 256 megabytes | ["3\naabce\nace\nabacaba\naax\nty\nyyt"] | PASSED | #!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from __builtin__ import xrange a... | 1580308500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["1 4 3\n4 1 2\n300000000 300000000 300000000\n999999998 1 1\n1 2 2"] | e0ec0cd81d2ec632ef89d207d80fa8a3 | NoteThe subsequence of the array $$$a$$$ is a sequence that can be obtained from $$$a$$$ by removing zero or more of its elements.Two subsequences are considered different if index sets of elements included in them are different. That is, the values of the elements don't matter in the comparison of subsequences. In par... | Polycarp had an array $$$a$$$ of $$$3$$$ positive integers. He wrote out the sums of all non-empty subsequences of this array, sorted them in non-decreasing order, and got an array $$$b$$$ of $$$7$$$ integers.For example, if $$$a = \{1, 4, 3\}$$$, then Polycarp wrote out $$$1$$$, $$$4$$$, $$$3$$$, $$$1 + 4 = 5$$$, $$$1... | For each test case, print $$$3$$$ integers — $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$. If there can be several answers, print any of them. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases. Each test case consists of one line which contains $$$7$$$ integers $$$b_1, b_2, \dots, b_7$$$ ($$$1 \le b_i \le 10^9$$$; $$$b_i \le b_{i+1}$$$). Additional constraint on the input: there exists at least one array $$$a$$$ ... | standard output | standard input | Python 3 | Python | 800 | train_087.jsonl | 6190165bc56a36f783638350f49bcc01 | 256 megabytes | ["5\n1 3 4 4 5 7 8\n1 2 3 4 5 6 7\n300000000 300000000 300000000 600000000 600000000 600000000 900000000\n1 1 2 999999998 999999999 999999999 1000000000\n1 2 2 3 3 4 5"] | PASSED | import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
outp = []... | 1639492500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
5 seconds | ["2\n6\n9\n10\n20"] | a00e2e79a3914ee11202a799c9bc01e7 | NoteFor first query: n = 6, f = 2. Possible partitions are [1, 5] and [5, 1].For second query: n = 7, f = 2. Possible partitions are [1, 6] and [2, 5] and [3, 4] and [4, 3] and [5, 3] and [6, 1]. So in total there are 6 possible ways of partitioning. | Today is Devu's birthday. For celebrating the occasion, he bought n sweets from the nearby market. He has invited his f friends. He would like to distribute the sweets among them. As he is a nice guy and the occasion is great, he doesn't want any friend to be sad, so he would ensure to give at least one sweet to each f... | For each query, output a single integer in a line corresponding to the answer of each query. | The first line contains an integer q representing the number of queries (1 ≤ q ≤ 105). Each of the next q lines contains two space space-separated integers n, f (1 ≤ f ≤ n ≤ 105). | standard output | standard input | Python 3 | Python | 2,100 | train_042.jsonl | 8b5f7945551a610f438d17246fb5e461 | 256 megabytes | ["5\n6 2\n7 2\n6 3\n6 4\n7 4"] | PASSED | import itertools
import functools
import operator
N = 100001
P = 10**9 + 7
fact = [1]
for i in range(1, N):
fact.append(fact[-1] * i % P)
inv = [0, 1]
for i in range(2, N):
inv.append(P - P // i * inv[P % i] % P)
inv_fact = [1]
for i in range(1, N):
inv_fact.append(inv_fact[-1] * inv[i] % P)
least_div = [-1] * N... | 1401895800 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["9 3 6 12 4 8", "126 42 84 28", "3000000000000000000 1000000000000000000"] | f9375003a3b64bab17176a05764c20e8 | NoteIn the first example the given sequence can be rearranged in the following way: $$$[9, 3, 6, 12, 4, 8]$$$. It can match possible Polycarp's game which started with $$$x = 9$$$. | Polycarp likes to play with numbers. He takes some integer number $$$x$$$, writes it down on the board, and then performs with it $$$n - 1$$$ operations of the two kinds: divide the number $$$x$$$ by $$$3$$$ ($$$x$$$ must be divisible by $$$3$$$); multiply the number $$$x$$$ by $$$2$$$. After each operation, Polycar... | Print $$$n$$$ integer numbers — rearranged (reordered) input sequence that can be the sequence that Polycarp could write down on the board. It is guaranteed that the answer exists. | The first line of the input contatins an integer number $$$n$$$ ($$$2 \le n \le 100$$$) — the number of the elements in the sequence. The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 3 \cdot 10^{18}$$$) — rearranged (reordered) sequence that Polycarp can wrote d... | standard output | standard input | PyPy 3 | Python | 1,400 | train_001.jsonl | fce49720753405c68c5fb134cdfcacd3 | 256 megabytes | ["6\n4 8 6 3 12 9", "4\n42 28 84 126", "2\n1000000000000000000 3000000000000000000"] | PASSED | def f(n, b, c=0):
while n % b == 0:
n //= b
c += 1
return c
n, a = int(input()), [int(i) for i in input().split()]
print(*sorted(a, key = lambda x: (f(x, 2), -f(x, 3))))
| 1567258500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["YES", "NO"] | a457e22fc8ff882c15ac57bca6960657 | NoteA string s contains another string p as a subsequence if it is possible to delete some characters from s and obtain p. | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | Output YES if the string s contains heidi as a subsequence and NO otherwise. | The first and only line of input contains a single nonempty string s of length at most 1000 composed of lowercase letters (a-z). | standard output | standard input | Python 3 | Python | 800 | train_008.jsonl | f4fd10e26098f40f8e48955a23fd8bcf | 256 megabytes | ["abcheaibcdi", "hiedi"] | PASSED | x =[i for i in input()]
def charpos(c1,arr):
for i in range(len(arr)):
if arr[i] ==c1:
return i
return -1
temp=0
result =True
for i in "heidi":
temp = charpos(i,x)
x = x[temp:]
if temp==-1:
result=False
break
if result:
print("YES")
else:
print("NO")
| 1495958700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["0 1 1 2 0 4 \n0 0 1 \n0 1 2 0 2 5 6 2"] | a83aaaa8984d1a6dda1adf10127b7abc | NoteThe first test case matches the example from the statement.The second set of input data is simple. Note that the answer $$$[3, 2, 1]$$$ also gives the same permutation, but since the total number of shifts $$$3+2+1$$$ is greater than $$$0+0+1$$$, this answer is not correct. | Petya got an array $$$a$$$ of numbers from $$$1$$$ to $$$n$$$, where $$$a[i]=i$$$.He performed $$$n$$$ operations sequentially. In the end, he received a new state of the $$$a$$$ array.At the $$$i$$$-th operation, Petya chose the first $$$i$$$ elements of the array and cyclically shifted them to the right an arbitrary ... | For each test case, print the answer on a separate line. Print -1 if the given final value $$$a$$$ cannot be obtained by performing an arbitrary number of cyclic shifts on each operation. Otherwise, print $$$n$$$ non-negative integers $$$d_1, d_2, \dots, d_n$$$ ($$$d_i \ge 0$$$), where $$$d_i$$$ means that during the $... | The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of the description of each test case contains one integer $$$n$$$ ($$$2 \le n \le 2\cdot10^3$$$) — the length of the array $$$a$$$. The next l... | standard output | standard input | PyPy 3-64 | Python | 1,300 | train_104.jsonl | 180570f023d62d350db9f8510d3b81f6 | 256 megabytes | ["3\n\n6\n\n3 2 5 6 1 4\n\n3\n\n3 1 2\n\n8\n\n5 8 1 3 2 6 4 7"] | PASSED | #!/usr/bin/env pypy3
import io, os, sys
from sys import stdin, stdout
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def input(): return stdin.readline().strip()
def read_int_list(): return list(map(int, input().split()))
def read_int_tuple(): return tuple(map(int, input().split()))
def read_i... | 1646750100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["3\n1 6\n2 4\n5 7", "1\n1 2", "1\n2 4"] | a019519539d493201bef69aff31bcd4e | NoteHere are the points and the moves for the ones that get chosen for the moves from the first example: | There are $$$n$$$ points on an infinite plane. The $$$i$$$-th point has coordinates $$$(x_i, y_i)$$$ such that $$$x_i > 0$$$ and $$$y_i > 0$$$. The coordinates are not necessarily integer.In one move you perform the following operations: choose two points $$$a$$$ and $$$b$$$ ($$$a \neq b$$$); move point $$$a$$... | In the first line print a single integer $$$c$$$ — the maximum number of moves you can perform. Each of the next $$$c$$$ lines should contain a description of a move: two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le n$$$, $$$a \neq b$$$) — the points that are removed during the current move. There should be a way to... | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of points. The $$$i$$$-th of the next $$$n$$$ lines contains four integers $$$a_i, b_i, c_i, d_i$$$ ($$$1 \le a_i, b_i, c_i, d_i \le 10^9$$$). The coordinates of the $$$i$$$-th point are $$$x_i = \frac{a_i}{b_i}$$$ and $$$y_i... | standard output | standard input | PyPy 3 | Python | 2,700 | train_102.jsonl | 5154763a6c9ef29bd686e2df0069fd1a | 256 megabytes | ["7\n4 1 5 1\n1 1 1 1\n3 3 3 3\n1 1 4 1\n6 1 1 1\n5 1 4 1\n6 1 1 1", "4\n2 1 1 1\n1 1 2 1\n2 1 1 2\n1 2 1 2", "4\n182 168 60 96\n78 72 45 72\n69 21 144 63\n148 12 105 6"] | PASSED | import sys
from sys import stdin
import math
from collections import deque
n = int(stdin.readline())
dic = {}
lis = []
for i in range(n):
a,b,c,d = map(int,stdin.readline().split())
A,B,C,D = a+b,b,c,d
siA = C * B
boA = D * A
g = math.gcd(siA,boA)
siA //= g
boA //= g
i... | 1619706900 | [
"geometry",
"trees",
"graphs"
] | [
0,
1,
1,
0,
0,
0,
0,
1
] | |
1 second | ["NO\nYES\nNO\nYES\nNO\nYES\nYES\nNO\nNO\nYES\nNO\nYES"] | 3cd56870a96baf8860e9b7e89008d895 | null | You talked to Polycarp and asked him a question. You know that when he wants to answer "yes", he repeats Yes many times in a row.Because of the noise, you only heard part of the answer — some substring of it. That is, if he answered YesYes, then you could hear esY, YesYes, sYes, e, but you couldn't Yess, YES or se.Dete... | Output $$$t$$$ lines, each of which is the answer to the corresponding test case. As an answer, output "YES" if the specified string $$$s$$$ is a substring of the string YesYesYes...Yes (the number of words Yes is arbitrary), and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "ye... | The first line of input data contains the singular $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Each test case is described by a single string of Latin letters $$$s$$$ ($$$1 \le |s| \le 50$$$) — the part of Polycarp's answer that you heard, where $$$|s|$$$ — is the length of the string $$$s$... | standard output | standard input | Python 3 | Python | 800 | train_086.jsonl | f6d829173d49c526fb4f0aa9d9533fcb | 256 megabytes | ["12\n\nYES\n\nesYes\n\ncodeforces\n\nes\n\nse\n\nYesY\n\nesYesYesYesYesYesYe\n\nseY\n\nYess\n\nsY\n\no\n\nYes"] | PASSED | number = int(input())
cases = []
for i in range(number):
cases.append(input())
def yesno(c):
if c in "YesYes"*(len(c)//6+2):
return "Yes"
else:
return "NO"
for c in cases:
print(yesno(c))
| 1668782100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["2", "2"] | ad2c4d07da081505fa251ba8c27028b1 | NoteIn the first example there are two ways: xxo xoo xox ooo oxx oox | Toastman came up with a very complicated task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o', or nothing. How many ways to fill all the empty cells with 'x' or 'o' (each cell must contain... | Print a single integer — the answer to the problem. | The first line contains two integers n, k (1 ≤ n, k ≤ 105) — the size of the board, and the number of cells that has characters initially. Then k lines follows. The i-th line contains two integers and a character: ai, bi, ci (1 ≤ ai, bi ≤ n; ci is either 'o' or 'x'). This line means: there is a character ci in the cel... | standard output | standard input | Python 2 | Python | 2,800 | train_060.jsonl | df038c5e145652e0ae1f133373c0ef04 | 256 megabytes | ["3 2\n1 1 x\n2 2 o", "4 3\n2 4 x\n3 4 x\n3 2 x"] | PASSED | from sys import stdin
def main():
n, k = map(int, stdin.readline().split())
par = [range(n+10), range(n+10)]
def find(i, x):
if par[i][x] == x:
return x
else:
par[i][x] = find(i, par[i][x])
return par[i][x]
def unite(i, x, y):
x, y = find(i, x)... | 1409061600 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["$2,012.00", "$0.00", "($0.00)", "($12,345,678.90)"] | c704c5fb9e054fab1caeab534849901d | NotePay attention to the second and third sample tests. They show that the sign of a number in the financial format (and consequently, the presence or absence of brackets) is determined solely by the sign of the initial number. It does not depend on the sign of the number you got after translating the number to the fin... | For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more easily readable format. However, as time went by, the economy of the Far Far Away developed and the scale of operatio... | Print the number given in the input in the financial format by the rules described in the problem statement. | The input contains a number that needs to be converted into financial format. The number's notation length does not exceed 100 characters, including (possible) signs "-" (minus) and "." (decimal point). The number's notation is correct, that is: The number's notation only contains characters from the set {"0" – "9",... | standard output | standard input | Python 3 | Python | 1,200 | train_010.jsonl | 1804266ce908e1129fc309a3998e358d | 256 megabytes | ["2012", "0.000", "-0.00987654321", "-12345678.9"] | PASSED | import math, re, sys, string, operator, functools, fractions, collections
sys.setrecursionlimit(10**7)
RI=lambda x=' ': list(map(int,input().split(x)))
RS=lambda x=' ': input().rstrip().split(x)
dX= [-1, 1, 0, 0,-1, 1,-1, 1]
dY= [ 0, 0,-1, 1, 1,-1,-1, 1]
mod=int(1e9+7)
eps=1e-6
pi=math.acos(-1.0)
MAX=100
##############... | 1326380700 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
4 seconds | ["2", "0", "4"] | d3e972b7652c0c1321c2e8f15dbc264b | NoteIn the first case, the answer is $$$2$$$, as the whole array is good: $$$5 \& 6 = 4 > 5 \oplus 6 = 3$$$.In the third case, the answer is $$$4$$$, and one of the longest good subarrays is $$$[a_2, a_3, a_4, a_5]$$$: $$$1\& 3 \& 3 \&1 = 1 > 1\oplus 3 \oplus 3\oplus 1 = 0$$$. | Bakry got bored of solving problems related to xor, so he asked you to solve this problem for him.You are given an array $$$a$$$ of $$$n$$$ integers $$$[a_1, a_2, \ldots, a_n]$$$.Let's call a subarray $$$a_{l}, a_{l+1}, a_{l+2}, \ldots, a_r$$$ good if $$$a_l \, \& \, a_{l+1} \, \& \, a_{l+2} \, \ldots \, \&... | Print a single integer — the length of the longest good subarray. If there are no good subarrays, print $$$0$$$. | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — elements of the array. | standard output | standard input | PyPy 2 | Python | 2,400 | train_106.jsonl | 03148d1d3d87d331660d5363e9f713ba | 256 megabytes | ["2\n5 6", "3\n2 4 3", "6\n8 1 3 3 1 2"] | PASSED | from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
from bisect import bisect_left as lower_bound, bisect_right as upper_bound
... | 1633271700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1 1 1 2 -1 1 1 3 1 1"] | 9271c88a3bc3c69855daeda9bb6bbaf5 | null | You are given an array $$$a$$$ consisting of $$$n$$$ integers. In one move, you can jump from the position $$$i$$$ to the position $$$i - a_i$$$ (if $$$1 \le i - a_i$$$) or to the position $$$i + a_i$$$ (if $$$i + a_i \le n$$$).For each position $$$i$$$ from $$$1$$$ to $$$n$$$ you want to know the minimum the number of... | Print $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$, where $$$d_i$$$ is the minimum the number of moves required to reach any position $$$j$$$ such that $$$a_j$$$ has the opposite parity from $$$a_i$$$ (i.e. if $$$a_i$$$ is odd then $$$a_j$$$ has to be even and vice versa) or -1 if it is impossible to reach such a positi... | The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. | standard output | standard input | Python 2 | Python | 1,900 | train_008.jsonl | 65a43994e1db0c200db1350790b7b34e | 256 megabytes | ["10\n4 5 7 6 7 5 4 4 6 4"] | PASSED |
class Solution(object):
def solve(self,array):
"""
:type arr: List[int]
:type start: int
:rtype: bool
"""
from collections import defaultdict,deque
D=defaultdict(list)
self.t_max=float('inf')
for i in range(0,len(array)):
if array[... | 1576157700 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["8\n2\n11\n1111111110"] | 7a51d536d5212023cc226ef1f6201174 | null | You are given two integers $$$l$$$ and $$$r$$$, where $$$l < r$$$. We will add $$$1$$$ to $$$l$$$ until the result is equal to $$$r$$$. Thus, there will be exactly $$$r-l$$$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.For example: if $$$l=909$$$, th... | For each test case, calculate the total number of changed digits if you want to get $$$r$$$ from $$$l$$$, adding one each time. | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. Each test case is characterized by two integers $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le 10^9$$$). | standard output | standard input | PyPy 3 | Python | 1,500 | train_097.jsonl | 50a668437258d7b7d8f523c58bcc3909 | 256 megabytes | ["4\n1 9\n9 10\n10 20\n1 1000000000"] | PASSED | import sys
def memoize(f):
st = {}
def _mk_r():
def r(*args):
_k = args
if _k in st:
return st[_k]
c = f(*args)
st[_k] = c
# print(f'{key}{_k} -> {c}')
return c
return r
return _mk_r()
def run():
class _fake_int(object):
def _... | 1623335700 | [
"number theory",
"math"
] | [
0,
0,
0,
1,
1,
0,
0,
0
] | |
4 seconds | ["465\n12\n986128624\n7636394\n57118194"] | d8ba9b38f7b2293452363ccd9c21d748 | null | Calculate the number of permutations $$$p$$$ of size $$$n$$$ with exactly $$$k$$$ inversions (pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$p_i > p_j$$$) and exactly $$$x$$$ indices $$$i$$$ such that $$$p_i > p_{i+1}$$$.Yep, that's the whole problem. Good luck! | For each test case, print one integer — the answer to the problem, taken modulo $$$998244353$$$. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 3 \cdot 10^4$$$) — the number of test cases. Each test case consists of one line which contains three integers $$$n$$$, $$$k$$$ and $$$x$$$ ($$$1 \le n \le 998244352$$$; $$$1 \le k \le 11$$$; $$$1 \le x \le 11$$$). | standard output | standard input | PyPy 3 | Python | 2,700 | train_087.jsonl | 1217acb44ea0b3f6015bbb004457aed7 | 512 megabytes | ["5\n\n10 6 4\n\n7 3 1\n\n163316 11 7\n\n136373 11 1\n\n325902 11 11"] | PASSED | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v, w):
return u + v * l1 + w * l2
def g(x):
u = x % l1
v = x % l2 // l1
w = x // l2
return u, v, w
pow2 = [1]
for _ in range(13):
pow2.append(2 * pow2[-1])
sp = set()
for i in pow2:
s... | 1650638100 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["5\n2 1 4 7 5 \n4\n1 5\n2 5\n5 4\n3 4"] | ff8219b0e4fd699b1898500664087e90 | NoteOne of the possible structures in the first example: | The Dogeforces company has $$$k$$$ employees. Each employee, except for lower-level employees, has at least $$$2$$$ subordinates. Lower-level employees have no subordinates. Each employee, except for the head of the company, has exactly one direct supervisor. The head of the company is a direct or indirect supervisor o... | In the first line, print a single integer $$$k$$$ — the number of employees in the company. In the second line, print $$$k$$$ integers $$$c_1, c_2, \dots, c_k$$$, where $$$c_i$$$ is the salary of the employee with the number $$$i$$$. In the third line, print a single integer $$$r$$$ — the number of the employee who is ... | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 500$$$) — the number of lower-level employees. This is followed by $$$n$$$ lines, where $$$i$$$-th line contains $$$n$$$ integers $$$a_{i,1}, a_{i,2}, \dots, a_{i,n}$$$ ($$$1 \le a_{i,j} \le 5000$$$) — salary of the common supervisor of employees with num... | standard output | standard input | PyPy 3-64 | Python | 2,300 | train_094.jsonl | c4d7e01d107b6923cdd8b469dc1b7d35 | 256 megabytes | ["3\n2 5 7\n5 1 7\n7 7 4"] | PASSED | import sys
input = sys.stdin.buffer.readline
def findroot(parent, x):
y = x
while y != parent[y]:
y = parent[y]
return y
def process(A):
n = len(A[0])
parent = [i for i in range(n)]
weight = [None for i in range(n)]
L = []
for i in range(n):
w = A[i][i]... | 1614696300 | [
"trees"
] | [
0,
0,
0,
0,
0,
0,
0,
1
] | |
2 seconds | ["3", "3"] | f3dde329830d8c479b3dab9d5df8baf5 | NoteIn the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).In the second sample any couple of clients is opposite. | Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the i-th client number ti ( - 10 ≤ ti ≤ 10). Of course, one number can be assigned to any number of cust... | Print the number of couples of customs with opposite t. The opposite number for x is number - x (0 is opposite to itself). Couples that only differ in the clients' order are considered the same. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, d... | The first line of the input data contains an integer n (1 ≤ n ≤ 105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers t1, t2, ..., tn ( - 10 ≤ ti ≤ 10), ti — is the parameter of the i-th customer that has been assigned to the customer by the res... | standard output | standard input | Python 3 | Python | 1,200 | train_002.jsonl | bbe0c6853e557bf03be2e99021a7bc1d | 256 megabytes | ["5\n-3 3 0 0 3", "3\n0 0 0"] | PASSED | data = input()
cnt = int(data[0])
t = [int(i) for i in input().split()]
d = dict()
for idx in range(-10, 11):
d[idx] = 0
for r in t:
d[r] += 1
s = 0
for idx in range(1, 11):
s += d[idx] * d[(-idx)]
if d[0] > 1:
for idx in range(1, d[0]):
s += idx
print(s) | 1322233200 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["1\n1", "0", "4\n1 2 3 4"] | 794b0ac038e4e32f35f754e9278424d3 | NoteIn the first sample Igor supposes that the first employee will receive 0 messages. Since he isn't contained in any other contact list he must come to the party in order to receive one message from himself. If he is the only who come to the party then he will receive 1 message, the second employee will receive 0 mes... | The Looksery company, consisting of n staff members, is planning another big party. Every employee has his phone number and the phone numbers of his friends in the phone book. Everyone who comes to the party, sends messages to his contacts about how cool it is. At the same time everyone is trying to spend as much time ... | In the first line print a single integer m — the number of employees who should come to the party so that Igor loses the dispute. In the second line print m space-separated integers — the numbers of these employees in an arbitrary order. If Igor wins the dispute in any case, print -1. If there are multiple possible sol... | The first line contains a single integer n (1 ≤ n ≤ 100) — the number of employees of company Looksery. Next n lines contain the description of the contact lists of the employees. The i-th of these lines contains a string of length n, consisting of digits zero and one, specifying the contact list of the i-th employee. ... | standard output | standard input | Python 3 | Python | 2,300 | train_014.jsonl | df5efee3e21521aba858c9ded9496d96 | 256 megabytes | ["3\n101\n010\n001\n0 1 2", "1\n1\n1", "4\n1111\n0101\n1110\n0001\n1 0 1 0"] | PASSED | n=int(input().strip())
nums=['']+[' '+input().strip() for _ in range(n)]
a=[0]+list(map(int,input().split()))
def send(x):
for i in range(1,n+1):
if nums[x][i]=='1':
a[i]-=1
vis=[0]*(n+1)
while True:
for i in range(1,n+1):
if not vis[i] and not a[i]:
vis[i]=1
... | 1433595600 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["17\n1\n3\n4", "1"] | b7942cf792c368cc240ed22e91ad406f | NoteIn the first example, the array $$$A$$$ obtained is $$$[1, 2, 3, 3, 4, 4]$$$. We can see that the array is sortable by doing the following operations: Choose index $$$5$$$, then $$$A = [1, 2, 3, 3, 6, 4]$$$. Choose index $$$6$$$, then $$$A = [1, 2, 3, 3, 6, 6]$$$. Choose index $$$4$$$, then $$$A = [1, 2, 3, 4, ... | Let's say Pak Chanek has an array $$$A$$$ consisting of $$$N$$$ positive integers. Pak Chanek will do a number of operations. In each operation, Pak Chanek will do the following: Choose an index $$$p$$$ ($$$1 \leq p \leq N$$$). Let $$$c$$$ be the number of operations that have been done on index $$$p$$$ before this ... | Print $$$Q+1$$$ lines. The $$$1$$$-st line contains an integer representing $$$A_1 + A_2 + A_3 + A_4 + \ldots + A_N$$$. For each $$$1 \leq i \leq Q$$$, the $$$(i+1)$$$-th line contains an integer representing $$$A_{P_i}$$$. | The first line contains two integers $$$N$$$ and $$$Q$$$ ($$$1 \leq N \leq 10^9$$$, $$$0 \leq Q \leq \min(N, 10^5)$$$) — the required length of array $$$A$$$ and the number of questions. The $$$i$$$-th of the next $$$Q$$$ lines contains a single integer $$$P_i$$$ ($$$1 \leq P_1 < P_2 < \ldots < P_Q \leq N$$$) ... | standard output | standard input | PyPy 3-64 | Python | 2,900 | train_093.jsonl | c09458318e0550d6c5de3b52ccac47e8 | 512 megabytes | ["6 3\n1\n4\n5", "1 0"] | PASSED | ## Fast I/O
import io,os,sys
# Fast input. Use s = input().decode() for strings
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# Fast output
def print(*args, sep = ' ', end = '\n'):
string = sep.join(map(str, args))+end
sys.stdout.write(string)
def debug(*args, sep = ' ', end = '\n'):
stri... | 1662298500 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["1\n3\n3\n10"] | ac4aac095e71cbfaf8b79262d4038095 | null | You are given an array $$$a$$$ of $$$n$$$ integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_j - a_i = j - i$$$. | For each test case output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_j - a_i = j - i$$$. | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — array $$... | standard output | standard input | Python 3 | Python | 1,200 | train_083.jsonl | 23d1f492d2cabafd0e351f6929d223bb | 256 megabytes | ["4\n6\n3 5 1 4 6 6\n3\n1 2 3\n4\n1 3 3 4\n6\n1 6 3 4 5 6"] | PASSED | LENGHT = 4*10**3
PRIME_NUMB = 99999989
PRIME_NUMB2 = 999999937
from enum import Enum, auto
import random
import time
class Situation(Enum):
EMPTY = auto
DELETED = auto
FILLED = auto
class HashTable():
def __init__(self , lenght = LENGHT):
self.lenght = lenght
self.table ... | 1620225300 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
1 second | ["<RUn.exe O>\n<>\n< 2ne, >\n<two!>\n<.>\n< >", "<firstarg>\n<second>\n<>"] | 6c7858731c57e1b24c7a299a8eeab373 | null | The problem describes the properties of a command line. The description somehow resembles the one you usually see in real operating systems. However, there are differences in the behavior. Please make sure you've read the statement attentively and use it as a formal document.In the Pindows operating system a strings ar... | In the first line print the first lexeme, in the second line print the second one and so on. To make the output clearer, print the "<" (less) character to the left of your lexemes and the ">" (more) character to the right. Print the lexemes in the order in which they occur in the command. Please, follow the given... | The single line contains a non-empty string s. String s consists of at most 105 characters. Each character is either an uppercase or a lowercase English letter, or a digit, or one of the ".,?!"" signs, or a space. It is guaranteed that the given string is some correct command line string of the OS Pindows. It is guaran... | standard output | standard input | PyPy 2 | Python | 1,300 | train_009.jsonl | 64451ed6fca0f307fe206c14c502607f | 256 megabytes | ["\"RUn.exe O\" \"\" \" 2ne, \" two! . \" \"", "firstarg second \"\""] | PASSED | s = raw_input().strip()
lexemes = []
quoting = False
chars = []
for pos, ch in enumerate(s):
if ch == '"':
if not quoting:
quoting = True
continue
lexemes.append('<' + ''.join(chars) + '>')
chars = []
quoting = False
continue
if ch == ' ':
if quoting:
chars.append(ch)
e... | 1365796800 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
2 seconds | ["0.0000000000", "18.0038068653"] | 754df388958709e3820219b14beb7517 | null | You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you understood that it is broken and behaves rather strangely (randomly). The board consists of N rows and M columns of cells. The robot is initially at some cell on the i-th row and the j-th column. Then at every step the robot c... | Output the expected number of steps on a line of itself with at least 4 digits after the decimal point. | On the first line you will be given two space separated integers N and M (1 ≤ N, M ≤ 1000). On the second line you will be given another two space separated integers i and j (1 ≤ i ≤ N, 1 ≤ j ≤ M) — the number of the initial row and the number of the initial column. Note that, (1, 1) is the upper left corner of the boa... | standard output | standard input | Python 3 | Python | 2,400 | train_080.jsonl | f538afd9ecec4411db8ccabdd6c25bfa | 256 megabytes | ["10 10\n10 4", "10 14\n5 14"] | PASSED | n,m = (int(s) for s in input().split())
i,j = (int(s) for s in input().split())
def find(n,m,i,j):
if i==n:
return 0
if m==1:
return 2*(n-i)
e,a,b = [0.]*m,[0]*m,[0]*m
for l in range(n-1,0,-1):
a[0],b[0]=.5,.5*(3+e[0])
for k in range(1,m-1):
a[k] = 1/(3-a[k-1]... | 1280149200 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
2.5 seconds | ["4 6"] | 6d0bc28aa0b47c12438a84e57cd8e081 | NoteThe 5-by-5 grid for the first test case looks like this: maytheforcebewithyouhctwo | The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the so... | The only line of the output should contain two space-separated integers i and j, denoting that the section of size M × M in the first map that starts at the i-th row is equal to the section of the second map that starts at the j-th column. Rows and columns are numbered starting from 1. If there are several possible way... | The first line of the input contains two space-separated integers N and M (1 ≤ N ≤ 2000, 1 ≤ M ≤ 200, M ≤ N). The next N lines each contain M lower-case Latin characters (a-z), denoting the first map. Different characters correspond to different cosmic object types. The next M lines each contain N characters, describin... | standard output | standard input | Python 3 | Python | 2,000 | train_015.jsonl | 8f818b36ff89af69420d5bbcef59514a | 256 megabytes | ["10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo"] | PASSED | n, m = list(map(int, input().strip().split(' ')))
mat1, mat2 = [], []
for i in range(0, n): mat1.append(tuple(input().strip()))
for i in range(0, m): mat2.append(tuple(input().strip()))
ix, jx, flg = -1, -1, 0
matr, matc = [], []
for i in range(0, n-m+1):
si, se = i, i+m
matr.append(hash(tuple(mat1[si:se])))
matcur2... | 1523689500 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
4 seconds | ["332748119\n332748119", "3", "160955686\n185138929\n974061117"] | ba9c136f84375cd317f0f8b53e3939c7 | NoteIn the first example, if the only visit shows the first picture with a probability of $$$\frac 2 3$$$, the final weights are $$$(1,1)$$$; if the only visit shows the second picture with a probability of $$$\frac1 3$$$, the final weights are $$$(2,2)$$$.So, both expected weights are $$$\frac2 3\cdot 1+\frac 1 3\cdot... | The only difference between easy and hard versions is constraints.Nauuo is a girl who loves random picture websites.One day she made a random picture website by herself which includes $$$n$$$ pictures.When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal proba... | The output contains $$$n$$$ integers $$$r_1,r_2,\ldots,r_n$$$ — the expected weights modulo $$$998244353$$$. | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n\le 2\cdot 10^5$$$, $$$1\le m\le 3000$$$) — the number of pictures and the number of visits to the website. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$a_i$$$ is either $$$0$$$ or $$$1$$$) — if $$$a_i=0$$$ , Nauuo does not lik... | standard output | standard input | PyPy 2 | Python | 2,600 | train_007.jsonl | 3c5cd6958f4986a074603d2532720d03 | 256 megabytes | ["2 1\n0 1\n2 1", "1 2\n1\n1", "3 3\n0 1 1\n4 3 5"] | PASSED | P = 998244353
N, M = map(int, raw_input().split())
A = [int(a) for a in raw_input().split()]
B = [int(a) for a in raw_input().split()]
li = sum([A[i]*B[i] for i in range(N)])
di = sum([(A[i]^1)*B[i] for i in range(N)])
X = [1]
SU = li+di
PO = [0] * (5*M+10)
for i in range(-M-5, 2*M+5):
PO[i] = pow((SU+i)%P, P-2, P)... | 1559909100 | [
"probabilities"
] | [
0,
0,
0,
0,
0,
1,
0,
0
] | |
2 seconds | ["YES", "NO"] | 9ee3d548f93390db0fc2f72500d9eeb0 | NoteIn the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.So, user tncks0121 has ma... | If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO". | The first line contains two space-separated integers n (3 ≤ n ≤ 3 × 104) and t (2 ≤ t ≤ n) — the number of cells, and the index of the cell which I want to go to. The second line contains n - 1 space-separated integers a1, a2, ..., an - 1 (1 ≤ ai ≤ n - i). It is guaranteed, that using the given transportation system, o... | standard output | standard input | Python 3 | Python | 1,000 | train_011.jsonl | e2da9fc9cbce369cdb16efbe1d988905 | 256 megabytes | ["8 4\n1 2 1 2 1 2 1", "8 5\n1 2 1 2 1 1 1"] | PASSED | n, t = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
x = 0
i = 0
while i in range(0, t):
i += a[i]
if i == t-1:
x = 1
break
if x == 1:
print('YES')
else:
print('NO')
| 1419951600 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
1 second | ["1\n0\n2\n4\n4"] | d786585fee251ebfd5c3e8d8b0425791 | NoteIn the first test case, $$$s=1+2+3+4+5=15$$$, only $$$(2,3,4,5)$$$ is a nearly full subsequence among all subsequences, the sum in it is equal to $$$2+3+4+5=14=15-1$$$.In the second test case, there are no nearly full subsequences.In the third test case, $$$s=1+0=1$$$, the nearly full subsequences are $$$(0)$$$ and... | Luntik came out for a morning stroll and found an array $$$a$$$ of length $$$n$$$. He calculated the sum $$$s$$$ of the elements of the array ($$$s= \sum_{i=1}^{n} a_i$$$). Luntik calls a subsequence of the array $$$a$$$ nearly full if the sum of the numbers in that subsequence is equal to $$$s-1$$$.Luntik really wants... | For each test case print the number of nearly full subsequences of the array. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The next $$$2 \cdot t$$$ lines contain descriptions of test cases. The description of each test case consists of two lines. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 60$$$) — th... | standard output | standard input | Python 3 | Python | 900 | train_106.jsonl | 3cb3e8acfa1c66ce1dffe8a9d346e3ed | 256 megabytes | ["5\n5\n1 2 3 4 5\n2\n1000 1000\n2\n1 0\n5\n3 0 2 1 1\n5\n2 1 0 3 0"] | PASSED | t=int(input())
for k in range(t):
n=int(input())
s=list(map(int,input().split(' ')))
p1=s.count(1)
p2=s.count(0)
print(2**p2*p1) | 1635069900 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
2 seconds | ["2\nmasha 1 00123 \nivan 1 00123", "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612", "2\ndasha 2 23 789 \nivan 4 789 123 2 456"] | df7b16d582582e6756cdb2d6d856c873 | null | Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a frien... | Print out the ordered information about the phone numbers of Vasya's friends. First output m — number of friends that are found in Vasya's phone books. The following m lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each reco... | First line contains the integer n (1 ≤ n ≤ 20) — number of entries in Vasya's phone books. The following n lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English lett... | standard output | standard input | PyPy 3 | Python | 1,400 | train_026.jsonl | 620c7e1133a98a8610b8d3a932986028 | 256 megabytes | ["2\nivan 1 00123\nmasha 1 00123", "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789"] | PASSED | def cleaner(l):
l = list(set(l))
l.sort()
ans=[]
for i in range(len(l)):
for j in range(0,len(l)):
if l[j].endswith(l[i]) and i!=j:
break
else:
ans+=[l[i]]
return ans
d = dict()
for t in range(int(input())):
l = [x for x in input().split(" ... | 1513424100 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
1 second | ["3\n1\n4"] | ce3f65acc33d624ed977e1d8f3494597 | NoteIn the first example, any edge $$$x \to y$$$ such that $$$x > y$$$ is valid, because there already is a path $$$1 \to 2 \to 3$$$.In the second example only the edge $$$4 \to 1$$$ is valid. There is a path $$$3 \to 4 \to 1 \to 2$$$ if this edge is added.In the third example you can add edges $$$2 \to 1$$$, $$$3 \... | You are given a directed acyclic graph with $$$n$$$ vertices and $$$m$$$ edges. For all edges $$$a \to b$$$ in the graph, $$$a < b$$$ holds.You need to find the number of pairs of vertices $$$x$$$, $$$y$$$, such that $$$x > y$$$ and after adding the edge $$$x \to y$$$ to the graph, it has a Hamiltonian path. | For each test case, print one integer: the number of pairs of vertices $$$x$$$, $$$y$$$, $$$x > y$$$, such that after adding the edge $$$x \to y$$$ to the graph, it has a Hamiltonian path. | The first line of input contains one integer $$$t$$$ ($$$1 \leq t \leq 5$$$): the number of test cases. The next lines contains the descriptions of the test cases. In the first line you are given two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 150\,000$$$, $$$0 \leq m \leq \min(150\,000, \frac{n(n-1)}{2})$$$): the n... | standard output | standard input | PyPy 3 | Python | 3,500 | train_101.jsonl | 4c32784f824e939589f7e424cf8220fb | 256 megabytes | ["3\n3 2\n1 2\n2 3\n4 3\n1 2\n3 4\n1 4\n4 4\n1 3\n1 4\n2 3\n3 4"] | PASSED | import io,os,sys
read = io.BytesIO(os.read(0, os.fstat(0).st_size))
I = lambda:map(int, read.readline().split())
import time
#I = lambda:map(int, sys.stdin.readline().split())
t, = I()
for _ in range(t):
n, m = I()
# if n > 100:
# print(time.time())
to = [[] for i in range(n)]
fro = [[] for i in rang... | 1640792100 | [
"graphs"
] | [
0,
0,
1,
0,
0,
0,
0,
0
] | |
2 seconds | ["2", "7"] | 180c19997a37974199bc73a5d731d289 | NoteThe following image describes the answer for the second sample case: | After returned from forest, Alyona started reading a book. She noticed strings s and t, lengths of which are n and m respectively. As usual, reading bored Alyona and she decided to pay her attention to strings s and t, which she considered very similar.Alyona has her favourite positive integer k and because she is too ... | In the only line print the only non-negative integer — the sum of the lengths of the strings in a desired sequence. It is guaranteed, that at least one desired sequence exists. | In the first line of the input three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 10) are given — the length of the string s, the length of the string t and Alyona's favourite number respectively. The second line of the input contains string s, consisting of lowercase English letters. The third line of the input contains... | standard output | standard input | PyPy 2 | Python | 1,900 | train_007.jsonl | 7205ab57459670266c0f0fe528f98b31 | 256 megabytes | ["3 2 2\nabc\nab", "9 12 4\nbbaaababb\nabbbabbaaaba"] | PASSED | def main():
n, m, k = map(int, raw_input().split())
dp = [[0] * (m + 1) for _ in xrange(n + 1)]
cnt = [[0] * (m + 1) for _ in xrange(n + 1)]
s, t = raw_input(), raw_input()
for i, c in enumerate(s):
for j in xrange(m):
if t[j] == c:
dp[i + 1][j + 1] = dp[i][j] + 1... | 1466181300 | [
"strings"
] | [
0,
0,
0,
0,
0,
0,
1,
0
] | |
3 seconds | ["0\n\n\n0\n\n\n1\n\n\n1"] | 26c413fd747041b7501c451e36f92529 | NoteIn the example, the participants made 1, 2, and 3 mistakes respectively, therefore $$$b=1$$$ (the smallest of these numbers). Izzy made 3 mistakes, which were not more than $$$1.3\cdot b + 100=101.3$$$, so these outputs are good enough to pass this test case (as are any other valid outputs). | The popular improv website Interpretation Impetus hosts regular improv contests and maintains a rating of the best performers. However, since improv can often go horribly wrong, the website is notorious for declaring improv contests unrated. It now holds a wager before each improv contest where the participants try to ... | null | null | standard output | standard input | PyPy 3 | Python | 2,700 | train_099.jsonl | 5c7c5557fc80e0d98dce7f4a17cd4231 | 512 megabytes | ["3 4\n000\n\n1\n100\n\n1\n001\n\n0\n111\n\n1"] | PASSED | import math
from sys import stdout
from typing import List
def get_guesses() -> List[int]:
inp = input()
return [-1 if x == '0' else 1 for x in inp]
def guess(answer: int) -> None:
print(answer)
stdout.flush()
def get_ans() -> int:
true_ans = int(input())
return true_ans
... | 1617523500 | [
"probabilities",
"math"
] | [
0,
0,
0,
1,
0,
1,
0,
0
] | |
1 second | ["quailty", "once again", "tokitsukaze", "once again"] | 5e73099c7ec0b82aee54f0841c00f15e | NoteIn the first example, no matter how Tokitsukaze moves, there would be three cards with color sides facing the same direction after her move, and Quailty can flip the last card to this direction and win.In the second example, no matter how Tokitsukaze moves, Quailty can choose the same card and flip back to the init... | "Duel!"Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.There are $$$n$$$ cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping ca... | Print "once again" (without quotes) if the total number of their moves can exceed $$$10^9$$$, which is considered a draw. In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win. Note that the output characters are case-sensitive, and any wrong spe... | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^5$$$). The second line contains a single string of length $$$n$$$ that only consists of $$$0$$$ and $$$1$$$, representing the situation of these $$$n$$$ cards, where the color side of the $$$i$$$-th card faces up if the $$$i$$$-th charact... | standard output | standard input | Python 2 | Python | 2,300 | train_050.jsonl | 0bb77906a08afd96e4246b8c6077f914 | 256 megabytes | ["4 2\n0101", "6 1\n010101", "6 5\n010101", "4 1\n0011"] | PASSED | import sys
import copy
input = sys.stdin.readline
n,k=map(int,raw_input().split())
C=list(raw_input().strip())
def JUDGE(C):
ANS_one=0
ANS_zero=0
for c in C:
if c=="0":
ANS_zero+=1
else:
break
for c in C[::-1]:
if c=="0":
ANS_zero+=1
el... | 1562942100 | [
"games"
] | [
1,
0,
0,
0,
0,
0,
0,
0
] | |
3 seconds | ["5.000000000 2.549499369\n4.000000000 0.378324889", "10.204081436 0.000000000\n4.000000000 0.378324889"] | d51aa18439e7afffa11ad181064c0450 | null | Bertown is under siege! The attackers have blocked all the ways out and their cannon is bombarding the city. Fortunately, Berland intelligence managed to intercept the enemies' shooting plan. Let's introduce the Cartesian system of coordinates, the origin of which coincides with the cannon's position, the Ox axis is di... | Print n lines containing two real numbers each — calculate for every ball the coordinates of its landing point. Your answer should have the relative or absolute error less than 10 - 4. | The first line contains integers n and V (1 ≤ n ≤ 104, 1 ≤ V ≤ 1000) which represent the number of shots and the initial speed of every ball. The second line contains n space-separated real numbers alphai (0 < alphai < π / 4) which represent the angles in radians at which the cannon will fire. The third line cont... | standard output | standard input | PyPy 3 | Python | 2,200 | train_078.jsonl | 11b07351bc932b8eba66e1f7ba7309fc | 256 megabytes | ["2 10\n0.7853\n0.3\n3\n5.0 5.0\n4.0 2.4\n6.0 1.9", "2 10\n0.7853\n0.3\n2\n4.0 2.4\n6.0 1.9"] | PASSED | import sys
from array import array # noqa: F401
from math import pi, sin, cos
from bisect import bisect_left
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, v = map(int, input().split())
v = float(v)
alpha = [float(input()) for _ in range(n)]
m = int(input())
wall = sorted(tuple(map(float, i... | 1291737600 | [
"geometry"
] | [
0,
1,
0,
0,
0,
0,
0,
0
] | |
1 second | ["-1\n1\n11\n110\n190\n9012345679\n-87611785637\n1\n0"] | dbe12a665c374ce3745e20b4a8262eac | NoteThe first two test cases in the example correspond to the first two jumps from the point $$$x_0 = 0$$$. Since $$$0$$$ is an even number, the first jump of length $$$1$$$ is made to the left, and the grasshopper ends up at the point $$$0 - 1 = -1$$$.Then, since $$$-1$$$ is an odd number, a jump of length $$$2$$$ is ... | The grasshopper is located on the numeric axis at the point with coordinate $$$x_0$$$.Having nothing else to do he starts jumping between integer points on the axis. Making a jump from a point with coordinate $$$x$$$ with a distance $$$d$$$ to the left moves the grasshopper to a point with a coordinate $$$x - d$$$, whi... | Print exactly $$$t$$$ lines. On the $$$i$$$-th line print one integer — the answer to the $$$i$$$-th test case — the coordinate of the point the grasshopper will be at after making $$$n$$$ jumps from the point $$$x_0$$$. | The first line of input contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Each of the following $$$t$$$ lines contains two integers $$$x_0$$$ ($$$-10^{14} \leq x_0 \leq 10^{14}$$$) and $$$n$$$ ($$$0 \leq n \leq 10^{14}$$$) — the coordinate of the grasshopper's initial position and the n... | standard output | standard input | Python 3 | Python | 900 | train_108.jsonl | 9504ff934304acf48cf21891843eeb48 | 256 megabytes | ["9\n0 1\n0 2\n10 10\n10 99\n177 13\n10000000000 987654321\n-433494437 87178291199\n1 0\n-1 1"] | PASSED | t=int(input())
for _ in range(t):
x,times=map(int,input().split())
x=int(x)
times=int(times)
r=times%4
d=times//4*4+1
for i in range(r):
if x%2==0:
x-=d
else:
x+=d
d+=1
print(x) | 1635863700 | [
"math"
] | [
0,
0,
0,
1,
0,
0,
0,
0
] | |
4 seconds | ["2\n0\n13\n1\n4\n7\n0"] | 60190de3b5ae124d3cdca86fa931f1e0 | NoteIn the first test case, the optimal array is $$$p = [1, 1, 1, 2, 2]$$$. The resulting array of values of $$$\lfloor \frac{a_i}{p_i} \rfloor$$$ is $$$[4, 5, 6, 4, 5]$$$. The cost of $$$p$$$ is $$$\max\limits_{1 \le i \le n}(\lfloor \frac{a_i}{p_i} \rfloor) - \min\limits_{1 \le i \le n}(\lfloor \frac{a_i}{p_i} \rfloo... | This is the easy version of the problem. The only difference between the versions is the constraints on $$$n$$$, $$$k$$$, $$$a_i$$$, and the sum of $$$n$$$ over all test cases. You can make hacks only if both versions of the problem are solved.Note the unusual memory limit.You are given an array of integers $$$a_1, a_2... | For each test case, print a single integer — the minimum possible cost of an array $$$p$$$ satisfying the condition above. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 3000$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_1 \le a_2 \le \ldots \le a_n \le ... | standard output | standard input | PyPy 3-64 | Python | 1,700 | train_093.jsonl | 4fb78d1af667fb77e7e02376f4ccffcb | 64 megabytes | ["7\n\n5 2\n\n4 5 6 8 11\n\n5 12\n\n4 5 6 8 11\n\n3 1\n\n2 9 15\n\n7 3\n\n2 3 5 5 6 9 10\n\n6 56\n\n54 286 527 1436 2450 2681\n\n3 95\n\n16 340 2241\n\n2 2\n\n1 3"] | PASSED | import os
import sys
from io import BytesIO, IOBase
import sys
import threading
threading.stack_size(250 * 1024 * 1024)
sys.setrecursionlimit(5000)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO... | 1658154900 | [
"number theory"
] | [
0,
0,
0,
0,
1,
0,
0,
0
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.