prob_desc_time_limit
stringclasses
21 values
prob_desc_sample_outputs
stringlengths
5
329
src_uid
stringlengths
32
32
prob_desc_notes
stringlengths
31
2.84k
prob_desc_description
stringlengths
121
3.8k
prob_desc_output_spec
stringlengths
17
1.16k
prob_desc_input_spec
stringlengths
38
2.42k
prob_desc_output_to
stringclasses
3 values
prob_desc_input_from
stringclasses
3 values
lang
stringclasses
5 values
lang_cluster
stringclasses
1 value
difficulty
int64
-1
3.5k
file_name
stringclasses
111 values
code_uid
stringlengths
32
32
prob_desc_memory_limit
stringclasses
11 values
prob_desc_sample_inputs
stringlengths
5
802
exec_outcome
stringclasses
1 value
source_code
stringlengths
29
58.4k
prob_desc_created_at
stringlengths
10
10
tags
listlengths
1
5
hidden_unit_tests
stringclasses
1 value
labels
listlengths
8
8
2 seconds
["1\n3 1", "3\n2 5\n2 6\n3 7"]
c8f63597670a7b751822f8cef01b8ba3
null
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third mem...
In the first line output one number — the minimum amount of instructions to add. Then output one of the possible variants to add these instructions into the scheme, one instruction in each line. If the solution is not unique, output any.
The first input line contains number n (2 ≤ n ≤ 105) — amount of BolgenOS community members. The second line contains n space-separated integer numbers fi (1 ≤ fi ≤ n, i ≠ fi) — index of a person, to whom calls a person with index i.
standard output
standard input
Python 3
Python
2,300
train_005.jsonl
53881e819c8eff72cb225b42a8cae123
256 megabytes
["3\n3 3 2", "7\n2 3 1 3 4 4 1"]
PASSED
#!/usr/bin/env python3 # Read data n = int(input()) f = map(int, input().split()) f = [d-1 for d in f] # Make indices 0-based # Determine in-degree of all the nodes indegree = [0 for i in range(n)] for i in range(n): indegree[f[i]] += 1 # Nodes with indegree = 0 will need to be an end-point of a new edge endpoints...
1277823600
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1 second
["12 11 4\n1063 234 1484\n25 23 8\n2221 94 2609"]
f0c22161cb5a9bc17320ccd05517f867
NoteIn the first test case:$$$$$$x \bmod y = 12 \bmod 11 = 1;$$$$$$$$$$$$y \bmod z = 11 \bmod 4 = 3;$$$$$$$$$$$$z \bmod x = 4 \bmod 12 = 4.$$$$$$
You are given three positive integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$a < b < c$$$). You have to find three positive integers $$$x$$$, $$$y$$$, $$$z$$$ such that:$$$$$$x \bmod y = a,$$$$$$ $$$$$$y \bmod z = b,$$$$$$ $$$$$$z \bmod x = c.$$$$$$Here $$$p \bmod q$$$ denotes the remainder from dividing $$$p$$$ by $$$q$$...
For each test case output three positive integers $$$x$$$, $$$y$$$, $$$z$$$ ($$$1 \le x, y, z \le 10^{18}$$$) such that $$$x \bmod y = a$$$, $$$y \bmod z = b$$$, $$$z \bmod x = c$$$. You can output any correct answer.
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) — the number of test cases. Description of the test cases follows. Each test case contains a single line with three integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \le a < b < c \le 10^8$$$).
standard output
standard input
Python 3
Python
800
train_103.jsonl
006ec88c754043b339fe309ce2efc5b1
256 megabytes
["4\n1 3 4\n127 234 421\n2 7 8\n59 94 388"]
PASSED
if __name__ == "__main__": for i in range(int(input())): abc = list(map(int, input().split(" "))) print(abc[0] + abc[1] + abc[2], abc[1] + abc[2], abc[2])
1652970900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["12", "24"]
1777c06783ecd795f855a4e9811da4b2
NoteHere is an illustration of the second example. Black triangles indicate the important tents. This example also indicates all $$$8$$$ forbidden patterns.
At the foot of Liyushan Mountain, $$$n$$$ tents will be carefully arranged to provide accommodation for those who are willing to experience the joy of approaching nature, the tranquility of the night, and the bright starry sky.The $$$i$$$-th tent is located at the point of $$$(x_i, y_i)$$$ and has a weight of $$$w_i$$$...
A single integer — the maximum sum of the weights of the remaining tents.
The first line contains a single integer $$$n$$$ ($$$1\leq n\leq 1\,000$$$), representing the number of tents. Each of the next $$$n$$$ lines contains three integers $$$x_i$$$, $$$y_i$$$ and $$$w_i$$$ ($$$-10^9\leq x_i,y_i \leq 10^9$$$, $$$1\leq w_i\leq 10^9$$$), representing the coordinate of the $$$i$$$-th tent and i...
standard output
standard input
PyPy 3
Python
3,300
train_101.jsonl
99643e44e0f6e06dd8a235de187126f2
256 megabytes
["5\n0 0 4\n0 1 5\n1 0 3\n1 1 1\n-1 1 2", "32\n2 2 1\n2 3 1\n3 2 1\n3 3 1\n2 6 1\n2 5 1\n3 6 1\n3 5 1\n2 8 1\n2 9 1\n1 8 1\n1 9 1\n2 12 1\n2 11 1\n1 12 1\n1 11 1\n6 2 1\n7 2 1\n6 3 1\n5 3 1\n6 6 1\n7 6 1\n5 5 1\n6 5 1\n6 8 1\n5 8 1\n6 9 1\n7 9 1\n6 12 1\n5 12 1\n6 11 1\n7 11 1"]
PASSED
import sys,io,os try:Z=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline except:Z=lambda:sys.stdin.readline().encode() Y=lambda:map(int,Z().split()) INF=float("inf");big=10**13 class D: def __init__(self, n): self.lvl = [0] * n self.ptr = [0] * n self.q = [0] * n self.adj...
1619188500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2.5 seconds
["YES\nYES\nNO", "NO\nYES\nNO\nYES"]
39e7083c9d16a8cb92fc93bd8185fad2
NoteIn the first sample, the array initially is {2, 6, 3}. For query 1, the first two numbers already have their gcd as 2.For query 2, we can achieve a gcd of 3 by changing the first element of the array to 3. Note that the changes made during queries of type 1 are temporary and do not get reflected in the array. After...
Bash likes playing with arrays. He has an array a1, a2, ... an of n integers. He likes to guess the greatest common divisor (gcd) of different segments of the array. Of course, sometimes the guess is not correct. However, Bash will be satisfied if his guess is almost correct.Suppose he guesses that the gcd of the eleme...
For each query of first type, output "YES" (without quotes) if Bash's guess is almost correct and "NO" (without quotes) otherwise.
The first line contains an integer n (1 ≤ n ≤ 5·105)  — the size of the array. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109)  — the elements of the array. The third line contains an integer q (1 ≤ q ≤ 4·105)  — the number of queries. The next q lines describe the queries and may have one of the fol...
standard output
standard input
PyPy 2
Python
1,900
train_050.jsonl
fe32e8eff270252594a5f5a7729d7b33
256 megabytes
["3\n2 6 3\n4\n1 1 2 2\n1 1 3 3\n2 1 9\n1 1 3 2", "5\n1 2 3 4 5\n6\n1 1 4 2\n2 3 6\n1 1 4 2\n1 1 5 2\n2 5 10\n1 1 5 2"]
PASSED
#!/usr/bin/env python2 """ This file is part of https://github.com/cheran-senthil/PyRival Copyright 2019 Cheran Senthilkumar <hello@cheran.io> """ from __future__ import division, print_function import itertools import os import sys from atexit import register from io import BytesIO class dict(dict): """dict() ...
1516462500
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
2 seconds
["27\n27\n9\n-1\n1\n6471793\n358578060125049"]
1ab174688ba76168ca047ed2b06b0670
NoteIn the first testcase Polycarp wakes up after $$$3$$$ minutes. He only rested for $$$3$$$ minutes out of $$$10$$$ minutes he needed. So after that he sets his alarm to go off in $$$6$$$ minutes and spends $$$4$$$ minutes falling asleep. Thus, he rests for $$$2$$$ more minutes, totaling in $$$3+2=5$$$ minutes of sle...
Polycarp has spent the entire day preparing problems for you. Now he has to sleep for at least $$$a$$$ minutes to feel refreshed.Polycarp can only wake up by hearing the sound of his alarm. So he has just fallen asleep and his first alarm goes off in $$$b$$$ minutes.Every time Polycarp wakes up, he decides if he wants ...
For each test case print one integer. If Polycarp never gets out of his bed then print -1. Otherwise, print the time it takes for Polycarp to get out of his bed.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. The only line of each testcase contains four integers $$$a, b, c, d$$$ ($$$1 \le a, b, c, d \le 10^9$$$) — the time Polycarp has to sleep for to feel refreshed, the time before the first alarm goes off, the time before every...
standard output
standard input
Python 3
Python
900
train_015.jsonl
7a31748579f759307c256ce127699f8a
256 megabytes
["7\n10 3 6 4\n11 3 6 4\n5 9 4 10\n6 5 2 3\n1 1 1 1\n3947465 47342 338129 123123\n234123843 13 361451236 361451000"]
PASSED
import math num_of_rows = input() for i in range(int(num_of_rows)): data_list = (list(map(int,input().split()))) a = data_list[0] b = data_list[1] c = data_list[2] d = data_list[3] if b >= a: print(b) continue elif (b < a) and (d >= c): print(-1) continue else: time_passed = b a = a - b facto...
1589707200
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2\n1\n2", "-1\n2\n2\n3"]
09eaa5ce235350bbc1a3d52441472c37
NoteIn the first example, the moves in one of the optimal answers are: for the first test case $$$s=$$$"iredppipe", $$$t=$$$"piedpiper": "iredppipe" $$$\rightarrow$$$ "iedppiper" $$$\rightarrow$$$ "piedpiper"; for the second test case $$$s=$$$"estt", $$$t=$$$"test": "estt" $$$\rightarrow$$$ "test"; for the third tes...
The problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out.You are given two strings $$$s$$$ and $$$t$$$ of the same length $$$n$$$. Their characters are numbered from $$$1$$$ to $$$n$$$ f...
For every test print minimum possible number of moves, which are needed to transform $$$s$$$ into $$$t$$$, or -1, if it is impossible to do.
The first line contains integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of independent test cases in the input. Each test case is given in three lines. The first line of a test case contains $$$n$$$ ($$$1 \le n \le 100$$$) — the length of the strings $$$s$$$ and $$$t$$$. The second line contains $$$s$$$, the third...
standard output
standard input
Python 3
Python
2,200
train_058.jsonl
cb051f006cbd9a5b71280386920ce84f
256 megabytes
["3\n9\niredppipe\npiedpiper\n4\nestt\ntest\n4\ntste\ntest", "4\n1\na\nz\n5\nadhas\ndasha\n5\naashd\ndasha\n5\naahsd\ndasha"]
PASSED
q = int(input()) for x in range(q): n = int(input()) s = str(input()) t = str(input()) ss = sorted(s) tt = sorted(t) if ss != tt: ans = -1 else: ans = 1000000000 for i in range(n): k = i for j in range(n): if k < n and s[j] =...
1569143100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["bab", "cabab", "zscoder"]
1f38c88f89786f118c65215d7df7bc9c
null
zscoder loves simple strings! A string t is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.zscoder is given a string s. He wants to change a minimum number of characters so that the string s becomes simple. Help him with this task!
Print the simple string s' — the string s after the minimal number of changes. If there are multiple solutions, you may output any of them. Note that the string s' should also consist of only lowercase English letters.
The only line contains the string s (1 ≤ |s| ≤ 2·105) — the string given to zscoder. The string s consists of only lowercase English letters.
standard output
standard input
PyPy 3
Python
1,300
train_002.jsonl
69c91a05454d60233a97f65a8882c610
256 megabytes
["aab", "caaab", "zscoder"]
PASSED
lis=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] s = list(input())+['#'] n=len(s) for i in range(1,n): if s[i]==s[i-1]: for j in lis: if j!=s[i] and j!=s[i+1]: s[i]=j break print...
1461164400
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
3 seconds
["1 2 3\n1 2 3\n5 4 3 7 2 1 6\n4 3 1 7 5 2 6\n4 3 2 1 5\n5 4 2 1 3"]
fd0e9b90f36611c28fa8aca5b4e59ae9
NoteIn the first case, $$$1$$$ $$$2$$$ $$$3$$$ is the only possible answer.In the second case, the shortest length of the LIS is $$$2$$$, and the longest length of the LIS is $$$3$$$. In the example of the maximum LIS sequence, $$$4$$$ '$$$3$$$' $$$1$$$ $$$7$$$ '$$$5$$$' $$$2$$$ '$$$6$$$' can be one of the possible LIS...
Gildong recently learned how to find the longest increasing subsequence (LIS) in $$$O(n\log{n})$$$ time for a sequence of length $$$n$$$. He wants to test himself if he can implement it correctly, but he couldn't find any online judges that would do it (even though there are actually many of them). So instead he's goin...
For each test case, print two lines with $$$n$$$ integers each. The first line is the sequence with the minimum length of the LIS, and the second line is the sequence with the maximum length of the LIS. If there are multiple answers, print any one of them. Each sequence should contain all integers between $$$1$$$ and $...
Each test contains one or more test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Each test case contains exactly one line, consisting of an integer and a string consisting of characters '&lt;' and '&gt;' only. The integer is $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$), the leng...
standard output
standard input
PyPy 3
Python
1,800
train_010.jsonl
1bf1abaf39afbb23c32404f464503df7
256 megabytes
["3\n3 &lt;&lt;\n7 &gt;&gt;&lt;&gt;&gt;&lt;\n5 &gt;&gt;&gt;&lt;"]
PASSED
import math #import math #------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writab...
1581771900
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["NO", "YES"]
2effde97cdb0e9962452a9cab63673c1
NoteIn the first sample there is no possibility to separate points, because any circle that contains both points ( - 1, 0), (1, 0) also contains at least one point from the set (0,  - 1), (0, 1), and vice-versa: any circle that contains both points (0,  - 1), (0, 1) also contains at least one point from the set ( - 1, ...
Berlanders like to eat cones after a hard day. Misha Square and Sasha Circle are local authorities of Berland. Each of them controls its points of cone trade. Misha has n points, Sasha — m. Since their subordinates constantly had conflicts with each other, they decided to build a fence in the form of a circle, so that ...
The only output line should contain either word "YES" without quotes in case it is possible to build a such fence or word "NO" in the other case.
The first line contains two integers n and m (1 ≤ n, m ≤ 10000), numbers of Misha's and Sasha's trade points respectively. The next n lines contains pairs of space-separated integers Mx, My ( - 104 ≤ Mx, My ≤ 104), coordinates of Misha's trade points. The next m lines contains pairs of space-separated integers Sx, Sy (...
standard output
standard input
Python 3
Python
2,700
train_003.jsonl
ee51a5475e253551ea21c373a3903215
256 megabytes
["2 2\n-1 0\n1 0\n0 -1\n0 1", "4 4\n1 0\n0 1\n-1 0\n0 -1\n1 1\n-1 1\n-1 -1\n1 -1"]
PASSED
nm = input() nOm = nm.split() n = int(nOm[0]) m = int(nOm[1]) a = b = [] for i in range(0, n): a.append(input()) for i in range(0, m): b.append(input()) if(n == 2 and m == 2 and a[0] == '-1 0') or (n == 2 and m == 3 and a[0] == '-1 0') or (n == 3 and m == 3 and a[0] == '-3 -4') or ( n == 1000 and m == 1000 and a[...
1433595600
[ "geometry", "math" ]
[ 0, 1, 0, 1, 0, 0, 0, 0 ]
2 seconds
["0", "1\n3 1 3 7"]
1c1641aeb850e5b20a4054e839cc22e4
null
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way r...
Output the answer, number t — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output t lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between ...
The first line contains integer n (2 ≤ n ≤ 1000) — amount of cities in Berland and neighboring countries. Next n - 1 lines contain the description of roads. Each road is described by two space-separated integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — pair of cities, which the road connects. It can't be more than one road b...
standard output
standard input
Python 2
Python
1,900
train_003.jsonl
618716eb8276c172ec96352465751b7a
256 megabytes
["2\n1 2", "7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7"]
PASSED
n=int(raw_input()) st=[0]*n for i in xrange(n): st[i]=i def find_st(i): if st[i]==i: return i st[i]=find_st(st[i]) return st[i] def union_st(i,j): i=find_st(i) j=find_st(j) if i==j: return False st[i]=j return True x...
1280761200
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1.5 seconds
["1", "2"]
23c8f5922c7a1cdb82d229eb9938f3ee
NoteIn the first test case, $$$f(x)$$$ is $$$2x^2 + x + 1$$$ and $$$g(x)$$$ is $$$x + 2$$$, their product $$$h(x)$$$ being $$$2x^3 + 5x^2 + 3x + 2$$$, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.In the second test case, $$$f(x)$$$ is $$$x + 2$$$ and $$$g(x)$$$ is $$$x + 3$$$, their product $$$h(x)...
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.You are given two polynomials $$$f(x) = a_0 + a_1x + \dots + a_{n-1}x^{n-1}$$$ and $$$g(x) = b_...
Print a single integer $$$t$$$ ($$$0\le t \le n+m-2$$$)  — the appropriate power of $$$x$$$ in $$$h(x)$$$ whose coefficient isn't divisible by the given prime $$$p$$$. If there are multiple powers of $$$x$$$ that satisfy the condition, print any.
The first line of the input contains three integers, $$$n$$$, $$$m$$$ and $$$p$$$ ($$$1 \leq n, m \leq 10^6, 2 \leq p \leq 10^9$$$),  — $$$n$$$ and $$$m$$$ are the number of terms in $$$f(x)$$$ and $$$g(x)$$$ respectively (one more than the degrees of the respective polynomials) and $$$p$$$ is the given prime number. I...
standard output
standard input
PyPy 3
Python
1,800
train_004.jsonl
8e4022415c82b6c4f3106b48db45cd73
256 megabytes
["3 2 2\n1 1 2\n2 1", "2 2 999999937\n2 1\n3 1"]
PASSED
import sys input = sys.stdin.buffer.readline n, m, p = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans1 = 0 ans2 = 0 for i, num in enumerate(a): if num % p != 0: ans1 = i break for i, num in enumerate(b): if num % p != 0: ans2 =...
1583332500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["2", "1", "33", "4"]
3b2d0d396649a200a73faf1b930ef611
NoteIn the first example, an example set of optimal cuts on the number is 3|1|21.In the second example, you do not need to make any cuts. The specified number 6 forms one number that is divisible by $$$3$$$.In the third example, cuts must be made between each pair of digits. As a result, Polycarp gets one digit 1 and $...
Polycarp likes numbers that are divisible by 3.He has a huge number $$$s$$$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $$$3$$$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $$$m$$$ such cuts, there will be $$$m+1$$...
Print the maximum number of numbers divisible by $$$3$$$ that Polycarp can get by making vertical cuts in the given number $$$s$$$.
The first line of the input contains a positive integer $$$s$$$. The number of digits of the number $$$s$$$ is between $$$1$$$ and $$$2\cdot10^5$$$, inclusive. The first (leftmost) digit is not equal to 0.
standard output
standard input
PyPy 3
Python
1,500
train_003.jsonl
e29069371d94680350803d2319e718ff
256 megabytes
["3121", "6", "1000000000000000000000000000000000", "201920181"]
PASSED
import sys sys.setrecursionlimit(10000) # default is 1000 in python # increase stack size as well (for hackerrank) # import resource # resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY)) # t = int(input()) t = 1 for _ in range(t): s = input() no = '' count = 0 for i in s...
1531150500
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
2 seconds
["16"]
d2227a4ed6299626c2906962f91b066a
NotePicture for the example test: The coordinate grid is painted grey, the coordinates axes are painted black, the cows are painted red and the sought route is painted green.
The Happy Farm 5 creators decided to invent the mechanism of cow grazing. The cows in the game are very slow and they move very slowly, it can even be considered that they stand still. However, carnivores should always be chased off them. For that a young player Vasya decided to make the shepherd run round the cows alo...
Print the single number — the minimum number of moves in the sought path.
The first line contains an integer N which represents the number of cows in the herd (1 ≤ N ≤ 105). Each of the next N lines contains two integers Xi and Yi which represent the coordinates of one cow of (|Xi|, |Yi| ≤ 106). Several cows can stand on one point.
standard output
standard input
Python 3
Python
2,000
train_026.jsonl
75e96b07b19bb3bc84a08643c0781aa3
256 megabytes
["4\n1 1\n5 1\n5 3\n1 3"]
PASSED
import math n = int(input()) l = [] for i in range(n): l.append(tuple(list(map(int, input().split(" "))))) l = list(set(l)) n = len(l) pmin = 0 for i in range(1, n): if(l[i][1] < l[pmin][1] or (l[i][1] == l[pmin][1] and l[i][0] < l[pmin][0])): pmin = i l[pmin], l[0] = l[0], l[pmin] def orientation(...
1292862000
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
3 seconds
["Yes\nYes\nNo"]
6bd41042c6a442765cd93c73d55f6189
null
In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $$$s$$$ starting from the $$$l$$$-th character and ending with the $$$r$$$-th c...
For each query, print either YES if $$$t[l_1 \dots l_1 + len - 1]$$$ is reachable from $$$t[l_2 \dots l_2 + len - 1]$$$, or NO otherwise. You may print each letter in any register.
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of string $$$t$$$. The second line contains one string $$$t$$$ ($$$|t| = n$$$). Each character of $$$t$$$ is either 0 or 1. The third line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Then...
standard output
standard input
PyPy 3
Python
2,500
train_057.jsonl
6620748f5f350641c425854e90f8d0a8
256 megabytes
["5\n11011\n3\n1 3 3\n1 4 2\n1 2 3"]
PASSED
import sys input = sys.stdin.readline n=int(input()) t=input().strip() q=int(input()) ZEROS=[0]*n ZERO_ONE=[] ONECOUNT=[0]*n ind=0 count=0 for i in range(n): ZEROS[i]=ind if t[i]=="0": ind+=1 ONECOUNT[i]=count%2 ZERO_ONE.append(count%2) count=0 else: count+=1 ...
1583068500
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["A B B B", "D C B A D C B D C D"]
4770fb8fb5c0663bef38ae0385a2d8c0
NoteIn the first example, for any two officers of rank 'B', an officer with rank 'A' will be on the path between them. So it is a valid solution.
Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has n cities connected by n - 1 undirected roads, and for any two cities there always exists a path between them.Fox Ciel needs to assign an officer to each city. Each officer has a rank — a letter from 'A' to 'Z'. So there will be 26 differe...
If there is a valid plane, output n space-separated characters in a line — i-th character is the rank of officer in the city with number i. Otherwise output "Impossible!".
The first line contains an integer n (2 ≤ n ≤ 105) — the number of cities in Tree Land. Each of the following n - 1 lines contains two integers a and b (1 ≤ a, b ≤ n, a ≠ b) — they mean that there will be an undirected road between a and b. Consider all the cities are numbered from 1 to n. It guaranteed that the given ...
standard output
standard input
PyPy 2
Python
2,100
train_041.jsonl
8743e1c207cc7746fd0d53294c583399
256 megabytes
["4\n1 2\n1 3\n1 4", "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10"]
PASSED
import sys range = xrange def decomp(coupl, root = 0): n = len(coupl) visible_labels = [0] * n bfs = [root] for node in bfs: for nei in coupl[node]: coupl[nei].remove(node) bfs += coupl[node] for node in reversed(bfs): seen = seen_twice = 0 for ne...
1372433400
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["1", "-1", "0", "2"]
ff0d972460443cc13156ede0d4a16f52
NoteIn the first example, for $$$c'$$$ equal to "katie" $$$f(c', s) = 1$$$ and $$$f(c', t) = 0$$$, which makes $$$f(c', s) - f(c', t) = 1$$$ which is the largest possible.In the second example, the only $$$c'$$$ conforming to the given $$$c$$$ is "caat". The corresponding $$$f(c', s) - f(c', t) = 1 - 2 = -1$$$.In the t...
During a normal walk in the forest, Katie has stumbled upon a mysterious code! However, the mysterious code had some characters unreadable. She has written down this code as a string $$$c$$$ consisting of lowercase English characters and asterisks ("*"), where each of the asterisks denotes an unreadable character. Exci...
Print a single integer — the largest possible value of $$$f(c', s) - f(c', t)$$$ of the recovered code.
The first line contains string $$$c$$$ ($$$1 \leq |c| \leq 1000$$$) — the mysterious code . It is guaranteed that $$$c$$$ consists of lowercase English characters and asterisks "*" only. The second and third line contain strings $$$s$$$ and $$$t$$$ respectively ($$$1 \leq |s|, |t| \leq 50$$$, $$$s \neq t$$$). It is gua...
standard output
standard input
PyPy 2
Python
2,100
train_021.jsonl
2b98316e35051370b7bf60cbf75a63cf
256 megabytes
["*****\nkatie\nshiro", "caat\ncaat\na", "*a*\nbba\nb", "***\ncc\nz"]
PASSED
import sys range = xrange input = raw_input def partial(s): g, pi = 0, [0] * len(s) for i in range(1, len(s)): while g and (s[g] != s[i]): g = pi[g - 1] pi[i] = g = g + (s[g] == s[i]) return pi A = input() B = input() C = input() A = [ord(c) - 97 if c != '*' else -1 for c in ...
1557414300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["2\n0 4", "1\n0"]
c9c3fabde66856667c338d71e17f6418
NoteConsider the first test case. It uses the octal number system.If you take one banknote with the value of $$$12$$$, you will get $$$14_8$$$ in octal system. The last digit is $$$4_8$$$.If you take one banknote with the value of $$$12$$$ and one banknote with the value of $$$20$$$, the total value will be $$$32$$$. I...
Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars.There are $...
On the first line output the number of values $$$d$$$ for which Natasha can make the Martians happy. In the second line, output all these values in increasing order. Print all numbers in decimal notation.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100\,000$$$, $$$2 \le k \le 100\,000$$$) — the number of denominations of banknotes and the base of the number system on Mars. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — denominations of bank...
standard output
standard input
Python 2
Python
1,800
train_005.jsonl
b83c6c548f9c92f8ad5822c957f70230
256 megabytes
["2 8\n12 20", "3 10\n10 20 30"]
PASSED
from fractions import gcd n,k = [int(x) for x in raw_input().split()] a = [int(x)%k for x in raw_input().split()] g = reduce(gcd, a) if g == 0: print "1\n0" else: g = gcd(g,k) print k/g print " ".join([str(i) for i in range(0,k,g)])
1532617500
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
1 second
["1\n2\n1073741824"]
a896ba035e56dc707f8123b1e2f2b11c
NoteLet's define the bitwise exclusive OR (XOR) operation. Given two integers $$$x$$$ and $$$y$$$, consider their binary representations (possibly with leading zeroes): $$$x_k \dots x_2 x_1 x_0$$$ and $$$y_k \dots y_2 y_1 y_0$$$. Here, $$$x_i$$$ is the $$$i$$$-th bit of the number $$$x$$$ and $$$y_i$$$ is the $$$i$$$-t...
Colossal! — exclaimed Hawk-nose. — A programmer! That's exactly what we are looking for.Arkadi and Boris Strugatsky. Monday starts on SaturdayReading the book "Equations of Mathematical Magic" Roman Oira-Oira and Cristobal Junta found an interesting equation: $$$a - (a \oplus x) - x = 0$$$ for some given $$$a$$$, where...
For each value of $$$a$$$ print exactly one integer — the number of non-negative solutions of the equation for the given value of the parameter. Print answers in the same order as values of $$$a$$$ appear in the input. One can show that the number of solutions is always finite.
Each test contains several possible values of $$$a$$$ and your task is to find the number of equation's solution for each of them. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of these values. The following $$$t$$$ lines contain the values of parameter $$$a$$$, each value is an integ...
standard output
standard input
Python 3
Python
1,200
train_010.jsonl
49d3cec47f32480abcd7deeea67fad4d
256 megabytes
["3\n0\n2\n1073741823"]
PASSED
def solve(a): binary = f"{a:b}" return 2 ** binary.count("1") n = int(input()) for i in range(n): a = int(input()) print(solve(a))
1539511500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["YES\nYES\nNO\nYES\nYES"]
e8e32f179080f9d12bb1e4df303ea124
NoteIn the first test case, the sequence $$$b = [-9, \, 2, \, 1, \, 3, \, -2]$$$ satisfies the property. Indeed, the following holds: $$$a_1 = 4 = 2 - (-2) = b_2 - b_5$$$; $$$a_2 = -7 = -9 - (-2) = b_1 - b_5$$$; $$$a_3 = -1 = 1 - 2 = b_3 - b_2$$$; $$$a_4 = 5 = 3 - (-2) = b_4 - b_5$$$; $$$a_5 = 10 = 1 - (-9) = b_3...
You are given a sequence of $$$n$$$ integers $$$a_1, \, a_2, \, \dots, \, a_n$$$.Does there exist a sequence of $$$n$$$ integers $$$b_1, \, b_2, \, \dots, \, b_n$$$ such that the following property holds? For each $$$1 \le i \le n$$$, there exist two (not necessarily distinct) indices $$$j$$$ and $$$k$$$ ($$$1 \le j, ...
For each test case, output a line containing YES if a sequence $$$b_1, \, \dots, \, b_n$$$ satisfying the required property exists, and NO otherwise.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10$$$). The second line of each test case contains the $$$n$$$ integers $$$a_1, \, \dots, \, a_n$$$ ($$$-10^5 ...
standard output
standard input
Python 3
Python
1,800
train_098.jsonl
fe927a5a44f589d0850aff74930b39e4
256 megabytes
["5\n5\n4 -7 -1 5 10\n1\n0\n3\n1 10 100\n4\n-3 2 10 2\n9\n25 -171 250 174 152 242 100 -205 -258"]
PASSED
from itertools import* for s in[*open(0)][2::2]:a=*map(int,s.split()),;n=len(a);print('YNEOS'[len({sum(c)for i in range(n+1)for c in combinations(a,i)})>>n::2])
1627223700
[ "math", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
1 second
["8", "27", "73741817", "1"]
4867d014809bfc1d90672b32ecf43b43
NoteIn the first sample . Thus, the answer to the problem is 8.In the second sample, . The answer to the problem is 27, as 351 = 13·27, 729 = 27·27.In the third sample the answer to the problem is 1073741824 mod 1000000007 = 73741817.In the fourth sample . Thus, the answer to the problem is 1.
Simon has a prime number x and an array of non-negative integers a1, a2, ..., an.Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number t equals xa1 + a2 + ... + an. Now Simon wants to r...
Print a single number — the answer to the problem modulo 1000000007 (109 + 7).
The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 109).
standard output
standard input
Python 2
Python
1,900
train_021.jsonl
e662cabc90e2303974a4592713c988b3
256 megabytes
["2 2\n2 2", "3 3\n1 2 3", "2 2\n29 29", "4 5\n0 0 0 0"]
PASSED
def matome_num(): global num ans = num[0][0] for i in range(len(num)-1): if num[i][1] == num[i+1][1]: ans += num[i+1][0] else: num = [(ans,num[0][1])] + num[i+1:] return num = [(ans,num[0][1])] n,x = map(int,raw_input().split()) old_num = map(int,ra...
1383379200
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
3 seconds
["4", "6", "1", "-1", "-1", "382480067"]
eddb90c1f26d9c44544617aeff56c782
NoteIn the first sample, we have $$$f_4 = f_3^2 \cdot f_2^3 \cdot f_1^5$$$. Therefore, applying $$$f_3 = 4$$$, we have $$$f_4 = 16$$$. Note that there can be multiple answers.In the third sample, applying $$$f_7 = 1$$$ makes $$$f_{23333} = 1$$$.In the fourth sample, no such $$$f_1$$$ makes $$$f_{88888} = 66666$$$. Ther...
Lunar New Year is approaching, and Bob received a gift from his friend recently — a recursive sequence! He loves this sequence very much and wants to play with it.Let $$$f_1, f_2, \ldots, f_i, \ldots$$$ be an infinite sequence of positive integers. Bob knows that for $$$i &gt; k$$$, $$$f_i$$$ can be obtained by the fol...
Output a possible value of $$$f_k$$$, where $$$f_k$$$ is a positive integer satisfying $$$1 \leq f_k &lt; p$$$. If there are multiple answers, print any of them. If no such $$$f_k$$$ makes $$$f_n = m$$$, output $$$-1$$$ instead. It is easy to show that if there are some possible values of $$$f_k$$$, there must be at le...
The first line contains a positive integer $$$k$$$ ($$$1 \leq k \leq 100$$$), denoting the length of the sequence $$$b_1, b_2, \ldots, b_k$$$. The second line contains $$$k$$$ positive integers $$$b_1, b_2, \ldots, b_k$$$ ($$$1 \leq b_i &lt; p$$$). The third line contains two positive integers $$$n$$$ and $$$m$$$ ($$$k...
standard output
standard input
PyPy 2
Python
2,400
train_025.jsonl
90200b59525549a2e2838114e4aea5e4
256 megabytes
["3\n2 3 5\n4 16", "5\n4 7 1 5 6\n7 14187219", "8\n2 3 5 6 1 7 9 10\n23333 1", "1\n2\n88888 66666", "3\n998244352 998244352 998244352\n4 2", "10\n283 463 213 777 346 201 463 283 102 999\n2333333 6263423"]
PASSED
from __future__ import division from sys import stdin, stdout from math import sqrt, ceil pow(1, 2, 3) def write(x): stdout.write(str(x) + "\n") def mmul(a, b, p): assert len(a[0]) == len(b) n = len(a) m = len(a[0]) k = len(b[0]) res = [[0] * k for _ in xrange(n)] for r in xrange(n): ...
1548938100
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["1 2 2 1 \n1 3 3 1 1"]
1fea137016452340beb13dd7518f00c9
null
It is the hard version of the problem. The only difference is that in this version $$$3 \le k \le n$$$.You are given a positive integer $$$n$$$. Find $$$k$$$ positive integers $$$a_1, a_2, \ldots, a_k$$$, such that: $$$a_1 + a_2 + \ldots + a_k = n$$$ $$$LCM(a_1, a_2, \ldots, a_k) \le \frac{n}{2}$$$ Here $$$LCM$$$ is ...
For each test case print $$$k$$$ positive integers $$$a_1, a_2, \ldots, a_k$$$, for which all conditions are satisfied.
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 10^4)$$$  — the number of test cases. The only line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$3 \le n \le 10^9$$$, $$$3 \le k \le n$$$). It is guaranteed that the sum of $$$k$$$ over all test cases does not exceed $$$10^5$$$.
standard output
standard input
PyPy 3-64
Python
1,600
train_087.jsonl
e5624b2c2df43f8561ce7265c0d181cc
256 megabytes
["2\n6 4\n9 5"]
PASSED
#import io, os #input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline t = int(input()) for _ in range(t): n, k = map(int,input().split()) final = [] while k > 3: n -= 1 k -= 1 final.append(1) if n % 2 == 1: final.append(n//2) final.append(1) final.append(n...
1615991700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["3.7677669529663684 3.7677669529663684 3.914213562373095", "5.0 5.0 10.0"]
29d4ca13888c0e172dde315b66380fe5
null
Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access point can be accessed within a range of r meters (this range can be chosen by...
Print three space-separated numbers xap, yap, r where (xap, yap) is the position which Fifa chose for the access point and r is the radius of its range. Your answer will be considered correct if the radius does not differ from optimal more than 10 - 6 absolutely or relatively, and also the radius you printed can be ch...
The single line of the input contains 5 space-separated integers R, x1, y1, x2, y2 (1 ≤ R ≤ 105, |x1|, |y1|, |x2|, |y2| ≤ 105).
standard output
standard input
Python 3
Python
1,600
train_013.jsonl
3733e5cecfcacee785c6796bf5d523f2
256 megabytes
["5 3 3 1 1", "10 5 5 5 15"]
PASSED
R,x1,y1,x2,y2=map(int,input().split()) s=((x1-x2)**2+(y1-y2)**2)**(0.5) sin=0 cos=1 def dist(x1,x2,y1,y2): return ((x1-x2)**2+(y1-y2)**2)**(0.5) if (s>R): print(x1,y1,R) else: r=(s+R)/2 if s!=0: sin=((y2-y1)/s) cos=((x2-x1)/s) xpos,ypos=x2+r*cos,y2+r*sin xneg,yneg=x2-r*cos,y2-r*...
1519058100
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
1 second
["1 2 3", "199633", "725081944 922153789 481174947 427448285 516570428 509717938 855104873 280317429 281091129 1050390365"]
c2e099580cd4c5d09d5d63921ad95561
NoteIf we let $$$a = [1,2,3]$$$, then $$$b$$$ will be: $$$\bf{0}$$$$$$\bf{1}$$$$$$\bf{2}$$$$$$\bf{3}$$$$$$\bf{0}$$$$$$1$$$$$$3$$$$$$0$$$$$$\bf{0}$$$$$$1$$$$$$2$$$$$$2$$$$$$\bf{0}$$$$$$1$$$$$$3$$$$$$1$$$ The values of $$$b_{1,n}, b_{2,n}, \ldots, b_{n,n}$$$ generated are $$$[0,2,1]$$$ which is consistent with what the a...
My orzlers, we can optimize this problem from $$$O(S^3)$$$ to $$$O\left(T^\frac{5}{9}\right)$$$!— Spyofgame, founder of Orzlim religionA long time ago, Spyofgame invented the famous array $$$a$$$ ($$$1$$$-indexed) of length $$$n$$$ that contains information about the world and life. After that, he decided to convert it...
If some array $$$a$$$ is consistent with the information, print a line containing $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$. If there are multiple solutions, output any. If such an array does not exist, output $$$-1$$$ instead.
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 5 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$b_{1,n}, b_{2,n}, \ldots, b_{n,n}$$$ ($$$0 \leq b_{i,n} &lt; 2^{30}$$$).
standard output
standard input
PyPy 3
Python
2,900
train_088.jsonl
0db5b254907f8c96983714fdc7cfe15f
256 megabytes
["3\n0 2 1", "1\n199633", "10\n346484077 532933626 858787727 369947090 299437981 416813461 865836801 141384800 157794568 691345607"]
PASSED
a=[*map(int,[*open(0)][1].split())] for k in 0,1: for i in range(19): z=1<<i for j in range(len(a)): if j&z:a[j-k*z]^=a[j+k*z-z] print(*reversed(a))
1659796500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1.17809724510", "1.07823651333"]
36cf5a28f09a39afc1e6d1e788af71ee
NoteIn the first example, the polygon $$$\mathcal P$$$ can be visualised on the Cartesian Plane as:
Mainak has a convex polygon $$$\mathcal P$$$ with $$$n$$$ vertices labelled as $$$A_1, A_2, \ldots, A_n$$$ in a counter-clockwise fashion. The coordinates of the $$$i$$$-th point $$$A_i$$$ are given by $$$(x_i, y_i)$$$, where $$$x_i$$$ and $$$y_i$$$ are both integers.Further, it is known that the interior angle at $$$A...
Print the area of the region coloured in $$$\color{red}{\text{red}}$$$. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-4}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le ...
The first line contains an integer $$$n$$$ ($$$4 \le n \le 5000$$$) — the number of vertices of a polygon $$$\mathcal P$$$. The $$$i$$$-th line of the next $$$n$$$ lines contain two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^9 \le x_i, y_i \le 10^9$$$) — the coordinates of $$$A_i$$$. Additional constraint on the input: T...
standard output
standard input
Python 3
Python
3,500
train_106.jsonl
a9ea9cd076fbaa4b70dde693a3728409
256 megabytes
["4\n4 5\n4 1\n7 1\n7 5", "5\n-3 3\n3 1\n4 2\n-1 9\n-2 9"]
PASSED
import math pi = 3.14159265358979323846264338327950288419716939937510 eps, sq2 = 1e-13, math.sqrt(2) x, y = [], [] n = 0 def binary_find(la, lb, ra, rb, cy, fy, alpha_1, alpha_2, ab): while math.fabs(cy - fy) > eps: mid_y = cy / 2.0 + fy / 2.0 la = lb = 0.0 ra, rb = pi - alpha...
1662474900
[ "geometry", "math" ]
[ 0, 1, 0, 1, 0, 0, 0, 0 ]
1 second
["NO", "YES"]
43bb8fec6b0636d88ce30f23b61be39f
NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in h...
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
The first line of input contains string s containing lowercase English letters (1 ≤ |s| ≤ 1000). The second line contains integer k (1 ≤ k ≤ 1000).
standard output
standard input
Python 2
Python
1,100
train_000.jsonl
7956bc4c65a48358e90bccdd9bd52207
256 megabytes
["saba\n2", "saddastavvat\n2"]
PASSED
st = str(raw_input()) n = int(raw_input()) size = len(st)/n def is_palindrome(seq): return seq == seq[::-1] if n <= len(st): cnt = 0 for i in range(0,len(st),size): if is_palindrome(st[i:size+i].lower()): cnt += 1 else: cnt -=1 if cnt == n: print "YES" else: print "NO" else: ...
1432658100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["2", "1"]
ccdd28603921a99fa5f1f75d42f479a9
null
Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a0 + a1x1 + ... + anxn. Numbers ai are called coefficients of a polynomial, non-negative integer n is called a degree of a polynomial.Vasya has made a bet with his friends that he ...
If there is an infinite number of such polynomials, then print "inf" without quotes, otherwise print the reminder of an answer modulo 109 + 7.
The input contains three integer positive numbers no greater than 1018.
standard output
standard input
Python 2
Python
2,800
train_057.jsonl
9895a1458ffdca40def4fe20a95142be
256 megabytes
["2 2 2", "2 3 3"]
PASSED
def dfs(t, a, b, s1, s2): cnt = 0 is_inf = False if s1 == s2: if s1 < t or s2 < a: return is_inf, 1 else: cnt += 1 if s2 >= a and s1 >= t: a0 = s2 % a if (s1-a0) % t == 0 and (s2-a0) % a == 0: ns1, ns2 = (s1-a0)/t, (s2-a0)/a ...
1417618800
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
0.5 seconds
["-10.000000000000000\n-20.000000000000000"]
2d4ad39d42b349765435b351897403da
null
The Department of economic development of IT City created a model of city development till year 2100.To prepare report about growth perspectives it is required to get growth estimates from the model.To get the growth estimates it is required to solve a quadratic equation. Since the Department of economic development of...
In the first line output the greater of the equation roots, in the second line output the smaller one. Absolute or relative error should not be greater than 10 - 6.
The only line of the input contains three integers a, b, c ( - 1000 ≤ a, b, c ≤ 1000) — the coefficients of ax2 + bx + c = 0 equation.
standard output
standard input
Python 2
Python
1,300
train_025.jsonl
5b30fdd85360f4217bba7c72b2b204f1
64 megabytes
["1 30 200"]
PASSED
a,b,c=map(float,raw_input().split()) q=(b*b-4*a*c)**0.5 x=(-b+q)/(2*a) y=(-b-q)/(2*a) print max(x,y) print min(x,y)
1455807600
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["26", "20"]
f9fbb45e45d3040e3be19a39ea8faa1f
NoteThe following pictures show optimal trees for example tests. The squared distance in the first example equals $$$5 \cdot 5 + 1 \cdot 1 = 26$$$, and in the second example $$$4 \cdot 4 + 2 \cdot 2 = 20$$$.
Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them.The tree looks like a polyline on the plane, consisting of ...
Print one integer — the square of the largest possible distance from $$$(0, 0)$$$ to the tree end.
The first line contains an integer $$$n$$$ ($$$1 \le n \le 100\,000$$$) — the number of sticks Alexey got as a present. The second line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$) — the lengths of the sticks.
standard output
standard input
PyPy 3
Python
900
train_006.jsonl
b041efd202160976590ab0fec7c53e3b
512 megabytes
["3\n1 2 3", "4\n1 1 2 2"]
PASSED
n = int(input()) line = input().split() arr = [] for i in range(n): arr.append(int(line[i])) arr.sort(reverse = True) import math x = sum(arr[:math.ceil(n/2)]) # print(x) y = sum(arr[math.ceil(n/2):]) # print(y) print((x**2) + (y**2))
1571562300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["11", "79"]
5c12573b3964ee30af0349c11c0ced3b
NoteIn the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:1. Move to floor 5: takes 2 seconds.2. Pick up passenger 3.3. Move to floor 3: takes 2 seconds.4. Wait for passenger 2 to arrive: takes 4 seconds.5. Pick up passenger 2.6. Go to floor 2: takes 1 seco...
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to s and elevator initially starts on floor s...
Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
The first line of input contains two integers n and s (1 ≤ n ≤ 100, 1 ≤ s ≤ 1000) — the number of passengers and the number of the top floor respectively. The next n lines each contain two space-separated integers fi and ti (1 ≤ fi ≤ s, 1 ≤ ti ≤ 1000) — the floor and the time of arrival in seconds for the passenger num...
standard output
standard input
Python 3
Python
1,000
train_014.jsonl
99848bec05616f20b7793b3efe22c9ba
256 megabytes
["3 7\n2 1\n3 8\n5 2", "5 10\n2 77\n3 33\n8 21\n9 12\n10 64"]
PASSED
R = lambda : map(int, input().split()) n,s=R() m = max([sum(R()) for _ in range(n)]) print(max(m,s))
1450888500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2\n5\n4\n333\n0"]
d9fd10700cb122b148202a664e7f7689
null
You are given two positive integers $$$a$$$ and $$$b$$$. In one move you can increase $$$a$$$ by $$$1$$$ (replace $$$a$$$ with $$$a+1$$$). Your task is to find the minimum number of moves you need to do in order to make $$$a$$$ divisible by $$$b$$$. It is possible, that you have to make $$$0$$$ moves, as $$$a$$$ is alr...
For each test case print the answer — the minimum number of moves you need to do in order to make $$$a$$$ divisible by $$$b$$$.
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9$$$).
standard output
standard input
PyPy 3
Python
800
train_005.jsonl
c170a86b12cceab893d83e8bd1ee2161
256 megabytes
["5\n10 4\n13 9\n100 13\n123 456\n92 46"]
PASSED
for i in range(int(input())) : a1, a2 = map(int, input().split()) if a1%a2 == 0 : print(0) else : tempmin = a1//a2+1 ans = a2*tempmin -a1 print(ans)
1585233300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["YES\nNO\nYES\nNO\nYES", "YES\nNO\nYES\nYES"]
65fef0995daf35d7a60b3680c158a683
null
This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected graph of $$$n$$$ vertices and $$$n-1$$$ edges that does not contain cycles.He cal...
Output $$$q$$$ lines, each of which contains the answer to the corresponding query. As an answer, output "YES" if the set is passable, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
The first line of input contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — number of vertices. Following $$$n - 1$$$ lines a description of the tree.. Each line contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$) — indices of vertices connected by an edge. Following line ...
standard output
standard input
PyPy 3-64
Python
2,000
train_089.jsonl
d42021c4f8979d555aab4b0ad95fd812
256 megabytes
["5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1"]
PASSED
def dfs(root): dis=[0]*n parent_list = [-1] * n stops_left=[len(tree[node])-1 for node in range(n)] stops_left[root]=-1 # you always have to stop when you reach the root eular_path=[] stack=[root] node_mapping=[-1]*n count=0 while stack: node=stack.pop() no...
1657463700
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["acab", "kbub", "-1"]
0550004c6c7a386b8e7d214e71990572
NoteIn the first example s1 is obtained by swapping the second and the fourth character in acab, s2 is obtained by swapping the first and the second character, and to get s3, we swap the third and the fourth character.In the second example s1 is obtained by swapping the third and the fourth character in kbub, s2 — by s...
We had a string s consisting of n lowercase Latin letters. We made k copies of this string, thus obtaining k identical strings s1, s2, ..., sk. After that, in each of these strings we swapped exactly two characters (the characters we swapped could be identical, but they had different indices in the string).You are give...
Print any suitable string s, or -1 if such string doesn't exist.
The first line contains two integers k and n (1 ≤ k ≤ 2500, 2 ≤ n ≤ 5000, k · n ≤ 5000) — the number of strings we obtained, and the length of each of these strings. Next k lines contain the strings s1, s2, ..., sk, each consisting of exactly n lowercase Latin letters.
standard output
standard input
PyPy 2
Python
2,200
train_023.jsonl
41b2fabd7e13cff643460303e5cf4441
256 megabytes
["3 4\nabac\ncaab\nacba", "3 4\nkbbu\nkbub\nubkb", "5 4\nabcd\ndcba\nacbd\ndbca\nzzzz"]
PASSED
import sys k, n = map(int, raw_input().split()) arr = [] cands = None """ for _ in range(k): s = str(raw_input()) assert len(s) == n diffs = set() for i in range(n): for j in range(i+1, n): swapped = list(s) swapped[i], swapped[j] = swapped[j], swapped[i] swap...
1513091100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["NO\nYES\nYES\nYES"]
1305b44c5c588221bc991c696a492fe7
NoteIn the first test case, you can't do any operations.In the second test case, the array is already sorted.In the third test case, you can do the operations as follows: $$$[5,1,2,3,4]$$$, $$$swap(a_1,a_3)$$$ $$$[2,1,5,3,4]$$$, $$$swap(a_2,a_5)$$$ $$$[2,4,5,3,1]$$$, $$$swap(a_2,a_4)$$$ $$$[2,3,5,4,1]$$$, $$$swap(...
Hemose was shopping with his friends Samez, AhmedZ, AshrafEzz, TheSawan and O_E in Germany. As you know, Hemose and his friends are problem solvers, so they are very clever. Therefore, they will go to all discount markets in Germany.Hemose has an array of $$$n$$$ integers. He wants Samez to sort the array in the non-de...
For each test case, you should output a single string. If Samez can sort the array in non-decreasing order using the operation written above, output "YES" (without quotes). Otherwise, output "NO" (without quotes). You can print each letter of "YES" and "NO" in any case (upper or lower).
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \leq t \leq 10^5)$$$. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ $$$(1 \leq x \leq n \leq 10^5)$$$. The second line of each test case contains $$$...
standard output
standard input
Python 3
Python
1,200
train_106.jsonl
b659aa7241b52cef562cfaa485d48c75
256 megabytes
["4\n3 3\n3 2 1\n4 3\n1 2 3 4\n5 2\n5 1 2 3 4\n5 4\n1 2 3 4 4"]
PASSED
from sys import stdin input() ans = [] for line in stdin: n, x = map(int, line.split()) a = list(map(int, input().split())) if 2*x <= n: ans.append('yes') continue b = a[n-x:x] a.sort() if b == a[n - x : x]: ans.append('yes') else: ans.append('NO...
1633271700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["665496237\n1", "0\n8\n665496236"]
ccf4ac6b61b48604b7d9f49b7daaeb0f
null
You are playing a computer game. In this game, you have to fight $$$n$$$ monsters.To defend from monsters, you need a shield. Each shield has two parameters: its current durability $$$a$$$ and its defence rating $$$b$$$. Each monster has only one parameter: its strength $$$d$$$.When you fight a monster with strength $$...
Print $$$m$$$ integers, where the $$$i$$$-th integer represents the expected damage you receive with the $$$i$$$-th shield as follows: it can be proven that, for each shield, the expected damage is an irreducible fraction $$$\dfrac{x}{y}$$$, where $$$y$$$ is coprime with $$$998244353$$$. You have to print the value of ...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the number of monsters and the number of shields, respectively. The second line contains $$$n$$$ integers $$$d_1$$$, $$$d_2$$$, ..., $$$d_n$$$ ($$$1 \le d_i \le 10^9$$$), where $$$d_i$$$ is the strength of the $$$i$$$-th mons...
standard output
standard input
PyPy 3
Python
2,400
train_029.jsonl
d9eaecfbbb95516f84b7dcdd20bef1f9
256 megabytes
["3 2\n1 3 1\n2 1\n1 2", "3 3\n4 2 6\n3 1\n1 2\n2 3"]
PASSED
import sys;input=sys.stdin.readline mod = 998244353 #mod=10**9+7 def frac(limit): frac = [1]*limit for i in range(2,limit): frac[i] = i * frac[i-1]%mod fraci = [None]*limit fraci[-1] = pow(frac[-1], mod -2, mod) for i in range(-2, -limit-1, -1): fraci[i] = fraci[i+1] * (limit + i + ...
1600094100
[ "probabilities" ]
[ 0, 0, 0, 0, 0, 1, 0, 0 ]
2 seconds
["0\n1\n2"]
c72d6f6b365354bea0c9cab81e34b395
NoteIn the first test case, there is only one vertex, so you don't need any queries.In the second test case, you can ask a single query about the node $$$1$$$. Then, if $$$x = 1$$$, you will get $$$0$$$, otherwise you will get $$$1$$$.
The only difference between this problem and D2 is the bound on the size of the tree.You are given an unrooted tree with $$$n$$$ vertices. There is some hidden vertex $$$x$$$ in that tree that you are trying to find.To do this, you may ask $$$k$$$ queries $$$v_1, v_2, \ldots, v_k$$$ where the $$$v_i$$$ are vertices in ...
For each test case print a single nonnegative integer, the minimum number of queries you need, on its own line.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2000$$$)  — the number of vertices in the tree. Each of the next $$$n-1$$$ l...
standard output
standard input
PyPy 3-64
Python
2,200
train_089.jsonl
7f86192b7ae65d930b46f1f674a35b6c
256 megabytes
["3\n\n1\n\n2\n\n1 2\n\n10\n\n2 4\n\n2 1\n\n5 7\n\n3 10\n\n8 6\n\n6 1\n\n1 3\n\n4 7\n\n9 6"]
PASSED
#!/usr/bin/env python3 import sys import math, random import functools, itertools, collections, heapq, bisect from collections import Counter, defaultdict, deque input = sys.stdin.readline # to read input quickly # available on Google, AtCoder Python3, not available on Codeforces # import numpy as np # import scipy ...
1655562900
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
1 second
["0.250", "0.279"]
f84b7122ffc7f585fd4ac8f1b3ef977a
NoteIn the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows: choose indexes i and j (i ≠ j) that haven't been chosen yet; round element ai to ...
In a single line print a single real number — the required difference with exactly three digits after the decimal point.
The first line contains integer n (1 ≤ n ≤ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 ≤ ai ≤ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
standard output
standard input
Python 2
Python
1,800
train_003.jsonl
48d7c6d898fd6af23942f68025c8fecc
256 megabytes
["3\n0.000 0.500 0.750 1.000 2.000 3.000", "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896"]
PASSED
n = int(raw_input()) r = [int(x.split('.')[1]) for x in raw_input().split()] r_n, s = r.count(0), sum(r) res = min(abs(s - i * 1000) for i in range(max(0, n - r_n), min(2 * n - r_n, n) + 1) ) print '%.3f' % (res/1000.0)
1380900600
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2", "-1"]
0f49b4a5696ee71ebbc8f83d1ec3b901
NoteIn the second example Vasya is not able to determine items count uniquely because 3 items, as well as 4 items, can be displayed on two pages.
Vasya plays The Elder Trolls III: Morrowindows. He has a huge list of items in the inventory, however, there is no limits on the size of things. Vasya does not know the total amount of items but he is sure that are not more than x and not less than 2 items in his inventory. A new patch for the game appeared to view inv...
Output the fewest amount of modes required to uniquely determine amount of items in the inventory. If there is no solution output  - 1.
The first line contains two integers n and x (0 ≤ n ≤ 105, 2 ≤ x ≤ 109). The second line contains integers ai (1 ≤ ai ≤ 109). Some numbers among all ai may be equal.
standard output
standard input
Python 2
Python
2,400
train_010.jsonl
da2963669469d481ec2f814b811f58e4
256 megabytes
["2 4\n2 3", "1 4\n2"]
PASSED
n,x = map(int,raw_input().split()) a = set(map(int,raw_input().split())) if 1 in a and x>2: print 1 elif x>1300000: print -1 else: pr = range(x) for i in xrange(2,x): if not pr[i]: continue ii=i*i if ii>x: break pr[ii::i]=[0]*len(pr[ii::i]) pr = set(filter(None,pr)[1:]) ...
1302422400
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["0\n1\n0\n1"]
4322861935ca727b0de8556849bc5982
NoteIn the first test case, Luntik can include a one-minute song and a two-minute song into the first concert, and a three-minute song into the second concert. Then the difference will be equal to $$$0$$$.In the second test case, Luntik can include two one-minute songs and a two-minute song and a three-minute song into...
Luntik has decided to try singing. He has $$$a$$$ one-minute songs, $$$b$$$ two-minute songs and $$$c$$$ three-minute songs. He wants to distribute all songs into two concerts such that every song should be included to exactly one concert.He wants to make the absolute difference of durations of the concerts as small as...
For each test case print the minimal possible difference in minutes between the concerts durations.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of one line containing three integers $$$a, b, c$$$ $$$(1 \le a, b, c \le 10^9)$$$ — the number of one-minute, two-minute and three-minute songs.
standard output
standard input
Python 3
Python
800
train_106.jsonl
ec4cd3b4f5b5fb6e2a0d0ccb7dc78fbe
256 megabytes
["4\n1 1 1\n2 1 3\n5 5 5\n1 1 2"]
PASSED
for t in range(int(input())): a, b, c = map(int, input().split()) print((a + (2 * b) + (3 * c)) % 2)
1635069900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["5 5 6 7"]
612884cad3d52cc952f2b49674e70a08
NoteInitially, the mountain has heights $$$2, 6, 7, 8$$$.In the first minute, we have $$$2 + 2 \leq 6$$$, so $$$2$$$ increases to $$$3$$$ and $$$6$$$ decreases to $$$5$$$, leaving $$$3, 5, 7, 8$$$.In the second minute, we have $$$3 + 2 \leq 5$$$ and $$$5 + 2 \leq 7$$$, so $$$3$$$ increases to $$$4$$$, $$$5$$$ is unchan...
Omkar is standing at the foot of Celeste mountain. The summit is $$$n$$$ meters away from him, and he can see all of the mountains up to the summit, so for all $$$1 \leq j \leq n$$$ he knows that the height of the mountain at the point $$$j$$$ meters away from himself is $$$h_j$$$ meters. It turns out that for all $$$j...
Output $$$n$$$ integers, where the $$$j$$$-th integer is the value of $$$h_j$$$ after the landslide has stopped.
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^6$$$). The second line contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ satisfying $$$0 \leq h_1 &lt; h_2 &lt; \dots &lt; h_n \leq 10^{12}$$$ — the heights.
standard output
standard input
Python 3
Python
2,400
train_016.jsonl
66610989d81f590c328bf5eb8712ab25
256 megabytes
["4\n2 6 7 8"]
PASSED
import sys n=int(input()) a=[int(v) for v in sys.stdin.readline().split()] s=sum(a)-((n*(n+1))//2) p=s//n q=s%n for j in range(n): a[j]=j+1+p+(q>0) q=q-1 print(' '.join(map(str,a)))
1597588500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["5", "2596"]
8a752a1d78876fc20ee674d4fb93d769
NoteConsider the first example. In the given grid, cells $$$(0,0),(0,1),(1,0),(1,1)$$$ are white, and all other cells are black. Let us use triples to describe the grid: triple $$$(x,y,z)$$$ means that there are $$$z$$$ dolls placed on cell $$$(x,y)$$$. Initially the state of the grid is $$$(0,0,1)$$$.One of the optima...
We say an infinite sequence $$$a_{0}, a_{1}, a_2, \ldots$$$ is non-increasing if and only if for all $$$i\ge 0$$$, $$$a_i \ge a_{i+1}$$$.There is an infinite right and down grid. The upper-left cell has coordinates $$$(0,0)$$$. Rows are numbered $$$0$$$ to infinity from top to bottom, columns are numbered from $$$0$$$ ...
Print one integer — the answer to the problem, modulo $$$10^9+7$$$.
The first line of input contains one integer $$$n$$$ ($$$1\le n\le 2\cdot 10^5$$$). The second line of input contains $$$n+1$$$ integers $$$a_0,a_1,\ldots,a_n$$$ ($$$0\le a_i\le 2\cdot 10^5$$$). It is guaranteed that the sequence $$$a$$$ is non-increasing.
standard output
standard input
Python 3
Python
2,000
train_105.jsonl
b1baac63e692e5af0a7eea77ab106889
512 megabytes
["2\n2 2 0", "10\n12 11 8 8 6 6 6 5 3 2 1"]
PASSED
N = int(input()) x = list(map(int, input().split())) ans = 0 MOD = 1000000007 for i in range(0, len(x)) : x[i] += i if x[0] == 0 : ans = 0 else : tmp = x[0] ll = x[0] lr = x[0] r = 1 for i in range(0, len(x)) : while lr < x[i] : lr += 1 ...
1656167700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["-", "ac", "abcba"]
89aef6720eac7376ce0a657d46c3c5b7
NoteIn the first example strings a and b don't share any symbols, so the longest string that you can get is empty.In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of th...
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters. If the answer consists of zero characters, output «-» (a minus sign).
The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 105 characters.
standard output
standard input
PyPy 3
Python
2,100
train_035.jsonl
0c952d7963baee5aaec05ec2f03c1e3f
256 megabytes
["hi\nbob", "abca\naccepted", "abacaba\nabcdcba"]
PASSED
a, b = input(), input() n = len(b) def f(a, b): i, t = 0, [0] for q in a: if i < n and q == b[i]: i += 1 t.append(i) return t u, v = f(a, b), f(a[::-1], b[::-1])[::-1] t = [x + y for x, y in zip(u, v)] i = t.index(max(t)) x, y = u[i], v[i] s = b[:x] + b[max(x, n - y):] print(s if s else '-')
1485354900
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["NO\nYES\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES"]
9640b7197bd7b8a59f29aecf104291e1
null
A string is called square if it is some string written twice in a row. For example, the strings "aa", "abcabc", "abab" and "baabaa" are square. But the strings "aaa", "abaaab" and "abcdabc" are not square.For a given string $$$s$$$ determine if it is square.
For each test case, output on a separate line: YES if the string in the corresponding test case is square, NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).
The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) —the number of test cases. This is followed by $$$t$$$ lines, each containing a description of one test case. The given strings consist only of lowercase Latin letters and have lengths between $$$1$$$ and $$$100$$$ inclusive.
standard output
standard input
PyPy 3-64
Python
800
train_093.jsonl
3d3389375b872c27d6568b306488eea0
256 megabytes
["10\na\naa\naaa\naaaa\nabab\nabcabc\nabacaba\nxxyy\nxyyx\nxyxy"]
PASSED
n = int(input()) m = [] for i in range(n): a = input() m.append(a) for j in m: if len(j) == 1: print('NO') else: b = len(j) // 2 if len(j) % 2 == 0: if j[:b] == j[b:]: print('YES') else: print('NO') el...
1640010900
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["12", "25", "1423"]
028e83d83cc99a2b3826627efd87a304
NoteIn the first example it is optimal to put people in this order: ($$$3, 1, 2$$$). The first person is in the position of $$$2$$$, then his dissatisfaction will be equal to $$$4 \cdot 1+2 \cdot 1=6$$$. The second person is in the position of $$$3$$$, his dissatisfaction will be equal to $$$2 \cdot 2+3 \cdot 0=4$$$. T...
During a break in the buffet of the scientific lyceum of the Kingdom of Kremland, there was formed a queue of $$$n$$$ high school students numbered from $$$1$$$ to $$$n$$$. Initially, each student $$$i$$$ is on position $$$i$$$. Each student $$$i$$$ is characterized by two numbers — $$$a_i$$$ and $$$b_i$$$. Dissatisfac...
Output one integer — minimum total dissatisfaction which can be achieved by rearranging people in the queue.
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of people in the queue. Each of the following $$$n$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq 10^8$$$) — the characteristic of the student $$$i$$$, initially on the position $$$i$$$.
standard output
standard input
PyPy 3
Python
1,600
train_004.jsonl
f83112517b06cb6acb6cb7d17f1df203
256 megabytes
["3\n4 2\n2 3\n6 1", "4\n2 4\n3 3\n7 1\n2 3", "10\n5 10\n12 4\n31 45\n20 55\n30 17\n29 30\n41 32\n7 1\n5 5\n3 15"]
PASSED
from sys import stdin input=stdin.readline ans=0 k=[] n=int(input()) for i in range(n): a,b=map(int,input().split()) ans+=b*n-a k.append(a-b) k.sort(reverse=True) for i in range(n): ans+=k[i]*(i+1) print(ans)
1555601700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES\nNO\nNO\nYES\nYES"]
c569b47cf80dfa98a7105e246c3c1e01
NoteIn the first test case, $$$s$$$="abcde". You need to get $$$s$$$="c". For the first operation, delete the first two letters, we get $$$s$$$="cde". In the second operation, we delete the last two letters, so we get the expected value of $$$s$$$="c".In the third test case, $$$s$$$="x", it is required to get $$$s$$$="...
The string $$$s$$$ is given, the string length is odd number. The string consists of lowercase letters of the Latin alphabet.As long as the string length is greater than $$$1$$$, the following operation can be performed on it: select any two adjacent letters in the string $$$s$$$ and delete them from the string. For ex...
For each test case in a separate line output: YES, if the string $$$s$$$ can be converted so that $$$s=c$$$ is true; NO otherwise. You can output YES and NO in any case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive response).
The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of input test cases. The descriptions of the $$$t$$$ cases follow. Each test case is represented by two lines: string $$$s$$$, which has an odd length from $$$1$$$ to $$$49$$$ inclusive and consists of lowercase letters of ...
standard output
standard input
PyPy 3-64
Python
800
train_104.jsonl
6ff28fc4bea9d760cef1fb20c717d017
256 megabytes
["5\n\nabcde\n\nc\n\nabcde\n\nb\n\nx\n\ny\n\naaaaaaaaaaaaaaa\n\na\n\ncontest\n\nt"]
PASSED
for _ in range(int(input())): s = str(input()) c = str(input()) n = len(s) index = 0 for i in range(0, n+1, 2): if s[i] == c: index = 1 break if index == 1: print("YES") else: print("NO")
1646750100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["5\n3\n12\n46"]
e015574e9122016e67543de5ed8e547a
NoteHere are the graphs for the four test cases of the example (the edges of a possible MST of the graphs are marked pink):For test case 1 For test case 2 For test case 3 For test case 4
You are given an array $$$a$$$ of $$$n$$$ ($$$n \geq 2$$$) positive integers and an integer $$$p$$$. Consider an undirected weighted graph of $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$ for which the edges between the vertices $$$i$$$ and $$$j$$$ ($$$i&lt;j$$$) are added in the following manner: If $$$gcd(a_i, a...
Output $$$t$$$ lines. For each test case print the weight of the corresponding graph.
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) and $$$p$$$ ($$$1 \leq p \leq 10^9$$$) — the number of nodes and the parameter $$$p$$$. The second line contains $$$n$...
standard output
standard input
PyPy 3-64
Python
2,000
train_088.jsonl
e653f15be50bd084bdea61e6bcc4e98c
256 megabytes
["4\n2 5\n10 10\n2 5\n3 3\n4 5\n5 2 4 9\n8 8\n5 3 3 6 10 100 9 15"]
PASSED
from operator import mod import os,sys from random import randint, shuffle 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, permutati...
1618151700
[ "number theory", "graphs" ]
[ 0, 0, 1, 0, 1, 0, 0, 0 ]
1 second
["7", "999999228"]
607e670403a40e4fddf389caba79607e
NoteIn the first example:$$$(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i})$$$ = $$$2^{2} 3^{0} - 2^{1} 3^{1} + 2^{0} 3^{2}$$$ = 7In the second example:$$$(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = -1^{4} 5^{0} - 1^{3} 5^{1} - 1^{2} 5^{2} - 1^{1} 5^{3} - 1^{0} 5^{4} = -781 \equiv 999999228 \pmod{10^{9} + 9}$$$.
You are given two integers $$$a$$$ and $$$b$$$. Moreover, you are given a sequence $$$s_0, s_1, \dots, s_{n}$$$. All values in $$$s$$$ are integers $$$1$$$ or $$$-1$$$. It's known that sequence is $$$k$$$-periodic and $$$k$$$ divides $$$n+1$$$. In other words, for each $$$k \leq i \leq n$$$ it's satisfied that $$$s_{i}...
Output a single integer — value of given expression modulo $$$10^{9} + 9$$$.
The first line contains four integers $$$n, a, b$$$ and $$$k$$$ $$$(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5})$$$. The second line contains a sequence of length $$$k$$$ consisting of characters '+' and '-'. If the $$$i$$$-th character (0-indexed) is '+', then $$$s_{i} = 1$$$, otherwise $$$s_{...
standard output
standard input
PyPy 3
Python
1,800
train_000.jsonl
be3a8a2ba6790f9107422997c89f2f4f
256 megabytes
["2 2 3 3\n+-+", "4 1 5 1\n-"]
PASSED
n, a, b, k = [int(i) for i in input().split()] st = input() l = (n + 1) // k s = 0 mod = 1000000009 def f_pow(a, k): if k == 0: return 1 if k % 2 == 1: return f_pow(a, k - 1) * a % mod else: return f_pow(a * a % mod, k // 2) % mod def rev(b): return f_pow(b, mod - 2) q = f_pow...
1523973900
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["11\n0\n1\n1500"]
b65767c1ebfe72e08f58a9f9254eaa7b
NoteIn the first test case, Day 1: prices are $$$[2, 1, 2]$$$. You can buy all $$$3$$$ packs, since $$$2 + 1 + 2 \le 7$$$. Day 2: prices are $$$[3, 2, 3]$$$. You can't buy all $$$3$$$ packs, since $$$3 + 2 + 3 &gt; 7$$$, so you buy only $$$2$$$ packs. Day 3: prices are $$$[4, 3, 4]$$$. You can buy $$$2$$$ packs wit...
Turbulent times are coming, so you decided to buy sugar in advance. There are $$$n$$$ shops around that sell sugar: the $$$i$$$-th shop sells one pack of sugar for $$$a_i$$$ coins, but only one pack to one customer each day. So in order to buy several packs, you need to visit several shops.Another problem is that price...
For each test case, print one integer — the total number of packs you will be able to buy until prices exceed your everyday budget.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Next $$$t$$$ cases follow. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le x \le 10^9$$$) — the number of shops and your everyday budget. The second ...
standard output
standard input
Python 3
Python
1,200
train_086.jsonl
bf32686aaadf9b405171c01a0e277ad4
256 megabytes
["4\n\n3 7\n\n2 1 2\n\n5 9\n\n10 20 30 40 50\n\n1 1\n\n1\n\n2 1000\n\n1 1"]
PASSED
import math for i in range(int(input())): n, x = list(map(int, input().split())) l = sorted(list(map(int, input().split()))) ans = 0 if x >= l[0]: s = 0 for i, a in enumerate(l): s += a u = math.floor((x - s) / (i + 1.0)) + 1 if u > 0: ...
1650638100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2", "1"]
c98abd01f026df4254bd29cbeb09dd6f
NoteOn the pictures below all $$$U$$$-shaped parabolas that pass through at least two given points are drawn for each of the examples. The $$$U$$$-shaped parabolas that do not have any given point inside their internal area are drawn in red. The first example. The second example.
Recently Vasya learned that, given two points with different $$$x$$$ coordinates, you can draw through them exactly one parabola with equation of type $$$y = x^2 + bx + c$$$, where $$$b$$$ and $$$c$$$ are reals. Let's call such a parabola an $$$U$$$-shaped one.Vasya drew several distinct points with integer coordinates...
In the only line print a single integer — the number of $$$U$$$-shaped parabolas that pass through at least two of the given points and do not contain any of the given points inside their internal area (excluding the parabola itself).
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100\,000$$$) — the number of points. The next $$$n$$$ lines describe the points, the $$$i$$$-th of them contains two integers $$$x_i$$$ and $$$y_i$$$ — the coordinates of the $$$i$$$-th point. It is guaranteed that all points are distinct and that the coo...
standard output
standard input
Python 2
Python
2,400
train_022.jsonl
3dbd820c8760e128f1014f9a8721d661
256 megabytes
["3\n-1 0\n0 2\n1 0", "5\n1 0\n1 -1\n0 -1\n-1 0\n-1 -1"]
PASSED
import sys def read(tp=int): return tp(raw_input()) def readn(tp=int): ln = raw_input().split() return [tp(x) for x in ln] def readf(*tp): ln = raw_input().split() return [x(y) for x,y in zip(tp,ln)] ################################################################################ def ori(p, q, ...
1553965800
[ "math", "geometry" ]
[ 0, 1, 0, 1, 0, 0, 0, 0 ]
3 seconds
["4", "2"]
37bef742c08e1969b609e39fd6eb8f69
NoteIn the first example, the possible pairs $$$(r_0, r_1)$$$ are as follows: "a", "aaaaa" "aa", "aaaa" "aaaa", "aa" "aaaaa", "a" The pair "aaa", "aaa" is not allowed, since $$$r_0$$$ and $$$r_1$$$ must be different.In the second example, the following pairs are possible: "ko", "kokotlin" "koko", "tlin"
One of Arkady's friends works at a huge radio telescope. A few decades ago the telescope has sent a signal $$$s$$$ towards a faraway galaxy. Recently they've received a response $$$t$$$ which they believe to be a response from aliens! The scientists now want to check if the signal $$$t$$$ is similar to $$$s$$$.The orig...
Print a single integer — the number of pairs of strings $$$r_0$$$ and $$$r_1$$$ that transform $$$s$$$ to $$$t$$$. In case there are no such pairs, print $$$0$$$.
The first line contains a string $$$s$$$ ($$$2 \le |s| \le 10^5$$$) consisting of zeros and ones — the original signal. The second line contains a string $$$t$$$ ($$$1 \le |t| \le 10^6$$$) consisting of lowercase English letters only — the received signal. It is guaranteed, that the string $$$s$$$ contains at least one...
standard output
standard input
PyPy 3
Python
2,100
train_052.jsonl
18bbeefd5aab1c0c88bcdd0ff95f7d4d
256 megabytes
["01\naaaaaa", "001\nkokokokotlin"]
PASSED
s = input() t = input() n,m = len(s), len(t) a = s.count('0') b = len(s) - a pow = [1] * m h = [0] * (m+1) p, mod = 31, 10**9+9 for i in range(1, m): pow[i] = pow[i-1] * p % mod for i in range(m): h[i+1] = (h[i] + (ord(t[i])-ord('a')+1) * pow[i]) % mod def get_hash(i, j): hash_value = (h[j] - h[i] + m...
1543163700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["5\n1 2\n1 3\n2 3\n2 4\n3 4", "13\n1 2\n1 3\n2 3\n1 4\n2 4\n1 5\n2 5\n1 6\n2 6\n1 7\n1 8\n5 8\n7 8"]
17d29a0c2ab4e4be14fe3bdeb10d1e55
NoteThe first example was described in the statement.In the second example, the degrees of vertices are $$$[7, 5, 2, 2, 3, 2, 2, 3]$$$. Each of these numbers is prime. Additionally, the number of edges, $$$13$$$, is also a prime number, hence both conditions are satisfied.
Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wanted to give her an affectionate gift but couldn't think of anything inventive. Hence, he will be giving her a graph. How original, Bob! Alice will surely be thrilled!When building the graph, he needs four conditions to b...
If there is no graph satisfying the conditions, print a single line containing the integer $$$-1$$$. Otherwise, first print a line containing a prime number $$$m$$$ ($$$2 \leq m \leq \frac{n(n-1)}{2}$$$) — the number of edges in the graph. Then, print $$$m$$$ lines, the $$$i$$$-th of which containing two integers $$$u_...
The input consists of a single integer $$$n$$$ ($$$3 \leq n \leq 1\,000$$$) — the number of vertices.
standard output
standard input
PyPy 3
Python
1,500
train_008.jsonl
427ed96879eab9aafc25e725e39f1a35
256 megabytes
["4", "8"]
PASSED
prime = [-1]*(2001) for i in range(2,2001): if prime[i]==-1: for j in range(i,2001,i): prime[j] = i n = int(input()) e = [] for i in range(n): e.append((i,(i+1)%n)) if prime[n]==n: print (len(e)) for i in e: print (i[0]+1,i[1]+1) else: i = 1 j = n-1 while prime[n]!=n: e.append((i,j)) i += 1 j -= 1 ...
1563636900
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["0.2000000000", "0.5000000000"]
b779946fe86b1a2a4449bc85ff887367
NoteIn the first sample matrix B is In the second sample matrix B is
The determinant of a matrix 2 × 2 is defined as follows:A matrix is called degenerate if its determinant is equal to zero. The norm ||A|| of a matrix A is defined as a maximum of absolute values of its elements.You are given a matrix . Consider any degenerate matrix B such that norm ||A - B|| is minimum possible. Deter...
Output a single real number, the minimum possible value of ||A - B||. Your answer is considered to be correct if its absolute or relative error does not exceed 10 - 9.
The first line contains two integers a and b (|a|, |b| ≤ 109), the elements of the first row of matrix A. The second line contains two integers c and d (|c|, |d| ≤ 109) the elements of the second row of matrix A.
standard output
standard input
Python 2
Python
2,100
train_035.jsonl
dc8403adc103fef533d0d3a57861d6cf
256 megabytes
["1 2\n3 4", "1 0\n0 1"]
PASSED
from decimal import * import sys getcontext().prec = 22 a,b = map(int,sys.stdin.readline().split()) c, d = map(int,sys.stdin.readline().split()) a = Decimal(a) b = Decimal(b) c = Decimal(c) d = Decimal(d) l = Decimal(0) r = Decimal(1000000001) eps = Decimal(0.00000000001) binn = Decimal(2) while(r - l >= eps): mid ...
1433595600
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["50\n46\n10\n26\n35184372088846"]
f5de1e9b059bddf8f8dd46c18ce12683
NoteIn the first example test case the optimal sequence would be: Pick $$$i = 2$$$ and $$$j = 1$$$. After performing a sequence of operations $$$a_2 = \frac{4}{2} = 2$$$ and $$$a_1 = 6 \cdot 2 = 12$$$, making the array look as: [12, 2, 2]. Pick $$$i = 2$$$ and $$$j = 1$$$. After performing a sequence of operations $...
William has array of $$$n$$$ numbers $$$a_1, a_2, \dots, a_n$$$. He can perform the following sequence of operations any number of times: Pick any two items from array $$$a_i$$$ and $$$a_j$$$, where $$$a_i$$$ must be a multiple of $$$2$$$ $$$a_i = \frac{a_i}{2}$$$ $$$a_j = a_j \cdot 2$$$ Help William find the max...
For each test case output the maximal sum of array elements after performing an optimal sequence of operations.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ $$$(1 \le n \le 15)$$$, the number of elements in William's array. The second line contains $$$n$...
standard output
standard input
PyPy 3-64
Python
900
train_110.jsonl
38a0869ec21bae34fb76186bbeefbbdb
256 megabytes
["5\n3\n6 4 2\n5\n1 2 3 4 5\n1\n10\n3\n2 3 4\n15\n8 8 8 8 8 8 8 8 8 8 8 8 8 8 8"]
PASSED
# import math # for i in range(int(input())): # n = int(input()) # if n % 2 == 0 and math.sqrt(n//2) == int(math.sqrt(n//2)): # print("YES") # elif n % 4 == 0 and math.sqrt(n//4) == int(math.sqrt(n//4)): # print("YES") # else: # print('NO') ##for i in range(int(input())): ## ...
1638110100
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["303", "25", "60"]
39dbd405be19c5a56c2b97b28e0edf06
NoteNote to the first sample test. 3 + 5 * (7 + 8) * 4 = 303.Note to the second sample test. (2 + 3) * 5 = 25.Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
Vanya is doing his maths homework. He has an expression of form , where x1, x2, ..., xn are digits from 1 to 9, and sign represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression.
In the first line print the maximum possible value of an expression.
The first line contains expression s (1 ≤ |s| ≤ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs  +  and  * . The number of signs  *  doesn't exceed 15.
standard output
standard input
Python 2
Python
2,100
train_005.jsonl
4a4c14e78ddbf5f4e4ad1ee279e57229
256 megabytes
["3+5*7+8*4", "2+3*5", "3*4*5"]
PASSED
n = raw_input() ans = 0 a = [-1] for i in xrange(len(n)): if n[i]=='*':a.append(i) a.append(len(n)) for i in a: for j in a: if j>i: ans = max(ans,eval(n[:i+1]+'('+n[i+1:j]+')'+n[j:])) ans = max(ans,eval(n)) print ans
1434645000
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["4\n0\n2"]
14ce451a31c0dbc2b2f4e04a939b199d
NoteIn the first test case, the following combinations of pairs fit: $$$(1, 2)$$$ and $$$(3, 4)$$$; $$$(1, 3)$$$ and $$$(2, 2)$$$; $$$(1, 3)$$$ and $$$(3, 4)$$$; $$$(2, 2)$$$ and $$$(3, 4)$$$. There is only one pair in the second test case.In the third test case, the following combinations of pairs fit: $$$(1, 1...
At the school where Vasya is studying, preparations are underway for the graduation ceremony. One of the planned performances is a ball, which will be attended by pairs of boys and girls.Each class must present two couples to the ball. In Vasya's class, $$$a$$$ boys and $$$b$$$ girls wish to participate. But not all bo...
For each test case, on a separate line print one integer — the number of ways to choose two pairs that match the condition above.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$k$$$ ($$$1 \le a, b, k \le 2 \cdot 10^5$$$) — the number of boys and girls in the class and the number of coup...
standard output
standard input
PyPy 3-64
Python
1,400
train_086.jsonl
9918b9e83cdf5f85e4f12502b8968a7e
256 megabytes
["3\n3 4 4\n1 1 2 3\n2 3 2 4\n1 1 1\n1\n1\n2 2 4\n1 1 2 2\n1 2 1 2"]
PASSED
from sys import stdin, stdout I = stdin.readline O = stdout.write # n = int(I()) # arr = list(map(int, I().split())) cntA = [0] * 200005 cntB = [0] * 200005 def solve(): a, b, k = map(int,(input().split())) arr = list(map(int, input().split())) brr = list(map(int, input().split())) ...
1611586800
[ "math", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
2 seconds
["1\n0\n4\n2\n1\n3"]
e9065e8bd9afb7d797527bc3a50f2150
NoteIn the first test case, Bob can't win on subsegments of length $$$1$$$, as there is no pair of adjacent piles in an array of length $$$1$$$.In the second test case, every subsegment is not winning.In the fourth test case, the subsegment $$$[1, 4]$$$ is winning, because Bob can make moves with pairs of adjacent pile...
Bob decided to take a break from calculus homework and designed a game for himself. The game is played on a sequence of piles of stones, which can be described with a sequence of integers $$$s_1, \ldots, s_k$$$, where $$$s_i$$$ is the number of stones in the $$$i$$$-th pile. On each turn, Bob picks a pair of non-empty ...
Print a single integer for each test case — the answer to the problem.
Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 3 \cdot 10^5$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 3 \cdot 10^5$$$). The second line of each...
standard output
standard input
PyPy 3-64
Python
2,300
train_091.jsonl
70ab0197ded3ece87b6151529d2d643d
256 megabytes
["6\n2\n2 2\n3\n1 2 3\n4\n1 1 1 1\n4\n1 2 2 1\n4\n1 2 1 2\n8\n1 2 1 2 1 2 1 2"]
PASSED
''' E. Game with Stones https://codeforces.com/contest/1589/problem/E ''' import io, os, sys from math import e input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # decode().strip() if str output = sys.stdout.write from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwa...
1636869900
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
2 seconds
["2\n1 5 11 9\n2 5 7 6\n0"]
8b2b7208630af1d086420513a437a914
NoteConsider the first test case.Initially $$$a = [9, 6, 3, 11, 15]$$$.In the first operation replace $$$a_1$$$ with $$$11$$$ and $$$a_5$$$ with $$$9$$$. It's valid, because $$$\min{(a_1, a_5)} = \min{(11, 9)} = 9$$$.After this $$$a = [11, 6, 3, 11, 9]$$$.In the second operation replace $$$a_2$$$ with $$$7$$$ and $$$a_...
Nastia has received an array of $$$n$$$ positive integers as a gift.She calls such an array $$$a$$$ good that for all $$$i$$$ ($$$2 \le i \le n$$$) takes place $$$gcd(a_{i - 1}, a_{i}) = 1$$$, where $$$gcd(u, v)$$$ denotes the greatest common divisor (GCD) of integers $$$u$$$ and $$$v$$$.You can perform the operation: ...
For each of $$$t$$$ test cases print a single integer $$$k$$$ ($$$0 \le k \le n$$$) — the number of operations. You don't need to minimize this number. In each of the next $$$k$$$ lines print $$$4$$$ integers $$$i$$$, $$$j$$$, $$$x$$$, $$$y$$$ ($$$1 \le i \neq j \le n$$$, $$$1 \le x, y \le 2 \cdot 10^9$$$) so that $$$\...
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 length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_{n}$$$ ($$$1 ...
standard output
standard input
PyPy 3-64
Python
1,300
train_099.jsonl
4b7b9ffdfc81ffac5cf28df3df1afdb7
256 megabytes
["2\n5\n9 6 3 11 15\n3\n7 5 13"]
PASSED
import sys import math from collections import defaultdict,Counter from itertools import permutations from collections import deque from decimal import Decimal from fractions import Fraction from heapq import heappush , heappop import bisect def sin(): return int(sys.stdin.readline()) def array(): ...
1620398100
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["3\n1 2 3", "4\n3 4 1 2"]
250c0e647d0f2ff6d86db01675192c9f
null
You've got a undirected graph G, consisting of n nodes. We will consider the nodes of the graph indexed by integers from 1 to n. We know that each node of graph G is connected by edges with at least k other nodes of this graph. Your task is to find in the given graph a simple cycle of length of at least k + 1.A simple ...
In the first line print integer r (r ≥ k + 1) — the length of the found cycle. In the next line print r distinct integers v1, v2, ..., vr (1 ≤ vi ≤ n) — the found simple cycle. It is guaranteed that the answer exists. If there are multiple correct answers, you are allowed to print any of them.
The first line contains three integers n, m, k (3 ≤ n, m ≤ 105; 2 ≤ k ≤ n - 1) — the number of the nodes of the graph, the number of the graph's edges and the lower limit on the degree of the graph node. Next m lines contain pairs of integers. The i-th line contains integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi) — the index...
standard output
standard input
Python 2
Python
1,800
train_018.jsonl
aac2d18d7934d1627c06c48ab65200ef
256 megabytes
["3 3 2\n1 2\n2 3\n3 1", "4 6 3\n4 3\n1 2\n1 3\n1 4\n2 3\n2 4"]
PASSED
r = lambda: map(int, raw_input().split()) n, m, k = r() e = [[] for _ in xrange(n + 1)] for _ in xrange(m): a, b = r() e[a].append(b) e[b].append(a) flag = [-1] * (n + 1) path = [] x, l = 1, 0 while True: path.append(x) flag[x] = l l += 1 for y in e[x]: if flag[y] == -1: ...
1358350200
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["2 3\n2 1\n1 1 1", "1 1\n20\n3"]
01ac609133428a0074e8506786096e02
NoteIn the first test sample the numerator equals 1000, the denominator equals 500. If we reduce fraction 1000/500 by the greatest common divisor of the numerator and the denominator (by 500), we obtain fraction 2/1.In the second test sample the numerator equals 2000, the denominator equals 300. If we reduce fraction 2...
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
Print the answer to the problem in the form, similar to the form of the input data. The number of values in the sets you print nout, mout must satisfy the inequality 1 ≤ nout, mout ≤ 105, and the actual values in the sets aout, i and bout, i must satisfy the inequality 1 ≤ aout, i, bout, i ≤ 107. Separate the values i...
The first input line contains two space-separated integers n, m (1 ≤ n, m ≤ 105) that show how many numbers the first set (the numerator) and the second set (the denominator) contain, correspondingly. The second line contains n space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 107) — the numbers that are multiplied t...
standard output
standard input
PyPy 3
Python
1,800
train_079.jsonl
e58e72f702be5a3686204ab3c424c4ef
256 megabytes
["3 2\n100 5 2\n50 10", "4 3\n2 5 10 20\n100 1 3"]
PASSED
import math as mt from sys import stdin,stdout MAXN = 10000001 spf = [0]*(MAXN) def sieve(): spf[1] = 1 for i in range(2, MAXN): spf[i] = i for i in range(4, MAXN, 2): spf[i] = 2 for i in range(3, mt.ceil(mt.sqrt(MAXN))): if (spf[i] == i): for j in range(i * i, MAXN, i): if (spf[j] == j): ...
1347291900
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
38375efafa4861f3443126f20cacf3ae
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
standard output
standard input
Python 3
Python
1,300
train_110.jsonl
fd454fc166a3964aa2869f9f990c7762
256 megabytes
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
PASSED
I=input for _ in[0]*int(I()): n,k=map(int,I().split());a=[int(x)^k&1for x in I()];b=[0]*n;i=0 while(n-i)*k:b[i]=a[i]^1;a[i]=1;k-=b[i];i+=1 a[-1]^=k&1;b[-1]+=k;print(*a,sep='');print(*b)
1650206100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["0\n4\n21"]
935bceb69117d06eb75121c805bff69c
NoteFor the first test case, you can move a car from the $$$3$$$-rd sub-track to the $$$1$$$-st sub-track to obtain $$$0$$$ inconvenience.For the second test case, moving any car won't decrease the inconvenience of the track.
Highway 201 is the most busy street in Rockport. Traffic cars cause a lot of hindrances to races, especially when there are a lot of them. The track which passes through this highway can be divided into $$$n$$$ sub-tracks. You are given an array $$$a$$$ where $$$a_i$$$ represents the number of traffic cars in the $$$i$...
For each test case, print a single line containing a single integer: the minimum inconvenience you can achieve by applying the given operation any (possibly zero) number of times.
The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 10\,000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1\leq n\leq 2\cdot 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0\leq a_i\leq ...
standard output
standard input
PyPy 3-64
Python
900
train_091.jsonl
181c34b71f1b0cce381ff6e9e98f5ec9
256 megabytes
["3\n3\n1 2 3\n4\n0 1 1 0\n10\n8 3 6 11 5 2 1 7 10 4"]
PASSED
import sys input = lambda: sys.stdin.buffer.readline().decode().strip() print = sys.stdout.write for _ in range(int(input())): n = int(input()) nums = list(map(int, input().split())) total = sum(nums) reminder = total % n print(str((n - reminder) * reminder) + "\n")
1625668500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["volga", "no", "baba"]
2a414730d1bc7eef50bdb631ea966366
NoteIn the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word...
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf...
Print the word that Polycarp encoded.
The first line contains a positive integer n (1 ≤ n ≤ 2000) — the length of the encoded word. The second line contains the string s of length n consisting of lowercase English letters — the encoding.
standard output
standard input
PyPy 2
Python
900
train_002.jsonl
8580285f81fdd6b80bac0074e6da18e9
256 megabytes
["5\nlogva", "2\nno", "4\nabba"]
PASSED
n=input() s=raw_input() t=s[::2][::-1]+s[1::2] if n%2:t=t[::-1] print t
1482057300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["1 2 2 3\n4 1 4 4\n3 1 1 5\n5 1 1 1\n1 1 2 1\n1 1 1 1\n50 1 1 1000000000"]
5aae6b27f35852512a250751ef957ab9
NoteHere is a visualization of the first test case.
Riley is a very bad boy, but at the same time, he is a yo-yo master. So, he decided to use his yo-yo skills to annoy his friend Anton.Anton's room can be represented as a grid with $$$n$$$ rows and $$$m$$$ columns. Let $$$(i, j)$$$ denote the cell in row $$$i$$$ and column $$$j$$$. Anton is currently standing at positi...
For each test case, print four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ ($$$1 \leq x_1, x_2 \leq n$$$, $$$1\le y_1, y_2\le m$$$) — the coordinates of where the two yo-yos should be thrown. They will be thrown at coordinates $$$(x_1,y_1)$$$ and $$$(x_2,y_2)$$$. If there are multiple answers, you may print any...
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of each test case contains four integers $$$n$$$, $$$m$$$, $$$i$$$, $$$j$$$ ($$$1 \leq n, m \leq 10^9$$$, $$$1\le i\le n$$$, $$$1\le j\le m$$$) — the dimensions of the ro...
standard output
standard input
Python 3
Python
900
train_084.jsonl
a066260df29628fb10bce33fc3e7297f
256 megabytes
["7\n2 3 1 1\n4 4 1 2\n3 5 2 2\n5 1 2 1\n3 1 3 1\n1 1 1 1\n1000000000 1000000000 1000000000 50"]
PASSED
t = int(input()) for _ in range(t): n, m, y, x = map(int, input().split()) if x <= round(m/2): print(n, m, 1, 1) else: print(n, 1, 1, m)
1624026900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["-1\n1\n2\n2\n2\n1"]
3dc5850220458dec9876560150b612c4
NoteIn the first test case, there is no possible $$$m$$$, because all elements of all arrays should be equal to $$$0$$$. But in this case, it is impossible to get $$$a_4 = 1$$$ as the sum of zeros.In the second test case, we can take $$$b_1 = [3, 3, 3]$$$. $$$1$$$ is the smallest possible value of $$$m$$$.In the third ...
You are given a non-decreasing array of non-negative integers $$$a_1, a_2, \ldots, a_n$$$. Also you are given a positive integer $$$k$$$.You want to find $$$m$$$ non-decreasing arrays of non-negative integers $$$b_1, b_2, \ldots, b_m$$$, such that: The size of $$$b_i$$$ is equal to $$$n$$$ for all $$$1 \leq i \leq m$$...
For each test case print a single integer: the minimum possible value of $$$m$$$. If there is no such $$$m$$$, print $$$-1$$$.
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$): the number of test cases. The first line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1 \leq n \leq 100$$$, $$$1 \leq k \leq n$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_1 \leq a_2 \leq \l...
standard output
standard input
Python 3
Python
1,400
train_011.jsonl
6559ce04c65fa8337a20b6d94153b9dd
256 megabytes
["6\n4 1\n0 0 0 1\n3 1\n3 3 3\n11 3\n0 1 2 2 3 3 3 4 4 4 4\n5 3\n1 2 3 4 5\n9 4\n2 2 3 5 7 11 13 13 17\n10 7\n0 1 1 2 3 3 4 5 5 6"]
PASSED
import math test = int(input()) for q in range(test): n,k = map(int,input().split()) a = list(map(int,input().split())) x = set() if k==1: if a[0]!=a[n-1]: print(-1) continue else: print(1) continue ans = 0 i = 0 while i<n: ...
1601476500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2\n1\n1\n0\n2\n500000000"]
8a1ceac1440f7cb406f12d9fc2ca0e20
NoteIn the first test case of the example, two teams can be composed. One way to compose two teams is to compose two teams of $$$2$$$ programmers and $$$2$$$ mathematicians.In the second test case of the example, only one team can be composed: $$$3$$$ programmers and $$$1$$$ mathematician in the team.
The All-Berland Team Programming Contest will take place very soon. This year, teams of four are allowed to participate.There are $$$a$$$ programmers and $$$b$$$ mathematicians at Berland State University. How many maximum teams can be made if: each team must consist of exactly $$$4$$$ students, teams of $$$4$$$ math...
Print $$$t$$$ lines. Each line must contain the answer to the corresponding set of input data — the required maximum number of teams.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases. This is followed by descriptions of $$$t$$$ sets, one per line. Each set is given by two integers $$$a$$$ and $$$b$$$ ($$$0 \le a,b \le 10^9$$$).
standard output
standard input
PyPy 3-64
Python
800
train_093.jsonl
14398edafa7fdb83898db276cd10be83
256 megabytes
["6\n5 5\n10 1\n2 3\n0 0\n17 2\n1000000000 1000000000"]
PASSED
from sys import stdin, stdout t = int(stdin.readline()) for i in range(t): a, b = map(int, stdin.readline().strip().split()) teams=0 if a==b: teams += (a+b)//4 else: max_one = max(a, b) min_one = min(a, b) m_p_pairs = min_one max_one-=min_one ...
1637850900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["cadb\ngg\ncodfoerces\nNo answer"]
d62d0a9d827444a671029407f6a4ad39
NoteIn the first example answer "bdac" is also correct.The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.There are lots of valid answers for the third example.
You are given a string, consisting of lowercase Latin letters.A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $$$(1, 2)$$$ — "ab" and $$$(2, 3)$$$ — "ba". Letters 'a' and 'z' aren't considere...
Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th query. If the answer for the $$$i$$$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new l...
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. Each of the next $$$T$$$ lines contains string $$$s$$$ $$$(1 \le |s| \le 100)$$$ — the string for the next query. It is guaranteed that it contains only lowercase Latin letters. Note that in hacks you have to set $$$T = 1$...
standard output
standard input
Python 3
Python
1,800
train_016.jsonl
2cad658f31049589fa58a0c5ec188842
256 megabytes
["4\nabcd\ngg\ncodeforces\nabaca"]
PASSED
import collections def add1(c): return chr(ord(c)+1) def sv(): m = collections.defaultdict(int) for c in input(): m[c] += 1 m = list(m.items()) m.sort() if len(m) == 2 and add1(m[0][0]) == m[1][0]: return False if len(m) == 3: if add1(m[0][0]) != m[1][0]: pass ...
1556721300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["8", "7", "6"]
e849aa63710c817aac610a1deeb366c5
null
You are given an array $$$a_1, a_2, \ldots, a_n$$$ and an integer $$$x$$$.Find the number of non-empty subsets of indices of this array $$$1 \leq b_1 &lt; b_2 &lt; \ldots &lt; b_k \leq n$$$, such that for all pairs $$$(i, j)$$$ where $$$1 \leq i &lt; j \leq k$$$, the inequality $$$a_{b_i} \oplus a_{b_j} \leq x$$$ is he...
Print one integer: the number of non-empty subsets such that the bitwise XOR of every pair of elements is at most $$$x$$$, modulo $$$998\,244\,353$$$.
The first line of the input contains two integers $$$n$$$ and $$$x$$$ ($$$1 \leq n \leq 150\,000$$$, $$$0 \leq x &lt; 2^{30}$$$). Here, $$$n$$$ is the size of the array. The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i &lt; 2^{30}$$$): the array itself.
standard output
standard input
PyPy 3
Python
3,000
train_101.jsonl
b4ca7c994a12b253b23b565dce7edacd
256 megabytes
["4 2\n0 1 2 3", "3 6\n4 2 2", "4 0\n1 1 2 2"]
PASSED
I=lambda:[*map(int,input().split())] M=998244353 n,X=I() a=I() q=lambda x:pow(2,x,M)-1 E=len B=lambda a,H:[[z for z in a if z>>H&1==d]for d in[0,1]] def f(a,b,i): if i<0 or[]in[a,b]:return q(E(a))*q(E(b)) w,x=B(a,i);y,z=B(b,i);return(f(x,y,i-1)+q(E(x))+q(E(y))+1)*(f(w,z,i-1)+q(E(w))+q(E(z))+1)-q(E(a))-q(E(b)...
1640792100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1\n3", "2\n1 2", "0"]
ce19cc45bbe24177155ce87dfe9d5c22
NoteIn the first example, $$$3$$$ is the only possible answer. In the second example, there are $$$2$$$ possible answers. In the third example, the tree can't be generated by McDic's generation.
You have an integer $$$n$$$. Let's define following tree generation as McDic's generation: Make a complete and full binary tree of $$$2^{n} - 1$$$ vertices. Complete and full binary tree means a tree that exactly one vertex is a root, all leaves have the same depth (distance from the root), and all non-leaf nodes have...
Print two lines. In the first line, print a single integer — the number of answers. If given tree cannot be made by McDic's generation, then print $$$0$$$. In the second line, print all possible answers in ascending order, separated by spaces. If the given tree cannot be made by McDic's generation, then don't print any...
The first line contains integer $$$n$$$ ($$$2 \le n \le 17$$$). The $$$i$$$-th of the next $$$2^{n} - 3$$$ lines contains two integers $$$a_{i}$$$ and $$$b_{i}$$$ ($$$1 \le a_{i} \lt b_{i} \le 2^{n} - 2$$$) — meaning there is an edge between $$$a_{i}$$$ and $$$b_{i}$$$. It is guaranteed that the given edges form a tree...
standard output
standard input
PyPy 3
Python
2,500
train_053.jsonl
eddc88ff772193c203afec5e9195f864
256 megabytes
["4\n1 2\n1 3\n2 4\n2 5\n3 6\n3 13\n3 14\n4 7\n4 8\n5 9\n5 10\n6 11\n6 12", "2\n1 2", "3\n1 2\n2 3\n3 4\n4 5\n5 6"]
PASSED
#!/usr/bin/python3 import array import math import os import sys DEBUG = 'DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def dprint(*value, sep=' ', end='\n'): if DEBUG: print(*value, sep=sep, end=end) def solve(N, M, G): if N == 2: return [0, 1] degv = [s...
1569762300
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["? 0\n\n? 1\n\n! 1", "? 2\n\n? 1\n\n? 0\n\n! -1"]
b26140f647eee09f5f0d6c428d99126d
NoteThe polynomial in the first sample is $$$1000002 + x^2$$$.The polynomial in the second sample is $$$1 + x^2$$$.
Jury picked a polynomial $$$f(x) = a_0 + a_1 \cdot x + a_2 \cdot x^2 + \dots + a_k \cdot x^k$$$. $$$k \le 10$$$ and all $$$a_i$$$ are integer numbers and $$$0 \le a_i &lt; 10^6 + 3$$$. It's guaranteed that there is at least one $$$i$$$ such that $$$a_i &gt; 0$$$.Now jury wants you to find such an integer $$$x_0$$$ that...
null
null
standard output
standard input
Python 3
Python
2,200
train_072.jsonl
f12c1b3b780a5d9698537ea8a5b24b63
256 megabytes
["1000002\n\n0", "5\n\n2\n\n1"]
PASSED
def main(): seed = [] for i in range(11): print('?', i) seed.append(int(input())) if not seed[-1]: print('!', i) return poly = [seed[-1]] for _ in range(10): seed = [(b - a) % 1000003 for a, b in zip(seed, seed[1:])] poly.append(seed[-1]) ...
1555943700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["0.5", "0.875", "-1"]
74ed99af5a5ed51c73d68f7d4ff2c70e
NoteIn the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to .In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to .
An atom of element X can exist in n distinct states with energies E1 &lt; E2 &lt; ... &lt; En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i &lt; j &lt; k. After that the following process...
If it is not possible to choose three states that satisfy all constraints, print -1. Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9. Formally, let your answer be a, and the jury's answer be b...
The first line contains two integers n and U (3 ≤ n ≤ 105, 1 ≤ U ≤ 109) — the number of states and the maximum possible difference between Ek and Ei. The second line contains a sequence of integers E1, E2, ..., En (1 ≤ E1 &lt; E2... &lt; En ≤ 109). It is guaranteed that all Ei are given in increasing order.
standard output
standard input
Python 3
Python
1,600
train_001.jsonl
58595d599ad2ee26fd5e4be8d8f8d244
256 megabytes
["4 4\n1 3 5 7", "10 8\n10 13 15 16 17 19 20 22 24 25", "3 1\n2 5 10"]
PASSED
n,u=[int(x) for x in input().split()] a=list(map(int,input().split())) idx=0 ans=-1 for i in range(n): while(idx<n-1 and a[idx+1]-a[i]<=u): idx+=1 if(idx-i<2): continue ans=max(ans,(a[idx]-a[i+1])/(a[idx]-a[i])) print(ans)
1521905700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["3", "2"]
94f1521ccc24cfb78469c81546346cd5
NoteIn the first sample case there is only one sum $$$1 + 2 = 3$$$.In the second sample case there are three sums: $$$1 + 2 = 3$$$, $$$1 + 3 = 4$$$, $$$2 + 3 = 5$$$. In binary they are represented as $$$011_2 \oplus 100_2 \oplus 101_2 = 010_2$$$, thus the answer is 2.$$$\oplus$$$ is the bitwise xor operation. To define...
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realiz...
Print a single integer — xor of all pairwise sums of integers in the given array.
The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 400\,000$$$) — the number of integers in the array. The second line contains integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^7$$$).
standard output
standard input
PyPy 3
Python
2,100
train_008.jsonl
ee98d3057ddb217fe13e6794f6262fe8
512 megabytes
["2\n1 2", "3\n1 2 3"]
PASSED
import io import os from collections import deque, defaultdict, Counter from bisect import bisect_left, bisect_right DEBUG = False def solveBrute(N, A): ans = 0 for i in range(N): for j in range(i + 1, N): ans ^= A[i] + A[j] return ans def solve(N, A): B = max(A).bit_length()...
1583573700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["9", "0", "299997"]
cabb7edf51f32c94415d580b96eef7b7
NoteThe notation $$$(i,j)$$$ denotes a scenario where Alice starts at cell $$$i$$$ and ends at cell $$$j$$$.In the first example, the valid scenarios are $$$(1, 2), (2, 1), (2, 2), (2, 3), (3, 2), (3, 3), (3, 4), (4, 3), (4, 5)$$$. For example, $$$(3,4)$$$ is valid since Alice can start at cell $$$3$$$, stay there for ...
Alice and Bob are playing a game on a line with $$$n$$$ cells. There are $$$n$$$ cells labeled from $$$1$$$ through $$$n$$$. For each $$$i$$$ from $$$1$$$ to $$$n-1$$$, cells $$$i$$$ and $$$i+1$$$ are adjacent.Alice initially has a token on some cell on the line, and Bob tries to guess where it is. Bob guesses a sequen...
Print a single integer, the number of scenarios that let Alice answer "NO" to all of Bob's questions.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n,k \leq 10^5$$$) — the number of cells and the number of questions Bob asked. The second line contains $$$k$$$ integers $$$x_1, x_2, \ldots, x_k$$$ ($$$1 \leq x_i \leq n$$$) — Bob's questions.
standard output
standard input
Python 3
Python
1,500
train_026.jsonl
11c86b36666fdda7358c622ab76c7b33
256 megabytes
["5 3\n5 1 4", "4 8\n1 2 3 4 4 3 2 1", "100000 1\n42"]
PASSED
n, k = list(map(int, input().split())) x = list(map(int, input().split())) ml = [] for i in range(n): ml.append([]) for i in range(k): ml[x[i]-1] += [i+1] c = 0 for i in range(n): if not ml[i]: c += 1 if i != 0: if not ml[i] or not ml[i-1] or min(ml[i]) > max(ml[i-1]): c ...
1556989500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["166666669", "500000009", "500000007"]
987433ba0b6a115d05f79f512e329f7a
NoteThis is the tree from the first sample: For the first sample, the arrays are almost fixed. If node $$$2$$$ is chosen initially, then the only possible array is $$$[2, 1, 3]$$$ ($$$1$$$ inversion). If node $$$3$$$ is chosen initially, then the only possible array is $$$[3, 1, 2]$$$ ($$$2$$$ inversions). If node $$$...
You are given a tree consisting of $$$n$$$ nodes. You generate an array from the tree by marking nodes one by one.Initially, when no nodes are marked, a node is equiprobably chosen and marked from the entire tree. After that, until all nodes are marked, a node is equiprobably chosen and marked from the set of unmarked ...
Output the expected number of inversions in the generated array modulo $$$10^9+7$$$. Formally, let $$$M = 10^9+7$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the integer equal to $$$p ...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 200$$$) — the number of nodes in the tree. The next $$$n - 1$$$ lines each contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le n$$$; $$$x \neq y$$$), denoting an edge between node $$$x$$$ and $$$y$$$. It's guaranteed that the given edges form a t...
standard output
standard input
PyPy 2
Python
2,300
train_092.jsonl
73b96d00c90909ef37de0a780994e1cc
256 megabytes
["3\n1 2\n1 3", "6\n2 1\n2 3\n6 1\n1 4\n2 5", "5\n1 2\n1 3\n1 4\n2 5"]
PASSED
m=10**9+7 n=input() h=range(n) d=[n*[m]for f in h] for f in h[1:]:a,b=map(int,raw_input().split());a-=1;b-=1;d[a][b]=d[b][a]=1;d[a][a]=d[b][b]=s=0 for k in h: for i in h: for j in h:d[i][j]=min(d[i][j],d[i][k]+d[k][j]) c=[[1]+n*[0]for f in[0]+h] for i in h: for j in h:c[i+1][j+1]=(c[i][j+1]+c[i+1][j])*-~m...
1624635300
[ "probabilities", "math", "trees", "graphs" ]
[ 0, 0, 1, 1, 0, 1, 0, 1 ]
1 second
["? 1 1\n? 2 2\n? 3 5\n? 4 6\n! 4 8 15 16 23 42"]
c0f79d7ebcecc4eb7d07c372ba9be802
NoteIf you want to submit a hack for this problem, your test should contain exactly six space-separated integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_6$$$. Each of $$$6$$$ special numbers should occur exactly once in the test. The test should be ended with a line break character.
This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You m...
null
null
standard output
standard input
PyPy 3
Python
1,400
train_003.jsonl
22b745e04d857f2e8013dd849090868a
256 megabytes
["16\n64\n345\n672"]
PASSED
from itertools import permutations x = [4,8,15,16,23,42] print("? 1 2", flush=True) a = int(input()) print("? 3 4", flush=True) b = int(input()) print("? 5 5", flush=True) c = int(input()) print("? 1 3", flush=True) d = int(input()) for p in permutations(x): if p[0]*p[1] == a and p[2]*p[3] == b and p[4]*p[4] == c ...
1557930900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2\n3\n3"]
c9da10199ad1a5358195b693325e628b
NoteIn the first testcase, each shuffle effectively swaps two cards. After three swaps, the deck will be $$$[2, 1]$$$.In the second testcase, the second shuffle cancels what the first shuffle did. First, three topmost cards went underneath the last card, then that card went back below the remaining three cards. So the ...
Monocarp has just learned a new card trick, and can't wait to present it to you. He shows you the entire deck of $$$n$$$ cards. You see that the values of cards from the topmost to the bottommost are integers $$$a_1, a_2, \dots, a_n$$$, and all values are different.Then he asks you to shuffle the deck $$$m$$$ times. Wi...
For each testcase, print a single integer — the value of the card on the top of the deck after the deck is shuffled $$$m$$$ times.
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 a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of cards in the deck. The second line contains $$$n$$$ pairwise distinct integers $$$a_1, a_2, \dots, a_n$$...
standard output
standard input
PyPy 3-64
Python
800
train_087.jsonl
92dd58c9ae9fcc3a77c757e7da165d0e
256 megabytes
["3\n\n2\n\n1 2\n\n3\n\n1 1 1\n\n4\n\n3 1 4 2\n\n2\n\n3 1\n\n5\n\n2 1 5 4 3\n\n5\n\n3 2 1 2 1"]
PASSED
case = int(input()) def solve(): n = int(input()) card = list(map(int,input().split())) m = int(input()) v = list(map(int,input().split())) counter = 0 for i in v: counter+=i counter = counter%n print(card[counter]) for _ in range(case): solve()
1653316500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["70.00000000", "55.00000000"]
0c3fd1226188cccd013b0842666c3597
null
Once Petya was in such a good mood that he decided to help his mum with the washing-up. There were n dirty bowls in the sink. From the geometrical point of view each bowl looks like a blunted cone. We can disregard the width of the walls and bottom. Petya puts the clean bowls one on another naturally, i. e. so that the...
Output the height of the plate pile accurate to at least 10 - 6.
The first input line contains integer n (1 ≤ n ≤ 3000). Each of the following n lines contains 3 integers h, r and R (1 ≤ h ≤ 10000, 1 ≤ r &lt; R ≤ 10000). They are the height of a bowl, the radius of its bottom and the radius of its top. The plates are given in the order Petya puts them on the table.
output.txt
input.txt
PyPy 3
Python
2,200
train_058.jsonl
ee4e7a89ddb096556d53238cd9cb3a86
64 megabytes
["2\n40 10 50\n60 20 30", "3\n50 30 80\n35 25 70\n40 10 90"]
PASSED
import sys from array import array # noqa: F401 def input1(): with open('input.txt') as fp: return fp.readlines() def output1(ans: str): with open('output.txt', mode='w') as fp: fp.write(ans) def input2(): return [line.decode('utf-8') for line in sys.stdin.buffer.readlines()] def ou...
1287482400
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
1 second
["6", "8", "8"]
a88e4a7c476b9af1ff2ca9137214dfd7
NoteIn the first example, Nut could write strings "aa", "ab", "ba", "bb". These $$$4$$$ strings are prefixes of at least one of the written strings, as well as "a" and "b". Totally, $$$6$$$ strings.In the second example, Nut could write strings "aba", "baa", "bba".In the third example, there are only two different stri...
Recently, the Fair Nut has written $$$k$$$ strings of length $$$n$$$, consisting of letters "a" and "b". He calculated $$$c$$$ — the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time.Then, he lost his sheet with strings. He remembers that all written stri...
Print one number — maximal value of $$$c$$$.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 5 \cdot 10^5$$$, $$$1 \leq k \leq 10^9$$$). The second line contains a string $$$s$$$ ($$$|s| = n$$$) — the string consisting of letters "a" and "b. The third line contains a string $$$t$$$ ($$$|t| = n$$$) — the string consisting of letters "a" ...
standard output
standard input
Python 3
Python
2,000
train_004.jsonl
1c2e7cfd1ae49e41e349035e00537f47
256 megabytes
["2 4\naa\nbb", "3 3\naba\nbba", "4 5\nabbb\nbaaa"]
PASSED
n, k = map(int, input().split()) a = input() b = input() res = 0 ans = 0 for i in range(0, n): res = min(res * 2 + (b[i] == 'b') - (a[i] == 'b'), k) ans += min(res + 1, k) print(ans)
1544459700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["12", "11"]
d2fe5a201d1ec20c5b32cd99b54e13d0
NoteThe algorithm for the first example: add to the answer $$$1010_2~ \&amp;~ 1101_2 = 1000_2 = 8_{10}$$$ and set $$$b := 110$$$; add to the answer $$$1010_2~ \&amp;~ 110_2 = 10_2 = 2_{10}$$$ and set $$$b := 11$$$; add to the answer $$$1010_2~ \&amp;~ 11_2 = 10_2 = 2_{10}$$$ and set $$$b := 1$$$; add to the answer...
You are given two huge binary integer numbers $$$a$$$ and $$$b$$$ of lengths $$$n$$$ and $$$m$$$ respectively. You will repeat the following process: if $$$b &gt; 0$$$, then add to the answer the value $$$a~ \&amp;~ b$$$ and divide $$$b$$$ by $$$2$$$ rounding down (i.e. remove the last digit of $$$b$$$), and repeat the...
Print the answer to this problem in decimal notation modulo $$$998244353$$$.
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the length of $$$a$$$ and the length of $$$b$$$ correspondingly. The second line of the input contains one huge integer $$$a$$$. It is guaranteed that this number consists of exactly $$$n$$$ zeroes and ones and t...
standard output
standard input
PyPy 3
Python
1,700
train_008.jsonl
0af6a82bceb4fc9cdaa52febaa7c4160
256 megabytes
["4 4\n1010\n1101", "4 5\n1001\n10101"]
PASSED
def main(): n, m = [int(c) for c in input().split()] a, b = input(), input() mod = 998244353 N = 300009 if n < m: a = '0' * (m - n) + a elif m < n: b = '0' * (n - m) + b n = max(n, m) one = [b[0] == '1'] for i in range(1, n): one.append(one[-1] + (b[i] == '...
1539354900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["4", "528", "63"]
268f90d0595f7c51fb336ce377409dde
NoteIn the first case, there are four possible ways to make a number that is divisible by 5: 5, 15, 25 and 125.In the second case, remember to concatenate the copies of a. The actual plate is 1399013990.In the third case, except deleting all digits, any choice will do. Therefore there are 26 - 1 = 63 possible ways to d...
There is a long plate s containing n digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting number may contain leading zeros.Now Iahub wants to count the number of ways h...
Print a single integer — the required number of ways modulo 1000000007 (109 + 7).
In the first line you're given a string a (1 ≤ |a| ≤ 105), containing digits only. In the second line you're given an integer k (1 ≤ k ≤ 109). The plate s is formed by concatenating k copies of a together. That is n = |a|·k.
standard output
standard input
Python 3
Python
1,700
train_015.jsonl
036201488c1d3ed9cb8bb8f0413b6472
256 megabytes
["1256\n1", "13990\n2", "555\n2"]
PASSED
t, k = input(), int(input()) s, n, d = 0, 1, 1000000007 for i in t: if i in '05': s += n n = (n << 1) % d p = (pow(n, k, d) - 1) * pow(n - 1, d - 2, d) print(((p % d) * (s % d)) % d) # Made By Mostafa_Khaled
1372941000
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1", "2", "4"]
b2bc51df4a2c05c56c211e8f33fe1b45
NoteIn the first sample n = 2 is a beautiful number.In the second sample n = 7 and Valera can decompose it into sum 23 + ( - 20).In the third sample n = 109 can be decomposed into the sum of four summands as follows: 27 + ( - 24) + ( - 22) + 20.
Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k ≥ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible. Help Valera and find, how many numb...
Print a single integer — the minimum amount of beautiful numbers that give a total of n.
The first line contains string s (1 ≤ |s| ≤ 106), that is the binary representation of number n without leading zeroes (n &gt; 0).
standard output
standard input
Python 3
Python
1,900
train_044.jsonl
76c3466abdc3b452cf7ffb1b0c53bd4a
256 megabytes
["10", "111", "1101101"]
PASSED
t = input() j = t[0] d, s = 0, int(j) for i in t[1: ]: if j != i: if d == 1: d, s = 0, s + 1 else: d = 1 j = i else: d = 1 print(s + (d and j == '1'))
1362411000
[ "number theory", "games" ]
[ 1, 0, 0, 0, 1, 0, 0, 0 ]
1 second
["YES", "NO"]
99f37936b243907bf4ac1822dc547a61
NoteIn the first example Vasya needs to erase the second character. Then Petya cannot erase a character from the remaining string 880011223344 so that it does not become a telephone number.In the second example after Vasya's turn Petya can erase one character character 8. The resulting string can't be a telephone numbe...
A telephone number is a sequence of exactly $$$11$$$ digits such that its first digit is 8.Vasya and Petya are playing a game. Initially they have a string $$$s$$$ of length $$$n$$$ ($$$n$$$ is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a char...
If Vasya has a strategy that guarantees him victory, print YES. Otherwise print NO.
The first line contains one integer $$$n$$$ ($$$13 \le n &lt; 10^5$$$, $$$n$$$ is odd) — the length of string $$$s$$$. The second line contains the string $$$s$$$ ($$$|s| = n$$$) consisting only of decimal digits.
standard output
standard input
PyPy 2
Python
1,200
train_002.jsonl
cc1d033ffd1653e8fa0ed051cc3133d9
256 megabytes
["13\n8380011223344", "15\n807345619350641"]
PASSED
n=int(raw_input()) s=list(raw_input()) cnt=n-11 cntt=[0 for i in xrange(10)] for i in xrange(n): cntt[int(s[i])] += 1 if cntt[8] <= cnt/2: print "NO" else: summ=0 for i in xrange(n): if s[i] == "8": summ += 1 s[i]='0' if summ == cnt/2: break flag =...
1555943700
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
1 second
["0\n-1\n2\n-1\n-1\n12\n36"]
3ae468c425c7b156983414372fd35ab8
NoteConsider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer $$$15116544$$$: Divide by $$$6$$$ and get $$$2519424$$$; divide by $$$6$$$ and get $$$419904$$$; divide by $$$6$$$ and get $$$69984$$$; divide by $$$6$$$ and get $$$11664$$$; multip...
You are given an integer $$$n$$$. In one move, you can either multiply $$$n$$$ by two or divide $$$n$$$ by $$$6$$$ (if it is divisible by $$$6$$$ without the remainder).Your task is to find the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ or determine if it's impossible to do that.You have to answer $$...
For each test case, print the answer — the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ if it's possible to do that or -1 if it's impossible to obtain $$$1$$$ from $$$n$$$.
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$).
standard output
standard input
Python 3
Python
900
train_002.jsonl
0c55656e8cbd4ebdac8e5788ee7e3f29
256 megabytes
["7\n1\n2\n3\n12\n12345\n15116544\n387420489"]
PASSED
for i in range (int(input())): n=int(input()) j=0;k=0 while n % 6 == 0: n/=6 j=j+1 while n % 3 == 0: n/=3 k=k+1 if n!=1: print(-1) else:print(j+2*k)
1593354900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["99\n0"]
53975eea2503bb47bfd0a5119406aea3
NoteIn the first test case, you can, for example, increase $$$p_0$$$ by $$$50$$$ and $$$p_1$$$ by $$$49$$$ and get array $$$[20150, 50, 202, 202]$$$. Then you get the next inflation coefficients: $$$\frac{50}{20150} \le \frac{1}{100}$$$; $$$\frac{202}{20150 + 50} \le \frac{1}{100}$$$; $$$\frac{202}{20200 + 202} \le...
You have a statistic of price changes for one product represented as an array of $$$n$$$ positive integers $$$p_0, p_1, \dots, p_{n - 1}$$$, where $$$p_0$$$ is the initial price of the product and $$$p_i$$$ is how the price was increased during the $$$i$$$-th month.Using these price changes you are asked to calculate t...
For each test case, print the minimum total sum of changes you need to make all inflation coefficients not more than $$$k$$$ %.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 100$$$; $$$1 \le k \le 100$$$) — the length of array $$$p$$$ and coefficient $$$k$$$. The second line of each test case contain...
standard output
standard input
PyPy 3-64
Python
1,300
train_102.jsonl
18bbd696c53ac0fa40a25b6869c381fb
256 megabytes
["2\n4 1\n20100 1 202 202\n3 100\n1 1 1"]
PASSED
#import io, os #input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline import math t = int(input()) for _ in range(t): n, k = map(int,input().split()) k = k arr = list(map(int,input().split())) running_total = arr[0] ans = 0 for i in range(1,len(arr)): if (arr[i] / running...
1611930900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2012-03-16 16:16:43", "-1", "2012-03-17 00:00:00"]
c3f671243f0aef7b78a7e091b0e8f75e
null
You've got a list of program warning logs. Each record of a log stream is a string in this format: "2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes). String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters "!", ".", ",", "?". String "2012-MM-DD" determines a correct date in the yea...
If there is no sought moment of time, print -1. Otherwise print a string in the format "2012-MM-DD HH:MM:SS" (without the quotes) — the first moment of time when the number of warnings for the last n seconds got no less than m.
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 10000). The second and the remaining lines of the input represent the log stream. The second line of the input contains the first record of the log stream, the third line contains the second record and so on. Each record of the log st...
standard output
standard input
Python 2
Python
2,000
train_012.jsonl
6dfed102eff84baaf1c4af6a008100a9
256 megabytes
["60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: Timeout detected", "1 2\n2012-03-16 23:59:59:Disk size\n2012-03-17 00:00:00: Network\n2...
PASSED
import sys,time,re n,m=map(int,raw_input().split()) t=[] i=j=0 for s in sys.stdin: t+=[time.mktime(map(int,re.split('[-: ]',s[:19]))+[0]*3)] while j<i and t[j]<=t[i]-n:j+=1 i+=1 if i-j>=m: print s[:19] exit() print -1
1353339000
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["MULTIPLE", "NONE", "UNIQUE\nSSSSSSSSSS\nSGGGGGGGGS\nSGSSSSSSGS\nSGSGGGGSGS\nSGSGSSGSGS\nSGSGSSGSGS\nSGSGGGGSGS\nSGSSSSSSGS\nSGGGGGGGGS\nSSSSSSSSSS", "NONE"]
4425c6660c9e9c037e32c2e1c081b9c1
NoteFor the first test case, Omkar can make the mastapeecesSSSSSGGSSGGSSSSSand SSGGSSGGGGSSGGSS.For the second test case, it can be proven that it is impossible for Omkar to add tiles to create a mastapeece.For the third case, it can be proven that the given mastapeece is the only mastapeece Omkar can create by adding ...
Omkar is creating a mosaic using colored square tiles, which he places in an $$$n \times n$$$ grid. When the mosaic is complete, each cell in the grid will have either a glaucous or sinoper tile. However, currently he has only placed tiles in some cells. A completed mosaic will be a mastapeece if and only if each tile ...
On the first line, print UNIQUE if there is a unique way to get a mastapeece, NONE if Omkar cannot create any, and MULTIPLE if there is more than one way to do so. All letters must be uppercase. If you print UNIQUE, then print $$$n$$$ additional lines with $$$n$$$ characters in each line, such that the $$$i$$$-th chara...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 2000$$$). Then follow $$$n$$$ lines with $$$n$$$ characters in each line. The $$$i$$$-th character in the $$$j$$$-th line corresponds to the cell in row $$$i$$$ and column $$$j$$$ of the grid, and will be $$$S$$$ if Omkar has placed a sinoper tile in th...
standard output
standard input
PyPy 3
Python
3,500
train_096.jsonl
2b789c313224ccc55157a487155d383c
256 megabytes
["4\nS...\n..G.\n....\n...S", "6\nS.....\n....G.\n..S...\n.....S\n....G.\nG.....", "10\n.S....S...\n..........\n...SSS....\n..........\n..........\n...GS.....\n....G...G.\n..........\n......G...\n..........", "1\n."]
PASSED
import sys o = {'G':'S', 'S':'G'} n = int(sys.stdin.readline()) d = [list(sys.stdin.readline()[:n]) for _ in range(n)] f = [1]*(n*n) finished = 1 def none(): print('NONE'); sys.exit() def printd(): print('\n'.join(''.join(d[i]) for i in range(n))) if n % 2: none() x = ['']*(n//2) def findt(i,j): return abs(j-...
1634468700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["42", "28"]
e6689123fefea251555e0e096f58f6d1
NoteIn the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: Tetrahedron. Tetrahedron has 4 triangular faces. Cube. Cube has 6 square faces. Octahedron. Octahedron has 8 triangular faces. Dodecahedron. Dodecahedron has 12 pentagonal faces. Icosahedron. Icosah...
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of polyhedrons in Anton's collection. Each of the following n lines of the input contains a string si — the name of the i-th polyhedron in Anton's collection. The string can look like this: "Tetrahedron" (without quotes), if the i-...
standard output
standard input
Python 3
Python
800
train_010.jsonl
5f5b99a7173786f22366e38943303554
256 megabytes
["4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "3\nDodecahedron\nOctahedron\nOctahedron"]
PASSED
n = int(input()) k = 0 i = 0 while i != n: x = str(input()) if x == 'Tetrahedron': k += 4 if x == 'Cube': k += 6 if x == 'Octahedron': k += 8 if x == 'Dodecahedron': k += 12 if x == 'Icosahedron': k += 20 i += 1 print(k) # 374 ms по слову for # 390 ms...
1489590300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["YES\nYES\nNO\nNO"]
a27ad7c21cd6402bfd082da4f6c7ab9d
NoteIn the first test case there is the following sequence of operation: $$$s = $$$ ab, $$$t = $$$ acxb, $$$p = $$$ cax; $$$s = $$$ acb, $$$t = $$$ acxb, $$$p = $$$ ax; $$$s = $$$ acxb, $$$t = $$$ acxb, $$$p = $$$ a. In the second test case there is the following sequence of operation: $$$s = $$$ a, $$$t = $$$ aa...
You are given three strings $$$s$$$, $$$t$$$ and $$$p$$$ consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.During each operation you choose any character from $$$p$$$, erase it from $$$p$$$ and insert it into string $$$s$$$ (you may insert this character anyw...
For each query print YES if it is possible to make $$$s$$$ equal to $$$t$$$, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is represented by three consecutive lines. The first line of each query contains the string $$$s$$$ ($$$1 \le |s| \le 100$$$) consisting of lowercase Latin letters. The second line of each query contains the string $...
standard output
standard input
Python 3
Python
1,300
train_008.jsonl
5260e723c4bf71ec0f83d3cc18495056
256 megabytes
["4\nab\nacxb\ncax\na\naaaa\naaabbcc\na\naaaa\naabbcc\nab\nbaaa\naaaaa"]
PASSED
t=int(input()) for _ in range(t): s=input() t=input() p=input() if(len(t)<len(s)): print('NO') elif(len(t)==len(s)): if(t==s): print('YES') else: print('NO') else: j=0 c=0 for i in s: while(j<len(t)): ...
1563115500
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["1 0", "4 14", "0 8"]
1e6d7ec8023eb0dc482b1f133e5dfe2a
NoteIn the first sample it is optimal to leave the array as it is by choosing $$$x = 0$$$.In the second sample the selection of $$$x = 14$$$ results in $$$b$$$: $$$[4, 9, 7, 4, 9, 11, 11, 13, 11]$$$. It has $$$4$$$ inversions: $$$i = 2$$$, $$$j = 3$$$; $$$i = 2$$$, $$$j = 4$$$; $$$i = 3$$$, $$$j = 4$$$; $$$i = 8$$$...
You are given an array $$$a$$$ consisting of $$$n$$$ non-negative integers. You have to choose a non-negative integer $$$x$$$ and form a new array $$$b$$$ of size $$$n$$$ according to the following rule: for all $$$i$$$ from $$$1$$$ to $$$n$$$, $$$b_i = a_i \oplus x$$$ ($$$\oplus$$$ denotes the operation bitwise XOR).A...
Output two integers: the minimum possible number of inversions in $$$b$$$, and the minimum possible value of $$$x$$$, which achieves those number of inversions.
First line contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in $$$a$$$. Second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$0 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.
standard output
standard input
PyPy 2
Python
2,000
train_006.jsonl
651a581141808334f7590ad06be54f47
512 megabytes
["4\n0 1 3 2", "9\n10 7 9 10 7 5 5 3 5", "3\n8 10 3"]
PASSED
#!/usr/bin/env python from __future__ import division, print_function import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def main(): n = int(input()) l = list(map(int, i...
1601219100
[ "math", "strings", "trees" ]
[ 0, 0, 0, 1, 0, 0, 1, 1 ]
1 second
["4", "5"]
0151a87d0f82a9044a0ac8731d369bb9
NoteIn the first sample, Vasya can obtain both strings "aaaa" and "bbbb".In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.Vasya can change no more than k characters of the original string. Wha...
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only.
standard output
standard input
Python 3
Python
1,500
train_003.jsonl
e312b5d158a67e1ee59db648b992aca9
256 megabytes
["4 2\nabba", "8 1\naabaabaa"]
PASSED
def getMax(s,i,j,t,k,n): res = 0 count = 0 while i<n : while j<n and count<k: if s[j]!=t: count+=1 j+=1 while j<n and s[j]==t: j+=1 res = max(res,j-i) while i<n and s[i]==t: i+=1 if i<n : i+=...
1464188700
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["4", "1", "0"]
d98ecf6c5550e7ec7639fcd1f727fb35
null
Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you should print the value modulo 109 + 7 (the remainder when divided by 109 + 7).The modulo operator a mod b stands for the remainder after dividing a by b. For example 10 mod 3 = 1.
Print integer s — the value of the required sum modulo 109 + 7.
The only line contains two integers n, m (1 ≤ n, m ≤ 1013) — the parameters of the sum.
standard output
standard input
PyPy 2
Python
2,200
train_023.jsonl
afcf7d0217b0f37d409716fd8e633984
256 megabytes
["3 4", "4 4", "1 1"]
PASSED
n,m = map(int,raw_input().split(" ")) ans = 0 w = 1000000007 if m > n: ans += n*(m-n) m = n last = min(m,n-1) def su(s,e,l): return (s+e)*l/2 for i in xrange(2,900000): q = n/i if q >= last: continue ans += (n%last+n%(q+1))*(last-q)/2 last = q ans %= w for i in xrange(1,last+1): ans += n%i ans %= w print...
1452524400
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
3 seconds
["3", "0"]
3dc14d8d19938d9a5ed8323fe608f581
null
You are given $$$n$$$ segments on a number line, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th segments covers all integer points from $$$l_i$$$ to $$$r_i$$$ and has a value $$$w_i$$$.You are asked to select a subset of these segments (possibly, all of them). Once the subset is selected, it's possible to travel betw...
Print a single integer — the minimum cost of a good subset.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$2 \le m \le 10^6$$$) — the number of segments and the number of integer points. Each of the next $$$n$$$ lines contains three integers $$$l_i$$$, $$$r_i$$$ and $$$w_i$$$ ($$$1 \le l_i &lt; r_i \le m$$$; $$$1 \le w_i \le 10^6$$$...
standard output
standard input
PyPy 3-64
Python
2,100
train_088.jsonl
5ddb90d6a6d600f3803336cf0ac1b199
256 megabytes
["5 12\n1 5 5\n3 4 10\n4 10 6\n11 12 5\n10 12 3", "1 10\n1 10 23"]
PASSED
import bisect import sys input = sys.stdin.readline from collections import defaultdict, deque from itertools import permutations, accumulate from functools import reduce p = print r = range def I(): return int(input()) def II(): return list(map(int, input().split())) def S(): return input()[:-1] def M(n): r...
1627655700
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["1\n2\n2\n5\n8"]
19df5f3b8b31b763162c5331c1499529
NotePossible optimal arrangement of the lanterns for the $$$2$$$-nd test case of input data example: Possible optimal arrangement of the lanterns for the $$$3$$$-rd test case of input data example:
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.The park is a rectangular table with $$$n$$$ rows and $$$m$$$ columns, where the ce...
Print $$$t$$$ answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$n$$$, $$$m$$$ ($$$1 \le n, m \le 10^4$$$) — park sizes.
standard output
standard input
Python 3
Python
800
train_018.jsonl
8e580289d2bb2743d731f11fc13766b0
256 megabytes
["5\n1 1\n1 3\n2 2\n3 3\n5 3"]
PASSED
for _ in range(int(input())): n,m=map(int,input().split()) s=n*m if s%2==0: print(int(m*n/2)) else: print(int(m*n//2)+1)
1590503700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1 2 2 3 3 3", "-1"]
7dea96a7599946a5b5d0b389c7e76651
NoteIn the first example, if $$$v_{1} = \{ 1 \}$$$, $$$v_{2} = \{ 2, 3 \}$$$, and $$$v_{3} = \{ 4, 5, 6 \}$$$ then vertex sets will satisfy all conditions. But you can assign vertices to vertex sets in a different way; Other answers like "2 3 3 1 1 1" will be accepted as well. In the second example, it's impossible to...
You have a simple undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.Let's make a definition.Let $$$v_1$$$ and $$$v_2$$$ be two some nonempty subsets of vertices that do not in...
If the answer exists, print $$$n$$$ integers. $$$i$$$-th integer means the vertex set number (from $$$1$$$ to $$$3$$$) of $$$i$$$-th vertex. Otherwise, print $$$-1$$$. If there are multiple answers, print any.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 10^{5}$$$, $$$0 \le m \le \text{min}(3 \cdot 10^{5}, \frac{n(n-1)}{2})$$$) — the number of vertices and edges in the graph. The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$a_{i}$$$ and $$$b_{i}$$$ ($$$1 \le a_{i} \lt b_{i} \le n$...
standard output
standard input
Python 3
Python
1,900
train_000.jsonl
9c372f74ccc3656797e5d61fdee09156
256 megabytes
["6 11\n1 2\n1 3\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4"]
PASSED
# https://codeforces.com/contest/1228/problem/D # all neightbor in group --> pass 1 # all neighbor not in group --> merge 0 # invalid 2 # WA def type_(list_v, group): cnt_0 = 0 cnt_1 = 0 for v in list_v: if v in group: cnt_1 += 1 else: cnt_0 += 1 ...
1569762300
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["3\n2\n2\n2\n1\n2\n1\n1\n1\n0"]
db473ad780a93983667d12b1357c6e2f
NoteLet's consider the state of the string after each query: $$$s =$$$ "abcabcabc". In this case $$$3$$$ replacements can be performed to get, for instance, string $$$s =$$$ "bbcaccabb". This string does not contain "abc" as a substring. $$$s =$$$ "bbcabcabc". In this case $$$2$$$ replacements can be performed to get...
Before becoming a successful trader William got a university degree. During his education an interesting situation happened, after which William started to listen to homework assignments much more attentively. What follows is the correct formal description of the homework assignment:You are given a string $$$s$$$ of ...
For each query output the minimal number of characters that would have to be replaced so that the string doesn't contain "abc" as a substring.
The first line contains two integers $$$n$$$ and $$$q$$$ $$$(1 \le n, q \le 10^5)$$$, the length of the string and the number of queries, respectively. The second line contains the string $$$s$$$, consisting of characters "a", "b" and "c". Each of the next $$$q$$$ lines contains an integer $$$i$$$ and character $$$c$$$...
standard output
standard input
PyPy 3-64
Python
1,100
train_110.jsonl
711ec2f0e5300d8273b52a74ad3add05
256 megabytes
["9 10\nabcabcabc\n1 a\n1 b\n2 c\n3 a\n4 b\n5 c\n8 a\n9 b\n1 c\n4 a"]
PASSED
from sys import stdin,stdout import re n,m=map(int,input().split()) s=list(input()) k="".join(s) l=k.count("abc") for i in range(m): j,x=map(str,input().split()) j=int(j)-1 if(s[j]==x): stdout.write(str(l)+"\n") continue if(j+2<n and s[j]=="a" and s[j+1]=="b" and s[j+2]=="c")...
1638110100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["1000100010", "1001101000", "No"]
61a067dc6b8e04bfc661b7fa9ecb4eda
NoteIn the first example, $$$7$$$ is not a period of the resulting string because the $$$1$$$-st and $$$8$$$-th characters of it are different.In the second example, $$$6$$$ is not a period of the resulting string because the $$$4$$$-th and $$$10$$$-th characters of it are different.In the third example, $$$9$$$ is alw...
Walking along a riverside, Mino silently takes a note of something."Time," Mino thinks aloud."What?""Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this.""And what are you recording?""You see it, tide. Everything has its own period, and I think I've figured out this...
Output one line — if it's possible that $$$p$$$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
The first line contains two space-separated integers $$$n$$$ and $$$p$$$ ($$$1 \leq p \leq n \leq 2000$$$) — the length of the given string and the supposed period, respectively. The second line contains a string $$$s$$$ of $$$n$$$ characters — Mino's records. $$$s$$$ only contains characters '0', '1' and '.', and cont...
standard output
standard input
Python 2
Python
1,200
train_013.jsonl
73fdf29e6f43bb412031c11c7f8b9741
256 megabytes
["10 7\n1.0.1.0.1.", "10 6\n1.0.1.1000", "10 9\n1........1"]
PASSED
entrada = raw_input().split() p = int(entrada[1]) abc = raw_input() s = list(abc) ans = True #print s for i in xrange(len(s)): if i + p >= len(s): break #print s[i], s[i + p] if s[i] == "." and s[i + p] == ".": s[i] = "0" s[i + p] = "1" ans = False elif s[i] != s[i + p]: if s[i] == "1": s[i + p] == ...
1528724100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
4 seconds
["2", "-1", "0", "3"]
56b207a6d280dc5ea39ced365b402a96
NoteIn the first sample test, Okabe can take the path , paying only when moving to (2, 3) and (4, 4).In the fourth sample, Okabe can take the path , paying when moving to (1, 2), (3, 4), and (5, 4).
Okabe likes to be able to walk through his city on a path lit by street lamps. That way, he doesn't get beaten up by schoolchildren.Okabe's city is represented by a 2D grid of cells. Rows are numbered from 1 to n from top to bottom, and columns are numbered 1 to m from left to right. Exactly k cells in the city are lit...
Print the minimum number of coins Okabe needs to pay to complete his walk, or -1 if it's not possible.
The first line of input contains three space-separated integers n, m, and k (2 ≤ n, m, k ≤ 104). Each of the next k lines contains two space-separated integers ri and ci (1 ≤ ri ≤ n, 1 ≤ ci ≤ m) — the row and the column of the i-th lit cell. It is guaranteed that all k lit cells are distinct. It is guaranteed that the ...
standard output
standard input
Python 2
Python
2,200
train_062.jsonl
e824cc9dbd2407eff33fca75ac9e0e47
256 megabytes
["4 4 5\n1 1\n2 1\n2 3\n3 3\n4 3", "5 5 4\n1 1\n2 1\n3 1\n3 2", "2 2 4\n1 1\n1 2\n2 1\n2 2", "5 5 4\n1 1\n2 2\n3 3\n4 4"]
PASSED
from sys import stdin from collections import deque def main(): n, m, k = map(int, stdin.readline().split()) a = [map(int, stdin.readline().split()) for _ in xrange(k)] row = [dict() for i in xrange(n + 10)] col = [dict() for i in xrange(m + 10)] inf = 10010001 d = [inf] * k q = [] pu = ...
1498401300
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["5\n10\n5\n2\n5\n3\n1\n0", "49\n35\n24\n29\n49\n39\n31\n23\n29\n27", "1332632508\n1333333000"]
c72b1a45f5cf80a31c239cf1409c0104
null
You are given a matrix, consisting of $$$n$$$ rows and $$$m$$$ columns. The rows are numbered top to bottom, the columns are numbered left to right.Each cell of the matrix can be either free or locked.Let's call a path in the matrix a staircase if it: starts and ends in the free cell; visits only free cells; has on...
Print $$$q$$$ integers — the $$$i$$$-th value should be equal to the number of different staircases after $$$i$$$ queries. Two staircases are considered different if there exists such a cell that appears in one path and doesn't appear in the other path.
The first line contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$1 \le n, m \le 1000$$$; $$$1 \le q \le 10^4$$$) — the sizes of the matrix and the number of queries. Each of the next $$$q$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x \le n$$$; $$$1 \le y \le m$$$) — the description of each query...
standard output
standard input
Python 3
Python
2,100
train_090.jsonl
413ca9100c30f80ee9eaf5cb2abae5fe
256 megabytes
["2 2 8\n1 1\n1 1\n1 1\n2 2\n1 1\n1 2\n2 1\n1 1", "3 4 10\n1 4\n1 2\n2 3\n1 2\n2 3\n3 2\n1 3\n3 4\n1 3\n3 1", "1000 1000 2\n239 634\n239 634"]
PASSED
class SplayTree(): def __init__(self): self.children={} self.parents={} self.root=None def insert(self, x): if self.root is None: self.root=x self.children[x]=[None,None] self.parents[x]=None else: curr = self.root while True: if curr == x: self.splay(x) return No...
1633856700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["5", "2"]
7b56edf7cc71a1b3e39b3057a4387cad
NoteIn the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.In the second sample, Kevin can flip the entire string and still have the same score.
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.However, all is not l...
Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.
The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000). The following line contains a binary string of length n representing Kevin's results on the USAICO.
standard output
standard input
Python 3
Python
1,600
train_004.jsonl
8d06b5826ffd382a4a7a37ee3ed10469
256 megabytes
["8\n10000011", "2\n01"]
PASSED
n = int(input()) t = [int(i) for i in input()] ch = 0 sm = 0 for i in range(n-1): if t[i] == t[i+1]: sm+=1 else: ch+=1 print(ch + min(sm,2) + 1)
1448984100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["8\n19"]
00b1e45e9395d23e850ce1a0751b8378
NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$.
You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \right...
For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$).
standard output
standard input
Python 3
Python
900
train_019.jsonl
1e3f3ddc813e321a7fc03e354a546f31
256 megabytes
["2\n59 3\n1000000000000000000 10"]
PASSED
t=int(input()) for _ in range(t): n,k = map(int,input().split()) counter=0 while(n!=0): if(n%k==0): n=n//k counter+=1 else: counter+=(n%k) n=n-(n%k) print(int(counter))
1559745300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["0001111111\n001\n01\n0\n1"]
bb071f1f4fc1c129a32064c1301f4942
NoteIn the first test case, Lee can't perform any moves.In the second test case, Lee should erase $$$s_2$$$.In the third test case, Lee can make moves, for example, in the following order: 11001101 $$$\rightarrow$$$ 1100101 $$$\rightarrow$$$ 110101 $$$\rightarrow$$$ 10101 $$$\rightarrow$$$ 1101 $$$\rightarrow$$$ 101 $$...
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...The string $$$s$$$ he found is a binary string of length $$$n$$$ (i. e. string consists only of 0-s and 1-s).In one move he can choose two consecutive characters $$$s...
Print $$$t$$$ answers — one per test case. The answer to the $$$i$$$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
The first line contains the integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$2t$$$ lines contain test cases — one per two lines. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the string $$$s$$$. The second line contains the binary str...
standard output
standard input
PyPy 3
Python
1,200
train_002.jsonl
6d75cb443fc90476dfd18173d04668c7
256 megabytes
["5\n10\n0001111111\n4\n0101\n8\n11001101\n10\n1110000000\n1\n1"]
PASSED
from sys import stdin from collections import deque # https://codeforces.com/contest/1354/status/D mod = 10**9 + 7 import sys import random # sys.setrecursionlimit(10**6) from queue import PriorityQueue from collections import Counter as cc # def rl(): # return [int(w) for w in stdin.readline().split()] from bisect...
1592921100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]