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\n0\n2\n3\n5\n141\n53384\n160909\n36"]
efdb966e414050c5e51e8beb7bb06b20
NoteIn the first test case, the only special pair is $$$(3, 2)$$$.In the second test case, there are no special pairs.In the third test case, there are two special pairs: $$$(3, 2)$$$ and $$$(4, 3)$$$.
A pair of positive integers $$$(a,b)$$$ is called special if $$$\lfloor \frac{a}{b} \rfloor = a \bmod b$$$. Here, $$$\lfloor \frac{a}{b} \rfloor$$$ is the result of the integer division between $$$a$$$ and $$$b$$$, while $$$a \bmod b$$$ is its remainder.You are given two integers $$$x$$$ and $$$y$$$. Find the number of...
For each test case print the answer on a single line.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The only line of the description of each test case contains two integers $$$x$$$, $$$y$$$ ($$$1 \le x,y \le 10^9$$$).
standard output
standard input
Python 3
Python
1,700
train_092.jsonl
a4e271d3387f754cea40c0432268f71d
256 megabytes
["9\n3 4\n2 100\n4 3\n50 3\n12 4\n69 420\n12345 6789\n123456 789\n12345678 9"]
PASSED
for test_case in range(int(input())): x,y = map(int,input().split()) res = 0 k = 1 while k*(k+1) < x and k < y: res += min(y,x//k-1)-k k += 1 print(res)
1613141400
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["3\n1\n7"]
ce9a0649ccfc956559254f324dfa02a7
NoteFor the first integer the optimal choice is $$$b = 1$$$, then $$$a \oplus b = 3$$$, $$$a \&gt; \&amp; \&gt; b = 0$$$, and the greatest common divisor of $$$3$$$ and $$$0$$$ is $$$3$$$.For the second integer one optimal choice is $$$b = 2$$$, then $$$a \oplus b = 1$$$, $$$a \&gt; \&amp; \&gt; b = 2$$$, and the great...
Can the greatest common divisor and bitwise operations have anything in common? It is time to answer this question.Suppose you are given a positive integer $$$a$$$. You want to choose some integer $$$b$$$ from $$$1$$$ to $$$a - 1$$$ inclusive in such a way that the greatest common divisor (GCD) of integers $$$a \oplus ...
For each integer, print the answer in the same order as the integers are given in input.
The first line contains an integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of integers you need to compute the answer for. After that $$$q$$$ integers are given, one per line: $$$a_1, a_2, \ldots, a_q$$$ ($$$2 \le a_i \le 2^{25} - 1$$$) — the integers you need to compute the answer for.
standard output
standard input
Python 3
Python
1,500
train_005.jsonl
c601e61ffe1146b3139782c911890e37
256 megabytes
["3\n2\n3\n5"]
PASSED
# -*- coding: utf-8 -*- """ Created on Sun Oct 4 06:35:25 2020 @author: Dark Soul """ import math q=int(input('')) for _ in range(q): n=int(input('')) ans=-1 if n&(n+1)==0: for i in range(2,int(math.sqrt(n))+1): if n%i==0: ans=n//i break if ans==...
1549546500
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["9\n6\n1", "225\n2001\n6014\n6939"]
6def7ffa0989d5c5bcab3ac456b231fb
NoteIn the example test, $$$n=2$$$. Thus, there are $$$3$$$ pigs at minute $$$1$$$, and $$$6$$$ pigs at minute $$$2$$$. There are three queries: $$$x=1$$$, $$$x=5$$$, and $$$x=6$$$.If the wolf wants to eat $$$1$$$ pig, he can do so in $$$3+6=9$$$ possible attack plans, depending on whether he arrives at minute $$$1$$$ ...
Three little pigs from all over the world are meeting for a convention! Every minute, a triple of 3 new pigs arrives on the convention floor. After the $$$n$$$-th minute, the convention ends.The big bad wolf has learned about this convention, and he has an attack plan. At some minute in the convention, he will arrive a...
You should print $$$q$$$ lines, with line $$$i$$$ representing the number of attack plans if the wolf wants to eat $$$x_i$$$ pigs. Since each query answer can be large, output each answer modulo $$$10^9+7$$$.
The first line of input contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^6$$$, $$$1 \le q \le 2\cdot 10^5$$$), the number of minutes the convention lasts and the number of queries the wolf asks. Each of the next $$$q$$$ lines contains a single integer $$$x_i$$$ ($$$1 \le x_i \le 3n$$$), the number of pigs t...
standard output
standard input
PyPy 3
Python
2,500
train_083.jsonl
6ebee54968ad72be04e37731346968e1
512 megabytes
["2 3\n1\n5\n6", "5 4\n2\n4\n6\n8"]
PASSED
import sys import __pypy__ int_add = __pypy__.intop.int_add int_sub = __pypy__.intop.int_sub int_mul = __pypy__.intop.int_mul def make_mod_mul(mod=10**9 + 7): fmod_inv = 1.0 / mod def mod_mul(a, b, c=0): res = int_sub(int_add(int_mul(a, b), c), int_mul(mod, int(fmod_inv * a * b + fmod_inv * c))) ...
1627828500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["4 2 0", "16 9", "9999800001"]
faf1abdeb6f0cf34972d5cb981116186
NoteOn the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack.
Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook ...
Print m integer, the i-th of them should be equal to the number of cells that are not under attack after first i rooks are put.
The first line of the input contains two integers n and m (1 ≤ n ≤ 100 000, 1 ≤ m ≤ min(100 000, n2)) — the size of the board and the number of rooks. Each of the next m lines contains integers xi and yi (1 ≤ xi, yi ≤ n) — the number of the row and the number of the column where Vasya will put the i-th rook. Vasya put...
standard output
standard input
Python 3
Python
1,200
train_012.jsonl
65687845e1fa13e5cf9e419a39b69bdf
256 megabytes
["3 3\n1 1\n3 1\n2 2", "5 2\n1 5\n5 1", "100000 1\n300 400"]
PASSED
n, m = map(int, input().split()) ans = [n ** 2] rows, cols = set(), set() for i in range(m): x, y = map(int, input().split()) res = ans[-1] if x not in rows: res -= (n - len(cols)) rows.add(x) if y not in cols: res -= (n - len(rows)) cols.add(y) ans.append(res) prin...
1469205300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["6", "0", "2"]
f44041707694eece7de0cc7c087f57d9
NoteIn the first example, you can set $$$a_{1, 1} := 7, a_{1, 2} := 8$$$ and $$$a_{1, 3} := 9$$$ then shift the first, the second and the third columns cyclically, so the answer is $$$6$$$. It can be shown that you cannot achieve a better answer.In the second example, the matrix is already good so the answer is $$$0$$$...
You are given a rectangular matrix of size $$$n \times m$$$ consisting of integers from $$$1$$$ to $$$2 \cdot 10^5$$$.In one move, you can: choose any element of the matrix and change its value to any integer between $$$1$$$ and $$$n \cdot m$$$, inclusive; take any column and shift it one cell up cyclically (see the ...
Print one integer — the minimum number of moves required to obtain the matrix, where $$$a_{1, 1} = 1, a_{1, 2} = 2, \dots, a_{1, m} = m, a_{2, 1} = m + 1, a_{2, 2} = m + 2, \dots, a_{n, m} = n \cdot m$$$ ($$$a_{i, j} = (i - 1)m + j$$$).
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5, n \cdot m \le 2 \cdot 10^5$$$) — the size of the matrix. The next $$$n$$$ lines contain $$$m$$$ integers each. The number at the line $$$i$$$ and position $$$j$$$ is $$$a_{i, j}$$$ ($$$1 \le a_{i, j} \le 2 \cdot 10^5$...
standard output
standard input
PyPy 3
Python
1,900
train_004.jsonl
fd525d26e93ea7482fa829b9eb3250df
256 megabytes
["3 3\n3 2 1\n1 2 3\n4 5 6", "4 3\n1 2 3\n4 5 6\n7 8 9\n10 11 12", "3 4\n1 6 3 4\n5 10 7 8\n9 2 11 12"]
PASSED
import sys input = sys.stdin.readline from collections import * n, m = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(n)] ans = 0 for i in range(m): l = [i+1] for _ in range(n-1): l.append(l[-1]+m) s = set(l) idx = defaultdict(int) for j in ran...
1579703700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
4 seconds
["YES\n3 1\n4 1\n1 2\n5 2\n2 6", "NO", "YES\n2 9\n2 10\n10 3\n3 1\n6 10\n8 2\n4 3\n5 6\n6 7", "YES\n2 5\n7 2\n3 7\n3 1\n1 6\n8 7\n4 3"]
a4849505bca48b408a5e8fb5aebf5cb6
null
You are given three integers $$$n$$$, $$$d$$$ and $$$k$$$.Your task is to construct an undirected tree on $$$n$$$ vertices with diameter $$$d$$$ and degree of each vertex at most $$$k$$$, or say that it is impossible.An undirected tree is a connected undirected graph with $$$n - 1$$$ edges.Diameter of a tree is the max...
If there is no tree satisfying the conditions above, print only one word "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), and then print $$$n - 1$$$ lines describing edges of a tree satisfying the conditions above. Vertices of the tree must be numbered from $$$1$$$ to $$$n$$$. You can pr...
The first line of the input contains three integers $$$n$$$, $$$d$$$ and $$$k$$$ ($$$1 \le n, d, k \le 4 \cdot 10^5$$$).
standard output
standard input
Python 2
Python
2,100
train_002.jsonl
67d367d8f6c84392f200638e9f4aab1b
256 megabytes
["6 3 3", "6 2 3", "10 4 3", "8 5 3"]
PASSED
n,d,k=map(int,raw_input().strip().split()) ans=[] if (d>n-1): print ("NO") exit(0) if (k<2 and n>2): print ("NO") exit(0) l1=[0 for i in range(d+2)] count=d cnt=d+2 def insert(par,v,r,e): global count global cnt if count==n-1: print ("YES") for o in ans: print o[0],o[1] exit(0) else: ans.append([par,...
1530628500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["NO\nYES\nNO\nYES\nYES"]
26354d2628f26eb2eff9432bd46400d5
NoteIn the first test case, $$$n = 1$$$, $$$k_1 = 0$$$ and $$$k_2 = 1$$$. It means that $$$2 \times 1$$$ board has black cell $$$(1, 1)$$$ and white cell $$$(2, 1)$$$. So, you can't place any white domino, since there is only one white cell.In the second test case, the board of the same size $$$2 \times 1$$$, but both ...
You have a board represented as a grid with $$$2 \times n$$$ cells.The first $$$k_1$$$ cells on the first row and first $$$k_2$$$ cells on the second row are colored in white. All other cells are colored in black.You have $$$w$$$ white dominoes ($$$2 \times 1$$$ tiles, both cells are colored in white) and $$$b$$$ black...
For each test case, print YES if it's possible to place all $$$w + b$$$ dominoes on the board and NO, otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — the number of test cases. The first line of each test case contains three integers $$$n$$$, $$$k_1$$$ and $$$k_2$$$ ($$$1 \le n \le 1000$$$; $$$0 \le k_1, k_2 \le n$$$). The second line of each test case contains two integers $$$w$$$ and $$$b$$...
standard output
standard input
Python 3
Python
800
train_104.jsonl
66083bccd6f1853bc132b8d95906a948
256 megabytes
["5\n1 0 1\n1 0\n1 1 1\n0 0\n3 0 0\n1 3\n4 3 1\n2 2\n5 4 3\n3 1"]
PASSED
t=int(input()) for y in range(t): n,k1,k2=map(int,input().split()) w,b=map(int,input().split()) kw=k1+k2 to=kw//2 tob=(n*2-kw)//2 # print(to) if w<=to: # print("this w") w=0 avil=to-w else: # print("w n") print("NO") continu...
1616079000
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["2", "2"]
3cafbcf1a397def07d6a2d1dd5526281
NoteIn the first sample you can delete any two squares that do not share a side. After that the set of painted squares is not connected anymore.The note to the second sample is shown on the figure below. To the left there is a picture of the initial set of squares. To the right there is a set with deleted squares. The ...
You've gotten an n × m sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as A. Set A is connected. Your task is to find the minimum number of squares that we can delete from set A to make it not connected.A set of painted squares is called connected, if for every two squ...
On the first line print the minimum number of squares that need to be deleted to make set A not connected. If it is impossible, print -1.
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the sizes of the sheet of paper. Each of the next n lines contains m characters — the description of the sheet of paper: the j-th character of the i-th line equals either "#", if the corresponding square is painted (belongs to set A),...
standard output
standard input
Python 2
Python
1,700
train_036.jsonl
e9dce08673ebe48f1007ef3c91a107f7
256 megabytes
["5 4\n####\n#..#\n#..#\n#..#\n####", "5 5\n#####\n#...#\n#####\n#...#\n#####"]
PASSED
from sys import setrecursionlimit setrecursionlimit(3000) def main(): n,m = map(int, raw_input().split()) S, total = [], 0 for i in xrange(n): t = map(lambda s: 1 if s == "#" else 0, raw_input()) S.append(t) total += sum(t) if total in (1,2): print -1 retur...
1338737400
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1 second
["7", "105", "761141116"]
40a5e4b4193901cb3004dac24dba1d62
NoteIn the first example, the answer is the sum of the first three numbers written out ($$$1 + 2 + 4 = 7$$$).In the second example, the numbers with numbers from $$$5$$$ to $$$14$$$: $$$5, 7, 9, 6, 8, 10, 12, 14, 16, 18$$$. Their sum is $$$105$$$.
Nazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for his outstanding mathematical abilities. Today a math teacher gave him a very difficult task.Consider two infinite sets of numbers. The first set consists of odd positive numbers ($$$1, 3, 5, 7, \ldots$$$), and the second set consists of ...
Print a single integer — the answer modulo $$$1000000007$$$ ($$$10^9+7$$$).
The first line contains two integers $$$l$$$ and $$$r$$$ ($$$1 \leq l \leq r \leq 10^{18}$$$) — the range in which you need to find the sum.
standard output
standard input
PyPy 2
Python
1,800
train_001.jsonl
2722d2f1479cbd19c93dfd9142a191b1
256 megabytes
["1 3", "5 14", "88005553535 99999999999"]
PASSED
def ways(l): if l == 0: return 0 count = 0 p=l while p>=2: p=p/2 count += 1 odd=count/2 even=count/2 if count%2==1: odd += 1 ans=0 odd_terms=(pow(4,odd)-1)/3 even_terms=(2*(pow(4,even)-1))/3 total=odd_terms+even_terms ans += pow(odd_terms,2...
1555601700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
5 seconds
["3\n\n4\n\n5\n\n\n1\n\n4\n\n6"]
7a9b559eb3b601590e22eb128f2bf307
NoteTest Case 1:In this case, the hidden password is $$$2$$$.The first query is $$$3$$$. It is not equal to the current password. So, $$$0$$$ is returned, and the password is changed to $$$1$$$ since $$$2\oplus_2 1=3$$$.The second query is $$$4$$$. It is not equal to the current password. So, $$$0$$$ is returned, and t...
This is the hard version of the problem. The only difference is that here $$$2\leq k\leq 100$$$. You can make hacks only if both the versions of the problem are solved.This is an interactive problem!Every decimal number has a base $$$k$$$ equivalent. The individual digits of a base $$$k$$$ number are called $$$k$$$-its...
null
The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 10\,000$$$) denoting the number of test cases. $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ ($$$1\leq n\leq 2\cdot 10^5$$$) and $$$k$$$ $$$(2\leq k\leq 100)$$$. It is guaranteed that the sum of $$$n$$$...
standard output
standard input
PyPy 2
Python
2,200
train_091.jsonl
36f6ccc85cec8eb345d82cf04662655e
256 megabytes
["2\n5 2\n\n0\n\n0\n\n1\n5 3\n\n0\n\n0\n\n1"]
PASSED
from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip from bisect import bisect_left as lower_bound, bisect_right as upper_bound ...
1625668500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["2.5000000000", "2.0000000000"]
d79166497eb61d81fdfa4ef80ec1c8e8
NoteConsider the second sample. At d = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
Vanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point l. Then the i-th lantern is at the point ai. The lantern lights all points of the street that are at the ...
Print the minimum light radius d, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 9.
The first line contains two integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 109) — the number of lanterns and the length of the street respectively. The next line contains n integers ai (0 ≤ ai ≤ l). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.
standard output
standard input
PyPy 2
Python
1,200
train_000.jsonl
3bc2feb6d2d9d557e6445f1256210d72
256 megabytes
["7 15\n15 5 3 7 9 14 0", "2 5\n2 5"]
PASSED
y=int(raw_input().split()[1]) b=raw_input().split() for c in range(len(b)): b[c]=int(b[c]) b.sort() p=float(b[0]-0) q=float(y-b[-1]) #print p,q z=0 ans=0 while z+1<=len(b)-1: m=b[z+1]-b[z] if m>ans: ans=m z+=1 ans=ans/2.0 #print ans print max(p,q,ans)
1417451400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["12", "9", "4", "4", "3"]
c9c65223b8575676647fe943f8dff25a
null
You have to restore the wall. The wall consists of $$$N$$$ pillars of bricks, the height of the $$$i$$$-th pillar is initially equal to $$$h_{i}$$$, the height is measured in number of bricks. After the restoration all the $$$N$$$ pillars should have equal heights.You are allowed the following operations: put a brick o...
Print one integer — the minimal cost of restoration.
The first line of input contains four integers $$$N$$$, $$$A$$$, $$$R$$$, $$$M$$$ ($$$1 \le N \le 10^{5}$$$, $$$0 \le A, R, M \le 10^{4}$$$) — the number of pillars and the costs of operations. The second line contains $$$N$$$ integers $$$h_{i}$$$ ($$$0 \le h_{i} \le 10^{9}$$$) — initial heights of pillars.
standard output
standard input
PyPy 3
Python
2,100
train_039.jsonl
138a8320d475768651c6b25222c1b33e
256 megabytes
["3 1 100 100\n1 3 8", "3 100 1 100\n1 3 8", "3 100 100 1\n1 3 8", "5 1 2 4\n5 5 3 6 5", "5 1 2 2\n5 5 3 6 5"]
PASSED
# https://codeforces.com/contest/1355/problem/E import bisect def func(val): cost = 0 toAdd,toRemove = 0,0 lessEqual = bisect.bisect_right(arr,val) greater = n - lessEqual toAdd = (lessEqual * val) - dp[lessEqual] toRemove = (total - dp[lessEqual]) - (greater * val) if toRemove >= toAdd: ...
1589628900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["0", "2 1 3\n\n0"]
aea7e7220a8534c1053e8755a70dd499
NoteWhen $$$n = 3$$$, any John's move can be reversed, thus $$$R(3) = 0$$$, and terminating the game immediately is correct.$$$R(4) = 1$$$, and one strategy to achieve this result is shown in the second sample case.Blank lines in sample interactions are for clarity and should not be printed.
This is an interactive problem.John and his imaginary friend play a game. There are $$$n$$$ lamps arranged in a circle. Lamps are numbered $$$1$$$ through $$$n$$$ in clockwise order, that is, lamps $$$i$$$ and $$$i + 1$$$ are adjacent for any $$$i = 1, \ldots, n - 1$$$, and also lamps $$$n$$$ and $$$1$$$ are adjacent. ...
null
null
standard output
standard input
Python 3
Python
2,600
train_009.jsonl
adc11f1a9809409cbfd0da723c56abc9
512 megabytes
["3", "4\n\n1"]
PASSED
#lizhou n = int(input()) a = [0]*n r = max(int(n-k-n/k+1) for k in range(1, n+1)) for i in range(1, n+1): if int(n-i-n/i+1) == r: k = i break def query(b): for x in b: a[x] = 1 print(k, end = " ") print(*[x+1 for x in b]) x = int(input())-1 for i in range(k): ...
1592491500
[ "math", "games" ]
[ 1, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["4\n0\n1\n14"]
9ca9df1ab3760edb8e7adc3be533c576
NoteIn the first test case, there are three ways to draw the $$$2$$$ additional chords, shown below (black chords are the ones initially drawn, while red chords are the new ones): We see that the third way gives the maximum number of intersections, namely $$$4$$$.In the second test case, there are no more chords to dr...
On a circle lie $$$2n$$$ distinct points, with the following property: however you choose $$$3$$$ chords that connect $$$3$$$ disjoint pairs of points, no point strictly inside the circle belongs to all $$$3$$$ chords. The points are numbered $$$1, \, 2, \, \dots, \, 2n$$$ in clockwise order.Initially, $$$k$$$ chords c...
For each test case, output the maximum number of intersections that can be obtained by drawing $$$n - k$$$ additional chords.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100$$$, $$$0 \le k \le n$$$) — half the number of points and the number of chords initially draw...
standard output
standard input
PyPy 3-64
Python
1,800
train_098.jsonl
34dad85d1d2e8c565c3605b1aa09d1bd
256 megabytes
["4\n4 2\n8 2\n1 5\n1 1\n2 1\n2 0\n10 6\n14 6\n2 20\n9 10\n13 18\n15 12\n11 7"]
PASSED
import sys input = sys.stdin.readline inf = float('inf') def getInt(): return int(input()) def getStr(): return input().strip() def getList(split=True): s = getStr() if split: s = s.split() return map(int, s) t = getInt() # t = 1 def solve(): n, k = getList() a = [sorted(g...
1627223700
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
2 seconds
["ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler", "icm codeforces\nicm technex"]
3c06e3cb2d8468e738b736a9bf88b4ca
NoteIn first example, the killer starts with ross and rachel. After day 1, ross is killed and joey appears. After day 2, rachel is killed and phoebe appears. After day 3, phoebe is killed and monica appears. After day 4, monica is killed and chandler appears.
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.The killer starts with two potential victims on his first day, selects one of these two, kills selected vi...
Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second b...
standard output
standard input
PyPy 2
Python
900
train_005.jsonl
09bab30e474f73e8ae26b4980bbdfffd
256 megabytes
["ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "icm codeforces\n1\ncodeforces technex"]
PASSED
now_list = raw_input().split(' ') n = int(raw_input()) print ' '.join(now_list) for i in xrange(n): x, y = raw_input().split(' ') now_list.remove(x) now_list.append(y) print ' '.join(now_list)
1487861100
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["5\n60\n1439\n1180\n1"]
f4982de28aca7080342eb1d0ff87734c
null
New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh &lt; 24$$$ and $$$0 \le mm &lt; 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You k...
For each test case, print the answer on it — the number of minutes before the New Year.
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) — the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h &lt; 24$$$, $$$0 \le m &lt; 60$$$). It is guaranteed that this time is not ...
standard output
standard input
Python 3
Python
800
train_015.jsonl
55ad85192ed602a3b20444f16f87e522
256 megabytes
["5\n23 55\n23 0\n0 1\n4 20\n23 59"]
PASSED
testCase = int(input()) Output = 0 while testCase != 0: H, Min = map(int, input().split()) if 0 <= H < 24 and 0 <= Min < 60: Output = ((23-H) * 60) + (60 - Min) print(Output) testCase = testCase - 1
1577552700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["First", "First", "Second"]
2de867c08946eade5f674a98b377343d
null
Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players.Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his step player must add a single letter in the end of the word, the resu...
If the player who moves first wins, print "First", otherwise print "Second" (without the quotes).
The first line contains two integers, n and k (1 ≤ n ≤ 105; 1 ≤ k ≤ 109). Each of the next n lines contains a single non-empty string from the given group. The total length of all strings from the group doesn't exceed 105. Each string of the group consists only of lowercase English letters.
standard output
standard input
Python 3
Python
1,900
train_017.jsonl
f9c87f3bd177e15c586a426c71170373
256 megabytes
["2 3\na\nb", "3 1\na\nb\nc", "1 2\nab"]
PASSED
N = 100000 Z = 26 #别用这玩意儿: trie = [[0] * Z] * N 巨坑!https://www.cnblogs.com/PyLearn/p/7795552.html trie = [[0 for i in range(Z)] for j in range(N)] n = 0 k = 0 nodeNum = 0 def insertNode(): u = 0 string = input() global nodeNum for i in range(len(string)): c = ord(string[i]) - ord('a') if trie[u][c] == 0: ...
1407511800
[ "games", "strings", "trees" ]
[ 1, 0, 0, 0, 0, 0, 1, 1 ]
3 seconds
["3.4142135624", "37.7044021497"]
51c355a5b56f9b1599e7d985f0b7c04e
null
In Medieval times existed the tradition of burning witches at steaks together with their pets, black cats. By the end of the 15-th century the population of black cats ceased to exist. The difficulty of the situation led to creating the EIC - the Emergency Inquisitory Commission.The resolution #666 says that a white ca...
Print a single number, the answer to the problem, perimeter of the union of triangles. Your answer should differ from the correct one in no more than 10 - 6.
The first input line contains a single integer n (0 ≤ n ≤ 100). It is the number of spots on the cat's fur. The i-th of the last n lines contains 6 integers: x1i, y1i, x2i, y2i, x3i, y3i. They are the coordinates of the i-th triangular spot (0 &lt; xji, yji &lt; 105).
standard output
standard input
Python 2
Python
2,300
train_002.jsonl
55208628c101d596b3c0e3b7a6bad399
256 megabytes
["1\n1 1 2 1 1 2", "3\n3 3 10 3 3 10\n1 1 9 4 5 6\n2 2 11 7 6 11"]
PASSED
from math import * eps=1e-14 n = input() l = [map(int,raw_input().split()) for _ in xrange(n)] res = 0 def isect(a1,b1,c1,x1,y1,x2,y2): a2,b2,c2=y1-y2,x2-x1,x1*y2-y1*x2 d = a1*b2-a2*b1 if d==0: return None, None x = -1.0*(c1*b2-c2*b1)/d y = -1.0*(c2*a1-a2*c1)/d #print x1,y1,x2,y2,x,y if min(...
1298649600
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
2 seconds
["unique\n5", "not unique"]
bfbd7a73e65d240ee7e8c83cc68ca0a1
NoteIn the second example the answer is not unique. For example, if α = 10, we'll have such a sequence as 1, 2, 3, and if α = 14, the sequence will be 1, 2, 4.
Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name — The Huff-puffer.So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with α lite...
Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique".
The first line contains an integer n (1 ≤ n ≤ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in ...
standard output
standard input
Python 2
Python
1,800
train_006.jsonl
e6c9662e1079a38a6394080ee9d5b85e
256 megabytes
["3\n1 2 4", "2\n1 2"]
PASSED
I = lambda: map(int, raw_input().split()) n = input() S = [None]*n S = I() #print S counter = 1 decr = 0 alpha = 0.0 lower = 0.0 for i in xrange(n): if(i == 0): alpha = 10*S[0]+10 decr = 10*S[0] counter += 1 else: decr = 10*(S[i]-S[i-1]) + decr alpha = min(alpha,(decr +...
1292140800
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["abab\n-1\naaa\nab\nz"]
8d4cdf75f726b59a8fcc374e1417374a
NoteThe first test case was explained in the statement.In the second test case, the answer does not exist.
You are given $$$n$$$ strings $$$a_1, a_2, \ldots, a_n$$$: all of them have the same length $$$m$$$. The strings consist of lowercase English letters.Find any string $$$s$$$ of length $$$m$$$ such that each of the given $$$n$$$ strings differs from $$$s$$$ in at most one position. Formally, for each given string $$$a_i...
Print $$$t$$$ answers to the test cases. Each answer (if it exists) is a string of length $$$m$$$ consisting of lowercase English letters. If there are several answers, print any of them. If the answer does not exist, print "-1" ("minus one", without quotes).
The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case starts with a line containing two positive integers $$$n$$$ ($$$1 \le n \le 10$$$) and $$$m$$$ ($$$1 \le m \le 10$$$) — the number of strings and their length. Then follow $$$n$$...
standard output
standard input
PyPy 3
Python
1,700
train_007.jsonl
8611089238d9864067855d6f2391005d
256 megabytes
["5\n2 4\nabac\nzbab\n2 4\naaaa\nbbbb\n3 3\nbaa\naaa\naab\n2 2\nab\nbb\n3 1\na\nb\nc"]
PASSED
import string for _ in range(int(input())): n,m=map(int,input().split()) s=[input() for _ in range(n)] totry=string.ascii_lowercase for i in range(m): t1=0 for l in totry: ans=s[0][:i]+l+s[0][i+1:] t=0 for st in s: r=0 f...
1590327300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
4 seconds
["2\n0\n13\n1\n4\n7\n0"]
a7ae834884ce801ffe111bd8161e89d2
NoteIn the first test case, the optimal array is $$$p = [1, 1, 1, 2, 2]$$$. The resulting array of values of $$$\lfloor \frac{a_i}{p_i} \rfloor$$$ is $$$[4, 5, 6, 4, 5]$$$. The cost of $$$p$$$ is $$$\max\limits_{1 \le i \le n}(\lfloor \frac{a_i}{p_i} \rfloor) - \min\limits_{1 \le i \le n}(\lfloor \frac{a_i}{p_i} \rfloo...
This is the hard version of the problem. The only difference between the versions is the constraints on $$$n$$$, $$$k$$$, $$$a_i$$$, and the sum of $$$n$$$ over all test cases. You can make hacks only if both versions of the problem are solved.Note the unusual memory limit.You are given an array of integers $$$a_1, a_2...
For each test case, print a single integer — the minimum possible cost of an array $$$p$$$ satisfying the condition above.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_1 \le a_2 \le \ldots \le a_n \le ...
standard output
standard input
PyPy 3-64
Python
2,400
train_093.jsonl
c3378cdf501f3cc31c0ea5e47090e67f
64 megabytes
["7\n\n5 2\n\n4 5 6 8 11\n\n5 12\n\n4 5 6 8 11\n\n3 1\n\n2 9 15\n\n7 3\n\n2 3 5 5 6 9 10\n\n6 56\n\n54 286 527 1436 2450 2681\n\n3 95\n\n16 340 2241\n\n2 2\n\n1 3"]
PASSED
#!/usr/bin/env python3 import sys import heapq input = sys.stdin.readline # to read input quickly def ceiling_division(numer, denom): return -((-numer)//denom) mask = 2**18 - 1 m0 = mask m1 = mask << 18 m2 = mask << 36 def ungroup(x): return (x&m2) >> 36, (x&m1) >> 18, (x&m0) def gr...
1658154900
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["110110", "01100011", "01"]
6ac00fcd4a483f9f446e692d05fd31a4
NoteIn the first example there are two occurrences, one starting from first position and one starting from fourth position.In the second example there is only one occurrence, which starts from third position. Note, that the answer is not unique. For example, if we move the first day (which is a day off) to the last pos...
The new camp by widely-known over the country Spring Programming Camp is going to start soon. Hence, all the team of friendly curators and teachers started composing the camp's schedule. After some continuous discussion, they came up with a schedule $$$s$$$, which can be represented as a binary string, in which the $$$...
In the only line print the schedule having the largest number of substrings equal to $$$t$$$. Printed schedule should consist of characters '0' and '1' only and the number of zeros should be equal to the number of zeros in $$$s$$$ and the number of ones should be equal to the number of ones in $$$s$$$. In case there mu...
The first line contains string $$$s$$$ ($$$1 \leqslant |s| \leqslant 500\,000$$$), denoting the current project of the camp's schedule. The second line contains string $$$t$$$ ($$$1 \leqslant |t| \leqslant 500\,000$$$), denoting the optimal schedule according to Gleb. Strings $$$s$$$ and $$$t$$$ contain characters '0' ...
standard output
standard input
Python 3
Python
1,600
train_054.jsonl
0b72121ba7e0922a43d287ce4565e9c3
512 megabytes
["101101\n110", "10010110\n100011", "10\n11100"]
PASSED
import sys def count_bits(s): return [s.count("0"), s.count("1")] # 1 - in case where a >= b # 0 - otherwise def compare_bits_count(a, b): if a[0] >= b[0] and a[1] >= b[1]: return 1 else: return 0 def subtract_bits_count(a, b): return [a[0] - b[0], a[1] - b[1]] def z_function(s):...
1552035900
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["Yes\nNo\nYes"]
34aa41871ee50f06e8acbd5eee94b493
NoteThe first two sets are desribed in the statement.The third set produces garland "RBRG", for example.
Polycarp is sad — New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.The local store introduced a new service this year, called "Build your own garland". So you can buy some red, green and blue lamps, provide them an...
Print $$$t$$$ lines — for each set of lamps print "Yes" if the store workers can build a garland from them and "No" otherwise.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of sets of lamps Polycarp has bought. Each of the next $$$t$$$ lines contains three integers $$$r$$$, $$$g$$$ and $$$b$$$ ($$$1 \le r, g, b \le 10^9$$$) — the number of red, green and blue lamps in the set, respectively.
standard output
standard input
Python 3
Python
900
train_000.jsonl
d53ffbdbe544d9997b359900cde00fa8
256 megabytes
["3\n3 3 3\n1 10 2\n2 1 1"]
PASSED
t=int(input()) for _ in range(t): l=list(map(int,input().split())) if 2*max(l)<=sum(l)+1: print('Yes') else: print('No')
1577457600
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["3", "0 2 4", "-1", "13 15 17 19 21"]
e5ac0312381701a25970dd9a98cda3d4
NoteIn the first test case, the only solution is that everyone is friends with everyone. That is why Bob should have $$$3$$$ friends.In the second test case, there are three possible solutions (apart from symmetries): $$$a$$$ is friend of $$$b$$$, $$$c$$$ is friend of $$$d$$$, and Bob has no friends, or $$$a$$$ is a...
Bob is an active user of the social network Faithbug. On this network, people are able to engage in a mutual friendship. That is, if $$$a$$$ is a friend of $$$b$$$, then $$$b$$$ is also a friend of $$$a$$$. Each user thus has a non-negative amount of friends.This morning, somebody anonymously sent Bob the following lin...
Print all possible values of $$$a_{n+1}$$$ — the amount of people that Bob can be friend of, in increasing order. If no solution exists, output $$$-1$$$.
The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 5 \cdot 10^5$$$), the number of people on the network excluding Bob. The second line contains $$$n$$$ numbers $$$a_1,a_2, \dots, a_n$$$ ($$$0 \leq a_i \leq n$$$), with $$$a_i$$$ being the number of people that person $$$i$$$ is a friend of.
standard output
standard input
Python 3
Python
2,400
train_033.jsonl
d179a722084be6092d643ecc0adb97fb
256 megabytes
["3\n3 3 3", "4\n1 1 1 1", "2\n0 2", "35\n21 26 18 4 28 2 15 13 16 25 6 32 11 5 31 17 9 3 24 33 14 27 29 1 20 4 12 7 10 30 34 8 19 23 22"]
PASSED
def main(): n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) mod=sum(a)%2 counts=[0]*(n+1) for guy in a: counts[guy]+=1 cumcounts=[counts[0]] for i in range(n): cumcounts.append(cumcounts[-1]+counts[i+1]) partialsums=[0] curr=0 for i in ran...
1546180500
[ "math", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
1 second
["NO", "YES"]
9cf8b711a3fcf5dd5059f323f107a0bd
null
You have matrix a of size n × n. Let's number the rows of the matrix from 1 to n from top to bottom, let's number the columns from 1 to n from left to right. Let's use aij to represent the element on the intersection of the i-th row and the j-th column. Matrix a meets the following two conditions: for any numbers i, ...
If there is a positive integer k ≥ 1, such that matrix ak is strictly positive, print "YES" (without the quotes). Otherwise, print "NO" (without the quotes).
The first line contains integer n (2 ≤ n ≤ 2000) — the number of rows and columns in matrix a. The next n lines contain the description of the rows of matrix a. The i-th line contains n non-negative integers ai1, ai2, ..., ain (0 ≤ aij ≤ 50). It is guaranteed that .
standard output
standard input
PyPy 2
Python
2,200
train_077.jsonl
7c3a71881ab6ade147d41ec0b2f50cc6
256 megabytes
["2\n1 0\n0 1", "5\n4 5 6 1 2\n1 2 3 4 5\n6 4 1 2 4\n1 1 1 1 1\n4 4 4 4 4"]
PASSED
#!py2 def solve(N, A): graph = [set() for _ in xrange(N)] rgraph = [set() for _ in xrange(N)] for u, row in enumerate(A): for v, val in enumerate(row): if val: graph[u].add(v) rgraph[v].add(u) # Try to write row 0 in terms of row i stack...
1394983800
[ "math", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
15 seconds
["RL", "DLDDLLLRRRUURU", "IMPOSSIBLE"]
61689578b2623e750eced6f770fda2cc
NoteIn the first sample two cyclic ways for the Robot with the length 2 exist — "UD" and "RL". The second cycle is lexicographically less. In the second sample the Robot should move in the following way: down, left, down, down, left, left, left, right, right, right, up, up, right, up. In the third sample the Robot can'...
The Robot is in a rectangular maze of size n × m. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is empty. In...
Print the lexicographically minimum Robot's way with the length exactly k, which starts and ends in the cell where initially Robot is. If there is no such way, print "IMPOSSIBLE"(without quotes).
The first line contains three integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 106) — the size of the maze and the length of the cycle. Each of the following n lines contains m symbols — the description of the maze. If the symbol equals to "." the current cell is empty. If the symbol equals to "*" the current cell is occ...
standard output
standard input
Python 3
Python
1,700
train_077.jsonl
e6341ca044cd6a9a4d20792b5bfdde8a
256 megabytes
["2 3 2\n.**\nX..", "5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.", "3 3 4\n***\n*X*\n***"]
PASSED
from queue import Queue import sys #sys.stdin = open('input.txt') n, m, k = map(lambda x: int(x), input().split(' ')) if k&1: print('IMPOSSIBLE') sys.exit() s = [None]*n for i in range(n): s[i] = [None]*m t = input() for j in range(m): s[i][j] = t[j] if t[j] == 'X': x, y = j, i def bfs(x, y): re...
1488628800
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["YES", "NO"]
c659bdeda1c1da08cfc7f71367222332
Note First example: you can simply swap two letters in string "ab". So we get "ba". Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.Dwarf Misha ...
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that corr...
standard output
standard input
Python 3
Python
1,100
train_005.jsonl
74f9f2db9474289817555c34f9037caf
256 megabytes
["ab\nba", "aa\nab"]
PASSED
p=input() p=p.replace('',' ') p=p.split() q=input() q=q.replace('',' ') q=q.split() if len(p)==len(q): c=0 l=[] for i in range(len(p)): if p[i]!=q[i]: c+=1 l.append(p[i]) l.append(q[i]) if c==2: d=0 for i in range(4): if l.count(l[i...
1336145400
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["()", "(()(()))", "()()"]
cf1c39e85eded68515aae9eceac73313
NoteIn the first sample the cursor is initially at position 5. Consider actions of the editor: command "R" — the cursor moves to the position 6 on the right; command "D" — the deletion of brackets from the position 5 to the position 6. After that CBS takes the form (())(), the cursor is at the position 5; command "L...
Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and "1"-s to it. For example, sequences "(())()", "()" and "(()(()))" are correct, wh...
Print the correct bracket sequence, obtained as a result of applying all operations to the initial sequence.
The first line contains three positive integers n, m and p (2 ≤ n ≤ 500 000, 1 ≤ m ≤ 500 000, 1 ≤ p ≤ n) — the number of brackets in the correct bracket sequence, the number of operations and the initial position of cursor. Positions in the sequence are numbered from left to right, starting from one. It is guaranteed t...
standard output
standard input
Python 3
Python
1,700
train_059.jsonl
370a247f79c018a6b474d2a1688db039
256 megabytes
["8 4 5\n(())()()\nRDLD", "12 5 3\n((()())(()))\nRRDLD", "8 8 8\n(())()()\nLLLLLLDD"]
PASSED
class Node: def __init__(self, index): self.left = index - 1 self.right = index + 1 self.pair = -1 if __name__ == "__main__": n, m, p = map(int, input().split()) brackets = input() operations = input() nodes = [Node(i) for i in range(n + 1)] stack = [] for i in ran...
1462464300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["1", "1999982505"]
54e9c6f24c430c5124d840b5a65a1bc4
NoteIn the first example, we first reorder $$$\{1, 3, 2\}$$$ into $$$\{1, 2, 3\}$$$, then increment $$$a_2$$$ to $$$4$$$ with cost $$$1$$$ to get a power sequence $$$\{1, 2, 4\}$$$.
Let's call a list of positive integers $$$a_0, a_1, ..., a_{n-1}$$$ a power sequence if there is a positive integer $$$c$$$, so that for every $$$0 \le i \le n-1$$$ then $$$a_i = c^i$$$.Given a list of $$$n$$$ positive integers $$$a_0, a_1, ..., a_{n-1}$$$, you are allowed to: Reorder the list (i.e. pick a permutation...
Print the minimum cost to transform $$$a_0, a_1, ..., a_{n-1}$$$ into a power sequence.
The first line contains an integer $$$n$$$ ($$$3 \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_0, a_1, ..., a_{n-1}$$$ ($$$1 \le a_i \le 10^9$$$).
standard output
standard input
PyPy 3
Python
1,500
train_001.jsonl
3b75768ab9d2fa9782acad40a87ed191
256 megabytes
["3\n1 3 2", "3\n1000000000 1000000000 1000000000"]
PASSED
import copy import math n = int(input()) nums = list(map(int,input().split())) nums.sort() f_1 = 0 for i in range(n): f_1 += math.fabs(1 - nums[i]) term = f_1 + nums[-1] max_c = math.floor(math.pow(term,1/(n-1))) cost2 = float('inf') prev_cost = 0 for c in range(1,max_c+1): cost = 0 for i in range(n)...
1598798100
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["YES\nYES\nNO\nNO"]
c0ad2a6d14b0c9e09af2221d88a34d52
NoteIn the first test case, you can form one packet with $$$1$$$ red and $$$1$$$ blue bean. The absolute difference $$$|1 - 1| = 0 \le d$$$.In the second test case, you can form two packets: $$$1$$$ red and $$$4$$$ blue beans in the first packet and $$$1$$$ red and $$$3$$$ blue beans in the second one.In the third test...
You have $$$r$$$ red and $$$b$$$ blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet: has at least one red bean (or the number of red beans $$$r_i \ge 1$$$); has at least one blue bean (or the number of blue beans $$$b_i \ge 1$$$); the number of red and blue b...
For each test case, if you can distribute all beans, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
The first line contains the single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first and only line of each test case contains three integers $$$r$$$, $$$b$$$, and $$$d$$$ ($$$1 \le r, b \le 10^9$$$; $$$0 \le d \le 10^9$$$) — the number of red and blue beans and the maximum absolute differen...
standard output
standard input
Python 3
Python
800
train_101.jsonl
a149ae3b91445d8dcb18e6884f39240a
256 megabytes
["4\n1 1 0\n2 7 3\n6 1 4\n5 4 0"]
PASSED
for i in range(int(input())): arr = [int(_) for _ in input().split()] if abs(arr[0] / min(arr[:2]) - arr[1] / min(arr[:2])) <= arr[2]: print('YES') else: print('NO') # val = abs(arr[0] / 2 - arr[1] / 2) <= arr[2]
1619706900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1.931851653\n3.196226611\n126.687663595"]
c466c909fff92353ea676b643ca76908
null
The statement of this problem is the same as the statement of problem C1. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$...
Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single odd integer $$$n$$$ ($$$3 \le n \le 199$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.
standard output
standard input
PyPy 3
Python
2,000
train_004.jsonl
acd939ebac1b4aafb82d9aa8b69f4f7c
256 megabytes
["3\n3\n5\n199"]
PASSED
from math import sin,radians def C2(n): interiorangle = 360/(2*n) side = sin(radians(45)) angle = 45 number = (n-1)/2 for i in range(int(number)): angle += interiorangle if angle > 90: angle = 180 - angle side += sin(radians(angle)) angle = 180 - a...
1589707200
[ "geometry", "math" ]
[ 0, 1, 0, 1, 0, 0, 0, 0 ]
2 seconds
["a", "bc", "b"]
161f3f76bfe141899ad0773545b38c03
NoteIn the second sample before string "bc" follow strings "a", "ab", "abc", "b".
One day in the IT lesson Anna and Maria learned about the lexicographic order.String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi &lt; yi, and for any j (1 ≤ j &lt; i) xj = yj. Here |a| denotes the length of the string a. Th...
Print the string Anna and Maria need — the k-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than k, print a string saying "No such line." (without the quotes).
The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer k (1 ≤ k ≤ 105).
standard output
standard input
Python 3
Python
2,100
train_018.jsonl
f2c521438dade5afc86d45edc3340ba6
256 megabytes
["aa\n2", "abc\n5", "abab\n7"]
PASSED
# -*- coding: utf-8 -*- """ Created on Sat May 7 16:53:11 2016 @author: Alex """ from heapq import heappush,heappop,heapify string = input() l = len(string) k = int(input()) A = l*(l+1)/2 if A<k: print("No such line.") else: heap = [(string[i],i+1) for i in range(l)] heapify(heap) cnt = 0 while cn...
1321337400
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["YES\n25.5000000000\n10.0000000000 4.5000000000 0.0000000000", "NO", "YES\n0.0000000000\n1.0000000000 2.0000000000 3.0000000000"]
6e2a8aa58ed8cd308cb482e4c24cbbbb
null
Brothers Fred and George Weasley once got into the sporting goods store and opened a box of Quidditch balls. After long and painful experiments they found out that the Golden Snitch is not enchanted at all. It is simply a programmed device. It always moves along the same trajectory, which is a polyline with vertices at...
If Harry Potter can catch the snitch while it is moving along the polyline (including the end (xn, yn, zn)), print "YES" in the first line (without the quotes). Print in the second line t, which is the earliest moment of time, when Harry will be able to catch the snitch. On the third line print three numbers X, Y, Z, t...
The first line contains a single integer n (1 ≤ n ≤ 10000). The following n + 1 lines contain the coordinates xi, yi, zi, separated by single spaces. The coordinates of any two consecutive points do not coincide. The next line contains the velocities vp and vs, the last line contains Px, Py, Pz, separated by single spa...
standard output
standard input
Python 2
Python
2,100
train_060.jsonl
87d9b7abd9713d16eff012c23009e499
256 megabytes
["4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 25", "4\n0 0 0\n0 10 0\n10 10 0\n10 0 0\n0 0 0\n1 1\n5 5 50", "1\n1 2 3\n4 5 6\n20 10\n1 2 3"]
PASSED
import math,sys eps = 1e-8 n = input() al = [map(int,raw_input().split()) for i in xrange(n+1)] vp,vs = map(int,raw_input().split()) px,py,pz = p0 = map(int,raw_input().split()) al = [(x-px,y-py,z-pz) for x,y,z in al] d3=lambda x,y,z:x*x+y*y+z*z t0,ts = 0,0 rt = None for i in range(n): c = [y-x for x,y in...
1299340800
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
2 seconds
["164", "27"]
28c555fefd5c36697a5082c61d8a82b3
NoteIn the first sample, one of the optimal solutions is to divide those $$$4$$$ numbers into $$$2$$$ groups $$$\{2, 8\}, \{5, 3\}$$$. Thus the answer is $$$(2 + 8)^2 + (5 + 3)^2 = 164$$$.In the second sample, one of the optimal solutions is to divide those $$$6$$$ numbers into $$$3$$$ groups $$$\{1, 2\}, \{1, 2\}, \{1...
Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem.There are $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$ on Bob's homework paper, where $$$n$$$ is always an even number. Bob is asked to divide those numbers into groups, where each group must contain at least $$$...
A single line containing one integer, denoting the minimum of the sum of the square of $$$s_j$$$, which is $$$$$$\sum_{i = j}^{m} s_j^2,$$$$$$ where $$$m$$$ is the number of groups.
The first line contains an even integer $$$n$$$ ($$$2 \leq n \leq 3 \cdot 10^5$$$), denoting that there are $$$n$$$ integers on Bob's homework paper. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^4$$$), describing the numbers you need to deal with.
standard output
standard input
PyPy 3
Python
900
train_004.jsonl
1d7642edf48293b29f51ec811b2d01c3
256 megabytes
["4\n8 5 2 3", "6\n1 1 1 2 2 2"]
PASSED
n = int(input()) a = list(map(int, input().split(" "))) a.sort() min_sum = 0 i = 0 j = n - 1 while i <= j: if i == j: min_sum += a[j] else: min_sum += (a[i] + a[j]) ** 2 i += 1 j -= 1 print(min_sum)
1548938100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["4", "9"]
dceeb739a56bb799550138aa8c127996
NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get thei...
Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know...
Print exactly one integer — the maximum number of students that can get a favorite drink.
The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of t...
standard output
standard input
Python 3
Python
1,000
train_021.jsonl
31aeedb9329d4f4d7680c66eb3cba918
256 megabytes
["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"]
PASSED
import math n, k = map(int, input().split()) a = [0] * k for i in range(n): temp = int(input()) a[temp-1] += 1 nSet = math.ceil(n/2) ans = 0 # First deal with situation where a[i] > 1 for i in range(k): while a[i] > 1 and nSet > 0: ans += 2 nSet -= 1 a[i] -= 2 # Then deal with only ...
1563374100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1 2\n1 2\n1 3\n2 3"]
b01fb9d4d78a02e3c634800b4b177d75
NoteNote that you can add the same edge that you cut.In the first test case, after cutting and adding the same edge, the vertex $$$2$$$ is still the only centroid.In the second test case, the vertex $$$2$$$ becomes the only centroid after cutting the edge between vertices $$$1$$$ and $$$3$$$ and adding the edge between...
Fishing Prince loves trees, and he especially loves trees with only one centroid. The tree is a connected graph without cycles.A vertex is a centroid of a tree only when you cut this vertex (remove it and remove all edges from this vertex), the size of the largest connected component of the remaining graph is the small...
For each test case, print two lines. In the first line print two integers $$$x_1, y_1$$$ ($$$1 \leq x_1, y_1 \leq n$$$), which means you cut the edge between vertices $$$x_1$$$ and $$$y_1$$$. There should exist edge connecting vertices $$$x_1$$$ and $$$y_1$$$. In the second line print two integers $$$x_2, y_2$$$ ($$$1 ...
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t\leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3\leq n\leq 10^5$$$) — the number of vertices. Each of the next $$$n-1$$$...
standard output
standard input
PyPy 3
Python
1,700
train_029.jsonl
51565fc3d42f0f25dcc38f6c43bb0be3
512 megabytes
["2\n5\n1 2\n1 3\n2 4\n2 5\n6\n1 2\n1 3\n1 4\n2 5\n2 6"]
PASSED
###################################################### ############Created by Devesh Kumar################### #############devesh1102@gmail.com#################### ##########For CodeForces(Devesh1102)################# #####################2020############################# ###############################################...
1599918300
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
1 second
["YES\nNO\nYES"]
eba7fc8d103ba3d643c1424cbbebf571
null
There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place: either employee y became the boss of employee x (at that, employee x didn't have a boss be...
For each query of the third type print "YES" if the employee signed the document package and "NO" otherwise. Print all the words without the quotes.
The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of employees and the number of events. Each of the next m lines contains the description of one event (the events are given in the chronological order). The first number of the line determines the type of event t (1 ≤ t ≤ 3). If t = 1, then ...
standard output
standard input
Python 3
Python
2,100
train_051.jsonl
eacbdc33f4e998b7bd6f37c7a294131b
512 megabytes
["4 9\n1 4 3\n2 4\n3 3 1\n1 2 3\n2 2\n3 1 2\n1 3 1\n2 2\n3 1 3"]
PASSED
n, m = map(int, input().split()) ev = [tuple(map(int, input().split())) for _ in range(m)] g = [[] for _ in range(n + 1)] qry = [[] for _ in range(m + 1)] roots = set(range(1, n + 1)) qcnt = 0 for e in ev: if e[0] == 1: g[e[2]].append(e[1]) roots.remove(e[1]) elif e[0] == 3: qry[e[2]].append((qcnt, e[1])) qc...
1410535800
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
2 seconds
["12 14", "8"]
9eccd64bb49b74ed0eed3dbf6636f07d
NoteIn the first example, for $$$f(3)$$$, we consider four possible polygons: ($$$p_1, p_2, p_3$$$), with perimeter $$$12$$$. ($$$p_1, p_2, p_4$$$), with perimeter $$$8$$$. ($$$p_1, p_3, p_4$$$), with perimeter $$$12$$$. ($$$p_2, p_3, p_4$$$), with perimeter $$$12$$$. For $$$f(4)$$$, there is only one option, taki...
You are given $$$n$$$ points on the plane. The polygon formed from all the $$$n$$$ points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from $$$1$$$ to $$$n$$$, in clockwise order.We define the distance between...
For each $$$i$$$ ($$$3\leq i\leq n$$$), output $$$f(i)$$$.
The first line contains a single integer $$$n$$$ ($$$3 \leq n \leq 3\cdot 10^5$$$) — the number of points. Each of the next $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^8 \leq x_i, y_i \leq 10^8$$$) — the coordinates of point $$$p_i$$$. The set of points is guaranteed to be convex, all points ar...
standard output
standard input
Python 2
Python
2,100
train_026.jsonl
bd41715d0639fbd0991e1924adcb4216
256 megabytes
["4\n2 4\n4 3\n3 0\n1 3", "3\n0 0\n0 2\n2 0"]
PASSED
n = int(raw_input()) X = [] Y = [] for _ in range(n): x,y = map(int,raw_input().strip(' ').strip('\n').split(' ')) X.append(x) Y.append(y) maxx,minx = max(X),min(X) maxy,miny = max(Y),min(Y) ans = -10e18 for i in range(n): dx = max(maxx-X[i],X[i]-minx) dy = max(maxy-Y[i],Y[i]-miny) ans = max(an...
1541355000
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
2 seconds
["1", "24"]
f5cb28bf83f3b1b7c7df4037e65bddf2
NoteIn the first example, there is only one non-empty subset {1} with cost 11 = 1.In the second example, there are seven non-empty subsets.- {1} with cost 12 = 1- {2} with cost 12 = 1- {1, 2} with cost 22 = 4- {3} with cost 12 = 1- {1, 3} with cost 22 = 4- {2, 3} with cost 22 = 4- {1, 2, 3} with cost 32 = 9The total co...
You have a team of N people. For a particular task, you can pick any non-empty subset of people. The cost of having x people for the task is xk. Output the sum of costs over all non-empty subsets of people.
Output the sum of costs for all non empty subsets modulo 109 + 7.
Only line of input contains two integers N (1 ≤ N ≤ 109) representing total number of people and k (1 ≤ k ≤ 5000).
standard output
standard input
PyPy 2
Python
2,400
train_036.jsonl
88fc6f288789e850ed1f3dbb9b506b14
256 megabytes
["1 1", "3 2"]
PASSED
import sys range = xrange input = raw_input N,K = [int(x) for x in input().split()] MOD = 10**9+7 coeff = [0]*(K+1) coeff[0] = 1 for iters in range(K): #print coeff for i in reversed(range(iters+1)): coeff[i+1] += coeff[i] coeff[i]= coeff[i]*i%MOD #print coeff mod2inv = 500000004 pow2 = pow...
1518705300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["3", "1680"]
faf2c92c3a61ba5e33160bc7a18ad928
NoteIn the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: 1 2 1 2 31 1 2 2 32 1 1 2 3
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i...
A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1 000 000 007.
The first line of input will have one integer k (1 ≤ k ≤ 1000) the number of colors. Then, k lines will follow. The i-th line will contain ci, the number of balls of the i-th color (1 ≤ ci ≤ 1000). The total number of balls doesn't exceed 1000.
standard output
standard input
Python 2
Python
1,500
train_029.jsonl
6ff623793a4889c1c5c6550fa317c279
256 megabytes
["3\n2\n2\n1", "4\n1\n2\n3\n4"]
PASSED
import math ncol = int(raw_input()) #print ncol col = [] n = 0 for i in range(0,ncol): col.append(int(raw_input())) n += col[i] #print n m = 1 length = col[0] for i in range(1,ncol): k2 = col[i] m *= math.factorial(length+k2-1)/(math.factorial(k2-1)*math.factorial(length)) length += k2 m = m%1000...
1435163400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["7 7\n1 2 3\n2 3 2\n3 4 2\n2 4 4", "7 13\n1 2 2\n1 3 4\n1 4 3\n4 5 4"]
c0eec5938787a63fce3052b7e209eda3
NoteThe graph of sample 1: Shortest path sequence: {1, 2, 3, 4}. MST edges are marked with an asterisk (*).Definition of terms used in the problem statement:A shortest path in an undirected graph is a sequence of vertices (v1, v2, ... , vk) such that vi is adjacent to vi + 1 1 ≤ i &lt; k and the sum of weight is mini...
Jamie has recently found undirected weighted graphs with the following properties very interesting: The graph is connected and contains exactly n vertices and m edges. All edge weights are integers and are in range [1, 109] inclusive. The length of shortest path from 1 to n is a prime number. The sum of edges' weig...
In the first line output 2 integers sp, mstw (1 ≤ sp, mstw ≤ 1014) — the length of the shortest path and the sum of edges' weights in the minimum spanning tree. In the next m lines output the edges of the graph. In each line output 3 integers u, v, w (1 ≤ u, v ≤ n, 1 ≤ w ≤ 109) describing the edge connecting u and v an...
First line of input contains 2 integers n, m  — the required number of vertices and edges.
standard output
standard input
Python 2
Python
1,600
train_002.jsonl
5b26c2c16cca9df949466059016f9c87
256 megabytes
["4 4", "5 4"]
PASSED
def main(): n, m = map(int, raw_input().split()) if n == 2: print 2, 2 print 1, 2, 2 quit() else: print 2, 100003 for i in xrange(2, n - 1): print 1, i, 1 print 1, n - 1, 100003 - n + 1 print 1, n, 2 c, d = 2, 3 for _ in xrange(m - n + 1): ...
1516372500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
5 seconds
["7 8 9 4 5 6 1 2 3"]
32077a3111c3f28ad56eab0c085a882d
null
You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj).At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one can get?Let p and q be two permutations of the numbers 1, 2, ..., n. p is le...
Print the only line with n distinct integers p'i (1 ≤ p'i ≤ n) — the lexicographically maximal permutation one can get.
The first line contains two integers n and m (1 ≤ n, m ≤ 106) — the length of the permutation p and the number of pairs of positions. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the last m lines contains two integers (aj, bj) (1 ≤ aj, bj ≤ n) — the pairs of ...
standard output
standard input
PyPy 2
Python
1,700
train_036.jsonl
5f3adb1f8b18c3213117f90794273be5
256 megabytes
["9 6\n1 2 3 4 5 6 7 8 9\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9"]
PASSED
n, m = map(int, raw_input().split()) val = [_ for _ in map(int, raw_input().split())] adj = [[] for _ in range(n)] for i in range(m): a, b = map(int, raw_input().split()) adj[a - 1].append(b - 1) adj[b - 1].append(a - 1) vis = [False for _ in range(n)] for v in range(n): if vis[v] or len(adj[v]) == 0...
1468425600
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["? 1 2 1 1 1 3\n? 1 2 2 1 2 3\n? 1 2 3 1 3 3\n? 1 1 1 1 1 2\n! 2"]
f1b4048e5cd2aa0a533af9d08f7d58ba
NoteIn the example test the matrix $$$a$$$ of size $$$3 \times 4$$$ is equal to: 1 2 1 23 3 3 32 1 2 1
This is an interactive problem.There exists a matrix $$$a$$$ of size $$$n \times m$$$ ($$$n$$$ rows and $$$m$$$ columns), you know only numbers $$$n$$$ and $$$m$$$. The rows of the matrix are numbered from $$$1$$$ to $$$n$$$ from top to bottom, and columns of the matrix are numbered from $$$1$$$ to $$$m$$$ from left to...
When ready, print a line with an exclamation mark ('!') and then the answer — the number of suitable pairs $$$(r, c)$$$. After that your program should terminate.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of rows and columns, respectively.
standard output
standard input
Python 3
Python
2,600
train_105.jsonl
69807fc8ec9bc8172ce430138c0a162a
256 megabytes
["3 4\n1\n1\n1\n0"]
PASSED
import sys input = sys.stdin.readline def solve(): r, c = map(int, input().split()) r1 = r r2 = r i = 2 while True: if r2 % i == 0: while r2 % i == 0: r2 //= i while r1 % i == 0: #print('r',i) if i == 2: print('?',r1//i,c,1,1,r1//i+1,1) sys.stdout.flush() if i...
1615039500
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
2 seconds
["4", "20"]
ecbc339ad8064681789075f9234c269a
null
In one one-dimensional world there are n platforms. Platform with index k (platforms are numbered from 1) is a segment with coordinates [(k - 1)m, (k - 1)m + l], and l &lt; m. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly d units right. Find out the coordinate of the p...
Output the coordinates of the point, where the grosshopper will fall down. Don't forget that if Bob finds himself on the platform edge, he doesn't fall down.
The first input line contains 4 integer numbers n, d, m, l (1 ≤ n, d, m, l ≤ 106, l &lt; m) — respectively: amount of platforms, length of the grasshopper Bob's jump, and numbers m and l needed to find coordinates of the k-th platform: [(k - 1)m, (k - 1)m + l].
standard output
standard input
PyPy 3
Python
1,700
train_038.jsonl
a2b652b157428b0c0ef5c47464f7a96e
64 megabytes
["2 2 5 3", "5 4 11 8"]
PASSED
#Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict from collections import deque import threadi...
1276700400
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["3 1 1 \n700000000 700000000 \n0 0 0 0 0 \n0 0 2 1 0 \n0 0 \n9 9 999999990 \n0 0 0 \n3 1 3 1 1 1 \n0 0", "0 1 1 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 \n0 0 0 3 1 1 3 0 0 \n0 2 0 0 2 5 9 1 4"]
9be594097a1b2249c4227bde12c5552c
NoteIn the first test case of the first sample there is only one segment of color $$$2$$$, and all other segments have color $$$1$$$. Therefore, for segments of color $$$1$$$, the answer is equal to the distance to the $$$3$$$rd segment, and for $$$3$$$rd one, the answer is equal to the minimum of the distances to segm...
Dmitry has $$$n$$$ segments of different colors on the coordinate axis $$$Ox$$$. Each segment is characterized by three integers $$$l_i$$$, $$$r_i$$$ and $$$c_i$$$ ($$$1 \le l_i \le r_i \le 10^9, 1 \le c_i \le n$$$), where $$$l_i$$$ and $$$r_i$$$ are are the coordinates of the ends of the $$$i$$$-th segment, and $$$c_i...
For each test case, on a separate line print $$$n$$$ integers, where the $$$i$$$-th number is equal to the distance from the $$$i$$$-th segment to the nearest segment of a different color.
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of segments. The next $$$n$$$ lin...
standard output
standard input
Python 3
Python
2,000
train_084.jsonl
ee26ba0f05f2664ce9bc05badfd3fa9d
256 megabytes
["9\n\n3\n\n1 2 1\n\n3 4 1\n\n5 6 2\n\n2\n\n100000000 200000000 1\n\n900000000 1000000000 2\n\n5\n\n1 2 1\n\n2 3 2\n\n3 4 3\n\n4 5 4\n\n5 6 5\n\n5\n\n1 5 1\n\n4 9 2\n\n1 2 1\n\n8 9 2\n\n5 7 3\n\n2\n\n1 100 2\n\n10 90 1\n\n3\n\n1 1 1\n\n10 10 2\n\n1000000000 1000000000 3\n\n3\n\n3 4 1\n\n2 5 1\n\n1 6 2\n\n6\n\n5 6 2\n\n...
PASSED
t = int(input()) def dist(i,j): if i >= j: return 0 else: return j-i while t > 0: n = int(input()) seg = [] for i in range(n): seg.append(list(map(int,input().split()))+[i+1]) seg.sort(key=lambda x:(x[0],x[1])) color = {} i = 0 while i < n: ...
1665498900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["4", "629909355", "675837193"]
7ad1f3f220c12a68c1242a22f4fd7761
NoteFor the first sample case, the first player has $$$4$$$ possible moves. No matter what the first player plays, the second player only has $$$1$$$ possible move, so there are $$$4$$$ possible games.
Omkar and Akmar are playing a game on a circular board with $$$n$$$ ($$$2 \leq n \leq 10^6$$$) cells. The cells are numbered from $$$1$$$ to $$$n$$$ so that for each $$$i$$$ ($$$1 \leq i \leq n-1$$$) cell $$$i$$$ is adjacent to cell $$$i+1$$$ and cell $$$1$$$ is adjacent to cell $$$n$$$. Initially, each cell is empty.O...
Output a single integer — the number of possible distinct games where both players play optimally modulo $$$10^9+7$$$.
The only line will contain an integer $$$n$$$ ($$$2 \leq n \leq 10^6$$$) — the number of cells on the board.
standard output
standard input
Python 3
Python
2,600
train_094.jsonl
0ca1ebea0d32ae542243957267a7ece4
256 megabytes
["2", "69420", "42069"]
PASSED
from math import factorial def win(a): bw = None;bc = 0 for i in range(len(a)): if a[i] is None: for j in range(2): if a[i-1] == j or a[(i+1)%len(a)] == j:continue a[i] = j;w, c = win(a);a[i] = None if bw != False: bw = w if w == False:bc = c else:bc += c else:bc += c ...
1622990100
[ "geometry", "math", "games" ]
[ 1, 1, 0, 1, 0, 0, 0, 0 ]
1 second
["10\n0\n4"]
128d9ad5e5dfe4943e16fcc6a103e51b
NoteIn the first test case, we initially have a piece of size $$$1$$$, so all final pieces must have size $$$1$$$. The total number of steps is: $$$0 + 1 + 2 + 3 + 4 = 10$$$.In the second test case, we have just one piece, so we don't need to do anything, and the answer is $$$0$$$ steps.In the third test case, one of t...
There are $$$n$$$ pieces of tangerine peel, the $$$i$$$-th of them has size $$$a_i$$$. In one step it is possible to divide one piece of size $$$x$$$ into two pieces of positive integer sizes $$$y$$$ and $$$z$$$ so that $$$y + z = x$$$.You want that for each pair of pieces, their sizes differ strictly less than twice. ...
For each test case, output a single line containing the minimum number of steps.
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 100$$$). Then one line follows, containing $$$n$$$ integers $$$a_1 \le a_2 \le \ldots \le...
standard output
standard input
Python 3
Python
900
train_098.jsonl
c178e0e806b0ecf466dece9e12880c67
256 megabytes
["3\n\n5\n\n1 2 3 4 5\n\n1\n\n1033\n\n5\n\n600 900 1300 2000 2550"]
PASSED
def f(x,m): if x%(2*m-1)!=0: return x//(2*m-1) else: return x//(2*m-1)-1 N=int(input()) for i in range(N): n=int(input()) L=list(map(int,input().split())) M=max(L) m=min(L) L1=[x for x in L if x>=2*m] Lm=[m for i in range(len(L1))] L2=list(map(f,L1,Lm)) ...
1664721300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1\n2\n2\n10\n5\n9"]
1f29461c42665523d0a4d56b13f7e480
NoteIn the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.In...
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $$$r$$$ candies in it, the second pile contains only green candies and there are $$$g$$$ candies in it, the third pile contains only blue candies and there are $$$b$$$ candies in it. Each day Tanya ea...
Print $$$t$$$ integers: the $$$i$$$-th printed integer is the answer on the $$$i$$$-th test case in the input.
The first line contains integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is given as a separate line of the input. It contains three integers $$$r$$$, $$$g$$$ and $$$b$$$ ($$$1 \le r, g, b \le 10^8$$$) — the number of red, green and blue ca...
standard output
standard input
PyPy 3
Python
1,100
train_008.jsonl
78c76e91c876168cff4ab60aae4818a6
256 megabytes
["6\n1 1 1\n1 2 1\n4 1 1\n7 4 10\n8 1 4\n8 2 8"]
PASSED
n = int(input()) for _ in range(n): a = list(map(int, input().split())) a = sorted(a) if(a[0]+a[1] >= a[2]): print(sum(a)//2); else: print(sum(a)-a[2]);
1575038100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["3", "9", "130653412"]
1b336555c94d5d5198abe5426ff6fa7a
NoteFor a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia.In the first sample, there are 3 possible solutions: z&amp;_ = 61&amp;63 = 61 = z _&amp;z = 63&amp;61 = 61 = z z&amp;z = 61&amp;61 = 61 = z
While walking down the street Vanya saw a label "Hide&amp;Seek". Because he is a programmer, he used &amp; as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that t...
Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 109 + 7.
The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'.
standard output
standard input
PyPy 2
Python
1,500
train_007.jsonl
7f2ae05a46346d3040611ddacd32d9cc
256 megabytes
["z", "V_V", "Codeforces"]
PASSED
s = raw_input() d = 0 ans = 1 for c in map(ord, s): d = 0 if ord("0") <= c <= ord("9"): d += c - ord("0") elif ord("A") <= c <= ord("Z"): d += c - ord("A") + 10 elif ord("a") <= c <= ord("z"): d += c - ord("a") + 36 elif ord("-") == c: d += 62 else: d += 63 ans *= pow(3, format(d, "06b").count("0"), ...
1464798900
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["Yes\nNo\nYes\nYes\nNo\nYes\nNo\nNo\nYes\nNo"]
2d27f3530aa140be0add639a1edfd880
NoteThe first test case is clarified above.In the second test case, it is impossible to make all array elements equal.In the third test case, you need to apply this operation once to all elements equal to $$$5$$$.In the fourth test case, you need to apply this operation to all elements until they become equal to $$$8$$...
You are given an array of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$You can apply the following operation an arbitrary number of times: select an index $$$i$$$ ($$$1 \le i \le n$$$) and replace the value of the element $$$a_i$$$ with the value $$$a_i + (a_i \bmod 10)$$$, where $$$a_i \bmod 10$$$ is the remainder of ...
For each test case print: YES if it is possible to make all array elements equal; NO otherwise. You can print YES and NO in any case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive answer) .
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. What follows is a description of each test case. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the size of the array. The second line of each test case contains $$$n$$$ int...
standard output
standard input
PyPy 3-64
Python
1,400
train_103.jsonl
3d2093b68a460abe765d08ba42298b9f
256 megabytes
["10\n\n2\n\n6 11\n\n3\n\n2 18 22\n\n5\n\n5 10 5 10 5\n\n4\n\n1 2 4 8\n\n2\n\n4 5\n\n3\n\n93 96 102\n\n2\n\n40 6\n\n2\n\n50 30\n\n2\n\n22 44\n\n2\n\n1 5"]
PASSED
t = int(input()) for ti in range(t): n = int(input()) a = sorted(list(map(int, input().split()))) is0 = False res = "YES" while a[0] % 10 != 2: a[0] += a[0] % 10 if a[0] % 10 == 0: is0 = True break for i in range(n - 1): while a[i + 1] ...
1659364500
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["1\n2"]
7b80d3f3cd4f93e4277c76c76dc41f42
NoteIn the first test case, you can do the following to achieve a length of $$$1$$$:Pick $$$i=2$$$ to get $$$[2, 4, 1]$$$Pick $$$i=1$$$ to get $$$[6, 1]$$$Pick $$$i=1$$$ to get $$$[7]$$$In the second test case, you can't perform any operations because there is no valid $$$i$$$ that satisfies the requirements mentioned ...
Lord Omkar has permitted you to enter the Holy Church of Omkar! To test your worthiness, Omkar gives you a password which you must interpret!A password is an array $$$a$$$ of $$$n$$$ positive integers. You apply the following operation to the array: pick any two adjacent numbers that are not equal to each other and rep...
For each password, print one integer: the shortest possible length of the password after some number of operations.
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 an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of the password. The second line of each test case...
standard output
standard input
PyPy 2
Python
800
train_003.jsonl
581c7f544173e2b83ed06c0109da7265
256 megabytes
["2\n4\n2 1 3 1\n2\n420 420"]
PASSED
from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(): return int(input()) def si(): return input() def mi(): return map(in...
1597588500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["ACC\nACC\nACC\nWA\nACC\nACC\nWA", "WA\nACC\nACC"]
95ccc87fe9e431f9c6eeffeaf049f797
null
After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer!Some days before the contest, the teacher took a very simple-looking exam and all his n students took part in the exam. The teacher g...
For each student write in a different line. Print "WA" if his answer is wrong or "ACC" if his answer is OK.
The first three lines contain a string each. These are the initial strings. They consists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). All the initial strings have length from 1 to 100, inclusively. In the fourth line there is a single integer n (0 ≤ n ≤ 1000), the number of students. Nex...
standard output
standard input
PyPy 3
Python
1,300
train_030.jsonl
c6f70d857fd53d32b24fe65ee7a5aa54
256 megabytes
["Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful", "Shapur;;\nis___\na_genius\n3\nShapur__a_is___geniUs\nis___shapur___a__...
PASSED
def s(): import re,itertools pattern = re.compile('[^a-z]+') def st(x): return pattern.sub('',x.lower()) s = set([''.join(i)for i in itertools.permutations([st(input())for _ in range(3)])]) for i in range(int(input())): print('ACC'if st(input()) in s else 'WA') s()
1298390400
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["1", "5"]
c15ad483441864b3222eb62723b598e1
NoteIn the first example the only element can be removed.
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible.We remind that in a sequence of numbers a1, a2, ..., ak the element ai is a record if for every integer j (1 ≤ j &lt; i) the following holds: aj &lt; ai.
Print the only integer — the element that should be removed to make the number of records the maximum possible. If there are multiple such elements, print the smallest one.
The first line contains the only integer n (1 ≤ n ≤ 105) — the length of the permutation. The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation. All the integers are distinct.
standard output
standard input
Python 3
Python
1,700
train_005.jsonl
ce3aabd502c6918c7a3f96acb2c5ac21
256 megabytes
["1\n1", "5\n5 1 2 3 4"]
PASSED
import sys cases = sys.stdin.readline() my_list = [int(a) for a in sys.stdin.readline().split(" ")] #my_list = [4, 5, 3, 2, 1] max_val_a = my_list[0] max_val_b = 0 my_counts = dict() for x in my_list: my_counts[x] = 0 my_counts[max_val_a] = -1 for x in my_list: #print(my_counts) if(x > max_val_a): my_cou...
1513008300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["3 6\n4 5\n3 4\n1 9\n2 3\n4 5\n6 10"]
96fac9f9377bf03e144067bf93716d3d
NoteIn the first test case, $$$b = \{3+6, 4+5\} = \{9, 9\}$$$ and $$$\mathrm{gcd}(9, 9) = 9$$$.In the second test case, $$$b = \{9+10\} = \{19\}$$$ and $$$\mathrm{gcd}(19) = 19$$$.In the third test case, $$$b = \{1+2, 3+3, 4+5, 90+3\} = \{3, 6, 9, 93\}$$$ and $$$\mathrm{gcd}(3, 6, 9, 93) = 3$$$.
Ashish has an array $$$a$$$ of consisting of $$$2n$$$ positive integers. He wants to compress $$$a$$$ into an array $$$b$$$ of size $$$n-1$$$. To do this, he first discards exactly $$$2$$$ (any two) elements from $$$a$$$. He then performs the following operation until there are no elements left in $$$a$$$: Remove any...
For each test case, output $$$n-1$$$ lines — the operations performed to compress the array $$$a$$$ to the array $$$b$$$. The initial discard of the two elements is not an operation, you don't need to output anything about it. The $$$i$$$-th line should contain two integers, the indices ($$$1$$$ —based) of the two elem...
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 1000$$$). The second line of each test case contains $$$2n$$$ integers $$$a_1, a_2, \ldots...
standard output
standard input
Python 3
Python
1,100
train_016.jsonl
9b97c90fcc9a49511e40527837170e52
256 megabytes
["3\n3\n1 2 3 4 5 6\n2\n5 7 9 10\n5\n1 3 3 4 5 90 100 101 2 3"]
PASSED
# cook your dish here T=int(input()) for _ in range(T): n=int(input()) s=list(map(int,input().split())) odd=[] even=[] for i in range(len(s)): if(s[i]%2!=0): odd.append(i+1) else: even.append(i+1) count=0 for i in range(0,len(odd)-1,2): if(...
1592663700
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["3\n1\n3\n0"]
e0de8a6441614d1e41a53223b5fa576b
NoteThe first test case is explained in the statements.In the second test case, you need to make one move for $$$i=2$$$.The third test case you need to make three moves: the first move: $$$i=9$$$; the second move: $$$i=9$$$; the third move: $$$i=2$$$. In the fourth test case, the values $$$c_0$$$, $$$c_1$$$ and $$$...
You are given a number $$$n$$$ (divisible by $$$3$$$) and an array $$$a[1 \dots n]$$$. In one move, you can increase any of the array elements by one. Formally, you choose the index $$$i$$$ ($$$1 \le i \le n$$$) and replace $$$a_i$$$ with $$$a_i + 1$$$. You can choose the same index $$$i$$$ multiple times for different...
For each test case, output one integer — the minimum number of moves that must be made for the $$$a$$$ array to make it have balanced remainders.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$3 \le n \le 3 \cdot 10^4$$$) — the length of the array $$$a$$$. It is guaranteed that the number $$$n$$$ is divisible by $$$3$$$. The next line contains...
standard output
standard input
PyPy 3-64
Python
1,000
train_098.jsonl
4c879f2d0fbc86b5275d7ea344a96adf
256 megabytes
["4\n6\n0 2 5 5 4 8\n6\n2 0 2 1 0 0\n9\n7 1 3 4 2 10 3 9 6\n6\n0 1 2 3 4 5"]
PASSED
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) count = 0 ht = {0: 0, 1: 0, 2: 0} for i in arr: ht[i % 3] += 1 while True: # print(ht) diff = 1 if ht[0] == ht[1] == ht[2]: print(count) break if h...
1613486100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["Yes", "No", "Yes"]
bedb98780a71d7027798d14aa5f1f100
NoteThe picture below illustrates one of the possible trees for the first example. The picture below illustrates one of the possible trees for the third example.
Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees!Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and see...
If it is possible to reassemble the binary search tree, such that the greatest common divisor of any two vertices connected by the edge is greater than $$$1$$$, print "Yes" (quotes for clarity). Otherwise, print "No" (quotes for clarity).
The first line contains the number of vertices $$$n$$$ ($$$2 \le n \le 700$$$). The second line features $$$n$$$ distinct integers $$$a_i$$$ ($$$2 \le a_i \le 10^9$$$) — the values of vertices in ascending order.
standard output
standard input
PyPy 3
Python
2,100
train_061.jsonl
c3d37b01356f6d8acc95dce16f758cde
256 megabytes
["6\n3 6 9 18 36 108", "2\n7 17", "9\n4 8 10 12 15 18 33 44 81"]
PASSED
from sys import stdin from math import gcd n=int(stdin.readline()) a=[int(x) for x in stdin.readline().split()] c = [] ld=[] rd=[] def check(l, r, e): if r == l: return c[l][e] > 0 if e < l and ld[l][r-l] != 0: return ld[l][r-l] == 1 elif e > r and rd[l][r-l] != 0: return rd[l][r-l] == 1 ...
1534685700
[ "number theory", "math", "trees" ]
[ 0, 0, 0, 1, 1, 0, 0, 1 ]
1 second
["1337\n0"]
edf394051c6b35f593abd4c34b091eae
NoteIn the first test case you can perform the following sequence of operations: first, second, first. This way you spend $$$391 + 555 + 391 = 1337$$$ dollars.In the second test case both integers are equal to zero initially, so you dont' have to spend money.
You are given two integers $$$x$$$ and $$$y$$$. You can perform two types of operations: Pay $$$a$$$ dollars and increase or decrease any of these integers by $$$1$$$. For example, if $$$x = 0$$$ and $$$y = 7$$$ there are four possible outcomes after this operation: $$$x = 0$$$, $$$y = 6$$$; $$$x = 0$$$, $$$y = 8$...
For each test case print one integer — the minimum amount of dollars you have to spend.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 10^9$$$). The second line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9$$$).
standard output
standard input
Python 3
Python
1,000
train_017.jsonl
fce6803770ef2dfbdcde7627ba335e5f
256 megabytes
["2\n1 3\n391 555\n0 0\n9 4"]
PASSED
t=int(input()) while(t>0): t=t-1 l=[] x,y=map(int,input().split()) a,b=map(int,input().split()) if(x==0 and y==0): print(x) elif(x>y): a1=x-y a1=a1*a b1=y b1=b1*b l.append(abs(a1)+b1) a1=x*a b1=y*a l.append(abs(a1)+b1) ...
1587911700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["42", "7"]
9044eacc1833c667985c343a71fb4a58
NoteThe image for the first example: Several key points are marked blue, the answer contains some non-marked points as well.The image for the second example:
You are given $$$n$$$ segments on a Cartesian plane. Each segment's endpoints have integer coordinates. Segments can intersect with each other. No two segments lie on the same line.Count the number of distinct points with integer coordinates, which are covered by at least one segment.
Print a single integer — the number of distinct points with integer coordinates, which are covered by at least one segment.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of segments. Each of the next $$$n$$$ lines contains four integers $$$Ax_i, Ay_i, Bx_i, By_i$$$ ($$$-10^6 \le Ax_i, Ay_i, Bx_i, By_i \le 10^6$$$) — the coordinates of the endpoints $$$A$$$, $$$B$$$ ($$$A \ne B$$$) of the $$$i$$$-th s...
standard output
standard input
PyPy 3
Python
2,400
train_030.jsonl
e8da77cb46ac51e2c16d6199d540469a
256 megabytes
["9\n0 0 4 4\n-1 5 4 0\n4 0 4 4\n5 2 11 2\n6 1 6 7\n5 6 11 6\n10 1 10 7\n7 0 9 8\n10 -1 11 -1", "4\n-1 2 1 2\n-1 0 1 0\n-1 0 0 3\n0 3 1 0"]
PASSED
from math import gcd from bisect import * class Point: def __init__(self, x, y): self.x, self.y = x, y def __add__(self, val): return Point(self.x + val.x, self.y + val.y) def __sub__(self, val): return Point(self.x - val.x, self.y - val.y) def __mul__(self, ratio): retu...
1536330900
[ "number theory", "geometry" ]
[ 0, 1, 0, 0, 1, 0, 0, 0 ]
1 second
["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"]
0937a7e2f912fc094cc4275fd47cd457
NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled...
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the ga...
On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individu...
The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills.
standard output
standard input
Python 3
Python
1,500
train_024.jsonl
e090f3bd4d35427b7cdf99338edfc957
256 megabytes
["3\n1 2 1", "5\n2 3 3 1 1"]
PASSED
n = int(input()) a = list(map(int, input().split())) all = [] for i in range(n): all.append([a[i], i + 1]) all.sort(key = lambda x: x[0]) team_1 = [] team_2 = [] for i in range(n): if i % 2 == 0: team_1.append(all[i][1]) else: team_2.append(all[i][1]) print(len(team_1)) print(*team_1) pri...
1328886000
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["YES\nNO"]
465f1c612fa43313005d90cc8e9e6a24
NoteHere is a visualization of the first test case (the orange values denote the initial values and the blue ones the desired values): One possible order of operations to obtain the desired values for each node is the following: Operation $$$1$$$: Add $$$2$$$ to nodes $$$2$$$ and $$$3$$$. Operation $$$2$$$: Add $$$...
You have a connected undirected graph made of $$$n$$$ nodes and $$$m$$$ edges. The $$$i$$$-th node has a value $$$v_i$$$ and a target value $$$t_i$$$.In an operation, you can choose an edge $$$(i, j)$$$ and add $$$k$$$ to both $$$v_i$$$ and $$$v_j$$$, where $$$k$$$ can be any integer. In particular, $$$k$$$ can be nega...
For each test case, if it is possible for every node to reach its target after some number of operations, print "YES". Otherwise, print "NO".
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$), the number of test cases. Then the test cases follow. The first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$2 \leq n \leq 2\cdot 10^5$$$, $$$n-1\leq m\leq \min(2\cdot 10^5, \frac{n(n-1)}{2})$$$) — the number of nodes and ...
standard output
standard input
PyPy 3
Python
2,200
train_084.jsonl
24f06b8c054eb9061543f625a56e741c
256 megabytes
["2\n4 4\n5 1 2 -3\n3 3 10 1\n1 2\n1 4\n3 2\n3 4\n4 4\n5 8 6 6\n-3 1 15 4\n1 2\n1 4\n3 2\n3 4"]
PASSED
import bisect import copy import decimal import fractions import heapq import itertools import math import random import sys from collections import Counter, deque,defaultdict from functools import lru_cache,reduce from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max def _heappus...
1624026900
[ "math", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
1 second
["2\n2 3", "1\n2"]
dd26f45869b73137e5e5cc6820cdc2e4
null
Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple ta...
In the first line print single integer k — the minimal number of symbols that need to be replaced. In the second line print k distinct integers denoting the positions of symbols in the string s which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering o...
The first line contains two integers n and m (1 ≤ n ≤ m ≤ 1000) — the length of the string s and the length of the string t correspondingly. The second line contains n lowercase English letters — string s. The third line contains m lowercase English letters — string t.
standard output
standard input
PyPy 2
Python
1,000
train_012.jsonl
06d50f5fefee68e61096267cc049b0c9
256 megabytes
["3 5\nabc\nxaybz", "4 10\nabcd\nebceabazcd"]
PASSED
n, m = map(int, raw_input().split()) s = raw_input() t = raw_input() ans = float('inf') pos = [] for i in xrange(m-n+1): count = 0 tempPos = [] for j in xrange(n): if t[i+j] != s[j]: count += 1 tempPos.append(j+1) if count < ans: ans = count pos = tempP...
1499011500
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["3"]
5ea0351ac9f949dedae1928bfb7ebffa
null
Let's introduce the designation , where x is a string, n is a positive integer and operation " + " is the string concatenation operation. For example, [abc, 2] = abcabc.We'll say that string s can be obtained from string t, if we can remove some characters from string t and obtain string s. For example, strings ab and ...
In a single line print an integer — the largest number p. If the required value of p doesn't exist, print 0.
The first line contains two integers b, d (1 ≤ b, d ≤ 107). The second line contains string a. The third line contains string c. The given strings are not empty and consist of lowercase English letters. Their lengths do not exceed 100.
standard output
standard input
Python 2
Python
2,000
train_028.jsonl
9a74738784a0838c806bfede442df63f
256 megabytes
["10 3\nabab\nbab"]
PASSED
from itertools import repeat,chain from fractions import gcd def eternal(c,d, n = None): while True: yield chain.from_iterable(repeat(c,d)) def cyclic_array(arr): n = len(arr) def cyclar(i): return arr[i % n] return cyclar def find_repeat(enum,q_r_gen, a_n): a...
1370619000
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["Bob\nAlice\nAlice"]
4c5187193cf7f2d2721cedbb15b2a1c3
NoteIn the first testcase, in her turn, Alice can only choose $$$i = 2$$$, making the array equal $$$[1, 0]$$$. Then Bob, in his turn, will also choose $$$i = 2$$$ and make the array equal $$$[0, 0]$$$. As $$$a_1 = 0$$$, Alice loses.In the second testcase, once again, players can only choose $$$i = 2$$$. Then the array...
Alice and Bob are playing a game on an array $$$a$$$ of $$$n$$$ positive integers. Alice and Bob make alternating moves with Alice going first.In his/her turn, the player makes the following move: If $$$a_1 = 0$$$, the player loses the game, otherwise: Player chooses some $$$i$$$ with $$$2\le i \le n$$$. Then player de...
For each test case, if Alice will win the game, output "Alice". Otherwise, output "Bob". You can output each letter in any case. For example, "alIcE", "Alice", "alice" will all be considered identical.
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 2 \cdot 10^4)$$$  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ $$$(2 \leq n \leq 10^5)$$$  — the length of the array ...
standard output
standard input
Python 3
Python
1,200
train_087.jsonl
9f687f7bb394d63b4df6f246c7bbbc5f
256 megabytes
["3\n\n2\n\n1 1\n\n2\n\n2 1\n\n3\n\n5 4 4"]
PASSED
for i in range(int(input())): n=int(input()) l=list(map(int,input().split())) d=min(l) if d==l[0]: print("Bob") else: print("Alice")
1667572500
[ "games" ]
[ 1, 0, 0, 0, 0, 0, 0, 0 ]
1 second
["1", "8"]
3b7cafc280a9b0dba567863c80b978b0
NoteIn the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.
You are given n × m table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: All cells in a set have the same color. Every two cells in a set share row or column.
Output single integer  — the number of non-empty sets from the problem description.
The first line of input contains integers n and m (1 ≤ n, m ≤ 50) — the number of rows and the number of columns correspondingly. The next n lines of input contain descriptions of rows. There are m integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 i...
standard output
standard input
PyPy 2
Python
1,300
train_015.jsonl
0a5a4486701e3377db660db3213414ac
256 megabytes
["1 1\n0", "2 3\n1 0 1\n0 1 0"]
PASSED
n,m = map(int, raw_input().split(" ")) a =[] for i in range(n): b = map(int, raw_input().split(" ")) a.append(b) ans=0 for i in range(n): d={1:0, 0:0} for j in a[i]: if j==0: d[0]+=1 else: d[1]+=1 ans+=pow(2,d[0])-1 ans+=pow(2,d[1])-1 c =[[] for i in range...
1503592500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1227\n-1\n17703\n2237344218521717191"]
8f00837e04627e445dfb8b6cd0216640
NoteIn the first test case of the example, $$$1227$$$ is already an ebne number (as $$$1 + 2 + 2 + 7 = 12$$$, $$$12$$$ is divisible by $$$2$$$, while in the same time, $$$1227$$$ is not divisible by $$$2$$$) so we don't need to delete any digits. Answers such as $$$127$$$ and $$$17$$$ will also be accepted.In the secon...
Let's define a number ebne (even but not even) if and only if its sum of digits is divisible by $$$2$$$ but the number itself is not divisible by $$$2$$$. For example, $$$13$$$, $$$1227$$$, $$$185217$$$ are ebne numbers, while $$$12$$$, $$$2$$$, $$$177013$$$, $$$265918$$$ are not. If you're still unsure what ebne numbe...
For each test case given in the input print the answer in the following format: If it is impossible to create an ebne number, print "-1" (without quotes); Otherwise, print the resulting number after deleting some, possibly zero, but not all digits. This number should be ebne. If there are multiple answers, you can pri...
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3000$$$)  — the number of digits in the original...
standard output
standard input
Python 3
Python
900
train_005.jsonl
43ca9ecef047c647f9aaa3a015cbf9dc
256 megabytes
["4\n4\n1227\n1\n0\n6\n177013\n24\n222373204424185217171912"]
PASSED
t =int(input()) while t!=0: t-=1 n=int(input()) s=input() ar=[] sar=[] for i in s: if i!='0': ar.append(int(i)) sar.append(i) if len(ar)==0 or len(ar)==1 : print(-1) continue else: tsum=sum(ar) if tsum%2==0 and ar[l...
1580652300
[ "math", "strings" ]
[ 0, 0, 0, 1, 0, 0, 1, 0 ]
2 seconds
["11.084259940083", "33.121375178000"]
ae8687ed3cb5df080fb6ee79b040cef1
NoteConsider the first sample.Adil will use the following path: .Bera will use the following path: .Adil's path will be units long, while Bera's path will be units long.
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can car...
Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker...
First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively. The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground. Then follow n lines, each of them contains two...
standard output
standard input
Python 3
Python
1,800
train_000.jsonl
8694d69785e15093f3cc9909d405f96b
256 megabytes
["3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3"]
PASSED
ax,ay,bx,by,tx,ty=map(int,input().split()) n=int(input()) l=[tuple(map(int,input().split())) for _ in range(n)] a,b=[],[] for i in range(n): x,y=l[i] lt=((tx-x)*(tx-x)+(ty-y)*(ty-y))**0.5 la=((ax-x)*(ax-x)+(ay-y)*(ay-y))**0.5 lb=((bx-x)*(bx-x)+(by-y)*(by-y))**0.5 a+=[(la-lt,i)] b+=[(lb-lt,i)] a.sort();b.sor...
1462984500
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
1 second
["141", "25", "183"]
de6361f522936eac3d88b7268b8c2793
NoteIn sample case one it's optimal to use autocompletion for the first instance of «snowboarding» after typing up «sn» and for the second instance of «snowboarding» after typing up «snowb». This will save 7 clicks.In sample case two it doesn't matter whether to use autocompletion or not.
Arcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor.Arcady types words, punctuation signs and spaces one after another. Each letter and each sign (including line feed) requires one keyboard click in order to be printed. Moreover, when Arcady has a non-emp...
Print a single integer — the minimum number of clicks.
The only line contains Arcady's text, consisting only of lowercase latin letters, spaces, line feeds and the following punctuation signs: «.», «,», «?», «!», «'» and «-». The total amount of symbols doesn't exceed 3·105. It's guaranteed that all lines are non-empty.
standard output
standard input
Python 3
Python
1,900
train_035.jsonl
55d9a0f55e02784d19864ca9f406eea2
256 megabytes
["snow affects sports such as skiing, snowboarding, and snowmachine travel.\nsnowboarding is a recreational activity and olympic and paralympic sport.", "'co-co-co, codeforces?!'", "thun-thun-thunder, thunder, thunder\nthunder, thun-, thunder\nthun-thun-thunder, thunder\nthunder, feel the thunder\nlightning then the th...
PASSED
class Ddict: def __init__(self): self.dicts={} def add(self,key): d=self.dicts for i in key: if i not in d: d[i]={} d=d[i] d[' ']='' def find(self,key): if key=='': return '','' d=self.dicts q=[] ...
1519486500
[ "trees", "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 1 ]
1 second
["0\n1\n12\n499999999"]
c34db7897f051b0de2f49f2696c6ee2f
NoteIn the first test case, the only allowed pair is $$$(a, b) = (1, 1)$$$, for which $$$a \bmod b = 1 \bmod 1 = 0$$$.In the second test case, the optimal choice is pair $$$(a, b) = (1000000000, 999999999)$$$, for which $$$a \bmod b = 1$$$.
You are given two integers $$$l$$$ and $$$r$$$, $$$l\le r$$$. Find the largest possible value of $$$a \bmod b$$$ over all pairs $$$(a, b)$$$ of integers for which $$$r\ge a \ge b \ge l$$$.As a reminder, $$$a \bmod b$$$ is a remainder we get when dividing $$$a$$$ by $$$b$$$. For example, $$$26 \bmod 8 = 2$$$.
For every test case, output the largest possible value of $$$a \bmod b$$$ over all pairs $$$(a, b)$$$ of integers for which $$$r\ge a \ge b \ge l$$$.
Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ $$$(1\le t\le 10^4)$$$, denoting the number of test cases. Description of the test cases follows. The only line of each test case contains two integers $$$l$$$, $$$r$$$ ($$$1\le l \le r \le 10^9$$$).
standard output
standard input
Python 3
Python
800
train_086.jsonl
49df8e8d76f98d081f15aa806539cd06
256 megabytes
["4\n1 1\n999999999 1000000000\n8 26\n1 999999999"]
PASSED
import os, sys import math from io import BytesIO, IOBase from collections import Counter # Fast IO Region BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "...
1629988500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["27", "9"]
0cc9e1f64f615806d07e657be7386f5b
NoteIn the first sample the result equals (1 + 08) + (10 + 8) = 27.In the second sample the result equals 1 + 0 + 8 = 9.
Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out n numbers on a single line. After that, Vasya began to write out different ways to put pluses ("+") in the line between certain digits in the line so that the result was a correct arithmetic expression; formally, no ...
Print the answer to the problem modulo 109 + 7.
The first line contains two integers, n and k (0 ≤ k &lt; n ≤ 105). The second line contains a string consisting of n digits.
standard output
standard input
Python 3
Python
2,200
train_002.jsonl
fece09dfb0961b9b215cffd62afd564f
256 megabytes
["3 1\n108", "3 2\n108"]
PASSED
n, k = map(int, input().split()) t = list(map(int, input())) p, d = 1, 10 ** 9 + 7 s, f = 0, [1] * n for i in range(2, n): f[i] = (i * f[i - 1]) % d c = lambda a, b: 0 if a > b else (f[b] * pow(f[a] * f[b - a], d - 2, d)) % d if k: u = [0] * (n + 1) p = [1] * (n + 1) for i in range(n): u[i] = (p[i] ...
1425279600
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
1 second
["1", "2", "-1"]
9115965ff3421230eac37b22328c6153
NoteIn the first example, the greatest common divisor is $$$1$$$ in the beginning. You can remove $$$1$$$ so that the greatest common divisor is enlarged to $$$2$$$. The answer is $$$1$$$.In the second example, the greatest common divisor is $$$3$$$ in the beginning. You can remove $$$6$$$ and $$$9$$$ so that the great...
Mr. F has $$$n$$$ positive integers, $$$a_1, a_2, \ldots, a_n$$$.He thinks the greatest common divisor of these integers is too small. So he wants to enlarge it by removing some of the integers.But this problem is too simple for him, so he does not want to do it by himself. If you help him, he will give you some scores...
Print an integer — the minimum number of integers you need to remove so that the greatest common divisor of the remaining integers is bigger than that of all integers. You should not remove all of the integers. If there is no solution, print «-1» (without quotes).
The first line contains an integer $$$n$$$ ($$$2 \leq n \leq 3 \cdot 10^5$$$) — the number of integers Mr. F has. The second line contains $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 1.5 \cdot 10^7$$$).
standard output
standard input
PyPy 2
Python
1,800
train_009.jsonl
a7be496d9cfe2abb4ffed5d77715e8f0
256 megabytes
["3\n1 2 4", "4\n6 9 15 30", "3\n1 1 1"]
PASSED
def gcd(a, b): while b: c = a%b a = b b = c return a import sys raw_input = sys.stdin.readline sieve = [0] * (15000001) i = 2 while i <= 15000000: sieve[i] = 2 i += 2 i = 3 while i < 15000000: if sieve[i]: i += 2 continue sieve[i] = i j = i*i whi...
1537540500
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
2 seconds
["10\n1 2 3", "99\n2 1", "-9\n3 5 6 1 9 4 10 7 8 2"]
5ebae703049e9ab4547df87861034176
null
Captain Fint is involved in another treasure hunt, but have found only one strange problem. The problem may be connected to the treasure's location or may not. That's why captain Flint decided to leave the solving the problem to his crew and offered an absurdly high reward: one day off. The problem itself sounds like t...
In the first line, print the maximum $$$ans$$$ you can get. In the second line, print the order of operations: $$$n$$$ different integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \le p_i \le n$$$). The $$$p_i$$$ is the position which should be chosen at the $$$i$$$-th step. If there are multiple orders, print any of them.
The first line contains the integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of arrays $$$a$$$ and $$$b$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$−10^6 \le a_i \le 10^6$$$). The third line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le n$$$ or $$...
standard output
standard input
PyPy 3
Python
2,000
train_039.jsonl
d4a99228d2d306cb7e9777c1de2019dd
256 megabytes
["3\n1 2 3\n2 3 -1", "2\n-1 100\n2 -1", "10\n-10 -1 2 2 5 -2 -3 -4 2 -6\n-1 -1 2 2 -1 5 5 7 7 9"]
PASSED
import sys;input=sys.stdin.readline N, = map(int, input().split()) X = [0]+list(map(int, input().split())) Y = [0]+list(map(int, input().split())) st = [] G = [set() for _ in range(N+1)] for i in range(1, N+1): if Y[i] < 0: st.append(i) else: G[Y[i]].add(i) ato = [] R = [] W = [0]*(N+1) for s i...
1596119700
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
2 seconds
["2 1\n3 1 2\n1 6 5 8 3 2 4 7"]
0903a40d72c19a9d1cc1147d01ea94a7
NoteIn the first testcase, there exists only one permutation $$$q$$$ such that each liked song is rating higher than each disliked song: song $$$1$$$ gets rating $$$2$$$ and song $$$2$$$ gets rating $$$1$$$. $$$\sum\limits_{i=1}^n |p_i-q_i|=|1-2|+|2-1|=2$$$.In the second testcase, Monocarp liked all songs, so all permu...
Berland Music is a music streaming service built specifically to support Berland local artist. Its developers are currently working on a song recommendation module.So imagine Monocarp got recommended $$$n$$$ songs, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th song had its predicted rating equal to $$$p_i$$$, where ...
For each testcase, print a permutation $$$q$$$ — the re-evaluated ratings of the songs. If there are multiple answers such that $$$\sum\limits_{i=1}^n |p_i-q_i|$$$ is minimum possible, you can print any of them.
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$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of songs. The second line of each testcase contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p...
standard output
standard input
Python 3
Python
1,000
train_085.jsonl
654feabfa49f056eedf2d0f1a93f911a
256 megabytes
["3\n2\n1 2\n10\n3\n3 1 2\n111\n8\n2 3 1 8 5 4 7 6\n01110001"]
PASSED
t= int(input()) for i in range(t): n= int(input()) p= [int(x) for x in input().split()] s= [int(x) for x in input()] l= sorted([[s[i], p[i], i] for i in range(n)]) q= [0] * n for i in range(n): q[l[i][2]] = i+1 print(*q)
1640615700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["6.00000000", "6.50000000"]
822e8f394a59329fa05c96d7fb35797e
NoteIn the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (a3 + a4) / 2 + a2 = (3 + 2) / 2 + 4 = 6.5
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities. The wealth of the i of them is equal to ai. Authorities plan to build two cities, first for n1 people and second for n2 peo...
Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer ...
The first line of the input contains three integers n, n1 and n2 (1 ≤ n, n1, n2 ≤ 100 000, n1 + n2 ≤ n) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city. The second line contains n integers a1, a2, ..., an...
standard output
standard input
Python 3
Python
1,100
train_016.jsonl
e1b7cfed7e781d598b5f66b0a56bf9ed
256 megabytes
["2 1 1\n1 5", "4 2 1\n1 4 2 3"]
PASSED
i = lambda: map(int, input().split()) n, x, y = i() a = sorted(i())[::-1] if x > y: x, y = y, x print(sum(a[:x])/x + sum(a[x:][:y])/y)
1480264500
[ "number theory" ]
[ 0, 0, 0, 0, 1, 0, 0, 0 ]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
3fb70a77e4de4851ed93f988140df221
null
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≤ i ≤ j ≤ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≤ l ≤ |s|) is string s[1..l]. The suffix of string s of length l (1 ...
In the first line, print integer k (0 ≤ k ≤ |s|) — the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in t...
The single line contains a sequence of characters s1s2...s|s| (1 ≤ |s| ≤ 105) — string s. The string only consists of uppercase English letters.
standard output
standard input
Python 3
Python
2,000
train_054.jsonl
34ca44611c717c1b164a2ddb50108653
256 megabytes
["ABACABA", "AAA"]
PASSED
def z_advanced(s): """An advanced computation of Z-values of a string.""" Z = [0] * len(s) Z[0] = len(s) rt = 0 lt = 0 for k in range(1, len(s)): if k > rt: # If k is outside the current Z-box, do naive computation. n = 0 while n + k < len(s) and s...
1400167800
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
1 second
["YES\n1 0\n2 3\n4 1", "NO"]
5c026adda2ae3d7b707d5054bd84db3f
NoteIn the first example area of the triangle should be equal to $$$\frac{nm}{k} = 4$$$. The triangle mentioned in the output is pictured below: In the second example there is no triangle with area $$$\frac{nm}{k} = \frac{16}{7}$$$.
Vasya has got three integers $$$n$$$, $$$m$$$ and $$$k$$$. He'd like to find three integer points $$$(x_1, y_1)$$$, $$$(x_2, y_2)$$$, $$$(x_3, y_3)$$$, such that $$$0 \le x_1, x_2, x_3 \le n$$$, $$$0 \le y_1, y_2, y_3 \le m$$$ and the area of the triangle formed by these points is equal to $$$\frac{nm}{k}$$$.Help Vasya...
If there are no such points, print "NO". Otherwise print "YES" in the first line. The next three lines should contain integers $$$x_i, y_i$$$ — coordinates of the points, one point per line. If there are multiple solutions, print any of them. You can print each letter in any case (upper or lower).
The single line contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$1\le n, m \le 10^9$$$, $$$2 \le k \le 10^9$$$).
standard output
standard input
PyPy 3
Python
1,800
train_005.jsonl
3ab5974739b59a2f7707451462505fae
256 megabytes
["4 3 3", "4 4 7"]
PASSED
#Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict BUFSIZE = 8192 class FastIO(IOBase): ...
1537707900
[ "number theory", "geometry" ]
[ 0, 1, 0, 0, 1, 0, 0, 0 ]
1 second
["-2", "10"]
a12103bd632fa73a7faab71df3fd0164
NoteNote that the answer to the problem can be negative.The GCD(x1, x2, ..., xk) is the maximum positive integer that divides each xi.
You have an array of positive integers a[1], a[2], ..., a[n] and a set of bad prime numbers b1, b2, ..., bm. The prime numbers that do not occur in the set b are considered good. The beauty of array a is the sum , where function f(s) is determined as follows: f(1) = 0; Let's assume that p is the minimum prime divisor...
Print a single integer — the answer to the problem.
The first line contains two integers n and m (1 ≤ n, m ≤ 5000) showing how many numbers are in the array and how many bad prime numbers there are. The second line contains n space-separated integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109) — array a. The third line contains m space-separated integers b1, b2, ..., bm (2 ≤...
standard output
standard input
Python 2
Python
1,800
train_040.jsonl
360d4e4cbb892f4bfead7c8cae357d0d
256 megabytes
["5 2\n4 20 34 10 10\n2 5", "4 5\n2 4 8 16\n3 5 7 11 17"]
PASSED
import fractions n, m = map(int, raw_input().split()) primes_cache = {} primes = [] def lowest_prime_divisor(x, sorted_primes_to_check=primes, cache=primes_cache): if x in cache: return cache[x] for i in sorted_primes_to_check: if i * i > x: cache[x] = x return x...
1394983800
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["2 4\n1 4\n3 4\n3 1\n3 2", "-1"]
1a9968052a363f04380d1177c764717b
null
Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following defin...
If Vladislav has made a mistake and such graph doesn't exist, print  - 1. Otherwise print m lines. On the j-th line print a pair of vertices (uj, vj) (1 ≤ uj, vj ≤ n, uj ≠ vj), that should be connected by the j-th edge. The edges are numbered in the same order as in the input. The graph, determined by these edges, must...
The first line of the input contains two integers n and m () — the number of vertices and the number of edges in the graph. Each of the next m lines describes an edge of the graph and consists of two integers aj and bj (1 ≤ aj ≤ 109, bj = {0, 1}). The first of these numbers is the weight of the edge and the second numb...
standard output
standard input
Python 3
Python
1,700
train_056.jsonl
9b5f207249c2428d5556fcf64cc48092
256 megabytes
["4 5\n2 1\n3 1\n4 0\n1 1\n5 0", "3 3\n1 0\n2 1\n3 1"]
PASSED
import sys from operator import itemgetter lines = sys.stdin.readlines() n, m = map(int, lines[0].split(' ')) def build_edge(i, row): parts = row.split(' ') return (int(parts[0]), int(parts[1]), i) def edge_key(a): return (a[0], -a[1]) edges = [build_edge(i, row) for i, row in enumerate(lines[1:])] edges = sorte...
1449677100
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["2", "3"]
40a965a28e38bad3aff9c58bdeeeb8f6
null
Further research on zombie thought processes yielded interesting results. As we know from the previous problem, the nervous system of a zombie consists of n brains and m brain connectors joining some pairs of brains together. It was observed that the intellectual abilities of a zombie depend mainly on the topology of i...
Print one number – the brain latency.
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100000) denoting the number of brains (which are conveniently numbered from 1 to n) and the number of brain connectors in the nervous system, respectively. In the next m lines, descriptions of brain connectors follow. Every connector ...
standard output
standard input
Python 3
Python
1,500
train_004.jsonl
5000894a71456b418e95fea3047708d8
256 megabytes
["4 3\n1 2\n1 3\n1 4", "5 4\n1 2\n2 3\n3 4\n3 5"]
PASSED
# itne me hi thakk gaye? def bfs(x, g): n, q = len(g), [x] dist = [0 if y == x else -1 for y in range(n)] i = 0 while i < len(q): v = q[i] i += 1 for to in g[v]: if dist[to] < 0: dist[to] = dist[v] + 1 q.append(to) return (q[-1], di...
1468137600
[ "trees", "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 1 ]
2 seconds
["5\n1 2 4 3 0", "6\n3 9 2 9 8 0"]
5a3bbc6668268dabb49316a1c8d4ea8c
NoteFor the first case, the prefix products of this sequence modulo m are [1, 2, 3, 4, 0].For the second case, the prefix products of this sequence modulo m are [3, 7, 4, 6, 8, 0].
You are given an integer m, and a list of n distinct integers between 0 and m - 1.You would like to construct a sequence satisfying the properties: Each element is an integer between 0 and m - 1, inclusive. All prefix products of the sequence modulo m are distinct. No prefix product modulo m appears as an element of...
On the first line, print the number k, denoting the length of your sequence. On the second line, print k space separated integers, denoting your sequence.
The first line of input contains two integers n and m (0 ≤ n &lt; m ≤ 200 000) — the number of forbidden prefix products and the modulus. If n is non-zero, the next line of input contains n distinct integers between 0 and m - 1, the forbidden prefix products. If n is zero, this line doesn't exist.
standard output
standard input
PyPy 3
Python
2,300
train_051.jsonl
25d0761f13a23b6619cb8e739dd2595c
256 megabytes
["0 5", "3 10\n2 9 1"]
PASSED
import math def gcdExtended(a, b): # Base Case if a == 0 : return b, 0, 1 gcd, x1, y1 = gcdExtended(b%a, a) # Update x and y using results of recursive # call x = y1 - (b//a) * x1 y = x1 return gcd, x, y def rev_elem(x, m): r...
1492356900
[ "number theory", "math", "graphs" ]
[ 0, 0, 1, 1, 1, 0, 0, 0 ]
2 seconds
["NO\nYES\nYES"]
044c2a3bafe4f47036ee81f2e40f639a
NoteIn the first test case, we can prove that we can't make all $$$a_i \le 3$$$.In the second test case, all $$$a_i$$$ are already less or equal than $$$d = 4$$$.In the third test case, we can, for example, choose $$$i = 5$$$, $$$j = 1$$$, $$$k = 2$$$ and make $$$a_5 = a_1 + a_2 = 2 + 1 = 3$$$. Array $$$a$$$ will becom...
You have an array $$$a_1, a_2, \dots, a_n$$$. All $$$a_i$$$ are positive integers.In one step you can choose three distinct indices $$$i$$$, $$$j$$$, and $$$k$$$ ($$$i \neq j$$$; $$$i \neq k$$$; $$$j \neq k$$$) and assign the sum of $$$a_j$$$ and $$$a_k$$$ to $$$a_i$$$, i. e. make $$$a_i = a_j + a_k$$$.Can you make all...
For each test case, print YES, if it's possible to make all elements $$$a_i$$$ less or equal than $$$d$$$ using the operation above. Otherwise, print NO. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$d$$$ ($$$3 \le n \le 100$$$; $$$1 \le d \le 100$$$) — the number of elements in the array $$$a$$$ and the value $$$d$$$. The second line contains $$...
standard output
standard input
Python 3
Python
800
train_106.jsonl
6aec5e0fe0295869b8b1a0965ef998bb
256 megabytes
["3\n5 3\n2 3 2 5 4\n3 4\n2 4 4\n5 4\n2 1 5 3 6"]
PASSED
for t in range(int(input())): n,d=map(int,input().split()) lst=sorted(map(int,input().split())) print ("YES" if min(lst[0] + lst[1], lst[-1]) <=d else "NO")
1610634900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1 2 0", "43 42 41 1337 1336", "4 3 2 1 2"]
48c8ce45ab38a382dc52db1e59be234f
null
You are given a directed acyclic graph (a directed graph that does not contain cycles) of $$$n$$$ vertices and $$$m$$$ arcs. The $$$i$$$-th arc leads from the vertex $$$x_i$$$ to the vertex $$$y_i$$$ and has the weight $$$w_i$$$.Your task is to select an integer $$$a_v$$$ for each vertex $$$v$$$, and then write a numbe...
Print $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$0 \le a_v \le 10^9$$$), which must be written on the vertices so that all $$$b_i$$$ are positive, and the value of the expression $$$\sum \limits_{i = 1}^{m} w_i b_i$$$ is the lowest possible. If there are several answers, print any of them. It can be show...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 18$$$; $$$0 \le m \le \dfrac{n(n - 1)}{2}$$$). Then $$$m$$$ lines follow, the $$$i$$$-th of them contains three integers $$$x_i$$$, $$$y_i$$$ and $$$w_i$$$ ($$$1 \le x_i, y_i \le n$$$, $$$1 \le w_i \le 10^5$$$, $$$x_i \ne y_i$$$) — the description...
standard output
standard input
PyPy 3
Python
2,600
train_047.jsonl
c4e0a7fa0d9ff0c6153f616078f138bb
1024 megabytes
["3 2\n2 1 4\n1 3 2", "5 4\n1 2 1\n2 3 1\n1 3 6\n4 5 8", "5 5\n1 2 1\n2 3 1\n3 4 1\n1 5 1\n5 4 10"]
PASSED
from heapq import heappush, heappop class MinCostFlow: INF = 10**18 def __init__(self, N): self.N = N self.G = [[] for i in range(N)] def add_edge(self, fr, to, cap, cost): forward = [to, cap, cost, None] backward = forward[3] = [fr, 0, -cost, forward] self.G[fr].ap...
1602407100
[ "math", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
2 seconds
["1\n2\n-1\n1", "0\n1\n0\n-1", "-1\n-1\n-1", "-1"]
883f728327aea19993089a65d452b79f
null
Why I have to finish so many assignments???Jamie is getting very busy with his school life. He starts to forget the assignments that he has to do. He decided to write the things down on a to-do list. He assigns a value priority for each of his assignment (lower value means more important) so he can decide which he need...
For each query operation, output a single integer — the number of assignments that have a priority lower than assignment ai, or  - 1 if ai is not in the to-do list.
The first line consists of a single integer q (1 ≤ q ≤ 105) — the number of operations. The following q lines consists of the description of the operations. The i-th line consists of the operation that Jamie has done in the i-th day. The query has the following format: The first word in the line indicates the type of o...
standard output
standard input
PyPy 2
Python
2,200
train_044.jsonl
932ccde0446ccee0b75faadf77810094
512 megabytes
["8\nset chemlabreport 1\nset physicsexercise 2\nset chinesemockexam 3\nquery physicsexercise\nquery chinesemockexam\nremove physicsexercise\nquery physicsexercise\nquery chinesemockexam", "8\nset physicsexercise 2\nset chinesemockexam 3\nset physicsexercise 1\nquery physicsexercise\nquery chinesemockexam\nundo 4\nquer...
PASSED
import sys, os, __pypy__ from collections import defaultdict from cStringIO import StringIO from io import IOBase range = xrange input = raw_input L = [] R = [] A = [0] __pypy__.resizelist_hint(L, 50*10**5) __pypy__.resizelist_hint(R, 50*10**5) __pypy__.resizelist_hint(A, 50*10**5) def create(): L.append(-1) ...
1516372500
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
3 seconds
["500000.000000000000000000000000000000", "400.000000000000000000000000000000"]
7de7e7983909d7a8f51fee4fa9ede838
NoteIn the first example, it is optimal to place the bomb at a point with a coordinate of 400000. Then at time 0, the speed of the first person becomes 1000 and he reaches the point 106 at the time 600. The bomb will not affect on the second person, and he will reach the 0 point at the time 500000.In the second example...
n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed.You can put a bomb in some point with non-negative integer coordinate, and blow it up. At this moment all people w...
Print the minimum time needed for both points 0 and 106 to be reached. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Namely, if your answer is a, and the jury's answer is b, then your answer is accepted, if .
The first line contains two integers n and s (2 ≤ n ≤ 105, 2 ≤ s ≤ 106) — the number of people and the rays' speed. The next n lines contain the description of people. The i-th of these lines contains three integers xi, vi and ti (0 &lt; xi &lt; 106, 1 ≤ vi &lt; s, 1 ≤ ti ≤ 2) — the coordinate of the i-th person on the...
standard output
standard input
Python 3
Python
2,500
train_039.jsonl
a42d6d5c84b635e9620546ca9fdef8de
256 megabytes
["2 999\n400000 1 2\n500000 1 1", "2 1000\n400000 500 1\n600000 500 2"]
PASSED
import math leftpeople = set() rightpeople = set() n, vl = map(int, input().split()) def leftinterval(x0, v0, t): if x0 / v0 <= t: return (0, 10**6) if x0 / (vl + v0) > t: return (-1, -2) leftbound = x0 rightbound = (vl * vl - v0 * v0) * t + x0 * v0 rightbound /= vl rightbound ...
1500906900
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["bcdefghijklmnopqrsatuvwxyz", "Impossible", "aghjlnopefikdmbcqrstuvwxyz", "acbdefhijklmnogpqrstuvwxyz"]
12218097cf5c826d83ab11e5b049999f
null
Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in the lexicographical order. After checking some examples, she found out that sometimes it wasn't true. On some papers authors' names weren't sorted in lex...
If there exists such order of letters that the given names are sorted lexicographically, output any such order as a permutation of characters 'a'–'z' (i. e. first output the first letter of the modified alphabet, then the second, and so on). Otherwise output a single word "Impossible" (without quotes).
The first line contains an integer n (1 ≤ n ≤ 100): number of names. Each of the following n lines contain one string namei (1 ≤ |namei| ≤ 100), the i-th name. Each name contains only lowercase Latin letters. All names are different.
standard output
standard input
Python 3
Python
1,600
train_006.jsonl
985dff6833c2e9ba3cd6fee94083193f
256 megabytes
["3\nrivest\nshamir\nadleman", "10\ntourist\npetr\nwjmzbmr\nyeputons\nvepifanov\nscottwu\noooooooooooooooo\nsubscriber\nrowdark\ntankengineer", "10\npetr\negor\nendagorion\nfeferivan\nilovetanyaromanova\nkostka\ndmitriyh\nmaratsnowbear\nbredorjaguarturnik\ncgyforever", "7\ncar\ncare\ncareful\ncarefully\nbecarefuldontfo...
PASSED
def go_through(given_char): global order global freq global orders if given_char in orders: while orders[given_char]: next_letter = orders[given_char].pop() freq[next_letter] = freq[next_letter] - 1 go_through(next_letter) if given_char not in order: ...
1422894600
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["0", "2", "1"]
acd48e32c96a10cc0d4161225407bf67
NoteFor each example you have a picture which illustrates it.The first picture for each example describes the initial set of element samples available. Black crosses represent elements available in the lab initially.The second picture describes how remaining samples can be obtained. Red dashed circles denote elements t...
Innopolis University scientists continue to investigate the periodic table. There are n·m known elements and they form a periodic table: a rectangle with n rows and m columns. Each element can be described by its coordinates (r, c) (1 ≤ r ≤ n, 1 ≤ c ≤ m) in the table.Recently scientists discovered that for every four d...
Print the minimal number of elements to be purchased.
The first line contains three integers n, m, q (1 ≤ n, m ≤ 200 000; 0 ≤ q ≤ min(n·m, 200 000)), the chemical table dimensions and the number of elements scientists already have. The following q lines contain two integers ri, ci (1 ≤ ri ≤ n, 1 ≤ ci ≤ m), each describes an element that scientists already have. All elemen...
standard output
standard input
Python 3
Python
1,900
train_031.jsonl
d751140f3c28dfdfc271bc1271caf119
512 megabytes
["2 2 3\n1 2\n2 2\n2 1", "1 5 3\n1 3\n1 1\n1 5", "4 3 6\n1 2\n1 3\n2 2\n2 3\n3 1\n3 3"]
PASSED
from sys import stdin def main(): n, m, q = map(int, input().split()) chm = list(range(n + m)) r = [0] * (n + m) n -= 1 res = n + m for s in stdin.read().splitlines(): a, b = map(int, s.split()) a -= 1 b += n l = [] while a != chm[a]: l.appen...
1532938500
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
1 second
["12\n3 4\n1 2 3 5\n3 1 5 4\n5 6 8 9", "1\n1 1\n1"]
db447a8896347bb47ce05a1df334a8b3
null
You are given $$$n$$$ integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the $$$n$$$ numbers may not be chosen.A rectangle (rectangul...
In the first line print $$$x$$$ ($$$1 \le x \le n$$$) — the total number of cells of the required maximum beautiful rectangle. In the second line print $$$p$$$ and $$$q$$$ ($$$p \cdot q=x$$$): its sizes. In the next $$$p$$$ lines print the required rectangle itself. If there are several answers, print any.
The first line contains $$$n$$$ ($$$1 \le n \le 4\cdot10^5$$$). The second line contains $$$n$$$ integers ($$$1 \le a_i \le 10^9$$$).
standard output
standard input
Python 3
Python
2,300
train_009.jsonl
a0bfd8e7bd1558537a370e3239202980
256 megabytes
["12\n3 1 4 1 5 9 2 6 5 3 5 8", "5\n1 1 1 1 1"]
PASSED
from collections import Counter from itertools import accumulate from math import sqrt from operator import itemgetter import sys n = int(input()) cnt = Counter(map(int, input().split())) nums, counts = zip(*sorted(cnt.items(), key=itemgetter(1))) acc = [0] + list(accumulate(counts)) area = 1 h, w = 1, 1 i = len(cou...
1576321500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["3\n2\n4 3\n3 1"]
b97db0567760f2fc5d3ca15611fe7177
NoteIn the first sample test we swap numbers on positions 3 and 4 and permutation p becomes 4 2 3 1. We pay |3 - 4| = 1 coins for that. On second turn we swap numbers on positions 1 and 3 and get permutation 3241 equal to s. We pay |3 - 1| = 2 coins for that. In total we pay three coins.
Anton loves transforming one permutation into another one by swapping elements for money, and Ira doesn't like paying for stupid games. Help them obtain the required permutation by paying as little money as possible.More formally, we have two permutations, p and s of numbers from 1 to n. We can swap pi and pj, by payin...
In the first line print the minimum number of coins that you need to spend to transform permutation p into permutation s. In the second line print number k (0 ≤ k ≤ 2·106) — the number of operations needed to get the solution. In the next k lines print the operations. Each line must contain two numbers i and j (1 ≤ i, ...
The first line contains a single number n (1 ≤ n ≤ 2000) — the length of the permutations. The second line contains a sequence of n numbers from 1 to n — permutation p. Each number from 1 to n occurs exactly once in this line. The third line contains a sequence of n numbers from 1 to n — permutation s. Each number from...
standard output
standard input
Python 2
Python
2,300
train_048.jsonl
ec4fe4aae531b51db135f9ad6d812061
256 megabytes
["4\n4 2 1 3\n3 2 4 1"]
PASSED
def sol1(): #wrong solution global n, p1, p2, di, di2 swaps = [] cost = 0 flag = True while flag: flag = False for i in range(n-1): if di[p1[i]] > di[p1[i+1]]: temp = p1[i] p1[i] = p1[i+1] p1[i+1] = p1[i] cost += 1 swaps.append( (i,i+1) ) flag = True def sol2(): global n, p1, p2,...
1444149000
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["1\n2\n3\n4\n8\n12\n5\n10\n15"]
37c3725f583ca33387dfd05fe75898a9
NoteThe first elements of $$$s$$$ are $$$1, 2, 3, 4, 8, 12, 5, 10, 15, \dots $$$
Consider the infinite sequence $$$s$$$ of positive integers, created by repeating the following steps: Find the lexicographically smallest triple of positive integers $$$(a, b, c)$$$ such that $$$a \oplus b \oplus c = 0$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. $$$a$$$, $$$b$$$, $$$c$$$ are not in $...
In each of the $$$t$$$ lines, output the answer to the corresponding test case.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each of the next $$$t$$$ lines contains a single integer $$$n$$$ ($$$1\le n \le 10^{16}$$$) — the position of the element you want to know.
standard output
standard input
Python 3
Python
2,200
train_012.jsonl
6476e4a08ca6045c10cb4c65ac689850
256 megabytes
["9\n1\n2\n3\n4\n5\n6\n7\n8\n9"]
PASSED
import sys lines = sys.stdin.readlines() T = int(lines[0].strip()) partial = [1, 2, 3, 4, 8, 12, 5, 10, 15, 6, 11, 13, 7, 9, 14, 16, 32, 48, 17, 34, 51, 18, 35, 49, 19, 33, 50, 20, 40, 60, 21, 42, 63, 22, 43, 61, 23, 41, 62, 24, 44, 52, 25, 46, 55, 26, 47, 53, 27, 45, 54, 28, 36, 56, 29, 38, 59, 30, 39, 57, 31, 37, 58,...
1586700300
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
2 seconds
["Possible\n4\n-6\n8\n-7\n7", "Impossible"]
666b710742bb710dda112e4a6bbbe96b
null
You have to handle a very complex water distribution system. The system consists of $$$n$$$ junctions and $$$m$$$ pipes, $$$i$$$-th pipe connects junctions $$$x_i$$$ and $$$y_i$$$.The only thing you can do is adjusting the pipes. You have to choose $$$m$$$ integer numbers $$$f_1$$$, $$$f_2$$$, ..., $$$f_m$$$ and use th...
If you can choose such integer numbers $$$f_1, f_2, \dots, f_m$$$ in such a way that all requirements on incoming and outcoming flows are satisfied, then output "Possible" in the first line. Then output $$$m$$$ lines, $$$i$$$-th line should contain $$$f_i$$$ — the chosen setting numbers for the pipes. Pipes are numbere...
The first line contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of junctions. The second line contains $$$n$$$ integers $$$s_1, s_2, \dots, s_n$$$ ($$$-10^4 \le s_i \le 10^4$$$) — constraints for the junctions. The third line contains an integer $$$m$$$ ($$$0 \le m \le 2 \cdot 10^5$$$) — the nu...
standard output
standard input
Python 3
Python
2,400
train_026.jsonl
29992ffdd85a1c14451d6fe874985e3b
256 megabytes
["4\n3 -10 6 1\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "4\n3 -10 6 4\n5\n1 2\n3 2\n2 4\n3 4\n3 1"]
PASSED
import sys from time import time def i_ints(): return list(map(int, sys.stdin.readline().split())) def main(): limit =10**10 n, = i_ints() s = [0] + i_ints() if sum(s): print("Impossible") return print("Possible") m, = i_ints() es = [i_ints() for _ in range(m)] n...
1528625100
[ "trees" ]
[ 0, 0, 0, 0, 0, 0, 0, 1 ]
2 seconds
["1.500000", "1.000000"]
25494129e5358072efc58906b5102652
null
You are given an array a consisting of n positive integers. You pick two integer numbers l and r from 1 to n, inclusive (numbers are picked randomly, equiprobably and independently). If l &gt; r, then you swap values of l and r. You have to calculate the expected value of the number of unique elements in segment of the...
Print one number — the expected number of unique elements in chosen segment. Your answer will be considered correct if its absolute or relative error doesn't exceed 10 - 4 — formally, the answer is correct if , where x is jury's answer, and y is your answer.
The first line contains one integer number n (1 ≤ n ≤ 106). The second line contains n integer numbers a1, a2, ... an (1 ≤ ai ≤ 106) — elements of the array.
standard output
standard input
Python 3
Python
1,800
train_059.jsonl
224b91dfd8c9a839405aa10757467402
256 megabytes
["2\n1 2", "2\n2 2"]
PASSED
n=int(input()) a=list(map(int,input().split())) lastocc=[0]*1000006 ans=[0]*n ans[0]=1 lastocc[a[0]]=1 for i in range(1,n): ans[i]=ans[i-1]+(i+1-lastocc[a[i]]) lastocc[a[i]]=i+1 print((2*sum(ans)-n)/(n*n))
1504623900
[ "probabilities", "math" ]
[ 0, 0, 0, 1, 0, 1, 0, 0 ]
1.5 seconds
["2\n-1\n-1\n5"]
b540db49c0a509e3807e06397cf74aa8
NoteIn the first test case, one sequence of operations that achieves the minimum number of operations is the following. Select $$$i=3$$$, changing $$$\texttt{01}\color{red}{\texttt{0}}\texttt{0}$$$ to $$$\texttt{01}\color{red}{\texttt{1}}\texttt{0}$$$. Select $$$i=2$$$, changing $$$\texttt{0}\color{red}{\texttt{1}}\...
Mark has just purchased a rack of $$$n$$$ lightbulbs. The state of the lightbulbs can be described with binary string $$$s = s_1s_2\dots s_n$$$, where $$$s_i=\texttt{1}$$$ means that the $$$i$$$-th lightbulb is turned on, while $$$s_i=\texttt{0}$$$ means that the $$$i$$$-th lightbulb is turned off.Unfortunately, the li...
For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $$$s$$$ to $$$t$$$. If there is no such sequence of operations, print $$$-1$$$.
The first line of the input contains a single integer $$$q$$$ ($$$1\leq q\leq 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$3\leq n\leq 2\cdot 10^5$$$) — the number of lightbulbs. The second line of each test case contains a binary string $$$s$$$ of length $...
standard output
standard input
PyPy 3-64
Python
1,800
train_100.jsonl
088886a24b8daa9881bc5b10076d7f81
256 megabytes
["4\n\n4\n\n0100\n\n0010\n\n4\n\n1010\n\n0100\n\n5\n\n01001\n\n00011\n\n6\n\n000101\n\n010011"]
PASSED
import sys from array import array input = lambda: sys.stdin.buffer.readline().decode().strip() out = [] for _ in range(int(input())): n, ans = int(input()), 0 s = array('b', [int(x) for x in input()]) t = array('b', [int(x) for x in input()]) sxor = array('b', [s[i] ^ s[i - 1] for i in rang...
1657892100
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["1 3", "2 6"]
58c887568002d947706c448e6faa0f77
NoteExplanation for the first example:Suppose there were 5 participants A-E. Let's denote Nikolay as A. The the most favorable results for Nikolay could look as follows: However, the results of the Olympiad could also look like this: In the first case Nikolay would have taken first place, and in the second — third pl...
Nikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be $$$n$$$ participants, one of whom is Nikolay. Like any good olympiad, it consists of two rounds. Tired of the traditional rules, in which the participant who solved the larges...
Print two integers — the minimum and maximum possible overall place Nikolay could take.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases to solve. Each of the following $$$t$$$ lines contains integers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \leq n \leq 10^9$$$, $$$1 \le x, y \le n$$$) — the number of participants in the olympiad, the place that Nikolay took in the firs...
standard output
standard input
PyPy 3
Python
1,700
train_005.jsonl
58413aeeba9e694ff76d5b7dc5041439
256 megabytes
["1\n5 1 3", "1\n6 3 4"]
PASSED
import math import sys input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: map(int,input().split()) alele = lambda: list(map(int, input().split())) def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] INF ...
1582448700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
3 seconds
["5", "14"]
48b232b9d836b0be91d41e548a9fcefc
NoteIn the first sample there are 6 one-element sets of silos. For sets {1}, {5} the operation danger will equal 8, for sets {3}, {6} — 3, for sets {2}, {4} — 5. The mathematical average equals .In the second sample there are 3 two-elements sets of silos: {1, 3} (danger equals 21), {1, 2} (danger equals 11), {2, 3} (da...
Insurgents accidentally got hold of the plan of a top secret research polygon created on a distant planet for the needs of the Galaxy Empire. The insurgents suppose that this polygon is developing new deadly weapon. The polygon consists of n missile silos connected by bidirectional underground passages. The passages ar...
Print the average danger of the scouting operation, rounded down to an integer. Note that at the given limits the answer to the problem always fits into the standard integer 64-bit data type. Please do not use the %lld specifier to write 64-bit integers in С++. It is preferred to use the cout stream or the %I64d specif...
The first line contains two integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ n - 1) — the number of silos and the number of scout groups, correspondingly. The next n - 1 lines describe the polygon plan: the i-th of these lines contains n - i integers ci, i + 1, ci, i + 2, ..., ci, n — the number of droids that patrol the corres...
standard output
standard input
PyPy 2
Python
2,400
train_059.jsonl
b15e78d4495ee4e9a1cadbd7fb6a7463
256 megabytes
["6 1\n-1 -1 -1 8 -1\n-1 5 -1 -1\n-1 -1 3\n-1 -1\n-1", "3 2\n10 0\n11"]
PASSED
import sys sys.setrecursionlimit(2100) range = xrange input = raw_input def getter(DP, k): n = len(DP) - 1 if 2 * k >= n: k = n - k if k < 0: return 0 return DP[k] inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 n = inp[ii]; ii += 1 k = inp[ii]; ii += 1 DP = [1] DPk = [] DPkm...
1374679800
[ "math", "graphs" ]
[ 0, 0, 1, 1, 0, 0, 0, 0 ]
1 second
["Finite\nInfinite", "Finite\nFinite\nFinite\nInfinite"]
1b8c94f278ffbdf5b7fc38b3976252b6
Note$$$\frac{6}{12} = \frac{1}{2} = 0,5_{10}$$$$$$\frac{4}{3} = 1,(3)_{10}$$$$$$\frac{9}{36} = \frac{1}{4} = 0,01_2$$$$$$\frac{4}{12} = \frac{1}{3} = 0,1_3$$$
You are given several queries. Each query consists of three integers $$$p$$$, $$$q$$$ and $$$b$$$. You need to answer whether the result of $$$p/q$$$ in notation with base $$$b$$$ is a finite fraction.A fraction in notation with base $$$b$$$ is finite if it contains finite number of numerals after the decimal point. It...
For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of queries. Next $$$n$$$ lines contain queries, one per line. Each line contains three integers $$$p$$$, $$$q$$$, and $$$b$$$ ($$$0 \le p \le 10^{18}$$$, $$$1 \le q \le 10^{18}$$$, $$$2 \le b \le 10^{18}$$$). All numbers are given in...
standard output
standard input
Python 2
Python
1,700
train_026.jsonl
cb08db8d276c29c49094e212cafbf071
256 megabytes
["2\n6 12 10\n4 3 10", "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4"]
PASSED
s0 = raw_input() n = int(s0) for i in xrange(n): s = raw_input() sa = s.split() x, y, b = int(sa[0]), int(sa[1]), int(sa[2]) pb = b for k in range(7): pb = (pb * pb) % y if (x * pb) % y == 0: print "Finite" else: print "Infinite"
1526395500
[ "number theory", "math" ]
[ 0, 0, 0, 1, 1, 0, 0, 0 ]
2 seconds
["Yes\n1 0\n1 1\n0 1\n0 0\nNo", "Yes\n1 0\n1 1\n2 1\n2 2\n1 2\n1 1\n0 1\n0 0\nYes\n0 -2\n2 -2\n2 -1\n1 -1\n1 0\n0 0", "Yes\n2 0\n2 3\n3 3\n3 7\n4 7\n4 12\n0 12\n0 0\nNo"]
c8d8867789284b2e27fbb73ab3e59793
NoteIn the first test case of the first example, the answer is Yes — for example, the following picture illustrates a square that satisfies the requirements: In the first test case of the second example, the desired polyline also exists. Note that, the polyline contains self-intersections, but only in the endpoints:...
One drew a closed polyline on a plane, that consisted only of vertical and horizontal segments (parallel to the coordinate axes). The segments alternated between horizontal and vertical ones (a horizontal segment was always followed by a vertical one, and vice versa). The polyline did not contain strict self-intersecti...
For each test case output Yes, if there exists at least one polyline satisfying the requirements, or No otherwise. If it does exist, in the following $$$n$$$ lines print the coordinates of the polyline vertices, in order of the polyline traversal: the $$$i$$$-th line should contain two integers $$$x_i$$$ and $$$y_i$$$ ...
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 200$$$) —the number of test cases. The first line of each test case contains one integer $$$h$$$ ($$$1 \leq h \leq 1000$$$) — the number of horizontal segments. The following line contains $$$h$$$ integers $$$l_1, l_2, \dots, l_h$$$ ($$$1 \leq l_i \leq 1000$...
standard output
standard input
PyPy 3
Python
2,900
train_027.jsonl
68d9d087e43970f4cd36eafc1925fe66
512 megabytes
["2\n2\n1 1\n2\n1 1\n\n2\n1 2\n2\n3 3", "2\n4\n1 1 1 1\n4\n1 1 1 1\n\n3\n2 1 1\n3\n2 1 1", "2\n4\n1 4 1 2\n4\n3 4 5 12\n\n4\n1 2 3 6\n2\n1 3"]
PASSED
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase def main(): t = int(input()) for _ in range(t): if _ != 0: input() h = int(input()) l1 = list(map(int,input().split())) v = int(input()) l2 = list(map(int,input().split())) hKn...
1604228700
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
3 seconds
["30\n31\n10"]
da15eae7831e3eb5e1f2e2e4c5222fbf
null
One important contest will take place on the most famous programming platform (Topforces) very soon!The authors have a pool of $$$n$$$ problems and should choose at most three of them into this contest. The prettiness of the $$$i$$$-th problem is $$$a_i$$$. The authors have to compose the most pretty contest (in other ...
For each query print one integer — the maximum possible cumulative prettiness of the contest composed of at most three problems from the given pool of problems in the query.
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of problems. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$2 \...
standard output
standard input
PyPy 3
Python
2,100
train_013.jsonl
e6d5f6c8639fb25a2c217a8118fcc6eb
256 megabytes
["3\n4\n5 6 15 30\n4\n10 6 30 15\n3\n3 4 6"]
PASSED
def cal(sorted_list, size): max_sum = 0 for k in range(len(sorted_list)): max_sum = max(sorted_list[k], max_sum) for i in range(k+1,size): temp_1 = sorted_list[i] if sorted_list[k]%temp_1 != 0: if i+1 < size and max_sum >= sorted_list[k] + sorted_list[i] +...
1561559700
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]
1 second
["12.438.32", "6.38", "0.04"]
8da703549a3002bf9131d6929ec026a2
null
Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. The bill is a string in which the names of the purchases and their prices are printed in a row without any spaces. Check has the format "name1price1name2price2...namenpricen", where namei (name of the i-th purchase) is ...
Print the total price exactly in the same format as prices given in the input.
The only line of the input contains a non-empty string s with length not greater than 1000 — the content of the bill. It is guaranteed that the bill meets the format described above. It is guaranteed that each price in the bill is not less than one cent and not greater than 106 dollars.
standard output
standard input
PyPy 2
Python
1,600
train_004.jsonl
e0c678185449fe4d27ce94def541b732
256 megabytes
["chipsy48.32televizor12.390", "a1b2c3.38", "aa0.01t0.03"]
PASSED
#import resource #import sys #resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY]) #import threading #threading.stack_size(2**26) #sys.setrecursionlimit(0x1000000) from sys import stdin, stdout mod=(10**9)+7 mod1=mod-1 def modinv(n,p): return pow(n,p-2,p) fact=[1] for i in range(1,100001...
1476522300
[ "strings" ]
[ 0, 0, 0, 0, 0, 0, 1, 0 ]
2 seconds
["-3\n0\n0"]
7dfe0db5a99e6e4d71eb012fab07685b
NoteIn the first test case, you can add roads from pasture $$$1$$$ to pasture $$$2$$$ with a time of $$$2$$$, from pasture $$$2$$$ to pasture $$$3$$$ with a time of $$$1$$$, from pasture $$$3$$$ to pasture $$$1$$$ with a time of $$$-3$$$, from pasture $$$3$$$ to pasture $$$2$$$ with a time of $$$-1$$$, from pastu...
Farmer John has a farm that consists of $$$n$$$ pastures connected by one-directional roads. Each road has a weight, representing the time it takes to go from the start to the end of the road. The roads could have negative weight, where the cows go so fast that they go back in time! However, Farmer John guarantees that...
For each test case, output the minimum possible cost of a farm that is consistent with Farmer John's memory.
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of pastures. The second line of each test case contains $$$n$$$ space separated integer...
standard output
standard input
PyPy 3-64
Python
1,400
train_092.jsonl
f85b472e24f47532885c61d31d71f7d3
256 megabytes
["3\n3\n0 2 3\n2\n0 1000000000\n1\n0"]
PASSED
t = int(input()) def solve(n, a): a = sorted(a) s, uk = 0, 0 for i in range(1, n): uk = uk+(s-a[i]*i) s = s+a[i] uk=uk+a[-1] return uk for i in range(t): n = int(input()) a = list(map(int, input().split())) print(solve(n, a))
1624635300
[ "graphs" ]
[ 0, 0, 1, 0, 0, 0, 0, 0 ]
2 seconds
["1", "2"]
74da42a1627e4a00fbaae91c75140287
null
Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be t...
Output a single integer — the value of mini ≠ j  f(i, j).
The first line of input contains a single integer n (2 ≤ n ≤ 100000). Next line contains n integers a[1], a[2], ..., a[n] ( - 104 ≤ a[i] ≤ 104).
standard output
standard input
PyPy 2
Python
2,200
train_066.jsonl
b5e6750d3e97a9ed00febe76f645faf9
256 megabytes
["4\n1 0 0 -1", "2\n1 -1"]
PASSED
import sys sys.setrecursionlimit(10 ** 6) def pyes_no(condition) : if condition : print ("YES") else : print ("NO") def plist(a, s = ' ') : print (s.join(map(str, a))) def rint() : return int(sys.stdin.readline()) def rints() : return map(int, sys.stdin.readline().split()) def rfield(n, m = None...
1399822800
[ "geometry" ]
[ 0, 1, 0, 0, 0, 0, 0, 0 ]
2 seconds
["3\n1\n0\n1\n2\n3\n6"]
1de2203ba34e20fa35571a43c795da53
null
A matrix of size $$$n \times m$$$, such that each cell of it contains either $$$0$$$ or $$$1$$$, is considered beautiful if the sum in every contiguous submatrix of size $$$2 \times 2$$$ is exactly $$$2$$$, i. e. every "square" of size $$$2 \times 2$$$ contains exactly two $$$1$$$'s and exactly two $$$0$$$'s.You are gi...
For each query, print one integer — the number of ways to fill the empty cells of the matrix after the respective query, taken modulo $$$998244353$$$.
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \le n, m \le 10^6$$$; $$$1 \le k \le 3 \cdot 10^5$$$) — the number of rows in the matrix, the number of columns, and the number of queries, respectively. Then $$$k$$$ lines follow, the $$$i$$$-th of them contains three integers $$$x_i$$$, $$$y_i$...
standard output
standard input
PyPy 3
Python
2,500
train_088.jsonl
66e6e25780c39afb5b8596d3f35c5dce
256 megabytes
["2 2 7\n1 1 1\n1 2 1\n2 1 1\n1 1 0\n1 2 -1\n2 1 -1\n1 1 -1"]
PASSED
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m,k=map(int,input().split()) mod=998244353 MOD22=[[0,0],[0,0]] R=[[0]*n,[0]*n] C=[[0]*m,[0]*m] RB=0 CB=0 RK=0 CK=0 D=dict() ANSLIST=[] POW2=[1] for i in range(10**6+4): POW2.append(POW2[-1]*2%mod) ...
1632148500
[ "math" ]
[ 0, 0, 0, 1, 0, 0, 0, 0 ]